diff options
Diffstat (limited to 'zebra')
35 files changed, 422 insertions, 505 deletions
diff --git a/zebra/connected.c b/zebra/connected.c index 8c4ba163bd..6a1efc3e65 100644 --- a/zebra/connected.c +++ b/zebra/connected.c @@ -259,14 +259,10 @@ void connected_up(struct interface *ifp, struct connected *ifc) /* Schedule LSP forwarding entries for processing, if appropriate. */ if (zvrf->vrf->vrf_id == VRF_DEFAULT) { - if (IS_ZEBRA_DEBUG_MPLS) { - char buf[PREFIX_STRLEN]; - + if (IS_ZEBRA_DEBUG_MPLS) zlog_debug( - "%u: IF %s IP %s address add/up, scheduling MPLS processing", - zvrf->vrf->vrf_id, ifp->name, - prefix2str(&p, buf, sizeof(buf))); - } + "%u: IF %s IP %pFX address add/up, scheduling MPLS processing", + zvrf->vrf->vrf_id, ifp->name, &p); mpls_mark_lsps_for_processing(zvrf, &p); } } @@ -312,8 +308,8 @@ void connected_add_ipv4(struct interface *ifp, int flags, struct in_addr *addr, if (IPV4_ADDR_SAME(addr, dest)) flog_warn( EC_ZEBRA_IFACE_SAME_LOCAL_AS_PEER, - "warning: interface %s has same local and peer address %s, routing protocols may malfunction", - ifp->name, inet_ntoa(*addr)); + "warning: interface %s has same local and peer address %pI4, routing protocols may malfunction", + ifp->name, addr); } else { zlog_debug( "warning: %s called for interface %s with peer flag set, but no peer address supplied", @@ -326,8 +322,8 @@ void connected_add_ipv4(struct interface *ifp, int flags, struct in_addr *addr, if (!dest && (prefixlen == IPV4_MAX_PREFIXLEN) && if_is_pointopoint(ifp)) zlog_debug( - "warning: PtP interface %s with addr %s/%d needs a peer address", - ifp->name, inet_ntoa(*addr), prefixlen); + "warning: PtP interface %s with addr %pI4/%d needs a peer address", + ifp->name, addr, prefixlen); /* Label of this address. */ if (label) @@ -400,14 +396,10 @@ void connected_down(struct interface *ifp, struct connected *ifc) /* Schedule LSP forwarding entries for processing, if appropriate. */ if (zvrf->vrf->vrf_id == VRF_DEFAULT) { - if (IS_ZEBRA_DEBUG_MPLS) { - char buf[PREFIX_STRLEN]; - + if (IS_ZEBRA_DEBUG_MPLS) zlog_debug( - "%u: IF %s IP %s address down, scheduling MPLS processing", - zvrf->vrf->vrf_id, ifp->name, - prefix2str(&p, buf, sizeof(buf))); - } + "%u: IF %s IP %pFX address down, scheduling MPLS processing", + zvrf->vrf->vrf_id, ifp->name, &p); mpls_mark_lsps_for_processing(zvrf, &p); } } @@ -424,14 +416,10 @@ static void connected_delete_helper(struct connected *ifc, struct prefix *p) /* Schedule LSP forwarding entries for processing, if appropriate. */ if (ifp->vrf_id == VRF_DEFAULT) { - if (IS_ZEBRA_DEBUG_MPLS) { - char buf[PREFIX_STRLEN]; - + if (IS_ZEBRA_DEBUG_MPLS) zlog_debug( - "%u: IF %s IP %s address delete, scheduling MPLS processing", - ifp->vrf_id, ifp->name, - prefix2str(p, buf, sizeof(buf))); - } + "%u: IF %s IP %pFX address delete, scheduling MPLS processing", + ifp->vrf_id, ifp->name, p); mpls_mark_lsps_for_processing(vrf_info_lookup(ifp->vrf_id), p); } } diff --git a/zebra/interface.c b/zebra/interface.c index 3210855801..3b7d6f2432 100644 --- a/zebra/interface.c +++ b/zebra/interface.c @@ -1296,8 +1296,6 @@ static void ifs_dump_brief_vty(struct vty *vty, struct vrf *vrf) bool print_header = true; FOR_ALL_INTERFACES (vrf, ifp) { - char global_pfx[PREFIX_STRLEN] = {0}; - char buf[PREFIX_STRLEN] = {0}; bool first_pfx_printed = false; if (print_header) { @@ -1329,17 +1327,17 @@ static void ifs_dump_brief_vty(struct vty *vty, struct vrf *vrf) if (!CHECK_FLAG(connected->flags, ZEBRA_IFA_SECONDARY)) { p = connected->address; - prefix2str(p, buf, sizeof(buf)); if (first_pfx_printed) { - /* padding to prepare row only for ip addr */ + /* padding to prepare row only + * for ip addr */ vty_out(vty, "%-40s", ""); if (list_size > 1) vty_out(vty, "+ "); - vty_out(vty, "%s\n", buf); + vty_out(vty, "%pFX\n", p); } else { if (list_size > 1) vty_out(vty, "+ "); - vty_out(vty, "%s\n", buf); + vty_out(vty, "%pFX\n", p); } first_pfx_printed = true; break; @@ -1361,17 +1359,17 @@ static void ifs_dump_brief_vty(struct vty *vty, struct vrf *vrf) p = connected->address; /* Don't print link local pfx */ if (!IN6_IS_ADDR_LINKLOCAL(&p->u.prefix6)) { - prefix2str(p, global_pfx, PREFIX_STRLEN); if (first_pfx_printed) { - /* padding to prepare row only for ip addr */ + /* padding to prepare row only + * for ip addr */ vty_out(vty, "%-40s", ""); if (v6_list_size > 1) vty_out(vty, "+ "); - vty_out(vty, "%s\n", global_pfx); + vty_out(vty, "%pFX\n", p); } else { if (v6_list_size > 1) vty_out(vty, "+ "); - vty_out(vty, "%s\n", global_pfx); + vty_out(vty, "%pFX\n", p); } first_pfx_printed = true; break; @@ -1496,14 +1494,14 @@ static void if_dump_vty(struct vty *vty, struct interface *ifp) vxlan_info = &zebra_if->l2info.vxl; vty_out(vty, " VxLAN Id %u", vxlan_info->vni); if (vxlan_info->vtep_ip.s_addr != INADDR_ANY) - vty_out(vty, " VTEP IP: %s", - inet_ntoa(vxlan_info->vtep_ip)); + vty_out(vty, " VTEP IP: %pI4", + &vxlan_info->vtep_ip); if (vxlan_info->access_vlan) vty_out(vty, " Access VLAN Id %u\n", vxlan_info->access_vlan); if (vxlan_info->mcast_grp.s_addr != INADDR_ANY) - vty_out(vty, " Mcast Group %s", - inet_ntoa(vxlan_info->mcast_grp)); + vty_out(vty, " Mcast Group %pI4", + &vxlan_info->mcast_grp); if (vxlan_info->ifindex_link && (vxlan_info->link_nsid != NS_UNKNOWN)) { struct interface *ifp; @@ -1609,8 +1607,8 @@ static void if_dump_vty(struct vty *vty, struct interface *ifp) vty_out(vty, " Utilized Bandwidth %g (Byte/s)\n", iflp->use_bw); if (IS_PARAM_SET(iflp, LP_RMT_AS)) - vty_out(vty, " Neighbor ASBR IP: %s AS: %u \n", - inet_ntoa(iflp->rmt_ip), iflp->rmt_as); + vty_out(vty, " Neighbor ASBR IP: %pI4 AS: %u \n", + &iflp->rmt_ip, iflp->rmt_as); } hook_call(zebra_if_extra_info, vty, ifp); @@ -3498,7 +3496,7 @@ static int link_params_config_write(struct vty *vty, struct interface *ifp) if (IS_PARAM_SET(iflp, LP_USE_BW)) vty_out(vty, " use-bw %g\n", iflp->use_bw); if (IS_PARAM_SET(iflp, LP_RMT_AS)) - vty_out(vty, " neighbor %s as %u\n", inet_ntoa(iflp->rmt_ip), + vty_out(vty, " neighbor %pI4 as %u\n", &iflp->rmt_ip, iflp->rmt_as); vty_out(vty, " exit-link-params\n"); return 0; diff --git a/zebra/irdp_main.c b/zebra/irdp_main.c index b868d23a94..936206641f 100644 --- a/zebra/irdp_main.c +++ b/zebra/irdp_main.c @@ -175,7 +175,6 @@ static void irdp_send(struct interface *ifp, struct prefix *p, struct stream *s) { struct zebra_if *zi = ifp->info; struct irdp_interface *irdp = zi->irdp; - char buf[PREFIX_STRLEN]; uint32_t dst; uint32_t ttl = 1; @@ -190,10 +189,11 @@ static void irdp_send(struct interface *ifp, struct prefix *p, struct stream *s) dst = htonl(INADDR_ALLHOSTS_GROUP); if (irdp->flags & IF_DEBUG_MESSAGES) - zlog_debug("IRDP: TX Advert on %s %s Holdtime=%d Preference=%d", - ifp->name, prefix2str(p, buf, sizeof(buf)), - irdp->flags & IF_SHUTDOWN ? 0 : irdp->Lifetime, - get_pref(irdp, p)); + zlog_debug( + "IRDP: TX Advert on %s %pFX Holdtime=%d Preference=%d", + ifp->name, p, + irdp->flags & IF_SHUTDOWN ? 0 : irdp->Lifetime, + get_pref(irdp, p)); send_packet(ifp, s, dst, p, ttl); } @@ -263,9 +263,7 @@ void irdp_advert_off(struct interface *ifp) if (!irdp) return; - if (irdp->t_advertise) - thread_cancel(irdp->t_advertise); - irdp->t_advertise = NULL; + thread_cancel(&irdp->t_advertise); if (ifp->connected) for (ALL_LIST_ELEMENTS(ifp->connected, node, nnode, ifc)) { @@ -300,9 +298,7 @@ void process_solicit(struct interface *ifp) return; irdp->flags |= IF_SOLICIT; - if (irdp->t_advertise) - thread_cancel(irdp->t_advertise); - irdp->t_advertise = NULL; + thread_cancel(&irdp->t_advertise); timer = (frr_weak_random() % MAX_RESPONSE_DELAY) + 1; diff --git a/zebra/irdp_packet.c b/zebra/irdp_packet.c index 502a2f277c..56fd35a736 100644 --- a/zebra/irdp_packet.c +++ b/zebra/irdp_packet.c @@ -79,6 +79,7 @@ static void parse_irdp_packet(char *p, int len, struct interface *ifp) struct zebra_if *zi; struct irdp_interface *irdp; uint16_t saved_chksum; + char buf[PREFIX_STRLEN]; zi = ifp->info; if (!zi) @@ -104,8 +105,8 @@ static void parse_irdp_packet(char *p, int len, struct interface *ifp) if (iplen < ICMP_MINLEN) { flog_err(EC_ZEBRA_IRDP_LEN_MISMATCH, - "IRDP: RX ICMP packet too short from %s\n", - inet_ntoa(src)); + "IRDP: RX ICMP packet too short from %pI4\n", + &src); return; } @@ -115,8 +116,8 @@ static void parse_irdp_packet(char *p, int len, struct interface *ifp) len of IP-header) 14+20 */ if (iplen > IRDP_RX_BUF - 34) { flog_err(EC_ZEBRA_IRDP_LEN_MISMATCH, - "IRDP: RX ICMP packet too long from %s\n", - inet_ntoa(src)); + "IRDP: RX ICMP packet too long from %pI4\n", + &src); return; } @@ -128,8 +129,8 @@ static void parse_irdp_packet(char *p, int len, struct interface *ifp) if (in_cksum(icmp, datalen) != saved_chksum) { flog_warn( EC_ZEBRA_IRDP_BAD_CHECKSUM, - "IRDP: RX ICMP packet from %s. Bad checksum, silently ignored", - inet_ntoa(src)); + "IRDP: RX ICMP packet from %pI4 Bad checksum, silently ignored", + &src); return; } @@ -141,8 +142,8 @@ static void parse_irdp_packet(char *p, int len, struct interface *ifp) if (icmp->code != 0) { flog_warn( EC_ZEBRA_IRDP_BAD_TYPE_CODE, - "IRDP: RX packet type %d from %s. Bad ICMP type code, silently ignored", - icmp->type, inet_ntoa(src)); + "IRDP: RX packet type %d from %pI4 Bad ICMP type code, silently ignored", + icmp->type, &src); return; } @@ -152,11 +153,12 @@ static void parse_irdp_packet(char *p, int len, struct interface *ifp) && !(irdp->flags & IF_BROADCAST))) { flog_warn( EC_ZEBRA_IRDP_BAD_RX_FLAGS, - "IRDP: RX illegal from %s to %s while %s operates in %s; Please correct settings\n", - inet_ntoa(src), + "IRDP: RX illegal from %pI4 to %s while %s operates in %s; Please correct settings\n", + &src, ntohl(ip->ip_dst.s_addr) == INADDR_ALLRTRS_GROUP ? "multicast" - : inet_ntoa(ip->ip_dst), + : inet_ntop(AF_INET, &ip->ip_dst, + buf, sizeof(buf)), ifp->name, irdp->flags & IF_BROADCAST ? "broadcast" : "multicast"); return; @@ -169,8 +171,8 @@ static void parse_irdp_packet(char *p, int len, struct interface *ifp) case ICMP_ROUTERSOLICIT: if (irdp->flags & IF_DEBUG_MESSAGES) - zlog_debug("IRDP: RX Solicit on %s from %s", - ifp->name, inet_ntoa(src)); + zlog_debug("IRDP: RX Solicit on %s from %pI4", + ifp->name, &src); process_solicit(ifp); break; @@ -178,8 +180,8 @@ static void parse_irdp_packet(char *p, int len, struct interface *ifp) default: flog_warn( EC_ZEBRA_IRDP_BAD_TYPE_CODE, - "IRDP: RX packet type %d from %s. Bad ICMP type code, silently ignored", - icmp->type, inet_ntoa(src)); + "IRDP: RX packet type %d from %pI4 Bad ICMP type code, silently ignored", + icmp->type, &src); } } diff --git a/zebra/kernel_netlink.c b/zebra/kernel_netlink.c index c53d28a18c..129703d9a9 100644 --- a/zebra/kernel_netlink.c +++ b/zebra/kernel_netlink.c @@ -1051,7 +1051,7 @@ static int nl_batch_read_resp(struct nl_batch *bth) { struct nlmsghdr *h; struct sockaddr_nl snl; - struct msghdr msg; + struct msghdr msg = {}; int status, seq; const struct nlsock *nl; struct zebra_dplane_ctx *ctx; @@ -1501,7 +1501,7 @@ void kernel_init(struct zebra_ns *zns) void kernel_terminate(struct zebra_ns *zns, bool complete) { - THREAD_READ_OFF(zns->t_netlink); + thread_cancel(&zns->t_netlink); if (zns->netlink.sock >= 0) { close(zns->netlink.sock); diff --git a/zebra/main.c b/zebra/main.c index 6b6409f845..ced29e1a25 100644 --- a/zebra/main.c +++ b/zebra/main.c @@ -170,12 +170,14 @@ static void sigint(void) zebra_ptm_finish(); - if (retain_mode) + if (retain_mode) { + zebra_nhg_mark_keep(); RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { zvrf = vrf->info; if (zvrf) SET_FLAG(zvrf->flags, ZEBRA_VRF_RETAIN); } + } if (zrouter.lsp_process_q) work_queue_free_and_null(&zrouter.lsp_process_q); diff --git a/zebra/redistribute.c b/zebra/redistribute.c index c0f89e6afe..1f075cfb4b 100644 --- a/zebra/redistribute.c +++ b/zebra/redistribute.c @@ -119,18 +119,17 @@ static void zebra_redistribute(struct zserv *client, int type, for (rn = route_top(table); rn; rn = srcdest_route_next(rn)) RNODE_FOREACH_RE (rn, newre) { const struct prefix *dst_p, *src_p; - char buf[PREFIX_STRLEN]; srcdest_rnode_prefixes(rn, &dst_p, &src_p); if (IS_ZEBRA_DEBUG_RIB) zlog_debug( - "%s: client %s %s(%u) checking: selected=%d, type=%d, distance=%d, metric=%d zebra_check_addr=%d", + "%s: client %s %pFX(%u) checking: selected=%d, type=%d, distance=%d, metric=%d zebra_check_addr=%d", __func__, zebra_route_string(client->proto), - prefix2str(dst_p, buf, sizeof(buf)), - vrf_id, CHECK_FLAG(newre->flags, - ZEBRA_FLAG_SELECTED), + dst_p, vrf_id, + CHECK_FLAG(newre->flags, + ZEBRA_FLAG_SELECTED), newre->type, newre->distance, newre->metric, zebra_check_addr(dst_p)); @@ -196,15 +195,13 @@ void redistribute_update(const struct prefix *p, const struct prefix *src_p, struct listnode *node, *nnode; struct zserv *client; int afi; - char buf[PREFIX_STRLEN]; - if (IS_ZEBRA_DEBUG_RIB) { + if (IS_ZEBRA_DEBUG_RIB) zlog_debug( - "(%u:%u):%s: Redist update re %p (%s), old %p (%s)", - re->vrf_id, re->table, prefix2str(p, buf, sizeof(buf)), - re, zebra_route_string(re->type), prev_re, + "(%u:%u):%pFX: Redist update re %p (%s), old %p (%s)", + re->vrf_id, re->table, p, re, + zebra_route_string(re->type), prev_re, prev_re ? zebra_route_string(prev_re->type) : "None"); - } afi = family2afi(p->family); if (!afi) { @@ -214,8 +211,7 @@ void redistribute_update(const struct prefix *p, const struct prefix *src_p, } if (!zebra_check_addr(p)) { if (IS_ZEBRA_DEBUG_RIB) - zlog_debug("Redist update filter prefix %s", - prefix2str(p, buf, sizeof(buf))); + zlog_debug("Redist update filter prefix %pFX", p); return; } @@ -224,10 +220,9 @@ void redistribute_update(const struct prefix *p, const struct prefix *src_p, if (zebra_redistribute_check(re, client, p, afi)) { if (IS_ZEBRA_DEBUG_RIB) { zlog_debug( - "%s: client %s %s(%u:%u), type=%d, distance=%d, metric=%d", + "%s: client %s %pFX(%u:%u), type=%d, distance=%d, metric=%d", __func__, - zebra_route_string(client->proto), - prefix2str(p, buf, sizeof(buf)), + zebra_route_string(client->proto), p, re->vrf_id, re->table, re->type, re->distance, re->metric); } @@ -254,7 +249,6 @@ void redistribute_delete(const struct prefix *p, const struct prefix *src_p, struct listnode *node, *nnode; struct zserv *client; int afi; - char buf[PREFIX_STRLEN]; vrf_id_t vrfid; if (old_re) @@ -265,13 +259,11 @@ void redistribute_delete(const struct prefix *p, const struct prefix *src_p, return; if (IS_ZEBRA_DEBUG_RIB) { - zlog_debug( - "%u:%s: Redist del: re %p (%s), new re %p (%s)", - vrfid, prefix2str(p, buf, sizeof(buf)), - old_re, - old_re ? zebra_route_string(old_re->type) : "None", - new_re, - new_re ? zebra_route_string(new_re->type) : "None"); + zlog_debug("%u:%pFX: Redist del: re %p (%s), new re %p (%s)", + vrfid, p, old_re, + old_re ? zebra_route_string(old_re->type) : "None", + new_re, + new_re ? zebra_route_string(new_re->type) : "None"); } /* Add DISTANCE_INFINITY check. */ @@ -293,8 +285,8 @@ void redistribute_delete(const struct prefix *p, const struct prefix *src_p, if (!zebra_check_addr(p)) { if (IS_ZEBRA_DEBUG_RIB) { zlog_debug( - "%u:%s: Redist del old: skipping invalid prefix", - vrfid, prefix2str(p, buf, sizeof(buf))); + "%u:%pFX: Redist del old: skipping invalid prefix", + vrfid, p); } return; } @@ -541,12 +533,10 @@ void zebra_interface_address_add_update(struct interface *ifp, struct prefix *p; if (IS_ZEBRA_DEBUG_EVENT) { - char buf[PREFIX_STRLEN]; - p = ifc->address; - zlog_debug("MESSAGE: ZEBRA_INTERFACE_ADDRESS_ADD %s on %s(%u)", - prefix2str(p, buf, sizeof(buf)), ifp->name, - ifp->vrf_id); + zlog_debug( + "MESSAGE: ZEBRA_INTERFACE_ADDRESS_ADD %pFX on %s(%u)", + p, ifp->name, ifp->vrf_id); } if (!CHECK_FLAG(ifc->conf, ZEBRA_IFC_REAL)) @@ -580,12 +570,10 @@ void zebra_interface_address_delete_update(struct interface *ifp, struct prefix *p; if (IS_ZEBRA_DEBUG_EVENT) { - char buf[PREFIX_STRLEN]; - p = ifc->address; - zlog_debug("MESSAGE: ZEBRA_INTERFACE_ADDRESS_DELETE %s on %s(%u)", - prefix2str(p, buf, sizeof(buf)), - ifp->name, ifp->vrf_id); + zlog_debug( + "MESSAGE: ZEBRA_INTERFACE_ADDRESS_DELETE %pFX on %s(%u)", + p, ifp->name, ifp->vrf_id); } zebra_vxlan_add_del_gw_macip(ifp, ifc->address, 0); diff --git a/zebra/rt_netlink.c b/zebra/rt_netlink.c index 1ce3c435fe..da0eeb364e 100644 --- a/zebra/rt_netlink.c +++ b/zebra/rt_netlink.c @@ -731,11 +731,10 @@ static int netlink_route_change_read_unicast(struct nlmsghdr *h, ns_id_t ns_id, p.prefixlen = rtm->rtm_dst_len; if (rtm->rtm_src_len != 0) { - char buf[PREFIX_STRLEN]; flog_warn( EC_ZEBRA_UNSUPPORTED_V4_SRCDEST, - "unsupported IPv4 sourcedest route (dest %s vrf %u)", - prefix2str(&p, buf, sizeof(buf)), vrf_id); + "unsupported IPv4 sourcedest route (dest %pFX vrf %u)", + &p, vrf_id); return 0; } @@ -786,12 +785,11 @@ static int netlink_route_change_read_unicast(struct nlmsghdr *h, ns_id_t ns_id, } if (IS_ZEBRA_DEBUG_KERNEL) { - char buf[PREFIX_STRLEN]; char buf2[PREFIX_STRLEN]; + zlog_debug( - "%s %s%s%s vrf %s(%u) table_id: %u metric: %d Admin Distance: %d", - nl_msg_type_to_str(h->nlmsg_type), - prefix2str(&p, buf, sizeof(buf)), + "%s %pFX%s%s vrf %s(%u) table_id: %u metric: %d Admin Distance: %d", + nl_msg_type_to_str(h->nlmsg_type), &p, src_p.prefixlen ? " from " : "", src_p.prefixlen ? prefix2str(&src_p, buf2, sizeof(buf2)) : "", @@ -905,8 +903,6 @@ static int netlink_route_change_read_multicast(struct nlmsghdr *h, int count; int oif[256]; int oif_count = 0; - char sbuf[40]; - char gbuf[40]; char oif_list[256] = "\0"; vrf_id_t vrf; int table; @@ -968,8 +964,6 @@ static int netlink_route_change_read_multicast(struct nlmsghdr *h, struct interface *ifp = NULL; struct zebra_vrf *zvrf = NULL; - strlcpy(sbuf, inet_ntoa(m->sg.src), sizeof(sbuf)); - strlcpy(gbuf, inet_ntoa(m->sg.grp), sizeof(gbuf)); for (count = 0; count < oif_count; count++) { ifp = if_lookup_by_index(oif[count], vrf); char temp[256]; @@ -981,9 +975,10 @@ static int netlink_route_change_read_multicast(struct nlmsghdr *h, zvrf = zebra_vrf_lookup_by_id(vrf); ifp = if_lookup_by_index(iif, vrf); zlog_debug( - "MCAST VRF: %s(%d) %s (%s,%s) IIF: %s(%d) OIF: %s jiffies: %lld", + "MCAST VRF: %s(%d) %s (%pI4,%pI4) IIF: %s(%d) OIF: %s jiffies: %lld", zvrf_name(zvrf), vrf, nl_msg_type_to_str(h->nlmsg_type), - sbuf, gbuf, ifp ? ifp->name : "Unknown", iif, oif_list, + &m->sg.src, &m->sg.grp, ifp ? ifp->name : "Unknown", + iif, oif_list, m->lastused); } return 0; @@ -2892,8 +2887,8 @@ static int netlink_macfdb_change(struct nlmsghdr *h, int len, ns_id_t ns_id) dst_present = 1; memcpy(&vtep_ip.s_addr, RTA_DATA(tb[NDA_DST]), IPV4_MAX_BYTELEN); - snprintf(dst_buf, sizeof(dst_buf), " dst %s", - inet_ntoa(vtep_ip)); + snprintfrr(dst_buf, sizeof(dst_buf), " dst %pI4", + &vtep_ip); } if (tb[NDA_NH_ID]) @@ -3950,8 +3945,8 @@ static int netlink_fdb_nh_update(uint32_t nh_id, struct in_addr vtep_ip) return -1; if (IS_ZEBRA_DEBUG_KERNEL || IS_ZEBRA_DEBUG_EVPN_MH_NH) { - zlog_debug("Tx %s fdb-nh 0x%x %s", - nl_msg_type_to_str(cmd), nh_id, inet_ntoa(vtep_ip)); + zlog_debug("Tx %s fdb-nh 0x%x %pI4", + nl_msg_type_to_str(cmd), nh_id, &vtep_ip); } return netlink_talk(netlink_talk_filter, &req.n, &zns->netlink_cmd, zns, diff --git a/zebra/rt_socket.c b/zebra/rt_socket.c index a2e15cbd2b..a0f401c334 100644 --- a/zebra/rt_socket.c +++ b/zebra/rt_socket.c @@ -80,19 +80,15 @@ static int kernel_rtm(int cmd, const struct prefix *p, bool gate = false; int error; char gate_buf[INET6_BUFSIZ]; - char prefix_buf[PREFIX_STRLEN]; enum blackhole_type bh_type = BLACKHOLE_UNSPEC; - prefix2str(p, prefix_buf, sizeof(prefix_buf)); - /* * We only have the ability to ADD or DELETE at this point * in time. */ if (cmd != RTM_ADD && cmd != RTM_DELETE) { if (IS_ZEBRA_DEBUG_KERNEL) - zlog_debug("%s: %s odd command %s", - __func__, prefix_buf, + zlog_debug("%s: %pFX odd command %s", __func__, p, lookup_msg(rtm_type_str, cmd, NULL)); return 0; } @@ -237,8 +233,8 @@ static int kernel_rtm(int cmd, const struct prefix *p, if (IS_ZEBRA_DEBUG_KERNEL) { if (!gate) { zlog_debug( - "%s: %s: attention! gate not found for re", - __func__, prefix_buf); + "%s: %pFX: attention! gate not found for re", + __func__, p); } else { switch (p->family) { case AF_INET: @@ -266,8 +262,8 @@ static int kernel_rtm(int cmd, const struct prefix *p, case ZEBRA_ERR_NOERROR: nexthop_num++; if (IS_ZEBRA_DEBUG_KERNEL) - zlog_debug("%s: %s: successfully did NH %s", - __func__, prefix_buf, gate_buf); + zlog_debug("%s: %pFX: successfully did NH %s", + __func__, p, gate_buf); if (cmd == RTM_ADD) SET_FLAG(nexthop->flags, NEXTHOP_FLAG_FIB); break; @@ -289,8 +285,8 @@ static int kernel_rtm(int cmd, const struct prefix *p, default: flog_err( EC_LIB_SYSTEM_CALL, - "%s: %s: rtm_write() unexpectedly returned %d for command %s", - __func__, prefix_buf, error, + "%s: %pFX: rtm_write() unexpectedly returned %d for command %s", + __func__, p, error, lookup_msg(rtm_type_str, cmd, NULL)); break; } @@ -300,8 +296,8 @@ static int kernel_rtm(int cmd, const struct prefix *p, if (nexthop_num == 0) { if (IS_ZEBRA_DEBUG_KERNEL) zlog_debug( - "%s: No useful nexthops were found in RIB prefix %s", - __func__, prefix_buf); + "%s: No useful nexthops were found in RIB prefix %pFX", + __func__, p); return 1; } diff --git a/zebra/rtadv.c b/zebra/rtadv.c index 13b7c150a3..c3add16c56 100644 --- a/zebra/rtadv.c +++ b/zebra/rtadv.c @@ -2337,7 +2337,6 @@ static int rtadv_config_write(struct vty *vty, struct interface *ifp) struct rtadv_prefix *rprefix; struct rtadv_rdnss *rdnss; struct rtadv_dnssl *dnssl; - char buf[PREFIX_STRLEN]; int interval; zif = ifp->info; @@ -2408,8 +2407,7 @@ static int rtadv_config_write(struct vty *vty, struct interface *ifp) for (ALL_LIST_ELEMENTS_RO(zif->rtadv.AdvPrefixList, node, rprefix)) { if ((rprefix->AdvPrefixCreate == PREFIX_SRC_MANUAL) || (rprefix->AdvPrefixCreate == PREFIX_SRC_BOTH)) { - vty_out(vty, " ipv6 nd prefix %s", - prefix2str(&rprefix->prefix, buf, sizeof(buf))); + vty_out(vty, " ipv6 nd prefix %pFX", &rprefix->prefix); if ((rprefix->AdvValidLifetime != RTADV_VALID_LIFETIME) || (rprefix->AdvPreferredLifetime != RTADV_PREFERRED_LIFETIME)) { diff --git a/zebra/rule_netlink.c b/zebra/rule_netlink.c index d6a34327a6..a63504992e 100644 --- a/zebra/rule_netlink.c +++ b/zebra/rule_netlink.c @@ -75,8 +75,6 @@ netlink_rule_msg_encode(int cmd, const struct zebra_dplane_ctx *ctx, } *req = buf; const char *ifname = dplane_ctx_rule_get_ifname(ctx); - char buf1[PREFIX_STRLEN]; - char buf2[PREFIX_STRLEN]; if (buflen < sizeof(*req)) return 0; @@ -141,11 +139,9 @@ netlink_rule_msg_encode(int cmd, const struct zebra_dplane_ctx *ctx, if (IS_ZEBRA_DEBUG_KERNEL) zlog_debug( - "Tx %s family %s IF %s Pref %u Fwmark %u Src %s Dst %s Table %u", + "Tx %s family %s IF %s Pref %u Fwmark %u Src %pFX Dst %pFX Table %u", nl_msg_type_to_str(cmd), nl_family_to_str(family), - ifname, priority, fwmark, - prefix2str(src_ip, buf1, sizeof(buf1)), - prefix2str(dst_ip, buf2, sizeof(buf2)), table); + ifname, priority, fwmark, src_ip, dst_ip, table); return NLMSG_ALIGN(req->n.nlmsg_len); } @@ -231,8 +227,6 @@ int netlink_rule_change(struct nlmsghdr *h, ns_id_t ns_id, int startup) int len; char *ifname; struct zebra_pbr_rule rule = {}; - char buf1[PREFIX_STRLEN]; - char buf2[PREFIX_STRLEN]; uint8_t proto = 0; /* Basic validation followed by extracting attributes. */ @@ -324,17 +318,14 @@ int netlink_rule_change(struct nlmsghdr *h, ns_id_t ns_id, int startup) ret = dplane_pbr_rule_delete(&rule); zlog_debug( - "%s: %s leftover rule: family %s IF %s Pref %u Src %s Dst %s Table %u", + "%s: %s leftover rule: family %s IF %s Pref %u Src %pFX Dst %pFX Table %u", __func__, ((ret == ZEBRA_DPLANE_REQUEST_FAILURE) ? "Failed to remove" : "Removed"), nl_family_to_str(frh->family), rule.ifname, - rule.rule.priority, - prefix2str(&rule.rule.filter.src_ip, buf1, - sizeof(buf1)), - prefix2str(&rule.rule.filter.dst_ip, buf2, - sizeof(buf2)), + rule.rule.priority, &rule.rule.filter.src_ip, + &rule.rule.filter.dst_ip, rule.rule.action.table); } @@ -350,15 +341,11 @@ int netlink_rule_change(struct nlmsghdr *h, ns_id_t ns_id, int startup) if (IS_ZEBRA_DEBUG_KERNEL) zlog_debug( - "Rx %s family %s IF %s Pref %u Src %s Dst %s Table %u", + "Rx %s family %s IF %s Pref %u Src %pFX Dst %pFX Table %u", nl_msg_type_to_str(h->nlmsg_type), nl_family_to_str(frh->family), rule.ifname, - rule.rule.priority, - prefix2str(&rule.rule.filter.src_ip, buf1, - sizeof(buf1)), - prefix2str(&rule.rule.filter.dst_ip, buf2, - sizeof(buf2)), - rule.rule.action.table); + rule.rule.priority, &rule.rule.filter.src_ip, + &rule.rule.filter.dst_ip, rule.rule.action.table); return kernel_pbr_rule_del(&rule); } diff --git a/zebra/zapi_msg.c b/zebra/zapi_msg.c index c33bca3d86..18017c9700 100644 --- a/zebra/zapi_msg.c +++ b/zebra/zapi_msg.c @@ -644,17 +644,12 @@ int zsend_redistribute_route(int cmd, struct zserv *client, return -1; } - if (IS_ZEBRA_DEBUG_SEND) { - char buf_prefix[PREFIX_STRLEN]; - - prefix2str(&api.prefix, buf_prefix, sizeof(buf_prefix)); - - zlog_debug("%s: %s to client %s: type %s, vrf_id %d, p %s", + if (IS_ZEBRA_DEBUG_SEND) + zlog_debug("%s: %s to client %s: type %s, vrf_id %d, p %pFX", __func__, zserv_command_string(cmd), zebra_route_string(client->proto), zebra_route_string(api.type), api.vrf_id, - buf_prefix); - } + &api.prefix); return zserv_send_message(client, s); } @@ -755,26 +750,18 @@ static int route_notify_internal(const struct prefix *p, int type, client = zserv_find_client(type, instance); if (!client || !client->notify_owner) { - if (IS_ZEBRA_DEBUG_PACKET) { - char buff[PREFIX_STRLEN]; - + if (IS_ZEBRA_DEBUG_PACKET) zlog_debug( - "Not Notifying Owner: %s about prefix %s(%u) %d vrf: %u", - zebra_route_string(type), - prefix2str(p, buff, sizeof(buff)), table_id, - note, vrf_id); - } + "Not Notifying Owner: %s about prefix %pFX(%u) %d vrf: %u", + zebra_route_string(type), p, table_id, note, + vrf_id); return 0; } - if (IS_ZEBRA_DEBUG_PACKET) { - char buff[PREFIX_STRLEN]; - - zlog_debug("Notifying Owner: %s about prefix %s(%u) %d vrf: %u", - zebra_route_string(type), - prefix2str(p, buff, sizeof(buff)), table_id, note, - vrf_id); - } + if (IS_ZEBRA_DEBUG_PACKET) + zlog_debug( + "Notifying Owner: %s about prefix %pFX(%u) %d vrf: %u", + zebra_route_string(type), p, table_id, note, vrf_id); s = stream_new(ZEBRA_MAX_PACKET_SIZ); stream_reset(s); @@ -1903,14 +1890,10 @@ static void zread_route_add(ZAPI_HANDLER_ARGS) vrf_id = zvrf_id(zvrf); - if (IS_ZEBRA_DEBUG_RECV) { - char buf_prefix[PREFIX_STRLEN]; - - prefix2str(&api.prefix, buf_prefix, sizeof(buf_prefix)); - zlog_debug("%s: p=(%u:%u)%s, msg flags=0x%x, flags=0x%x", - __func__, vrf_id, api.tableid, buf_prefix, + if (IS_ZEBRA_DEBUG_RECV) + zlog_debug("%s: p=(%u:%u)%pFX, msg flags=0x%x, flags=0x%x", + __func__, vrf_id, api.tableid, &api.prefix, (int)api.message, api.flags); - } /* Allocate new route. */ re = XCALLOC(MTYPE_RE, sizeof(struct route_entry)); @@ -2068,14 +2051,10 @@ static void zread_route_del(ZAPI_HANDLER_ARGS) else table_id = zvrf->table_id; - if (IS_ZEBRA_DEBUG_RECV) { - char buf_prefix[PREFIX_STRLEN]; - - prefix2str(&api.prefix, buf_prefix, sizeof(buf_prefix)); - zlog_debug("%s: p=(%u:%u)%s, msg flags=0x%x, flags=0x%x", - __func__, zvrf_id(zvrf), table_id, buf_prefix, + if (IS_ZEBRA_DEBUG_RECV) + zlog_debug("%s: p=(%u:%u)%pFX, msg flags=0x%x, flags=0x%x", + __func__, zvrf_id(zvrf), table_id, &api.prefix, (int)api.message, api.flags); - } rib_delete(afi, api.safi, zvrf_id(zvrf), api.type, api.instance, api.flags, &api.prefix, src_p, NULL, 0, table_id, api.metric, diff --git a/zebra/zebra_dplane.c b/zebra/zebra_dplane.c index 76d7d00e4a..e93444d22e 100644 --- a/zebra/zebra_dplane.c +++ b/zebra/zebra_dplane.c @@ -2224,20 +2224,14 @@ static int dplane_ctx_rule_init(struct zebra_dplane_ctx *ctx, struct zebra_pbr_rule *new_rule, struct zebra_pbr_rule *old_rule) { - if (IS_ZEBRA_DEBUG_DPLANE_DETAIL) { - char buf1[PREFIX_STRLEN]; - char buf2[PREFIX_STRLEN]; - + if (IS_ZEBRA_DEBUG_DPLANE_DETAIL) zlog_debug( - "init dplane ctx %s: IF %s Prio %u Fwmark %u Src %s Dst %s Table %u", + "init dplane ctx %s: IF %s Prio %u Fwmark %u Src %pFX Dst %pFX Table %u", dplane_op2str(op), new_rule->ifname, new_rule->rule.priority, new_rule->rule.filter.fwmark, - prefix2str(&new_rule->rule.filter.src_ip, buf1, - sizeof(buf1)), - prefix2str(&new_rule->rule.filter.dst_ip, buf2, - sizeof(buf2)), + &new_rule->rule.filter.src_ip, + &new_rule->rule.filter.dst_ip, new_rule->rule.action.table); - } ctx->zd_op = op; ctx->zd_status = ZEBRA_DPLANE_REQUEST_SUCCESS; @@ -2895,15 +2889,10 @@ static enum zebra_dplane_result intf_addr_update_internal( struct zebra_dplane_ctx *ctx = NULL; struct zebra_ns *zns; - if (IS_ZEBRA_DEBUG_DPLANE_DETAIL) { - char addr_str[PREFIX_STRLEN]; - - prefix2str(ifc->address, addr_str, sizeof(addr_str)); - - zlog_debug("init intf ctx %s: idx %d, addr %u:%s", + if (IS_ZEBRA_DEBUG_DPLANE_DETAIL) + zlog_debug("init intf ctx %s: idx %d, addr %u:%pFX", dplane_op2str(op), ifp->ifindex, ifp->vrf_id, - addr_str); - } + ifc->address); ctx = dplane_ctx_alloc(); @@ -3220,8 +3209,8 @@ enum zebra_dplane_result dplane_vtep_add(const struct interface *ifp, struct ipaddr addr; if (IS_ZEBRA_DEBUG_VXLAN) - zlog_debug("Install %s into flood list for VNI %u intf %s(%u)", - inet_ntoa(*ip), vni, ifp->name, ifp->ifindex); + zlog_debug("Install %pI4 into flood list for VNI %u intf %s(%u)", + ip, vni, ifp->name, ifp->ifindex); SET_IPADDR_V4(&addr); addr.ipaddr_v4 = *ip; @@ -3245,8 +3234,8 @@ enum zebra_dplane_result dplane_vtep_delete(const struct interface *ifp, if (IS_ZEBRA_DEBUG_VXLAN) zlog_debug( - "Uninstall %s from flood list for VNI %u intf %s(%u)", - inet_ntoa(*ip), vni, ifp->name, ifp->ifindex); + "Uninstall %pI4 from flood list for VNI %u intf %s(%u)", + ip, vni, ifp->name, ifp->ifindex); SET_IPADDR_V4(&addr); addr.ipaddr_v4 = *ip; @@ -3773,11 +3762,9 @@ static void kernel_dplane_log_detail(struct zebra_dplane_ctx *ctx) case DPLANE_OP_ROUTE_INSTALL: case DPLANE_OP_ROUTE_UPDATE: case DPLANE_OP_ROUTE_DELETE: - prefix2str(dplane_ctx_get_dest(ctx), buf, sizeof(buf)); - - zlog_debug("%u:%s Dplane route update ctx %p op %s", - dplane_ctx_get_vrf(ctx), buf, ctx, - dplane_op2str(dplane_ctx_get_op(ctx))); + zlog_debug("%u:%pFX Dplane route update ctx %p op %s", + dplane_ctx_get_vrf(ctx), dplane_ctx_get_dest(ctx), + ctx, dplane_op2str(dplane_ctx_get_op(ctx))); break; case DPLANE_OP_NH_INSTALL: @@ -3804,11 +3791,10 @@ static void kernel_dplane_log_detail(struct zebra_dplane_ctx *ctx) case DPLANE_OP_ADDR_INSTALL: case DPLANE_OP_ADDR_UNINSTALL: - prefix2str(dplane_ctx_get_intf_addr(ctx), buf, sizeof(buf)); - - zlog_debug("Dplane intf %s, idx %u, addr %s", + zlog_debug("Dplane intf %s, idx %u, addr %pFX", dplane_op2str(dplane_ctx_get_op(ctx)), - dplane_ctx_get_ifindex(ctx), buf); + dplane_ctx_get_ifindex(ctx), + dplane_ctx_get_intf_addr(ctx)); break; case DPLANE_OP_MAC_INSTALL: diff --git a/zebra/zebra_evpn.c b/zebra/zebra_evpn.c index 56699c4e83..6722af117c 100644 --- a/zebra/zebra_evpn.c +++ b/zebra/zebra_evpn.c @@ -109,6 +109,7 @@ void zebra_evpn_print(zebra_evpn_t *zevpn, void **ctxt) json_object *json = NULL; json_object *json_vtep_list = NULL; json_object *json_ip_str = NULL; + char buf[PREFIX_STRLEN]; vty = ctxt[0]; json = ctxt[1]; @@ -134,18 +135,20 @@ void zebra_evpn_print(zebra_evpn_t *zevpn, void **ctxt) if (json == NULL) { vty_out(vty, " VxLAN interface: %s\n", zevpn->vxlan_if->name); vty_out(vty, " VxLAN ifIndex: %u\n", zevpn->vxlan_if->ifindex); - vty_out(vty, " Local VTEP IP: %s\n", - inet_ntoa(zevpn->local_vtep_ip)); - vty_out(vty, " Mcast group: %s\n", - inet_ntoa(zevpn->mcast_grp)); + vty_out(vty, " Local VTEP IP: %pI4\n", + &zevpn->local_vtep_ip); + vty_out(vty, " Mcast group: %pI4\n", + &zevpn->mcast_grp); } else { json_object_string_add(json, "vxlanInterface", zevpn->vxlan_if->name); json_object_int_add(json, "ifindex", zevpn->vxlan_if->ifindex); json_object_string_add(json, "vtepIp", - inet_ntoa(zevpn->local_vtep_ip)); + inet_ntop(AF_INET, &zevpn->local_vtep_ip, + buf, sizeof(buf))); json_object_string_add(json, "mcastGroup", - inet_ntoa(zevpn->mcast_grp)); + inet_ntop(AF_INET, &zevpn->mcast_grp, + buf, sizeof(buf))); json_object_string_add(json, "advertiseGatewayMacip", zevpn->advertise_gw_macip ? "Yes" : "No"); json_object_int_add(json, "numMacs", num_macs); @@ -165,12 +168,14 @@ void zebra_evpn_print(zebra_evpn_t *zevpn, void **ctxt) VXLAN_FLOOD_STR_DEFAULT); if (json == NULL) { - vty_out(vty, " %s flood: %s\n", - inet_ntoa(zvtep->vtep_ip), + vty_out(vty, " %pI4 flood: %s\n", + &zvtep->vtep_ip, flood_str); } else { json_ip_str = json_object_new_string( - inet_ntoa(zvtep->vtep_ip)); + inet_ntop(AF_INET, + &zvtep->vtep_ip, buf, + sizeof(buf))); json_object_array_add(json_vtep_list, json_ip_str); } @@ -207,6 +212,7 @@ void zebra_evpn_print_hash(struct hash_bucket *bucket, void *ctxt[]) json_object *json_evpn = NULL; json_object *json_ip_str = NULL; json_object *json_vtep_list = NULL; + char buf[PREFIX_STRLEN]; vty = ctxt[0]; json = ctxt[1]; @@ -245,7 +251,8 @@ void zebra_evpn_print_hash(struct hash_bucket *bucket, void *ctxt[]) json_vtep_list = json_object_new_array(); for (zvtep = zevpn->vteps; zvtep; zvtep = zvtep->next) { json_ip_str = json_object_new_string( - inet_ntoa(zvtep->vtep_ip)); + inet_ntop(AF_INET, &zvtep->vtep_ip, buf, + sizeof(buf))); json_object_array_add(json_vtep_list, json_ip_str); } @@ -349,7 +356,6 @@ static int ip_prefix_send_to_client(vrf_id_t vrf_id, struct prefix *p, { struct zserv *client = NULL; struct stream *s = NULL; - char buf[PREFIX_STRLEN]; client = zserv_find_client(ZEBRA_ROUTE_BGP, 0); /* BGP may not be running. */ @@ -365,8 +371,7 @@ static int ip_prefix_send_to_client(vrf_id_t vrf_id, struct prefix *p, stream_putw_at(s, 0, stream_get_endp(s)); if (IS_ZEBRA_DEBUG_VXLAN) - zlog_debug("Send ip prefix %s %s on vrf %s", - prefix2str(p, buf, sizeof(buf)), + zlog_debug("Send ip prefix %pFX %s on vrf %s", p, (cmd == ZEBRA_IP_PREFIX_ROUTE_ADD) ? "ADD" : "DEL", vrf_id_to_name(vrf_id)); @@ -1076,8 +1081,8 @@ int zebra_evpn_send_add_to_client(zebra_evpn_t *zevpn) stream_putw_at(s, 0, stream_get_endp(s)); if (IS_ZEBRA_DEBUG_VXLAN) - zlog_debug("Send EVPN_ADD %u %s tenant vrf %s to %s", zevpn->vni, - inet_ntoa(zevpn->local_vtep_ip), + zlog_debug("Send EVPN_ADD %u %pI4 tenant vrf %s to %s", zevpn->vni, + &zevpn->local_vtep_ip, vrf_id_to_name(zevpn->vrf_id), zebra_route_string(client->proto)); diff --git a/zebra/zebra_evpn_mac.c b/zebra/zebra_evpn_mac.c index 75031ddba6..8e9a1a4e8e 100644 --- a/zebra/zebra_evpn_mac.c +++ b/zebra/zebra_evpn_mac.c @@ -417,11 +417,11 @@ static void zebra_evpn_dup_addr_detect_for_mac(struct zebra_vrf *zvrf, if (mac->dad_count >= zvrf->dad_max_moves) { flog_warn(EC_ZEBRA_DUP_MAC_DETECTED, - "VNI %u: MAC %s detected as duplicate during %s VTEP %s", + "VNI %u: MAC %s detected as duplicate during %s VTEP %pI4", mac->zevpn->vni, prefix_mac2str(&mac->macaddr, buf, sizeof(buf)), is_local ? "local update, last" : - "remote update, from", inet_ntoa(vtep_ip)); + "remote update, from", &vtep_ip); SET_FLAG(mac->flags, ZEBRA_MAC_DUPLICATE); @@ -485,6 +485,7 @@ void zebra_evpn_print_mac(zebra_mac_t *mac, void *ctxt, json_object *json) struct listnode *node = NULL; char buf1[ETHER_ADDR_STRLEN]; char buf2[INET6_ADDRSTRLEN]; + char addr_buf[PREFIX_STRLEN]; struct zebra_vrf *zvrf; struct timeval detect_start_time = {0, 0}; char timebuf[MONOTIME_STRLEN]; @@ -518,7 +519,8 @@ void zebra_evpn_print_mac(zebra_mac_t *mac, void *ctxt, json_object *json) json_object_string_add(json_mac, "type", "remote"); json_object_string_add( json_mac, "remoteVtep", - inet_ntoa(mac->fwd_info.r_vtep_ip)); + inet_ntop(AF_INET, &mac->fwd_info.r_vtep_ip, + addr_buf, sizeof(addr_buf))); } else if (CHECK_FLAG(mac->flags, ZEBRA_MAC_AUTO)) json_object_string_add(json_mac, "type", "auto"); @@ -617,8 +619,8 @@ void zebra_evpn_print_mac(zebra_mac_t *mac, void *ctxt, json_object *json) vty_out(vty, " Remote ES: %s", mac->es->esi_str); else - vty_out(vty, " Remote VTEP: %s", - inet_ntoa(mac->fwd_info.r_vtep_ip)); + vty_out(vty, " Remote VTEP: %pI4", + &mac->fwd_info.r_vtep_ip); } else if (CHECK_FLAG(mac->flags, ZEBRA_MAC_AUTO)) { vty_out(vty, " Auto Mac "); } @@ -709,6 +711,7 @@ void zebra_evpn_print_mac_hash(struct hash_bucket *bucket, void *ctxt) json_object *json_mac_hdr = NULL, *json_mac = NULL; zebra_mac_t *mac; char buf1[ETHER_ADDR_STRLEN]; + char addr_buf[PREFIX_STRLEN]; struct mac_walk_ctx *wctx = ctxt; char flags_buf[6]; @@ -785,18 +788,22 @@ void zebra_evpn_print_mac_hash(struct hash_bucket *bucket, void *ctxt) "Intf/Remote ES/VTEP", "VLAN", "Seq #'s"); } + if (mac->es == NULL) + inet_ntop(AF_INET, &mac->fwd_info.r_vtep_ip, + addr_buf, sizeof(addr_buf)); + vty_out(vty, "%-17s %-6s %-5s %-30s %-5s %u/%u\n", buf1, "remote", zebra_evpn_print_mac_flags(mac, flags_buf, - sizeof(flags_buf)), - mac->es ? mac->es->esi_str - : inet_ntoa(mac->fwd_info.r_vtep_ip), + sizeof(flags_buf)), + mac->es ? mac->es->esi_str : addr_buf, "", mac->loc_seq, mac->rem_seq); } else { json_object_string_add(json_mac, "type", "remote"); json_object_string_add( json_mac, "remoteVtep", - inet_ntoa(mac->fwd_info.r_vtep_ip)); + inet_ntop(AF_INET, &mac->fwd_info.r_vtep_ip, + addr_buf, sizeof(addr_buf))); json_object_object_add(json_mac_hdr, buf1, json_mac); json_object_int_add(json_mac, "localSequence", mac->loc_seq); @@ -1769,10 +1776,10 @@ int process_mac_remote_macip_add(zebra_evpn_t *zevpn, struct zebra_vrf *zvrf, mac = zebra_evpn_mac_add(zevpn, macaddr); if (!mac) { zlog_warn( - "Failed to add MAC %s VNI %u Remote VTEP %s", + "Failed to add MAC %s VNI %u Remote VTEP %pI4", prefix_mac2str(macaddr, buf, sizeof(buf)), - zevpn->vni, inet_ntoa(vtep_ip)); + zevpn->vni, &vtep_ip); return -1; } @@ -2028,10 +2035,10 @@ int zebra_evpn_add_update_local_mac(struct zebra_vrf *zvrf, zebra_evpn_t *zevpn, if (CHECK_FLAG(mac->flags, ZEBRA_MAC_STICKY)) { flog_warn( EC_ZEBRA_STICKY_MAC_ALREADY_LEARNT, - "MAC %s already learnt as remote sticky MAC behind VTEP %s VNI %u", + "MAC %s already learnt as remote sticky MAC behind VTEP %pI4 VNI %u", prefix_mac2str(macaddr, buf, sizeof(buf)), - inet_ntoa(mac->fwd_info.r_vtep_ip), + &mac->fwd_info.r_vtep_ip, zevpn->vni); return 0; } diff --git a/zebra/zebra_evpn_mh.c b/zebra/zebra_evpn_mh.c index a406884187..dad019731b 100644 --- a/zebra/zebra_evpn_mh.c +++ b/zebra/zebra_evpn_mh.c @@ -919,9 +919,9 @@ static void zebra_evpn_nh_add(struct zebra_evpn_es_vtep *es_vtep) return; if (IS_ZEBRA_DEBUG_EVPN_MH_NH) - zlog_debug("es %s vtep %s nh 0x%x add", + zlog_debug("es %s vtep %pI4 nh 0x%x add", es_vtep->es->esi_str, - inet_ntoa(es_vtep->vtep_ip), es_vtep->nh_id); + &es_vtep->vtep_ip, es_vtep->nh_id); /* install the NH */ kernel_upd_mac_nh(es_vtep->nh_id, es_vtep->vtep_ip); /* add the NH to the parent NHG */ @@ -936,9 +936,9 @@ static void zebra_evpn_nh_del(struct zebra_evpn_es_vtep *es_vtep) return; if (IS_ZEBRA_DEBUG_EVPN_MH_NH) - zlog_debug("es %s vtep %s nh 0x%x del", + zlog_debug("es %s vtep %pI4 nh 0x%x del", es_vtep->es->esi_str, - inet_ntoa(es_vtep->vtep_ip), es_vtep->nh_id); + &es_vtep->vtep_ip, es_vtep->nh_id); nh_id = es_vtep->nh_id; es_vtep->nh_id = 0; @@ -1024,8 +1024,8 @@ static void zebra_evpn_es_vtep_add(struct zebra_evpn_es *es, if (!es_vtep) { if (IS_ZEBRA_DEBUG_EVPN_MH_ES) - zlog_debug("es %s vtep %s add", - es->esi_str, inet_ntoa(vtep_ip)); + zlog_debug("es %s vtep %pI4 add", + es->esi_str, &vtep_ip); es_vtep = zebra_evpn_es_vtep_new(es, vtep_ip); /* update the L2-NHG associated with the ES */ zebra_evpn_nh_add(es_vtep); @@ -1041,8 +1041,8 @@ static void zebra_evpn_es_vtep_del(struct zebra_evpn_es *es, if (es_vtep) { if (IS_ZEBRA_DEBUG_EVPN_MH_ES) - zlog_debug("es %s vtep %s del", - es->esi_str, inet_ntoa(vtep_ip)); + zlog_debug("es %s vtep %pI4 del", + es->esi_str, &vtep_ip); zebra_evpn_es_vtep_free(es_vtep); } } @@ -1168,9 +1168,9 @@ static int zebra_evpn_es_send_add_to_client(struct zebra_evpn_es *es) stream_putw_at(s, 0, stream_get_endp(s)); if (IS_ZEBRA_DEBUG_EVPN_MH_ES) - zlog_debug("send add local es %s %s to %s", + zlog_debug("send add local es %s %pI4 to %s", es->esi_str, - inet_ntoa(zmh_info->es_originator_ip), + &zmh_info->es_originator_ip, zebra_route_string(client->proto)); client->local_es_add_cnt++; @@ -1498,9 +1498,8 @@ static int zebra_evpn_remote_es_del(esi_t *esi, struct in_addr vtep_ip) struct zebra_evpn_es *es; if (IS_ZEBRA_DEBUG_EVPN_MH_ES) - zlog_debug("remote es %s vtep %s del", - esi_to_str(esi, buf, sizeof(buf)), - inet_ntoa(vtep_ip)); + zlog_debug("remote es %s vtep %pI4 del", + esi_to_str(esi, buf, sizeof(buf)), &vtep_ip); es = zebra_evpn_es_find(esi); if (!es) { @@ -1525,9 +1524,9 @@ static void zebra_evpn_remote_es_flush(struct zebra_evpn_es **esp) for (ALL_LIST_ELEMENTS(es->es_vtep_list, node, nnode, es_vtep)) { if (IS_ZEBRA_DEBUG_EVPN_MH_ES) - zlog_debug("es %s vtep %s flush", + zlog_debug("es %s vtep %pI4 flush", es->esi_str, - inet_ntoa(es_vtep->vtep_ip)); + &es_vtep->vtep_ip); zebra_evpn_es_vtep_free(es_vtep); } zebra_evpn_es_remote_info_re_eval(esp); @@ -1539,9 +1538,8 @@ static int zebra_evpn_remote_es_add(esi_t *esi, struct in_addr vtep_ip) struct zebra_evpn_es *es; if (IS_ZEBRA_DEBUG_EVPN_MH_ES) - zlog_debug("remote es %s vtep %s add", - esi_to_str(esi, buf, sizeof(buf)), - inet_ntoa(vtep_ip)); + zlog_debug("remote es %s vtep %pI4 add", + esi_to_str(esi, buf, sizeof(buf)), &vtep_ip); es = zebra_evpn_es_find(esi); if (!es) { @@ -1756,17 +1754,20 @@ static char *zebra_evpn_es_vtep_str(char *vtep_str, struct zebra_evpn_es *es, { struct zebra_evpn_es_vtep *zvtep; struct listnode *node; + char buf[PREFIX_STRLEN]; bool first = true; vtep_str[0] = '\0'; for (ALL_LIST_ELEMENTS_RO(es->es_vtep_list, node, zvtep)) { if (first) { first = false; - strlcat(vtep_str, inet_ntoa(zvtep->vtep_ip), + strlcat(vtep_str, inet_ntop(AF_INET, &zvtep->vtep_ip, + buf, sizeof(buf)), vtep_str_size); } else { strlcat(vtep_str, ",", vtep_str_size); - strlcat(vtep_str, inet_ntoa(zvtep->vtep_ip), + strlcat(vtep_str, inet_ntop(AF_INET, &zvtep->vtep_ip, + buf, sizeof(buf)), vtep_str_size); } } @@ -1832,8 +1833,8 @@ static void zebra_evpn_es_show_entry_detail(struct vty *vty, vty_out(vty, " Nexthop group: 0x%x\n", es->nhg_id); vty_out(vty, " VTEPs:\n"); for (ALL_LIST_ELEMENTS_RO(es->es_vtep_list, node, zvtep)) - vty_out(vty, " %s nh: 0x%x\n", - inet_ntoa(zvtep->vtep_ip), + vty_out(vty, " %pI4 nh: 0x%x\n", + &zvtep->vtep_ip, zvtep->nh_id); vty_out(vty, "\n"); @@ -2029,8 +2030,8 @@ void zebra_evpn_es_set_base_evpn(zebra_evpn_t *zevpn) zmh_info->es_base_evpn->local_vtep_ip.s_addr; if (IS_ZEBRA_DEBUG_EVPN_MH_ES) - zlog_debug("es originator ip set to %s", - inet_ntoa(zmh_info->es_base_evpn->local_vtep_ip)); + zlog_debug("es originator ip set to %pI4", + &zmh_info->es_base_evpn->local_vtep_ip); /* if originator ip changes we need to update bgp */ for (ALL_LIST_ELEMENTS_RO(zmh_info->local_es_list, node, es)) { diff --git a/zebra/zebra_evpn_neigh.c b/zebra/zebra_evpn_neigh.c index 860dc5b054..bb848255d0 100644 --- a/zebra/zebra_evpn_neigh.c +++ b/zebra/zebra_evpn_neigh.c @@ -1283,12 +1283,12 @@ zebra_evpn_dup_addr_detect_for_neigh(struct zebra_vrf *zvrf, zebra_neigh_t *nbr, if (nbr->dad_count >= zvrf->dad_max_moves) { flog_warn( EC_ZEBRA_DUP_IP_DETECTED, - "VNI %u: MAC %s IP %s detected as duplicate during %s VTEP %s", + "VNI %u: MAC %s IP %s detected as duplicate during %s VTEP %pI4", nbr->zevpn->vni, prefix_mac2str(&nbr->emac, buf, sizeof(buf)), ipaddr2str(&nbr->ip, buf1, sizeof(buf1)), is_local ? "local update, last" : "remote update, from", - inet_ntoa(vtep_ip)); + &vtep_ip); SET_FLAG(nbr->flags, ZEBRA_NEIGH_DUPLICATE); @@ -1790,6 +1790,7 @@ void zebra_evpn_print_neigh(zebra_neigh_t *n, void *ctxt, json_object *json) struct vty *vty; char buf1[ETHER_ADDR_STRLEN]; char buf2[INET6_ADDRSTRLEN]; + char addr_buf[PREFIX_STRLEN]; const char *type_str; const char *state_str; bool flags_present = false; @@ -1867,11 +1868,13 @@ void zebra_evpn_print_neigh(zebra_neigh_t *n, void *ctxt, json_object *json) n->mac->es->esi_str); } else { if (json) - json_object_string_add(json, "remoteVtep", - inet_ntoa(n->r_vtep_ip)); + json_object_string_add( + json, "remoteVtep", + inet_ntop(AF_INET, &n->r_vtep_ip, + addr_buf, sizeof(addr_buf))); else - vty_out(vty, " Remote VTEP: %s\n", - inet_ntoa(n->r_vtep_ip)); + vty_out(vty, " Remote VTEP: %pI4\n", + &n->r_vtep_ip); } } if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_DEF_GW)) { @@ -1952,6 +1955,7 @@ void zebra_evpn_print_neigh_hash(struct hash_bucket *bucket, void *ctxt) zebra_neigh_t *n; char buf1[ETHER_ADDR_STRLEN]; char buf2[INET6_ADDRSTRLEN]; + char addr_buf[PREFIX_STRLEN]; struct neigh_walk_ctx *wctx = ctxt; const char *state_str; char flags_buf[6]; @@ -2006,12 +2010,16 @@ void zebra_evpn_print_neigh_hash(struct hash_bucket *bucket, void *ctxt) if ((wctx->flags & SHOW_REMOTE_NEIGH_FROM_VTEP) && (wctx->count == 0)) zebra_evpn_print_neigh_hdr(vty, wctx); + + if (n->mac->es == NULL) + inet_ntop(AF_INET, &n->r_vtep_ip, + addr_buf, sizeof(addr_buf)); + vty_out(vty, "%*s %-6s %-5s %-8s %-17s %-30s %u/%u\n", -wctx->addr_width, buf2, "remote", zebra_evpn_print_neigh_flags(n, flags_buf, sizeof(flags_buf)), state_str, buf1, - n->mac->es ? n->mac->es->esi_str - : inet_ntoa(n->r_vtep_ip), + n->mac->es ? n->mac->es->esi_str : addr_buf, n->loc_seq, n->rem_seq); } else { json_object_string_add(json_row, "type", "remote"); @@ -2021,8 +2029,10 @@ void zebra_evpn_print_neigh_hash(struct hash_bucket *bucket, void *ctxt) json_object_string_add(json_row, "remoteEs", n->mac->es->esi_str); else - json_object_string_add(json_row, "remoteVtep", - inet_ntoa(n->r_vtep_ip)); + json_object_string_add( + json_row, "remoteVtep", + inet_ntop(AF_INET, &n->r_vtep_ip, + addr_buf, sizeof(addr_buf))); if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_DEF_GW)) json_object_boolean_true_add(json_row, "defaultGateway"); @@ -2133,11 +2143,11 @@ void process_neigh_remote_macip_add(zebra_evpn_t *zevpn, struct zebra_vrf *zvrf, mac, 0); if (!n) { zlog_warn( - "Failed to add Neigh %s MAC %s VNI %u Remote VTEP %s", + "Failed to add Neigh %s MAC %s VNI %u Remote VTEP %pI4", ipaddr2str(ipaddr, buf1, sizeof(buf1)), prefix_mac2str(&mac->macaddr, buf, sizeof(buf)), - zevpn->vni, inet_ntoa(vtep_ip)); + zevpn->vni, &vtep_ip); return; } diff --git a/zebra/zebra_fpm.c b/zebra/zebra_fpm.c index f84c8c1fcc..2bf48c6277 100644 --- a/zebra/zebra_fpm.c +++ b/zebra/zebra_fpm.c @@ -489,7 +489,7 @@ static inline void zfpm_write_on(void) */ static inline void zfpm_read_off(void) { - THREAD_READ_OFF(zfpm_g->t_read); + thread_cancel(&zfpm_g->t_read); } /* @@ -497,12 +497,12 @@ static inline void zfpm_read_off(void) */ static inline void zfpm_write_off(void) { - THREAD_WRITE_OFF(zfpm_g->t_write); + thread_cancel(&zfpm_g->t_write); } static inline void zfpm_connect_off(void) { - THREAD_TIMER_OFF(zfpm_g->t_connect); + thread_cancel(&zfpm_g->t_connect); } /* @@ -1437,7 +1437,6 @@ static inline int zfpm_conn_is_up(void) static int zfpm_trigger_update(struct route_node *rn, const char *reason) { rib_dest_t *dest; - char buf[PREFIX_STRLEN]; /* * Ignore if the connection is down. We will update the FPM about @@ -1454,8 +1453,8 @@ static int zfpm_trigger_update(struct route_node *rn, const char *reason) } if (reason) { - zfpm_debug("%s triggering update to FPM - Reason: %s", - prefix2str(&rn->p, buf, sizeof(buf)), reason); + zfpm_debug("%pFX triggering update to FPM - Reason: %s", &rn->p, + reason); } SET_FLAG(dest->flags, RIB_DEST_UPDATE_FPM); @@ -1688,7 +1687,7 @@ static void zfpm_stop_stats_timer(void) return; zfpm_debug("Stopping existing stats timer"); - THREAD_TIMER_OFF(zfpm_g->t_stats); + thread_cancel(&zfpm_g->t_stats); } /* @@ -1934,7 +1933,7 @@ static int fpm_remote_srv_write(struct vty *vty) if ((zfpm_g->fpm_server != FPM_DEFAULT_IP && zfpm_g->fpm_server != INADDR_ANY) || (zfpm_g->fpm_port != FPM_DEFAULT_PORT && zfpm_g->fpm_port != 0)) - vty_out(vty, "fpm connection ip %s port %d\n", inet_ntoa(in), + vty_out(vty, "fpm connection ip %pI4 port %d\n", &in, zfpm_g->fpm_port); return 0; diff --git a/zebra/zebra_fpm_dt.c b/zebra/zebra_fpm_dt.c index 81437e72f5..e392722030 100644 --- a/zebra/zebra_fpm_dt.c +++ b/zebra/zebra_fpm_dt.c @@ -181,6 +181,7 @@ static void zfpm_dt_log_fpm_message(Fpm__Message *msg) char *if_name; size_t i; char buf[INET6_ADDRSTRLEN]; + char addr_buf[PREFIX_STRLEN]; union g_addr nh_addr; if (msg->type != FPM__MESSAGE__TYPE__ADD_ROUTE) @@ -213,7 +214,9 @@ static void zfpm_dt_log_fpm_message(Fpm__Message *msg) zfpm_debug("Nexthop - if_index: %d (%s), gateway: %s, ", if_index, if_name ? if_name : "name not specified", - nexthop->address ? inet_ntoa(nh_addr.ipv4) : "None"); + nexthop->address ? + inet_ntop(AF_INET, &nh_addr.ipv4, + addr_buf, sizeof(addr_buf)) : "None"); } } diff --git a/zebra/zebra_fpm_netlink.c b/zebra/zebra_fpm_netlink.c index 2c07413638..44f574073c 100644 --- a/zebra/zebra_fpm_netlink.c +++ b/zebra/zebra_fpm_netlink.c @@ -44,41 +44,6 @@ #include "zebra/zebra_vxlan_private.h" /* - * addr_to_a - * - * Returns string representation of an address of the given AF. - */ -static inline const char *addr_to_a(uint8_t af, void *addr) -{ - if (!addr) - return "<No address>"; - - switch (af) { - - case AF_INET: - return inet_ntoa(*((struct in_addr *)addr)); - case AF_INET6: - return inet6_ntoa(*((struct in6_addr *)addr)); - default: - return "<Addr in unknown AF>"; - } -} - -/* - * prefix_addr_to_a - * - * Convience wrapper that returns a human-readable string for the - * address in a prefix. - */ -static const char *prefix_addr_to_a(struct prefix *prefix) -{ - if (!prefix) - return "<No address>"; - - return addr_to_a(prefix->family, &prefix->u.prefix); -} - -/* * af_addr_size * * The size of an address in a given address family. @@ -525,18 +490,24 @@ static void zfpm_log_route_info(struct netlink_route_info *ri, { struct netlink_nh_info *nhi; unsigned int i; + char buf[PREFIX_STRLEN]; - zfpm_debug("%s : %s %s/%d, Proto: %s, Metric: %u", label, + zfpm_debug("%s : %s %s, Proto: %s, Metric: %u", label, nl_msg_type_to_str(ri->nlmsg_type), - prefix_addr_to_a(ri->prefix), ri->prefix->prefixlen, + prefix2str(ri->prefix, buf, sizeof(buf)), nl_rtproto_to_str(ri->rtm_protocol), ri->metric ? *ri->metric : 0); for (i = 0; i < ri->num_nhs; i++) { nhi = &ri->nhs[i]; + + if (ri->af == AF_INET) + inet_ntop(AF_INET, &nhi->gateway, buf, sizeof(buf)); + else + inet_ntop(AF_INET6, &nhi->gateway, buf, sizeof(buf)); + zfpm_debug(" Intf: %u, Gateway: %s, Recursive: %s, Type: %s, Encap type: %s", - nhi->if_index, addr_to_a(ri->af, nhi->gateway), - nhi->recursive ? "yes" : "no", + nhi->if_index, buf, nhi->recursive ? "yes" : "no", nexthop_type_to_str(nhi->type), fpm_nh_encap_type_to_str(nhi->encap_info.encap_type) ); @@ -621,11 +592,11 @@ int zfpm_netlink_encode_mac(struct fpm_mac_info_t *mac, char *in_buf, assert(req->hdr.nlmsg_len < in_buf_len); - zfpm_debug("Tx %s family %s ifindex %u MAC %s DEST %s", + zfpm_debug("Tx %s family %s ifindex %u MAC %s DEST %pI4", nl_msg_type_to_str(req->hdr.nlmsg_type), nl_family_to_str(req->ndm.ndm_family), req->ndm.ndm_ifindex, prefix_mac2str(&mac->macaddr, buf1, sizeof(buf1)), - inet_ntoa(mac->r_vtep_ip)); + &mac->r_vtep_ip); return req->hdr.nlmsg_len; } diff --git a/zebra/zebra_gr.c b/zebra/zebra_gr.c index a4f32dbf39..ca6a33cd52 100644 --- a/zebra/zebra_gr.c +++ b/zebra/zebra_gr.c @@ -490,19 +490,15 @@ static void zebra_gr_process_route_entry(struct zserv *client, struct route_node *rn, struct route_entry *re) { - char buf[PREFIX2STR_BUFFER]; - if ((client == NULL) || (rn == NULL) || (re == NULL)) return; /* If the route is not refreshed after restart, delete the entry */ if (re->uptime < client->restart_time) { - if (IS_ZEBRA_DEBUG_RIB) { - prefix2str(&rn->p, buf, sizeof(buf)); - zlog_debug("%s: Client %s stale route %s is deleted", + if (IS_ZEBRA_DEBUG_RIB) + zlog_debug("%s: Client %s stale route %pFX is deleted", __func__, zebra_route_string(client->proto), - buf); - } + &rn->p); rib_delnode(rn, re); } } diff --git a/zebra/zebra_mpls.c b/zebra/zebra_mpls.c index e0ad4f1cbe..66aea8936e 100644 --- a/zebra/zebra_mpls.c +++ b/zebra/zebra_mpls.c @@ -1502,7 +1502,8 @@ static json_object *nhlfe_json(zebra_nhlfe_t *nhlfe) case NEXTHOP_TYPE_IPV4: case NEXTHOP_TYPE_IPV4_IFINDEX: json_object_string_add(json_nhlfe, "nexthop", - inet_ntoa(nexthop->gate.ipv4)); + inet_ntop(AF_INET, &nexthop->gate.ipv4, + buf, sizeof(buf))); break; case NEXTHOP_TYPE_IPV6: case NEXTHOP_TYPE_IPV6_IFINDEX: @@ -1560,7 +1561,7 @@ static void nhlfe_print(zebra_nhlfe_t *nhlfe, struct vty *vty, switch (nexthop->type) { case NEXTHOP_TYPE_IPV4: case NEXTHOP_TYPE_IPV4_IFINDEX: - vty_out(vty, " via %s", inet_ntoa(nexthop->gate.ipv4)); + vty_out(vty, " via %pI4", &nexthop->gate.ipv4); if (nexthop->ifindex) vty_out(vty, " dev %s", ifindex2ifname(nexthop->ifindex, @@ -2362,10 +2363,9 @@ int zebra_mpls_fec_unregister(struct zebra_vrf *zvrf, struct prefix *p, fec = fec_find(table, p); if (!fec) { - prefix2str(p, buf, BUFSIZ); flog_err(EC_ZEBRA_FEC_RM_FAILED, - "Failed to find FEC %s upon unregister, client %s", - buf, zebra_route_string(client->proto)); + "Failed to find FEC %pFX upon unregister, client %s", + p, zebra_route_string(client->proto)); return -1; } @@ -2530,9 +2530,8 @@ int zebra_mpls_static_fec_add(struct zebra_vrf *zvrf, struct prefix *p, fec = fec_add(table, p, in_label, FEC_FLAG_CONFIGURED, MPLS_INVALID_LABEL_INDEX); if (!fec) { - prefix2str(p, buf, BUFSIZ); flog_err(EC_ZEBRA_FEC_ADD_FAILED, - "Failed to add FEC %s upon config", buf); + "Failed to add FEC %pFX upon config", p); return -1; } @@ -2585,8 +2584,7 @@ int zebra_mpls_static_fec_del(struct zebra_vrf *zvrf, struct prefix *p) } if (IS_ZEBRA_DEBUG_MPLS) { - prefix2str(p, buf, BUFSIZ); - zlog_debug("Delete fec %s label %u label index %u", buf, + zlog_debug("Delete fec %pFX label %u label index %u", p, fec->label, fec->label_index); } @@ -2620,7 +2618,6 @@ int zebra_mpls_write_fec_config(struct vty *vty, struct zebra_vrf *zvrf) struct route_node *rn; int af; zebra_fec_t *fec; - char buf[BUFSIZ]; int write = 0; for (af = AFI_IP; af < AFI_MAX; af++) { @@ -2639,8 +2636,7 @@ int zebra_mpls_write_fec_config(struct vty *vty, struct zebra_vrf *zvrf) continue; write = 1; - prefix2str(&rn->p, buf, BUFSIZ); - vty_out(vty, "mpls label bind %s %s\n", buf, + vty_out(vty, "mpls label bind %pFX %s\n", &rn->p, label2str(fec->label, lstr, BUFSIZ)); } } @@ -2846,7 +2842,7 @@ int mpls_zapi_labels_process(bool add_p, struct zebra_vrf *zvrf, const struct zapi_labels *zl) { int i, counter, ret = 0; - char buf[NEXTHOP_STRLEN], prefix_buf[PREFIX_STRLEN]; + char buf[NEXTHOP_STRLEN]; const struct zapi_nexthop *znh; struct route_table *table; struct route_node *rn = NULL; @@ -2910,12 +2906,10 @@ int mpls_zapi_labels_process(bool add_p, struct zebra_vrf *zvrf, * attempted to manage LSPs before trying to * find a route/FEC, so we'll continue that way. */ - if (IS_ZEBRA_DEBUG_RECV || IS_ZEBRA_DEBUG_MPLS) { - prefix2str(prefix, prefix_buf, - sizeof(prefix_buf)); - zlog_debug("%s: FTN update requested: no route for prefix %s", - __func__, prefix_buf); - } + if (IS_ZEBRA_DEBUG_RECV || IS_ZEBRA_DEBUG_MPLS) + zlog_debug( + "%s: FTN update requested: no route for prefix %pFX", + __func__, prefix); } } @@ -2957,9 +2951,9 @@ int mpls_zapi_labels_process(bool add_p, struct zebra_vrf *zvrf, counter++; } else if (IS_ZEBRA_DEBUG_RECV | IS_ZEBRA_DEBUG_MPLS) { zapi_nexthop2str(znh, buf, sizeof(buf)); - prefix2str(prefix, prefix_buf, sizeof(prefix_buf)); - zlog_debug("%s: Unable to update FEC: prefix %s, label %u, znh %s", - __func__, prefix_buf, zl->local_label, buf); + zlog_debug( + "%s: Unable to update FEC: prefix %pFX, label %u, znh %s", + __func__, prefix, zl->local_label, buf); } } @@ -3007,9 +3001,9 @@ int mpls_zapi_labels_process(bool add_p, struct zebra_vrf *zvrf, counter++; } else if (IS_ZEBRA_DEBUG_RECV | IS_ZEBRA_DEBUG_MPLS) { zapi_nexthop2str(znh, buf, sizeof(buf)); - prefix2str(prefix, prefix_buf, sizeof(prefix_buf)); - zlog_debug("%s: Unable to update backup FEC: prefix %s, label %u, znh %s", - __func__, prefix_buf, zl->local_label, buf); + zlog_debug( + "%s: Unable to update backup FEC: prefix %pFX, label %u, znh %s", + __func__, prefix, zl->local_label, buf); } } diff --git a/zebra/zebra_mroute.c b/zebra/zebra_mroute.c index 583b666e66..3af805558d 100644 --- a/zebra/zebra_mroute.c +++ b/zebra/zebra_mroute.c @@ -47,8 +47,8 @@ void zebra_ipmr_route_stats(ZAPI_HANDLER_ARGS) char sbuf[40]; char gbuf[40]; - strlcpy(sbuf, inet_ntoa(mroute.sg.src), sizeof(sbuf)); - strlcpy(gbuf, inet_ntoa(mroute.sg.grp), sizeof(gbuf)); + inet_ntop(AF_INET, &mroute.sg.src, sbuf, sizeof(sbuf)); + inet_ntop(AF_INET, &mroute.sg.grp, gbuf, sizeof(gbuf)); zlog_debug("Asking for (%s,%s)[%s(%u)] mroute information", sbuf, gbuf, zvrf->vrf->name, zvrf->vrf->vrf_id); diff --git a/zebra/zebra_nb_config.c b/zebra/zebra_nb_config.c index b4ed910b4d..f5a85519bb 100644 --- a/zebra/zebra_nb_config.c +++ b/zebra/zebra_nb_config.c @@ -21,6 +21,7 @@ #include "lib/log.h" #include "lib/northbound.h" +#include "lib/printfrr.h" #include "libfrr.h" #include "lib/command.h" #include "lib/routemap.h" @@ -839,7 +840,6 @@ int lib_interface_zebra_ip_addrs_create(struct nb_cb_create_args *args) { struct interface *ifp; struct prefix prefix; - char buf[PREFIX_STRLEN] = {0}; ifp = nb_running_get_entry(args->dnode, NULL, true); // addr_family = yang_dnode_get_enum(dnode, "./address-family"); @@ -850,15 +850,13 @@ int lib_interface_zebra_ip_addrs_create(struct nb_cb_create_args *args) case NB_EV_VALIDATE: if (prefix.family == AF_INET && ipv4_martian(&prefix.u.prefix4)) { - snprintf(args->errmsg, args->errmsg_len, - "invalid address %s", - prefix2str(&prefix, buf, sizeof(buf))); + snprintfrr(args->errmsg, args->errmsg_len, + "invalid address %pFX", &prefix); return NB_ERR_VALIDATION; } else if (prefix.family == AF_INET6 && ipv6_martian(&prefix.u.prefix6)) { - snprintf(args->errmsg, args->errmsg_len, - "invalid address %s", - prefix2str(&prefix, buf, sizeof(buf))); + snprintfrr(args->errmsg, args->errmsg_len, + "invalid address %pFX", &prefix); return NB_ERR_VALIDATION; } break; diff --git a/zebra/zebra_netns_notify.c b/zebra/zebra_netns_notify.c index 995fa6fb5a..ee2dc7a0ed 100644 --- a/zebra/zebra_netns_notify.c +++ b/zebra/zebra_netns_notify.c @@ -378,7 +378,7 @@ void zebra_ns_notify_close(void) fd = zebra_netns_notify_current->u.fd; if (zebra_netns_notify_current->master != NULL) - thread_cancel(zebra_netns_notify_current); + thread_cancel(&zebra_netns_notify_current); /* auto-removal of notify items */ if (fd > 0) diff --git a/zebra/zebra_nhg.c b/zebra/zebra_nhg.c index f1f6e7e2bf..ebefa020c8 100644 --- a/zebra/zebra_nhg.c +++ b/zebra/zebra_nhg.c @@ -442,11 +442,8 @@ static void *zebra_nhg_hash_alloc(void *arg) /* Mark duplicate nexthops in a group at creation time. */ nexthop_group_mark_duplicates(&(nhe->nhg)); - zebra_nhg_connect_depends(nhe, &(copy->nhg_depends)); - /* Add the ifp now if it's not a group or recursive and has ifindex */ - if (zebra_nhg_depends_is_empty(nhe) && nhe->nhg.nexthop - && nhe->nhg.nexthop->ifindex) { + if (nhe->nhg.nexthop && nhe->nhg.nexthop->ifindex) { struct interface *ifp = NULL; ifp = if_lookup_by_index(nhe->nhg.nexthop->ifindex, @@ -461,7 +458,6 @@ static void *zebra_nhg_hash_alloc(void *arg) nhe->nhg.nexthop->vrf_id, nhe->id); } - return nhe; } @@ -754,7 +750,7 @@ static bool zebra_nhe_find(struct nhg_hash_entry **nhe, /* return value */ * resolving nexthop; or a group of nexthops, where we need * relationships with the corresponding singletons. */ - zebra_nhg_depends_init(lookup); + zebra_nhg_depends_init(newnhe); nh = newnhe->nhg.nexthop; @@ -786,7 +782,14 @@ static bool zebra_nhe_find(struct nhg_hash_entry **nhe, /* return value */ } if (recursive) - SET_FLAG((*nhe)->flags, NEXTHOP_GROUP_RECURSIVE); + SET_FLAG(newnhe->flags, NEXTHOP_GROUP_RECURSIVE); + + /* Attach dependent backpointers to singletons */ + zebra_nhg_connect_depends(newnhe, &newnhe->nhg_depends); + + /** + * Backup Nexthops + */ if (zebra_nhg_get_backup_nhg(newnhe) == NULL || zebra_nhg_get_backup_nhg(newnhe)->nexthop == NULL) @@ -1588,6 +1591,7 @@ void zebra_nhg_free(struct nhg_hash_entry *nhe) void zebra_nhg_hash_free(void *p) { + zebra_nhg_release_all_deps((struct nhg_hash_entry *)p); zebra_nhg_free((struct nhg_hash_entry *)p); } @@ -2711,6 +2715,30 @@ void zebra_nhg_sweep_table(struct hash *hash) hash_iterate(hash, zebra_nhg_sweep_entry, NULL); } +static void zebra_nhg_mark_keep_entry(struct hash_bucket *bucket, void *arg) +{ + struct nhg_hash_entry *nhe = bucket->data; + + UNSET_FLAG(nhe->flags, NEXTHOP_GROUP_INSTALLED); +} + +/* + * When we are shutting down and we have retain mode enabled + * in zebra the process is to mark each vrf that it's + * routes should not be deleted. The problem with that + * is that shutdown actually free's up memory which + * causes the nexthop group's ref counts to go to zero + * we need a way to subtly tell the system to not remove + * the nexthop groups from the kernel at the same time. + * The easiest just looks like that we should not mark + * the nhg's as installed any more and when the ref count + * goes to zero we'll attempt to delete and do nothing + */ +void zebra_nhg_mark_keep(void) +{ + hash_iterate(zrouter.nhgs_id, zebra_nhg_mark_keep_entry, NULL); +} + /* Global control to disable use of kernel nexthops, if available. We can't * force the kernel to support nexthop ids, of course, but we can disable * zebra's use of them, for testing e.g. By default, if the kernel supports @@ -2814,10 +2842,15 @@ struct nhg_hash_entry *zebra_nhg_proto_add(uint32_t id, int type, if (old) { /* * This is a replace, just release NHE from ID for now, The - * depends/dependents may still be used in the replacement. + * depends/dependents may still be used in the replacement so + * we don't touch them other than to remove their refs to their + * old parent. */ replace = true; hash_release(zrouter.nhgs_id, old); + + /* Free all the things */ + zebra_nhg_release_all_deps(old); } new = zebra_nhg_rib_find_nhe(&lookup, afi); @@ -2854,9 +2887,6 @@ struct nhg_hash_entry *zebra_nhg_proto_add(uint32_t id, int type, zebra_nhg_decrement_ref(rb_node_dep->nhe); } - /* Free all the things */ - zebra_nhg_release_all_deps(old); - /* Dont call the dec API, we dont want to uninstall the ID */ old->refcnt = 0; zebra_nhg_free(old); diff --git a/zebra/zebra_nhg.h b/zebra/zebra_nhg.h index 052fa65d06..b2ef88bb61 100644 --- a/zebra/zebra_nhg.h +++ b/zebra/zebra_nhg.h @@ -324,9 +324,16 @@ struct zebra_dplane_ctx; extern void zebra_nhg_dplane_result(struct zebra_dplane_ctx *ctx); -/* Sweet the nhg hash tables for old entries on restart */ +/* Sweep the nhg hash tables for old entries on restart */ extern void zebra_nhg_sweep_table(struct hash *hash); +/* + * We are shutting down but the nexthops should be kept + * as that -r has been specified and we don't want to delete + * the routes unintentionally + */ +extern void zebra_nhg_mark_keep(void); + /* Nexthop resolution processing */ struct route_entry; /* Forward ref to avoid circular includes */ extern int nexthop_active_update(struct route_node *rn, struct route_entry *re); diff --git a/zebra/zebra_ptm.c b/zebra/zebra_ptm.c index 9a3b567b5a..1e7b38086b 100644 --- a/zebra/zebra_ptm.c +++ b/zebra/zebra_ptm.c @@ -156,13 +156,10 @@ void zebra_ptm_finish(void) if (ptm_cb.in_data) free(ptm_cb.in_data); - /* Release threads. */ - if (ptm_cb.t_read) - thread_cancel(ptm_cb.t_read); - if (ptm_cb.t_write) - thread_cancel(ptm_cb.t_write); - if (ptm_cb.t_timer) - thread_cancel(ptm_cb.t_timer); + /* Cancel events. */ + thread_cancel(&ptm_cb.t_read); + thread_cancel(&ptm_cb.t_write); + thread_cancel(&ptm_cb.t_timer); if (ptm_cb.wb) buffer_free(ptm_cb.wb); @@ -218,7 +215,7 @@ static int zebra_ptm_send_message(char *data, int size) ptm_cb.reconnect_time, &ptm_cb.t_timer); return -1; case BUFFER_EMPTY: - THREAD_OFF(ptm_cb.t_write); + thread_cancel(&ptm_cb.t_write); break; case BUFFER_PENDING: thread_add_write(zrouter.master, zebra_ptm_flush_messages, NULL, diff --git a/zebra/zebra_pw.c b/zebra/zebra_pw.c index cdcca1e930..ecae021dba 100644 --- a/zebra/zebra_pw.c +++ b/zebra/zebra_pw.c @@ -102,7 +102,7 @@ void zebra_pw_del(struct zebra_vrf *zvrf, struct zebra_pw *pw) hook_call(pw_uninstall, pw); dplane_pw_uninstall(pw); } else if (pw->install_retry_timer) - THREAD_TIMER_OFF(pw->install_retry_timer); + thread_cancel(&pw->install_retry_timer); /* unlink and release memory */ RB_REMOVE(zebra_pw_head, &zvrf->pseudowires, pw); @@ -219,7 +219,7 @@ void zebra_pw_install_failure(struct zebra_pw *pw, int pwstatus) pw->vrf_id, pw->ifname, PW_INSTALL_RETRY_INTERVAL); /* schedule to retry later */ - THREAD_TIMER_OFF(pw->install_retry_timer); + thread_cancel(&pw->install_retry_timer); thread_add_timer(zrouter.master, zebra_pw_install_retry, pw, PW_INSTALL_RETRY_INTERVAL, &pw->install_retry_timer); diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c index 166d479d78..730042b72c 100644 --- a/zebra/zebra_rib.c +++ b/zebra/zebra_rib.c @@ -694,15 +694,13 @@ void zebra_rib_evaluate_rn_nexthops(struct route_node *rn, uint32_t seq) if (IS_ZEBRA_DEBUG_NHT_DETAILED) { char buf1[PREFIX_STRLEN]; - char buf2[PREFIX_STRLEN]; zlog_debug( - "%s(%u):%s has Nexthop(%s) Type: %s depending on it, evaluating %u:%u", + "%s(%u):%s has Nexthop(%pFX) Type: %s depending on it, evaluating %u:%u", zvrf_name(zvrf), zvrf_id(zvrf), srcdest_rnode2str(rn, buf1, sizeof(buf1)), - prefix2str(p, buf2, sizeof(buf2)), - rnh_type2str(rnh->type), seq, + p, rnh_type2str(rnh->type), seq, rnh->seqno); } @@ -1924,11 +1922,9 @@ static void rib_process_result(struct zebra_dplane_ctx *ctx) zsend_route_notify_owner(re, dest_pfx, ZAPI_ROUTE_FAIL_INSTALL); - zlog_warn("%s(%u:%u):%s: Route install failed", + zlog_warn("%s(%u:%u):%pFX: Route install failed", VRF_LOGNAME(vrf), dplane_ctx_get_vrf(ctx), - dplane_ctx_get_table(ctx), - prefix2str(dest_pfx, dest_str, - sizeof(dest_str))); + dplane_ctx_get_table(ctx), dest_pfx); } break; case DPLANE_OP_ROUTE_DELETE: @@ -1954,11 +1950,9 @@ static void rib_process_result(struct zebra_dplane_ctx *ctx) zsend_route_notify_owner_ctx(ctx, ZAPI_ROUTE_REMOVE_FAIL); - zlog_warn("%s(%u:%u):%s: Route Deletion failure", + zlog_warn("%s(%u:%u):%pFX: Route Deletion failure", VRF_LOGNAME(vrf), dplane_ctx_get_vrf(ctx), - dplane_ctx_get_table(ctx), - prefix2str(dest_pfx, dest_str, - sizeof(dest_str))); + dplane_ctx_get_table(ctx), dest_pfx); } /* @@ -2831,7 +2825,6 @@ void rib_lookup_and_dump(struct prefix_ipv4 *p, vrf_id_t vrf_id) struct route_node *rn; struct route_entry *re; struct vrf *vrf; - char prefix_buf[INET_ADDRSTRLEN]; vrf = vrf_lookup_by_id(vrf_id); @@ -2849,10 +2842,8 @@ void rib_lookup_and_dump(struct prefix_ipv4 *p, vrf_id_t vrf_id) /* No route for this prefix. */ if (!rn) { - zlog_debug("%s:%s(%u) lookup failed for %s", __func__, - VRF_LOGNAME(vrf), vrf_id, - prefix2str((struct prefix *)p, prefix_buf, - sizeof(prefix_buf))); + zlog_debug("%s:%s(%u) lookup failed for %pFX", __func__, + VRF_LOGNAME(vrf), vrf_id, (struct prefix *)p); return; } @@ -2911,14 +2902,13 @@ void rib_lookup_and_pushup(struct prefix_ipv4 *p, vrf_id_t vrf_id) */ if (dest->selected_fib) { if (IS_ZEBRA_DEBUG_RIB) { - char buf[PREFIX_STRLEN]; struct vrf *vrf = vrf_lookup_by_id(dest->selected_fib->vrf_id); zlog_debug( - "%s(%u):%s: freeing way for connected prefix", + "%s(%u):%pFX: freeing way for connected prefix", VRF_LOGNAME(vrf), dest->selected_fib->vrf_id, - prefix2str(&rn->p, buf, sizeof(buf))); + &rn->p); route_entry_dump(&rn->p, NULL, dest->selected_fib); } rib_uninstall(rn, dest->selected_fib); @@ -2969,14 +2959,12 @@ int rib_add_multipath_nhe(afi_t afi, safi_t safi, struct prefix *p, /* Lookup nhe from route information */ nhe = zebra_nhg_rib_find_nhe(re_nhe, afi); if (!nhe) { - char buf[PREFIX_STRLEN] = ""; char buf2[PREFIX_STRLEN] = ""; flog_err( EC_ZEBRA_TABLE_LOOKUP_FAILED, - "Zebra failed to find or create a nexthop hash entry for %s%s%s", - prefix2str(p, buf, sizeof(buf)), - src_p ? " from " : "", + "Zebra failed to find or create a nexthop hash entry for %pFX%s%s", + p, src_p ? " from " : "", src_p ? prefix2str(src_p, buf2, sizeof(buf2)) : ""); @@ -3116,9 +3104,8 @@ void rib_delete(afi_t afi, safi_t safi, vrf_id_t vrf_id, int type, /* Lookup route node. */ rn = srcdest_rnode_lookup(table, p, src_p); if (!rn) { - char dst_buf[PREFIX_STRLEN], src_buf[PREFIX_STRLEN]; + char src_buf[PREFIX_STRLEN]; - prefix2str(p, dst_buf, sizeof(dst_buf)); if (src_p && src_p->prefixlen) prefix2str(src_p, src_buf, sizeof(src_buf)); else @@ -3127,8 +3114,8 @@ void rib_delete(afi_t afi, safi_t safi, vrf_id_t vrf_id, int type, if (IS_ZEBRA_DEBUG_RIB) { struct vrf *vrf = vrf_lookup_by_id(vrf_id); - zlog_debug("%s[%d]:%s%s%s doesn't exist in rib", - vrf->name, table_id, dst_buf, + zlog_debug("%s[%d]:%pFX%s%s doesn't exist in rib", + vrf->name, table_id, p, (src_buf[0] != '\0') ? " from " : "", src_buf); } diff --git a/zebra/zebra_rnh.c b/zebra/zebra_rnh.c index 9c6ed44585..521f969fcc 100644 --- a/zebra/zebra_rnh.c +++ b/zebra/zebra_rnh.c @@ -480,7 +480,6 @@ static void zebra_rnh_eval_import_check_entry(struct zebra_vrf *zvrf, afi_t afi, { int state_changed = 0; struct zserv *client; - char bufn[INET6_ADDRSTRLEN]; struct listnode *node; zebra_rnh_remove_from_routing_table(rnh); @@ -506,13 +505,11 @@ static void zebra_rnh_eval_import_check_entry(struct zebra_vrf *zvrf, afi_t afi, } if (state_changed || force) { - if (IS_ZEBRA_DEBUG_NHT) { - prefix2str(&nrn->p, bufn, INET6_ADDRSTRLEN); + if (IS_ZEBRA_DEBUG_NHT) zlog_debug("%s(%u):%pRN: Route import check %s %s", VRF_LOGNAME(zvrf->vrf), zvrf->vrf->vrf_id, nrn, rnh->state ? "passed" : "failed", state_changed ? "(state changed)" : ""); - } /* state changed, notify clients */ for (ALL_LIST_ELEMENTS_RO(rnh->client_list, node, client)) { zebra_send_rnh_update(rnh, client, @@ -1200,7 +1197,7 @@ static void print_nh(struct nexthop *nexthop, struct vty *vty) switch (nexthop->type) { case NEXTHOP_TYPE_IPV4: case NEXTHOP_TYPE_IPV4_IFINDEX: - vty_out(vty, " via %s", inet_ntoa(nexthop->gate.ipv4)); + vty_out(vty, " via %pI4", &nexthop->gate.ipv4); if (nexthop->ifindex) vty_out(vty, ", %s", ifindex2ifname_per_ns(zns, nexthop->ifindex)); diff --git a/zebra/zebra_routemap.c b/zebra/zebra_routemap.c index 8155f9acfe..294f2c17ff 100644 --- a/zebra/zebra_routemap.c +++ b/zebra/zebra_routemap.c @@ -1695,7 +1695,7 @@ static void zebra_route_map_set_delay_timer(uint32_t value) if (!value && zebra_t_rmap_update) { /* Event driven route map updates is being disabled */ /* But there's a pending timer. Fire it off now */ - thread_cancel(zebra_t_rmap_update); + thread_cancel(&zebra_t_rmap_update); zebra_route_map_update_timer(zebra_t_rmap_update); } } @@ -1705,7 +1705,7 @@ void zebra_routemap_finish(void) /* Set zebra_rmap_update_timer to 0 so that it wont schedule again */ zebra_rmap_update_timer = 0; /* Thread off if any scheduled already */ - THREAD_TIMER_OFF(zebra_t_rmap_update); + thread_cancel(&zebra_t_rmap_update); route_map_finish(); } diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index 762da5d0d3..1a6e6032b6 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -304,8 +304,8 @@ static void show_nexthop_detail_helper(struct vty *vty, switch (nexthop->type) { case NEXTHOP_TYPE_IPV4: case NEXTHOP_TYPE_IPV4_IFINDEX: - vty_out(vty, " %s", - inet_ntoa(nexthop->gate.ipv4)); + vty_out(vty, " %pI4", + &nexthop->gate.ipv4); if (nexthop->ifindex) vty_out(vty, ", via %s", ifindex2ifname( @@ -508,7 +508,7 @@ static void show_route_nexthop_helper(struct vty *vty, switch (nexthop->type) { case NEXTHOP_TYPE_IPV4: case NEXTHOP_TYPE_IPV4_IFINDEX: - vty_out(vty, " via %s", inet_ntoa(nexthop->gate.ipv4)); + vty_out(vty, " via %pI4", &nexthop->gate.ipv4); if (nexthop->ifindex) vty_out(vty, ", %s", ifindex2ifname(nexthop->ifindex, @@ -636,7 +636,8 @@ static void show_nexthop_json_helper(json_object *json_nexthop, case NEXTHOP_TYPE_IPV4_IFINDEX: json_object_string_add( json_nexthop, "ip", - inet_ntoa(nexthop->gate.ipv4)); + inet_ntop(AF_INET, &nexthop->gate.ipv4, + buf, sizeof(buf))); json_object_string_add(json_nexthop, "afi", "ipv4"); diff --git a/zebra/zebra_vxlan.c b/zebra/zebra_vxlan.c index 82e871801a..cca7680953 100644 --- a/zebra/zebra_vxlan.c +++ b/zebra/zebra_vxlan.c @@ -310,8 +310,7 @@ static void zl3vni_print_nh(zebra_neigh_t *n, struct vty *vty, rb_host_count(&n->host_rb)); vty_out(vty, " Prefixes:\n"); RB_FOREACH (hle, host_rb_tree_entry, &n->host_rb) - vty_out(vty, " %s\n", - prefix2str(&hle->p, buf2, sizeof(buf2))); + vty_out(vty, " %pFX\n", &hle->p); } else { json_hosts = json_object_new_array(); json_object_string_add( @@ -341,20 +340,21 @@ static void zl3vni_print_rmac(zebra_mac_t *zrmac, struct vty *vty, if (!json) { vty_out(vty, "MAC: %s\n", prefix_mac2str(&zrmac->macaddr, buf1, sizeof(buf1))); - vty_out(vty, " Remote VTEP: %s\n", - inet_ntoa(zrmac->fwd_info.r_vtep_ip)); + vty_out(vty, " Remote VTEP: %pI4\n", + &zrmac->fwd_info.r_vtep_ip); vty_out(vty, " Refcount: %d\n", rb_host_count(&zrmac->host_rb)); vty_out(vty, " Prefixes:\n"); RB_FOREACH (hle, host_rb_tree_entry, &zrmac->host_rb) - vty_out(vty, " %s\n", - prefix2str(&hle->p, buf2, sizeof(buf2))); + vty_out(vty, " %pFX\n", &hle->p); } else { json_hosts = json_object_new_array(); json_object_string_add( json, "routerMac", prefix_mac2str(&zrmac->macaddr, buf1, sizeof(buf1))); json_object_string_add(json, "vtepIp", - inet_ntoa(zrmac->fwd_info.r_vtep_ip)); + inet_ntop(AF_INET, + &zrmac->fwd_info.r_vtep_ip, + buf1, sizeof(buf1))); json_object_int_add(json, "refCount", rb_host_count(&zrmac->host_rb)); json_object_int_add(json, "localSequence", zrmac->loc_seq); @@ -631,7 +631,7 @@ static void zl3vni_print_rmac_hash(struct hash_bucket *bucket, void *ctx) struct vty *vty = NULL; struct json_object *json = NULL; struct json_object *json_rmac = NULL; - char buf[ETHER_ADDR_STRLEN]; + char buf[PREFIX_STRLEN]; wctx = (struct rmac_walk_ctx *)ctx; vty = wctx->vty; @@ -641,15 +641,17 @@ static void zl3vni_print_rmac_hash(struct hash_bucket *bucket, void *ctx) zrmac = (zebra_mac_t *)bucket->data; if (!json) { - vty_out(vty, "%-17s %-21s\n", + vty_out(vty, "%-17s %-21pI4\n", prefix_mac2str(&zrmac->macaddr, buf, sizeof(buf)), - inet_ntoa(zrmac->fwd_info.r_vtep_ip)); + &zrmac->fwd_info.r_vtep_ip); } else { json_object_string_add( json_rmac, "routerMac", prefix_mac2str(&zrmac->macaddr, buf, sizeof(buf))); json_object_string_add(json_rmac, "vtepIp", - inet_ntoa(zrmac->fwd_info.r_vtep_ip)); + inet_ntop(AF_INET, + &zrmac->fwd_info.r_vtep_ip, + buf, sizeof(buf))); json_object_object_add( json, prefix_mac2str(&zrmac->macaddr, buf, sizeof(buf)), json_rmac); @@ -659,7 +661,7 @@ static void zl3vni_print_rmac_hash(struct hash_bucket *bucket, void *ctx) /* print a specific L3 VNI entry */ static void zl3vni_print(zebra_l3vni_t *zl3vni, void **ctx) { - char buf[ETHER_ADDR_STRLEN]; + char buf[PREFIX_STRLEN]; struct vty *vty = NULL; json_object *json = NULL; zebra_evpn_t *zevpn = NULL; @@ -673,8 +675,8 @@ static void zl3vni_print(zebra_l3vni_t *zl3vni, void **ctx) vty_out(vty, "VNI: %u\n", zl3vni->vni); vty_out(vty, " Type: %s\n", "L3"); vty_out(vty, " Tenant VRF: %s\n", zl3vni_vrf_name(zl3vni)); - vty_out(vty, " Local Vtep Ip: %s\n", - inet_ntoa(zl3vni->local_vtep_ip)); + vty_out(vty, " Local Vtep Ip: %pI4\n", + &zl3vni->local_vtep_ip); vty_out(vty, " Vxlan-Intf: %s\n", zl3vni_vxlan_if_name(zl3vni)); vty_out(vty, " SVI-If: %s\n", zl3vni_svi_if_name(zl3vni)); @@ -695,8 +697,10 @@ static void zl3vni_print(zebra_l3vni_t *zl3vni, void **ctx) json_evpn_list = json_object_new_array(); json_object_int_add(json, "vni", zl3vni->vni); json_object_string_add(json, "type", "L3"); - json_object_string_add(json, "localVtepIp", - inet_ntoa(zl3vni->local_vtep_ip)); + json_object_string_add( + json, "localVtepIp", + inet_ntop(AF_INET, &zl3vni->local_vtep_ip, buf, + sizeof(buf))); json_object_string_add(json, "vxlanIntf", zl3vni_vxlan_if_name(zl3vni)); json_object_string_add(json, "sviIntf", @@ -945,9 +949,9 @@ static int zevpn_build_hash_table_zns(struct ns *ns, if (IS_ZEBRA_DEBUG_VXLAN) zlog_debug( - "Create L2-VNI hash for intf %s(%u) L2-VNI %u local IP %s", + "Create L2-VNI hash for intf %s(%u) L2-VNI %u local IP %pI4", ifp->name, ifp->ifindex, vni, - inet_ntoa(vxl->vtep_ip)); + &vxl->vtep_ip); /* EVPN hash entry is expected to exist, if the BGP process is killed */ zevpn = zebra_evpn_lookup(vni); @@ -1270,7 +1274,6 @@ static int zl3vni_remote_rmac_add(zebra_l3vni_t *zl3vni, { char buf[ETHER_ADDR_STRLEN]; char buf1[INET6_ADDRSTRLEN]; - char buf2[PREFIX_STRLEN]; zebra_mac_t *zrmac = NULL; zrmac = zl3vni_rmac_lookup(zl3vni, rmac); @@ -1280,11 +1283,11 @@ static int zl3vni_remote_rmac_add(zebra_l3vni_t *zl3vni, zrmac = zl3vni_rmac_add(zl3vni, rmac); if (!zrmac) { zlog_debug( - "Failed to add RMAC %s L3VNI %u Remote VTEP %s, prefix %s", + "Failed to add RMAC %s L3VNI %u Remote VTEP %s, prefix %pFX", prefix_mac2str(rmac, buf, sizeof(buf)), zl3vni->vni, ipaddr2str(vtep_ip, buf1, sizeof(buf1)), - prefix2str(host_prefix, buf2, sizeof(buf2))); + host_prefix); return -1; } memset(&zrmac->fwd_info, 0, sizeof(zrmac->fwd_info)); @@ -1300,12 +1303,12 @@ static int zl3vni_remote_rmac_add(zebra_l3vni_t *zl3vni, &vtep_ip->ipaddr_v4)) { if (IS_ZEBRA_DEBUG_VXLAN) zlog_debug( - "L3VNI %u Remote VTEP change(%s -> %s) for RMAC %s, prefix %s", + "L3VNI %u Remote VTEP change(%pI4 -> %s) for RMAC %s, prefix %pFX", zl3vni->vni, - inet_ntoa(zrmac->fwd_info.r_vtep_ip), + &zrmac->fwd_info.r_vtep_ip, ipaddr2str(vtep_ip, buf1, sizeof(buf1)), prefix_mac2str(rmac, buf, sizeof(buf)), - prefix2str(host_prefix, buf2, sizeof(buf2))); + host_prefix); zrmac->fwd_info.r_vtep_ip = vtep_ip->ipaddr_v4; @@ -1465,7 +1468,6 @@ static int zl3vni_remote_nh_add(zebra_l3vni_t *zl3vni, char buf[ETHER_ADDR_STRLEN]; char buf1[ETHER_ADDR_STRLEN]; char buf2[INET6_ADDRSTRLEN]; - char buf3[PREFIX_STRLEN]; zebra_neigh_t *nh = NULL; /* Create the next hop entry, or update its mac, if necessary. */ @@ -1474,11 +1476,10 @@ static int zl3vni_remote_nh_add(zebra_l3vni_t *zl3vni, nh = zl3vni_nh_add(zl3vni, vtep_ip, rmac); if (!nh) { zlog_debug( - "Failed to add NH %s as Neigh (RMAC %s L3-VNI %u prefix %s)", + "Failed to add NH %s as Neigh (RMAC %s L3-VNI %u prefix %pFX)", ipaddr2str(vtep_ip, buf1, sizeof(buf2)), prefix_mac2str(rmac, buf, sizeof(buf)), - zl3vni->vni, - prefix2str(host_prefix, buf2, sizeof(buf2))); + zl3vni->vni, host_prefix); return -1; } @@ -1486,12 +1487,13 @@ static int zl3vni_remote_nh_add(zebra_l3vni_t *zl3vni, zl3vni_nh_install(zl3vni, nh); } else if (memcmp(&nh->emac, rmac, ETH_ALEN) != 0) { if (IS_ZEBRA_DEBUG_VXLAN) - zlog_debug("L3VNI %u RMAC change(%s --> %s) for nexthop %s, prefix %s", - zl3vni->vni, - prefix_mac2str(&nh->emac, buf, sizeof(buf)), - prefix_mac2str(rmac, buf1, sizeof(buf1)), - ipaddr2str(vtep_ip, buf2, sizeof(buf2)), - prefix2str(host_prefix, buf3, sizeof(buf3))); + zlog_debug( + "L3VNI %u RMAC change(%s --> %s) for nexthop %s, prefix %pFX", + zl3vni->vni, + prefix_mac2str(&nh->emac, buf, sizeof(buf)), + prefix_mac2str(rmac, buf1, sizeof(buf1)), + ipaddr2str(vtep_ip, buf2, sizeof(buf2)), + host_prefix); memcpy(&nh->emac, rmac, ETH_ALEN); /* install (update) the nh neigh in kernel */ @@ -1913,11 +1915,11 @@ static int zl3vni_send_add_to_client(zebra_l3vni_t *zl3vni) if (IS_ZEBRA_DEBUG_VXLAN) zlog_debug( - "Send L3_VNI_ADD %u VRF %s RMAC %s VRR %s local-ip %s filter %s to %s", + "Send L3_VNI_ADD %u VRF %s RMAC %s VRR %s local-ip %pI4 filter %s to %s", zl3vni->vni, vrf_id_to_name(zl3vni_vrf_id(zl3vni)), prefix_mac2str(&svi_rmac, buf, sizeof(buf)), prefix_mac2str(&vrr_rmac, buf1, sizeof(buf1)), - inet_ntoa(zl3vni->local_vtep_ip), + &zl3vni->local_vtep_ip, CHECK_FLAG(zl3vni->filter, PREFIX_ROUTES_ONLY) ? "prefix-routes-only" : "none", @@ -3766,14 +3768,13 @@ void zebra_vxlan_remote_macip_del(ZAPI_HANDLER_ARGS) l += res_length; if (IS_ZEBRA_DEBUG_VXLAN) zlog_debug( - "Recv MACIP DEL VNI %u MAC %s%s%s Remote VTEP %s from %s", + "Recv MACIP DEL VNI %u MAC %s%s%s Remote VTEP %pI4 from %s", vni, prefix_mac2str(&macaddr, buf, sizeof(buf)), ipa_len ? " IP " : "", ipa_len ? ipaddr2str(&ip, buf1, sizeof(buf1)) : "", - inet_ntoa(vtep_ip), - zebra_route_string(client->proto)); + &vtep_ip, zebra_route_string(client->proto)); process_remote_macip_del(vni, &macaddr, ipa_len, &ip, vtep_ip); } @@ -3828,7 +3829,7 @@ void zebra_vxlan_remote_macip_add(ZAPI_HANDLER_ARGS) else strlcpy(esi_buf, "-", ESI_STR_LEN); zlog_debug( - "Recv %sMACIP ADD VNI %u MAC %s%s%s flags 0x%x seq %u VTEP %s ESI %s from %s", + "Recv %sMACIP ADD VNI %u MAC %s%s%s flags 0x%x seq %u VTEP %pI4 ESI %s from %s", (flags & ZEBRA_MACIP_TYPE_SYNC_PATH) ? "sync-" : "", vni, @@ -3836,7 +3837,7 @@ void zebra_vxlan_remote_macip_add(ZAPI_HANDLER_ARGS) ipa_len ? " IP " : "", ipa_len ? ipaddr2str(&ip, buf1, sizeof(buf1)) : "", - flags, seq, inet_ntoa(vtep_ip), esi_buf, + flags, seq, &vtep_ip, esi_buf, zebra_route_string(client->proto)); } @@ -3887,8 +3888,8 @@ int zebra_vxlan_check_readd_vtep(struct interface *ifp, if (IS_ZEBRA_DEBUG_VXLAN) zlog_debug( - "Del MAC for remote VTEP %s intf %s(%u) VNI %u - readd", - inet_ntoa(vtep_ip), ifp->name, ifp->ifindex, vni); + "Del MAC for remote VTEP %pI4 intf %s(%u) VNI %u - readd", + &vtep_ip, ifp->name, ifp->ifindex, vni); zebra_evpn_vtep_install(zevpn, zvtep); return 0; @@ -4128,8 +4129,8 @@ void zebra_vxlan_remote_vtep_del(ZAPI_HANDLER_ARGS) l += 4; if (IS_ZEBRA_DEBUG_VXLAN) - zlog_debug("Recv VTEP_DEL %s VNI %u from %s", - inet_ntoa(vtep_ip), vni, + zlog_debug("Recv VTEP_DEL %pI4 VNI %u from %s", + &vtep_ip, vni, zebra_route_string(client->proto)); /* Locate VNI hash entry - expected to exist. */ @@ -4212,8 +4213,8 @@ void zebra_vxlan_remote_vtep_add(ZAPI_HANDLER_ARGS) l += IPV4_MAX_BYTELEN + 4; if (IS_ZEBRA_DEBUG_VXLAN) - zlog_debug("Recv VTEP_ADD %s VNI %u flood %d from %s", - inet_ntoa(vtep_ip), vni, flood_control, + zlog_debug("Recv VTEP_ADD %pI4 VNI %u flood %d from %s", + &vtep_ip, vni, flood_control, zebra_route_string(client->proto)); /* Locate VNI hash entry - expected to exist. */ @@ -4795,9 +4796,9 @@ int zebra_vxlan_if_update(struct interface *ifp, uint16_t chgflags) if (IS_ZEBRA_DEBUG_VXLAN) zlog_debug( - "Update L3-VNI %u intf %s(%u) VLAN %u local IP %s master %u chg 0x%x", + "Update L3-VNI %u intf %s(%u) VLAN %u local IP %pI4 master %u chg 0x%x", vni, ifp->name, ifp->ifindex, vxl->access_vlan, - inet_ntoa(vxl->vtep_ip), + &vxl->vtep_ip, zif->brslave_info.bridge_ifindex, chgflags); /* Removed from bridge? Cleanup and return */ @@ -4859,9 +4860,9 @@ int zebra_vxlan_if_update(struct interface *ifp, uint16_t chgflags) if (IS_ZEBRA_DEBUG_VXLAN) zlog_debug( - "Update L2-VNI %u intf %s(%u) VLAN %u local IP %s master %u chg 0x%x", + "Update L2-VNI %u intf %s(%u) VLAN %u local IP %pI4 master %u chg 0x%x", vni, ifp->name, ifp->ifindex, vxl->access_vlan, - inet_ntoa(vxl->vtep_ip), + &vxl->vtep_ip, zif->brslave_info.bridge_ifindex, chgflags); /* Removed from bridge? Cleanup and return */ @@ -4966,9 +4967,9 @@ int zebra_vxlan_if_add(struct interface *ifp) /* process if-add for l3-vni*/ if (IS_ZEBRA_DEBUG_VXLAN) zlog_debug( - "Add L3-VNI %u intf %s(%u) VLAN %u local IP %s master %u", + "Add L3-VNI %u intf %s(%u) VLAN %u local IP %pI4 master %u", vni, ifp->name, ifp->ifindex, vxl->access_vlan, - inet_ntoa(vxl->vtep_ip), + &vxl->vtep_ip, zif->brslave_info.bridge_ifindex); /* associate with vxlan_if */ diff --git a/zebra/zserv.c b/zebra/zserv.c index 44f4641fcf..4b5791530d 100644 --- a/zebra/zserv.c +++ b/zebra/zserv.c @@ -1172,11 +1172,9 @@ static void zebra_show_stale_client_detail(struct vty *vty, } } vty_out(vty, "Current AFI : %d\n", info->current_afi); - if (info->current_prefix) { - prefix2str(info->current_prefix, buf, - sizeof(buf)); - vty_out(vty, "Current prefix : %s\n", buf); - } + if (info->current_prefix) + vty_out(vty, "Current prefix : %pFX\n", + info->current_prefix); } } vty_out(vty, "\n"); |
