From a5e3a60985b7a6e6d6f4b717adc23854a59176e9 Mon Sep 17 00:00:00 2001 From: Carmine Scarpitta Date: Fri, 21 Feb 2025 13:21:36 +0100 Subject: [PATCH] lib,sharpd,zebra: Extend nexthop_add_srv6_seg6 to encode encap behavior Previous commits introduced the `encap_behavior` field in the SRv6 nexthop data structure and updated the compare, hash, and copy functions to handle this new field. This commit extends the `nexthop_add_srv6_seg6` function by adding a new parameter `encap_behavior` and modify the code in various places to pass the encap behavior when calling this function. Signed-off-by: Carmine Scarpitta --- lib/nexthop.c | 13 +++++++------ lib/nexthop.h | 4 ++-- lib/zclient.c | 2 +- sharpd/sharp_vty.c | 4 ++-- zebra/rt_netlink.c | 4 ++-- zebra/zapi_msg.c | 4 ++-- zebra/zebra_nhg.c | 7 +++---- 7 files changed, 19 insertions(+), 19 deletions(-) diff --git a/lib/nexthop.c b/lib/nexthop.c index 7850827f4a..7526dd86f6 100644 --- a/lib/nexthop.c +++ b/lib/nexthop.c @@ -646,8 +646,8 @@ void nexthop_del_srv6_seg6local(struct nexthop *nexthop) XFREE(MTYPE_NH_SRV6, nexthop->nh_srv6); } -void nexthop_add_srv6_seg6(struct nexthop *nexthop, const struct in6_addr *segs, - int num_segs) +void nexthop_add_srv6_seg6(struct nexthop *nexthop, const struct in6_addr *segs, int num_segs, + enum srv6_headend_behavior encap_behavior) { int i; @@ -674,6 +674,8 @@ void nexthop_add_srv6_seg6(struct nexthop *nexthop, const struct in6_addr *segs, for (i = 0; i < num_segs; i++) memcpy(&nexthop->nh_srv6->seg6_segs->seg[i], &segs[i], sizeof(struct in6_addr)); + + nexthop->nh_srv6->seg6_segs->encap_behavior = encap_behavior; } void nexthop_del_srv6_seg6(struct nexthop *nexthop) @@ -872,10 +874,9 @@ void nexthop_copy_no_recurse(struct nexthop *copy, if (nexthop->nh_srv6->seg6_segs && nexthop->nh_srv6->seg6_segs->num_segs && !sid_zero(nexthop->nh_srv6->seg6_segs)) - nexthop_add_srv6_seg6(copy, - &nexthop->nh_srv6->seg6_segs->seg[0], - nexthop->nh_srv6->seg6_segs - ->num_segs); + nexthop_add_srv6_seg6(copy, &nexthop->nh_srv6->seg6_segs->seg[0], + nexthop->nh_srv6->seg6_segs->num_segs, + nexthop->nh_srv6->seg6_segs->encap_behavior); } } diff --git a/lib/nexthop.h b/lib/nexthop.h index cea7c77e3e..dba5162752 100644 --- a/lib/nexthop.h +++ b/lib/nexthop.h @@ -207,8 +207,8 @@ void nexthop_change_labels(struct nexthop *nexthop, struct mpls_label_stack *new void nexthop_add_srv6_seg6local(struct nexthop *nexthop, uint32_t action, const struct seg6local_context *ctx); void nexthop_del_srv6_seg6local(struct nexthop *nexthop); -void nexthop_add_srv6_seg6(struct nexthop *nexthop, const struct in6_addr *seg, - int num_segs); +void nexthop_add_srv6_seg6(struct nexthop *nexthop, const struct in6_addr *seg, int num_segs, + enum srv6_headend_behavior encap_behavior); void nexthop_del_srv6_seg6(struct nexthop *nexthop); /* diff --git a/lib/zclient.c b/lib/zclient.c index 4340863a3f..122a6ef52a 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -2359,7 +2359,7 @@ struct nexthop *nexthop_from_zapi_nexthop(const struct zapi_nexthop *znh) &znh->seg6local_ctx); if (znh->seg_num && !sid_zero_ipv6(znh->seg6_segs)) - nexthop_add_srv6_seg6(n, &znh->seg6_segs[0], znh->seg_num); + nexthop_add_srv6_seg6(n, &znh->seg6_segs[0], znh->seg_num, znh->srv6_encap_behavior); return n; } diff --git a/sharpd/sharp_vty.c b/sharpd/sharp_vty.c index fd36e8898e..a6bcfff3b7 100644 --- a/sharpd/sharp_vty.c +++ b/sharpd/sharp_vty.c @@ -429,7 +429,7 @@ DEFPY (install_seg6_routes, sg.r.nhop.gate.ipv6 = seg6_nh6; sg.r.nhop.vrf_id = vrf->vrf_id; sg.r.nhop_group.nexthop = &sg.r.nhop; - nexthop_add_srv6_seg6(&sg.r.nhop, &seg6_seg, 1); + nexthop_add_srv6_seg6(&sg.r.nhop, &seg6_seg, 1, SRV6_HEADEND_BEHAVIOR_H_ENCAPS); sg.r.vrf_id = vrf->vrf_id; sharp_install_routes_helper(&prefix, sg.r.vrf_id, sg.r.inst, 0, @@ -527,7 +527,7 @@ DEFPY(install_seg6local_segs_routes, install_seg6local_segs_routes_cmd, sg.r.nhop_group.nexthop = &sg.r.nhop; seg_list[0] = seg6_seg1; seg_list[1] = seg6_seg2; - nexthop_add_srv6_seg6(&sg.r.nhop, p_seg_list, 2); + nexthop_add_srv6_seg6(&sg.r.nhop, p_seg_list, 2, SRV6_HEADEND_BEHAVIOR_H_ENCAPS); sg.r.vrf_id = vrf->vrf_id; sharp_install_routes_helper(&sg.r.orig_prefix, sg.r.vrf_id, sg.r.inst, 0, &sg.r.nhop_group, diff --git a/zebra/rt_netlink.c b/zebra/rt_netlink.c index 8f6a032959..62fde90018 100644 --- a/zebra/rt_netlink.c +++ b/zebra/rt_netlink.c @@ -612,7 +612,7 @@ parse_nexthop_unicast(ns_id_t ns_id, struct rtmsg *rtm, struct rtattr **tb, nexthop_add_srv6_seg6local(&nh, seg6l_act, &seg6l_ctx); if (num_segs) - nexthop_add_srv6_seg6(&nh, segs, num_segs); + nexthop_add_srv6_seg6(&nh, segs, num_segs, srv6_encap_behavior); return nh; } @@ -729,7 +729,7 @@ static uint16_t parse_multipath_nexthops_unicast(ns_id_t ns_id, struct nexthop_g &seg6l_ctx); if (num_segs) - nexthop_add_srv6_seg6(nh, segs, num_segs); + nexthop_add_srv6_seg6(nh, segs, num_segs, srv6_encap_behavior); if (rtnh->rtnh_flags & RTNH_F_ONLINK) SET_FLAG(nh->flags, NEXTHOP_FLAG_ONLINK); diff --git a/zebra/zapi_msg.c b/zebra/zapi_msg.c index fc78f87eb1..9687d71e25 100644 --- a/zebra/zapi_msg.c +++ b/zebra/zapi_msg.c @@ -1888,8 +1888,8 @@ static bool zapi_read_nexthops(struct zserv *client, struct prefix *p, if (IS_ZEBRA_DEBUG_RECV) zlog_debug("%s: adding seg6", __func__); - nexthop_add_srv6_seg6(nexthop, &api_nh->seg6_segs[0], - api_nh->seg_num); + nexthop_add_srv6_seg6(nexthop, &api_nh->seg6_segs[0], api_nh->seg_num, + api_nh->srv6_encap_behavior); } if (IS_ZEBRA_DEBUG_RECV) { diff --git a/zebra/zebra_nhg.c b/zebra/zebra_nhg.c index 1da2c13c15..4d73d8620e 100644 --- a/zebra/zebra_nhg.c +++ b/zebra/zebra_nhg.c @@ -1965,10 +1965,9 @@ static struct nexthop *nexthop_set_resolved(afi_t afi, &nexthop->nh_srv6 ->seg6local_ctx); if (nexthop->nh_srv6->seg6_segs) - nexthop_add_srv6_seg6(resolved_hop, - &nexthop->nh_srv6->seg6_segs->seg[0], - nexthop->nh_srv6->seg6_segs - ->num_segs); + nexthop_add_srv6_seg6(resolved_hop, &nexthop->nh_srv6->seg6_segs->seg[0], + nexthop->nh_srv6->seg6_segs->num_segs, + nexthop->nh_srv6->seg6_segs->encap_behavior); } resolved_hop->rparent = nexthop; -- 2.39.5