summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bgpd/bgp_attr.c3
-rw-r--r--bgpd/bgp_attr.h4
-rw-r--r--bgpd/bgp_routemap.c43
-rw-r--r--bgpd/bgp_zebra.c8
-rw-r--r--bgpd/bgpd.h1
-rw-r--r--doc/user/routemap.rst6
6 files changed, 64 insertions, 1 deletions
diff --git a/bgpd/bgp_attr.c b/bgpd/bgp_attr.c
index cac3ab1ca7..d8eaabfdf8 100644
--- a/bgpd/bgp_attr.c
+++ b/bgpd/bgp_attr.c
@@ -729,7 +729,8 @@ bool attrhash_cmp(const void *p1, const void *p2)
&& attr1->nh_lla_ifindex == attr2->nh_lla_ifindex
&& attr1->distance == attr2->distance
&& srv6_l3vpn_same(attr1->srv6_l3vpn, attr2->srv6_l3vpn)
- && srv6_vpn_same(attr1->srv6_vpn, attr2->srv6_vpn))
+ && srv6_vpn_same(attr1->srv6_vpn, attr2->srv6_vpn)
+ && attr1->srte_color == attr2->srte_color)
return true;
}
diff --git a/bgpd/bgp_attr.h b/bgpd/bgp_attr.h
index c57cf81007..e6e953364b 100644
--- a/bgpd/bgp_attr.h
+++ b/bgpd/bgp_attr.h
@@ -24,6 +24,7 @@
#include "mpls.h"
#include "bgp_attr_evpn.h"
#include "bgpd/bgp_encap_types.h"
+#include "srte.h"
/* Simple bit mapping. */
#define BITMAP_NBBY 8
@@ -290,6 +291,9 @@ struct attr {
/* EVPN ES */
esi_t esi;
+
+ /* SR-TE Color */
+ uint32_t srte_color;
};
/* rmap_change_flags definition */
diff --git a/bgpd/bgp_routemap.c b/bgpd/bgp_routemap.c
index 6d81cfaab4..09cc775d47 100644
--- a/bgpd/bgp_routemap.c
+++ b/bgpd/bgp_routemap.c
@@ -1668,6 +1668,45 @@ static const struct route_map_rule_cmd route_match_tag_cmd = {
route_map_rule_tag_free,
};
+static enum route_map_cmd_result_t
+route_set_srte_color(void *rule, const struct prefix *prefix,
+ route_map_object_t type, void *object)
+{
+ uint32_t *srte_color = rule;
+ struct bgp_path_info *path;
+
+ if (type != RMAP_BGP)
+ return RMAP_OKAY;
+
+ path = object;
+
+ path->attr->srte_color = *srte_color;
+ path->attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_SRTE_COLOR);
+
+ return RMAP_OKAY;
+}
+
+/* Route map `sr-te color' compile function */
+static void *route_set_srte_color_compile(const char *arg)
+{
+ uint32_t *color;
+
+ color = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(uint32_t));
+ *color = atoi(arg);
+
+ return color;
+}
+
+/* Free route map's compiled `sr-te color' value. */
+static void route_set_srte_color_free(void *rule)
+{
+ XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
+}
+
+/* Route map commands for sr-te color set. */
+struct route_map_rule_cmd route_set_srte_color_cmd = {
+ "sr-te color", route_set_srte_color, route_set_srte_color_compile,
+ route_set_srte_color_free};
/* Set nexthop to object. ojbect must be pointer to struct attr. */
struct rmap_ip_nexthop_set {
@@ -5686,6 +5725,9 @@ void bgp_route_map_init(void)
route_map_match_tag_hook(generic_match_add);
route_map_no_match_tag_hook(generic_match_delete);
+ route_map_set_srte_color_hook(generic_set_add);
+ route_map_no_set_srte_color_hook(generic_set_delete);
+
route_map_set_ip_nexthop_hook(generic_set_add);
route_map_no_set_ip_nexthop_hook(generic_set_delete);
@@ -5728,6 +5770,7 @@ void bgp_route_map_init(void)
route_map_install_match(&route_match_vrl_source_vrf_cmd);
route_map_install_set(&route_set_table_id_cmd);
+ route_map_install_set(&route_set_srte_color_cmd);
route_map_install_set(&route_set_ip_nexthop_cmd);
route_map_install_set(&route_set_local_pref_cmd);
route_map_install_set(&route_set_weight_cmd);
diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c
index dba114f86a..15bd6d33b8 100644
--- a/bgpd/bgp_zebra.c
+++ b/bgpd/bgp_zebra.c
@@ -1265,6 +1265,9 @@ void bgp_zebra_announce(struct bgp_dest *dest, const struct prefix *p,
api.tableid = info->attr->rmap_table_id;
}
+ if (CHECK_FLAG(info->attr->flag, ATTR_FLAG_BIT(BGP_ATTR_SRTE_COLOR)))
+ SET_FLAG(api.message, ZAPI_MESSAGE_SRTE);
+
/* Metric is currently based on the best-path only */
metric = info->attr->med;
@@ -1303,6 +1306,11 @@ void bgp_zebra_announce(struct bgp_dest *dest, const struct prefix *p,
continue;
}
api_nh = &api.nexthops[valid_nh_count];
+
+ if (CHECK_FLAG(info->attr->flag,
+ ATTR_FLAG_BIT(BGP_ATTR_SRTE_COLOR)))
+ api_nh->srte_color = info->attr->srte_color;
+
if (nh_family == AF_INET) {
if (bgp_debug_zebra(&api.prefix)) {
if (mpinfo->extra) {
diff --git a/bgpd/bgpd.h b/bgpd/bgpd.h
index 20a41987ca..6145d9305f 100644
--- a/bgpd/bgpd.h
+++ b/bgpd/bgpd.h
@@ -1538,6 +1538,7 @@ struct bgp_nlri {
#define BGP_ATTR_IPV6_EXT_COMMUNITIES 25
#define BGP_ATTR_LARGE_COMMUNITIES 32
#define BGP_ATTR_PREFIX_SID 40
+#define BGP_ATTR_SRTE_COLOR 51
#ifdef ENABLE_BGP_VNC_ATTR
#define BGP_ATTR_VNC 255
#endif
diff --git a/doc/user/routemap.rst b/doc/user/routemap.rst
index f557cbe022..fa5fc248a8 100644
--- a/doc/user/routemap.rst
+++ b/doc/user/routemap.rst
@@ -329,6 +329,12 @@ Route Map Set Command
Set the BGP table to a given table identifier
+.. index:: set sr-te color (1-4294967295)
+.. clicmd:: set sr-te color (1-4294967295)
+
+ Set the color of a SR-TE Policy to be applied to a learned route. The SR-TE
+ Policy is uniquely determined by the color and the BGP nexthop.
+
.. _route-map-call-command:
Route Map Call Command