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 <donatas.abraitis@gmail.com>
This commit is contained in:
Donatas Abraitis 2021-04-18 21:53:19 +03:00
parent 638fc64c64
commit 94effaf032
4 changed files with 80 additions and 10 deletions

View 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)

38
lib/route_opaque.h Normal file
View file

@ -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 */

View 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 \

View 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;
}