]> git.puffer.fish Git - matthieu/frr.git/commitdiff
zebra: Send more OPAQUE data from BGP
authorDonatas Abraitis <donatas.abraitis@gmail.com>
Sun, 18 Apr 2021 18:53:19 +0000 (21:53 +0300)
committerDonatas Abraitis <donatas.abraitis@gmail.com>
Fri, 14 May 2021 19:12:33 +0000 (22:12 +0300)
This includes community and large-community data.

```
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:23 ago
  * 192.168.0.2, via eth1, weight 1
    AS-Path          : 65030
    Communities      : 65001:1 65001:2 65001:3 65001:4 65001:5 65001:6
    Large-Communities: 65001:123:1 65001:123:2
```

Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
bgpd/bgp_zebra.c
lib/route_opaque.h [new file with mode: 0644]
lib/subdir.am
zebra/zebra_vty.c

index 63214c5676f08b20aad3473e185ab7a690f72b3e..3af874fb82e85832c2278889f8f7ad165f939699 100644 (file)
@@ -33,6 +33,7 @@
 #include "memory.h"
 #include "lib/json.h"
 #include "lib/bfd.h"
+#include "lib/route_opaque.h"
 #include "filter.h"
 #include "mpls.h"
 #include "vxlan.h"
@@ -1400,11 +1401,24 @@ void bgp_zebra_announce(struct bgp_dest *dest, const struct prefix *p,
        is_add = (valid_nh_count || nhg_id) ? true : false;
 
        if (is_add && CHECK_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA)) {
-               struct aspath *aspath = info->attr->aspath;
+               struct bgp_zebra_opaque bzo = {};
+
+               strlcpy(bzo.aspath, info->attr->aspath->str,
+                       sizeof(bzo.aspath));
+
+               if (info->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES))
+                       strlcpy(bzo.community, info->attr->community->str,
+                               sizeof(bzo.community));
+
+               if (info->attr->flag
+                   & ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES))
+                       strlcpy(bzo.lcommunity, info->attr->lcommunity->str,
+                               sizeof(bzo.lcommunity));
 
                SET_FLAG(api.message, ZAPI_MESSAGE_OPAQUE);
-               api.opaque.length = strlen(aspath->str) + 1;
-               memcpy(api.opaque.data, aspath->str, api.opaque.length);
+               api.opaque.length = MIN(sizeof(struct bgp_zebra_opaque),
+                                       ZAPI_MESSAGE_OPAQUE_LENGTH);
+               memcpy(api.opaque.data, &bzo, api.opaque.length);
        }
 
        if (allow_recursion)
diff --git a/lib/route_opaque.h b/lib/route_opaque.h
new file mode 100644 (file)
index 0000000..599a036
--- /dev/null
@@ -0,0 +1,38 @@
+/* Opaque data for Zebra from other daemons.
+ *
+ * Copyright (C) 2021 Donatas Abraitis <donatas.abraitis@gmail.com>
+ *
+ * This file is part of FRRouting (FRR).
+ *
+ * FRR is free software; you can redistribute it and/or modify it under the
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation; either version 2, or (at your option) any later version.
+ *
+ * FRR is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; see the file COPYING; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef FRR_ROUTE_OPAQUE_H
+#define FRR_ROUTE_OPAQUE_H
+
+#include "bgpd/bgp_aspath.h"
+#include "bgpd/bgp_community.h"
+#include "bgpd/bgp_lcommunity.h"
+
+struct bgp_zebra_opaque {
+       char aspath[ASPATH_STR_DEFAULT_LEN];
+
+       /* Show at least 10 communities AA:BB */
+       char community[COMMUNITY_SIZE * 20];
+
+       /* Show at least 10 large-communities AA:BB:CC */
+       char lcommunity[LCOMMUNITY_SIZE * 30];
+};
+
+#endif /* FRR_ROUTE_OPAQUE_H */
index 480c2938d0d4a93b3668f2bd0a01e8dc43daec4f..4015c67ea8d6ac8d8812a475b6397ac8a9a63caa 100644 (file)
@@ -247,6 +247,7 @@ pkginclude_HEADERS += \
        lib/queue.h \
        lib/ringbuf.h \
        lib/routemap.h \
+       lib/route_opaque.h \
        lib/sbuf.h \
        lib/seqlock.h \
        lib/sha256.h \
index 9d7af3f6c73cc5e6cacb5b7400795e1ef73e221e..861600596ecb718bce3d2d38fed98b9ba59c5176 100644 (file)
@@ -42,6 +42,7 @@
 #include "zebra/redistribute.h"
 #include "zebra/zebra_routemap.h"
 #include "lib/json.h"
+#include "lib/route_opaque.h"
 #include "zebra/zebra_vxlan.h"
 #include "zebra/zebra_evpn_mh.h"
 #ifndef VTYSH_EXTRACT_PL
@@ -421,6 +422,8 @@ static void show_nexthop_detail_helper(struct vty *vty,
 static void zebra_show_ip_route_opaque(struct vty *vty, struct route_entry *re,
                                       struct json_object *json)
 {
+       struct bgp_zebra_opaque bzo = {};
+
        if (!re->opaque)
                return;
 
@@ -433,13 +436,27 @@ static void zebra_show_ip_route_opaque(struct vty *vty, struct route_entry *re,
                        vty_out(vty, "    Opaque Data: %s",
                                (char *)re->opaque->data);
                break;
-       case ZEBRA_ROUTE_BGP:
-               if (json)
-                       json_object_string_add(json, "asPath",
-                                              (char *)re->opaque->data);
-               else
-                       vty_out(vty, "    AS-Path: %s",
-                               (char *)re->opaque->data);
+       case ZEBRA_ROUTE_BGP: {
+               memcpy(&bzo, re->opaque->data, re->opaque->length);
+
+               if (json) {
+                       json_object_string_add(json, "asPath", bzo.aspath);
+                       json_object_string_add(json, "communities",
+                                              bzo.community);
+                       json_object_string_add(json, "largeCommunities",
+                                              bzo.lcommunity);
+               } else {
+                       vty_out(vty, "    AS-Path          : %s\n", bzo.aspath);
+
+                       if (bzo.community[0] != '\0')
+                               vty_out(vty, "    Communities      : %s\n",
+                                       bzo.community);
+
+                       if (bzo.lcommunity[0] != '\0')
+                               vty_out(vty, "    Large-Communities: %s\n",
+                                       bzo.lcommunity);
+               }
+       }
        default:
                break;
        }