Commit df37b03c5d for frr
commit df37b03c5da2fe1967466aa0cd9058deeebd9294
Author: Donald Sharp <sharpd@nvidia.com>
Date: Thu Sep 24 10:20:49 2026 -0400
bgpd: Convert some HOOKS to being connection oriented
These hooks are connection oriented, let's use them that way.
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
diff --git a/bgpd/bgp_bmp.c b/bgpd/bgp_bmp.c
index ebd2c19cc6..cda2dc4d4d 100644
--- a/bgpd/bgp_bmp.c
+++ b/bgpd/bgp_bmp.c
@@ -796,9 +796,10 @@ static void bmp_mirror_cull(struct bmp_bgp *bmpbgp)
}
}
-static int bmp_mirror_packet(struct peer *peer, uint8_t type, bgp_size_t size,
- struct stream *packet)
+static int bmp_mirror_packet(struct peer_connection *connection, uint8_t type, bgp_size_t size,
+ struct stream *packet)
{
+ struct peer *peer = connection->peer;
struct bmp_bgp *bmpbgp;
struct timeval tv;
struct bmp_targets *bt;
@@ -957,9 +958,11 @@ out:
return written;
}
-static int bmp_outgoing_packet(struct peer *peer, uint8_t type, bgp_size_t size,
- struct stream *packet)
+static int bmp_outgoing_packet(struct peer_connection *connection, uint8_t type, bgp_size_t size,
+ struct stream *packet)
{
+ struct peer *peer = connection->peer;
+
if (type == BGP_MSG_OPEN) {
frrtrace(2, frr_bgp, bmp_update_saved_open, peer, packet);
@@ -1090,13 +1093,14 @@ static void bmp_adj_in_release(struct bmp_targets *bt, afi_t afi, safi_t safi)
}
}
-static int bmp_peer_status_changed(struct peer *peer)
+static int bmp_peer_status_changed(struct peer_connection *connection)
{
+ struct peer *peer = connection->peer;
struct bmp_bgp_peer *bbpeer, *bbdopp;
frrtrace(1, frr_bgp, bmp_peer_status_changed, peer);
- if (peer->connection->status == Deleted) {
+ if (connection->status == Deleted) {
bbpeer = bmp_bgp_peer_find(peer->qobj_node.nid);
if (bbpeer) {
XFREE(MTYPE_BMP_OPEN, bbpeer->open_rx);
@@ -1108,8 +1112,7 @@ static int bmp_peer_status_changed(struct peer *peer)
}
/* Check if this peer just went to Established */
- if ((peer->connection->ostatus != OpenConfirm) ||
- !(peer_established(peer->connection)))
+ if ((connection->ostatus != OpenConfirm) || !(peer_established(connection)))
return 0;
if (peer->doppelganger &&
diff --git a/bgpd/bgp_dump.c b/bgpd/bgp_dump.c
index 899a18d745..9098a9396b 100644
--- a/bgpd/bgp_dump.c
+++ b/bgpd/bgp_dump.c
@@ -519,8 +519,9 @@ static void bgp_dump_common(struct stream *obuf, struct peer *peer,
}
/* Dump BGP status change. */
-int bgp_dump_state(struct peer *peer)
+int bgp_dump_state(struct peer_connection *connection)
{
+ struct peer *peer = connection->peer;
struct stream *obuf;
/* If dump file pointer is disabled return immediately. */
@@ -535,8 +536,8 @@ int bgp_dump_state(struct peer *peer)
bgp_dump_all.type);
bgp_dump_common(obuf, peer, 1); /* force this in as4speak*/
- stream_putw(obuf, peer->connection->ostatus);
- stream_putw(obuf, peer->connection->status);
+ stream_putw(obuf, connection->ostatus);
+ stream_putw(obuf, connection->status);
/* Set length. */
bgp_dump_set_size(obuf, MSG_PROTOCOL_BGP4MP);
@@ -595,9 +596,11 @@ static void bgp_dump_packet_func(struct bgp_dump *bgp_dump, struct peer *peer,
}
/* Called from bgp_packet.c when BGP packet is received. */
-static int bgp_dump_packet(struct peer *peer, uint8_t type, bgp_size_t size,
- struct stream *packet)
+static int bgp_dump_packet(struct peer_connection *connection, uint8_t type, bgp_size_t size,
+ struct stream *packet)
{
+ struct peer *peer = connection->peer;
+
/* bgp_dump_all. */
bgp_dump_packet_func(&bgp_dump_all, peer, packet);
diff --git a/bgpd/bgp_dump.h b/bgpd/bgp_dump.h
index 2235bbc52f..2427a6aa2b 100644
--- a/bgpd/bgp_dump.h
+++ b/bgpd/bgp_dump.h
@@ -44,6 +44,6 @@
extern void bgp_dump_init(void);
extern void bgp_dump_finish(void);
-extern int bgp_dump_state(struct peer *peer);
+extern int bgp_dump_state(struct peer_connection *connection);
#endif /* _QUAGGA_BGP_DUMP_H */
diff --git a/bgpd/bgp_fsm.c b/bgpd/bgp_fsm.c
index 6efd183599..36f11a0019 100644
--- a/bgpd/bgp_fsm.c
+++ b/bgpd/bgp_fsm.c
@@ -46,7 +46,7 @@
#include "bgpd/bgp_ls.h"
DEFINE_HOOK(peer_backward_transition, (struct peer * peer), (peer));
-DEFINE_HOOK(peer_status_changed, (struct peer * peer), (peer));
+DEFINE_HOOK(peer_status_changed, (struct peer_connection * connection), (connection));
DEFINE_HOOK(bgp_rpki_connection_status, (const char *vrf_name), (vrf_name));
bool bgp_rpki_cache_connected(struct bgp *bgp)
@@ -2107,7 +2107,7 @@ void bgp_fsm_change_status(struct peer_connection *connection,
connection->dir = ESTABLISHED;
/* Operations after status change */
- hook_call(peer_status_changed, peer);
+ hook_call(peer_status_changed, connection);
/* If max-med processing is applicable, do the necessary. */
if (status == Established) {
diff --git a/bgpd/bgp_packet.c b/bgpd/bgp_packet.c
index abf0f08f1c..3769d2aabd 100644
--- a/bgpd/bgp_packet.c
+++ b/bgpd/bgp_packet.c
@@ -54,14 +54,12 @@
#include "bgpd/bgp_ls.h"
DEFINE_HOOK(bgp_packet_dump,
- (struct peer *peer, uint8_t type, bgp_size_t size,
- struct stream *s),
- (peer, type, size, s));
+ (struct peer_connection *connection, uint8_t type, bgp_size_t size, struct stream *s),
+ (connection, type, size, s));
DEFINE_HOOK(bgp_packet_send,
- (struct peer *peer, uint8_t type, bgp_size_t size,
- struct stream *s),
- (peer, type, size, s));
+ (struct peer_connection *connection, uint8_t type, bgp_size_t size, struct stream *s),
+ (connection, type, size, s));
/**
* Sets marker and type fields for a BGP message.
@@ -724,7 +722,7 @@ void bgp_open_send(struct peer_connection *connection)
/* Dump packet if debug option is set. */
/* bgp_packet_dump (s); */
- hook_call(bgp_packet_send, peer, BGP_MSG_OPEN, stream_get_endp(s), s);
+ hook_call(bgp_packet_send, connection, BGP_MSG_OPEN, stream_get_endp(s), s);
/* Add packet to the peer. */
bgp_packet_add(connection, s);
@@ -4193,7 +4191,7 @@ void bgp_process_packet(struct event *event)
size = stream_getw(connection->curr);
type = stream_getc(connection->curr);
- hook_call(bgp_packet_dump, peer, type, size, connection->curr);
+ hook_call(bgp_packet_dump, connection, type, size, connection->curr);
/* adjust size to exclude the marker + length + type */
size -= BGP_HEADER_SIZE;
diff --git a/bgpd/bgp_packet.h b/bgpd/bgp_packet.h
index f6633ccec6..0d3d3311cb 100644
--- a/bgpd/bgp_packet.h
+++ b/bgpd/bgp_packet.h
@@ -15,14 +15,12 @@ struct bgp_enhe_capability {
};
DECLARE_HOOK(bgp_packet_dump,
- (struct peer *peer, uint8_t type, bgp_size_t size,
- struct stream *s),
- (peer, type, size, s));
+ (struct peer_connection *connection, uint8_t type, bgp_size_t size, struct stream *s),
+ (connection, type, size, s));
DECLARE_HOOK(bgp_packet_send,
- (struct peer *peer, uint8_t type, bgp_size_t size,
- struct stream *s),
- (peer, type, size, s));
+ (struct peer_connection *connection, uint8_t type, bgp_size_t size, struct stream *s),
+ (connection, type, size, s));
#define BGP_NLRI_LENGTH 1U
#define BGP_TOTAL_ATTR_LEN 2U
diff --git a/bgpd/bgp_snmp.c b/bgpd/bgp_snmp.c
index 03b5798770..bf576e8abd 100644
--- a/bgpd/bgp_snmp.c
+++ b/bgpd/bgp_snmp.c
@@ -112,8 +112,10 @@ int bgp_cli_snmp_traps_config_write(struct vty *vty)
return write;
}
-int bgpTrapEstablished(struct peer *peer)
+int bgpTrapEstablished(struct peer_connection *connection)
{
+ struct peer *peer = connection->peer;
+
if (CHECK_FLAG(bm->options, BGP_OPT_TRAPS_RFC4273))
bgp4TrapEstablished(peer);
diff --git a/bgpd/bgp_snmp.h b/bgpd/bgp_snmp.h
index 12ec652f8d..2dfbc68e72 100644
--- a/bgpd/bgp_snmp.h
+++ b/bgpd/bgp_snmp.h
@@ -15,7 +15,7 @@
#define IPADDRESS ASN_IPADDRESS
#define GAUGE32 ASN_UNSIGNED
-extern int bgpTrapEstablished(struct peer *peer);
+extern int bgpTrapEstablished(struct peer_connection *connection);
extern int bgpTrapBackwardTransition(struct peer *peer);
#endif /* _FRR_BGP_SNMP_H_ */
diff --git a/bgpd/bgpd.h b/bgpd/bgpd.h
index 3e9b8ae501..7513c49e1b 100644
--- a/bgpd/bgpd.h
+++ b/bgpd/bgpd.h
@@ -3408,7 +3408,7 @@ extern int bgp_lookup_by_as_name_type(struct bgp **bgp_val, as_t *as, const char
/* Hooks */
DECLARE_HOOK(bgp_vrf_status_changed, (struct bgp *bgp, struct interface *ifp),
(bgp, ifp));
-DECLARE_HOOK(peer_status_changed, (struct peer *peer), (peer));
+DECLARE_HOOK(peer_status_changed, (struct peer_connection *connection), (connection));
DECLARE_HOOK(bgp_snmp_init_stats, (struct bgp *bgp), (bgp));
DECLARE_HOOK(bgp_snmp_update_last_changed, (struct bgp *bgp), (bgp));
DECLARE_HOOK(bgp_snmp_update_stats,