Skip to content

Commit

Permalink
Canonicalise IPv6 address before searching for peers (librenms#16541)
Browse files Browse the repository at this point in the history
* Canonicalise IPv6 address before searching for peers

JunOS (and probably other platforms) compress the peer identifier, but the code searches the uncompressed database field.

The existing behaviour isn't great either - it clobbers the value of bgpPeerIdentifier.

So, to fix it this change saves an IP object and operates on that, then only uses the pretty value for rendering - SQL queries use the unmodified version.

* Fix a typo and a copy-paste error

* Remove whitespace

* Use a local variable

* IP may be null since errors are ignored

---------

Co-authored-by: Tony Murray <[email protected]>
  • Loading branch information
TheMysteriousX and murrant authored Dec 17, 2024
1 parent c63c912 commit 99440c7
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions includes/html/pages/device/routing/bgp.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@
unset($alert);
unset($peerhost, $peername);

// load the peer identifier into an object
$peerIdentifierIp = IP::parse($peer['bgpPeerIdentifier'], true);

if ($peer['bgpPeerState'] == 'established') {
$col = 'green';
} else {
Expand Down Expand Up @@ -159,7 +162,7 @@
$query = 'SELECT * FROM ipv6_addresses AS A, ports AS I, devices AS D WHERE ';
$query .= '(A.ipv6_address = ? AND I.port_id = A.port_id)';
$query .= ' AND D.device_id = I.device_id';
$ipv6_host = dbFetchRow($query, [$peer['bgpPeerIdentifier']]);
$ipv6_host = dbFetchRow($query, [$peerIdentifierIp?->uncompressed()]);

if ($ipv4_host) {
$peerhost = $ipv4_host;
Expand Down Expand Up @@ -198,9 +201,6 @@
// Build a list of valid AFI/SAFI for this peer
}

// make ipv6 look pretty
$peer['bgpPeerIdentifier'] = (string) IP::parse($peer['bgpPeerIdentifier'], true);

// display overlib graphs
$graph_array = [];
$graph_array['type'] = 'bgp_updates';
Expand All @@ -222,7 +222,7 @@
$link_array['page'] = 'graphs';
unset($link_array['height'], $link_array['width'], $link_array['legend']);
$link = \LibreNMS\Util\Url::generate($link_array);
$peeraddresslink = '<span class=list-large>' . \LibreNMS\Util\Url::overlibLink($link, $peer['bgpPeerIdentifier'], \LibreNMS\Util\Url::graphTag($graph_array_zoom)) . '</span>';
$peeraddresslink = '<span class=list-large>' . \LibreNMS\Util\Url::overlibLink($link, $peerIdentifierIp?->compressed(), \LibreNMS\Util\Url::graphTag($graph_array_zoom)) . '</span>';

if ($peer['bgpPeerLastErrorCode'] == 0 && $peer['bgpPeerLastErrorSubCode'] == 0) {
$last_error = $peer['bgpPeerLastErrorText'];
Expand Down

0 comments on commit 99440c7

Please sign in to comment.