[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Debian JP master SVN www commits (rev.1081)
=======================================================
Repository: /org/svn.debian.or.jp/repos
Revision: 1081
Commiter: yasu
Date: 2010-09-23 20:23:07 +0900 (木, 23 9月 2010)
=======================================================
Log:
ASN
=======================================================
Changed:
U cdn/trunk/DNS-Balance/ChangeLog
U cdn/trunk/DNS-Balance/dns_balance.rb
A cdn/trunk/maxmind/
A cdn/trunk/maxmind/GeoIP.dat
A cdn/trunk/maxmind/GeoIPASNum.dat
A cdn/trunk/maxmind/GeoLiteCity.dat
Modified: cdn/trunk/DNS-Balance/ChangeLog
===================================================================
--- cdn/trunk/DNS-Balance/ChangeLog 2010-09-05 05:30:46 UTC (rev 1080)
+++ cdn/trunk/DNS-Balance/ChangeLog 2010-09-23 11:23:07 UTC (rev 1081)
@@ -1,3 +1,7 @@
+2010-08-28 ARAKI Yasuhiro <ar@debian.org>
+
+ * dns_balance.rb: Now use Maxmind's BGP ASN information to lookup.
+
2009-08-08 ARAKI Yasuhiro <ar@debian.org>
* dns_balance.rb (#run): Fix to apply JRuby. At JRuby, Type is important for UDPSocket::new.bind(Sting a, Fixnum b).
Modified: cdn/trunk/DNS-Balance/dns_balance.rb
===================================================================
--- cdn/trunk/DNS-Balance/dns_balance.rb 2010-09-05 05:30:46 UTC (rev 1080)
+++ cdn/trunk/DNS-Balance/dns_balance.rb 2010-09-23 11:23:07 UTC (rev 1081)
@@ -20,11 +20,12 @@
$LOAD_PATH.unshift(PREFIX)
end
-
-
$process_file = '/var/run/dns_balance.pid'
$logfile = '/var/log/dns_balance.log'
+$fgeoip = File.dirname(__FILE__) + '/../maxmind/GeoIP.dat'
+$fgeoipasn = File.dirname(__FILE__) + '/../maxmind/GeoIPASNum.dat'
+
require 'socket'
require 'thread'
require 'optparse'
@@ -33,7 +34,6 @@
require 'multilog.rb'
require 'log_writer.rb'
require 'util.rb'
-require 'as_search.rb'
require 'namespace.rb'
require 'addrdb.rb'
@@ -102,16 +102,16 @@
end
}
- # country by GeoIP
- if OPT["country"] &&
+ # AS namespace
+ if OPT["as"] &&
+ # RFC1918 / プライベートアドレスはどこの AS にも属していない
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"
-
- as = geoip_search_country(addrstr)
+ as = geoip_search_asn(addrstr)
if as != nil &&
$addr_db[as] != nil &&
$addr_db[as][name] != nil
@@ -119,16 +119,15 @@
end
end
- # continent: AS, EU, SA, AF, OC, NA
- # continent by GeoIP
- if OPT["continent"] &&
+ # country by GeoIP
+ if OPT["country"] &&
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"
- as = geoip_search_continent(addrstr)
+ as = geoip_search_country(addrstr)
if as != nil &&
$addr_db[as] != nil &&
@@ -137,16 +136,17 @@
end
end
- # AS namespace
- if OPT["as"] &&
- # RFC1918 / プライベートアドレスはどこの AS にも属していない
+ # continent: AS, EU, SA, AF, OC, NA
+ # continent by GeoIP
+ if OPT["continent"] &&
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"
+
+ as = geoip_search_continent(addrstr)
- as = as_search(addrstr)
if as != nil &&
$addr_db[as] != nil &&
$addr_db[as][name] != nil
@@ -154,10 +154,13 @@
end
end
+
# return "default"
return "NA"
end
+
+
def geoip_search_country(str)
geo = GeoIP.new('/usr/share/GeoIP/GeoIP.dat').country(str)
return geo[4]
@@ -168,7 +171,12 @@
return geo[6]
end
+def geoip_search_asn(str)
+ geo = GeoIP.new($fgeoipasn).asn(str)
+ return geo[0]
+end
+
# 重みつき変数のための表を作る
def make_rand_array(namespace, name)
rnd_max = 0
@@ -176,10 +184,9 @@
$addr_db[namespace][name].each {
|i|
- rnd_max += (10000 - min(10000, i[1])) # badness の最大値は 10000
+ rnd_max = rand(rnd_max).to_i + (10000 - min(10000, i[1])) # badness の最大値は 10000
rnd_slesh.push(rnd_max)
}
-
return [rnd_max, rnd_slesh]
end
@@ -195,8 +202,10 @@
(0...size).each {
|i|
rnd = rand(rnd_max)
+
(0...rnd_slesh.size).each {
|j|
+
if rnd <= rnd_slesh[j]
arr.push(j)
break
@@ -262,12 +271,6 @@
ML.log("reload failed")
end
end
-
- #if test(?r, PREFIX + "/addr-once") || test(?r, "./addr-once")
- # Thread.exit
- #end
-
- #p $addr_db
sleep(2*60) # 5 分毎に更新
}
}
@@ -319,8 +322,19 @@
else
size = 1
end
- a_array = select_rand_array(namespace, name, size) #.uniq
+ a1 = select_rand_array(namespace, name, size)
+ h1 = a1.inject(Hash.new(0)) { |r, e| r[e] += 1; r }
+ a2 = h1.to_a.sort{|a, b| b[1] <=> a[1]}
+ a3 = Array.new
+ count = 0
+ a2.each do |n1|
+ a3.push(n1.first)
+ count += n1.last
+ break if count > 5
+ end
+
+ a_array = a3
if a_array.size == 0
raise DnsNoMoreResourceError
end
@@ -438,6 +452,14 @@
OPT["logfile"] = true
$logfile = o;
}
+ opt.on("--geoip-file filename", String, "Set logfile (default: #{$fgeoip})") {
+ |o|
+ $fgeoip = o;
+ }
+ opt.on("--geoip-asn-file filename", String, "Set logfile (default: #{$fgeoipasn})") {
+ |o|
+ $fgeoipasn = o;
+ }
opt.on("--geoip", "Enable GeoIP ") {
OPT["country"] = true
OPT["continent"] = true
@@ -471,6 +493,25 @@
end
OPT.freeze
+
+
+unless File.exist? $fgeoip
+ puts $fgeoip + ' is not exist.'
+ puts "Please set MaxMind's GeoIP data file."
+ puts "Download from http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry"
+ puts File.dirname(__FILE__) + '/../maxmind/GeoIP.dat'
+ exit 0
+end
+
+unless File.exist? $fgeoipasn
+ puts $fgeoipasn + ' is not exist.'
+ puts "Please set MaxMind's GeoIPASNum data file."
+ puts "Download from http://geolite.maxmind.com/download/geoip/database/asnum/"
+ puts File.dirname(__FILE__) + '/../maxmind/GeoIPASNum.dat'
+ exit 0
+end
+
+
ML = MultiLog::new
def srun
Added: cdn/trunk/maxmind/GeoIP.dat
===================================================================
(Binary files differ)
Property changes on: cdn/trunk/maxmind/GeoIP.dat
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: cdn/trunk/maxmind/GeoIPASNum.dat
===================================================================
(Binary files differ)
Property changes on: cdn/trunk/maxmind/GeoIPASNum.dat
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: cdn/trunk/maxmind/GeoLiteCity.dat
===================================================================
(Binary files differ)
Property changes on: cdn/trunk/maxmind/GeoLiteCity.dat
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream