BEGIN { $sockaddr_t = 'S n a4 x8'; $hostmaster = "root.viva"; $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; } ## 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("best",T_NS,rr_NS("best.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("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_dynamic("round.robin.best.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 { my($domain,$residual,$qtype,$qclass,$dm) = @_; my($the_host,$the_ip,$answer,$qname,$group); @hostArray = ("viva", "vinci", "frodo"); $hostCount = scalar @hostArray; %ipArray = ( "viva" => "128.198.192.192", "vinci" => "128.198.192.193", "frodo" => "128.198.192.183" ); $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" 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}; } sub handle_best_request { my($domain,$residual,$qtype,$qclass,$dm) = @_; my($the_host,$the_ip,$answer,$qname,$group); %ipArray = ( "viva" => "128.198.192.192", "vinci" => "128.198.192.193", "frodo" => "128.198.192.183", "gandalf" => "128.198.192.194", "walrus" => "128.198.192.197", "third" => "128.198.192.203" ); $qname = $residual; open(STATFILE, ") { @lineArray = split /:/, $line; $host = $lineArray[0]; $_ = $host; $host = $1 if (/^(\w+)\./); $hosts[$i] = $host; $weight = $lineArray[1]; #$weight -= $touched{$host}; #$weight -= $touched{$host}*10; &write_log("Best: before sorting: $the_host with $weight{$the_host}"); $weight{$host} = $weight; $i++; } @hosts = sort by_weight @hosts; 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;