From 848973c71e75424d07c2cd52ba991aae1b9df12a Mon Sep 17 00:00:00 2001 From: paul Date: Wed, 13 Aug 2003 00:32:49 +0000 Subject: 2003-08-13 kunihiro * bgpd/bgp{_fsm.c,_vty.c,d.c,d.h}: Add support for "bgp log-neighbor-changes" command. --- bgpd/bgp_fsm.c | 13 +++++++++++++ bgpd/bgp_vty.c | 35 +++++++++++++++++++++++++++++++++++ bgpd/bgpd.c | 23 +++++++++++++++++++++++ bgpd/bgpd.h | 2 ++ 4 files changed, 73 insertions(+) (limited to 'bgpd') diff --git a/bgpd/bgp_fsm.c b/bgpd/bgp_fsm.c index 64a4c1bd..3d8e9576 100644 --- a/bgpd/bgp_fsm.c +++ b/bgpd/bgp_fsm.c @@ -322,6 +322,14 @@ bgp_stop (struct peer *peer) established = 1; peer->dropped++; bgp_fsm_change_status (peer, Idle); + + /* bgp log-neighbor-changes of neighbor Down */ + if (bgp_flag_check (peer->bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES)) + zlog_info ("%%ADJCHANGE: neighbor %s Down", peer->host); + + /* set last reset time */ + peer->resettime = time (NULL); + #ifdef HAVE_SNMP bgpTrapBackwardTransition (peer); #endif /* HAVE_SNMP */ @@ -629,6 +637,11 @@ bgp_establish (struct peer *peer) /* Increment established count. */ peer->established++; bgp_fsm_change_status (peer, Established); + + /* bgp log-neighbor-changes of neighbor Up */ + if (bgp_flag_check (peer->bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES)) + zlog_info ("%%ADJCHANGE: neighbor %s Up", peer->host); + #ifdef HAVE_SNMP bgpTrapEstablished (peer); #endif /* HAVE_SNMP */ diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index 6514ac22..39a43c04 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -878,6 +878,34 @@ DEFUN (no_bgp_bestpath_aspath_ignore, return CMD_SUCCESS; } +/* "bgp log-neighbor-changes" configuration. */ +DEFUN (bgp_log_neighbor_changes, + bgp_log_neighbor_changes_cmd, + "bgp log-neighbor-changes", + "BGP specific commands\n" + "Log neighbor up/down and reset reason\n") +{ + struct bgp *bgp; + + bgp = vty->index; + bgp_flag_set (bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES); + return CMD_SUCCESS; +} + +DEFUN (no_bgp_log_neighbor_changes, + no_bgp_log_neighbor_changes_cmd, + "no bgp log-neighbor-changes", + NO_STR + "BGP specific commands\n" + "Log neighbor up/down and reset reason\n") +{ + struct bgp *bgp; + + bgp = vty->index; + bgp_flag_unset (bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES); + return CMD_SUCCESS; +} + /* "bgp bestpath med" configuration. */ DEFUN (bgp_bestpath_med, bgp_bestpath_med_cmd, @@ -6660,6 +6688,9 @@ bgp_show_peer (struct vty *vty, struct peer *p) p->established, p->dropped, VTY_NEWLINE); + vty_out (vty, " Last reset %s%s", p->dropped ? peer_uptime (p->resettime, timebuf, BGP_UPTIME_LEN) : "never", + VTY_NEWLINE); + if (CHECK_FLAG (p->sflags, PEER_STATUS_PREFIX_OVERFLOW)) { vty_out (vty, " Peer had exceeded the max. no. of prefixes configured.%s", VTY_NEWLINE); @@ -7743,6 +7774,10 @@ bgp_vty_init () install_element (BGP_NODE, &bgp_bestpath_aspath_ignore_cmd); install_element (BGP_NODE, &no_bgp_bestpath_aspath_ignore_cmd); + /* "bgp log-neighbor-changes" commands */ + install_element (BGP_NODE, &bgp_log_neighbor_changes_cmd); + install_element (BGP_NODE, &no_bgp_log_neighbor_changes_cmd); + /* "bgp bestpath med" commands */ install_element (BGP_NODE, &bgp_bestpath_med_cmd); install_element (BGP_NODE, &bgp_bestpath_med2_cmd); diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c index f116a0cf..3a12a27c 100644 --- a/bgpd/bgpd.c +++ b/bgpd/bgpd.c @@ -752,6 +752,9 @@ peer_create (union sockunion *su, struct bgp *bgp, as_t local_as, /* Last read time set */ peer->readtime = time (NULL); + /* Last reset time set */ + peer->resettime = time (NULL); + /* Default TTL set. */ peer->ttl = (peer_sort (peer) == BGP_PEER_IBGP ? 255 : 1); @@ -797,6 +800,13 @@ peer_as_change (struct peer *peer, as_t as) type = peer_sort (peer); peer->as = as; + if (bgp_config_check (peer->bgp, BGP_CONFIG_CONFEDERATION) + && ! bgp_confederation_peers_check (peer->bgp, as) + && peer->bgp->as != as) + peer->local_as = peer->bgp->confed_id; + else + peer->local_as = peer->bgp->as; + /* Advertisement-interval reset */ if (peer_sort (peer) == BGP_PEER_IBGP) peer->v_routeadv = BGP_DEFAULT_IBGP_ROUTEADV; @@ -1634,6 +1644,15 @@ bgp_create (as_t *as, char *name) return bgp; } +/* Return master of BGP. */ +struct bgp_master * +bgp_get_master () +{ + if (bm) + return bm; + return NULL; +} + /* Return first entry of BGP. */ struct bgp * bgp_get_default () @@ -4415,6 +4434,10 @@ bgp_config_write (struct vty *vty) vty_out (vty, " bgp router-id %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE); + /* BGP log-neighbor-changes. */ + if (bgp_flag_check (bgp, BGP_FLAG_LOG_NEIGHBOR_CHANGES)) + vty_out (vty, " bgp log-neighbor-changes%s", VTY_NEWLINE); + /* BGP configuration. */ if (bgp_flag_check (bgp, BGP_FLAG_ALWAYS_COMPARE_MED)) vty_out (vty, " bgp always-compare-med%s", VTY_NEWLINE); diff --git a/bgpd/bgpd.h b/bgpd/bgpd.h index 11c6bdec..498bd072 100644 --- a/bgpd/bgpd.h +++ b/bgpd/bgpd.h @@ -96,6 +96,7 @@ struct bgp #define BGP_FLAG_ASPATH_IGNORE (1 << 8) #define BGP_FLAG_IMPORT_CHECK (1 << 9) #define BGP_FLAG_NO_FAST_EXT_FAILOVER (1 << 10) +#define BGP_FLAG_LOG_NEIGHBOR_CHANGES (1 << 11) /* BGP Per AF flags */ u_int16_t af_flags[AFI_MAX][SAFI_MAX]; @@ -263,6 +264,7 @@ struct peer union sockunion su; /* Sockunion address of the peer. */ time_t uptime; /* Last Up/Down time */ time_t readtime; /* Last read time */ + time_t resettime; /* Last reset time */ unsigned int ifindex; /* ifindex of the BGP connection. */ char *ifname; /* bind interface name. */ -- cgit v1.2.1