From: Donatas Abraitis Date: Sun, 18 Apr 2021 18:53:19 +0000 (+0300) Subject: zebra: Send more OPAQUE data from BGP X-Git-Tag: base_8.1~503^2~1 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=94effaf032edc269f79b61fd8df04401d6e29ee2;p=matthieu%2Ffrr.git zebra: Send more OPAQUE data from BGP 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 --- diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c index 63214c5676..3af874fb82 100644 --- a/bgpd/bgp_zebra.c +++ b/bgpd/bgp_zebra.c @@ -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 index 0000000000..599a0363eb --- /dev/null +++ b/lib/route_opaque.h @@ -0,0 +1,38 @@ +/* Opaque data for Zebra from other daemons. + * + * Copyright (C) 2021 Donatas Abraitis + * + * 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 */ diff --git a/lib/subdir.am b/lib/subdir.am index 480c2938d0..4015c67ea8 100644 --- a/lib/subdir.am +++ b/lib/subdir.am @@ -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 \ diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index 9d7af3f6c7..861600596e 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -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; }