]> git.puffer.fish Git - mirror/frr.git/commitdiff
bgpd: add [no] bgp snmp traps rfc4273 command
authorFrancois Dumontet <francois.dumontet@6wind.com>
Tue, 29 Aug 2023 15:53:26 +0000 (17:53 +0200)
committerFrancois Dumontet <francois.dumontet@6wind.com>
Tue, 24 Oct 2023 15:16:47 +0000 (17:16 +0200)
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>
bgpd/bgp_snmp.c
bgpd/bgp_snmp.h
bgpd/bgp_snmp_bgp4.c
bgpd/bgp_vty.c
bgpd/bgpd.h
bgpd/subdir.am

index ce9442c1e0205f717f43761de979d04544caf001..0d26b5c64ceb8c06323958dcb417b5800e60aded 100644 (file)
 #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;
 }
 
index d324782ae33bb713b37b38b61deea36000967410..36ee4d6162afc29613f71957cbcfea73270b7c12 100644 (file)
@@ -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_ */
index 692e232a83c2f6891f84d2e46e078223e16e9297..6da16057d1a24c6b40872b2ca280e1ef98e524e0 100644 (file)
@@ -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;
index 8144d6e7b3bc2b3fda85ad9ce8db64b0528086c2..49213bcfb7c4d8ac515f8e5740960a1e12bf6131 100644 (file)
@@ -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);
index bc2008b78ba279410d55d1ebc03ab64392b1f7a8..60d61918a30cc4fb880307e66bdc6c84852e999f 100644 (file)
@@ -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 */
index c2dd207a49d19471a59fbc3b55366075306e1b3b..7de6e7a9f1a1c0968763d80a20200c3c481015cb 100644 (file)
@@ -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 = \