Skip to content

Commit

Permalink
bgpd: add support of bgp snmp traps bgp4-mibv2<enable|disable> command
Browse files Browse the repository at this point in the history
since the MIB bgp4-mibv2 notification are  redundant with MIB RFC4273
we added a command
"bgp snmp traps bgp4-mibv2<enable|disable>" for allowing or not
the diffusion of notifications.

Signed-off-by: Francois Dumontet <[email protected]>
  • Loading branch information
fdumontet6WIND committed Sep 4, 2023
1 parent a0ff1e5 commit 9b0ed1c
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 12 deletions.
48 changes: 43 additions & 5 deletions bgpd/bgp_snmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -63,33 +63,67 @@ 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<enable$on|disable$off>",
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)
{
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;
}

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;
Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion bgpd/bgp_snmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 2 additions & 6 deletions bgpd/bgp_snmp_bgp4.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand All @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions bgpd/bgp_snmp_bgp4v2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 9b0ed1c

Please sign in to comment.