diff --git a/bgpd/bgp_snmp.c b/bgpd/bgp_snmp.c index e070483d4533..f2a8ae5659a6 100644 --- a/bgpd/bgp_snmp.c +++ b/bgpd/bgp_snmp.c @@ -48,12 +48,12 @@ DEFPY (bgp_snmp_traps_rfc4273, "Specify unusing rfc4273 traps\n") { - if (on){ + if (on) { SET_FLAG(bgp_snmp_traps_flags, BGP_SNMP_TRAPS_RFC4273_ENABLED); return CMD_SUCCESS; } - if (off){ + if (off) { UNSET_FLAG(bgp_snmp_traps_flags, BGP_SNMP_TRAPS_RFC4273_ENABLED); return CMD_SUCCESS; @@ -63,11 +63,41 @@ DEFPY (bgp_snmp_traps_rfc4273, return CMD_ERR_INCOMPLETE; } +DEFPY (bgp_snmp_traps_bgp4_mibv2, + bgp_snmp_traps_bgp4_mibv2_cmd, + "bgp snmp traps bgp4-mibv2", + BGP_STR + "Configure BGP SNMP\n" + "Configure SNMP traps for BGP \n" + "Configure use of bgp4-mibv2 SNMP traps for BGP \n" + "Specify using of bgp4-mibv2 traps\n" + "Specify unusing bgp4-mibv2 traps\n") +{ + + if (on) { + SET_FLAG(bgp_snmp_traps_flags, + BGP_SNMP_TRAPS_BGP4MIBV2_ENABLED); + return CMD_SUCCESS; + } + if (off) { + UNSET_FLAG(bgp_snmp_traps_flags, + BGP_SNMP_TRAPS_BGP4MIBV2_ENABLED); + return CMD_SUCCESS; + } + + vty_out(vty, "bgp traps configuration must be specified \n"); + return CMD_ERR_INCOMPLETE; +} + static void bgp_snmp_traps_init(void) { install_element(CONFIG_NODE, &bgp_snmp_traps_rfc4273_cmd); + install_element(CONFIG_NODE, &bgp_snmp_traps_bgp4_mibv2_cmd); + + SET_FLAG(bgp_snmp_traps_flags, + BGP_SNMP_TRAPS_RFC4273_ENABLED); SET_FLAG(bgp_snmp_traps_flags, - BGP_SNMP_TRAPS_RFC4273_ENABLED); + BGP_SNMP_TRAPS_BGP4MIBV2_ENABLED); } int bgp_cli_snmp_traps_config_write(struct vty *vty) @@ -75,11 +105,11 @@ int bgp_cli_snmp_traps_config_write(struct vty *vty) vty_out(vty, "!\n"); vty_out(vty, "traps rfc4273 %s\n", CHECK_FLAG(bgp_snmp_traps_flags, - BGP_SNMP_TRAPS_RFC4273_ENABLED)? + BGP_SNMP_TRAPS_RFC4273_ENABLED) ? "enabled":"disabled"); vty_out(vty, "traps bgp4-mibv2 %s\n", CHECK_FLAG(bgp_snmp_traps_flags, - BGP_SNMP_TRAPS_BGP4MIBV2_ENABLED)? + BGP_SNMP_TRAPS_BGP4MIBV2_ENABLED) ? "enabled":"disabled"); return 0; } @@ -87,9 +117,13 @@ int bgp_cli_snmp_traps_config_write(struct vty *vty) int bgpTrapEstablished(struct peer *peer) { + if (!CHECK_FLAG(bgp_snmp_traps_flags, + BGP_SNMP_TRAPS_RFC4273_ENABLED)) bgp4TrapEstablished(peer); + if (!CHECK_FLAG(bgp_snmp_traps_flags, + BGP_SNMP_TRAPS_BGP4MIBV2_ENABLED)) bgpv2TrapEstablished(peer); return 0; @@ -98,9 +132,13 @@ int bgpTrapEstablished(struct peer *peer) int bgpTrapBackwardTransition(struct peer *peer) { + if (!CHECK_FLAG(bgp_snmp_traps_flags, + BGP_SNMP_TRAPS_RFC4273_ENABLED)) bgp4TrapBackwardTransition(peer); + if (!CHECK_FLAG(bgp_snmp_traps_flags, + BGP_SNMP_TRAPS_BGP4MIBV2_ENABLED)) bgpv2TrapBackwardTransition(peer); return 0; diff --git a/bgpd/bgp_snmp.h b/bgpd/bgp_snmp.h index 7092a000f3bb..3deafd22f227 100644 --- a/bgpd/bgp_snmp.h +++ b/bgpd/bgp_snmp.h @@ -17,7 +17,8 @@ extern uint32_t bgp_snmp_traps_flags; -#define BGP_SNMP_TRAPS_RFC4273_ENABLED (1 << 0) +#define BGP_SNMP_TRAPS_RFC4273_ENABLED (1 << 0) +#define BGP_SNMP_TRAPS_BGP4MIBV2_ENABLED (1 << 1) extern int bgpTrapEstablished(struct peer *peer); extern int bgpTrapBackwardTransition(struct peer *peer); diff --git a/bgpd/bgp_snmp_bgp4.c b/bgpd/bgp_snmp_bgp4.c index f85389f1189c..94f211af797f 100644 --- a/bgpd/bgp_snmp_bgp4.c +++ b/bgpd/bgp_snmp_bgp4.c @@ -749,16 +749,12 @@ static struct variable bgp_variables[] = { {6, 1, 14}}, }; -int bgpTrapEstablished(struct peer *peer) +int bgp4TrapEstablished(struct peer *peer) { int ret; struct in_addr addr; oid index[sizeof(oid) * IN_ADDR_SIZE]; - if (!CHECK_FLAG(bgp_snmp_traps_flags, - BGP_SNMP_TRAPS_RFC4273_ENABLED)) - return 0; - /* Check if this peer just went to Established */ if ((peer->connection->ostatus != OpenConfirm) || !(peer_established(peer))) @@ -777,7 +773,7 @@ int bgpTrapEstablished(struct peer *peer) return 0; } -int bgpTrapBackwardTransition(struct peer *peer) +int bgp4TrapBackwardTransition(struct peer *peer) { int ret; struct in_addr addr; diff --git a/bgpd/bgp_snmp_bgp4v2.c b/bgpd/bgp_snmp_bgp4v2.c index 548b1397b432..eda00a204a5c 100644 --- a/bgpd/bgp_snmp_bgp4v2.c +++ b/bgpd/bgp_snmp_bgp4v2.c @@ -1469,6 +1469,10 @@ int bgpv2TrapBackwardTransition(struct peer *peer) oid index[sizeof(oid) * IN6_ADDR_SIZE]; size_t length; + if (!CHECK_FLAG(bgp_snmp_traps_flags, + BGP_SNMP_TRAPS_BGP4MIBV2_ENABLED)) + return 0; + switch (sockunion_family(&peer->su)) { case AF_INET: oid_copy_in_addr(index, &peer->su.sin.sin_addr);