From b6c4848171b1c4cb7f290038089fb2d005495023 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Wed, 10 Mar 2021 07:25:49 -0500 Subject: [PATCH] nhrpd: Use our built-in printf functionality Signed-off-by: Donald Sharp --- nhrpd/netlink_arp.c | 18 ++++---------- nhrpd/nhrp_cache.c | 35 +++++++++----------------- nhrpd/nhrp_interface.c | 6 ++--- nhrpd/nhrp_nhs.c | 22 ++++++----------- nhrpd/nhrp_peer.c | 56 ++++++++++++++---------------------------- nhrpd/nhrp_route.c | 6 ++--- nhrpd/nhrp_shortcut.c | 25 ++++++------------- nhrpd/nhrp_vc.c | 7 ++---- 8 files changed, 56 insertions(+), 119 deletions(-) diff --git a/nhrpd/netlink_arp.c b/nhrpd/netlink_arp.c index 309f733526..dc4697cda0 100644 --- a/nhrpd/netlink_arp.c +++ b/nhrpd/netlink_arp.c @@ -67,7 +67,6 @@ static void netlink_neigh_msg(struct nlmsghdr *msg, struct zbuf *zb) struct zbuf payload; union sockunion addr, lladdr; size_t len; - char buf[4][SU_ADDRSTRLEN]; int state; memset(&lladdr, 0, sizeof(lladdr)); @@ -99,27 +98,20 @@ static void netlink_neigh_msg(struct nlmsghdr *msg, struct zbuf *zb) return; debugf(NHRP_DEBUG_KERNEL, - "Netlink: %s %s dev %s lladdr %s nud 0x%x cache used %u type %u", + "Netlink: %s %pSU dev %s lladdr %pSU nud 0x%x cache used %u type %u", (msg->nlmsg_type == RTM_GETNEIGH) ? "who-has" : (msg->nlmsg_type == RTM_NEWNEIGH) ? "new-neigh" : "del-neigh", - sockunion2str(&addr, buf[0], sizeof(buf[0])), ifp->name, - sockunion2str(&lladdr, buf[1], sizeof(buf[1])), ndm->ndm_state, - c->used, c->cur.type); + &addr, ifp->name, &lladdr, ndm->ndm_state, c->used, c->cur.type); if (msg->nlmsg_type == RTM_GETNEIGH) { if (c->cur.type >= NHRP_CACHE_CACHED) { nhrp_cache_set_used(c, 1); debugf(NHRP_DEBUG_KERNEL, - "Netlink: update binding for %s dev %s from c %s peer.vc.nbma %s to lladdr %s", - sockunion2str(&addr, buf[0], sizeof(buf[0])), - ifp->name, - sockunion2str(&c->cur.remote_nbma_natoa, buf[1], - sizeof(buf[1])), - sockunion2str(&c->cur.peer->vc->remote.nbma, - buf[2], sizeof(buf[2])), - sockunion2str(&lladdr, buf[3], sizeof(buf[3]))); + "Netlink: update binding for %pSU dev %s from c %pSU peer.vc.nbma %pSU to lladdr %pSU", + &addr, ifp->name, &c->cur.remote_nbma_natoa, + &c->cur.peer->vc->remote.nbma, &lladdr); /* In case of shortcuts, nbma is given by lladdr, not * vc->remote.nbma. */ diff --git a/nhrpd/nhrp_cache.c b/nhrpd/nhrp_cache.c index 0b5a0427e6..cb298b1a09 100644 --- a/nhrpd/nhrp_cache.c +++ b/nhrpd/nhrp_cache.c @@ -220,7 +220,6 @@ static void nhrp_cache_update_route(struct nhrp_cache *c) { struct prefix pfx; struct nhrp_peer *p = c->cur.peer; - char buf[3][SU_ADDRSTRLEN]; struct nhrp_interface *nifp; if (!sockunion2hostprefix(&c->remote_addr, &pfx)) @@ -233,26 +232,18 @@ static void nhrp_cache_update_route(struct nhrp_cache *c) * nbma. */ debugf(NHRP_DEBUG_COMMON, - "cache (remote_nbma_natoa set): Update binding for %s dev %s from (deleted) peer.vc.nbma %s to %s", - sockunion2str(&c->remote_addr, buf[0], - sizeof(buf[0])), - p->ifp->name, - sockunion2str(&p->vc->remote.nbma, buf[1], - sizeof(buf[1])), - sockunion2str(&c->cur.remote_nbma_natoa, buf[2], - sizeof(buf[2]))); + "cache (remote_nbma_natoa set): Update binding for %pSU dev %s from (deleted) peer.vc.nbma %pSU to %pSU", + &c->remote_addr, p->ifp->name, + &p->vc->remote.nbma, &c->cur.remote_nbma_natoa); netlink_update_binding(p->ifp, &c->remote_addr, &c->cur.remote_nbma_natoa); } else { /* update binding to peer->vc->remote->nbma */ debugf(NHRP_DEBUG_COMMON, - "cache (remote_nbma_natoa unspec): Update binding for %s dev %s from (deleted) to peer.vc.nbma %s", - sockunion2str(&c->remote_addr, buf[0], - sizeof(buf[0])), - p->ifp->name, - sockunion2str(&p->vc->remote.nbma, buf[1], - sizeof(buf[1]))); + "cache (remote_nbma_natoa unspec): Update binding for %pSU dev %s from (deleted) to peer.vc.nbma %pSU", + &c->remote_addr, p->ifp->name, + &p->vc->remote.nbma); netlink_update_binding(p->ifp, &c->remote_addr, &p->vc->remote.nbma); @@ -353,9 +344,8 @@ static void nhrp_cache_authorize_binding(struct nhrp_reqid *r, void *arg) struct nhrp_cache *c = container_of(r, struct nhrp_cache, eventid); char buf[3][SU_ADDRSTRLEN]; - debugf(NHRP_DEBUG_COMMON, "cache: %s %s: %s", c->ifp->name, - sockunion2str(&c->remote_addr, buf[0], sizeof(buf[0])), - (const char *)arg); + debugf(NHRP_DEBUG_COMMON, "cache: %s %pSU: %s", c->ifp->name, + &c->remote_addr, (const char *)arg); nhrp_reqid_free(&nhrp_event_reqid, r); @@ -377,16 +367,13 @@ static void nhrp_cache_authorize_binding(struct nhrp_reqid *r, void *arg) if (sockunion_family(&c->cur.remote_nbma_natoa) != AF_UNSPEC) { debugf(NHRP_DEBUG_COMMON, - "cache: update binding for %s dev %s from (deleted) peer.vc.nbma %s to %s", - sockunion2str(&c->remote_addr, buf[0], - sizeof(buf[0])), - c->ifp->name, + "cache: update binding for %pSU dev %s from (deleted) peer.vc.nbma %s to %pSU", + &c->remote_addr, c->ifp->name, (c->cur.peer ? sockunion2str( &c->cur.peer->vc->remote.nbma, buf[1], sizeof(buf[1])) : "(no peer)"), - sockunion2str(&c->cur.remote_nbma_natoa, buf[2], - sizeof(buf[2]))); + &c->cur.remote_nbma_natoa); if (c->cur.peer) netlink_update_binding( diff --git a/nhrpd/nhrp_interface.c b/nhrpd/nhrp_interface.c index 269499cc59..f86dbe3d29 100644 --- a/nhrpd/nhrp_interface.c +++ b/nhrpd/nhrp_interface.c @@ -117,7 +117,6 @@ static void nhrp_interface_interface_notifier(struct notifier_block *n, container_of(n, struct nhrp_interface, nbmanifp_notifier); struct interface *nbmaifp = nifp->nbmaifp; struct nhrp_interface *nbmanifp = nbmaifp->info; - char buf[SU_ADDRSTRLEN]; switch (cmd) { case NOTIFY_INTERFACE_CHANGED: @@ -129,9 +128,8 @@ static void nhrp_interface_interface_notifier(struct notifier_block *n, nhrp_interface_update(nifp->ifp); notifier_call(&nifp->notifier_list, NOTIFY_INTERFACE_NBMA_CHANGED); - debugf(NHRP_DEBUG_IF, "%s: NBMA change: address %s", - nifp->ifp->name, - sockunion2str(&nifp->nbma, buf, sizeof(buf))); + debugf(NHRP_DEBUG_IF, "%s: NBMA change: address %pSU", + nifp->ifp->name, &nifp->nbma); break; } } diff --git a/nhrpd/nhrp_nhs.c b/nhrpd/nhrp_nhs.c index 540708f1ae..9ed03098ac 100644 --- a/nhrpd/nhrp_nhs.c +++ b/nhrpd/nhrp_nhs.c @@ -33,7 +33,6 @@ static void nhrp_reg_reply(struct nhrp_reqid *reqid, void *arg) struct nhrp_cache *c; struct zbuf extpl; union sockunion cie_nbma, cie_proto, *proto; - char buf[64]; int ok = 0, holdtime; unsigned short mtu = 0; @@ -52,8 +51,8 @@ static void nhrp_reg_reply(struct nhrp_reqid *reqid, void *arg) proto = sockunion_family(&cie_proto) != AF_UNSPEC ? &cie_proto : &p->src_proto; - debugf(NHRP_DEBUG_COMMON, "NHS: CIE registration: %s: %d", - sockunion2str(proto, buf, sizeof(buf)), cie->code); + debugf(NHRP_DEBUG_COMMON, "NHS: CIE registration: %pSU: %d", + proto, cie->code); if (!((cie->code == NHRP_CODE_SUCCESS) || (cie->code == NHRP_CODE_ADMINISTRATIVELY_PROHIBITED && nhs->hub))) @@ -76,10 +75,8 @@ static void nhrp_reg_reply(struct nhrp_reqid *reqid, void *arg) &cie_proto)) { nifp->nat_nbma = cie_nbma; debugf(NHRP_DEBUG_IF, - "%s: NAT detected, real NBMA address: %s", - ifp->name, - sockunion2str(&nifp->nbma, buf, - sizeof(buf))); + "%s: NAT detected, real NBMA address: %pSU", + ifp->name, &nifp->nbma); } break; } @@ -130,16 +127,14 @@ static void nhrp_reg_peer_notify(struct notifier_block *n, unsigned long cmd) { struct nhrp_registration *r = container_of(n, struct nhrp_registration, peer_notifier); - char buf[SU_ADDRSTRLEN]; switch (cmd) { case NOTIFY_PEER_UP: case NOTIFY_PEER_DOWN: case NOTIFY_PEER_IFCONFIG_CHANGED: case NOTIFY_PEER_MTU_CHANGED: - debugf(NHRP_DEBUG_COMMON, "NHS: Flush timer for %s", - sockunion2str(&r->peer->vc->remote.nbma, buf, - sizeof(buf))); + debugf(NHRP_DEBUG_COMMON, "NHS: Flush timer for %pSU", + &r->peer->vc->remote.nbma); THREAD_OFF(r->t_register); thread_add_timer_msec(master, nhrp_reg_send_req, r, 10, &r->t_register); @@ -163,9 +158,8 @@ static int nhrp_reg_send_req(struct thread *t) r->t_register = NULL; if (!nhrp_peer_check(r->peer, 2)) { - debugf(NHRP_DEBUG_COMMON, "NHS: Waiting link for %s", - sockunion2str(&r->peer->vc->remote.nbma, buf1, - sizeof(buf1))); + debugf(NHRP_DEBUG_COMMON, "NHS: Waiting link for %pSU", + &r->peer->vc->remote.nbma); thread_add_timer(master, nhrp_reg_send_req, r, 120, &r->t_register); return 0; diff --git a/nhrpd/nhrp_peer.c b/nhrpd/nhrp_peer.c index 9aaa9dec1e..622cb4ebb6 100644 --- a/nhrpd/nhrp_peer.c +++ b/nhrpd/nhrp_peer.c @@ -38,16 +38,13 @@ static void nhrp_packet_debug(struct zbuf *zb, const char *dir); static void nhrp_peer_check_delete(struct nhrp_peer *p) { - char buf[2][256]; struct nhrp_interface *nifp = p->ifp->info; if (p->ref || notifier_active(&p->notifier_list)) return; - debugf(NHRP_DEBUG_COMMON, "Deleting peer ref:%d remote:%s local:%s", - p->ref, - sockunion2str(&p->vc->remote.nbma, buf[0], sizeof(buf[0])), - sockunion2str(&p->vc->local.nbma, buf[1], sizeof(buf[1]))); + debugf(NHRP_DEBUG_COMMON, "Deleting peer ref:%d remote:%pSU local:%pSU", + p->ref, &p->vc->remote.nbma, &p->vc->local.nbma); THREAD_OFF(p->t_fallback); hash_release(nifp->peer_hash, p); @@ -326,16 +323,13 @@ void nhrp_peer_notify_del(struct nhrp_peer *p, struct notifier_block *n) void nhrp_peer_send(struct nhrp_peer *p, struct zbuf *zb) { - char buf[2][256]; - nhrp_packet_debug(zb, "Send"); if (!p->online) return; - debugf(NHRP_DEBUG_KERNEL, "PACKET: Send %s -> %s", - sockunion2str(&p->vc->local.nbma, buf[0], sizeof(buf[0])), - sockunion2str(&p->vc->remote.nbma, buf[1], sizeof(buf[1]))); + debugf(NHRP_DEBUG_KERNEL, "PACKET: Send %pSU -> %pSU", + &p->vc->local.nbma, &p->vc->remote.nbma); os_sendmsg(zb->head, zbuf_used(zb), p->ifp->ifindex, sockunion_get_addr(&p->vc->remote.nbma), @@ -658,7 +652,6 @@ void nhrp_peer_send_indication(struct interface *ifp, uint16_t protocol_type, struct nhrp_afi_data *if_ad; struct nhrp_packet_header *hdr; struct nhrp_peer *p; - char buf[2][SU_ADDRSTRLEN]; if (!nifp->enabled) return; @@ -673,17 +666,14 @@ void nhrp_peer_send_indication(struct interface *ifp, uint16_t protocol_type, if_ad = &nifp->afi[family2afi(sockunion_family(&dst))]; if (!(if_ad->flags & NHRP_IFF_REDIRECT)) { debugf(NHRP_DEBUG_COMMON, - "Send Traffic Indication to %s about packet to %s ignored", - sockunion2str(&p->vc->remote.nbma, buf[0], - sizeof(buf[0])), - sockunion2str(&dst, buf[1], sizeof(buf[1]))); + "Send Traffic Indication to %pSU about packet to %pSU ignored", + &p->vc->remote.nbma, &dst); return; } debugf(NHRP_DEBUG_COMMON, - "Send Traffic Indication to %s (online=%d) about packet to %s", - sockunion2str(&p->vc->remote.nbma, buf[0], sizeof(buf[0])), - p->online, sockunion2str(&dst, buf[1], sizeof(buf[1]))); + "Send Traffic Indication to %pSU (online=%d) about packet to %pSU", + &p->vc->remote.nbma, p->online, &dst); /* Create reply */ zb = zbuf_alloc(1500); @@ -705,16 +695,14 @@ static void nhrp_handle_error_ind(struct nhrp_packet_parser *pp) struct nhrp_packet_header *hdr; struct nhrp_reqid *reqid; union sockunion src_nbma, src_proto, dst_proto; - char buf[2][SU_ADDRSTRLEN]; hdr = nhrp_packet_pull(&origmsg, &src_nbma, &src_proto, &dst_proto); if (!hdr) return; debugf(NHRP_DEBUG_COMMON, - "Error Indication from %s about packet to %s ignored", - sockunion2str(&pp->src_proto, buf[0], sizeof(buf[0])), - sockunion2str(&dst_proto, buf[1], sizeof(buf[1]))); + "Error Indication from %pSU about packet to %pSU ignored", + &pp->src_proto, &dst_proto); reqid = nhrp_reqid_lookup(&nhrp_packet_reqid, htonl(hdr->u.request_id)); if (reqid) @@ -724,16 +712,14 @@ static void nhrp_handle_error_ind(struct nhrp_packet_parser *pp) static void nhrp_handle_traffic_ind(struct nhrp_packet_parser *p) { union sockunion dst; - char buf[2][SU_ADDRSTRLEN]; if (!parse_ether_packet(&p->payload, htons(p->hdr->protocol_type), NULL, &dst)) return; debugf(NHRP_DEBUG_COMMON, - "Traffic Indication from %s about packet to %s: %s", - sockunion2str(&p->src_proto, buf[0], sizeof(buf[0])), - sockunion2str(&dst, buf[1], sizeof(buf[1])), + "Traffic Indication from %pSU about packet to %pSU: %s", + &p->src_proto, &dst, (p->if_ad->flags & NHRP_IFF_SHORTCUT) ? "trying shortcut" : "ignored"); @@ -929,7 +915,6 @@ struct nhrp_route_info { void nhrp_peer_recv(struct nhrp_peer *p, struct zbuf *zb) { - char buf[2][SU_ADDRSTRLEN]; struct nhrp_packet_header *hdr; struct nhrp_vc *vc = p->vc; struct interface *ifp = p->ifp; @@ -942,9 +927,8 @@ void nhrp_peer_recv(struct nhrp_peer *p, struct zbuf *zb) unsigned paylen, extoff, extlen, realsize; afi_t nbma_afi, proto_afi; - debugf(NHRP_DEBUG_KERNEL, "PACKET: Recv %s -> %s", - sockunion2str(&vc->remote.nbma, buf[0], sizeof(buf[0])), - sockunion2str(&vc->local.nbma, buf[1], sizeof(buf[1]))); + debugf(NHRP_DEBUG_KERNEL, "PACKET: Recv %pSU -> %pSU", &vc->remote.nbma, + &vc->local.nbma); if (!p->online) { info = "peer not online"; @@ -975,10 +959,9 @@ void nhrp_peer_recv(struct nhrp_peer *p, struct zbuf *zb) || packet_types[hdr->type].type == PACKET_UNKNOWN || htons(hdr->packet_size) > realsize) { zlog_info( - "From %s: error: packet type %d, version %d, AFI %d, proto %x, size %d (real size %d)", - sockunion2str(&vc->remote.nbma, buf[0], sizeof(buf[0])), - (int)hdr->type, (int)hdr->version, (int)nbma_afi, - (int)htons(hdr->protocol_type), + "From %pSU: error: packet type %d, version %d, AFI %d, proto %x, size %d (real size %d)", + &vc->remote.nbma, (int)hdr->type, (int)hdr->version, + (int)nbma_afi, (int)htons(hdr->protocol_type), (int)htons(hdr->packet_size), (int)realsize); goto drop; } @@ -1055,10 +1038,7 @@ void nhrp_peer_recv(struct nhrp_peer *p, struct zbuf *zb) drop: if (info) { - zlog_info( - "From %s: error: %s", - sockunion2str(&vc->remote.nbma, buf[0], sizeof(buf[0])), - info); + zlog_info("From %pSU: error: %s", &vc->remote.nbma, info); } if (peer) nhrp_peer_unref(peer); diff --git a/nhrpd/nhrp_route.c b/nhrpd/nhrp_route.c index 334f468c18..737772dbc7 100644 --- a/nhrpd/nhrp_route.c +++ b/nhrpd/nhrp_route.c @@ -200,7 +200,6 @@ int nhrp_route_read(ZAPI_CALLBACK_ARGS) struct zapi_nexthop *api_nh; struct interface *ifp = NULL; union sockunion nexthop_addr; - char buf[PREFIX_STRLEN]; int added; if (zapi_route_decode(zclient->ibuf, &api) < 0) @@ -233,9 +232,8 @@ int nhrp_route_read(ZAPI_CALLBACK_ARGS) } added = (cmd == ZEBRA_REDISTRIBUTE_ROUTE_ADD); - debugf(NHRP_DEBUG_ROUTE, "if-route-%s: %pFX via %s dev %s", - added ? "add" : "del", &api.prefix, - sockunion2str(&nexthop_addr, buf, sizeof(buf)), + debugf(NHRP_DEBUG_ROUTE, "if-route-%s: %pFX via %pSU dev %s", + added ? "add" : "del", &api.prefix, &nexthop_addr, ifp ? ifp->name : "(none)"); nhrp_route_update_zebra(&api.prefix, &nexthop_addr, added ? ifp : NULL); diff --git a/nhrpd/nhrp_shortcut.c b/nhrpd/nhrp_shortcut.c index fbb883185a..ef3be82ca9 100644 --- a/nhrpd/nhrp_shortcut.c +++ b/nhrpd/nhrp_shortcut.c @@ -94,8 +94,6 @@ static void nhrp_shortcut_update_binding(struct nhrp_shortcut *s, enum nhrp_cache_type type, struct nhrp_cache *c, int holding_time) { - char buf[2][PREFIX_STRLEN]; - s->type = type; if (c != s->cache) { if (s->cache) { @@ -111,13 +109,9 @@ static void nhrp_shortcut_update_binding(struct nhrp_shortcut *s, * change */ s->route_installed = 0; debugf(NHRP_DEBUG_ROUTE, - "Shortcut: forcing renewal of zebra announce on prefix change peer %s ht %u cur nbma %s dev %s", - sockunion2str(&s->cache->remote_addr, - buf[0], sizeof(buf[0])), - holding_time, - sockunion2str( - &s->cache->cur.remote_nbma_natoa, - buf[1], sizeof(buf[1])), + "Shortcut: forcing renewal of zebra announce on prefix change peer %pSU ht %u cur nbma %pSU dev %s", + &s->cache->remote_addr, holding_time, + &s->cache->cur.remote_nbma_natoa, s->cache->ifp->name); nhrp_shortcut_cache_notify(&s->cache_notifier, NOTIFY_CACHE_UP); @@ -255,9 +249,9 @@ static void nhrp_shortcut_recv_resolution_rep(struct nhrp_reqid *reqid, prefix2sockunion(s->p, &cie_proto); if (!sockunion_same(&cie_proto, &pp->dst_proto)) { debugf(NHRP_DEBUG_COMMON, - "Shortcut: Warning dst_proto altered from %s to %s", - sockunion2str(&cie_proto, buf[0], sizeof(buf[0])), - sockunion2str(&pp->dst_proto, buf[1], sizeof(buf[1]))); + "Shortcut: Warning dst_proto altered from %pSU to %pSU", + &cie_proto, &pp->dst_proto); + ; } /* One or more CIEs should be given as reply, we support only one */ @@ -287,11 +281,8 @@ static void nhrp_shortcut_recv_resolution_rep(struct nhrp_reqid *reqid, } debugf(NHRP_DEBUG_COMMON, - "Shortcut: %pFX is at proto %s dst_proto %s cie-nbma %s nat-nbma %s cie-holdtime %d", - &prefix, sockunion2str(proto, buf[0], sizeof(buf[0])), - sockunion2str(&pp->dst_proto, buf[1], sizeof(buf[1])), - sockunion2str(&cie_nbma, buf[2], sizeof(buf[2])), - sockunion2str(&nat_nbma, buf[3], sizeof(buf[3])), + "Shortcut: %pFX is at proto %pSU dst_proto %pSU cie-nbma %pSU nat-nbma %pSU cie-holdtime %d", + &prefix, proto, &pp->dst_proto, &cie_nbma, &nat_nbma, htons(cie->holding_time)); /* Update cache entry for the protocol to nbma binding */ diff --git a/nhrpd/nhrp_vc.c b/nhrpd/nhrp_vc.c index 6567b231a9..d538163e90 100644 --- a/nhrpd/nhrp_vc.c +++ b/nhrpd/nhrp_vc.c @@ -100,7 +100,6 @@ static void nhrp_vc_ipsec_reset(struct nhrp_vc *vc) int nhrp_vc_ipsec_updown(uint32_t child_id, struct nhrp_vc *vc) { - char buf[2][SU_ADDRSTRLEN]; struct child_sa *sa = NULL, *lsa; uint32_t child_hash = child_id % array_size(childlist_head); int abort_migration = 0; @@ -140,10 +139,8 @@ int nhrp_vc_ipsec_updown(uint32_t child_id, struct nhrp_vc *vc) if (sa->vc && vc) { /* Notify old VC of migration */ sa->vc->abort_migration = 0; - debugf(NHRP_DEBUG_COMMON, "IPsec NBMA change of %s to %s", - sockunion2str(&sa->vc->remote.nbma, buf[0], - sizeof(buf[0])), - sockunion2str(&vc->remote.nbma, buf[1], sizeof(buf[1]))); + debugf(NHRP_DEBUG_COMMON, "IPsec NBMA change of %pSU to %pSU", + &sa->vc->remote.nbma, &vc->remote.nbma); nhrp_vc_update(sa->vc, NOTIFY_VC_IPSEC_UPDATE_NBMA); abort_migration = sa->vc->abort_migration; } -- 2.39.5