diff options
author | Jon Langseth <jon.langseth@lilug.no> | 2014-04-16 02:33:53 +0200 |
---|---|---|
committer | Jon Langseth <jon.langseth@lilug.no> | 2014-04-16 02:33:53 +0200 |
commit | fe0d64deab4b01b808e6f1280a33072f07d511fe (patch) | |
tree | 4b925d3b1b1a4514067fbe9c46cd41759fc37f57 | |
parent | c1413d078530854af1aeadbf315ec931e3ef6635 (diff) |
Candidate code for IPv6 addresses in build-linknets.pl. Note, SQL is not updated....
-rwxr-xr-x | clients/build-linknets.pl | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/clients/build-linknets.pl b/clients/build-linknets.pl index 9978ae8..b0bd7e0 100755 --- a/clients/build-linknets.pl +++ b/clients/build-linknets.pl @@ -16,6 +16,7 @@ $coregws->execute; my %switch_id = (); # sysname -> switch database ID my %loopbacks = (); # sysname -> primary address +my %loop_ipv6 = (); # sysname -> primary address my %map = (); # CIDR -> (sysname,ip)* my %lldpneigh = (); # sysname -> sysname -> 1 @@ -35,6 +36,7 @@ while (my $ref = $coregws->fetchrow_hashref) { my $ifs = $snmp->gettable('ifTable'); my $addrs = $snmp->gettable('ipAddrTable'); my $lldp = $snmp->gettable('lldpRemTable'); + my $ipaddresstable = $snmp->gettable('ipAddressTable'); # Find all direct routes we have, and that we also have an address in. # These are our linknet candidates. @@ -63,6 +65,18 @@ while (my $ref = $coregws->fetchrow_hashref) { last; } + my %loopbacks_ipv6_this_switch = (); + for my $addr (values %$ipaddresstable) { + next if not $addr->{'ipAddressAddrType'} == 2; # Only IPv6 addresses please. + my $ifdescr = $ifs->{$addr->{'ipAddressIfIndex'}}->{'ifDescr'}; + next unless $ifdescr =~ /^Loop/; + $loopbacks_ipv6_this_switch{$ifdescr} = nms::convert_ipv6( $addr->{'ipAddressAddr'} ); + } + for my $if (sort keys %loopbacks_ipv6_this_switch) { + $loop_ipv6{$sysname} = $loopbacks_ipv6_this_switch{$if}; + last; + } + # Find all LLDP neighbors. for my $neigh (values %$lldp) { $lldpneigh{$sysname}{$neigh->{'lldpRemSysName'}} = 1; @@ -83,6 +97,12 @@ while (my ($sysname, $ip) = each %loopbacks) { undef, $ip, $sysname); } +# Update the switches we have loopback addresses fora +while (my ($sysname, $ipv6) = each %loopbacks) { + $dbh->do('UPDATE switches SET ipv6=? WHERE sysname=?', + undef, $ipv6, $sysname); +} + # Now go through each linknet candidate, and see if we can find any # direct LLDP neighbors. my $qexist = $dbh->prepare('SELECT COUNT(*) AS cnt FROM linknets WHERE switch1=? AND switch2=?'); |