From 7c7ef4a8c8f38fc3ea1ffe52792233f873449b7a Mon Sep 17 00:00:00 2001 From: Mark Stapp Date: Thu, 25 Jul 2019 14:01:22 -0400 Subject: [PATCH] zebra: consolidate dataplane interface name and ifindex attrs Move interface name and index to shared data struct, and remove operation-specific values. Signed-off-by: Mark Stapp --- zebra/zebra_dplane.c | 52 +++++++++++++++----------------------- zebra/zebra_dplane.h | 5 ++-- zebra/zebra_mpls_openbsd.c | 4 +-- zebra/zebra_rib.c | 2 +- 4 files changed, 26 insertions(+), 37 deletions(-) diff --git a/zebra/zebra_dplane.c b/zebra/zebra_dplane.c index f93562b31b..930141ba54 100644 --- a/zebra/zebra_dplane.c +++ b/zebra/zebra_dplane.c @@ -109,8 +109,6 @@ struct dplane_route_info { * Pseudowire info for the dataplane */ struct dplane_pw_info { - char ifname[IF_NAMESIZE]; - ifindex_t ifindex; int type; int af; int status; @@ -130,9 +128,6 @@ struct dplane_pw_info { */ struct dplane_intf_info { - char ifname[INTERFACE_NAMSIZ]; - ifindex_t ifindex; - uint32_t metric; uint32_t flags; @@ -188,6 +183,9 @@ struct zebra_dplane_ctx { vrf_id_t zd_vrf_id; uint32_t zd_table_id; + char zd_ifname[INTERFACE_NAMSIZ]; + ifindex_t zd_ifindex; + /* Support info for different kinds of updates */ union { struct dplane_route_info rinfo; @@ -744,6 +742,19 @@ void dplane_ctx_set_notif_provider(struct zebra_dplane_ctx *ctx, ctx->zd_notif_provider = id; } +const char *dplane_ctx_get_ifname(const struct zebra_dplane_ctx *ctx) +{ + DPLANE_CTX_VALID(ctx); + + return ctx->zd_ifname; +} + +ifindex_t dplane_ctx_get_ifindex(const struct zebra_dplane_ctx *ctx) +{ + DPLANE_CTX_VALID(ctx); + + return ctx->zd_ifindex; +} void dplane_ctx_set_type(struct zebra_dplane_ctx *ctx, int type) { @@ -1030,13 +1041,6 @@ uint32_t dplane_ctx_get_lsp_num_ecmp(const struct zebra_dplane_ctx *ctx) return ctx->u.lsp.num_ecmp; } -const char *dplane_ctx_get_pw_ifname(const struct zebra_dplane_ctx *ctx) -{ - DPLANE_CTX_VALID(ctx); - - return ctx->u.pw.ifname; -} - mpls_label_t dplane_ctx_get_pw_local_label(const struct zebra_dplane_ctx *ctx) { DPLANE_CTX_VALID(ctx); @@ -1104,20 +1108,6 @@ dplane_ctx_get_pw_nhg(const struct zebra_dplane_ctx *ctx) } /* Accessors for interface information */ -const char *dplane_ctx_get_ifname(const struct zebra_dplane_ctx *ctx) -{ - DPLANE_CTX_VALID(ctx); - - return ctx->u.intf.ifname; -} - -ifindex_t dplane_ctx_get_ifindex(const struct zebra_dplane_ctx *ctx) -{ - DPLANE_CTX_VALID(ctx); - - return ctx->u.intf.ifindex; -} - uint32_t dplane_ctx_get_intf_metric(const struct zebra_dplane_ctx *ctx) { DPLANE_CTX_VALID(ctx); @@ -1422,10 +1412,10 @@ static int dplane_ctx_pw_init(struct zebra_dplane_ctx *ctx, memset(&ctx->u.pw, 0, sizeof(ctx->u.pw)); /* This name appears to be c-string, so we use string copy. */ - strlcpy(ctx->u.pw.ifname, pw->ifname, sizeof(ctx->u.pw.ifname)); + strlcpy(ctx->zd_ifname, pw->ifname, sizeof(ctx->zd_ifname)); ctx->zd_vrf_id = pw->vrf_id; - ctx->u.pw.ifindex = pw->ifindex; + ctx->zd_ifindex = pw->ifindex; ctx->u.pw.type = pw->type; ctx->u.pw.af = pw->af; ctx->u.pw.local_label = pw->local_label; @@ -1967,8 +1957,8 @@ static enum zebra_dplane_result intf_addr_update_internal( /* Init the interface-addr-specific area */ memset(&ctx->u.intf, 0, sizeof(ctx->u.intf)); - strlcpy(ctx->u.intf.ifname, ifp->name, sizeof(ctx->u.intf.ifname)); - ctx->u.intf.ifindex = ifp->ifindex; + strlcpy(ctx->zd_ifname, ifp->name, sizeof(ctx->zd_ifname)); + ctx->zd_ifindex = ifp->ifindex; ctx->u.intf.prefix = *(ifc->address); if (if_is_broadcast(ifp)) @@ -2374,7 +2364,7 @@ kernel_dplane_pw_update(struct zebra_dplane_ctx *ctx) if (IS_ZEBRA_DEBUG_DPLANE_DETAIL) zlog_debug("Dplane pw %s: op %s af %d loc: %u rem: %u", - dplane_ctx_get_pw_ifname(ctx), + dplane_ctx_get_ifname(ctx), dplane_op2str(ctx->zd_op), dplane_ctx_get_pw_af(ctx), dplane_ctx_get_pw_local_label(ctx), diff --git a/zebra/zebra_dplane.h b/zebra/zebra_dplane.h index 6238026bcf..01a23b0881 100644 --- a/zebra/zebra_dplane.h +++ b/zebra/zebra_dplane.h @@ -180,6 +180,8 @@ const char *dplane_op2str(enum dplane_op_e op); const struct prefix *dplane_ctx_get_dest(const struct zebra_dplane_ctx *ctx); void dplane_ctx_set_dest(struct zebra_dplane_ctx *ctx, const struct prefix *dest); +const char *dplane_ctx_get_ifname(const struct zebra_dplane_ctx *ctx); +ifindex_t dplane_ctx_get_ifindex(const struct zebra_dplane_ctx *ctx); /* Retrieve last/current provider id */ uint32_t dplane_ctx_get_provider(const struct zebra_dplane_ctx *ctx); @@ -262,7 +264,6 @@ const zebra_nhlfe_t *dplane_ctx_set_best_nhlfe(struct zebra_dplane_ctx *ctx, uint32_t dplane_ctx_get_lsp_num_ecmp(const struct zebra_dplane_ctx *ctx); /* Accessors for pseudowire information */ -const char *dplane_ctx_get_pw_ifname(const struct zebra_dplane_ctx *ctx); mpls_label_t dplane_ctx_get_pw_local_label(const struct zebra_dplane_ctx *ctx); mpls_label_t dplane_ctx_get_pw_remote_label(const struct zebra_dplane_ctx *ctx); int dplane_ctx_get_pw_type(const struct zebra_dplane_ctx *ctx); @@ -277,8 +278,6 @@ const struct nexthop_group *dplane_ctx_get_pw_nhg( const struct zebra_dplane_ctx *ctx); /* Accessors for interface information */ -const char *dplane_ctx_get_ifname(const struct zebra_dplane_ctx *ctx); -ifindex_t dplane_ctx_get_ifindex(const struct zebra_dplane_ctx *ctx); uint32_t dplane_ctx_get_intf_metric(const struct zebra_dplane_ctx *ctx); /* Is interface addr p2p? */ bool dplane_ctx_intf_is_connected(const struct zebra_dplane_ctx *ctx); diff --git a/zebra/zebra_mpls_openbsd.c b/zebra/zebra_mpls_openbsd.c index e7fdaf127d..9f3ea70c77 100644 --- a/zebra/zebra_mpls_openbsd.c +++ b/zebra/zebra_mpls_openbsd.c @@ -369,7 +369,7 @@ static enum zebra_dplane_result kmpw_install(struct zebra_dplane_ctx *ctx) /* ioctl */ memset(&ifr, 0, sizeof(ifr)); - strlcpy(ifr.ifr_name, dplane_ctx_get_pw_ifname(ctx), + strlcpy(ifr.ifr_name, dplane_ctx_get_ifname(ctx), sizeof(ifr.ifr_name)); ifr.ifr_data = (caddr_t)&imr; if (ioctl(kr_state.ioctl_fd, SIOCSETMPWCFG, &ifr) == -1) { @@ -388,7 +388,7 @@ static enum zebra_dplane_result kmpw_uninstall(struct zebra_dplane_ctx *ctx) memset(&ifr, 0, sizeof(ifr)); memset(&imr, 0, sizeof(imr)); - strlcpy(ifr.ifr_name, dplane_ctx_get_pw_ifname(ctx), + strlcpy(ifr.ifr_name, dplane_ctx_get_ifname(ctx), sizeof(ifr.ifr_name)); ifr.ifr_data = (caddr_t)&imr; if (ioctl(kr_state.ioctl_fd, SIOCSETMPWCFG, &ifr) == -1) { diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c index afe59b9593..601970785e 100644 --- a/zebra/zebra_rib.c +++ b/zebra/zebra_rib.c @@ -3220,7 +3220,7 @@ static int handle_pw_result(struct zebra_dplane_ctx *ctx) if (dplane_ctx_get_status(ctx) != ZEBRA_DPLANE_REQUEST_SUCCESS) { vrf = zebra_vrf_lookup_by_id(dplane_ctx_get_vrf(ctx)); - pw = zebra_pw_find(vrf, dplane_ctx_get_pw_ifname(ctx)); + pw = zebra_pw_find(vrf, dplane_ctx_get_ifname(ctx)); if (pw) zebra_pw_install_failure(pw); } -- 2.39.5