[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Debian JP master SVN www commits (rev.551)



=======================================================
Repository: /org/svn.debian.or.jp/repos
  Revision: 551
  Commiter: yasu
      Date: 2008-02-03 21:24:53 +0900 (日, 03  2月 2008)
=======================================================
Log:

first version use GeoIP. Plese apt-get install geoip-bin before use it. This program uses /usr/share/GeoIP/GeoIP.dat

=======================================================
Changed:

_U  cdn/trunk/
U   cdn/trunk/DNS-Balance/dns_balance.rb
U   cdn/trunk/check-surrogates.rb
A   cdn/trunk/country/
A   cdn/trunk/country/JP_deb_cdn_araki_net.rb
A   cdn/trunk/country/JP_jp_cdn_araki_net.rb
A   cdn/trunk/country/KR_deb_cdn_araki_net.rb


Property changes on: cdn/trunk
___________________________________________________________________
Name: svn:externals
   + geoip svn://rubyforge.org/var/svn/geoip/trunk


Modified: cdn/trunk/DNS-Balance/dns_balance.rb
===================================================================
--- cdn/trunk/DNS-Balance/dns_balance.rb	2008-02-03 12:10:06 UTC (rev 550)
+++ cdn/trunk/DNS-Balance/dns_balance.rb	2008-02-03 12:24:53 UTC (rev 551)
@@ -15,7 +15,6 @@
   PREFIX = ENV["ROOT"]
   $LOAD_PATH.unshift(PREFIX)
 end
-$LOAD_PATH.freeze
 
 require 'socket'
 require 'thread'
@@ -30,6 +29,9 @@
 require 'namespace.rb'
 require 'addrdb.rb'
 
+require File.dirname(__FILE__) + '/../geoip/lib/geoip'
+$LOAD_PATH.freeze ## for geoip
+
 #####################################################################
 # ユーザ定義例外
 class DnsNotImplementedError < StandardError ; end
@@ -91,6 +93,24 @@
     end
   }
 
+  # XXX by GeoIP
+  if OPT["geoip"] &&
+      ip_mask(addrstr,  8) != "10.0.0.0"      &&
+      ip_mask(addrstr, 12) != "172.16.0.0"    &&
+      ip_mask(addrstr, 16) != "192.168.0.0"   &&
+      ip_mask(addrstr, 21) != "204.152.184.0" #&&
+#      addrstr              != "127.0.0.1"
+    
+    addrstr = "210.130.0.1"
+    as = geoip_search(addrstr)
+
+    if as                  != nil &&
+	$addr_db[as]       != nil &&
+	$addr_db[as][name] != nil
+      return as
+    end
+  end
+
   # AS namespace
   if OPT["as"] &&
       # RFC1918 / プライベートアドレスはどこの AS にも属していない
@@ -111,6 +131,12 @@
   return "default"
 end
 
+def geoip_search(str)
+  geo = GeoIP.new('/usr/share/GeoIP/GeoIP.dat').country(str)
+  return geo[3]
+end
+
+
 # 重みつき変数のための表を作る
 def make_rand_array(namespace, name)
   rnd_max = 0
@@ -201,6 +227,13 @@
     |o|
     OPT["i"] = o;
   }
+  opt.on("-p PORT", String, "Listen UDP PORT number (default:53)") {
+    |o|
+    OPT["port"] = o;
+  }
+  opt.on("--geoip", "Enable GeoIP namespace") {
+    OPT["geoip"] = true
+  }
   opt.on("--as", "Enable AS namespace") {
     OPT["as"] = true
   }
@@ -245,7 +278,11 @@
 
 gs = UDPSocket::new()
 sockaddr = (if OPT["i"] == nil then Socket::INADDR_ANY else OPT["i"] end)
-gs.bind(sockaddr, Service::Domain)
+if OPT["port"]
+  gs.bind(sockaddr, OPT["port"])
+else
+  gs.bind(sockaddr, Service::Domain)
+end
 
 #
 # メインループ

Modified: cdn/trunk/check-surrogates.rb
===================================================================
--- cdn/trunk/check-surrogates.rb	2008-02-03 12:10:06 UTC (rev 550)
+++ cdn/trunk/check-surrogates.rb	2008-02-03 12:24:53 UTC (rev 551)
@@ -21,6 +21,10 @@
     @last_modified = nil
   end
 
+  def logclose
+    @slog.close
+  end
+
   def checkhttp(host, tracefile, first_surrogate=nil, port=80)
     begin 
       h = Net::HTTP.new(host, port)
@@ -60,6 +64,7 @@
 
   def make_surrogate_line(listfile)
     domain = listfile.gsub(/\.\/lists_/, '')
+    domain.gsub!(/\.\/country\/[A-Z]+_/, '')
     domain.gsub!(/_/, '.')
 
     surrogates = ''
@@ -90,26 +95,32 @@
     @lines += "\t],\n"
 
   end
+end ## end CheckSurrogate
+
+domains = Array.new
+$addr_db = Hash.new
+begin
+  Dir.mkdir(".addrs")
+rescue
 end
 
-domains = Array.new
-listfiles = Array.new
+default_listfiles = Array.new
 Find.find(File.dirname(__FILE__)) do |f|
   if f =~ /^\.\/lists_([\w_]+)\.rb$/
     cl = $1
-    listfiles.push f.gsub(/\.rb$/,'')
+    default_listfiles.push f.gsub(/\.rb$/,'')
   end
 end
 
-cs = CheckSurrogate.new
+default_cs = CheckSurrogate.new
 
-listfiles.each do |f|
-  cs.make_surrogate_line(f)
+default_listfiles.each do |f|
+  default_cs.make_surrogate_line(f)
 end
 
-foo = File.open("addr", 'w')
+foo = File.open(".addrs/default", 'w')
 foo.puts "##" + Time.now.to_s + "\n\n"
-foo.puts '$addr_db = {
+foo.puts '$tmp_db = {
   "default" => {
     "ns.cdn.araki.net" => [
       [[210,157,158,38], 0],
@@ -118,10 +129,64 @@
       [[127,0,0,1], 0],
     ],
 '
-foo.puts cs.lines
-
+foo.puts default_cs.lines
 foo.puts '
   },
 }'
+foo.close
+default_cs.logclose
 
-foo.close
+###
+
+listfiles = Array.new
+countries = Array.new
+Find.find(File.dirname(__FILE__) + '/country') do |f|
+  if f =~ /^\.\/country\/([A-Z]+)_[\w_]+\.rb$/
+    countries.push $1
+  end
+end
+countries.uniq!
+
+countries.each do |country|
+  cs = CheckSurrogate.new
+  Find.find(File.dirname(__FILE__) + '/country') do |f|
+    if f =~ /^\.\/country\/#{country}_[\w_]+\.rb$/
+      f.gsub!(/\.rb$/,'')
+      cs.make_surrogate_line(f)
+    end
+  end
+  foo = File.open(".addrs/#{country}", 'w')
+  foo.puts "##" + Time.now.to_s + "\n\n"
+  foo.puts "$tmp_db = {
+  \"#{country}\" => {
+"
+  foo.puts cs.lines
+  foo.puts '
+  },
+}'
+  foo.close
+  cs.logclose
+end
+
+
+
+Find.find(File.dirname(__FILE__) + '/.addrs') do |f|
+  if f =~ /^\.\/\.addrs\/([\w_]+)$/
+    country = $1
+    bar = File.open(f, 'r')
+    eval(bar.read)
+
+    $addr_db[$1] = $tmp_db[$1] 
+  end
+end
+
+
+
+
+
+puts $addr_db.inspect
+
+addrfile = File.open("addr", 'w')
+addrfile.puts "##" + Time.now.to_s + "\n\n"
+addrfile.puts '$addr_db = ' + $addr_db.inspect
+addrfile.close

Added: cdn/trunk/country/JP_deb_cdn_araki_net.rb
===================================================================
--- cdn/trunk/country/JP_deb_cdn_araki_net.rb	                        (rev 0)
+++ cdn/trunk/country/JP_deb_cdn_araki_net.rb	2008-02-03 12:24:53 UTC (rev 551)
@@ -0,0 +1,16 @@
+$tracefile = 'hanzubon.jp' # hanzubon 2007apr5
+$first_surrogate = '61.115.118.67'
+
+$surrogates = {
+  '203.178.137.175' => '9000', # naist
+  '61.115.118.67' => '1000', # hanzubon 2007apr5
+  '210.157.158.38' => '9900', # plat
+  '202.229.186.27' => '20', # topstudio
+  '133.5.166.3' => '10', # dennou-q.gfd-dennou.org
+  '130.54.59.159' => '10', # dennou-k.gfd-dennou.org
+  '133.50.218.117' => '10', # dennou-h.gfd-dennou.org
+  '61.206.119.174' => '20', # oyu-net.jp
+##  '219.111.15.135' => '1000', # tagoh
+#  '15.12.218.222' => '9900', # fail data for test
+#  '210.157.158.59' => '9900' ## fail data for test
+}

Added: cdn/trunk/country/JP_jp_cdn_araki_net.rb
===================================================================
--- cdn/trunk/country/JP_jp_cdn_araki_net.rb	                        (rev 0)
+++ cdn/trunk/country/JP_jp_cdn_araki_net.rb	2008-02-03 12:24:53 UTC (rev 551)
@@ -0,0 +1,16 @@
+$tracefile = 'hanzubon.jp' # hanzubon 2007apr5
+$first_surrogate = '61.115.118.67'
+
+$surrogates = {
+  '203.178.137.175' => '9000', # naist
+  '61.115.118.67' => '1000', # hanzubon 2007apr5
+  '210.157.158.38' => '9900', # plat
+  '202.229.186.27' => '20', # topstudio
+  '133.5.166.3' => '10', # dennou-q.gfd-dennou.org
+  '130.54.59.159' => '10', # dennou-k.gfd-dennou.org
+  '133.50.218.117' => '10', # dennou-h.gfd-dennou.org
+  '61.206.119.174' => '20', # oyu-net.jp
+##  '219.111.15.135' => '1000', # tagoh
+#  '15.12.218.222' => '9900', # fail data for test
+#  '210.157.158.59' => '9900' ## fail data for test
+}

Added: cdn/trunk/country/KR_deb_cdn_araki_net.rb
===================================================================
--- cdn/trunk/country/KR_deb_cdn_araki_net.rb	                        (rev 0)
+++ cdn/trunk/country/KR_deb_cdn_araki_net.rb	2008-02-03 12:24:53 UTC (rev 551)
@@ -0,0 +1,3 @@
+$surrogates = {
+  '143.248.234.110' => '20', 
+}