hasGlobalRead()) { include 'includes/html/error-no-perm.inc.php'; } else { $link_array = [ 'page' => 'routing', 'protocol' => 'bgp', ]; print_optionbar_start('', ''); echo 'BGP » '; if (! $vars['type']) { $vars['type'] = 'all'; } if ($vars['type'] == 'all') { echo ""; } echo generate_link('All', $vars, ['type' => 'all']); if ($vars['type'] == 'all') { echo ''; } echo ' | '; if ($vars['type'] == 'internal') { echo ""; } echo generate_link('iBGP', $vars, ['type' => 'internal']); if ($vars['type'] == 'internal') { echo ''; } echo ' | '; if ($vars['type'] == 'external') { echo ""; } echo generate_link('eBGP', $vars, ['type' => 'external']); if ($vars['type'] == 'external') { echo ''; } echo ' | '; if ($vars['adminstatus'] == 'stop') { echo ""; echo generate_link('Shutdown', $vars, ['adminstatus' => null]); echo ''; } else { echo generate_link('Shutdown', $vars, ['adminstatus' => 'stop']); } echo ' | '; if ($vars['adminstatus'] == 'start') { echo ""; echo generate_link('Enabled', $vars, ['adminstatus' => null]); echo ''; } else { echo generate_link('Enabled', $vars, ['adminstatus' => 'start']); } echo ' | '; if ($vars['state'] == 'down') { echo ""; echo generate_link('Down', $vars, ['state' => null]); echo ''; } else { echo generate_link('Down', $vars, ['state' => 'down']); } // End BGP Menu if (! isset($vars['view'])) { $vars['view'] = 'details'; } echo '
'; if ($vars['view'] == 'details') { echo ""; } echo generate_link('No Graphs', $vars, ['view' => 'details', 'graph' => 'NULL']); if ($vars['view'] == 'details') { echo ''; } echo ' | '; if ($vars['graph'] == 'updates') { echo ""; } echo generate_link('Updates', $vars, ['view' => 'graphs', 'graph' => 'updates']); if ($vars['graph'] == 'updates') { echo ''; } echo ' | Prefixes: Unicast ('; if ($vars['graph'] == 'prefixes_ipv4unicast') { echo ""; $extra_sql = " AND `bgpPeerIdentifier` NOT LIKE '%:%'"; } echo generate_link('IPv4', $vars, ['view' => 'graphs', 'graph' => 'prefixes_ipv4unicast']); if ($vars['graph'] == 'prefixes_ipv4unicast') { echo ''; } echo '|'; if ($vars['graph'] == 'prefixes_ipv6unicast') { echo ""; $extra_sql = " AND `bgpPeerIdentifier` LIKE '%:%'"; } echo generate_link('IPv6', $vars, ['view' => 'graphs', 'graph' => 'prefixes_ipv6unicast']); if ($vars['graph'] == 'prefixes_ipv6unicast') { echo ''; } echo '|'; if ($vars['graph'] == 'prefixes_ipv4vpn') { echo ""; } echo generate_link('VPNv4', $vars, ['view' => 'graphs', 'graph' => 'prefixes_ipv4vpn']); if ($vars['graph'] == 'prefixes_ipv4vpn') { echo ''; } echo '|'; if ($vars['graph'] == 'prefixes_ipv6vpn') { echo ""; } echo generate_link('VPNv6', $vars, ['view' => 'graphs', 'graph' => 'prefixes_ipv6vpn']); if ($vars['graph'] == 'prefixes_ipv6vpn') { echo ''; } echo ')'; echo ' | Multicast ('; if ($vars['graph'] == 'prefixes_ipv4multicast') { echo ""; } echo generate_link('IPv4', $vars, ['view' => 'graphs', 'graph' => 'prefixes_ipv4multicast']); if ($vars['graph'] == 'prefixes_ipv4multicast') { echo ''; } echo '|'; if ($vars['graph'] == 'prefixes_ipv6multicast') { echo ""; } echo generate_link('IPv6', $vars, ['view' => 'graphs', 'graph' => 'prefixes_ipv6multicast']); if ($vars['graph'] == 'prefixes_ipv6multicast') { echo ''; } echo ')'; echo ' | MAC ('; if ($vars['graph'] == 'macaccounting_bits') { echo ""; } echo generate_link('Bits', $vars, ['view' => 'graphs', 'graph' => 'macaccounting_bits']); if ($vars['graph'] == 'macaccounting_bits') { echo ''; } echo '|'; if ($vars['graph'] == 'macaccounting_pkts') { echo ""; } echo generate_link('Packets', $vars, ['view' => 'graphs', 'graph' => 'macaccounting_pkts']); if ($vars['graph'] == 'macaccounting_pkts') { echo ''; } echo ')'; echo '
'; print_optionbar_end(); echo ""; echo ''; if ($vars['type'] == 'external') { $where = 'AND D.bgpLocalAs != B.bgpPeerRemoteAs'; } elseif ($vars['type'] == 'internal') { $where = 'AND D.bgpLocalAs = B.bgpPeerRemoteAs'; } if ($vars['adminstatus'] == 'stop') { $where .= " AND (B.bgpPeerAdminStatus = 'stop')"; } elseif ($vars['adminstatus'] == 'start') { $where .= " AND (B.bgpPeerAdminStatus = 'start' || B.bgpPeerAdminStatus = 'running')"; } if ($vars['state'] == 'down') { $where .= " AND (B.bgpPeerState != 'established')"; } $peer_query = "SELECT * FROM `bgpPeers` AS `B`, `devices` AS `D` WHERE `B`.`device_id` = `D`.`device_id` $where $extra_sql ORDER BY `D`.`hostname`, `B`.`bgpPeerRemoteAs`, `B`.`bgpPeerIdentifier`"; foreach (dbFetchRows($peer_query) as $peer) { unset($alert, $bg_image); if ($peer['bgpPeerState'] == 'established') { $col = 'green'; } else { $col = 'red'; $peer['alert'] = 1; } if ($peer['bgpPeerAdminStatus'] == 'start' || $peer['bgpPeerAdminStatus'] == 'running') { $admin_col = 'green'; } else { $admin_col = 'gray'; } if ($peer['bgpPeerAdminStatus'] == 'stop') { $peer['alert'] = 0; $peer['disabled'] = 1; } if ($peer['bgpPeerRemoteAs'] == $peer['bgpLocalAs']) { $peer_type = "iBGP"; } else { $peer_type = "eBGP"; if ($peer['bgpPeerRemoteAS'] >= '64512' && $peer['bgpPeerRemoteAS'] <= '65535') { $peer_type = "Priv eBGP"; } } try { $peer_ip = new IPv6($peer['bgpLocalAddr']); } catch (InvalidIpException $e) { $peer_ip = $peer['bgpLocalAddr']; } try { $peer_ident = new IPv6($peer['bgpPeerIdentifier']); } catch (InvalidIpException $e) { $peer_ident = $peer['bgpPeerIdentifier']; } // display overlib graphs $graph_array = []; $graph_array['type'] = 'bgp_updates'; $graph_array['id'] = $peer['bgpPeer_id']; $graph_array['to'] = \LibreNMS\Config::get('time.now'); $graph_array['from'] = \LibreNMS\Config::get('time.day'); $graph_array['height'] = '110'; $graph_array['width'] = $width; // Peer Address $graph_array_zoom = $graph_array; $graph_array_zoom['height'] = '150'; $graph_array_zoom['width'] = '500'; $overlib_link = 'device/device=' . $peer['device_id'] . '/tab=routing/proto=bgp/'; $peeraddresslink = '' . overlib_link($overlib_link, $peer_ident, generate_graph_tag($graph_array_zoom), null) . ''; // Local Address $graph_array['afi'] = 'ipv4'; $graph_array['safi'] = 'unicast'; $graph_array_zoom['afi'] = 'ipv4'; $graph_array_zoom['safi'] = 'unicast'; $overlib_link = 'device/device=' . $peer['device_id'] . '/tab=routing/proto=bgp/'; $localaddresslink = '' . overlib_link($overlib_link, $peer_ip, generate_graph_tag($graph_array_zoom), null) . ''; if ($peer['bgpPeerLastErrorCode'] == 0 && $peer['bgpPeerLastErrorSubCode'] == 0) { $last_error = $peer['bgpPeerLastErrorText']; } else { $last_error = describe_bgp_error_code($peer['bgpPeerLastErrorCode'], $peer['bgpPeerLastErrorSubCode']) . '
' . $peer['bgpPeerLastErrorText']; } echo ''; unset($sep); foreach (dbFetchRows('SELECT * FROM `bgpPeers_cbgp` WHERE `device_id` = ? AND bgpPeerIdentifier = ?', [$peer['device_id'], $peer['bgpPeerIdentifier']]) as $afisafi) { $afi = $afisafi['afi']; $safi = $afisafi['safi']; $this_afisafi = $afi . $safi; $peer['afi'] .= $sep . $afi . '.' . $safi; $sep = '
'; $peer['afisafi'][$this_afisafi] = 1; // Build a list of valid AFI/SAFI for this peer } unset($sep); echo ' '; unset($invalid); switch ($vars['graph']) { case 'prefixes_ipv4unicast': case 'prefixes_ipv4multicast': case 'prefixes_ipv4vpn': case 'prefixes_ipv6unicast': case 'prefixes_ipv6multicast': [,$afisafi] = explode('_', $vars['graph']); if (isset($peer['afisafi'][$afisafi])) { $peer['graph'] = 1; } // fall-through case 'updates': $graph_array['type'] = 'bgp_' . $vars['graph']; $graph_array['id'] = $peer['bgpPeer_id']; } switch ($vars['graph']) { case 'macaccounting_bits': case 'macaccounting_pkts': $acc = dbFetchRow('SELECT * FROM `ipv4_mac` AS I, `mac_accounting` AS M, `ports` AS P, `devices` AS D WHERE I.ipv4_address = ? AND M.mac = I.mac_address AND P.port_id = M.port_id AND D.device_id = P.device_id', [$peer['bgpPeerIdentifier']]); $database = rrd_name($device['hostname'], ['cip', $acc['ifIndex'], $acc['mac']]); if (is_array($acc) && is_file($database)) { $peer['graph'] = 1; $graph_array['id'] = $acc['ma_id']; $graph_array['type'] = $vars['graph']; } } if ($vars['graph'] == 'updates') { $peer['graph'] = 1; } if ($peer['graph']) { $graph_array['height'] = '100'; $graph_array['width'] = '218'; $graph_array['to'] = \LibreNMS\Config::get('time.now'); echo ''; } }//end foreach echo '
Local addressPeer addressTypeFamilyRemote ASPeer descriptionStateLast errorUptime / Updates
' . $localaddresslink . '
' . generate_device_link($peer, shorthost($peer['hostname']), ['tab' => 'routing', 'proto' => 'bgp']) . '
» ' . $peeraddresslink . " $peer_type " . $peer['afi'] . ' AS' . $peer['bgpPeerRemoteAs'] . '
' . $peer['astext'] . '
' . $peer['bgpPeerDescr'] . " " . $peer['bgpPeerAdminStatus'] . "
" . $peer['bgpPeerState'] . '
' . $last_error . ' ' . formatUptime($peer['bgpPeerFsmEstablishedTime']) . "
Updates " . format_si($peer['bgpPeerInUpdates']) . " " . format_si($peer['bgpPeerOutUpdates']) . '
'; include 'includes/html/print-graphrow.inc.php'; echo '
'; }//end if