From 728f2017ae285aea6f7e8bda369eaae7a3083899 Mon Sep 17 00:00:00 2001 From: Mark Stapp Date: Thu, 28 Oct 2021 11:19:32 -0400 Subject: [PATCH] zebra: add dplane type for NETCONF data Add a new dplane op for interface NETCONF data; add the new enum value to several switch statements. Signed-off-by: Mark Stapp --- zebra/dplane_fpm_nl.c | 1 + zebra/kernel_netlink.c | 1 + zebra/zebra_dplane.c | 94 ++++++++++++++++++++++++++++++++++++++++-- zebra/zebra_dplane.h | 34 +++++++++++++++ zebra/zebra_nhg.c | 1 + zebra/zebra_rib.c | 1 + zebra/zebra_script.c | 2 + 7 files changed, 131 insertions(+), 3 deletions(-) diff --git a/zebra/dplane_fpm_nl.c b/zebra/dplane_fpm_nl.c index 0baef5bdb5..8c8004190b 100644 --- a/zebra/dplane_fpm_nl.c +++ b/zebra/dplane_fpm_nl.c @@ -811,6 +811,7 @@ static int fpm_nl_enqueue(struct fpm_nl_ctx *fnc, struct zebra_dplane_ctx *ctx) case DPLANE_OP_GRE_SET: case DPLANE_OP_INTF_ADDR_ADD: case DPLANE_OP_INTF_ADDR_DEL: + case DPLANE_OP_INTF_NETCONFIG: case DPLANE_OP_NONE: break; diff --git a/zebra/kernel_netlink.c b/zebra/kernel_netlink.c index 8e472b4728..44389ae011 100644 --- a/zebra/kernel_netlink.c +++ b/zebra/kernel_netlink.c @@ -1492,6 +1492,7 @@ static enum netlink_msg_status nl_put_msg(struct nl_batch *bth, case DPLANE_OP_INTF_ADDR_ADD: case DPLANE_OP_INTF_ADDR_DEL: + case DPLANE_OP_INTF_NETCONFIG: case DPLANE_OP_NONE: return FRR_NETLINK_ERROR; } diff --git a/zebra/zebra_dplane.c b/zebra/zebra_dplane.c index 1967345d22..a062ad0cb6 100644 --- a/zebra/zebra_dplane.c +++ b/zebra/zebra_dplane.c @@ -290,6 +290,19 @@ struct dplane_gre_ctx { unsigned int mtu; struct zebra_l2info_gre info; }; + + +/* + * Network interface configuration info - aligned with netlink's NETCONF + * info. The flags values are public, in the dplane.h file... + */ +struct dplane_netconf_info { + ns_id_t ns_id; + ifindex_t ifindex; + enum dplane_netconf_status_e mpls_val; + enum dplane_netconf_status_e mcast_val; +}; + /* * The context block used to exchange info about route updates across * the boundary between the zebra main context (and pthread) and the @@ -347,6 +360,7 @@ struct zebra_dplane_ctx { } ipset_entry; struct dplane_neigh_table neightable; struct dplane_gre_ctx gre; + struct dplane_netconf_info netconf; } u; /* Namespace info, used especially for netlink kernel communication */ @@ -769,6 +783,7 @@ static void dplane_ctx_free_internal(struct zebra_dplane_ctx *ctx) } break; case DPLANE_OP_GRE_SET: + case DPLANE_OP_INTF_NETCONFIG: break; } } @@ -1053,6 +1068,9 @@ const char *dplane_op2str(enum dplane_op_e op) case DPLANE_OP_INTF_ADDR_DEL: return "INTF_ADDR_DEL"; + + case DPLANE_OP_INTF_NETCONFIG: + return "INTF_NETCONFIG"; } return ret; @@ -2239,6 +2257,10 @@ uint32_t dplane_intf_extra_get_status(const struct dplane_intf_extra *ptr) return ptr->status; } +/* + * End of interface extra info accessors + */ + uint8_t dplane_ctx_neightable_get_family(const struct zebra_dplane_ctx *ctx) { DPLANE_CTX_VALID(ctx); @@ -2270,9 +2292,66 @@ dplane_ctx_neightable_get_mcast_probes(const struct zebra_dplane_ctx *ctx) return ctx->u.neightable.mcast_probes; } -/* - * End of interface extra info accessors - */ +ifindex_t dplane_ctx_get_netconf_ifindex(const struct zebra_dplane_ctx *ctx) +{ + DPLANE_CTX_VALID(ctx); + + return ctx->u.netconf.ifindex; +} + +ns_id_t dplane_ctx_get_netconf_ns_id(const struct zebra_dplane_ctx *ctx) +{ + DPLANE_CTX_VALID(ctx); + + return ctx->u.netconf.ns_id; +} + +void dplane_ctx_set_netconf_ifindex(struct zebra_dplane_ctx *ctx, + ifindex_t ifindex) +{ + DPLANE_CTX_VALID(ctx); + + ctx->u.netconf.ifindex = ifindex; +} + +void dplane_ctx_set_netconf_ns_id(struct zebra_dplane_ctx *ctx, ns_id_t ns_id) +{ + DPLANE_CTX_VALID(ctx); + + ctx->u.netconf.ns_id = ns_id; +} + +enum dplane_netconf_status_e +dplane_ctx_get_netconf_mpls(const struct zebra_dplane_ctx *ctx) +{ + DPLANE_CTX_VALID(ctx); + + return ctx->u.netconf.mpls_val; +} + +enum dplane_netconf_status_e +dplane_ctx_get_netconf_mcast(const struct zebra_dplane_ctx *ctx) +{ + DPLANE_CTX_VALID(ctx); + + return ctx->u.netconf.mcast_val; +} + +void dplane_ctx_set_netconf_mpls(struct zebra_dplane_ctx *ctx, + enum dplane_netconf_status_e val) +{ + DPLANE_CTX_VALID(ctx); + + ctx->u.netconf.mpls_val = val; +} + +void dplane_ctx_set_netconf_mcast(struct zebra_dplane_ctx *ctx, + enum dplane_netconf_status_e val) +{ + DPLANE_CTX_VALID(ctx); + + ctx->u.netconf.mcast_val = val; +} /* * Retrieve the limit on the number of pending, unprocessed updates. @@ -5113,6 +5192,14 @@ static void kernel_dplane_log_detail(struct zebra_dplane_ctx *ctx) dplane_ctx_get_ifname(ctx), dplane_ctx_get_intf_addr(ctx)); break; + + case DPLANE_OP_INTF_NETCONFIG: + zlog_debug("%s: ifindex %d, mpls %d, mcast %d", + dplane_op2str(dplane_ctx_get_op(ctx)), + dplane_ctx_get_netconf_ifindex(ctx), + dplane_ctx_get_netconf_mpls(ctx), + dplane_ctx_get_netconf_mcast(ctx)); + break; } } @@ -5258,6 +5345,7 @@ static void kernel_dplane_handle_result(struct zebra_dplane_ctx *ctx) /* TODO -- error counters for incoming events? */ case DPLANE_OP_INTF_ADDR_ADD: case DPLANE_OP_INTF_ADDR_DEL: + case DPLANE_OP_INTF_NETCONFIG: break; case DPLANE_OP_NONE: diff --git a/zebra/zebra_dplane.h b/zebra/zebra_dplane.h index a7a5f99e45..29555d5b56 100644 --- a/zebra/zebra_dplane.h +++ b/zebra/zebra_dplane.h @@ -185,6 +185,9 @@ enum dplane_op_e { /* Incoming interface address events */ DPLANE_OP_INTF_ADDR_ADD, DPLANE_OP_INTF_ADDR_DEL, + + /* Incoming interface config events */ + DPLANE_OP_INTF_NETCONFIG, }; /* @@ -222,6 +225,22 @@ enum dplane_op_e { #define DPLANE_BR_PORT_NON_DF (1 << 0) +/* Definitions for the dplane 'netconf' apis, corresponding to the netlink + * NETCONF api. + * Sadly, netlink sends incremental updates, so its messages may contain + * just a single changed attribute, and not necessarily + * a complete snapshot of the attributes. + */ +enum dplane_netconf_status_e { + DPLANE_NETCONF_STATUS_UNKNOWN = 0, + DPLANE_NETCONF_STATUS_ENABLED, + DPLANE_NETCONF_STATUS_DISABLED +}; + +/* Some special ifindex values that may be part of the dplane netconf api. */ +#define DPLANE_NETCONF_IFINDEX_ALL -1 +#define DPLANE_NETCONF_IFINDEX_DEFAULT -2 + /* Enable system route notifications */ void dplane_enable_sys_route_notifs(void); @@ -564,6 +583,21 @@ dplane_ctx_gre_get_mtu(const struct zebra_dplane_ctx *ctx); const struct zebra_l2info_gre * dplane_ctx_gre_get_info(const struct zebra_dplane_ctx *ctx); +/* Interface netconf info */ +ifindex_t dplane_ctx_get_netconf_ifindex(const struct zebra_dplane_ctx *ctx); +ns_id_t dplane_ctx_get_netconf_ns_id(const struct zebra_dplane_ctx *ctx); +void dplane_ctx_set_netconf_ifindex(struct zebra_dplane_ctx *ctx, + ifindex_t ifindex); +void dplane_ctx_set_netconf_ns_id(struct zebra_dplane_ctx *ctx, ns_id_t ns_id); +enum dplane_netconf_status_e +dplane_ctx_get_netconf_mpls(const struct zebra_dplane_ctx *ctx); +enum dplane_netconf_status_e +dplane_ctx_get_netconf_mcast(const struct zebra_dplane_ctx *ctx); +void dplane_ctx_set_netconf_mpls(struct zebra_dplane_ctx *ctx, + enum dplane_netconf_status_e val); +void dplane_ctx_set_netconf_mcast(struct zebra_dplane_ctx *ctx, + enum dplane_netconf_status_e val); + /* Namespace fd info - esp. for netlink communication */ const struct zebra_dplane_info *dplane_ctx_get_ns( const struct zebra_dplane_ctx *ctx); diff --git a/zebra/zebra_nhg.c b/zebra/zebra_nhg.c index c1b104aec7..858309f3e7 100644 --- a/zebra/zebra_nhg.c +++ b/zebra/zebra_nhg.c @@ -2989,6 +2989,7 @@ void zebra_nhg_dplane_result(struct zebra_dplane_ctx *ctx) case DPLANE_OP_GRE_SET: case DPLANE_OP_INTF_ADDR_ADD: case DPLANE_OP_INTF_ADDR_DEL: + case DPLANE_OP_INTF_NETCONFIG: break; } diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c index c386fc4871..bfcbe645dd 100644 --- a/zebra/zebra_rib.c +++ b/zebra/zebra_rib.c @@ -4334,6 +4334,7 @@ static void rib_process_dplane_results(struct thread *thread) case DPLANE_OP_BR_PORT_UPDATE: case DPLANE_OP_NEIGH_TABLE_UPDATE: case DPLANE_OP_GRE_SET: + case DPLANE_OP_INTF_NETCONFIG: case DPLANE_OP_NONE: /* Don't expect this: just return the struct? */ dplane_ctx_fini(&ctx); diff --git a/zebra/zebra_script.c b/zebra/zebra_script.c index 0e19376abe..4087749fd7 100644 --- a/zebra/zebra_script.c +++ b/zebra/zebra_script.c @@ -412,6 +412,8 @@ void lua_pushzebra_dplane_ctx(lua_State *L, const struct zebra_dplane_ctx *ctx) lua_setfield(L, -2, "mtu"); } lua_setfield(L, -2, "gre"); + + case DPLANE_OP_INTF_NETCONFIG: /*NYI*/ case DPLANE_OP_NONE: break; } /* Dispatch by op code */ -- 2.39.5