diff options
-rw-r--r-- | zebra/debug.c | 1 | ||||
-rw-r--r-- | zebra/kernel_netlink.c | 2 | ||||
-rw-r--r-- | zebra/redistribute.h | 5 | ||||
-rw-r--r-- | zebra/rt_netlink.c | 168 | ||||
-rw-r--r-- | zebra/zebra_dplane.c | 150 | ||||
-rw-r--r-- | zebra/zebra_dplane.h | 26 | ||||
-rw-r--r-- | zebra/zebra_ns.h | 5 | ||||
-rw-r--r-- | zebra/zebra_rib.c | 41 |
8 files changed, 175 insertions, 223 deletions
diff --git a/zebra/debug.c b/zebra/debug.c index 19582bb09..0eb06d7f2 100644 --- a/zebra/debug.c +++ b/zebra/debug.c @@ -275,6 +275,7 @@ DEFUN (debug_zebra_dplane, "Detailed debug information\n") { int idx = 0; + SET_FLAG(zebra_debug_dplane, ZEBRA_DEBUG_DPLANE); if (argv_find(argv, argc, "detailed", &idx)) diff --git a/zebra/kernel_netlink.c b/zebra/kernel_netlink.c index cdfbdd230..08219924f 100644 --- a/zebra/kernel_netlink.c +++ b/zebra/kernel_netlink.c @@ -1011,7 +1011,7 @@ int netlink_talk(int (*filter)(struct nlmsghdr *, ns_id_t, int startup), /* Capture info in intermediate info struct */ zebra_dplane_info_from_zns(&dp_info, zns, (nl == &(zns->netlink_cmd))); - return (netlink_talk_info(filter, n, &dp_info, startup)); + return netlink_talk_info(filter, n, &dp_info, startup); } /* Issue request message to kernel via netlink socket. GET messages diff --git a/zebra/redistribute.h b/zebra/redistribute.h index f67480da9..f0dc79574 100644 --- a/zebra/redistribute.h +++ b/zebra/redistribute.h @@ -38,10 +38,11 @@ extern void zebra_redistribute_default_delete(ZAPI_HANDLER_ARGS); extern void redistribute_update(const struct prefix *p, const struct prefix *src_p, - struct route_entry *, struct route_entry *); + struct route_entry *re, + struct route_entry *prev_re); extern void redistribute_delete(const struct prefix *p, const struct prefix *src_p, - struct route_entry *); + struct route_entry *re); extern void zebra_interface_up_update(struct interface *); extern void zebra_interface_down_update(struct interface *); diff --git a/zebra/rt_netlink.c b/zebra/rt_netlink.c index bbaf89a7c..e5fc27bcc 100644 --- a/zebra/rt_netlink.c +++ b/zebra/rt_netlink.c @@ -1795,7 +1795,7 @@ static int netlink_route_multipath_ctx(int cmd, dplane_ctx_h ctx) family = PREFIX_FAMILY(p); - memset(&req, 0, sizeof req - NL_PKT_BUF_SIZE); + memset(&req, 0, sizeof(req) - NL_PKT_BUF_SIZE); bytelen = (family == AF_INET ? 4 : 16); @@ -1816,11 +1816,10 @@ static int netlink_route_multipath_ctx(int cmd, dplane_ctx_h ctx) req.r.rtm_src_len = src_p ? src_p->prefixlen : 0; req.r.rtm_scope = RT_SCOPE_UNIVERSE; - if (cmd == RTM_DELROUTE) { + if (cmd == RTM_DELROUTE) req.r.rtm_protocol = zebra2proto(dplane_ctx_get_old_type(ctx)); - } else { + else req.r.rtm_protocol = zebra2proto(dplane_ctx_get_type(ctx)); - } /* * blackhole routes are not RTN_UNICAST, they are @@ -1833,9 +1832,9 @@ static int netlink_route_multipath_ctx(int cmd, dplane_ctx_h ctx) if (cmd != RTM_DELROUTE) req.r.rtm_type = RTN_UNICAST; - addattr_l(&req.n, sizeof req, RTA_DST, &p->u.prefix, bytelen); + addattr_l(&req.n, sizeof(req), RTA_DST, &p->u.prefix, bytelen); if (src_p) - addattr_l(&req.n, sizeof req, RTA_SRC, &src_p->u.prefix, + addattr_l(&req.n, sizeof(req), RTA_SRC, &src_p->u.prefix, bytelen); /* Metric. */ @@ -1845,20 +1844,19 @@ static int netlink_route_multipath_ctx(int cmd, dplane_ctx_h ctx) * path(s) * by the routing protocol and for communicating with protocol peers. */ - addattr32(&req.n, sizeof req, RTA_PRIORITY, NL_DEFAULT_ROUTE_METRIC); + addattr32(&req.n, sizeof(req), RTA_PRIORITY, NL_DEFAULT_ROUTE_METRIC); #if defined(SUPPORT_REALMS) { route_tag_t tag; - if (cmd == RTM_DELROUTE) { + if (cmd == RTM_DELROUTE) tag = dplane_ctx_get_old_tag(ctx); - } else { + else tag = dplane_ctx_get_tag(ctx); - } if (tag > 0 && tag <= 255) - addattr32(&req.n, sizeof req, RTA_FLOW, tag); + addattr32(&req.n, sizeof(req), RTA_FLOW, tag); } #endif /* Table corresponding to this route. */ @@ -1867,7 +1865,7 @@ static int netlink_route_multipath_ctx(int cmd, dplane_ctx_h ctx) req.r.rtm_table = table_id; else { req.r.rtm_table = RT_TABLE_UNSPEC; - addattr32(&req.n, sizeof req, RTA_TABLE, table_id); + addattr32(&req.n, sizeof(req), RTA_TABLE, table_id); } _netlink_route_debug(cmd, p, family, dplane_ctx_get_vrf(ctx), table_id); @@ -1886,17 +1884,20 @@ static int netlink_route_multipath_ctx(int cmd, dplane_ctx_h ctx) struct rtattr *rta = (void *)buf; uint32_t mtu = dplane_ctx_get_mtu(ctx); uint32_t nexthop_mtu = dplane_ctx_get_nh_mtu(ctx); + if (!mtu || (nexthop_mtu && nexthop_mtu < mtu)) mtu = nexthop_mtu; rta->rta_type = RTA_METRICS; rta->rta_len = RTA_LENGTH(0); - rta_addattr_l(rta, NL_PKT_BUF_SIZE, RTAX_MTU, &mtu, sizeof mtu); + rta_addattr_l(rta, NL_PKT_BUF_SIZE, + RTAX_MTU, &mtu, sizeof(mtu)); addattr_l(&req.n, NL_PKT_BUF_SIZE, RTA_METRICS, RTA_DATA(rta), RTA_PAYLOAD(rta)); } /* Count overall nexthops so we can decide whether to use singlepath - * or multipath case. */ + * or multipath case. + */ nexthop_num = 0; for (ALL_NEXTHOPS_PTR(dplane_ctx_get_ng(ctx), nexthop)) { if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_RECURSIVE)) @@ -1934,43 +1935,36 @@ static int netlink_route_multipath_ctx(int cmd, dplane_ctx_h ctx) } if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_RECURSIVE)) { - if (!setsrc) { - if (family == AF_INET) { - if (nexthop->rmap_src.ipv4 - .s_addr - != 0) { - src.ipv4 = - nexthop->rmap_src - .ipv4; - setsrc = 1; - } else if (nexthop->src.ipv4 - .s_addr - != 0) { - src.ipv4 = - nexthop->src - .ipv4; - setsrc = 1; - } - } else if (family == AF_INET6) { - if (!IN6_IS_ADDR_UNSPECIFIED( - &nexthop->rmap_src - .ipv6)) { - src.ipv6 = - nexthop->rmap_src - .ipv6; - setsrc = 1; - } else if ( - !IN6_IS_ADDR_UNSPECIFIED( - &nexthop->src - .ipv6)) { - src.ipv6 = - nexthop->src - .ipv6; - setsrc = 1; - } + + if (setsrc) + continue; + + if (family == AF_INET) { + if (nexthop->rmap_src.ipv4.s_addr + != 0) { + src.ipv4 = + nexthop->rmap_src.ipv4; + setsrc = 1; + } else if (nexthop->src.ipv4.s_addr + != 0) { + src.ipv4 = + nexthop->src.ipv4; + setsrc = 1; + } + } else if (family == AF_INET6) { + if (!IN6_IS_ADDR_UNSPECIFIED( + &nexthop->rmap_src.ipv6)) { + src.ipv6 = + nexthop->rmap_src.ipv6; + setsrc = 1; + } else if ( + !IN6_IS_ADDR_UNSPECIFIED( + &nexthop->src.ipv6)) { + src.ipv6 = + nexthop->src.ipv6; + setsrc = 1; } } - continue; } if ((cmd == RTM_NEWROUTE @@ -1981,17 +1975,17 @@ static int netlink_route_multipath_ctx(int cmd, dplane_ctx_h ctx) _netlink_route_build_singlepath( routedesc, bytelen, nexthop, &req.n, - &req.r, sizeof req, cmd); + &req.r, sizeof(req), cmd); nexthop_num++; break; } } if (setsrc && (cmd == RTM_NEWROUTE)) { if (family == AF_INET) - addattr_l(&req.n, sizeof req, RTA_PREFSRC, + addattr_l(&req.n, sizeof(req), RTA_PREFSRC, &src.ipv4, bytelen); else if (family == AF_INET6) - addattr_l(&req.n, sizeof req, RTA_PREFSRC, + addattr_l(&req.n, sizeof(req), RTA_PREFSRC, &src.ipv6, bytelen); } } else { /* Multipath case */ @@ -2012,43 +2006,35 @@ static int netlink_route_multipath_ctx(int cmd, dplane_ctx_h ctx) if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_RECURSIVE)) { /* This only works for IPv4 now */ - if (!setsrc) { - if (family == AF_INET) { - if (nexthop->rmap_src.ipv4 - .s_addr - != 0) { - src.ipv4 = - nexthop->rmap_src - .ipv4; - setsrc = 1; - } else if (nexthop->src.ipv4 - .s_addr - != 0) { - src.ipv4 = - nexthop->src - .ipv4; - setsrc = 1; - } - } else if (family == AF_INET6) { - if (!IN6_IS_ADDR_UNSPECIFIED( - &nexthop->rmap_src - .ipv6)) { - src.ipv6 = - nexthop->rmap_src - .ipv6; - setsrc = 1; - } else if ( - !IN6_IS_ADDR_UNSPECIFIED( - &nexthop->src - .ipv6)) { - src.ipv6 = - nexthop->src - .ipv6; - setsrc = 1; - } + if (setsrc) + continue; + + if (family == AF_INET) { + if (nexthop->rmap_src.ipv4.s_addr + != 0) { + src.ipv4 = + nexthop->rmap_src.ipv4; + setsrc = 1; + } else if (nexthop->src.ipv4.s_addr + != 0) { + src.ipv4 = + nexthop->src.ipv4; + setsrc = 1; + } + } else if (family == AF_INET6) { + if (!IN6_IS_ADDR_UNSPECIFIED( + &nexthop->rmap_src.ipv6)) { + src.ipv6 = + nexthop->rmap_src.ipv6; + setsrc = 1; + } else if ( + !IN6_IS_ADDR_UNSPECIFIED( + &nexthop->src.ipv6)) { + src.ipv6 = + nexthop->src.ipv6; + setsrc = 1; } } - continue; } if ((cmd == RTM_NEWROUTE @@ -2075,10 +2061,10 @@ static int netlink_route_multipath_ctx(int cmd, dplane_ctx_h ctx) } if (setsrc && (cmd == RTM_NEWROUTE)) { if (family == AF_INET) - addattr_l(&req.n, sizeof req, RTA_PREFSRC, + addattr_l(&req.n, sizeof(req), RTA_PREFSRC, &src.ipv4, bytelen); else if (family == AF_INET6) - addattr_l(&req.n, sizeof req, RTA_PREFSRC, + addattr_l(&req.n, sizeof(req), RTA_PREFSRC, &src.ipv6, bytelen); if (IS_ZEBRA_DEBUG_KERNEL) zlog_debug("Setting source"); @@ -2100,7 +2086,7 @@ static int netlink_route_multipath_ctx(int cmd, dplane_ctx_h ctx) skip: /* Destination netlink address. */ - memset(&snl, 0, sizeof snl); + memset(&snl, 0, sizeof(snl)); snl.nl_family = AF_NETLINK; /* Talk to netlink socket. */ @@ -2242,7 +2228,7 @@ enum zebra_dplane_result kernel_route_update(dplane_ctx_h ctx) * of the route delete. If that happens yeah we're * screwed. */ - ret = netlink_route_multipath_ctx(RTM_DELROUTE, ctx); + (void )netlink_route_multipath_ctx(RTM_DELROUTE, ctx); cmd = RTM_NEWROUTE; } diff --git a/zebra/zebra_dplane.c b/zebra/zebra_dplane.c index 03cad8fb3..8fec9fbce 100644 --- a/zebra/zebra_dplane.c +++ b/zebra/zebra_dplane.c @@ -43,13 +43,12 @@ const uint32_t DPLANE_CTX_MAGIC = 0xb97a557f; #ifdef DPLANE_DEBUG -# define DPLANE_CTX_VALID(p) \ - (assert((p) && ((p)->zd_magic == DPLANE_CTX_MAGIC))) +# define DPLANE_CTX_VALID(p) \ + assert((p) && ((p)->zd_magic == DPLANE_CTX_MAGIC)) #else -# define DPLANE_CTX_VALID(p) \ - if ((p) && ((p)->zd_magic == DPLANE_CTX_MAGIC)) { ; } +# define DPLANE_CTX_VALID(p) #endif /* DPLANE_DEBUG */ @@ -61,7 +60,7 @@ const uint32_t DPLANE_CTX_MAGIC = 0xb97a557f; struct zebra_dplane_ctx_s { /* Operation code */ - dplane_op_e zd_op; + enum dplane_op_e zd_op; /* Status on return */ enum zebra_dplane_result zd_status; @@ -127,9 +126,6 @@ struct zebra_dplane_provider_s { /* Id value */ uint32_t dp_id; - /* Event pointer for use by the dplane thread */ -// struct thread *dp_t_event; - dplane_provider_process_fp dp_fp; /* Embedded list linkage */ @@ -181,20 +177,18 @@ static int dplane_route_process(struct thread *event); /* * Allocate a dataplane update context */ -dplane_ctx_h dplane_ctx_alloc(void) +static dplane_ctx_h dplane_ctx_alloc(void) { struct zebra_dplane_ctx_s *p; /* TODO -- just alloc'ing memory, but would like to maintain * a pool */ - p = XCALLOC(MTYPE_DP_CTX, sizeof(struct zebra_dplane_ctx_s)); - if (p) { + if (p) p->zd_magic = DPLANE_CTX_MAGIC; - } - return (p); + return p; } /* @@ -242,9 +236,9 @@ void dplane_ctx_enqueue_tail(struct dplane_ctx_q_s *q, dplane_ctx_h ctx) void dplane_ctx_dequeue(struct dplane_ctx_q_s *q, dplane_ctx_h *ctxp) { dplane_ctx_h ctx = TAILQ_FIRST(q); - if (ctx) { + + if (ctx) TAILQ_REMOVE(q, ctx, zd_q_entries); - } *ctxp = ctx; } @@ -256,21 +250,21 @@ enum zebra_dplane_result dplane_ctx_get_status(const dplane_ctx_h ctx) { DPLANE_CTX_VALID(ctx); - return (ctx->zd_status); + return ctx->zd_status; } -dplane_op_e dplane_ctx_get_op(const dplane_ctx_h ctx) +enum dplane_op_e dplane_ctx_get_op(const dplane_ctx_h ctx) { DPLANE_CTX_VALID(ctx); - return (ctx->zd_op); + return ctx->zd_op; } -const char *dplane_op2str(dplane_op_e op) +const char *dplane_op2str(enum dplane_op_e op) { const char *ret = "UNKNOWN"; - switch(op) { + switch (op) { case DPLANE_OP_NONE: ret = "NONE"; break; @@ -288,28 +282,26 @@ const char *dplane_op2str(dplane_op_e op) }; - return (ret); + return ret; } const struct prefix *dplane_ctx_get_dest(const dplane_ctx_h ctx) { DPLANE_CTX_VALID(ctx); - return (&(ctx->zd_dest)); + return &(ctx->zd_dest); } -/* Source prefix is a little special - use convention like prefix-len of zero - * and all-zeroes address means "no src prefix"? or ... return NULL in that case? - */ +/* Source prefix is a little special - return NULL for "no src prefix" */ const struct prefix *dplane_ctx_get_src(const dplane_ctx_h ctx) { DPLANE_CTX_VALID(ctx); if (ctx->zd_src.prefixlen == 0 && IN6_IS_ADDR_UNSPECIFIED(&(ctx->zd_src.u.prefix6))) { - return (NULL); + return NULL; } else { - return (&(ctx->zd_src)); + return &(ctx->zd_src); } } @@ -317,140 +309,140 @@ bool dplane_ctx_is_update(const dplane_ctx_h ctx) { DPLANE_CTX_VALID(ctx); - return (ctx->zd_is_update); + return ctx->zd_is_update; } uint32_t dplane_ctx_get_seq(const dplane_ctx_h ctx) { DPLANE_CTX_VALID(ctx); - return (ctx->zd_seq); + return ctx->zd_seq; } uint32_t dplane_ctx_get_old_seq(const dplane_ctx_h ctx) { DPLANE_CTX_VALID(ctx); - return (ctx->zd_old_seq); + return ctx->zd_old_seq; } vrf_id_t dplane_ctx_get_vrf(const dplane_ctx_h ctx) { DPLANE_CTX_VALID(ctx); - return (ctx->zd_vrf_id); + return ctx->zd_vrf_id; } int dplane_ctx_get_type(const dplane_ctx_h ctx) { DPLANE_CTX_VALID(ctx); - return (ctx->zd_type); + return ctx->zd_type; } int dplane_ctx_get_old_type(const dplane_ctx_h ctx) { DPLANE_CTX_VALID(ctx); - return (ctx->zd_old_type); + return ctx->zd_old_type; } afi_t dplane_ctx_get_afi(const dplane_ctx_h ctx) { DPLANE_CTX_VALID(ctx); - return (ctx->zd_afi); + return ctx->zd_afi; } safi_t dplane_ctx_get_safi(const dplane_ctx_h ctx) { DPLANE_CTX_VALID(ctx); - return (ctx->zd_safi); + return ctx->zd_safi; } uint32_t dplane_ctx_get_table(const dplane_ctx_h ctx) { DPLANE_CTX_VALID(ctx); - return (ctx->zd_table_id); + return ctx->zd_table_id; } route_tag_t dplane_ctx_get_tag(const dplane_ctx_h ctx) { DPLANE_CTX_VALID(ctx); - return (ctx->zd_tag); + return ctx->zd_tag; } route_tag_t dplane_ctx_get_old_tag(const dplane_ctx_h ctx) { DPLANE_CTX_VALID(ctx); - return (ctx->zd_old_tag); + return ctx->zd_old_tag; } uint16_t dplane_ctx_get_instance(const dplane_ctx_h ctx) { DPLANE_CTX_VALID(ctx); - return (ctx->zd_instance); + return ctx->zd_instance; } uint16_t dplane_ctx_get_old_instance(const dplane_ctx_h ctx) { DPLANE_CTX_VALID(ctx); - return (ctx->zd_instance); + return ctx->zd_instance; } uint32_t dplane_ctx_get_metric(const dplane_ctx_h ctx) { DPLANE_CTX_VALID(ctx); - return (ctx->zd_metric); + return ctx->zd_metric; } uint32_t dplane_ctx_get_mtu(const dplane_ctx_h ctx) { DPLANE_CTX_VALID(ctx); - return (ctx->zd_mtu); + return ctx->zd_mtu; } uint32_t dplane_ctx_get_nh_mtu(const dplane_ctx_h ctx) { DPLANE_CTX_VALID(ctx); - return (ctx->zd_nexthop_mtu); + return ctx->zd_nexthop_mtu; } uint8_t dplane_ctx_get_distance(const dplane_ctx_h ctx) { DPLANE_CTX_VALID(ctx); - return (ctx->zd_distance); + return ctx->zd_distance; } uint8_t dplane_ctx_get_old_distance(const dplane_ctx_h ctx) { DPLANE_CTX_VALID(ctx); - return (ctx->zd_old_distance); + return ctx->zd_old_distance; } const struct nexthop_group *dplane_ctx_get_ng(const dplane_ctx_h ctx) { DPLANE_CTX_VALID(ctx); - return (&(ctx->zd_ng)); + return &(ctx->zd_ng); } const struct zebra_dplane_info *dplane_ctx_get_ns(const dplane_ctx_h ctx) { DPLANE_CTX_VALID(ctx); - return (&(ctx->zd_ns_info)); + return &(ctx->zd_ns_info); } /* @@ -461,7 +453,7 @@ const struct zebra_dplane_info *dplane_ctx_get_ns(const dplane_ctx_h ctx) * Initialize a context block for a route update from zebra data structs. */ static int dplane_ctx_route_init(dplane_ctx_h ctx, - dplane_op_e op, + enum dplane_op_e op, struct route_node *rn, struct route_entry *re) { @@ -472,9 +464,8 @@ static int dplane_ctx_route_init(dplane_ctx_h ctx, struct zebra_ns *zns; struct zebra_vrf *zvrf; - if (!ctx || !rn || !re) { + if (!ctx || !rn || !re) goto done; - } ctx->zd_op = op; @@ -486,11 +477,10 @@ static int dplane_ctx_route_init(dplane_ctx_h ctx, prefix_copy(&(ctx->zd_dest), p); - if (src_p) { + if (src_p) prefix_copy(&(ctx->zd_src), src_p); - } else { + else memset(&(ctx->zd_src), 0, sizeof(ctx->zd_src)); - } ctx->zd_table_id = re->table; @@ -519,11 +509,10 @@ static int dplane_ctx_route_init(dplane_ctx_h ctx, /* Increment message counter after copying to context struct - may need * two messages in some 'update' cases. */ - if (op == DPLANE_OP_ROUTE_UPDATE) { + if (op == DPLANE_OP_ROUTE_UPDATE) zns->netlink_cmd.seq += 2; - } else { + else zns->netlink_cmd.seq++; - } #endif /* NETLINK*/ /* Copy nexthops; recursive info is included too */ @@ -564,7 +553,7 @@ static int dplane_route_enqueue(dplane_ctx_h ctx) ret = AOK; - return (ret); + return ret; } /* @@ -584,7 +573,7 @@ static dplane_ctx_h dplane_route_dequeue(void) } DPLANE_UNLOCK(); - return (ctx); + return ctx; } /* @@ -594,7 +583,7 @@ static enum zebra_dplane_result dplane_route_update_internal(struct route_node *rn, struct route_entry *re, struct route_entry *old_re, - dplane_op_e op) + enum dplane_op_e op) { enum zebra_dplane_result result = ZEBRA_DPLANE_REQUEST_FAILURE; int ret = EINVAL; @@ -631,13 +620,12 @@ dplane_route_update_internal(struct route_node *rn, } done: - if (ret == AOK) { + if (ret == AOK) result = ZEBRA_DPLANE_REQUEST_QUEUED; - } else if (ctx) { + else if (ctx) dplane_ctx_free(&ctx); - } - return (result); + return result; } /* @@ -648,15 +636,14 @@ enum zebra_dplane_result dplane_route_add(struct route_node *rn, { enum zebra_dplane_result ret = ZEBRA_DPLANE_REQUEST_FAILURE; - if (rn == NULL || re == NULL) { + if (rn == NULL || re == NULL) goto done; - } ret = dplane_route_update_internal(rn, re, NULL, DPLANE_OP_ROUTE_INSTALL); done: - return (ret); + return ret; } /* @@ -668,14 +655,13 @@ enum zebra_dplane_result dplane_route_update(struct route_node *rn, { enum zebra_dplane_result ret = ZEBRA_DPLANE_REQUEST_FAILURE; - if (rn == NULL || re == NULL) { + if (rn == NULL || re == NULL) goto done; - } ret = dplane_route_update_internal(rn, re, old_re, DPLANE_OP_ROUTE_UPDATE); done: - return (ret); + return ret; } /* @@ -686,15 +672,14 @@ enum zebra_dplane_result dplane_route_delete(struct route_node *rn, { enum zebra_dplane_result ret = ZEBRA_DPLANE_REQUEST_FAILURE; - if (rn == NULL || re == NULL) { + if (rn == NULL || re == NULL) goto done; - } ret = dplane_route_update_internal(rn, re, NULL, DPLANE_OP_ROUTE_DELETE); done: - return (ret); + return ret; } /* @@ -708,9 +693,8 @@ static int dplane_route_process(struct thread *event) while (1) { /* TODO -- limit number of updates per cycle? */ ctx = dplane_route_dequeue(); - if (ctx == NULL) { + if (ctx == NULL) break; - } /* TODO -- support series of providers */ @@ -736,14 +720,14 @@ static int dplane_route_process(struct thread *event) ctx = NULL; } - return (0); + return 0; } /* * Provider registration */ int dplane_provider_register(const char *name, - dplane_provider_prio_e prio, + enum dplane_provider_prio_e prio, dplane_provider_process_fp fp) { int ret = 0; @@ -778,19 +762,17 @@ int dplane_provider_register(const char *name, /* Insert into list ordered by priority */ TAILQ_FOREACH(last, &zdplane_g.dg_providers_q, dp_q_providers) { - if (last->dp_priority > p->dp_priority) { + if (last->dp_priority > p->dp_priority) break; - } } - if (last) { + if (last) TAILQ_INSERT_BEFORE(last, p, dp_q_providers); - } else { + else TAILQ_INSERT_TAIL(&zdplane_g.dg_providers_q, p, dp_q_providers); - } done: - return (ret); + return ret; } /* @@ -799,7 +781,7 @@ done: int dplane_results_register(dplane_results_fp fp) { zdplane_g.dg_results_cb = fp; - return (AOK); + return AOK; } /* @@ -818,8 +800,6 @@ static void zebra_dplane_init_internal(struct zebra_t *zebra) /* TODO -- using zebra core event thread temporarily */ zdplane_g.dg_master = zebra->master; - - return; } /* diff --git a/zebra/zebra_dplane.h b/zebra/zebra_dplane.h index fcc70e99b..4cd75961a 100644 --- a/zebra/zebra_dplane.h +++ b/zebra/zebra_dplane.h @@ -94,7 +94,7 @@ enum zebra_dplane_result { /* * Enqueue a route install or update for the dataplane. */ -typedef enum { +enum dplane_op_e { DPLANE_OP_NONE = 0, /* Route update */ @@ -102,14 +102,14 @@ typedef enum { DPLANE_OP_ROUTE_UPDATE, DPLANE_OP_ROUTE_DELETE, -} dplane_op_e; +}; /* * Opaque context block used to exchange info between the main zebra * context and the dataplane module(s). If these are two independent pthreads, * they cannot share existing global data structures safely. */ -typedef struct zebra_dplane_ctx_s * dplane_ctx_h; +typedef struct zebra_dplane_ctx_s *dplane_ctx_h; /* Define a tailq list type for context blocks. The list is exposed/public, * but the internal linkage in the context struct is private, so there @@ -117,11 +117,6 @@ typedef struct zebra_dplane_ctx_s * dplane_ctx_h; */ TAILQ_HEAD(dplane_ctx_q_s, zebra_dplane_ctx_s); -/* - * Allocate an opaque context block, currently for a route update. - */ -dplane_ctx_h dplane_ctx_alloc(void); - /* Return a dataplane results context block after use; the caller's pointer will * be cleared. */ @@ -140,13 +135,13 @@ void dplane_ctx_dequeue(struct dplane_ctx_q_s *q, dplane_ctx_h *ctxp); */ enum zebra_dplane_result dplane_ctx_get_status(const dplane_ctx_h ctx); -dplane_op_e dplane_ctx_get_op(const dplane_ctx_h ctx); -const char *dplane_op2str(dplane_op_e op); +enum dplane_op_e dplane_ctx_get_op(const dplane_ctx_h ctx); +const char *dplane_op2str(enum dplane_op_e op); const struct prefix *dplane_ctx_get_dest(const dplane_ctx_h ctx); -/* Source prefix is a little special - use convention like prefix-len of zero - * and all-zeroes address means "no src prefix"? or ... return NULL in that case? +/* Source prefix is a little special - use convention to return NULL + * to mean "no src prefix" */ const struct prefix *dplane_ctx_get_src(const dplane_ctx_h ctx); @@ -186,7 +181,6 @@ enum zebra_dplane_result dplane_route_delete(struct route_node *rn, struct route_entry *re); /* Opaque handle to a dataplane provider plugin */ -typedef struct zebra_dplane_provider_s *dplane_provider_h; #define DPLANE_PROVIDER_NAMELEN 64 @@ -195,21 +189,21 @@ typedef struct zebra_dplane_provider_s *dplane_provider_h; * followed by the kernel, followed by some post-processing step (such as * the fpm output stream.) */ -typedef enum { +enum dplane_provider_prio_e { DPLANE_PRIO_NONE = 0, DPLANE_PRIO_PREPROCESS, DPLANE_PRIO_PRE_KERNEL, DPLANE_PRIO_KERNEL, DPLANE_PRIO_POSTPROCESS, DPLANE_PRIO_LAST -} dplane_provider_prio_e; +}; /* Provider's entry-point to process a context block */ typedef int (*dplane_provider_process_fp)(dplane_ctx_h ctx); /* Provider registration */ int dplane_provider_register(const char *name, - dplane_provider_prio_e prio, + enum dplane_provider_prio_e prio, dplane_provider_process_fp fp); /* diff --git a/zebra/zebra_ns.h b/zebra/zebra_ns.h index ca909ef41..037c7322b 100644 --- a/zebra/zebra_ns.h +++ b/zebra/zebra_ns.h @@ -114,11 +114,10 @@ static inline void zebra_ns_info_from_ns(struct zebra_ns_info *zns_info, */ zns_info->is_cmd = is_cmd; zns_info->nl_cmd_pid = zns->netlink_cmd.snl.nl_pid; - if (is_cmd) { + if (is_cmd) zns_info->nls = zns->netlink_cmd; - } else { + else zns_info->nls = zns->netlink; - } #endif /* NETLINK */ } diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c index bd13248f5..496e0f10b 100644 --- a/zebra/zebra_rib.c +++ b/zebra/zebra_rib.c @@ -1215,11 +1215,10 @@ void rib_install_kernel(struct route_node *rn, struct route_entry *re, hook_call(rib_update, rn, "installing in kernel"); /* Send add or update */ - if (old && (old != re)) { + if (old && (old != re)) ret = dplane_route_update(rn, re, old); - } else { + else ret = dplane_route_add(rn, re); - } switch (ret) { case ZEBRA_DPLANE_REQUEST_QUEUED: @@ -1842,9 +1841,8 @@ static void rib_process(struct route_node *rn) /* Update SELECTED entry */ if (old_selected != new_selected || selected_changed) { - if (new_selected) { + if (new_selected) SET_FLAG(new_selected->flags, ZEBRA_FLAG_SELECTED); - } if (new_selected && new_selected != new_fib) { nexthop_active_update(rn, new_selected, 1); @@ -1947,7 +1945,7 @@ static void rib_process_after(dplane_ctx_h ctx) bool is_update = false; struct nexthop *nexthop; char dest_str[PREFIX_STRLEN] = ""; - dplane_op_e op; + enum dplane_op_e op; enum zebra_dplane_result status; const struct prefix *dest_pfx, *src_pfx; @@ -1975,13 +1973,12 @@ static void rib_process_after(dplane_ctx_h ctx) /* Note well: only capturing the prefix string if debug is enabled here; * unconditional log messages will have to generate the string. */ - if (IS_ZEBRA_DEBUG_DPLANE) { + if (IS_ZEBRA_DEBUG_DPLANE) prefix2str(dest_pfx, dest_str, sizeof(dest_str)); - } src_pfx = dplane_ctx_get_src(ctx); rn = srcdest_rnode_get(table, dplane_ctx_get_dest(ctx), - src_pfx ? (struct prefix_ipv6 * )src_pfx : NULL); + src_pfx ? (struct prefix_ipv6 *)src_pfx : NULL); if (rn == NULL) { if (IS_ZEBRA_DEBUG_DPLANE) { zlog_debug("Failed to process dplane results: no " @@ -2011,9 +2008,8 @@ static void rib_process_after(dplane_ctx_h ctx) if (status == ZEBRA_DPLANE_REQUEST_SUCCESS) { zsend_route_notify_owner_ctx(ctx, ZAPI_ROUTE_REMOVED); - if (zvrf) { + if (zvrf) zvrf->removals++; - } } else { zsend_route_notify_owner_ctx(ctx, ZAPI_ROUTE_FAIL_INSTALL); @@ -2041,22 +2037,19 @@ static void rib_process_after(dplane_ctx_h ctx) RNODE_FOREACH_RE(rn, rib) { if (re == NULL) { - if (rib_route_match_ctx(rib, ctx, false)) { + if (rib_route_match_ctx(rib, ctx, false)) re = rib; - } } /* Check for old route match */ if (is_update && (old_re == NULL)) { - if (rib_route_match_ctx(rib, ctx, true /*is_update*/)) { + if (rib_route_match_ctx(rib, ctx, true /*is_update*/)) old_re = rib; - } } /* Have we found the routes we need to work on? */ - if (re && ((!is_update || old_re))) { + if (re && ((!is_update || old_re))) break; - } } /* @@ -2102,9 +2095,8 @@ static void rib_process_after(dplane_ctx_h ctx) UNSET_FLAG(nexthop->flags, NEXTHOP_FLAG_FIB); } - if (zvrf) { + if (zvrf) zvrf->installs++; - } /* Redistribute */ /* TODO -- still calling the redist api using the route_entries, @@ -3295,15 +3287,14 @@ static int rib_process_dplane_results(struct thread *thread) } pthread_mutex_unlock(&dplane_mutex); - if (ctx) { + if (ctx) rib_process_after(ctx); - } else { + else break; - } - } while(1); + } while (1); - return (0); + return 0; } /* @@ -3325,7 +3316,7 @@ static int rib_dplane_results(dplane_ctx_h ctx) thread_add_event(zebrad.master, rib_process_dplane_results, NULL, 0, &t_dplane); - return (0); + return 0; } /* Routing information base initialize. */ |