summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrancois Dumontet <francois.dumontet@6wind.com>2023-08-29 17:53:26 +0200
committerFrancois Dumontet <francois.dumontet@6wind.com>2023-10-24 17:16:47 +0200
commit83ca9a605eb51b675fa19247acf23e93c7abf590 (patch)
treeeec42debfe3bfbaa07481cbfb4c1eed41d4de4af
parentMerge pull request #14607 from mobash-rasool/fixes2 (diff)
downloadfrr-83ca9a605eb51b675fa19247acf23e93c7abf590.tar.xz
frr-83ca9a605eb51b675fa19247acf23e93c7abf590.zip
bgpd: add [no] bgp snmp traps rfc4273 command
There is no cli command to prevent the router to send traps implemented in the rfc4273. If not done, when introducing the traps from bgp4v2mib, traps will be send for each of the two mibs: there will be redundancy in the sent information. Add a new command: - [no] bgp snmp traps rfc4273 Using this command will allow or not the notification of the following traps: - bgpEstablishedNotification - bgpBackwardTransNotification Signed-off-by: Francois Dumontet <francois.dumontet@6wind.com>
-rw-r--r--bgpd/bgp_snmp.c38
-rw-r--r--bgpd/bgp_snmp.h4
-rw-r--r--bgpd/bgp_snmp_bgp4.c6
-rw-r--r--bgpd/bgp_vty.c3
-rw-r--r--bgpd/bgpd.h1
-rw-r--r--bgpd/subdir.am1
6 files changed, 53 insertions, 0 deletions
diff --git a/bgpd/bgp_snmp.c b/bgpd/bgp_snmp.c
index ce9442c1e..0d26b5c64 100644
--- a/bgpd/bgp_snmp.c
+++ b/bgpd/bgp_snmp.c
@@ -29,10 +29,46 @@
#include "bgpd/bgp_snmp_bgp4.h"
#include "bgpd/bgp_snmp_bgp4v2.h"
#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);
+
+DEFPY(bgp_snmp_traps_rfc4273, bgp_snmp_traps_rfc4273_cmd,
+ "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"
+ "Enable rfc4273 traps\n"
+ "Disable rfc4273 traps\n")
+{
+ if (on) {
+ SET_FLAG(bgp_snmp_traps_flags, BGP_SNMP_TRAPS_RFC4273_ENABLED);
+ return CMD_SUCCESS;
+ }
+ UNSET_FLAG(bgp_snmp_traps_flags, BGP_SNMP_TRAPS_RFC4273_ENABLED);
+ return CMD_SUCCESS;
+}
+
+static void bgp_snmp_traps_init(void)
+{
+ install_element(CONFIG_NODE, &bgp_snmp_traps_rfc4273_cmd);
+ SET_FLAG(bgp_snmp_traps_flags, BGP_SNMP_TRAPS_RFC4273_ENABLED);
+}
+
+int bgp_cli_snmp_traps_config_write(struct vty *vty)
+{
+ if (CHECK_FLAG(bgp_snmp_traps_flags, BGP_SNMP_TRAPS_RFC4273_ENABLED))
+ return 0;
+ vty_out(vty, "traps rfc4273 disable\n");
+ return 0;
+}
static int bgp_snmp_init(struct event_loop *tm)
{
smux_init(tm);
+ bgp_snmp_traps_init();
bgp_snmp_bgp4_init(tm);
bgp_snmp_bgp4v2_init(tm);
bgp_mpls_l3vpn_module_init();
@@ -44,6 +80,8 @@ static int bgp_snmp_module_init(void)
hook_register(peer_status_changed, bgpTrapEstablished);
hook_register(peer_backward_transition, bgpTrapBackwardTransition);
hook_register(frr_late_init, bgp_snmp_init);
+ hook_register(bgp_snmp_traps_config_write,
+ bgp_cli_snmp_traps_config_write);
return 0;
}
diff --git a/bgpd/bgp_snmp.h b/bgpd/bgp_snmp.h
index d324782ae..36ee4d616 100644
--- a/bgpd/bgp_snmp.h
+++ b/bgpd/bgp_snmp.h
@@ -15,4 +15,8 @@
#define IPADDRESS ASN_IPADDRESS
#define GAUGE32 ASN_UNSIGNED
+extern uint32_t bgp_snmp_traps_flags;
+
+#define BGP_SNMP_TRAPS_RFC4273_ENABLED (1 << 0)
+
#endif /* _FRR_BGP_SNMP_H_ */
diff --git a/bgpd/bgp_snmp_bgp4.c b/bgpd/bgp_snmp_bgp4.c
index 692e232a8..6da16057d 100644
--- a/bgpd/bgp_snmp_bgp4.c
+++ b/bgpd/bgp_snmp_bgp4.c
@@ -764,6 +764,9 @@ int bgpTrapEstablished(struct peer *peer)
oid index[sizeof(oid) * IN_ADDR_SIZE];
struct peer_connection *connection = peer->connection;
+ if (!CHECK_FLAG(bgp_snmp_traps_flags, BGP_SNMP_TRAPS_RFC4273_ENABLED))
+ return 0;
+
/* Check if this peer just went to Established */
if ((connection->ostatus != OpenConfirm) ||
!(peer_established(connection)))
@@ -788,6 +791,9 @@ int bgpTrapBackwardTransition(struct peer *peer)
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;
+
ret = inet_aton(peer->host, &addr);
if (ret == 0)
return 0;
diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c
index 8144d6e7b..49213bcfb 100644
--- a/bgpd/bgp_vty.c
+++ b/bgpd/bgp_vty.c
@@ -128,6 +128,7 @@ DEFINE_HOOK(bgp_inst_config_write,
(bgp, vty));
DEFINE_HOOK(bgp_snmp_update_last_changed, (struct bgp *bgp), (bgp));
DEFINE_HOOK(bgp_snmp_init_stats, (struct bgp *bgp), (bgp));
+DEFINE_HOOK(bgp_snmp_traps_config_write, (struct vty * vty), (vty));
static struct peer_group *listen_range_exists(struct bgp *bgp,
struct prefix *range, int exact);
@@ -18477,6 +18478,8 @@ int bgp_config_write(struct vty *vty)
safi_t safi;
uint32_t tovpn_sid_index = 0;
+ hook_call(bgp_snmp_traps_config_write, vty);
+
if (bm->rmap_update_timer != RMAP_DEFAULT_UPDATE_TIMER)
vty_out(vty, "bgp route-map delay-timer %u\n",
bm->rmap_update_timer);
diff --git a/bgpd/bgpd.h b/bgpd/bgpd.h
index bc2008b78..60d61918a 100644
--- a/bgpd/bgpd.h
+++ b/bgpd/bgpd.h
@@ -832,6 +832,7 @@ DECLARE_HOOK(bgp_inst_delete, (struct bgp *bgp), (bgp));
DECLARE_HOOK(bgp_inst_config_write,
(struct bgp *bgp, struct vty *vty),
(bgp, vty));
+DECLARE_HOOK(bgp_snmp_traps_config_write, (struct vty * vty), (vty));
DECLARE_HOOK(bgp_config_end, (struct bgp *bgp), (bgp));
/* Thread callback information */
diff --git a/bgpd/subdir.am b/bgpd/subdir.am
index c2dd207a4..7de6e7a9f 100644
--- a/bgpd/subdir.am
+++ b/bgpd/subdir.am
@@ -214,6 +214,7 @@ clippy_scan += \
bgpd/bgp_rpki.c \
bgpd/bgp_vty.c \
bgpd/bgp_nexthop.c \
+ bgpd/bgp_snmp.c \
# end
nodist_bgpd_bgpd_SOURCES = \