Prefer OSPF router ID in L3 root_ip

The previous behavior of root_ip meant that whatever /32 hosted by the device
that got listed first would be chosen as the root_ip.  If the device only
serves one /32 this works fine, but if there are multiple /32s we could easily
pick the one that is not the intended address meant for management.

Instead, before we pick whatever /32 may exist, we now try to pick the /32 that
is also the OSPF router ID (the router ID is a 32-bit unique identifier which,
while not guaranteed, tends to be an IPv4 address unique to the device).
Otherwise we fall back to the previous method of finding the root_ip.
This commit is contained in:
Brian De Wolf
2011-06-24 01:44:20 -07:00
parent 5c44fc0b28
commit 30a73c035a

View File

@@ -157,6 +157,14 @@ sub root_ip {
my $router_ip = $l3->router_ip();
my $ospf_ip = $l3->ospf_ip();
# if the router ip exists and is a route advertised by the device we prefer
# it over the others
return $router_ip
if (( defined $router_ip )
and ( $router_ip ne '0.0.0.0' )
and ( grep { $_ eq $router_ip } (keys %ospf_ip)) )
and ( $l3->snmp_connect_ip($router_ip) ) );
# return the first one found here (should be only one)
if ( defined $ospf_ip and scalar( keys %$ospf_ip ) ) {
foreach my $key ( keys %$ospf_ip ) {