]> git.puffer.fish Git - mirror/frr.git/commitdiff
bgpd, topotests: bmp, fix wrong peer distinguisher for vrf route events
authorPhilippe Guibert <philippe.guibert@6wind.com>
Thu, 31 Oct 2024 07:21:22 +0000 (08:21 +0100)
committerPhilippe Guibert <philippe.guibert@6wind.com>
Wed, 11 Dec 2024 10:29:37 +0000 (11:29 +0100)
When running the bgp_bmp_2 vrf test, peer route messages from the pre
and post policy are received with a wrong peer distinguisher value.

> {"peer_type": "route distinguisher instance", "policy": "pre-policy", "ipv6": false,
> "peer_ip": "192.168.0.2", "peer_distinguisher": "0:0", "peer_asn": 65502,
> "peer_bgp_id": "192.168.0.2", "timestamp": "2024-10-31 08:19:58.111963",
> "bmp_log_type": "update", "origin": "IGP", "as_path": "65501 65502",
> "bgp_nexthop": "192.168.0.2", "ip_prefix": "172.31.0.15/32", "seq": 15}

RFC7854 mentions in 4.2 that if the peer is a "RD Instance Peer", it is
set to the route distinguisher of the particular instance the peer
belongs to.

Fix this by modifying the BMP client:
- update the peer distinguisher value by unlocking the filling of the peer distinguisher in the function.
This change impacts monitoring messages.
- add the peer distinguisher computation for mirror messages
- modify the bgp_bmp_2 vrf test, update the peer_distinguisher value

> {"peer_type": "route distinguisher instance", "policy": "pre-policy", "ipv6": false,
> "peer_ip": "192.168.0.2", "peer_distinguisher": "444:1", "peer_asn": 65502,
> "peer_bgp_id": "192.168.0.2", "timestamp": "2024-10-31 08:19:58.111963",
> "bmp_log_type": "update", "origin": "IGP", "as_path": "65501 65502",
> "bgp_nexthop": "192.168.0.2", "ip_prefix": "172.31.0.15/32", "seq": 15}

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
bgpd/bgp_bmp.c
tests/topotests/bgp_bmp/bmp1vrf/bmp-update-post-policy-step1.json
tests/topotests/bgp_bmp/bmp1vrf/bmp-update-pre-policy-step1.json
tests/topotests/bgp_bmp/bmp1vrf/bmp-withdraw-post-policy-step1.json
tests/topotests/bgp_bmp/bmp1vrf/bmp-withdraw-pre-policy-step1.json

index 2b3c2193e717f55562ab7639fb884d695e4fd61c..65a99d75e7f41f492fdc79c3d059c602cbff11b9 100644 (file)
@@ -285,13 +285,6 @@ static inline int bmp_get_peer_distinguisher(struct bgp *bgp, afi_t afi, uint8_t
        if (peer_type == BMP_PEER_TYPE_LOCAL_INSTANCE || bgp->vrf_id == VRF_UNKNOWN)
                return 1;
 
-       /* remove this check when the other peer types get correct peer dist.
-        *(RFC7854) impl.
-        * for now, always return no error and 0 peer distinguisher as before
-        */
-       if (peer_type != BMP_PEER_TYPE_LOC_RIB_INSTANCE)
-               return (*result_ref = 0);
-
        /* vrf default => ok, distinguisher 0 */
        if (bgp->inst_type == VRF_DEFAULT)
                return (*result_ref = 0);
@@ -795,16 +788,23 @@ static void bmp_wrmirror_lost(struct bmp *bmp, struct pullwr *pullwr)
        struct stream *s;
        struct timeval tv;
        uint8_t peer_type_flag;
+       uint64_t peer_distinguisher = 0;
 
        gettimeofday(&tv, NULL);
 
        peer_type_flag = bmp_get_peer_type_vrf(bmp->targets->bgp->vrf_id);
 
+       if (bmp_get_peer_distinguisher(bmp->targets->bgp, AFI_UNSPEC, peer_type_flag,
+                                      &peer_distinguisher)) {
+               zlog_warn("skipping bmp message for reason: can't get peer distinguisher");
+               return;
+       }
+
        s = stream_new(BGP_MAX_PACKET_SIZE);
 
        bmp_common_hdr(s, BMP_VERSION_3, BMP_TYPE_ROUTE_MIRRORING);
-       bmp_per_peer_hdr(s, bmp->targets->bgp, bmp->targets->bgp->peer_self, 0, peer_type_flag, 0,
-                        &tv);
+       bmp_per_peer_hdr(s, bmp->targets->bgp, bmp->targets->bgp->peer_self, 0, peer_type_flag,
+                        peer_distinguisher, &tv);
 
        stream_putw(s, BMP_MIRROR_TLV_TYPE_INFO);
        stream_putw(s, 2);
@@ -822,6 +822,7 @@ static bool bmp_wrmirror(struct bmp *bmp, struct pullwr *pullwr)
        struct peer *peer;
        bool written = false;
        uint8_t peer_type_flag;
+       uint64_t peer_distinguisher = 0;
 
        if (bmp->mirror_lost) {
                bmp_wrmirror_lost(bmp, pullwr);
@@ -841,11 +842,18 @@ static bool bmp_wrmirror(struct bmp *bmp, struct pullwr *pullwr)
 
        peer_type_flag = bmp_get_peer_type_vrf(bmp->targets->bgp->vrf_id);
 
+       if (bmp_get_peer_distinguisher(peer->bgp, AFI_UNSPEC, peer_type_flag, &peer_distinguisher)) {
+               zlog_warn("skipping bmp message for peer %s: can't get peer distinguisher",
+                         peer->host);
+               goto out;
+       }
+
        struct stream *s;
        s = stream_new(BGP_MAX_PACKET_SIZE);
 
        bmp_common_hdr(s, BMP_VERSION_3, BMP_TYPE_ROUTE_MIRRORING);
-       bmp_per_peer_hdr(s, bmp->targets->bgp, peer, 0, peer_type_flag, 0, &bmq->tv);
+       bmp_per_peer_hdr(s, bmp->targets->bgp, peer, 0, peer_type_flag, peer_distinguisher,
+                        &bmq->tv);
 
        /* BMP Mirror TLV. */
        stream_putw(s, BMP_MIRROR_TLV_TYPE_BGP_MESSAGE);
index 18f40b16c7d8d95690299365b2e91ca84120e269..04e01623dfc07f3e14b0f2e57f13493bdc41bedc 100644 (file)
@@ -10,7 +10,7 @@
                 "origin": "IGP",
                 "peer_asn": 65502,
                 "peer_bgp_id": "192.168.0.2",
-                "peer_distinguisher": "0:0",
+                "peer_distinguisher": "444:1",
                 "peer_ip": "192.168.0.2",
                 "peer_type": "route distinguisher instance",
                 "policy": "post-policy"
@@ -25,7 +25,7 @@
                 "origin": "IGP",
                 "peer_asn": 65502,
                 "peer_bgp_id": "192.168.0.2",
-                "peer_distinguisher": "0:0",
+                "peer_distinguisher": "555:1",
                 "peer_ip": "192:168::2",
                 "peer_type": "route distinguisher instance",
                 "policy": "post-policy",
index 61ef0eab86acd04e28537da944f7b8bfa0b7a9b4..760ee0409ab412a844cea4b1ae98fe8bf7e1ea7e 100644 (file)
@@ -10,7 +10,7 @@
                 "origin": "IGP",
                 "peer_asn": 65502,
                 "peer_bgp_id": "192.168.0.2",
-                "peer_distinguisher": "0:0",
+                "peer_distinguisher": "444:1",
                 "peer_ip": "192.168.0.2",
                 "peer_type": "route distinguisher instance",
                 "policy": "pre-policy"
@@ -25,7 +25,7 @@
                 "origin": "IGP",
                 "peer_asn": 65502,
                 "peer_bgp_id": "192.168.0.2",
-                "peer_distinguisher": "0:0",
+                "peer_distinguisher": "555:1",
                 "peer_ip": "192:168::2",
                 "peer_type": "route distinguisher instance",
                 "policy": "pre-policy",
index c28ce851a2a43341d80ad15f04eea7e0330d19a4..f57b1a51cefba7f3360eb70baff22dc30e087c64 100644 (file)
@@ -7,7 +7,7 @@
                 "ipv6": false,
                 "peer_asn": 65502,
                 "peer_bgp_id": "192.168.0.2",
-                "peer_distinguisher": "0:0",
+                "peer_distinguisher": "444:1",
                 "peer_ip": "192.168.0.2",
                 "peer_type": "route distinguisher instance",
                 "policy": "post-policy"
@@ -19,7 +19,7 @@
                 "ipv6": true,
                 "peer_asn": 65502,
                 "peer_bgp_id": "192.168.0.2",
-                "peer_distinguisher": "0:0",
+                "peer_distinguisher": "555:1",
                 "peer_ip": "192:168::2",
                 "peer_type": "route distinguisher instance",
                 "policy": "post-policy",
index 976c7d47167e627c1c49cb07633dd5c4db007402..a52308c7892ebbc7a55a67af7fa1c71a5c486ee5 100644 (file)
@@ -7,7 +7,7 @@
                 "ipv6": false,
                 "peer_asn": 65502,
                 "peer_bgp_id": "192.168.0.2",
-                "peer_distinguisher": "0:0",
+                "peer_distinguisher": "444:1",
                 "peer_ip": "192.168.0.2",
                 "peer_type": "route distinguisher instance",
                 "policy": "pre-policy"
@@ -19,7 +19,7 @@
                 "ipv6": true,
                 "peer_asn": 65502,
                 "peer_bgp_id": "192.168.0.2",
-                "peer_distinguisher": "0:0",
+                "peer_distinguisher": "555:1",
                 "peer_ip": "192:168::2",
                 "peer_type": "route distinguisher instance",
                 "policy": "pre-policy",