Skip to content

Commit d78854f

Browse files
bgpd: add snmp traps for bgp4-mibv2
This commit add the support of traps for bgp4-mibv2. It is conformant to draft-ietf-idr-bgp4-mibv2-11. The following traps are supported: - bgp4V2EstablishedNotification - bgp4V2BackwardTransitionNotification Signed-off-by: Francois Dumontet <[email protected]>
1 parent 83ca9a6 commit d78854f

File tree

6 files changed

+145
-7
lines changed

6 files changed

+145
-7
lines changed

bgpd/bgp_snmp.c

+25-3
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,31 @@ static void bgp_snmp_traps_init(void)
5959

6060
int bgp_cli_snmp_traps_config_write(struct vty *vty)
6161
{
62-
if (CHECK_FLAG(bgp_snmp_traps_flags, BGP_SNMP_TRAPS_RFC4273_ENABLED))
63-
return 0;
64-
vty_out(vty, "traps rfc4273 disable\n");
62+
int write = 0;
63+
64+
if (!CHECK_FLAG(bm->options, BGP_OPT_TRAPS_RFC4273)) {
65+
vty_out(vty, "no bgp snmp traps rfc4273\n");
66+
write++;
67+
}
68+
if (CHECK_FLAG(bm->options, BGP_OPT_TRAPS_BGP4MIBV2)) {
69+
vty_out(vty, "bgp snmp traps bgp4-mibv2\n");
70+
write++;
71+
}
72+
73+
return write;
74+
}
75+
76+
int bgpTrapEstablished(struct peer *peer)
77+
{
78+
bgp4TrapEstablished(peer);
79+
bgpv2TrapEstablished(peer);
80+
return 0;
81+
}
82+
83+
int bgpTrapBackwardTransition(struct peer *peer)
84+
{
85+
bgp4TrapBackwardTransition(peer);
86+
bgpv2TrapBackwardTransition(peer);
6587
return 0;
6688
}
6789

bgpd/bgp_snmp.h

+3
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,7 @@ extern uint32_t bgp_snmp_traps_flags;
1919

2020
#define BGP_SNMP_TRAPS_RFC4273_ENABLED (1 << 0)
2121

22+
extern int bgpTrapEstablished(struct peer *peer);
23+
extern int bgpTrapBackwardTransition(struct peer *peer);
24+
2225
#endif /* _FRR_BGP_SNMP_H_ */

bgpd/bgp_snmp_bgp4.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ static struct variable bgp_variables[] = {
757757
{6, 1, 14}},
758758
};
759759

760-
int bgpTrapEstablished(struct peer *peer)
760+
int bgp4TrapEstablished(struct peer *peer)
761761
{
762762
int ret;
763763
struct in_addr addr;
@@ -785,7 +785,7 @@ int bgpTrapEstablished(struct peer *peer)
785785
return 0;
786786
}
787787

788-
int bgpTrapBackwardTransition(struct peer *peer)
788+
int bgp4TrapBackwardTransition(struct peer *peer)
789789
{
790790
int ret;
791791
struct in_addr addr;

bgpd/bgp_snmp_bgp4.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@
6969
#define BGP4PATHATTRBEST 13
7070
#define BGP4PATHATTRUNKNOWN 14
7171

72-
extern int bgpTrapEstablished(struct peer *peer);
73-
extern int bgpTrapBackwardTransition(struct peer *peer);
72+
extern int bgp4TrapEstablished(struct peer *peer);
73+
extern int bgp4TrapBackwardTransition(struct peer *peer);
7474
extern int bgp_snmp_bgp4_init(struct event_loop *tm);
7575

7676
#endif /* _FRR_BGP_SNMP_BGP4_H_ */

bgpd/bgp_snmp_bgp4v2.c

+103
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
SNMP_LOCAL_VARIABLES
3333

3434
static oid bgpv2_oid[] = {BGP4V2MIB};
35+
static oid bgpv2_trap_oid[] = { BGP4V2MIB, 0 };
3536
static struct in_addr bgp_empty_addr = {};
3637

3738
static struct peer *peer_lookup_all_vrf(struct ipaddr *addr)
@@ -793,6 +794,38 @@ static uint8_t *bgp4v2PathAttrTable(struct variable *v, oid name[],
793794
return NULL;
794795
}
795796

797+
/* BGP V2 Traps. */
798+
static struct trap_object bgpv2TrapEstListv4[] = {
799+
{ 6, { 1, 2, 1, BGP4V2_PEER_STATE, 1, 1 } },
800+
{ 6, { 1, 2, 1, BGP4V2_PEER_LOCAL_PORT, 1, 1 } },
801+
{ 6, { 1, 2, 1, BGP4V2_PEER_REMOTE_PORT, 1, 1 } }
802+
};
803+
804+
static struct trap_object bgpv2TrapEstListv6[] = {
805+
{ 6, { 1, 2, 1, BGP4V2_PEER_STATE, 1, 2 } },
806+
{ 6, { 1, 2, 1, BGP4V2_PEER_LOCAL_PORT, 1, 2 } },
807+
{ 6, { 1, 2, 1, BGP4V2_PEER_REMOTE_PORT, 1, 2 } }
808+
};
809+
810+
static struct trap_object bgpv2TrapBackListv4[] = {
811+
{ 6, { 1, 2, 1, BGP4V2_PEER_STATE, 1, 1 } },
812+
{ 6, { 1, 2, 1, BGP4V2_PEER_LOCAL_PORT, 1, 1 } },
813+
{ 6, { 1, 2, 1, BGP4V2_PEER_REMOTE_PORT, 1, 1 } },
814+
{ 6, { 1, 3, 1, BGP4V2_PEER_LAST_ERROR_CODE_RECEIVED, 1, 1 } },
815+
{ 6, { 1, 3, 1, BGP4V2_PEER_LAST_ERROR_SUBCODE_RECEIVED, 1, 1 } },
816+
{ 6, { 1, 3, 1, BGP4V2_PEER_LAST_ERROR_RECEIVED_TEXT, 1, 1 } }
817+
};
818+
819+
static struct trap_object bgpv2TrapBackListv6[] = {
820+
{ 6, { 1, 2, 1, BGP4V2_PEER_STATE, 1, 2 } },
821+
{ 6, { 1, 2, 1, BGP4V2_PEER_LOCAL_PORT, 1, 2 } },
822+
{ 6, { 1, 2, 1, BGP4V2_PEER_REMOTE_PORT, 1, 2 } },
823+
{ 6, { 1, 3, 1, BGP4V2_PEER_LAST_ERROR_CODE_RECEIVED, 1, 2 } },
824+
{ 6, { 1, 3, 1, BGP4V2_PEER_LAST_ERROR_SUBCODE_RECEIVED, 1, 2 } },
825+
{ 6, { 1, 3, 1, BGP4V2_PEER_LAST_ERROR_RECEIVED_TEXT, 1, 2 } }
826+
};
827+
828+
796829
static struct variable bgpv2_variables[] = {
797830
/* bgp4V2PeerEntry */
798831
{BGP4V2_PEER_INSTANCE,
@@ -1412,6 +1445,76 @@ static struct variable bgpv2_variables[] = {
14121445
{1, 9, 1, BGP4V2_NLRI_PATH_ATTR_UNKNOWN, 1, 2}},
14131446
};
14141447

1448+
int bgpv2TrapEstablished(struct peer *peer)
1449+
{
1450+
oid index[sizeof(oid) * IN6_ADDR_SIZE];
1451+
size_t length;
1452+
1453+
/* Check if this peer just went to Established */
1454+
if ((peer->connection->ostatus != OpenConfirm) ||
1455+
!(peer_established(peer->connection)))
1456+
return 0;
1457+
1458+
switch (sockunion_family(&peer->connection->su)) {
1459+
case AF_INET:
1460+
oid_copy_in_addr(index, &peer->connection->su.sin.sin_addr);
1461+
length = IN_ADDR_SIZE;
1462+
smux_trap(bgpv2_variables, array_size(bgpv2_variables),
1463+
bgpv2_trap_oid, array_size(bgpv2_trap_oid), bgpv2_oid,
1464+
sizeof(bgpv2_oid) / sizeof(oid), index, length,
1465+
bgpv2TrapEstListv4, array_size(bgpv2TrapEstListv4),
1466+
BGP4V2ESTABLISHED);
1467+
break;
1468+
case AF_INET6:
1469+
oid_copy_in6_addr(index, &peer->connection->su.sin6.sin6_addr);
1470+
length = IN6_ADDR_SIZE;
1471+
smux_trap(bgpv2_variables, array_size(bgpv2_variables),
1472+
bgpv2_trap_oid, array_size(bgpv2_trap_oid), bgpv2_oid,
1473+
sizeof(bgpv2_oid) / sizeof(oid), index, length,
1474+
bgpv2TrapEstListv6, array_size(bgpv2TrapEstListv6),
1475+
BGP4V2ESTABLISHED);
1476+
break;
1477+
default:
1478+
return 0;
1479+
;
1480+
}
1481+
1482+
return 0;
1483+
}
1484+
1485+
int bgpv2TrapBackwardTransition(struct peer *peer)
1486+
{
1487+
oid index[sizeof(oid) * IN6_ADDR_SIZE];
1488+
size_t length;
1489+
1490+
switch (sockunion_family(&peer->connection->su)) {
1491+
case AF_INET:
1492+
oid_copy_in_addr(index, &peer->connection->su.sin.sin_addr);
1493+
length = IN_ADDR_SIZE;
1494+
smux_trap(bgpv2_variables, array_size(bgpv2_variables),
1495+
bgpv2_trap_oid, array_size(bgpv2_trap_oid), bgpv2_oid,
1496+
sizeof(bgpv2_oid) / sizeof(oid), index, length,
1497+
bgpv2TrapBackListv4, array_size(bgpv2TrapBackListv4),
1498+
BGP4V2BACKWARDTRANSITION);
1499+
break;
1500+
case AF_INET6:
1501+
oid_copy_in6_addr(index, &peer->connection->su.sin6.sin6_addr);
1502+
length = IN6_ADDR_SIZE;
1503+
smux_trap(bgpv2_variables, array_size(bgpv2_variables),
1504+
bgpv2_trap_oid, array_size(bgpv2_trap_oid), bgpv2_oid,
1505+
sizeof(bgpv2_oid) / sizeof(oid), index, length,
1506+
bgpv2TrapBackListv6, array_size(bgpv2TrapBackListv6),
1507+
BGP4V2BACKWARDTRANSITION);
1508+
break;
1509+
default:
1510+
return 0;
1511+
;
1512+
}
1513+
1514+
return 0;
1515+
}
1516+
1517+
14151518
int bgp_snmp_bgp4v2_init(struct event_loop *tm)
14161519
{
14171520
REGISTER_MIB("mibII/bgpv2", bgpv2_variables, variable, bgpv2_oid);

bgpd/bgp_snmp_bgp4v2.h

+10
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@
1616
* offset 1.3.6.1.3.5.1.1.2.1.x.(1|2).(4|16) = 13
1717
* offset 1.3.6.1.4.1.7336.3.2.1.1.2.1.x.1.(1|2) = 16
1818
*/
19+
20+
21+
/* bgpTraps */
22+
#define BGP4V2ESTABLISHED 1
23+
#define BGP4V2BACKWARDTRANSITION 2
24+
25+
/* bgpPeerTable */
26+
1927
#define BGP4V2_PEER_ENTRY_OFFSET 13
2028
#define BGP4V2_PEER_INSTANCE 1
2129
#define BGP4V2_PEER_LOCAL_ADDR_TYPE 2
@@ -84,5 +92,7 @@
8492
#define BGP4V2_BACKWARD_TRANSITION_NOTIFICATION 2
8593

8694
extern int bgp_snmp_bgp4v2_init(struct event_loop *tm);
95+
extern int bgpv2TrapEstablished(struct peer *peer);
96+
extern int bgpv2TrapBackwardTransition(struct peer *peer);
8797

8898
#endif /* _FRR_BGP_SNMP_BGP4V2_H_ */

0 commit comments

Comments
 (0)