diff options
Diffstat (limited to 'zebra')
| -rw-r--r-- | zebra/dplane_fpm_nl.c | 16 | ||||
| -rw-r--r-- | zebra/zebra_evpn_mh.c | 2 | ||||
| -rw-r--r-- | zebra/zebra_netns_notify.c | 15 | ||||
| -rw-r--r-- | zebra/zebra_srv6_vty.c | 12 | ||||
| -rw-r--r-- | zebra/zebra_vty.c | 99 | ||||
| -rw-r--r-- | zebra/zebra_vxlan.c | 81 |
6 files changed, 117 insertions, 108 deletions
diff --git a/zebra/dplane_fpm_nl.c b/zebra/dplane_fpm_nl.c index 245b799a91..9ad92d6269 100644 --- a/zebra/dplane_fpm_nl.c +++ b/zebra/dplane_fpm_nl.c @@ -654,14 +654,6 @@ static void fpm_read(struct event *t) hdr_available_bytes = fpm.msg_len - FPM_MSG_HDR_LEN; available_bytes -= hdr_available_bytes; - /* Sanity check: must be at least header size. */ - if (hdr->nlmsg_len < sizeof(*hdr)) { - zlog_warn( - "%s: [seq=%u] invalid message length %u (< %zu)", - __func__, hdr->nlmsg_seq, hdr->nlmsg_len, - sizeof(*hdr)); - continue; - } if (hdr->nlmsg_len > fpm.msg_len) { zlog_warn( "%s: Received a inner header length of %u that is greater than the fpm total length of %u", @@ -691,6 +683,14 @@ static void fpm_read(struct event *t) switch (hdr->nlmsg_type) { case RTM_NEWROUTE: + /* Sanity check: need at least route msg header size. */ + if (hdr->nlmsg_len < sizeof(struct rtmsg)) { + zlog_warn("%s: [seq=%u] invalid message length %u (< %zu)", + __func__, hdr->nlmsg_seq, + hdr->nlmsg_len, sizeof(struct rtmsg)); + break; + } + ctx = dplane_ctx_alloc(); dplane_ctx_route_init(ctx, DPLANE_OP_ROUTE_NOTIFY, NULL, NULL); diff --git a/zebra/zebra_evpn_mh.c b/zebra/zebra_evpn_mh.c index 5c19d226b1..75e7e20176 100644 --- a/zebra/zebra_evpn_mh.c +++ b/zebra/zebra_evpn_mh.c @@ -3026,7 +3026,7 @@ void zebra_evpn_es_if_oper_state_change(struct zebra_if *zif, bool up) } static char *zebra_evpn_es_vtep_str(char *vtep_str, struct zebra_evpn_es *es, - uint8_t vtep_str_size) + size_t vtep_str_size) { struct zebra_evpn_es_vtep *zvtep; struct listnode *node; diff --git a/zebra/zebra_netns_notify.c b/zebra/zebra_netns_notify.c index 617a2225f8..fb326b0ddf 100644 --- a/zebra/zebra_netns_notify.c +++ b/zebra/zebra_netns_notify.c @@ -15,6 +15,7 @@ #include <sched.h> #endif #include <dirent.h> +#include <libgen.h> #include <sys/inotify.h> #include <sys/stat.h> @@ -234,6 +235,7 @@ static void zebra_ns_ready_read(struct event *t) { struct zebra_netns_info *zns_info = EVENT_ARG(t); const char *netnspath; + const char *netnspath_basename; int err, stop_retry = 0; if (!zns_info) @@ -261,23 +263,24 @@ static void zebra_ns_ready_read(struct event *t) zebra_ns_continue_read(zns_info, stop_retry); return; } + netnspath_basename = basename(strdupa(netnspath)); /* check default name is not already set */ - if (strmatch(VRF_DEFAULT_NAME, basename(netnspath))) { - zlog_warn("NS notify : NS %s is already default VRF.Cancel VRF Creation", basename(netnspath)); + if (strmatch(VRF_DEFAULT_NAME, netnspath_basename)) { + zlog_warn("NS notify : NS %s is already default VRF.Cancel VRF Creation", netnspath_basename); zebra_ns_continue_read(zns_info, 1); return; } - if (zebra_ns_notify_is_default_netns(basename(netnspath))) { + if (zebra_ns_notify_is_default_netns(netnspath_basename)) { zlog_warn( "NS notify : NS %s is default VRF. Ignore VRF creation", - basename(netnspath)); + netnspath_basename); zebra_ns_continue_read(zns_info, 1); return; } /* success : close fd and create zns context */ - zebra_ns_notify_create_context_from_entry_name(basename(netnspath)); + zebra_ns_notify_create_context_from_entry_name(netnspath_basename); zebra_ns_continue_read(zns_info, 1); } @@ -396,7 +399,7 @@ void zebra_ns_notify_parse(void) continue; } /* check default name is not already set */ - if (strmatch(VRF_DEFAULT_NAME, basename(dent->d_name))) { + if (strmatch(VRF_DEFAULT_NAME, basename(strdupa(dent->d_name)))) { zlog_warn("NS notify : NS %s is already default VRF.Cancel VRF Creation", dent->d_name); continue; } diff --git a/zebra/zebra_srv6_vty.c b/zebra/zebra_srv6_vty.c index c5b8505992..d5cd30e64b 100644 --- a/zebra/zebra_srv6_vty.c +++ b/zebra/zebra_srv6_vty.c @@ -475,16 +475,24 @@ static int zebra_sr_config(struct vty *vty) struct listnode *node; struct srv6_locator *locator; char str[256]; + bool display_source_srv6 = false; + + if (srv6 && !IPV6_ADDR_SAME(&srv6->encap_src_addr, &in6addr_any)) + display_source_srv6 = true; vty_out(vty, "!\n"); - if (zebra_srv6_is_enable()) { + if (display_source_srv6 || zebra_srv6_is_enable()) { vty_out(vty, "segment-routing\n"); vty_out(vty, " srv6\n"); + } + if (display_source_srv6) { if (!IPV6_ADDR_SAME(&srv6->encap_src_addr, &in6addr_any)) { vty_out(vty, " encapsulation\n"); vty_out(vty, " source-address %pI6\n", &srv6->encap_src_addr); } + } + if (zebra_srv6_is_enable()) { vty_out(vty, " locators\n"); for (ALL_LIST_ELEMENTS_RO(srv6->locators, node, locator)) { inet_ntop(AF_INET6, &locator->prefix.prefix, @@ -514,6 +522,8 @@ static int zebra_sr_config(struct vty *vty) vty_out(vty, " !\n"); vty_out(vty, " exit\n"); vty_out(vty, " !\n"); + } + if (display_source_srv6 || zebra_srv6_is_enable()) { vty_out(vty, "exit\n"); vty_out(vty, "!\n"); } diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index 44720754ba..c31218a7c3 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -60,8 +60,8 @@ struct route_show_ctx { }; static int do_show_ip_route(struct vty *vty, const char *vrf_name, afi_t afi, - safi_t safi, bool use_fib, json_object *vrf_json, - bool use_json, route_tag_t tag, + safi_t safi, bool use_fib, bool use_json, + route_tag_t tag, const struct prefix *longer_prefix_p, bool supernets_only, int type, unsigned short ospf_instance_id, uint32_t tableid, @@ -153,8 +153,8 @@ DEFPY (show_ip_rpf, }; return do_show_ip_route(vty, VRF_DEFAULT_NAME, ip ? AFI_IP : AFI_IP6, - SAFI_MULTICAST, false, NULL, uj, 0, NULL, false, - 0, 0, 0, false, &ctx); + SAFI_MULTICAST, false, uj, 0, NULL, false, 0, 0, + 0, false, &ctx); } DEFPY (show_ip_rpf_addr, @@ -858,19 +858,20 @@ static void vty_show_ip_route_detail_json(struct vty *vty, vty_json(vty, json); } -static void -do_show_route_helper(struct vty *vty, struct zebra_vrf *zvrf, - struct route_table *table, afi_t afi, bool use_fib, - json_object *vrf_json, route_tag_t tag, - const struct prefix *longer_prefix_p, bool supernets_only, - int type, unsigned short ospf_instance_id, bool use_json, - uint32_t tableid, bool show_ng, struct route_show_ctx *ctx) +static void do_show_route_helper(struct vty *vty, struct zebra_vrf *zvrf, + struct route_table *table, afi_t afi, + bool use_fib, route_tag_t tag, + const struct prefix *longer_prefix_p, + bool supernets_only, int type, + unsigned short ospf_instance_id, bool use_json, + uint32_t tableid, bool show_ng, + struct route_show_ctx *ctx) { struct route_node *rn; struct route_entry *re; + bool first_json = true; int first = 1; rib_dest_t *dest; - json_object *json = NULL; json_object *json_prefix = NULL; uint32_t addr; char buf[BUFSIZ]; @@ -886,9 +887,6 @@ do_show_route_helper(struct vty *vty, struct zebra_vrf *zvrf, * => display the VRF and table if specific */ - if (use_json && !vrf_json) - json = json_object_new_object(); - /* Show all routes. */ for (rn = route_top(table); rn; rn = srcdest_route_next(rn)) { dest = rib_dest_from_rnode(rn); @@ -961,28 +959,20 @@ do_show_route_helper(struct vty *vty, struct zebra_vrf *zvrf, if (json_prefix) { prefix2str(&rn->p, buf, sizeof(buf)); - if (!vrf_json) - json_object_object_add(json, buf, json_prefix); - else - json_object_object_add(vrf_json, buf, - json_prefix); + vty_json_key(vty, buf, &first_json); + vty_json_no_pretty(vty, json_prefix); + json_prefix = NULL; } } - /* - * This is an extremely expensive operation at scale - * and non-pretty reduces memory footprint significantly. - */ - if (use_json && !vrf_json) { - vty_json_no_pretty(vty, json); - json = NULL; - } + if (use_json) + vty_json_close(vty, first_json); } static void do_show_ip_route_all(struct vty *vty, struct zebra_vrf *zvrf, - afi_t afi, bool use_fib, json_object *vrf_json, - bool use_json, route_tag_t tag, + afi_t afi, bool use_fib, bool use_json, + route_tag_t tag, const struct prefix *longer_prefix_p, bool supernets_only, int type, unsigned short ospf_instance_id, bool show_ng, @@ -1002,15 +992,15 @@ static void do_show_ip_route_all(struct vty *vty, struct zebra_vrf *zvrf, continue; do_show_ip_route(vty, zvrf_name(zvrf), afi, SAFI_UNICAST, - use_fib, vrf_json, use_json, tag, - longer_prefix_p, supernets_only, type, - ospf_instance_id, zrt->tableid, show_ng, ctx); + use_fib, use_json, tag, longer_prefix_p, + supernets_only, type, ospf_instance_id, + zrt->tableid, show_ng, ctx); } } static int do_show_ip_route(struct vty *vty, const char *vrf_name, afi_t afi, - safi_t safi, bool use_fib, json_object *vrf_json, - bool use_json, route_tag_t tag, + safi_t safi, bool use_fib, bool use_json, + route_tag_t tag, const struct prefix *longer_prefix_p, bool supernets_only, int type, unsigned short ospf_instance_id, uint32_t tableid, @@ -1045,7 +1035,7 @@ static int do_show_ip_route(struct vty *vty, const char *vrf_name, afi_t afi, return CMD_SUCCESS; } - do_show_route_helper(vty, zvrf, table, afi, use_fib, vrf_json, tag, + do_show_route_helper(vty, zvrf, table, afi, use_fib, tag, longer_prefix_p, supernets_only, type, ospf_instance_id, use_json, tableid, show_ng, ctx); @@ -1744,13 +1734,13 @@ DEFPY (show_route, "Nexthop Group Information\n") { afi_t afi = ipv4 ? AFI_IP : AFI_IP6; + bool first_vrf_json = true; struct vrf *vrf; int type = 0; struct zebra_vrf *zvrf; struct route_show_ctx ctx = { .multi = vrf_all || table_all, }; - json_object *root_json = NULL; if (!vrf_is_backend_netns()) { if ((vrf_all || vrf_name) && (table || table_all)) { @@ -1772,43 +1762,30 @@ DEFPY (show_route, } if (vrf_all) { - if (!!json) - root_json = json_object_new_object(); RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { - json_object *vrf_json = NULL; - if ((zvrf = vrf->info) == NULL || (zvrf->table[afi][SAFI_UNICAST] == NULL)) continue; - - if (!!json) - vrf_json = json_object_new_object(); - + if (json) + vty_json_key(vty, zvrf_name(zvrf), + &first_vrf_json); if (table_all) do_show_ip_route_all(vty, zvrf, afi, !!fib, - vrf_json, !!json, tag, + !!json, tag, prefix_str ? prefix : NULL, !!supernets_only, type, ospf_instance_id, !!ng, &ctx); else do_show_ip_route(vty, zvrf_name(zvrf), afi, - SAFI_UNICAST, !!fib, vrf_json, - !!json, tag, - prefix_str ? prefix : NULL, + SAFI_UNICAST, !!fib, !!json, + tag, prefix_str ? prefix : NULL, !!supernets_only, type, ospf_instance_id, table, !!ng, &ctx); - - if (!!json) - json_object_object_add(root_json, - zvrf_name(zvrf), - vrf_json); - } - if (!!json) { - vty_json_no_pretty(vty, root_json); - root_json = NULL; } + if (json) + vty_json_close(vty, first_vrf_json); } else { vrf_id_t vrf_id = VRF_DEFAULT; @@ -1823,13 +1800,13 @@ DEFPY (show_route, return CMD_SUCCESS; if (table_all) - do_show_ip_route_all(vty, zvrf, afi, !!fib, NULL, !!json, - tag, prefix_str ? prefix : NULL, + do_show_ip_route_all(vty, zvrf, afi, !!fib, !!json, tag, + prefix_str ? prefix : NULL, !!supernets_only, type, ospf_instance_id, !!ng, &ctx); else do_show_ip_route(vty, vrf->name, afi, SAFI_UNICAST, - !!fib, NULL, !!json, tag, + !!fib, !!json, tag, prefix_str ? prefix : NULL, !!supernets_only, type, ospf_instance_id, table, !!ng, &ctx); diff --git a/zebra/zebra_vxlan.c b/zebra/zebra_vxlan.c index 65dc6638bc..b8c11e186a 100644 --- a/zebra/zebra_vxlan.c +++ b/zebra/zebra_vxlan.c @@ -108,10 +108,11 @@ static void zevpn_build_hash_table(void); static unsigned int zebra_vxlan_sg_hash_key_make(const void *p); static bool zebra_vxlan_sg_hash_eq(const void *p1, const void *p2); static void zebra_vxlan_sg_do_deref(struct zebra_vrf *zvrf, - struct in_addr sip, struct in_addr mcast_grp); -static struct zebra_vxlan_sg *zebra_vxlan_sg_do_ref(struct zebra_vrf *vrf, - struct in_addr sip, - struct in_addr mcast_grp); + const struct ipaddr *sip, + const struct in_addr mcast_grp); +static struct zebra_vxlan_sg * +zebra_vxlan_sg_do_ref(struct zebra_vrf *vrf, const struct ipaddr *sip, + const struct in_addr mcast_grp); static void zebra_vxlan_cleanup_sg_table(struct zebra_vrf *zvrf); bool zebra_evpn_do_dup_addr_detect(struct zebra_vrf *zvrf) @@ -5891,7 +5892,10 @@ static int zebra_vxlan_sg_send(struct zebra_vrf *zvrf, zclient_create_header(s, cmd, VRF_DEFAULT); stream_putl(s, IPV4_MAX_BYTELEN); - stream_put(s, &sg->src.s_addr, IPV4_MAX_BYTELEN); + /* + * There is currently no support for IPv6 VTEPs with PIM. + */ + stream_put(s, &sg->src.ipaddr_v4, IPV4_MAX_BYTELEN); stream_put(s, &sg->grp.s_addr, IPV4_MAX_BYTELEN); /* Write packet size. */ @@ -5914,9 +5918,17 @@ static int zebra_vxlan_sg_send(struct zebra_vrf *zvrf, static unsigned int zebra_vxlan_sg_hash_key_make(const void *p) { const struct zebra_vxlan_sg *vxlan_sg = p; + uint32_t hash1; - return (jhash_2words(vxlan_sg->sg.src.s_addr, - vxlan_sg->sg.grp.s_addr, 0)); + if (IS_IPADDR_V4(&vxlan_sg->sg.src)) { + return (jhash_2words(vxlan_sg->sg.src.ipaddr_v4.s_addr, + vxlan_sg->sg.grp.s_addr, 0)); + } else { + hash1 = jhash_1word(vxlan_sg->sg.grp.s_addr, 0); + return jhash2(vxlan_sg->sg.src.ipaddr_v6.s6_addr32, + array_size(vxlan_sg->sg.src.ipaddr_v6.s6_addr32), + hash1); + } } static bool zebra_vxlan_sg_hash_eq(const void *p1, const void *p2) @@ -5924,8 +5936,8 @@ static bool zebra_vxlan_sg_hash_eq(const void *p1, const void *p2) const struct zebra_vxlan_sg *sg1 = p1; const struct zebra_vxlan_sg *sg2 = p2; - return ((sg1->sg.src.s_addr == sg2->sg.src.s_addr) - && (sg1->sg.grp.s_addr == sg2->sg.grp.s_addr)); + return (ipaddr_is_same(&sg1->sg.src, &sg2->sg.src) && + (sg1->sg.grp.s_addr == sg2->sg.grp.s_addr)); } static struct zebra_vxlan_sg *zebra_vxlan_sg_new(struct zebra_vrf *zvrf, @@ -5961,7 +5973,7 @@ static struct zebra_vxlan_sg *zebra_vxlan_sg_add(struct zebra_vrf *zvrf, { struct zebra_vxlan_sg *vxlan_sg; struct zebra_vxlan_sg *parent = NULL; - struct in_addr sip; + struct ipaddr sip; vxlan_sg = zebra_vxlan_sg_find(zvrf, sg); if (vxlan_sg) @@ -5972,9 +5984,9 @@ static struct zebra_vxlan_sg *zebra_vxlan_sg_add(struct zebra_vrf *zvrf, * 2. the XG entry is used by pimd to setup the * vxlan-termination-mroute */ - if (sg->src.s_addr != INADDR_ANY) { + if (!ipaddr_is_zero(&sg->src)) { memset(&sip, 0, sizeof(sip)); - parent = zebra_vxlan_sg_do_ref(zvrf, sip, sg->grp); + parent = zebra_vxlan_sg_do_ref(zvrf, &sip, sg->grp); if (!parent) return NULL; } @@ -5989,7 +6001,7 @@ static struct zebra_vxlan_sg *zebra_vxlan_sg_add(struct zebra_vrf *zvrf, static void zebra_vxlan_sg_del(struct zebra_vxlan_sg *vxlan_sg) { - struct in_addr sip; + struct ipaddr sip; struct zebra_vrf *zvrf; zvrf = vrf_info_lookup(VRF_DEFAULT); @@ -5997,13 +6009,13 @@ static void zebra_vxlan_sg_del(struct zebra_vxlan_sg *vxlan_sg) /* On SG entry deletion remove the reference to its parent XG * entry */ - if (vxlan_sg->sg.src.s_addr != INADDR_ANY) { + if (!ipaddr_is_zero(&vxlan_sg->sg.src)) { memset(&sip, 0, sizeof(sip)); - zebra_vxlan_sg_do_deref(zvrf, sip, vxlan_sg->sg.grp); + zebra_vxlan_sg_do_deref(zvrf, &sip, vxlan_sg->sg.grp); } - zebra_vxlan_sg_send(zvrf, &vxlan_sg->sg, - vxlan_sg->sg_str, ZEBRA_VXLAN_SG_DEL); + zebra_vxlan_sg_send(zvrf, &vxlan_sg->sg, vxlan_sg->sg_str, + ZEBRA_VXLAN_SG_DEL); hash_release(vxlan_sg->zvrf->vxlan_sg_table, vxlan_sg); @@ -6014,14 +6026,15 @@ static void zebra_vxlan_sg_del(struct zebra_vxlan_sg *vxlan_sg) } static void zebra_vxlan_sg_do_deref(struct zebra_vrf *zvrf, - struct in_addr sip, struct in_addr mcast_grp) + const struct ipaddr *sip, + const struct in_addr mcast_grp) { struct zebra_vxlan_sg *vxlan_sg; struct prefix_sg sg; sg.family = AF_INET; sg.prefixlen = IPV4_MAX_BYTELEN; - sg.src = sip; + sg.src = *sip; sg.grp = mcast_grp; vxlan_sg = zebra_vxlan_sg_find(zvrf, &sg); if (!vxlan_sg) @@ -6034,16 +6047,16 @@ static void zebra_vxlan_sg_do_deref(struct zebra_vrf *zvrf, zebra_vxlan_sg_del(vxlan_sg); } -static struct zebra_vxlan_sg *zebra_vxlan_sg_do_ref(struct zebra_vrf *zvrf, - struct in_addr sip, - struct in_addr mcast_grp) +static struct zebra_vxlan_sg * +zebra_vxlan_sg_do_ref(struct zebra_vrf *zvrf, const struct ipaddr *sip, + const struct in_addr mcast_grp) { struct zebra_vxlan_sg *vxlan_sg; struct prefix_sg sg; sg.family = AF_INET; sg.prefixlen = IPV4_MAX_BYTELEN; - sg.src = sip; + sg.src = *sip; sg.grp = mcast_grp; vxlan_sg = zebra_vxlan_sg_add(zvrf, &sg); if (vxlan_sg) @@ -6052,10 +6065,10 @@ static struct zebra_vxlan_sg *zebra_vxlan_sg_do_ref(struct zebra_vrf *zvrf, return vxlan_sg; } -void zebra_vxlan_sg_deref(struct in_addr local_vtep_ip, - struct in_addr mcast_grp) +void zebra_vxlan_sg_deref(struct in_addr local_vtep_ip, struct in_addr mcast_grp) { struct zebra_vrf *zvrf; + struct ipaddr local_vtep_ipaddr; if (local_vtep_ip.s_addr == INADDR_ANY || mcast_grp.s_addr == INADDR_ANY) @@ -6063,20 +6076,26 @@ void zebra_vxlan_sg_deref(struct in_addr local_vtep_ip, zvrf = vrf_info_lookup(VRF_DEFAULT); - zebra_vxlan_sg_do_deref(zvrf, local_vtep_ip, mcast_grp); + SET_IPADDR_V4(&local_vtep_ipaddr); + local_vtep_ipaddr.ipaddr_v4 = local_vtep_ip; + + zebra_vxlan_sg_do_deref(zvrf, &local_vtep_ipaddr, mcast_grp); } void zebra_vxlan_sg_ref(struct in_addr local_vtep_ip, struct in_addr mcast_grp) { struct zebra_vrf *zvrf; + struct ipaddr local_vtep_ipaddr; - if (local_vtep_ip.s_addr == INADDR_ANY - || mcast_grp.s_addr == INADDR_ANY) + if (local_vtep_ip.s_addr == INADDR_ANY || mcast_grp.s_addr == INADDR_ANY) return; zvrf = vrf_info_lookup(VRF_DEFAULT); - zebra_vxlan_sg_do_ref(zvrf, local_vtep_ip, mcast_grp); + SET_IPADDR_V4(&local_vtep_ipaddr); + local_vtep_ipaddr.ipaddr_v4 = local_vtep_ip; + + zebra_vxlan_sg_do_ref(zvrf, &local_vtep_ipaddr, mcast_grp); } static void zebra_vxlan_xg_pre_cleanup(struct hash_bucket *bucket, void *arg) @@ -6086,7 +6105,7 @@ static void zebra_vxlan_xg_pre_cleanup(struct hash_bucket *bucket, void *arg) /* increment the ref count against (*,G) to prevent them from being * deleted */ - if (vxlan_sg->sg.src.s_addr == INADDR_ANY) + if (ipaddr_is_zero(&vxlan_sg->sg.src)) ++vxlan_sg->ref_cnt; } @@ -6095,7 +6114,7 @@ static void zebra_vxlan_xg_post_cleanup(struct hash_bucket *bucket, void *arg) struct zebra_vxlan_sg *vxlan_sg = (struct zebra_vxlan_sg *)bucket->data; /* decrement the dummy ref count against (*,G) to delete them */ - if (vxlan_sg->sg.src.s_addr == INADDR_ANY) { + if (ipaddr_is_zero(&vxlan_sg->sg.src)) { if (vxlan_sg->ref_cnt) --vxlan_sg->ref_cnt; if (!vxlan_sg->ref_cnt) |
