From 30a73c035ab9ba4d7d9036a95c836eed834e86a4 Mon Sep 17 00:00:00 2001 From: Brian De Wolf Date: Fri, 24 Jun 2011 01:44:20 -0700 Subject: [PATCH 1/3] 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. --- Info/Layer3.pm | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Info/Layer3.pm b/Info/Layer3.pm index 894a2e8a..5b895f68 100644 --- a/Info/Layer3.pm +++ b/Info/Layer3.pm @@ -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 ) { From 3bb33fa8d42b144ebba0b88447bbd6074207491b Mon Sep 17 00:00:00 2001 From: Brian De Wolf Date: Mon, 27 Jun 2011 16:06:56 -0700 Subject: [PATCH 2/3] Fix syntax errors in L3 changes Fix some syntax errors in my improvement code for L3 so that it actually runs. --- Info/Layer3.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Info/Layer3.pm b/Info/Layer3.pm index 5b895f68..d179283d 100644 --- a/Info/Layer3.pm +++ b/Info/Layer3.pm @@ -162,7 +162,7 @@ sub root_ip { return $router_ip if (( defined $router_ip ) and ( $router_ip ne '0.0.0.0' ) - and ( grep { $_ eq $router_ip } (keys %ospf_ip)) ) + 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) From feffa6d47eb237d315e469d9c0f8040dfaf912d5 Mon Sep 17 00:00:00 2001 From: Brian De Wolf Date: Thu, 7 Jul 2011 10:42:00 -0700 Subject: [PATCH 3/3] Fix grep statement in L3 root_ip The grep statement was comparing the router_ip with the SNMP OID-looking keys instead of the values which were just the IPs. --- Info/Layer3.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Info/Layer3.pm b/Info/Layer3.pm index d179283d..985ac27d 100644 --- a/Info/Layer3.pm +++ b/Info/Layer3.pm @@ -162,7 +162,7 @@ sub root_ip { return $router_ip if (( defined $router_ip ) and ( $router_ip ne '0.0.0.0' ) - and ( grep { $_ eq $router_ip } (keys %$ospf_ip)) + and ( grep { $ospf_ip->{$_} eq $router_ip } (keys %$ospf_ip)) and ( $l3->snmp_connect_ip($router_ip) ) ); # return the first one found here (should be only one)