From 09cd307c621c69c09ce3c1a0c012e9e0aa8eeb58 Mon Sep 17 00:00:00 2001 From: Mark Stapp Date: Fri, 1 Mar 2019 13:33:17 -0500 Subject: [PATCH] zebra: dplane pseudowires including nexthop info Add nexthop info to the data that the zebra dataplane captures when programming pseudowires. Signed-off-by: Mark Stapp --- zebra/zebra_dplane.c | 41 +++++++++++++++++++++++++++++++++++++++++ zebra/zebra_dplane.h | 2 ++ 2 files changed, 43 insertions(+) diff --git a/zebra/zebra_dplane.c b/zebra/zebra_dplane.c index 63ac7666f4..e4bc3a85a8 100644 --- a/zebra/zebra_dplane.c +++ b/zebra/zebra_dplane.c @@ -842,6 +842,14 @@ const union pw_protocol_fields *dplane_ctx_get_pw_proto( return &(ctx->u.pw.fields); } +const struct nexthop_group * +dplane_ctx_get_pw_nhg(const struct zebra_dplane_ctx *ctx) +{ + DPLANE_CTX_VALID(ctx); + + return &(ctx->u.pw.nhg); +} + /* * End of dplane context accessors */ @@ -1051,6 +1059,12 @@ static int dplane_ctx_pw_init(struct zebra_dplane_ctx *ctx, enum dplane_op_e op, struct zebra_pw *pw) { + struct prefix p; + afi_t afi; + struct route_table *table; + struct route_node *rn; + struct route_entry *re; + if (IS_ZEBRA_DEBUG_DPLANE_DETAIL) zlog_debug("init dplane ctx %s: pw '%s', loc %u, rem %u", dplane_op2str(op), pw->ifname, pw->local_label, @@ -1081,6 +1095,33 @@ static int dplane_ctx_pw_init(struct zebra_dplane_ctx *ctx, ctx->u.pw.fields = pw->data; + /* Capture nexthop info for the pw destination. We need to look + * up and use zebra datastructs, but we're running in the zebra + * pthread here so that should be ok. + */ + memcpy(&p.u, &pw->nexthop, sizeof(pw->nexthop)); + p.family = pw->af; + p.prefixlen = ((pw->af == AF_INET) ? + IPV4_MAX_PREFIXLEN : IPV6_MAX_PREFIXLEN); + + afi = (pw->af == AF_INET) ? AFI_IP : AFI_IP6; + table = zebra_vrf_table(afi, SAFI_UNICAST, pw->vrf_id); + if (table) { + rn = route_node_match(table, &p); + if (rn) { + RNODE_FOREACH_RE(rn, re) { + if (CHECK_FLAG(re->flags, ZEBRA_FLAG_SELECTED)) + break; + } + + if (re) + copy_nexthops(&(ctx->u.pw.nhg.nexthop), + re->ng.nexthop, NULL); + + route_unlock_node(rn); + } + } + return AOK; } diff --git a/zebra/zebra_dplane.h b/zebra/zebra_dplane.h index 84da20f2a7..4cd8031d73 100644 --- a/zebra/zebra_dplane.h +++ b/zebra/zebra_dplane.h @@ -219,6 +219,8 @@ const union g_addr *dplane_ctx_get_pw_dest( const struct zebra_dplane_ctx *ctx); const union pw_protocol_fields *dplane_ctx_get_pw_proto( const struct zebra_dplane_ctx *ctx); +const struct nexthop_group *dplane_ctx_get_pw_nhg( + const struct zebra_dplane_ctx *ctx); /* Namespace info - esp. for netlink communication */ const struct zebra_dplane_info *dplane_ctx_get_ns( -- 2.39.5