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 e3a7c87 commit 13668f0
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 26 deletions.
57 changes: 41 additions & 16 deletions bgpd/bgp_snmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#include "bgpd/bgp_mplsvpn_snmp.h"
#include "bgpd/bgp_snmp_clippy.c"


uint32_t bgp_snmp_traps_flags;

static int bgp_cli_snmp_traps_config_write(struct vty *vty);
Expand All @@ -42,65 +41,91 @@ DEFPY (bgp_snmp_traps_rfc4273,
"bgp snmp traps rfc4273<enable$on|disable$off>",
BGP_STR
"Configure BGP SNMP\n"
"Configure SNMP traps for BGP \n"
"Configure use of rfc4273 SNMP traps for BGP \n"
"Configure SNMP traps for BGP\n"
"Configure use of rfc4273 SNMP traps for BGP\n"
"Specify using of rfc4273 traps\n"
"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){
else {
UNSET_FLAG(bgp_snmp_traps_flags,
BGP_SNMP_TRAPS_RFC4273_ENABLED);
return CMD_SUCCESS;
}
}

vty_out(vty, "bgp traps configuration must be specified \n");
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 VGP4-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;
}
else {
UNSET_FLAG(bgp_snmp_traps_flags,
BGP_SNMP_TRAPS_BGP4MIBV2_ENABLED);
return CMD_SUCCESS;
}
}

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",
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;
}

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
7 changes: 4 additions & 3 deletions bgpd/bgp_snmp_bgp4v2.c
Original file line number Diff line number Diff line change
Expand Up @@ -1458,7 +1458,6 @@ int bgpv2TrapEstablished(struct peer *peer)
break;
default:
return 0;
;
}

return 0;
Expand All @@ -1469,6 +1468,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 All @@ -1490,13 +1493,11 @@ int bgpv2TrapBackwardTransition(struct peer *peer)
break;
default:
return 0;
;
}

return 0;
}


int bgp_snmp_bgp4v2_init(struct event_loop *tm)
{
REGISTER_MIB("mibII/bgpv2", bgpv2_variables, variable, bgpv2_oid);
Expand Down

0 comments on commit 13668f0

Please sign in to comment.