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>
#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"
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)
--- /dev/null
+/* 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 */
lib/queue.h \
lib/ringbuf.h \
lib/routemap.h \
+ lib/route_opaque.h \
lib/sbuf.h \
lib/seqlock.h \
lib/sha256.h \
#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
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;
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;
}