BEGIN { $sockaddr_t = 'S n a4 x8'; $hostmaster = "root.gandalf"; $hostIndex = 0; $_ = "128.198.192.192"; ($a, $b, $c, $d) = /(\d+)\.(\d+)\.(\d+)\.(\d+)/; $vip = ($a<<24)|($b<<16)|($c<<8)|$d; $_ = "128.198.192.193"; ($a, $b, $c, $d) = /(\d+)\.(\d+)\.(\d+)\.(\d+)/; $nip = ($a<<24)|($b<<16)|($c<<8)|$d; $_ = "128.198.192.183"; ($a, $b, $c, $d) = /(\d+)\.(\d+)\.(\d+)\.(\d+)/; $fip = ($a<<24)|($b<<16)|($c<<8)|$d; $_ = "128.198.192.194"; ($a, $b, $c, $d) = /(\d+)\.(\d+)\.(\d+)\.(\d+)/; $gip = ($a<<24)|($b<<16)|($c<<8)|$d; $_ = "128.198.192.197"; ($a, $b, $c, $d) = /(\d+)\.(\d+)\.(\d+)\.(\d+)/; $wip = ($a<<24)|($b<<16)|($c<<8)|$d; $_ = "128.198.192.203"; ($a, $b, $c, $d) = /(\d+)\.(\d+)\.(\d+)\.(\d+)/; $tip = ($a<<24)|($b<<16)|($c<<8)|$d; $_ = "128.198.162.217"; ($a, $b, $c, $d) = /(\d+)\.(\d+)\.(\d+)\.(\d+)/; $hip = ($a<<24)|($b<<16)|($c<<8)|$d; $_ = "128.198.162.64"; ($a, $b, $c, $d) = /(\d+)\.(\d+)\.(\d+)\.(\d+)/; $sip = ($a<<24)|($b<<16)|($c<<8)|$d; $_ = "128.198.162.66"; ($a, $b, $c, $d) = /(\d+)\.(\d+)\.(\d+)\.(\d+)/; $rip = ($a<<24)|($b<<16)|($c<<8)|$d; $_ = "128.198.162.62"; ($a, $b, $c, $d) = /(\d+)\.(\d+)\.(\d+)\.(\d+)/; $lip = ($a<<24)|($b<<16)|($c<<8)|$d; $_ = "128.198.162.61"; ($a, $b, $c, $d) = /(\d+)\.(\d+)\.(\d+)\.(\d+)/; $cip = ($a<<24)|($b<<16)|($c<<8)|$d; $_ = "128.198.162.60"; ($a, $b, $c, $d) = /(\d+)\.(\d+)\.(\d+)\.(\d+)/; $bip = ($a<<24)|($b<<16)|($c<<8)|$d; } ## NOTE: handle_best_request still contains two hard-coded references ## to stanford.edu. You should change them to match your domain. ############################################################ #LBDB::add_static("best.csnet.uccs.edu",T_SOA,rr_SOA(hostname,$hostmaster,time,86400,86400,86400,0)); LBDB::add_static("csnet.uccs.edu",T_SOA,rr_SOA(hostname,$hostmaster,time,86400,86400,86400,0)); LBDB::add_static("best",T_NS,rr_NS("best.csnet.uccs.edu")); LBDB::add_static("round.robin",T_NS,rr_NS("round.robin.csnet.uccs.edu")); LBDB::add_static("viva",T_A,rr_A($vip)); LBDB::add_static("vinci",T_A,rr_A($nip)); LBDB::add_static("frodo",T_A,rr_A($fip)); LBDB::add_static("gandalf",T_A,rr_A($gip)); LBDB::add_static("walrus",T_A,rr_A($wip)); LBDB::add_static("third",T_A,rr_A($tip)); LBDB::add_static("wetterhorn",T_A,rr_A($hip)); LBDB::add_static("shavano",T_A,rr_A($sip)); LBDB::add_static("redcloud",T_A,rr_A($rip)); LBDB::add_static("sanluis",T_A,rr_A($lip)); LBDB::add_static("crestone",T_A,rr_A($cip)); LBDB::add_static("blanca",T_A,rr_A($bip)); LBDB::add_static("192.192.198.128.in-addr.arpa",T_PTR,rr_PTR("viva")); LBDB::add_static("193.192.198.128.in-addr.arpa",T_PTR,rr_PTR("vinci")); LBDB::add_static("183.192.198.128.in-addr.arpa",T_PTR,rr_PTR("frodo")); LBDB::add_static("197.192.198.128.in-addr.arpa",T_PTR,rr_PTR("walrus")); LBDB::add_static("194.192.198.128.in-addr.arpa",T_PTR,rr_PTR("gandalf")); LBDB::add_static("203.192.198.128.in-addr.arpa",T_PTR,rr_PTR("third")); LBDB::add_static("217.162.198.128.in-addr.arpa",T_PTR,rr_PTR("wetterhorn")); LBDB::add_static("64.162.198.128.in-addr.arpa",T_PTR,rr_PTR("shavano")); LBDB::add_static("66.162.198.128.in-addr.arpa",T_PTR,rr_PTR("redcloud")); LBDB::add_static("62.162.198.128.in-addr.arpa",T_PTR,rr_PTR("sanluis")); LBDB::add_static("61.162.198.128.in-addr.arpa",T_PTR,rr_PTR("crestone")); LBDB::add_static("60.162.198.128.in-addr.arpa",T_PTR,rr_PTR("blanca")); ####################################################################### #LBDB::add_dynamic("round.robin.best.csnet.uccs.edu" => \&handle_round_robin_request); LBDB::add_dynamic("round.robin.csnet.uccs.edu" => \&handle_round_robin_request); #LBDB::add_dynamic("best.csnet" => \&handle_best_request); LBDB::add_dynamic("best.csnet.uccs.edu" => \&handle_best_request); ############################################################ # dynamic domain handlers... sub handle_round_robin_request { &write_log("In Round Robin: Using: "); my($domain,$residual,$qtype,$qclass,$dm) = @_; my($the_host,$the_ip,$answer,$qname,$group); @hostArray = ( "wetterhorn", "sanluis", "crestone", "blanca"); $hostCount = scalar @hostArray; %ipArray = ( "wetterhorn" => "128.198.162.217", "sanluis" => "128.198.162.62", "crestone" => "128.198.162.61", "blanca" => "128.198.162.60" ); $qname = $residual; if ($qtype == T_A || $qtype == T_MX || $qtype == T_ANY) { $the_host = $hostArray[$hostIndex]; &write_log("Round Robin: Using: $the_host"); $hostIndex++; if ($hostIndex >= $hostCount) { $hostIndex = 0; } $ipaddr = $ipArray{$the_host}; $_ = $ipaddr; ($a,$b,$c,$d) = /(\d+)\.(\d+)\.(\d+)\.(\d+)/; $the_ip = ($a<<24)|($b<<16)|($c<<8)|$d; $the_host .= ".csnet.uccs.edu" if ($the_host !~/\.csnet/i); $answer = dns_answer(QPTR, T_CNAME, C_IN, 0, rr_CNAME($the_host)); $answer .= dns_answer( dns_simple_dname($the_host), T_A,C_IN,3600, rr_A($the_ip)); $dm->{'answer'} .= $answer; $dm->{'ancount'} += 2; } else { $dm->{'rcode'} = NXDOMAIN; } return 1; } sub by_weight { $weight{$b} <=> $weight{$a}; &write_log("InSUBbyWeight: $weight{$a}\n"); } sub handle_best_request { my($domain,$residual,$qtype,$qclass,$dm) = @_; my($the_host,$the_ip,$answer,$qname,$group); %ipArray = ( "wetterhorn" => "128.198.162.217", "sanluis" => "128.198.162.62", "crestone" => "128.198.162.61", "blanca" => "128.198.162.60" ); $qname = $residual; open(STATFILE, ") { #@lineArray = split /:/, $line; @lineArray = split(' ', $line); $host = $lineArray[0]; #&write_log("Read host-name= $host "); $_ = $host; $host = $1 if (/^(\w+)\./); $hosts[$i] = $host; $weight = $lineArray[1]; #&write_log("Check: weight= $weight "); #$weight -= $touched{$host}; #$weight -= $touched{$host}*10; $weight{$host} = $weight; &write_log("Best: before sorting: $hosts[$i] with $weight{$hosts[$i]}"); $i++; } $i = 0 ; while($i < 6) { #&write_log("The i val is : $i, and hos is $hosts[$i]"); $i++; } foreach $el (@hosts) { &write_log("listing of keys1:$host, $weight{$hosts}\n"); $el++; } #foreach $weight (keys %hosts){ # &write_log("listing of keys2: $weight, $hosts{$weight}\n");} # @hosts = sort by_weight @hosts; @hosts = sort { $weight{$b} <=> $weight{$a} } keys %weight; foreach $hosts (keys %weight){ &write_log("sorted listing of keys1:$hosts, $weight{$hosts}\n"); } $i = 0 ; while($i < 6) { # &write_log("The i val is : $i,and sorted hos is $hosts[$i] "); $i++; } if ($qtype == T_A || $qtype == T_MX || $qtype == T_ANY) { $the_host = @hosts[0]; &write_log("Best: Using: $the_host with $weight{$the_host}"); #$touched{$the_host} += 1; #foreach $h (keys %touched) #{ #if (($h ne $the_host) && ($touched{$h} != 0)) { $touched{$h} -= 1; } #} $ipaddr = $ipArray{$the_host}; $_ = $ipaddr; ($a,$b,$c,$d) = /(\d+)\.(\d+)\.(\d+)\.(\d+)/; $the_ip = ($a<<24)|($b<<16)|($c<<8)|$d; $the_host .= ".best.csnet.uccs.edu" if ($the_host !~ /\.csnet/i); $answer = dns_answer(QPTR, T_CNAME, C_IN, 0, rr_CNAME($the_host)); $answer .= dns_answer( dns_simple_dname($the_host), T_A,C_IN,3600, rr_A($the_ip)); $dm->{'answer'} .= $answer; $dm->{'ancount'} += 2; } else { $dm->{'rcode'} = NXDOMAIN; } close(STATFILE); return 1; } ############################################################ # standard hooks sub catch_hup { $need_maint=1; $need_reload=1; %touched = ("corelab1" => 0, "corelab2" => 0, "corelab3" => 0); } sub clean_exit { &write_log("received signal, exiting...") ; &close_log; exit(0); } sub init_signals { $::SIG{'INT'} = 'clean_exit'; $::SIG{'QUIT'} = 'clean_exit'; $::SIG{'TERM'} = 'clean_exit'; $::SIG{'HUP'} = 'catch_hup'; } &init_signals; 1;