From 24f3d9ff1a8680df1e2c11c457bec6dca88b82c0 Mon Sep 17 00:00:00 2001 From: mxyns Date: Thu, 28 Jul 2022 18:23:14 +0200 Subject: [PATCH] bgpd: safer vrf/table name (RFC9069) info tlv vrf_id_to_name is used for display values only and returns "Unknown" when the vrf is not found doing a manual lookup and not providing any tlv when the vrf is not found should be better Signed-off-by: Maxence Younsi --- bgpd/bgp_bmp.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/bgpd/bgp_bmp.c b/bgpd/bgp_bmp.c index e75f08eaff..78528b080a 100644 --- a/bgpd/bgp_bmp.c +++ b/bgpd/bgp_bmp.c @@ -344,6 +344,19 @@ static void bmp_put_info_tlv(struct stream *s, uint16_t type, stream_put(s, string, len); } +static void bmp_put_vrftablename_info_tlv(struct stream *s, struct bmp *bmp) +{ + +#define BMP_INFO_TYPE_VRFTABLENAME 3 + char *vrftablename = "global"; + if (bmp->targets->bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT) { + struct vrf *vrf = vrf_lookup_by_id(bmp->targets->bgp->vrf_id); + vrftablename = vrf ? vrf->name : NULL; + } + if (vrftablename != NULL) + bmp_put_info_tlv(s, BMP_INFO_TYPE_VRFTABLENAME, vrftablename); +} + static int bmp_send_initiation(struct bmp *bmp) { int len;