Merge pull request #11445 from opensourcerouting/fix/replace_sockunion2str

*: Replace sockunion2str => %pSU
This commit is contained in:
Donald Sharp 2022-06-22 07:33:14 -04:00 committed by GitHub
commit a01887c40b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 72 additions and 142 deletions

View File

@ -1889,7 +1889,6 @@ static void bmp_active_thread(struct thread *t)
struct bmp_active *ba = THREAD_ARG(t);
socklen_t slen;
int status, ret;
char buf[SU_ADDRSTRLEN];
vrf_id_t vrf_id;
/* all 3 end up here, though only timer or read+write are active
@ -1915,16 +1914,16 @@ static void bmp_active_thread(struct thread *t)
ret = getsockopt(ba->socket, SOL_SOCKET, SO_ERROR, (void *)&status,
&slen);
sockunion2str(&ba->addrs[ba->addrpos], buf, sizeof(buf));
if (ret < 0 || status != 0) {
ba->last_err = strerror(status);
zlog_warn("bmp[%s]: failed to connect to %s:%d: %s",
ba->hostname, buf, ba->port, ba->last_err);
zlog_warn("bmp[%s]: failed to connect to %pSU:%d: %s",
ba->hostname, &ba->addrs[ba->addrpos], ba->port,
ba->last_err);
goto out_next;
}
zlog_warn("bmp[%s]: outbound connection to %s:%d",
ba->hostname, buf, ba->port);
zlog_warn("bmp[%s]: outbound connection to %pSU:%d", ba->hostname,
&ba->addrs[ba->addrpos], ba->port);
ba->bmp = bmp_open(ba->targets, ba->socket);
if (!ba->bmp)
@ -2317,7 +2316,6 @@ DEFPY(show_bmp,
struct bmp_active *ba;
struct bmp *bmp;
struct ttable *tt;
char buf[SU_ADDRSTRLEN];
char uptime[BGP_UPTIME_LEN];
char *out;
@ -2364,9 +2362,8 @@ DEFPY(show_bmp,
vty_out(vty, " Listeners:\n");
frr_each (bmp_listeners, &bt->listeners, bl)
vty_out(vty, " %s:%d\n",
sockunion2str(&bl->addr, buf,
SU_ADDRSTRLEN), bl->port);
vty_out(vty, " %pSU:%d\n", &bl->addr,
bl->port);
vty_out(vty, "\n Outbound connections:\n");
tt = ttable_new(&ttable_styles[TTSTYLE_BLANK]);
@ -2379,13 +2376,11 @@ DEFPY(show_bmp,
peer_uptime(ba->bmp->t_up.tv_sec,
uptime, sizeof(uptime),
false, NULL);
ttable_add_row(tt, "%s:%d|Up|%s|%s|%s",
ttable_add_row(tt,
"%s:%d|Up|%s|%s|%pSU",
ba->hostname, ba->port,
ba->bmp->remote, uptime,
sockunion2str(
&ba->addrsrc,
buf,
SU_ADDRSTRLEN));
&ba->addrsrc);
continue;
}
@ -2405,15 +2400,11 @@ DEFPY(show_bmp,
state_str = "Resolving";
}
sockunion2str(&ba->addrsrc,
buf,
SU_ADDRSTRLEN);
ttable_add_row(tt, "%s:%d|%s|%s|%s|%s",
ttable_add_row(tt, "%s:%d|%s|%s|%s|%pSU",
ba->hostname, ba->port,
state_str,
ba->last_err ? ba->last_err : "",
uptime,
buf);
uptime, &ba->addrsrc);
continue;
}
out = ttable_dump(tt, "\n");
@ -2460,7 +2451,6 @@ static int bmp_config_write(struct bgp *bgp, struct vty *vty)
struct bmp_targets *bt;
struct bmp_listener *bl;
struct bmp_active *ba;
char buf[SU_ADDRSTRLEN];
afi_t afi;
safi_t safi;
@ -2497,9 +2487,8 @@ static int bmp_config_write(struct bgp *bgp, struct vty *vty)
afi_str, safi2str(safi));
}
frr_each (bmp_listeners, &bt->listeners, bl)
vty_out(vty, " \n bmp listener %s port %d\n",
sockunion2str(&bl->addr, buf, SU_ADDRSTRLEN),
bl->port);
vty_out(vty, " \n bmp listener %pSU port %d\n",
&bl->addr, bl->port);
frr_each (bmp_actives, &bt->actives, ba) {
vty_out(vty, " bmp connect %s port %u min-retry %u max-retry %u",

View File

@ -59,14 +59,10 @@ void bgp_dump_listener_info(struct vty *vty)
vty_out(vty, "Name fd Address\n");
vty_out(vty, "---------------------------\n");
for (ALL_LIST_ELEMENTS_RO(bm->listen_sockets, node, listener)) {
char buf[SU_ADDRSTRLEN];
vty_out(vty, "%-16s %d %s\n",
for (ALL_LIST_ELEMENTS_RO(bm->listen_sockets, node, listener))
vty_out(vty, "%-16s %d %pSU\n",
listener->name ? listener->name : VRF_DEFAULT_NAME,
listener->fd,
sockunion2str(&listener->su, buf, sizeof(buf)));
}
listener->fd, &listener->su);
}
/*
@ -103,21 +99,18 @@ static int bgp_md5_set_socket(int socket, union sockunion *su,
#endif /* HAVE_TCP_MD5SIG */
if (ret < 0) {
char sabuf[SU_ADDRSTRLEN];
sockunion2str(su, sabuf, sizeof(sabuf));
switch (ret) {
case -2:
flog_warn(
EC_BGP_NO_TCP_MD5,
"Unable to set TCP MD5 option on socket for peer %s (sock=%d): This platform does not support MD5 auth for prefixes",
sabuf, socket);
"Unable to set TCP MD5 option on socket for peer %pSU (sock=%d): This platform does not support MD5 auth for prefixes",
su, socket);
break;
default:
flog_warn(
EC_BGP_NO_TCP_MD5,
"Unable to set TCP MD5 option on socket for peer %s (sock=%d): %s",
sabuf, socket, safe_strerror(en));
"Unable to set TCP MD5 option on socket for peer %pSU (sock=%d): %s",
su, socket, safe_strerror(en));
}
}

View File

@ -9122,12 +9122,9 @@ void route_vty_out(struct vty *vty, const struct prefix *p,
else
vty_out(vty, "%7u ", attr->weight);
if (json_paths) {
char buf[BUFSIZ];
json_object_string_add(
json_path, "peerId",
sockunion2str(&path->peer->su, buf, SU_ADDRSTRLEN));
}
if (json_paths)
json_object_string_addf(json_path, "peerId", "%pSU",
&path->peer->su);
/* Print aspath */
if (attr->aspath) {
@ -9719,7 +9716,6 @@ static void route_vty_out_advertised_to(struct vty *vty, struct peer *peer,
int *first, const char *header,
json_object *json_adv_to)
{
char buf1[INET6_ADDRSTRLEN];
json_object *json_peer = NULL;
if (json_adv_to) {
@ -9739,10 +9735,8 @@ static void route_vty_out_advertised_to(struct vty *vty, struct peer *peer,
json_object_object_add(json_adv_to, peer->conf_if,
json_peer);
else
json_object_object_add(
json_adv_to,
sockunion2str(&peer->su, buf1, SU_ADDRSTRLEN),
json_peer);
json_object_object_addf(json_adv_to, json_peer, "%pSU",
&peer->su);
} else {
if (*first) {
vty_out(vty, "%s", header);
@ -9755,16 +9749,13 @@ static void route_vty_out_advertised_to(struct vty *vty, struct peer *peer,
vty_out(vty, " %s(%s)", peer->hostname,
peer->conf_if);
else
vty_out(vty, " %s(%s)", peer->hostname,
sockunion2str(&peer->su, buf1,
SU_ADDRSTRLEN));
vty_out(vty, " %s(%pSU)", peer->hostname,
&peer->su);
} else {
if (peer->conf_if)
vty_out(vty, " %s", peer->conf_if);
else
vty_out(vty, " %s",
sockunion2str(&peer->su, buf1,
SU_ADDRSTRLEN));
vty_out(vty, " %pSU", &peer->su);
}
}
}
@ -10184,10 +10175,8 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp, struct bgp_dest *bn,
else {
if (json_paths) {
json_object_string_add(json_peer, "peerId",
sockunion2str(&path->peer->su,
buf,
SU_ADDRSTRLEN));
json_object_string_addf(json_peer, "peerId", "%pSU",
&path->peer->su);
json_object_string_addf(json_peer, "routerId", "%pI4",
&path->peer->remote_id);
@ -10221,10 +10210,8 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp, struct bgp_dest *bn,
path->peer->hostname,
path->peer->host);
else
vty_out(vty, " from %s",
sockunion2str(&path->peer->su,
buf,
SU_ADDRSTRLEN));
vty_out(vty, " from %pSU",
&path->peer->su);
}
if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
@ -14963,10 +14950,8 @@ static void show_bgp_peerhash_entry(struct hash_bucket *bucket, void *arg)
{
struct vty *vty = arg;
struct peer *peer = bucket->data;
char buf[SU_ADDRSTRLEN];
vty_out(vty, "\tPeer: %s %s\n", peer->host,
sockunion2str(&peer->su, buf, sizeof(buf)));
vty_out(vty, "\tPeer: %s %pSU\n", peer->host, &peer->su);
}
DEFUN (show_bgp_listeners,

View File

@ -11679,7 +11679,6 @@ static void bgp_show_neighbor_graceful_restart_time(struct vty *vty,
static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
bool use_json, json_object *json)
{
char buf[SU_ADDRSTRLEN] = {0};
char dn_flag[2] = {0};
/* '*' + v6 address of neighbor */
char neighborAddr[INET6_ADDRSTRLEN + 1] = {0};
@ -11689,18 +11688,11 @@ static void bgp_show_peer_gr_status(struct vty *vty, struct peer *p,
if (p->conf_if) {
if (use_json)
json_object_string_add(
json, "neighborAddr",
BGP_PEER_SU_UNSPEC(p)
? "none"
: sockunion2str(&p->su, buf,
SU_ADDRSTRLEN));
json_object_string_addf(json, "neighborAddr", "%pSU",
&p->su);
else
vty_out(vty, "BGP neighbor on %s: %s\n", p->conf_if,
BGP_PEER_SU_UNSPEC(p)
? "none"
: sockunion2str(&p->su, buf,
SU_ADDRSTRLEN));
vty_out(vty, "BGP neighbor on %s: %pSU\n", p->conf_if,
&p->su);
} else {
snprintf(neighborAddr, sizeof(neighborAddr), "%s%s", dn_flag,
p->host);
@ -12368,7 +12360,7 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
json_object *json)
{
struct bgp *bgp;
char buf1[PREFIX2STR_BUFFER], buf[SU_ADDRSTRLEN];
char buf1[PREFIX2STR_BUFFER];
char timebuf[BGP_UPTIME_LEN];
char dn_flag[2];
afi_t afi;
@ -12390,11 +12382,8 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
if (!use_json) {
if (p->conf_if) /* Configured interface name. */
vty_out(vty, "BGP neighbor on %s: %s, ", p->conf_if,
BGP_PEER_SU_UNSPEC(p)
? "None"
: sockunion2str(&p->su, buf,
SU_ADDRSTRLEN));
vty_out(vty, "BGP neighbor on %s: %pSU, ", p->conf_if,
&p->su);
else /* Configured IP address. */
vty_out(vty, "BGP neighbor is %s%s, ", dn_flag,
p->host);
@ -12405,9 +12394,8 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
json_object_string_add(json_neigh, "bgpNeighborAddr",
"none");
else if (p->conf_if && !BGP_PEER_SU_UNSPEC(p))
json_object_string_add(
json_neigh, "bgpNeighborAddr",
sockunion2str(&p->su, buf, SU_ADDRSTRLEN));
json_object_string_addf(json_neigh, "bgpNeighborAddr",
"%pSU", &p->su);
json_object_int_add(json_neigh, "remoteAs", p->as);
@ -13814,10 +13802,9 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
"updateSource",
p->update_if);
else if (p->update_source)
json_object_string_add(
json_neigh, "updateSource",
sockunion2str(p->update_source, buf1,
SU_ADDRSTRLEN));
json_object_string_addf(json_neigh,
"updateSource", "%pSU",
p->update_source);
}
} else {
/* advertisement-interval */
@ -13831,9 +13818,7 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
if (p->update_if)
vty_out(vty, "%s", p->update_if);
else if (p->update_source)
vty_out(vty, "%s",
sockunion2str(p->update_source, buf1,
SU_ADDRSTRLEN));
vty_out(vty, "%pSU", p->update_source);
vty_out(vty, "\n");
}
@ -13989,15 +13974,13 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
/* Local address. */
if (p->su_local) {
if (use_json) {
json_object_string_add(json_neigh, "hostLocal",
sockunion2str(p->su_local, buf1,
SU_ADDRSTRLEN));
json_object_string_addf(json_neigh, "hostLocal", "%pSU",
p->su_local);
json_object_int_add(json_neigh, "portLocal",
ntohs(p->su_local->sin.sin_port));
} else
vty_out(vty, "Local host: %s, Local port: %d\n",
sockunion2str(p->su_local, buf1, SU_ADDRSTRLEN),
ntohs(p->su_local->sin.sin_port));
vty_out(vty, "Local host: %pSU, Local port: %d\n",
p->su_local, ntohs(p->su_local->sin.sin_port));
} else {
if (use_json) {
json_object_string_add(json_neigh, "hostLocal",
@ -14009,15 +13992,13 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
/* Remote address. */
if (p->su_remote) {
if (use_json) {
json_object_string_add(json_neigh, "hostForeign",
sockunion2str(p->su_remote, buf1,
SU_ADDRSTRLEN));
json_object_string_addf(json_neigh, "hostForeign",
"%pSU", p->su_remote);
json_object_int_add(json_neigh, "portForeign",
ntohs(p->su_remote->sin.sin_port));
} else
vty_out(vty, "Foreign host: %s, Foreign port: %d\n",
sockunion2str(p->su_remote, buf1,
SU_ADDRSTRLEN),
vty_out(vty, "Foreign host: %pSU, Foreign port: %d\n",
p->su_remote,
ntohs(p->su_remote->sin.sin_port));
} else {
if (use_json) {
@ -16506,7 +16487,6 @@ static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
struct peer *peer)
{
struct peer *g_peer = NULL;
char buf[SU_ADDRSTRLEN];
char *addr;
int if_pg_printed = false;
int if_ras_printed = false;
@ -16699,9 +16679,8 @@ static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
/* update-source */
if (peergroup_flag_check(peer, PEER_FLAG_UPDATE_SOURCE)) {
if (peer->update_source)
vty_out(vty, " neighbor %s update-source %s\n", addr,
sockunion2str(peer->update_source, buf,
SU_ADDRSTRLEN));
vty_out(vty, " neighbor %s update-source %pSU\n", addr,
peer->update_source);
else if (peer->update_if)
vty_out(vty, " neighbor %s update-source %s\n", addr,
peer->update_if);

View File

@ -1094,12 +1094,10 @@ void nexthop_group_json_nexthop(json_object *j, const struct nexthop *nh)
static void nexthop_group_write_nexthop_internal(struct vty *vty,
const struct nexthop_hold *nh)
{
char buf[100];
vty_out(vty, "nexthop");
if (nh->addr)
vty_out(vty, " %s", sockunion2str(nh->addr, buf, sizeof(buf)));
vty_out(vty, " %pSU", nh->addr);
if (nh->intf)
vty_out(vty, " %s", nh->intf);

View File

@ -163,7 +163,6 @@ static void nhrp_reg_send_req(struct thread *t)
{
struct nhrp_registration *r = THREAD_ARG(t);
struct nhrp_nhs *nhs = r->nhs;
char buf1[SU_ADDRSTRLEN], buf2[SU_ADDRSTRLEN];
struct interface *ifp = nhs->ifp;
struct nhrp_interface *nifp = ifp->info;
struct nhrp_afi_data *if_ad = &nifp->afi[nhs->afi];
@ -189,10 +188,8 @@ static void nhrp_reg_send_req(struct thread *t)
if (sockunion_family(dst_proto) == AF_UNSPEC)
dst_proto = &if_ad->addr;
sockunion2str(&if_ad->addr, buf1, sizeof(buf1));
sockunion2str(dst_proto, buf2, sizeof(buf2));
debugf(NHRP_DEBUG_COMMON, "NHS: Register %s -> %s (timeout %d)", buf1,
buf2, r->timeout);
debugf(NHRP_DEBUG_COMMON, "NHS: Register %pSU -> %pSU (timeout %d)",
&if_ad->addr, dst_proto, r->timeout);
/* No protocol address configured for tunnel interface */
if (sockunion_family(&if_ad->addr) == AF_UNSPEC)

View File

@ -1083,7 +1083,6 @@ err:
static void nhrp_packet_debug(struct zbuf *zb, const char *dir)
{
char buf[2][SU_ADDRSTRLEN];
union sockunion src_nbma, src_proto, dst_proto;
struct nhrp_packet_header *hdr;
struct zbuf zhdr;
@ -1095,14 +1094,12 @@ static void nhrp_packet_debug(struct zbuf *zb, const char *dir)
zbuf_init(&zhdr, zb->buf, zb->tail - zb->buf, zb->tail - zb->buf);
hdr = nhrp_packet_pull(&zhdr, &src_nbma, &src_proto, &dst_proto);
sockunion2str(&src_proto, buf[0], sizeof(buf[0]));
sockunion2str(&dst_proto, buf[1], sizeof(buf[1]));
reply = packet_types[hdr->type].type == PACKET_REPLY;
debugf(NHRP_DEBUG_COMMON, "%s %s(%d) %s -> %s", dir,
debugf(NHRP_DEBUG_COMMON, "%s %s(%d) %pSU -> %pSU", dir,
(packet_types[hdr->type].name ? packet_types[hdr->type].name
: "Unknown"),
hdr->type, reply ? buf[1] : buf[0], reply ? buf[0] : buf[1]);
hdr->type, reply ? &dst_proto : &src_proto,
reply ? &src_proto : &dst_proto);
}
static int proto2afi(uint16_t proto)

View File

@ -48,23 +48,17 @@ static void nhrp_shortcut_do_expire(struct thread *t)
static void nhrp_shortcut_cache_notify(struct notifier_block *n,
unsigned long cmd)
{
char buf2[PREFIX_STRLEN];
struct nhrp_shortcut *s =
container_of(n, struct nhrp_shortcut, cache_notifier);
struct nhrp_cache *c = s->cache;
if (c)
sockunion2str(&c->remote_addr, buf2, sizeof(buf2));
else
snprintf(buf2, sizeof(buf2), "(unspec)");
switch (cmd) {
case NOTIFY_CACHE_UP:
if (!s->route_installed) {
debugf(NHRP_DEBUG_ROUTE,
"Shortcut: route install %pFX nh %s dev %s",
s->p, buf2, c && c->ifp ?
c->ifp->name : "<unk>");
"Shortcut: route install %pFX nh %pSU dev %s",
s->p, &c->remote_addr,
c && c->ifp ? c->ifp->name : "<unk>");
nhrp_route_announce(1, s->type, s->p, c ? c->ifp : NULL,
c ? &c->remote_addr : NULL, 0);

View File

@ -1001,18 +1001,15 @@ static void show_dmvpn_entry(struct nhrp_vc *vc, void *ctx)
{
struct dmvpn_cfg *ctxt = ctx;
struct vty *vty;
char buf[2][SU_ADDRSTRLEN];
struct json_object *json = NULL;
if (!ctxt || !ctxt->vty)
return;
vty = ctxt->vty;
sockunion2str(&vc->local.nbma, buf[0], sizeof(buf[0]));
sockunion2str(&vc->remote.nbma, buf[1], sizeof(buf[1]));
if (ctxt->json) {
json = json_object_new_object();
json_object_string_add(json, "src", buf[0]);
json_object_string_add(json, "dst", buf[1]);
json_object_string_addf(json, "src", "%pSU", &vc->local.nbma);
json_object_string_addf(json, "dst", "%pSU", &vc->remote.nbma);
if (notifier_active(&vc->notifier_list))
json_object_boolean_true_add(json, "notifierActive");
@ -1023,9 +1020,10 @@ static void show_dmvpn_entry(struct nhrp_vc *vc, void *ctx)
json_object_string_add(json, "identity", vc->remote.id);
json_object_array_add(ctxt->json, json);
} else {
vty_out(vty, "%-24s %-24s %c %-4d %-24s\n",
buf[0], buf[1], notifier_active(&vc->notifier_list) ?
'n' : ' ', vc->ipsec, vc->remote.id);
vty_out(vty, "%-24pSU %-24pSU %c %-4d %-24s\n",
&vc->local.nbma, &vc->remote.nbma,
notifier_active(&vc->notifier_list) ? 'n' : ' ',
vc->ipsec, vc->remote.id);
}
}