Skip to content

Commit ef3e0d0

Browse files
sylanerwestphalGalaxyGorilla
committed
bgpd: Add support for SR-TE Policies in route-maps
Example configuration: route-map SET_SR_POLICY permit 10 set sr-te color 1 ! router bgp 1 bgp router-id 1.1.1.1 neighbor 2.2.2.2 remote-as 1 neighbor 2.2.2.2 update-source lo address-family ipv4 unicast neighbor 2.2.2.2 next-hop-self neighbor 2.2.2.2 route-map SET_SR_POLICY in exit-address-family ! ! Learned BGP routes from 2.2.2.2 are mapped to the SR-TE Policy which is uniquely determined by the BGP nexthop (2.2.2.2 in this case) and the SR-TE color in the route-map. Co-authored-by: Renato Westphal <[email protected]> Co-authored-by: GalaxyGorilla <[email protected]> Co-authored-by: Sebastien Merle <[email protected]> Signed-off-by: Sebastien Merle <[email protected]>
1 parent f663c58 commit ef3e0d0

File tree

6 files changed

+64
-1
lines changed

6 files changed

+64
-1
lines changed

bgpd/bgp_attr.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,8 @@ bool attrhash_cmp(const void *p1, const void *p2)
729729
&& attr1->nh_lla_ifindex == attr2->nh_lla_ifindex
730730
&& attr1->distance == attr2->distance
731731
&& srv6_l3vpn_same(attr1->srv6_l3vpn, attr2->srv6_l3vpn)
732-
&& srv6_vpn_same(attr1->srv6_vpn, attr2->srv6_vpn))
732+
&& srv6_vpn_same(attr1->srv6_vpn, attr2->srv6_vpn)
733+
&& attr1->srte_color == attr2->srte_color)
733734
return true;
734735
}
735736

bgpd/bgp_attr.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "mpls.h"
2525
#include "bgp_attr_evpn.h"
2626
#include "bgpd/bgp_encap_types.h"
27+
#include "srte.h"
2728

2829
/* Simple bit mapping. */
2930
#define BITMAP_NBBY 8
@@ -290,6 +291,9 @@ struct attr {
290291

291292
/* EVPN ES */
292293
esi_t esi;
294+
295+
/* SR-TE Color */
296+
uint32_t srte_color;
293297
};
294298

295299
/* rmap_change_flags definition */

bgpd/bgp_routemap.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1668,6 +1668,45 @@ static const struct route_map_rule_cmd route_match_tag_cmd = {
16681668
route_map_rule_tag_free,
16691669
};
16701670

1671+
static enum route_map_cmd_result_t
1672+
route_set_srte_color(void *rule, const struct prefix *prefix,
1673+
route_map_object_t type, void *object)
1674+
{
1675+
uint32_t *srte_color = rule;
1676+
struct bgp_path_info *path;
1677+
1678+
if (type != RMAP_BGP)
1679+
return RMAP_OKAY;
1680+
1681+
path = object;
1682+
1683+
path->attr->srte_color = *srte_color;
1684+
path->attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_SRTE_COLOR);
1685+
1686+
return RMAP_OKAY;
1687+
}
1688+
1689+
/* Route map `sr-te color' compile function */
1690+
static void *route_set_srte_color_compile(const char *arg)
1691+
{
1692+
uint32_t *color;
1693+
1694+
color = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(uint32_t));
1695+
*color = atoi(arg);
1696+
1697+
return color;
1698+
}
1699+
1700+
/* Free route map's compiled `sr-te color' value. */
1701+
static void route_set_srte_color_free(void *rule)
1702+
{
1703+
XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
1704+
}
1705+
1706+
/* Route map commands for sr-te color set. */
1707+
struct route_map_rule_cmd route_set_srte_color_cmd = {
1708+
"sr-te color", route_set_srte_color, route_set_srte_color_compile,
1709+
route_set_srte_color_free};
16711710

16721711
/* Set nexthop to object. ojbect must be pointer to struct attr. */
16731712
struct rmap_ip_nexthop_set {
@@ -5686,6 +5725,9 @@ void bgp_route_map_init(void)
56865725
route_map_match_tag_hook(generic_match_add);
56875726
route_map_no_match_tag_hook(generic_match_delete);
56885727

5728+
route_map_set_srte_color_hook(generic_set_add);
5729+
route_map_no_set_srte_color_hook(generic_set_delete);
5730+
56895731
route_map_set_ip_nexthop_hook(generic_set_add);
56905732
route_map_no_set_ip_nexthop_hook(generic_set_delete);
56915733

@@ -5728,6 +5770,7 @@ void bgp_route_map_init(void)
57285770
route_map_install_match(&route_match_vrl_source_vrf_cmd);
57295771

57305772
route_map_install_set(&route_set_table_id_cmd);
5773+
route_map_install_set(&route_set_srte_color_cmd);
57315774
route_map_install_set(&route_set_ip_nexthop_cmd);
57325775
route_map_install_set(&route_set_local_pref_cmd);
57335776
route_map_install_set(&route_set_weight_cmd);

bgpd/bgp_zebra.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,6 +1265,9 @@ void bgp_zebra_announce(struct bgp_dest *dest, const struct prefix *p,
12651265
api.tableid = info->attr->rmap_table_id;
12661266
}
12671267

1268+
if (CHECK_FLAG(info->attr->flag, ATTR_FLAG_BIT(BGP_ATTR_SRTE_COLOR)))
1269+
SET_FLAG(api.message, ZAPI_MESSAGE_SRTE);
1270+
12681271
/* Metric is currently based on the best-path only */
12691272
metric = info->attr->med;
12701273

@@ -1303,6 +1306,11 @@ void bgp_zebra_announce(struct bgp_dest *dest, const struct prefix *p,
13031306
continue;
13041307
}
13051308
api_nh = &api.nexthops[valid_nh_count];
1309+
1310+
if (CHECK_FLAG(info->attr->flag,
1311+
ATTR_FLAG_BIT(BGP_ATTR_SRTE_COLOR)))
1312+
api_nh->srte_color = info->attr->srte_color;
1313+
13061314
if (nh_family == AF_INET) {
13071315
if (bgp_debug_zebra(&api.prefix)) {
13081316
if (mpinfo->extra) {

bgpd/bgpd.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1538,6 +1538,7 @@ struct bgp_nlri {
15381538
#define BGP_ATTR_IPV6_EXT_COMMUNITIES 25
15391539
#define BGP_ATTR_LARGE_COMMUNITIES 32
15401540
#define BGP_ATTR_PREFIX_SID 40
1541+
#define BGP_ATTR_SRTE_COLOR 51
15411542
#ifdef ENABLE_BGP_VNC_ATTR
15421543
#define BGP_ATTR_VNC 255
15431544
#endif

doc/user/routemap.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,12 @@ Route Map Set Command
329329

330330
Set the BGP table to a given table identifier
331331

332+
.. index:: set sr-te color (1-4294967295)
333+
.. clicmd:: set sr-te color (1-4294967295)
334+
335+
Set the color of a SR-TE Policy to be applied to a learned route. The SR-TE
336+
Policy is uniquely determined by the color and the BGP nexthop.
337+
332338
.. _route-map-call-command:
333339

334340
Route Map Call Command

0 commit comments

Comments
 (0)