From 45f0a10befd363590ed55a38d83f6edc3600e01b Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Tue, 4 Oct 2022 15:41:36 -0400 Subject: [PATCH] zebra: Add ctx to netlink message parsing Add the initial step of passing in a dplane context to reading route netlink messages. This code will be run in two contexts: a) The normal pthread for reading netlink messages from the kernel b) The dplane_fpm_nl pthread. The goal of this commit is too just allow a) to work b) will be filled in in the future. Effectively everything should still be working as it should pre this change. We will just possibly allow the passing of the context around( but not used ) Signed-off-by: Donald Sharp --- zebra/rt_netlink.c | 30 ++++++++++++++++++++++-------- zebra/rt_netlink.h | 4 ++++ zebra/zebra_dplane.c | 11 +++++++++++ zebra/zebra_dplane.h | 10 ++++++++++ 4 files changed, 47 insertions(+), 8 deletions(-) diff --git a/zebra/rt_netlink.c b/zebra/rt_netlink.c index 2396dfe4d6..96ec90e549 100644 --- a/zebra/rt_netlink.c +++ b/zebra/rt_netlink.c @@ -692,8 +692,9 @@ static uint8_t parse_multipath_nexthops_unicast(ns_id_t ns_id, } /* Looking up routing table by netlink interface. */ -static int netlink_route_change_read_unicast(struct nlmsghdr *h, ns_id_t ns_id, - int startup) +int netlink_route_change_read_unicast_internal(struct nlmsghdr *h, + ns_id_t ns_id, int startup, + struct zebra_dplane_ctx *ctx) { int len; struct rtmsg *rtm; @@ -768,9 +769,8 @@ static int netlink_route_change_read_unicast(struct nlmsghdr *h, ns_id_t ns_id, selfroute = is_selfroute(rtm->rtm_protocol); - if (!startup && selfroute - && h->nlmsg_type == RTM_NEWROUTE - && !zrouter.asic_offloaded) { + if (!startup && selfroute && h->nlmsg_type == RTM_NEWROUTE && + !zrouter.asic_offloaded && !ctx) { if (IS_ZEBRA_DEBUG_KERNEL) zlog_debug("Route type: %d Received that we think we have originated, ignoring", rtm->rtm_protocol); @@ -988,8 +988,8 @@ static int netlink_route_change_read_unicast(struct nlmsghdr *h, ns_id_t ns_id, } } if (nhe_id || ng) - rib_add_multipath(afi, SAFI_UNICAST, &p, &src_p, re, ng, - startup); + dplane_rib_add_multipath(afi, SAFI_UNICAST, &p, &src_p, + re, ng, startup, ctx); else { /* * I really don't see how this is possible @@ -1004,6 +1004,13 @@ static int netlink_route_change_read_unicast(struct nlmsghdr *h, ns_id_t ns_id, XFREE(MTYPE_RE, re); } } else { + if (ctx) { + zlog_err( + "%s: %pFX RTM_DELROUTE received but received a context as well", + __func__, &p); + return 0; + } + if (nhe_id) { rib_delete(afi, SAFI_UNICAST, vrf_id, proto, 0, flags, &p, &src_p, NULL, nhe_id, table, metric, @@ -1028,7 +1035,14 @@ static int netlink_route_change_read_unicast(struct nlmsghdr *h, ns_id_t ns_id, } } - return 0; + return 1; +} + +static int netlink_route_change_read_unicast(struct nlmsghdr *h, ns_id_t ns_id, + int startup) +{ + return netlink_route_change_read_unicast_internal(h, ns_id, startup, + NULL); } static struct mcast_route_data *mroute = NULL; diff --git a/zebra/rt_netlink.h b/zebra/rt_netlink.h index b1af4b20e1..fd2b79a2bf 100644 --- a/zebra/rt_netlink.h +++ b/zebra/rt_netlink.h @@ -122,6 +122,10 @@ netlink_put_lsp_update_msg(struct nl_batch *bth, struct zebra_dplane_ctx *ctx); extern enum netlink_msg_status netlink_put_pw_update_msg(struct nl_batch *bth, struct zebra_dplane_ctx *ctx); +int netlink_route_change_read_unicast_internal(struct nlmsghdr *h, + ns_id_t ns_id, int startup, + struct zebra_dplane_ctx *ctx); + #ifdef NETLINK_DEBUG const char *nlmsg_type2str(uint16_t type); const char *af_type2str(int type); diff --git a/zebra/zebra_dplane.c b/zebra/zebra_dplane.c index 8e8547120b..66adbe84ba 100644 --- a/zebra/zebra_dplane.c +++ b/zebra/zebra_dplane.c @@ -6301,6 +6301,17 @@ kernel_dplane_process_ipset_entry(struct zebra_dplane_provider *prov, dplane_provider_enqueue_out_ctx(prov, ctx); } +void dplane_rib_add_multipath(afi_t afi, safi_t safi, struct prefix *p, + struct prefix_ipv6 *src_p, struct route_entry *re, + struct nexthop_group *ng, int startup, + struct zebra_dplane_ctx *ctx) +{ + if (!ctx) + rib_add_multipath(afi, safi, p, src_p, re, ng, startup); + else { + } +} + /* * Kernel provider callback */ diff --git a/zebra/zebra_dplane.h b/zebra/zebra_dplane.h index e392861ae0..3efbc33fe0 100644 --- a/zebra/zebra_dplane.h +++ b/zebra/zebra_dplane.h @@ -1081,6 +1081,16 @@ void zebra_dplane_pre_finish(void); void zebra_dplane_finish(void); void zebra_dplane_shutdown(void); +/* + * decision point for sending a routing update through the old + * straight to zebra master pthread or through the dplane to + * the master pthread for handling + */ +void dplane_rib_add_multipath(afi_t afi, safi_t safi, struct prefix *p, + struct prefix_ipv6 *src_p, struct route_entry *re, + struct nexthop_group *ng, int startup, + struct zebra_dplane_ctx *ctx); + #ifdef __cplusplus } #endif -- 2.39.5