Skip to content

Commit

Permalink
bgpd: fix loc-rib open message should use router-id
Browse files Browse the repository at this point in the history
When forging BMP open message, the BGP router-id of tx open message of
the BMP LOC-RIB peer up message is always set to 0.0.0.0, whatever the
configured value of 'bgp router-id'.

Actually, when forging a peer up LOC-RIB message, the BGP router-id
value should be taken from the main BGP instance, and not from the peer
bgp identifier. Fix this by refreshing the router-id whenever a peer up
loc-rib message should be sent.

Signed-off-by: Philippe Guibert <[email protected]>
  • Loading branch information
pguibert6WIND committed Feb 10, 2025
1 parent a97be61 commit 4d11ff3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
18 changes: 14 additions & 4 deletions bgpd/bgp_bmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ static int bmp_route_update_bgpbmp(struct bmp_targets *bt, afi_t afi, safi_t saf
static void bmp_send_all_bgp(struct peer *peer, bool down);
static struct bmp_imported_bgp *bmp_imported_bgp_find(struct bmp_targets *bt, char *name);
static void bmp_stats_per_instance(struct bgp *bgp, struct bmp_targets *bt);
static void bmp_bgp_peer_vrf(struct bmp_bgp_peer *bbpeer, struct bgp *bgp);

DEFINE_MGROUP(BMP, "BMP (BGP Monitoring Protocol)");

Expand Down Expand Up @@ -551,9 +552,12 @@ static struct stream *bmp_peerstate(struct peer *peer, bool down)

bbpeer = bmp_bgp_peer_find(peer->qobj_node.nid);

if (bbpeer && bbpeer->open_tx)
if (bbpeer && bbpeer->open_tx) {
if (is_locrib)
/* update bgp id each time peer up LOC-RIB message is to be sent */
bmp_bgp_peer_vrf(bbpeer, peer->bgp);
stream_put(s, bbpeer->open_tx, bbpeer->open_tx_len);
else {
} else {
stream_put(s, dummy_open, sizeof(dummy_open));
zlog_warn("bmp: missing TX OPEN message for peer %s",
peer->host);
Expand Down Expand Up @@ -2209,6 +2213,8 @@ static void bmp_bgp_peer_vrf(struct bmp_bgp_peer *bbpeer, struct bgp *bgp)
struct peer *peer = bgp->peer_self;
uint16_t send_holdtime;
as_t local_as;
struct stream *s;
size_t open_len;

if (CHECK_FLAG(peer->flags, PEER_FLAG_TIMER))
send_holdtime = peer->holdtime;
Expand All @@ -2221,15 +2227,19 @@ static void bmp_bgp_peer_vrf(struct bmp_bgp_peer *bbpeer, struct bgp *bgp)
else
local_as = peer->local_as;

struct stream *s = bgp_open_make(peer, send_holdtime, local_as);
size_t open_len = stream_get_endp(s);
s = bgp_open_make(peer, send_holdtime, local_as, &peer->local_id);
open_len = stream_get_endp(s);

bbpeer->open_rx_len = open_len;
if (bbpeer->open_rx)
XFREE(MTYPE_BMP_OPEN, bbpeer->open_rx);
bbpeer->open_rx = XMALLOC(MTYPE_BMP_OPEN, open_len);
memcpy(bbpeer->open_rx, s->data, open_len);

stream_free(s);

s = bgp_open_make(peer, send_holdtime, local_as, &bgp->router_id);
open_len = stream_get_endp(s);
bbpeer->open_tx_len = open_len;
if (bbpeer->open_tx)
XFREE(MTYPE_BMP_OPEN, bbpeer->open_tx);
Expand Down
7 changes: 4 additions & 3 deletions bgpd/bgp_packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,8 @@ void bgp_keepalive_send(struct peer *peer)
bgp_writes_on(peer->connection);
}

struct stream *bgp_open_make(struct peer *peer, uint16_t send_holdtime, as_t local_as)
struct stream *bgp_open_make(struct peer *peer, uint16_t send_holdtime, as_t local_as,
struct in_addr *id)
{
struct stream *s = stream_new(BGP_STANDARD_MESSAGE_MAX_PACKET_SIZE);
bool ext_opt_params = false;
Expand All @@ -650,7 +651,7 @@ struct stream *bgp_open_make(struct peer *peer, uint16_t send_holdtime, as_t loc
stream_putw(s, (local_as <= BGP_AS_MAX) ? (uint16_t)local_as
: BGP_AS_TRANS);
stream_putw(s, send_holdtime); /* Hold Time */
stream_put_in_addr(s, &peer->local_id); /* BGP Identifier */
stream_put_in_addr(s, id); /* BGP Identifier */

/* Set capabilities */
if (CHECK_FLAG(peer->flags, PEER_FLAG_EXTENDED_OPT_PARAMS)) {
Expand Down Expand Up @@ -705,7 +706,7 @@ void bgp_open_send(struct peer_connection *connection)
else
local_as = peer->local_as;

s = bgp_open_make(peer, send_holdtime, local_as);
s = bgp_open_make(peer, send_holdtime, local_as, &peer->local_id);

/* Dump packet if debug option is set. */
/* bgp_packet_dump (s); */
Expand Down
3 changes: 2 additions & 1 deletion bgpd/bgp_packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ DECLARE_HOOK(bgp_packet_send,

/* Packet send and receive function prototypes. */
extern void bgp_keepalive_send(struct peer *peer);
extern struct stream *bgp_open_make(struct peer *peer, uint16_t send_holdtime, as_t local_as);
extern struct stream *bgp_open_make(struct peer *peer, uint16_t send_holdtime, as_t local_as,
struct in_addr *id);
extern void bgp_open_send(struct peer_connection *connection);
extern void bgp_notify_send(struct peer_connection *connection, uint8_t code,
uint8_t sub_code);
Expand Down

0 comments on commit 4d11ff3

Please sign in to comment.