Commit a418e451 authored by Phil Sutter's avatar Phil Sutter Committed by Stephen Hemminger

make format_host non-reentrant by default

There are only three users which require it to be reentrant, the rest is
fine without. Instead, provide a reentrant format_host_r() for users
which need it.
Signed-off-by: default avatarPhil Sutter <phil@nwl.cc>
parent ff9d8f37
...@@ -104,7 +104,6 @@ int print_fdb(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) ...@@ -104,7 +104,6 @@ int print_fdb(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
fprintf(fp, "dev %s ", ll_index_to_name(r->ndm_ifindex)); fprintf(fp, "dev %s ", ll_index_to_name(r->ndm_ifindex));
if (tb[NDA_DST]) { if (tb[NDA_DST]) {
SPRINT_BUF(abuf);
int family = AF_INET; int family = AF_INET;
if (RTA_PAYLOAD(tb[NDA_DST]) == sizeof(struct in6_addr)) if (RTA_PAYLOAD(tb[NDA_DST]) == sizeof(struct in6_addr))
...@@ -113,8 +112,7 @@ int print_fdb(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) ...@@ -113,8 +112,7 @@ int print_fdb(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
fprintf(fp, "dst %s ", fprintf(fp, "dst %s ",
format_host(family, format_host(family,
RTA_PAYLOAD(tb[NDA_DST]), RTA_PAYLOAD(tb[NDA_DST]),
RTA_DATA(tb[NDA_DST]), RTA_DATA(tb[NDA_DST])));
abuf, sizeof(abuf)));
} }
if (tb[NDA_VLAN]) { if (tb[NDA_VLAN]) {
......
...@@ -122,8 +122,9 @@ int addr64_n2a(__u64 addr, char *buff, size_t len); ...@@ -122,8 +122,9 @@ int addr64_n2a(__u64 addr, char *buff, size_t len);
int af_bit_len(int af); int af_bit_len(int af);
int af_byte_len(int af); int af_byte_len(int af);
const char *format_host(int af, int len, const void *addr, const char *format_host_r(int af, int len, const void *addr,
char *buf, int buflen); char *buf, int buflen);
const char *format_host(int af, int lne, const void *addr);
const char *rt_addr_n2a(int af, int len, const void *addr, const char *rt_addr_n2a(int af, int len, const void *addr,
char *buf, int buflen); char *buf, int buflen);
......
...@@ -77,7 +77,7 @@ static void print_tunnel(struct ip6_tnl_parm2 *p) ...@@ -77,7 +77,7 @@ static void print_tunnel(struct ip6_tnl_parm2 *p)
printf("%s: %s/ipv6 remote %s local %s", printf("%s: %s/ipv6 remote %s local %s",
p->name, p->name,
tnl_strproto(p->proto), tnl_strproto(p->proto),
format_host(AF_INET6, 16, &p->raddr, s1, sizeof(s1)), format_host_r(AF_INET6, 16, &p->raddr, s1, sizeof(s1)),
rt_addr_n2a(AF_INET6, 16, &p->laddr, s2, sizeof(s2))); rt_addr_n2a(AF_INET6, 16, &p->laddr, s2, sizeof(s2)));
if (p->link) { if (p->link) {
const char *n = ll_index_to_name(p->link); const char *n = ll_index_to_name(p->link);
......
...@@ -964,7 +964,6 @@ int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n, ...@@ -964,7 +964,6 @@ int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n,
/* Use local copy of ifa_flags to not interfere with filtering code */ /* Use local copy of ifa_flags to not interfere with filtering code */
unsigned int ifa_flags; unsigned int ifa_flags;
struct rtattr *rta_tb[IFA_MAX+1]; struct rtattr *rta_tb[IFA_MAX+1];
char abuf[256];
SPRINT_BUF(b1); SPRINT_BUF(b1);
...@@ -1061,8 +1060,7 @@ int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n, ...@@ -1061,8 +1060,7 @@ int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n,
color_fprintf(fp, ifa_family_color(ifa->ifa_family), "%s", color_fprintf(fp, ifa_family_color(ifa->ifa_family), "%s",
format_host(ifa->ifa_family, format_host(ifa->ifa_family,
RTA_PAYLOAD(rta_tb[IFA_LOCAL]), RTA_PAYLOAD(rta_tb[IFA_LOCAL]),
RTA_DATA(rta_tb[IFA_LOCAL]), RTA_DATA(rta_tb[IFA_LOCAL])));
abuf, sizeof(abuf)));
if (rta_tb[IFA_ADDRESS] && if (rta_tb[IFA_ADDRESS] &&
memcmp(RTA_DATA(rta_tb[IFA_ADDRESS]), memcmp(RTA_DATA(rta_tb[IFA_ADDRESS]),
RTA_DATA(rta_tb[IFA_LOCAL]), RTA_DATA(rta_tb[IFA_LOCAL]),
...@@ -1071,8 +1069,7 @@ int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n, ...@@ -1071,8 +1069,7 @@ int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n,
color_fprintf(fp, ifa_family_color(ifa->ifa_family), color_fprintf(fp, ifa_family_color(ifa->ifa_family),
"%s", format_host(ifa->ifa_family, "%s", format_host(ifa->ifa_family,
RTA_PAYLOAD(rta_tb[IFA_ADDRESS]), RTA_PAYLOAD(rta_tb[IFA_ADDRESS]),
RTA_DATA(rta_tb[IFA_ADDRESS]), RTA_DATA(rta_tb[IFA_ADDRESS])));
abuf, sizeof(abuf)));
} }
fprintf(fp, "/%d ", ifa->ifa_prefixlen); fprintf(fp, "/%d ", ifa->ifa_prefixlen);
} }
...@@ -1085,16 +1082,14 @@ int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n, ...@@ -1085,16 +1082,14 @@ int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n,
color_fprintf(fp, ifa_family_color(ifa->ifa_family), "%s ", color_fprintf(fp, ifa_family_color(ifa->ifa_family), "%s ",
format_host(ifa->ifa_family, format_host(ifa->ifa_family,
RTA_PAYLOAD(rta_tb[IFA_BROADCAST]), RTA_PAYLOAD(rta_tb[IFA_BROADCAST]),
RTA_DATA(rta_tb[IFA_BROADCAST]), RTA_DATA(rta_tb[IFA_BROADCAST])));
abuf, sizeof(abuf)));
} }
if (rta_tb[IFA_ANYCAST]) { if (rta_tb[IFA_ANYCAST]) {
fprintf(fp, "any "); fprintf(fp, "any ");
color_fprintf(fp, ifa_family_color(ifa->ifa_family), "%s ", color_fprintf(fp, ifa_family_color(ifa->ifa_family), "%s ",
format_host(ifa->ifa_family, format_host(ifa->ifa_family,
RTA_PAYLOAD(rta_tb[IFA_ANYCAST]), RTA_PAYLOAD(rta_tb[IFA_ANYCAST]),
RTA_DATA(rta_tb[IFA_ANYCAST]), RTA_DATA(rta_tb[IFA_ANYCAST])));
abuf, sizeof(abuf)));
} }
fprintf(fp, "scope %s ", rtnl_rtscope_n2a(ifa->ifa_scope, b1, sizeof(b1))); fprintf(fp, "scope %s ", rtnl_rtscope_n2a(ifa->ifa_scope, b1, sizeof(b1)));
if (ifa_flags & IFA_F_SECONDARY) { if (ifa_flags & IFA_F_SECONDARY) {
......
...@@ -60,7 +60,6 @@ int print_addrlabel(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg ...@@ -60,7 +60,6 @@ int print_addrlabel(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg
struct ifaddrlblmsg *ifal = NLMSG_DATA(n); struct ifaddrlblmsg *ifal = NLMSG_DATA(n);
int len = n->nlmsg_len; int len = n->nlmsg_len;
struct rtattr *tb[IFAL_MAX+1]; struct rtattr *tb[IFAL_MAX+1];
char abuf[256];
if (n->nlmsg_type != RTM_NEWADDRLABEL && n->nlmsg_type != RTM_DELADDRLABEL) if (n->nlmsg_type != RTM_NEWADDRLABEL && n->nlmsg_type != RTM_DELADDRLABEL)
return 0; return 0;
...@@ -78,8 +77,7 @@ int print_addrlabel(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg ...@@ -78,8 +77,7 @@ int print_addrlabel(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg
fprintf(fp, "prefix %s/%u ", fprintf(fp, "prefix %s/%u ",
format_host(ifal->ifal_family, format_host(ifal->ifal_family,
RTA_PAYLOAD(tb[IFAL_ADDRESS]), RTA_PAYLOAD(tb[IFAL_ADDRESS]),
RTA_DATA(tb[IFAL_ADDRESS]), RTA_DATA(tb[IFAL_ADDRESS])),
abuf, sizeof(abuf)),
ifal->ifal_prefixlen); ifal->ifal_prefixlen);
} }
......
...@@ -138,7 +138,6 @@ static int geneve_parse_opt(struct link_util *lu, int argc, char **argv, ...@@ -138,7 +138,6 @@ static int geneve_parse_opt(struct link_util *lu, int argc, char **argv,
static void geneve_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) static void geneve_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
{ {
__u32 vni; __u32 vni;
char s1[1024];
__u8 tos; __u8 tos;
if (!tb) if (!tb)
...@@ -156,7 +155,7 @@ static void geneve_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) ...@@ -156,7 +155,7 @@ static void geneve_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
if (addr) if (addr)
fprintf(f, "remote %s ", fprintf(f, "remote %s ",
format_host(AF_INET, 4, &addr, s1, sizeof(s1))); format_host(AF_INET, 4, &addr));
} else if (tb[IFLA_GENEVE_REMOTE6]) { } else if (tb[IFLA_GENEVE_REMOTE6]) {
struct in6_addr addr; struct in6_addr addr;
...@@ -164,7 +163,7 @@ static void geneve_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) ...@@ -164,7 +163,7 @@ static void geneve_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
if (memcmp(&addr, &in6addr_any, sizeof(addr)) != 0) { if (memcmp(&addr, &in6addr_any, sizeof(addr)) != 0) {
if (IN6_IS_ADDR_MULTICAST(&addr)) if (IN6_IS_ADDR_MULTICAST(&addr))
fprintf(f, "remote %s ", fprintf(f, "remote %s ",
format_host(AF_INET6, sizeof(struct in6_addr), &addr, s1, sizeof(s1))); format_host(AF_INET6, sizeof(struct in6_addr), &addr));
} }
} }
......
...@@ -310,7 +310,6 @@ static void vxlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) ...@@ -310,7 +310,6 @@ static void vxlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
unsigned int link; unsigned int link;
__u8 tos; __u8 tos;
__u32 maxaddr; __u32 maxaddr;
char s1[1024];
char s2[64]; char s2[64];
if (!tb) if (!tb)
...@@ -329,10 +328,10 @@ static void vxlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) ...@@ -329,10 +328,10 @@ static void vxlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
if (addr) { if (addr) {
if (IN_MULTICAST(ntohl(addr))) if (IN_MULTICAST(ntohl(addr)))
fprintf(f, "group %s ", fprintf(f, "group %s ",
format_host(AF_INET, 4, &addr, s1, sizeof(s1))); format_host(AF_INET, 4, &addr));
else else
fprintf(f, "remote %s ", fprintf(f, "remote %s ",
format_host(AF_INET, 4, &addr, s1, sizeof(s1))); format_host(AF_INET, 4, &addr));
} }
} else if (tb[IFLA_VXLAN_GROUP6]) { } else if (tb[IFLA_VXLAN_GROUP6]) {
struct in6_addr addr; struct in6_addr addr;
...@@ -341,10 +340,10 @@ static void vxlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) ...@@ -341,10 +340,10 @@ static void vxlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
if (memcmp(&addr, &in6addr_any, sizeof(addr)) != 0) { if (memcmp(&addr, &in6addr_any, sizeof(addr)) != 0) {
if (IN6_IS_ADDR_MULTICAST(&addr)) if (IN6_IS_ADDR_MULTICAST(&addr))
fprintf(f, "group %s ", fprintf(f, "group %s ",
format_host(AF_INET6, sizeof(struct in6_addr), &addr, s1, sizeof(s1))); format_host(AF_INET6, sizeof(struct in6_addr), &addr));
else else
fprintf(f, "remote %s ", fprintf(f, "remote %s ",
format_host(AF_INET6, sizeof(struct in6_addr), &addr, s1, sizeof(s1))); format_host(AF_INET6, sizeof(struct in6_addr), &addr));
} }
} }
...@@ -353,14 +352,14 @@ static void vxlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) ...@@ -353,14 +352,14 @@ static void vxlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
if (addr) if (addr)
fprintf(f, "local %s ", fprintf(f, "local %s ",
format_host(AF_INET, 4, &addr, s1, sizeof(s1))); format_host(AF_INET, 4, &addr));
} else if (tb[IFLA_VXLAN_LOCAL6]) { } else if (tb[IFLA_VXLAN_LOCAL6]) {
struct in6_addr addr; struct in6_addr addr;
memcpy(&addr, RTA_DATA(tb[IFLA_VXLAN_LOCAL6]), sizeof(struct in6_addr)); memcpy(&addr, RTA_DATA(tb[IFLA_VXLAN_LOCAL6]), sizeof(struct in6_addr));
if (memcmp(&addr, &in6addr_any, sizeof(addr)) != 0) if (memcmp(&addr, &in6addr_any, sizeof(addr)) != 0)
fprintf(f, "local %s ", fprintf(f, "local %s ",
format_host(AF_INET6, sizeof(struct in6_addr), &addr, s1, sizeof(s1))); format_host(AF_INET6, sizeof(struct in6_addr), &addr));
} }
if (tb[IFLA_VXLAN_LINK] && if (tb[IFLA_VXLAN_LINK] &&
......
...@@ -204,8 +204,6 @@ static void print_maddr(FILE *fp, struct ma_info *list) ...@@ -204,8 +204,6 @@ static void print_maddr(FILE *fp, struct ma_info *list)
list->addr.bytelen, 0, list->addr.bytelen, 0,
b1, sizeof(b1))); b1, sizeof(b1)));
} else { } else {
char abuf[256];
switch (list->addr.family) { switch (list->addr.family) {
case AF_INET: case AF_INET:
fprintf(fp, "inet "); fprintf(fp, "inet ");
...@@ -219,9 +217,7 @@ static void print_maddr(FILE *fp, struct ma_info *list) ...@@ -219,9 +217,7 @@ static void print_maddr(FILE *fp, struct ma_info *list)
} }
fprintf(fp, "%s", fprintf(fp, "%s",
format_host(list->addr.family, format_host(list->addr.family,
-1, -1, list->addr.data));
list->addr.data,
abuf, sizeof(abuf)));
} }
if (list->users != 1) if (list->users != 1)
fprintf(fp, " users %d", list->users); fprintf(fp, " users %d", list->users);
......
...@@ -198,7 +198,6 @@ int print_neigh(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) ...@@ -198,7 +198,6 @@ int print_neigh(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
struct ndmsg *r = NLMSG_DATA(n); struct ndmsg *r = NLMSG_DATA(n);
int len = n->nlmsg_len; int len = n->nlmsg_len;
struct rtattr *tb[NDA_MAX+1]; struct rtattr *tb[NDA_MAX+1];
char abuf[256];
static int logit = 1; static int logit = 1;
if (n->nlmsg_type != RTM_NEWNEIGH && n->nlmsg_type != RTM_DELNEIGH && if (n->nlmsg_type != RTM_NEWNEIGH && n->nlmsg_type != RTM_DELNEIGH &&
...@@ -281,8 +280,7 @@ int print_neigh(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) ...@@ -281,8 +280,7 @@ int print_neigh(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
fprintf(fp, "%s ", fprintf(fp, "%s ",
format_host(r->ndm_family, format_host(r->ndm_family,
RTA_PAYLOAD(tb[NDA_DST]), RTA_PAYLOAD(tb[NDA_DST]),
RTA_DATA(tb[NDA_DST]), RTA_DATA(tb[NDA_DST])));
abuf, sizeof(abuf)));
} }
if (!filter.index && r->ndm_ifindex) if (!filter.index && r->ndm_ifindex)
fprintf(fp, "dev %s ", ll_index_to_name(r->ndm_ifindex)); fprintf(fp, "dev %s ", ll_index_to_name(r->ndm_ifindex));
......
...@@ -380,8 +380,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) ...@@ -380,8 +380,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
} else { } else {
fprintf(fp, "%s ", format_host(r->rtm_family, fprintf(fp, "%s ", format_host(r->rtm_family,
RTA_PAYLOAD(tb[RTA_DST]), RTA_PAYLOAD(tb[RTA_DST]),
RTA_DATA(tb[RTA_DST]), RTA_DATA(tb[RTA_DST]))
abuf, sizeof(abuf))
); );
} }
} else if (r->rtm_dst_len) { } else if (r->rtm_dst_len) {
...@@ -400,8 +399,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) ...@@ -400,8 +399,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
} else { } else {
fprintf(fp, "from %s ", format_host(r->rtm_family, fprintf(fp, "from %s ", format_host(r->rtm_family,
RTA_PAYLOAD(tb[RTA_SRC]), RTA_PAYLOAD(tb[RTA_SRC]),
RTA_DATA(tb[RTA_SRC]), RTA_DATA(tb[RTA_SRC]))
abuf, sizeof(abuf))
); );
} }
} else if (r->rtm_src_len) { } else if (r->rtm_src_len) {
...@@ -410,8 +408,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) ...@@ -410,8 +408,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
if (tb[RTA_NEWDST]) { if (tb[RTA_NEWDST]) {
fprintf(fp, "as to %s ", format_host(r->rtm_family, fprintf(fp, "as to %s ", format_host(r->rtm_family,
RTA_PAYLOAD(tb[RTA_NEWDST]), RTA_PAYLOAD(tb[RTA_NEWDST]),
RTA_DATA(tb[RTA_NEWDST]), RTA_DATA(tb[RTA_NEWDST]))
abuf, sizeof(abuf))
); );
} }
...@@ -427,8 +424,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) ...@@ -427,8 +424,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
fprintf(fp, "via %s ", fprintf(fp, "via %s ",
format_host(r->rtm_family, format_host(r->rtm_family,
RTA_PAYLOAD(tb[RTA_GATEWAY]), RTA_PAYLOAD(tb[RTA_GATEWAY]),
RTA_DATA(tb[RTA_GATEWAY]), RTA_DATA(tb[RTA_GATEWAY])));
abuf, sizeof(abuf)));
} }
if (tb[RTA_VIA]) { if (tb[RTA_VIA]) {
size_t len = RTA_PAYLOAD(tb[RTA_VIA]) - 2; size_t len = RTA_PAYLOAD(tb[RTA_VIA]) - 2;
...@@ -436,8 +432,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) ...@@ -436,8 +432,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
fprintf(fp, "via %s %s ", fprintf(fp, "via %s %s ",
family_name(via->rtvia_family), family_name(via->rtvia_family),
format_host(via->rtvia_family, len, via->rtvia_addr, format_host(via->rtvia_family, len, via->rtvia_addr));
abuf, sizeof(abuf)));
} }
if (tb[RTA_OIF] && filter.oifmask != -1) if (tb[RTA_OIF] && filter.oifmask != -1)
fprintf(fp, "dev %s ", ll_index_to_name(*(int *)RTA_DATA(tb[RTA_OIF]))); fprintf(fp, "dev %s ", ll_index_to_name(*(int *)RTA_DATA(tb[RTA_OIF])));
...@@ -671,8 +666,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) ...@@ -671,8 +666,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
fprintf(fp, " via %s ", fprintf(fp, " via %s ",
format_host(r->rtm_family, format_host(r->rtm_family,
RTA_PAYLOAD(tb[RTA_GATEWAY]), RTA_PAYLOAD(tb[RTA_GATEWAY]),
RTA_DATA(tb[RTA_GATEWAY]), RTA_DATA(tb[RTA_GATEWAY])));
abuf, sizeof(abuf)));
} }
if (tb[RTA_VIA]) { if (tb[RTA_VIA]) {
size_t len = RTA_PAYLOAD(tb[RTA_VIA]) - 2; size_t len = RTA_PAYLOAD(tb[RTA_VIA]) - 2;
...@@ -680,8 +674,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) ...@@ -680,8 +674,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
fprintf(fp, "via %s %s ", fprintf(fp, "via %s %s ",
family_name(via->rtvia_family), family_name(via->rtvia_family),
format_host(via->rtvia_family, len, via->rtvia_addr, format_host(via->rtvia_family, len, via->rtvia_addr));
abuf, sizeof(abuf)));
} }
if (tb[RTA_FLOW]) { if (tb[RTA_FLOW]) {
__u32 to = rta_getattr_u32(tb[RTA_FLOW]); __u32 to = rta_getattr_u32(tb[RTA_FLOW]);
......
...@@ -58,15 +58,13 @@ static const char *format_encap_type(int type) ...@@ -58,15 +58,13 @@ static const char *format_encap_type(int type)
static void print_encap_mpls(FILE *fp, struct rtattr *encap) static void print_encap_mpls(FILE *fp, struct rtattr *encap)
{ {
struct rtattr *tb[MPLS_IPTUNNEL_MAX+1]; struct rtattr *tb[MPLS_IPTUNNEL_MAX+1];
char abuf[256];
parse_rtattr_nested(tb, MPLS_IPTUNNEL_MAX, encap); parse_rtattr_nested(tb, MPLS_IPTUNNEL_MAX, encap);
if (tb[MPLS_IPTUNNEL_DST]) if (tb[MPLS_IPTUNNEL_DST])
fprintf(fp, " %s ", format_host(AF_MPLS, fprintf(fp, " %s ", format_host(AF_MPLS,
RTA_PAYLOAD(tb[MPLS_IPTUNNEL_DST]), RTA_PAYLOAD(tb[MPLS_IPTUNNEL_DST]),
RTA_DATA(tb[MPLS_IPTUNNEL_DST]), RTA_DATA(tb[MPLS_IPTUNNEL_DST])));
abuf, sizeof(abuf)));
} }
static void print_encap_ip(FILE *fp, struct rtattr *encap) static void print_encap_ip(FILE *fp, struct rtattr *encap)
......
...@@ -94,8 +94,7 @@ int print_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) ...@@ -94,8 +94,7 @@ int print_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
} else { } else {
fprintf(fp, "from %s ", format_host(r->rtm_family, fprintf(fp, "from %s ", format_host(r->rtm_family,
RTA_PAYLOAD(tb[FRA_SRC]), RTA_PAYLOAD(tb[FRA_SRC]),
RTA_DATA(tb[FRA_SRC]), RTA_DATA(tb[FRA_SRC]))
abuf, sizeof(abuf))
); );
} }
} else if (r->rtm_src_len) { } else if (r->rtm_src_len) {
...@@ -115,8 +114,7 @@ int print_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) ...@@ -115,8 +114,7 @@ int print_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
} else { } else {
fprintf(fp, "to %s ", format_host(r->rtm_family, fprintf(fp, "to %s ", format_host(r->rtm_family,
RTA_PAYLOAD(tb[FRA_DST]), RTA_PAYLOAD(tb[FRA_DST]),
RTA_DATA(tb[FRA_DST]), RTA_DATA(tb[FRA_DST])));
abuf, sizeof(abuf)));
} }
} else if (r->rtm_dst_len) { } else if (r->rtm_dst_len) {
fprintf(fp, "to 0/%d ", r->rtm_dst_len); fprintf(fp, "to 0/%d ", r->rtm_dst_len);
...@@ -191,8 +189,7 @@ int print_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) ...@@ -191,8 +189,7 @@ int print_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
fprintf(fp, "map-to %s ", fprintf(fp, "map-to %s ",
format_host(r->rtm_family, format_host(r->rtm_family,
RTA_PAYLOAD(tb[RTA_GATEWAY]), RTA_PAYLOAD(tb[RTA_GATEWAY]),
RTA_DATA(tb[RTA_GATEWAY]), RTA_DATA(tb[RTA_GATEWAY])));
abuf, sizeof(abuf)));
} else } else
fprintf(fp, "masquerade"); fprintf(fp, "masquerade");
} else if (r->rtm_type == FR_ACT_GOTO) { } else if (r->rtm_type == FR_ACT_GOTO) {
......
...@@ -51,7 +51,6 @@ static int print_token(const struct sockaddr_nl *who, struct nlmsghdr *n, void * ...@@ -51,7 +51,6 @@ static int print_token(const struct sockaddr_nl *who, struct nlmsghdr *n, void *
int len = n->nlmsg_len; int len = n->nlmsg_len;
struct rtattr *tb[IFLA_MAX + 1]; struct rtattr *tb[IFLA_MAX + 1];
struct rtattr *ltb[IFLA_INET6_MAX + 1]; struct rtattr *ltb[IFLA_INET6_MAX + 1];
char abuf[256];
if (n->nlmsg_type != RTM_NEWLINK) if (n->nlmsg_type != RTM_NEWLINK)
return -1; return -1;
...@@ -82,8 +81,7 @@ static int print_token(const struct sockaddr_nl *who, struct nlmsghdr *n, void * ...@@ -82,8 +81,7 @@ static int print_token(const struct sockaddr_nl *who, struct nlmsghdr *n, void *
fprintf(fp, "token %s ", fprintf(fp, "token %s ",
format_host(ifi->ifi_family, format_host(ifi->ifi_family,
RTA_PAYLOAD(ltb[IFLA_INET6_TOKEN]), RTA_PAYLOAD(ltb[IFLA_INET6_TOKEN]),
RTA_DATA(ltb[IFLA_INET6_TOKEN]), RTA_DATA(ltb[IFLA_INET6_TOKEN])));
abuf, sizeof(abuf)));
fprintf(fp, "dev %s ", ll_index_to_name(ifi->ifi_index)); fprintf(fp, "dev %s ", ll_index_to_name(ifi->ifi_index));
fprintf(fp, "\n"); fprintf(fp, "\n");
fflush(fp); fflush(fp);
......
...@@ -308,7 +308,7 @@ static void print_tunnel(struct ip_tunnel_parm *p) ...@@ -308,7 +308,7 @@ static void print_tunnel(struct ip_tunnel_parm *p)
printf("%s: %s/ip remote %s local %s", printf("%s: %s/ip remote %s local %s",
p->name, p->name,
tnl_strproto(p->iph.protocol), tnl_strproto(p->iph.protocol),
p->iph.daddr ? format_host(AF_INET, 4, &p->iph.daddr, s1, sizeof(s1)) : "any", p->iph.daddr ? format_host_r(AF_INET, 4, &p->iph.daddr, s1, sizeof(s1)) : "any",
p->iph.saddr ? rt_addr_n2a(AF_INET, 4, &p->iph.saddr, s2, sizeof(s2)) : "any"); p->iph.saddr ? rt_addr_n2a(AF_INET, 4, &p->iph.saddr, s2, sizeof(s2)) : "any");
if (p->iph.protocol == IPPROTO_IPV6 && (p->i_flags & SIT_ISATAP)) { if (p->iph.protocol == IPPROTO_IPV6 && (p->i_flags & SIT_ISATAP)) {
...@@ -324,7 +324,7 @@ static void print_tunnel(struct ip_tunnel_parm *p) ...@@ -324,7 +324,7 @@ static void print_tunnel(struct ip_tunnel_parm *p)
if (prl[i].addr != htonl(INADDR_ANY)) { if (prl[i].addr != htonl(INADDR_ANY)) {
printf(" %s %s ", printf(" %s %s ",
(prl[i].flags & PRL_DEFAULT) ? "pdr" : "pr", (prl[i].flags & PRL_DEFAULT) ? "pdr" : "pr",
format_host(AF_INET, 4, &prl[i].addr, s1, sizeof(s1))); format_host(AF_INET, 4, &prl[i].addr));
} }
} }
} }
...@@ -360,7 +360,7 @@ static void print_tunnel(struct ip_tunnel_parm *p) ...@@ -360,7 +360,7 @@ static void print_tunnel(struct ip_tunnel_parm *p)
ip6rd.prefixlen); ip6rd.prefixlen);
if (ip6rd.relay_prefix) { if (ip6rd.relay_prefix) {
printf(" 6rd-relay_prefix %s/%u", printf(" 6rd-relay_prefix %s/%u",
format_host(AF_INET, 4, &ip6rd.relay_prefix, s1, sizeof(s1)), format_host(AF_INET, 4, &ip6rd.relay_prefix),
ip6rd.relay_prefixlen); ip6rd.relay_prefixlen);
} }
} }
......
...@@ -339,7 +339,6 @@ get_failed: ...@@ -339,7 +339,6 @@ get_failed:
static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
{ {
char s1[1024];
char s2[64]; char s2[64];
const char *local = "any"; const char *local = "any";
const char *remote = "any"; const char *remote = "any";
...@@ -353,7 +352,7 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) ...@@ -353,7 +352,7 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
unsigned int addr = rta_getattr_u32(tb[IFLA_GRE_REMOTE]); unsigned int addr = rta_getattr_u32(tb[IFLA_GRE_REMOTE]);
if (addr) if (addr)
remote = format_host(AF_INET, 4, &addr, s1, sizeof(s1)); remote = format_host(AF_INET, 4, &addr);
} }
fprintf(f, "remote %s ", remote); fprintf(f, "remote %s ", remote);
...@@ -362,7 +361,7 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) ...@@ -362,7 +361,7 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
unsigned int addr = rta_getattr_u32(tb[IFLA_GRE_LOCAL]); unsigned int addr = rta_getattr_u32(tb[IFLA_GRE_LOCAL]);
if (addr) if (addr)
local = format_host(AF_INET, 4, &addr, s1, sizeof(s1)); local = format_host(AF_INET, 4, &addr);
} }
fprintf(f, "local %s ", local); fprintf(f, "local %s ", local);
......
...@@ -302,7 +302,6 @@ get_failed: ...@@ -302,7 +302,6 @@ get_failed:
static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
{ {
char s1[1024];
char s2[64]; char s2[64];
const char *local = "any"; const char *local = "any";
const char *remote = "any"; const char *remote = "any";
...@@ -327,7 +326,7 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) ...@@ -327,7 +326,7 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
memcpy(&addr, RTA_DATA(tb[IFLA_GRE_REMOTE]), sizeof(addr)); memcpy(&addr, RTA_DATA(tb[IFLA_GRE_REMOTE]), sizeof(addr));
if (memcmp(&addr, &in6_addr_any, sizeof(addr))) if (memcmp(&addr, &in6_addr_any, sizeof(addr)))
remote = format_host(AF_INET6, sizeof(addr), &addr, s1, sizeof(s1)); remote = format_host(AF_INET6, sizeof(addr), &addr);
} }
fprintf(f, "remote %s ", remote); fprintf(f, "remote %s ", remote);
...@@ -338,7 +337,7 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) ...@@ -338,7 +337,7 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
memcpy(&addr, RTA_DATA(tb[IFLA_GRE_LOCAL]), sizeof(addr)); memcpy(&addr, RTA_DATA(tb[IFLA_GRE_LOCAL]), sizeof(addr));
if (memcmp(&addr, &in6_addr_any, sizeof(addr))) if (memcmp(&addr, &in6_addr_any, sizeof(addr)))
local = format_host(AF_INET6, sizeof(addr), &addr, s1, sizeof(s1)); local = format_host(AF_INET6, sizeof(addr), &addr);
} }
fprintf(f, "local %s ", local); fprintf(f, "local %s ", local);
......
...@@ -339,7 +339,7 @@ static void iptunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[ ...@@ -339,7 +339,7 @@ static void iptunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[
unsigned int addr = rta_getattr_u32(tb[IFLA_IPTUN_REMOTE]); unsigned int addr = rta_getattr_u32(tb[IFLA_IPTUN_REMOTE]);
if (addr) if (addr)
remote = format_host(AF_INET, 4, &addr, s1, sizeof(s1)); remote = format_host(AF_INET, 4, &addr);
} }
fprintf(f, "remote %s ", remote); fprintf(f, "remote %s ", remote);
...@@ -348,7 +348,7 @@ static void iptunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[ ...@@ -348,7 +348,7 @@ static void iptunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[
unsigned int addr = rta_getattr_u32(tb[IFLA_IPTUN_LOCAL]); unsigned int addr = rta_getattr_u32(tb[IFLA_IPTUN_LOCAL]);
if (addr) if (addr)
local = format_host(AF_INET, 4, &addr, s1, sizeof(s1)); local = format_host(AF_INET, 4, &addr);
} }
fprintf(f, "local %s ", local); fprintf(f, "local %s ", local);
...@@ -404,8 +404,7 @@ static void iptunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[ ...@@ -404,8 +404,7 @@ static void iptunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[
prefixlen); prefixlen);
if (relayprefix) { if (relayprefix) {
printf("6rd-relay_prefix %s/%u ", printf("6rd-relay_prefix %s/%u ",
format_host(AF_INET, 4, &relayprefix, s1, format_host(AF_INET, 4, &relayprefix),
sizeof(s1)),
relayprefixlen); relayprefixlen);
} }
} }
......
...@@ -198,7 +198,6 @@ get_failed: ...@@ -198,7 +198,6 @@ get_failed:
static void vti_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) static void vti_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
{ {
char s1[1024];
char s2[64]; char s2[64];
const char *local = "any"; const char *local = "any";
const char *remote = "any"; const char *remote = "any";
...@@ -210,7 +209,7 @@ static void vti_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) ...@@ -210,7 +209,7 @@ static void vti_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
unsigned int addr = *(__u32 *)RTA_DATA(tb[IFLA_VTI_REMOTE]); unsigned int addr = *(__u32 *)RTA_DATA(tb[IFLA_VTI_REMOTE]);
if (addr) if (addr)
remote = format_host(AF_INET, 4, &addr, s1, sizeof(s1)); remote = format_host(AF_INET, 4, &addr);
} }
fprintf(f, "remote %s ", remote); fprintf(f, "remote %s ", remote);
...@@ -219,7 +218,7 @@ static void vti_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) ...@@ -219,7 +218,7 @@ static void vti_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
unsigned int addr = *(__u32 *)RTA_DATA(tb[IFLA_VTI_LOCAL]); unsigned int addr = *(__u32 *)RTA_DATA(tb[IFLA_VTI_LOCAL]);
if (addr) if (addr)
local = format_host(AF_INET, 4, &addr, s1, sizeof(s1)); local = format_host(AF_INET, 4, &addr);
} }
fprintf(f, "local %s ", local); fprintf(f, "local %s ", local);
......
...@@ -197,7 +197,6 @@ get_failed: ...@@ -197,7 +197,6 @@ get_failed:
static void vti6_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) static void vti6_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
{ {
char s1[1024];
char s2[64]; char s2[64];
const char *local = "any"; const char *local = "any";
const char *remote = "any"; const char *remote = "any";
...@@ -210,7 +209,7 @@ static void vti6_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) ...@@ -210,7 +209,7 @@ static void vti6_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
if (tb[IFLA_VTI_REMOTE]) { if (tb[IFLA_VTI_REMOTE]) {
memcpy(&daddr, RTA_DATA(tb[IFLA_VTI_REMOTE]), sizeof(daddr)); memcpy(&daddr, RTA_DATA(tb[IFLA_VTI_REMOTE]), sizeof(daddr));
remote = format_host(AF_INET6, 16, &daddr, s1, sizeof(s1)); remote = format_host(AF_INET6, 16, &daddr);
} }
fprintf(f, "remote %s ", remote); fprintf(f, "remote %s ", remote);
...@@ -218,7 +217,7 @@ static void vti6_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) ...@@ -218,7 +217,7 @@ static void vti6_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
if (tb[IFLA_VTI_LOCAL]) { if (tb[IFLA_VTI_LOCAL]) {
memcpy(&saddr, RTA_DATA(tb[IFLA_VTI_LOCAL]), sizeof(saddr)); memcpy(&saddr, RTA_DATA(tb[IFLA_VTI_LOCAL]), sizeof(saddr));
local = format_host(AF_INET6, 16, &saddr, s1, sizeof(s1)); local = format_host(AF_INET6, 16, &saddr);
} }
fprintf(f, "local %s ", local); fprintf(f, "local %s ", local);
......
...@@ -95,7 +95,6 @@ static int process_msg(const struct sockaddr_nl *who, struct nlmsghdr *n, ...@@ -95,7 +95,6 @@ static int process_msg(const struct sockaddr_nl *who, struct nlmsghdr *n,
struct genlmsghdr *ghdr; struct genlmsghdr *ghdr;
struct rtattr *attrs[TCP_METRICS_ATTR_MAX + 1], *a; struct rtattr *attrs[TCP_METRICS_ATTR_MAX + 1], *a;
int len = n->nlmsg_len; int len = n->nlmsg_len;
char abuf[256];
inet_prefix daddr, saddr; inet_prefix daddr, saddr;
int family, i, atype, stype, dlen = 0, slen = 0; int family, i, atype, stype, dlen = 0, slen = 0;
...@@ -194,7 +193,7 @@ static int process_msg(const struct sockaddr_nl *who, struct nlmsghdr *n, ...@@ -194,7 +193,7 @@ static int process_msg(const struct sockaddr_nl *who, struct nlmsghdr *n,
fprintf(fp, "Deleted "); fprintf(fp, "Deleted ");
fprintf(fp, "%s", fprintf(fp, "%s",
format_host(family, dlen, &daddr.data, abuf, sizeof(abuf))); format_host(family, dlen, &daddr.data));
a = attrs[TCP_METRICS_ATTR_AGE]; a = attrs[TCP_METRICS_ATTR_AGE];
if (a) { if (a) {
...@@ -298,8 +297,7 @@ static int process_msg(const struct sockaddr_nl *who, struct nlmsghdr *n, ...@@ -298,8 +297,7 @@ static int process_msg(const struct sockaddr_nl *who, struct nlmsghdr *n,
if (slen) { if (slen) {
fprintf(fp, " source %s", fprintf(fp, " source %s",
format_host(family, slen, &saddr.data, abuf, format_host(family, slen, &saddr.data));
sizeof(abuf)));
} }
fprintf(fp, "\n"); fprintf(fp, "\n");
......
...@@ -818,7 +818,7 @@ static const char *resolve_address(const void *addr, int len, int af) ...@@ -818,7 +818,7 @@ static const char *resolve_address(const void *addr, int len, int af)
} }
#endif #endif
const char *format_host(int af, int len, const void *addr, const char *format_host_r(int af, int len, const void *addr,
char *buf, int buflen) char *buf, int buflen)
{ {
#ifdef RESOLVE_HOSTNAMES #ifdef RESOLVE_HOSTNAMES
...@@ -835,6 +835,13 @@ const char *format_host(int af, int len, const void *addr, ...@@ -835,6 +835,13 @@ const char *format_host(int af, int len, const void *addr,
return rt_addr_n2a(af, len, addr, buf, buflen); return rt_addr_n2a(af, len, addr, buf, buflen);
} }
const char *format_host(int af, int len, const void *addr)
{
static char buf[256];
return format_host_r(af, len, addr, buf, 256);
}
char *hexstring_n2a(const __u8 *str, int len, char *buf, int blen) char *hexstring_n2a(const __u8 *str, int len, char *buf, int blen)
{ {
......
...@@ -1016,10 +1016,10 @@ static void inet_addr_print(const inet_prefix *a, int port, unsigned int ifindex ...@@ -1016,10 +1016,10 @@ static void inet_addr_print(const inet_prefix *a, int port, unsigned int ifindex
buf[0] = '*'; buf[0] = '*';
buf[1] = 0; buf[1] = 0;
} else { } else {
ap = format_host(AF_INET, 4, a->data, buf, sizeof(buf)); ap = format_host(AF_INET, 4, a->data);
} }
} else { } else {
ap = format_host(a->family, 16, a->data, buf, sizeof(buf)); ap = format_host(a->family, 16, a->data);
est_len = strlen(ap); est_len = strlen(ap);
if (est_len <= addr_width) if (est_len <= addr_width)
est_len = addr_width; est_len = addr_width;
......
...@@ -191,9 +191,9 @@ print_nat(struct action_util *au, FILE * f, struct rtattr *arg) ...@@ -191,9 +191,9 @@ print_nat(struct action_util *au, FILE * f, struct rtattr *arg)
fprintf(f, " nat %s %s/%d %s %s", sel->flags & TCA_NAT_FLAG_EGRESS ? fprintf(f, " nat %s %s/%d %s %s", sel->flags & TCA_NAT_FLAG_EGRESS ?
"egress" : "ingress", "egress" : "ingress",
format_host(AF_INET, 4, &sel->old_addr, buf1, sizeof(buf1)), format_host_r(AF_INET, 4, &sel->old_addr, buf1, sizeof(buf1)),
len, len,
format_host(AF_INET, 4, &sel->new_addr, buf2, sizeof(buf2)), format_host_r(AF_INET, 4, &sel->new_addr, buf2, sizeof(buf2)),
action_n2a(sel->action, buf3, sizeof(buf3))); action_n2a(sel->action, buf3, sizeof(buf3)));
if (show_stats) { if (show_stats) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment