]> git.puffer.fish Git - matthieu/frr.git/commitdiff
bgpd: Send BGP best path reason to Zebra
authorDonatas Abraitis <donatas.abraitis@gmail.com>
Fri, 6 Aug 2021 16:54:57 +0000 (19:54 +0300)
committerDonatas Abraitis <donatas.abraitis@gmail.com>
Thu, 14 Oct 2021 13:52:47 +0000 (16:52 +0300)
```
exit1-debian-9# show ip route 172.16.16.1/32
Routing entry for 172.16.16.1/32
  Known via "bgp", distance 20, metric 0, best
  Last update 00:00:28 ago
  * 192.168.0.2, via eth1, weight 1
    AS-Path          : 65003
    Communities      : first 65001:2 65001:3
    Large-Communities: 65001:1:1 65001:1:2 65001:1:3
    Selection reason : First path received
```

Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
bgpd/bgp_route.c
bgpd/bgp_route.h
bgpd/bgp_zebra.c
lib/route_opaque.h
zebra/zebra_vty.c

index 0eb3cc61e3f425e65e5c304c7d9984c2adfbba21..f2a3e07aee3d11ed97b504b1f704f49ef2b114b1 100644 (file)
@@ -8415,8 +8415,7 @@ enum bgp_display_type {
        normal_list,
 };
 
-static const char *
-bgp_path_selection_reason2str(enum bgp_path_selection_reason reason)
+const char *bgp_path_selection_reason2str(enum bgp_path_selection_reason reason)
 {
        switch (reason) {
        case bgp_path_selection_none:
index 37bf675b674f2983e8cbee8376b06d6e8c9e78eb..46802d0d14d8cc97942447b5e7b50e21251c5c47 100644 (file)
@@ -90,6 +90,9 @@ enum bgp_show_adj_route_type {
 /* Maximum number of sids we can process or send with a prefix. */
 #define BGP_MAX_SIDS 6
 
+/* Maximum buffer length for storing BGP best path selection reason */
+#define BGP_MAX_SELECTION_REASON_STR_BUF 32
+
 /* Error codes for handling NLRI */
 #define BGP_NLRI_PARSE_OK 0
 #define BGP_NLRI_PARSE_ERROR_PREFIX_OVERFLOW -1
@@ -803,4 +806,6 @@ extern void bgp_aggregate_toggle_suppressed(struct bgp_aggregate *aggregate,
                                            const struct prefix *p, afi_t afi,
                                            safi_t safi, bool suppress);
 extern void subgroup_announce_reset_nhop(uint8_t family, struct attr *attr);
+const char *
+bgp_path_selection_reason2str(enum bgp_path_selection_reason reason);
 #endif /* _QUAGGA_BGP_ROUTE_H */
index 0249d53f02184c45dc690c535d2f2ecdb130a4a5..a11a350fdc469ac2de9779c71b47b4af11268cb0 100644 (file)
@@ -1489,6 +1489,8 @@ void bgp_zebra_announce(struct bgp_dest *dest, const struct prefix *p,
 
        if (is_add && CHECK_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA)) {
                struct bgp_zebra_opaque bzo = {};
+               const char *reason =
+                       bgp_path_selection_reason2str(dest->reason);
 
                strlcpy(bzo.aspath, info->attr->aspath->str,
                        sizeof(bzo.aspath));
@@ -1502,6 +1504,9 @@ void bgp_zebra_announce(struct bgp_dest *dest, const struct prefix *p,
                        strlcpy(bzo.lcommunity, info->attr->lcommunity->str,
                                sizeof(bzo.lcommunity));
 
+               strlcpy(bzo.selection_reason, reason,
+                       sizeof(bzo.selection_reason));
+
                SET_FLAG(api.message, ZAPI_MESSAGE_OPAQUE);
                api.opaque.length = MIN(sizeof(struct bgp_zebra_opaque),
                                        ZAPI_MESSAGE_OPAQUE_LENGTH);
index 7c4e9a16e1c238450ab4e9b243f6164dacb1e152..c5e7d6a327a8b8fade9244e4cc0aae65c8611f67 100644 (file)
@@ -36,6 +36,12 @@ struct bgp_zebra_opaque {
 
        /* Show at least 10 large-communities AA:BB:CC */
        char lcommunity[LCOMMUNITY_SIZE * 30];
+
+       /* 32 bytes seems enough because of
+        * bgp_path_selection_confed_as_path which is
+        * `Confederation based AS Path`.
+        */
+       char selection_reason[BGP_MAX_SELECTION_REASON_STR_BUF];
 };
 
 static_assert(sizeof(struct bgp_zebra_opaque) <= ZAPI_MESSAGE_OPAQUE_LENGTH,
index 06528d3dbe3b3a9ed39b7650d1ea1b24e62c8ba3..3d101011eb51ea17d241331ea518ee21db9f37e0 100644 (file)
@@ -449,6 +449,8 @@ static void zebra_show_ip_route_opaque(struct vty *vty, struct route_entry *re,
                                               bzo.community);
                        json_object_string_add(json, "largeCommunities",
                                               bzo.lcommunity);
+                       json_object_string_add(json, "selectionReason",
+                                              bzo.selection_reason);
                } else {
                        vty_out(vty, "    AS-Path          : %s\n", bzo.aspath);
 
@@ -459,6 +461,9 @@ static void zebra_show_ip_route_opaque(struct vty *vty, struct route_entry *re,
                        if (bzo.lcommunity[0] != '\0')
                                vty_out(vty, "    Large-Communities: %s\n",
                                        bzo.lcommunity);
+
+                       vty_out(vty, "    Selection reason : %s\n",
+                               bzo.selection_reason);
                }
        }
        default: