zebra: remove old kernel one-update-at-a-time api

The old one is replaced by the api that is suitable for the batching.

Signed-off-by: Jakub Urbańczyk <xthaid@gmail.com>
This commit is contained in:
Jakub Urbańczyk 2020-07-31 00:15:51 +02:00
parent 67e3369ed4
commit 18f60fe999
9 changed files with 101 additions and 186 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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 */

View File

@ -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
}

View File

@ -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)
{

View File

@ -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)
{

View File

@ -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);

View File

@ -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

View File

@ -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.
*/