From 18f60fe9990db3c9313e579497d36e44a9818629 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jakub=20Urba=C5=84czyk?= Date: Fri, 31 Jul 2020 00:15:51 +0200 Subject: [PATCH] zebra: remove old kernel one-update-at-a-time api MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The old one is replaced by the api that is suitable for the batching. Signed-off-by: Jakub Urbańczyk --- zebra/if_netlink.c | 9 ---- zebra/kernel_netlink.c | 5 -- zebra/kernel_socket.c | 94 ++++++++++++++++++++++++++++++++++++-- zebra/rt.h | 8 +++- zebra/rt_netlink.c | 49 ++------------------ zebra/rule_netlink.c | 9 ---- zebra/zebra_dplane.c | 88 +---------------------------------- zebra/zebra_mpls_netlink.c | 18 -------- zebra/zebra_pbr.h | 7 --- 9 files changed, 101 insertions(+), 186 deletions(-) diff --git a/zebra/if_netlink.c b/zebra/if_netlink.c index ce04b3e04d..5cd3e69299 100644 --- a/zebra/if_netlink.c +++ b/zebra/if_netlink.c @@ -1058,15 +1058,6 @@ static ssize_t netlink_address_msg_encoder(struct zebra_dplane_ctx *ctx, return NLMSG_ALIGN(req->n.nlmsg_len); } -/* - * The communication with the kernel is done using the message batching - * interface, so return a failure. - */ -enum zebra_dplane_result kernel_address_update_ctx(struct zebra_dplane_ctx *ctx) -{ - return ZEBRA_DPLANE_REQUEST_FAILURE; -} - enum netlink_msg_status netlink_put_address_update_msg(struct nl_batch *bth, struct zebra_dplane_ctx *ctx) diff --git a/zebra/kernel_netlink.c b/zebra/kernel_netlink.c index cd8d3c095c..2ce48b33ef 100644 --- a/zebra/kernel_netlink.c +++ b/zebra/kernel_netlink.c @@ -1429,11 +1429,6 @@ void kernel_update_multi(struct dplane_ctx_q *ctx_list) dplane_ctx_list_append(ctx_list, &handled_list); } -bool kernel_supports_batch(void) -{ - return true; -} - /* Exported interface function. This function simply calls netlink_socket (). */ void kernel_init(struct zebra_ns *zns) diff --git a/zebra/kernel_socket.c b/zebra/kernel_socket.c index 896926bcbe..9e56e2988d 100644 --- a/zebra/kernel_socket.c +++ b/zebra/kernel_socket.c @@ -1466,12 +1466,96 @@ void kernel_terminate(struct zebra_ns *zns, bool complete) void kernel_update_multi(struct dplane_ctx_q *ctx_list) { - /* no-op */ -} + struct zebra_dplane_ctx *ctx; + struct dplane_ctx_q handled_list; + enum zebra_dplane_result res; -bool kernel_supports_batch(void) -{ - return false; + TAILQ_INIT(&handled_list); + + while (true) { + ctx = dplane_ctx_dequeue(ctx_list); + if (ctx == NULL) + break; + + /* + * A previous provider plugin may have asked to skip the + * kernel update. + */ + if (dplane_ctx_is_skip_kernel(ctx)) { + res = ZEBRA_DPLANE_REQUEST_SUCCESS; + goto skip_one; + } + + switch (dplane_ctx_get_op(ctx)) { + + case DPLANE_OP_ROUTE_INSTALL: + case DPLANE_OP_ROUTE_UPDATE: + case DPLANE_OP_ROUTE_DELETE: + res = kernel_route_update(ctx); + break; + + case DPLANE_OP_NH_INSTALL: + case DPLANE_OP_NH_UPDATE: + case DPLANE_OP_NH_DELETE: + res = kernel_nexthop_update(ctx); + break; + + case DPLANE_OP_LSP_INSTALL: + case DPLANE_OP_LSP_UPDATE: + case DPLANE_OP_LSP_DELETE: + res = kernel_lsp_update(ctx); + break; + + case DPLANE_OP_PW_INSTALL: + case DPLANE_OP_PW_UNINSTALL: + res = kernel_pw_update(ctx); + break; + + case DPLANE_OP_ADDR_INSTALL: + case DPLANE_OP_ADDR_UNINSTALL: + res = kernel_address_update_ctx(ctx); + break; + + case DPLANE_OP_MAC_INSTALL: + case DPLANE_OP_MAC_DELETE: + res = kernel_mac_update_ctx(ctx); + break; + + case DPLANE_OP_NEIGH_INSTALL: + case DPLANE_OP_NEIGH_UPDATE: + case DPLANE_OP_NEIGH_DELETE: + case DPLANE_OP_VTEP_ADD: + case DPLANE_OP_VTEP_DELETE: + res = kernel_neigh_update_ctx(ctx); + break; + + case DPLANE_OP_RULE_ADD: + case DPLANE_OP_RULE_DELETE: + case DPLANE_OP_RULE_UPDATE: + res = kernel_pbr_rule_update(ctx); + break; + + /* Ignore 'notifications' - no-op */ + case DPLANE_OP_SYS_ROUTE_ADD: + case DPLANE_OP_SYS_ROUTE_DELETE: + case DPLANE_OP_ROUTE_NOTIFY: + case DPLANE_OP_LSP_NOTIFY: + res = ZEBRA_DPLANE_REQUEST_SUCCESS; + break; + + default: + res = ZEBRA_DPLANE_REQUEST_FAILURE; + break; + } + + skip_one: + dplane_ctx_set_status(ctx, res); + + dplane_ctx_enqueue_tail(&handled_list, ctx); + } + + TAILQ_INIT(ctx_list); + dplane_ctx_list_append(ctx_list, &handled_list); } #endif /* !HAVE_NETLINK */ diff --git a/zebra/rt.h b/zebra/rt.h index c0ff2e22b3..48f1df2868 100644 --- a/zebra/rt.h +++ b/zebra/rt.h @@ -40,7 +40,7 @@ extern "C" { #define RSYSTEM_ROUTE(type) \ ((RKERNEL_ROUTE(type)) || (type) == ZEBRA_ROUTE_CONNECT) - +#ifndef HAVE_NETLINK /* * Update or delete a route, nexthop, LSP, pseudowire, or vxlan MAC from the * kernel, using info from a dataplane context. @@ -63,6 +63,11 @@ enum zebra_dplane_result kernel_mac_update_ctx(struct zebra_dplane_ctx *ctx); enum zebra_dplane_result kernel_neigh_update_ctx(struct zebra_dplane_ctx *ctx); +extern enum zebra_dplane_result +kernel_pbr_rule_update(struct zebra_dplane_ctx *ctx); + +#endif /* !HAVE_NETLINK */ + extern int kernel_neigh_update(int cmd, int ifindex, uint32_t addr, char *lla, int llalen, ns_id_t ns_id); extern int kernel_interface_set_master(struct interface *master, @@ -101,7 +106,6 @@ extern int kernel_del_mac_nhg(uint32_t nhg_id); * Message batching interface. */ extern void kernel_update_multi(struct dplane_ctx_q *ctx_list); -extern bool kernel_supports_batch(void); #ifdef __cplusplus } diff --git a/zebra/rt_netlink.c b/zebra/rt_netlink.c index 2f1f2c4bc9..190af3f59d 100644 --- a/zebra/rt_netlink.c +++ b/zebra/rt_netlink.c @@ -2251,15 +2251,6 @@ static ssize_t netlink_nexthop_msg_encoder(struct zebra_dplane_ctx *ctx, return netlink_nexthop_msg_encode(cmd, ctx, buf, buflen); } -/* - * The communication with the kernel is done using the message batching - * interface, so return a failure. - */ -enum zebra_dplane_result kernel_nexthop_update(struct zebra_dplane_ctx *ctx) -{ - return ZEBRA_DPLANE_REQUEST_FAILURE; -} - enum netlink_msg_status netlink_put_nexthop_update_msg(struct nl_batch *bth, struct zebra_dplane_ctx *ctx) @@ -2347,15 +2338,6 @@ netlink_put_route_update_msg(struct nl_batch *bth, struct zebra_dplane_ctx *ctx) false); } -/* - * The communication with the kernel is done using the message batching - * interface, so return a failure. - */ -enum zebra_dplane_result kernel_route_update(struct zebra_dplane_ctx *ctx) -{ - return ZEBRA_DPLANE_REQUEST_FAILURE; -} - /** * netlink_nexthop_process_nh() - Parse the gatway/if info from a new nexthop * @@ -2777,9 +2759,8 @@ netlink_vxlan_flood_update_ctx(const struct zebra_dplane_ctx *ctx, int cmd, return netlink_neigh_update_msg_encode( ctx, cmd, &dst_mac, dplane_ctx_neigh_get_ipaddr(ctx), false, - PF_BRIDGE, 0, NTF_SELF, (NUD_NOARP | NUD_PERMANENT), - 0 /*nhg*/, false /*nfy*/, 0 /*nfy_flags*/, - buf, buflen); + PF_BRIDGE, 0, NTF_SELF, (NUD_NOARP | NUD_PERMANENT), 0 /*nhg*/, + false /*nfy*/, 0 /*nfy_flags*/, buf, buflen); } #ifndef NDA_RTA @@ -3637,11 +3618,9 @@ static ssize_t netlink_neigh_update_ctx(const struct zebra_dplane_ctx *ctx, flags, state); } - return netlink_neigh_update_msg_encode(ctx, cmd, mac, ip, true, family, - RTN_UNICAST, flags, state, - 0 /*nhg*/, false /*nfy*/, 0 /*nfy_flags*/, - buf, - buflen); + return netlink_neigh_update_msg_encode( + ctx, cmd, mac, ip, true, family, RTN_UNICAST, flags, state, + 0 /*nhg*/, false /*nfy*/, 0 /*nfy_flags*/, buf, buflen); } static ssize_t netlink_neigh_msg_encoder(struct zebra_dplane_ctx *ctx, @@ -3676,15 +3655,6 @@ static ssize_t netlink_neigh_msg_encoder(struct zebra_dplane_ctx *ctx, * Update MAC, using dataplane context object. */ -/* - * The communication with the kernel is done using the message batching - * interface, so return a failure. - */ -enum zebra_dplane_result kernel_mac_update_ctx(struct zebra_dplane_ctx *ctx) -{ - return ZEBRA_DPLANE_REQUEST_FAILURE; -} - enum netlink_msg_status netlink_put_mac_update_msg(struct nl_batch *bth, struct zebra_dplane_ctx *ctx) { @@ -3692,15 +3662,6 @@ enum netlink_msg_status netlink_put_mac_update_msg(struct nl_batch *bth, false); } -/* - * The communication with the kernel is done using the message batching - * interface, so return a failure. - */ -enum zebra_dplane_result kernel_neigh_update_ctx(struct zebra_dplane_ctx *ctx) -{ - return ZEBRA_DPLANE_REQUEST_FAILURE; -} - enum netlink_msg_status netlink_put_neigh_update_msg(struct nl_batch *bth, struct zebra_dplane_ctx *ctx) { diff --git a/zebra/rule_netlink.c b/zebra/rule_netlink.c index 9f9ea27748..3a3baab4ca 100644 --- a/zebra/rule_netlink.c +++ b/zebra/rule_netlink.c @@ -182,15 +182,6 @@ static ssize_t netlink_oldrule_msg_encoder(struct zebra_dplane_ctx *ctx, /* Public functions */ -/* - * The communication with the kernel is done using the message batching - * interface, so return a failure. - */ -enum zebra_dplane_result kernel_pbr_rule_update(struct zebra_dplane_ctx *ctx) -{ - return ZEBRA_DPLANE_REQUEST_FAILURE; -} - enum netlink_msg_status netlink_put_rule_update_msg(struct nl_batch *bth, struct zebra_dplane_ctx *ctx) { diff --git a/zebra/zebra_dplane.c b/zebra/zebra_dplane.c index 2520a029b9..3bff95101c 100644 --- a/zebra/zebra_dplane.c +++ b/zebra/zebra_dplane.c @@ -3911,89 +3911,6 @@ static void kernel_dplane_handle_result(struct zebra_dplane_ctx *ctx) } } -static void kernel_dplane_dispatch_updates(struct dplane_ctx_q *ctx_list) -{ - enum zebra_dplane_result res; - struct zebra_dplane_ctx *ctx; - - TAILQ_FOREACH (ctx, ctx_list, zd_q_entries) { - /* - * A previous provider plugin may have asked to skip the - * kernel update. - */ - if (dplane_ctx_is_skip_kernel(ctx)) { - res = ZEBRA_DPLANE_REQUEST_SUCCESS; - goto skip_one; - } - - /* Dispatch to appropriate kernel-facing apis */ - switch (dplane_ctx_get_op(ctx)) { - - case DPLANE_OP_ROUTE_INSTALL: - case DPLANE_OP_ROUTE_UPDATE: - case DPLANE_OP_ROUTE_DELETE: - res = kernel_route_update(ctx); - break; - - case DPLANE_OP_NH_INSTALL: - case DPLANE_OP_NH_UPDATE: - case DPLANE_OP_NH_DELETE: - res = kernel_nexthop_update(ctx); - break; - - case DPLANE_OP_LSP_INSTALL: - case DPLANE_OP_LSP_UPDATE: - case DPLANE_OP_LSP_DELETE: - res = kernel_lsp_update(ctx); - break; - - case DPLANE_OP_PW_INSTALL: - case DPLANE_OP_PW_UNINSTALL: - res = kernel_pw_update(ctx); - break; - - case DPLANE_OP_ADDR_INSTALL: - case DPLANE_OP_ADDR_UNINSTALL: - res = kernel_address_update_ctx(ctx); - break; - - case DPLANE_OP_MAC_INSTALL: - case DPLANE_OP_MAC_DELETE: - res = kernel_mac_update_ctx(ctx); - break; - - case DPLANE_OP_NEIGH_INSTALL: - case DPLANE_OP_NEIGH_UPDATE: - case DPLANE_OP_NEIGH_DELETE: - case DPLANE_OP_VTEP_ADD: - case DPLANE_OP_VTEP_DELETE: - res = kernel_neigh_update_ctx(ctx); - break; - - case DPLANE_OP_RULE_ADD: - case DPLANE_OP_RULE_DELETE: - case DPLANE_OP_RULE_UPDATE: - res = kernel_pbr_rule_update(ctx); - break; - - /* Ignore 'notifications' - no-op */ - case DPLANE_OP_SYS_ROUTE_ADD: - case DPLANE_OP_SYS_ROUTE_DELETE: - case DPLANE_OP_ROUTE_NOTIFY: - case DPLANE_OP_LSP_NOTIFY: - res = ZEBRA_DPLANE_REQUEST_SUCCESS; - break; - - default: - res = ZEBRA_DPLANE_REQUEST_FAILURE; - break; - } - - skip_one: - dplane_ctx_set_status(ctx, res); - } -} - /* * Kernel provider callback */ @@ -4022,10 +3939,7 @@ static int kernel_dplane_process_func(struct zebra_dplane_provider *prov) TAILQ_INSERT_TAIL(&work_list, ctx, zd_q_entries); } - if (kernel_supports_batch()) - kernel_update_multi(&work_list); - else - kernel_dplane_dispatch_updates(&work_list); + kernel_update_multi(&work_list); TAILQ_FOREACH_SAFE (ctx, &work_list, zd_q_entries, tctx) { kernel_dplane_handle_result(ctx); diff --git a/zebra/zebra_mpls_netlink.c b/zebra/zebra_mpls_netlink.c index 742b08c376..3b2279c66c 100644 --- a/zebra/zebra_mpls_netlink.c +++ b/zebra/zebra_mpls_netlink.c @@ -55,30 +55,12 @@ static ssize_t netlink_lsp_msg_encoder(struct zebra_dplane_ctx *ctx, void *buf, return netlink_mpls_multipath_msg_encode(cmd, ctx, buf, buflen); } -/* - * The communication with the kernel is done using the message batching - * interface, so return a failure. - */ -enum zebra_dplane_result kernel_lsp_update(struct zebra_dplane_ctx *ctx) -{ - return ZEBRA_DPLANE_REQUEST_FAILURE; -} - enum netlink_msg_status netlink_put_lsp_update_msg(struct nl_batch *bth, struct zebra_dplane_ctx *ctx) { return netlink_batch_add_msg(bth, ctx, netlink_lsp_msg_encoder, false); } -/* - * The communication with the kernel is done using the message batching - * interface, so return a failure. - */ -enum zebra_dplane_result kernel_pw_update(struct zebra_dplane_ctx *ctx) -{ - return ZEBRA_DPLANE_REQUEST_FAILURE; -} - /* * Pseudowire update api - not supported by netlink as of 12/18, * but note that the default has been to report 'success' for pw updates diff --git a/zebra/zebra_pbr.h b/zebra/zebra_pbr.h index dd2d7a190d..888d2fcfa0 100644 --- a/zebra/zebra_pbr.h +++ b/zebra/zebra_pbr.h @@ -171,13 +171,6 @@ void zebra_pbr_del_ipset_entry(struct zebra_pbr_ipset_entry *ipset); void zebra_pbr_add_iptable(struct zebra_pbr_iptable *iptable); void zebra_pbr_del_iptable(struct zebra_pbr_iptable *iptable); -/* - * Add, update or delete a rule from the - * kernel, using info from a dataplane context. - */ -extern enum zebra_dplane_result -kernel_pbr_rule_update(struct zebra_dplane_ctx *ctx); - /* * Get to know existing PBR rules in the kernel - typically called at startup. */ -- 2.39.5