mirror of
https://git.proxmox.com/git/mirror_iproute2
synced 2025-12-09 17:25:48 +00:00
utils: make rt_addr_n2a() non-reentrant by default
There is only a single user who needs it to be reentrant (not really, but it's safer like this), add rt_addr_n2a_r() for it to use. Signed-off-by: Phil Sutter <phil@nwl.cc>
This commit is contained in:
parent
a418e45164
commit
2e96d2ccd0
@ -125,8 +125,9 @@ int af_byte_len(int af);
|
|||||||
const char *format_host_r(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 *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_r(int af, int len, const void *addr,
|
||||||
char *buf, int buflen);
|
char *buf, int buflen);
|
||||||
|
const char *rt_addr_n2a(int af, int len, const void *addr);
|
||||||
|
|
||||||
int read_family(const char *name);
|
int read_family(const char *name);
|
||||||
const char *family_name(int family);
|
const char *family_name(int family);
|
||||||
|
|||||||
@ -78,7 +78,7 @@ static void print_tunnel(struct ip6_tnl_parm2 *p)
|
|||||||
p->name,
|
p->name,
|
||||||
tnl_strproto(p->proto),
|
tnl_strproto(p->proto),
|
||||||
format_host_r(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_r(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);
|
||||||
|
|
||||||
|
|||||||
@ -411,7 +411,6 @@ static void bond_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
|
|||||||
|
|
||||||
if (tb[IFLA_BOND_ARP_IP_TARGET]) {
|
if (tb[IFLA_BOND_ARP_IP_TARGET]) {
|
||||||
struct rtattr *iptb[BOND_MAX_ARP_TARGETS + 1];
|
struct rtattr *iptb[BOND_MAX_ARP_TARGETS + 1];
|
||||||
char buf[INET_ADDRSTRLEN];
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
parse_rtattr_nested(iptb, BOND_MAX_ARP_TARGETS,
|
parse_rtattr_nested(iptb, BOND_MAX_ARP_TARGETS,
|
||||||
@ -425,9 +424,7 @@ static void bond_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
|
|||||||
fprintf(f, "%s",
|
fprintf(f, "%s",
|
||||||
rt_addr_n2a(AF_INET,
|
rt_addr_n2a(AF_INET,
|
||||||
RTA_PAYLOAD(iptb[i]),
|
RTA_PAYLOAD(iptb[i]),
|
||||||
RTA_DATA(iptb[i]),
|
RTA_DATA(iptb[i])));
|
||||||
buf,
|
|
||||||
INET_ADDRSTRLEN));
|
|
||||||
if (i < BOND_MAX_ARP_TARGETS-1 && iptb[i+1])
|
if (i < BOND_MAX_ARP_TARGETS-1 && iptb[i+1])
|
||||||
fprintf(f, ",");
|
fprintf(f, ",");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -58,7 +58,6 @@ int print_mroute(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
|
|||||||
struct rtmsg *r = NLMSG_DATA(n);
|
struct rtmsg *r = NLMSG_DATA(n);
|
||||||
int len = n->nlmsg_len;
|
int len = n->nlmsg_len;
|
||||||
struct rtattr *tb[RTA_MAX+1];
|
struct rtattr *tb[RTA_MAX+1];
|
||||||
char abuf[256];
|
|
||||||
char obuf[256];
|
char obuf[256];
|
||||||
|
|
||||||
SPRINT_BUF(b1);
|
SPRINT_BUF(b1);
|
||||||
@ -126,16 +125,14 @@ int print_mroute(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
|
|||||||
len = snprintf(obuf, sizeof(obuf),
|
len = snprintf(obuf, sizeof(obuf),
|
||||||
"(%s, ", rt_addr_n2a(family,
|
"(%s, ", rt_addr_n2a(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
|
else
|
||||||
len = sprintf(obuf, "(unknown, ");
|
len = sprintf(obuf, "(unknown, ");
|
||||||
if (tb[RTA_DST])
|
if (tb[RTA_DST])
|
||||||
snprintf(obuf + len, sizeof(obuf) - len,
|
snprintf(obuf + len, sizeof(obuf) - len,
|
||||||
"%s)", rt_addr_n2a(family,
|
"%s)", rt_addr_n2a(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
|
else
|
||||||
snprintf(obuf + len, sizeof(obuf) - len, "unknown) ");
|
snprintf(obuf + len, sizeof(obuf) - len, "unknown) ");
|
||||||
|
|
||||||
|
|||||||
@ -75,15 +75,12 @@ int print_prefix(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
|
|||||||
|
|
||||||
if (tb[PREFIX_ADDRESS]) {
|
if (tb[PREFIX_ADDRESS]) {
|
||||||
struct in6_addr *pfx;
|
struct in6_addr *pfx;
|
||||||
char abuf[256];
|
|
||||||
|
|
||||||
pfx = (struct in6_addr *)RTA_DATA(tb[PREFIX_ADDRESS]);
|
pfx = (struct in6_addr *)RTA_DATA(tb[PREFIX_ADDRESS]);
|
||||||
|
|
||||||
memset(abuf, '\0', sizeof(abuf));
|
|
||||||
fprintf(fp, "%s", rt_addr_n2a(family,
|
fprintf(fp, "%s", rt_addr_n2a(family,
|
||||||
RTA_PAYLOAD(tb[PREFIX_ADDRESS]),
|
RTA_PAYLOAD(tb[PREFIX_ADDRESS]),
|
||||||
pfx,
|
pfx));
|
||||||
abuf, sizeof(abuf)));
|
|
||||||
}
|
}
|
||||||
fprintf(fp, "/%u ", prefix->prefix_len);
|
fprintf(fp, "/%u ", prefix->prefix_len);
|
||||||
|
|
||||||
|
|||||||
10
ip/iproute.c
10
ip/iproute.c
@ -318,7 +318,6 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
|
|||||||
struct rtmsg *r = NLMSG_DATA(n);
|
struct rtmsg *r = NLMSG_DATA(n);
|
||||||
int len = n->nlmsg_len;
|
int len = n->nlmsg_len;
|
||||||
struct rtattr *tb[RTA_MAX+1];
|
struct rtattr *tb[RTA_MAX+1];
|
||||||
char abuf[256];
|
|
||||||
int host_len;
|
int host_len;
|
||||||
__u32 table;
|
__u32 table;
|
||||||
|
|
||||||
@ -373,8 +372,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
|
|||||||
if (r->rtm_dst_len != host_len) {
|
if (r->rtm_dst_len != host_len) {
|
||||||
fprintf(fp, "%s/%u ", rt_addr_n2a(r->rtm_family,
|
fprintf(fp, "%s/%u ", rt_addr_n2a(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)),
|
|
||||||
r->rtm_dst_len
|
r->rtm_dst_len
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
@ -392,8 +390,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
|
|||||||
if (r->rtm_src_len != host_len) {
|
if (r->rtm_src_len != host_len) {
|
||||||
fprintf(fp, "from %s/%u ", rt_addr_n2a(r->rtm_family,
|
fprintf(fp, "from %s/%u ", rt_addr_n2a(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)),
|
|
||||||
r->rtm_src_len
|
r->rtm_src_len
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
@ -452,8 +449,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
|
|||||||
fprintf(fp, " src %s ",
|
fprintf(fp, " src %s ",
|
||||||
rt_addr_n2a(r->rtm_family,
|
rt_addr_n2a(r->rtm_family,
|
||||||
RTA_PAYLOAD(tb[RTA_PREFSRC]),
|
RTA_PAYLOAD(tb[RTA_PREFSRC]),
|
||||||
RTA_DATA(tb[RTA_PREFSRC]),
|
RTA_DATA(tb[RTA_PREFSRC])));
|
||||||
abuf, sizeof(abuf)));
|
|
||||||
}
|
}
|
||||||
if (tb[RTA_PRIORITY])
|
if (tb[RTA_PRIORITY])
|
||||||
fprintf(fp, " metric %u ", rta_getattr_u32(tb[RTA_PRIORITY]));
|
fprintf(fp, " metric %u ", rta_getattr_u32(tb[RTA_PRIORITY]));
|
||||||
|
|||||||
@ -70,7 +70,6 @@ static void print_encap_mpls(FILE *fp, struct rtattr *encap)
|
|||||||
static void print_encap_ip(FILE *fp, struct rtattr *encap)
|
static void print_encap_ip(FILE *fp, struct rtattr *encap)
|
||||||
{
|
{
|
||||||
struct rtattr *tb[LWTUNNEL_IP_MAX+1];
|
struct rtattr *tb[LWTUNNEL_IP_MAX+1];
|
||||||
char abuf[256];
|
|
||||||
|
|
||||||
parse_rtattr_nested(tb, LWTUNNEL_IP_MAX, encap);
|
parse_rtattr_nested(tb, LWTUNNEL_IP_MAX, encap);
|
||||||
|
|
||||||
@ -81,15 +80,13 @@ static void print_encap_ip(FILE *fp, struct rtattr *encap)
|
|||||||
fprintf(fp, "src %s ",
|
fprintf(fp, "src %s ",
|
||||||
rt_addr_n2a(AF_INET,
|
rt_addr_n2a(AF_INET,
|
||||||
RTA_PAYLOAD(tb[LWTUNNEL_IP_SRC]),
|
RTA_PAYLOAD(tb[LWTUNNEL_IP_SRC]),
|
||||||
RTA_DATA(tb[LWTUNNEL_IP_SRC]),
|
RTA_DATA(tb[LWTUNNEL_IP_SRC])));
|
||||||
abuf, sizeof(abuf)));
|
|
||||||
|
|
||||||
if (tb[LWTUNNEL_IP_DST])
|
if (tb[LWTUNNEL_IP_DST])
|
||||||
fprintf(fp, "dst %s ",
|
fprintf(fp, "dst %s ",
|
||||||
rt_addr_n2a(AF_INET,
|
rt_addr_n2a(AF_INET,
|
||||||
RTA_PAYLOAD(tb[LWTUNNEL_IP_DST]),
|
RTA_PAYLOAD(tb[LWTUNNEL_IP_DST]),
|
||||||
RTA_DATA(tb[LWTUNNEL_IP_DST]),
|
RTA_DATA(tb[LWTUNNEL_IP_DST])));
|
||||||
abuf, sizeof(abuf)));
|
|
||||||
|
|
||||||
if (tb[LWTUNNEL_IP_TTL])
|
if (tb[LWTUNNEL_IP_TTL])
|
||||||
fprintf(fp, "ttl %d ", rta_getattr_u8(tb[LWTUNNEL_IP_TTL]));
|
fprintf(fp, "ttl %d ", rta_getattr_u8(tb[LWTUNNEL_IP_TTL]));
|
||||||
|
|||||||
@ -57,8 +57,6 @@ int print_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
|
|||||||
int host_len = -1;
|
int host_len = -1;
|
||||||
__u32 table;
|
__u32 table;
|
||||||
struct rtattr *tb[FRA_MAX+1];
|
struct rtattr *tb[FRA_MAX+1];
|
||||||
char abuf[256];
|
|
||||||
|
|
||||||
SPRINT_BUF(b1);
|
SPRINT_BUF(b1);
|
||||||
|
|
||||||
if (n->nlmsg_type != RTM_NEWRULE && n->nlmsg_type != RTM_DELRULE)
|
if (n->nlmsg_type != RTM_NEWRULE && n->nlmsg_type != RTM_DELRULE)
|
||||||
@ -87,8 +85,7 @@ int print_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
|
|||||||
if (r->rtm_src_len != host_len) {
|
if (r->rtm_src_len != host_len) {
|
||||||
fprintf(fp, "from %s/%u ", rt_addr_n2a(r->rtm_family,
|
fprintf(fp, "from %s/%u ", rt_addr_n2a(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)),
|
|
||||||
r->rtm_src_len
|
r->rtm_src_len
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
@ -107,8 +104,7 @@ int print_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
|
|||||||
if (r->rtm_dst_len != host_len) {
|
if (r->rtm_dst_len != host_len) {
|
||||||
fprintf(fp, "to %s/%u ", rt_addr_n2a(r->rtm_family,
|
fprintf(fp, "to %s/%u ", rt_addr_n2a(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)),
|
|
||||||
r->rtm_dst_len
|
r->rtm_dst_len
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -309,7 +309,7 @@ static void print_tunnel(struct ip_tunnel_parm *p)
|
|||||||
p->name,
|
p->name,
|
||||||
tnl_strproto(p->iph.protocol),
|
tnl_strproto(p->iph.protocol),
|
||||||
p->iph.daddr ? format_host_r(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_r(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)) {
|
||||||
struct ip_tunnel_prl prl[16];
|
struct ip_tunnel_prl prl[16];
|
||||||
|
|||||||
29
ip/ipxfrm.c
29
ip/ipxfrm.c
@ -285,17 +285,11 @@ void xfrm_id_info_print(xfrm_address_t *saddr, struct xfrm_id *id,
|
|||||||
__u8 mode, __u32 reqid, __u16 family, int force_spi,
|
__u8 mode, __u32 reqid, __u16 family, int force_spi,
|
||||||
FILE *fp, const char *prefix, const char *title)
|
FILE *fp, const char *prefix, const char *title)
|
||||||
{
|
{
|
||||||
char abuf[256];
|
|
||||||
|
|
||||||
if (title)
|
if (title)
|
||||||
fputs(title, fp);
|
fputs(title, fp);
|
||||||
|
|
||||||
memset(abuf, '\0', sizeof(abuf));
|
fprintf(fp, "src %s ", rt_addr_n2a(family, sizeof(*saddr), saddr));
|
||||||
fprintf(fp, "src %s ", rt_addr_n2a(family, sizeof(*saddr),
|
fprintf(fp, "dst %s", rt_addr_n2a(family, sizeof(id->daddr), &id->daddr));
|
||||||
saddr, abuf, sizeof(abuf)));
|
|
||||||
memset(abuf, '\0', sizeof(abuf));
|
|
||||||
fprintf(fp, "dst %s", rt_addr_n2a(family, sizeof(id->daddr),
|
|
||||||
&id->daddr, abuf, sizeof(abuf)));
|
|
||||||
fprintf(fp, "%s", _SL_);
|
fprintf(fp, "%s", _SL_);
|
||||||
|
|
||||||
if (prefix)
|
if (prefix)
|
||||||
@ -447,7 +441,6 @@ void xfrm_lifetime_print(struct xfrm_lifetime_cfg *cfg,
|
|||||||
void xfrm_selector_print(struct xfrm_selector *sel, __u16 family,
|
void xfrm_selector_print(struct xfrm_selector *sel, __u16 family,
|
||||||
FILE *fp, const char *prefix)
|
FILE *fp, const char *prefix)
|
||||||
{
|
{
|
||||||
char abuf[256];
|
|
||||||
__u16 f;
|
__u16 f;
|
||||||
|
|
||||||
f = sel->family;
|
f = sel->family;
|
||||||
@ -459,16 +452,12 @@ void xfrm_selector_print(struct xfrm_selector *sel, __u16 family,
|
|||||||
if (prefix)
|
if (prefix)
|
||||||
fputs(prefix, fp);
|
fputs(prefix, fp);
|
||||||
|
|
||||||
memset(abuf, '\0', sizeof(abuf));
|
|
||||||
fprintf(fp, "src %s/%u ",
|
fprintf(fp, "src %s/%u ",
|
||||||
rt_addr_n2a(f, sizeof(sel->saddr), &sel->saddr,
|
rt_addr_n2a(f, sizeof(sel->saddr), &sel->saddr),
|
||||||
abuf, sizeof(abuf)),
|
|
||||||
sel->prefixlen_s);
|
sel->prefixlen_s);
|
||||||
|
|
||||||
memset(abuf, '\0', sizeof(abuf));
|
|
||||||
fprintf(fp, "dst %s/%u ",
|
fprintf(fp, "dst %s/%u ",
|
||||||
rt_addr_n2a(f, sizeof(sel->daddr), &sel->daddr,
|
rt_addr_n2a(f, sizeof(sel->daddr), &sel->daddr),
|
||||||
abuf, sizeof(abuf)),
|
|
||||||
sel->prefixlen_d);
|
sel->prefixlen_d);
|
||||||
|
|
||||||
if (sel->proto)
|
if (sel->proto)
|
||||||
@ -740,7 +729,6 @@ void xfrm_xfrma_print(struct rtattr *tb[], __u16 family,
|
|||||||
|
|
||||||
if (tb[XFRMA_ENCAP]) {
|
if (tb[XFRMA_ENCAP]) {
|
||||||
struct xfrm_encap_tmpl *e;
|
struct xfrm_encap_tmpl *e;
|
||||||
char abuf[256];
|
|
||||||
|
|
||||||
if (prefix)
|
if (prefix)
|
||||||
fputs(prefix, fp);
|
fputs(prefix, fp);
|
||||||
@ -768,10 +756,8 @@ void xfrm_xfrma_print(struct rtattr *tb[], __u16 family,
|
|||||||
fprintf(fp, "sport %u ", ntohs(e->encap_sport));
|
fprintf(fp, "sport %u ", ntohs(e->encap_sport));
|
||||||
fprintf(fp, "dport %u ", ntohs(e->encap_dport));
|
fprintf(fp, "dport %u ", ntohs(e->encap_dport));
|
||||||
|
|
||||||
memset(abuf, '\0', sizeof(abuf));
|
|
||||||
fprintf(fp, "addr %s",
|
fprintf(fp, "addr %s",
|
||||||
rt_addr_n2a(family, sizeof(e->encap_oa), &e->encap_oa,
|
rt_addr_n2a(family, sizeof(e->encap_oa), &e->encap_oa));
|
||||||
abuf, sizeof(abuf)));
|
|
||||||
fprintf(fp, "%s", _SL_);
|
fprintf(fp, "%s", _SL_);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -783,7 +769,6 @@ void xfrm_xfrma_print(struct rtattr *tb[], __u16 family,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (tb[XFRMA_COADDR]) {
|
if (tb[XFRMA_COADDR]) {
|
||||||
char abuf[256];
|
|
||||||
xfrm_address_t *coa;
|
xfrm_address_t *coa;
|
||||||
|
|
||||||
if (prefix)
|
if (prefix)
|
||||||
@ -798,10 +783,8 @@ void xfrm_xfrma_print(struct rtattr *tb[], __u16 family,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(abuf, '\0', sizeof(abuf));
|
|
||||||
fprintf(fp, "%s",
|
fprintf(fp, "%s",
|
||||||
rt_addr_n2a(family, sizeof(*coa), coa,
|
rt_addr_n2a(family, sizeof(*coa), coa));
|
||||||
abuf, sizeof(abuf)));
|
|
||||||
fprintf(fp, "%s", _SL_);
|
fprintf(fp, "%s", _SL_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -260,7 +260,6 @@ get_failed:
|
|||||||
|
|
||||||
static void ip6tunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
|
static void ip6tunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
|
||||||
{
|
{
|
||||||
char s1[256];
|
|
||||||
char s2[64];
|
char s2[64];
|
||||||
int flags = 0;
|
int flags = 0;
|
||||||
__u32 flowinfo = 0;
|
__u32 flowinfo = 0;
|
||||||
@ -292,16 +291,14 @@ static void ip6tunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb
|
|||||||
fprintf(f, "remote %s ",
|
fprintf(f, "remote %s ",
|
||||||
rt_addr_n2a(AF_INET6,
|
rt_addr_n2a(AF_INET6,
|
||||||
RTA_PAYLOAD(tb[IFLA_IPTUN_REMOTE]),
|
RTA_PAYLOAD(tb[IFLA_IPTUN_REMOTE]),
|
||||||
RTA_DATA(tb[IFLA_IPTUN_REMOTE]),
|
RTA_DATA(tb[IFLA_IPTUN_REMOTE])));
|
||||||
s1, sizeof(s1)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tb[IFLA_IPTUN_LOCAL]) {
|
if (tb[IFLA_IPTUN_LOCAL]) {
|
||||||
fprintf(f, "local %s ",
|
fprintf(f, "local %s ",
|
||||||
rt_addr_n2a(AF_INET6,
|
rt_addr_n2a(AF_INET6,
|
||||||
RTA_PAYLOAD(tb[IFLA_IPTUN_LOCAL]),
|
RTA_PAYLOAD(tb[IFLA_IPTUN_LOCAL]),
|
||||||
RTA_DATA(tb[IFLA_IPTUN_LOCAL]),
|
RTA_DATA(tb[IFLA_IPTUN_LOCAL])));
|
||||||
s1, sizeof(s1)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tb[IFLA_IPTUN_LINK] && rta_getattr_u32(tb[IFLA_IPTUN_LINK])) {
|
if (tb[IFLA_IPTUN_LINK] && rta_getattr_u32(tb[IFLA_IPTUN_LINK])) {
|
||||||
|
|||||||
@ -227,12 +227,8 @@ static void xfrm_ae_flags_print(__u32 flags, void *arg)
|
|||||||
|
|
||||||
static void xfrm_usersa_print(const struct xfrm_usersa_id *sa_id, __u32 reqid, FILE *fp)
|
static void xfrm_usersa_print(const struct xfrm_usersa_id *sa_id, __u32 reqid, FILE *fp)
|
||||||
{
|
{
|
||||||
char buf[256];
|
|
||||||
|
|
||||||
buf[0] = 0;
|
|
||||||
fprintf(fp, "dst %s ",
|
fprintf(fp, "dst %s ",
|
||||||
rt_addr_n2a(sa_id->family, sizeof(sa_id->daddr), &sa_id->daddr,
|
rt_addr_n2a(sa_id->family, sizeof(sa_id->daddr), &sa_id->daddr));
|
||||||
buf, sizeof(buf)));
|
|
||||||
|
|
||||||
fprintf(fp, " reqid 0x%x", reqid);
|
fprintf(fp, " reqid 0x%x", reqid);
|
||||||
|
|
||||||
@ -245,15 +241,12 @@ static int xfrm_ae_print(const struct sockaddr_nl *who,
|
|||||||
{
|
{
|
||||||
FILE *fp = (FILE *)arg;
|
FILE *fp = (FILE *)arg;
|
||||||
struct xfrm_aevent_id *id = NLMSG_DATA(n);
|
struct xfrm_aevent_id *id = NLMSG_DATA(n);
|
||||||
char abuf[256];
|
|
||||||
|
|
||||||
fprintf(fp, "Async event ");
|
fprintf(fp, "Async event ");
|
||||||
xfrm_ae_flags_print(id->flags, arg);
|
xfrm_ae_flags_print(id->flags, arg);
|
||||||
fprintf(fp, "\n\t");
|
fprintf(fp, "\n\t");
|
||||||
memset(abuf, '\0', sizeof(abuf));
|
|
||||||
fprintf(fp, "src %s ", rt_addr_n2a(id->sa_id.family,
|
fprintf(fp, "src %s ", rt_addr_n2a(id->sa_id.family,
|
||||||
sizeof(id->saddr), &id->saddr,
|
sizeof(id->saddr), &id->saddr));
|
||||||
abuf, sizeof(abuf)));
|
|
||||||
|
|
||||||
xfrm_usersa_print(&id->sa_id, id->reqid, fp);
|
xfrm_usersa_print(&id->sa_id, id->reqid, fp);
|
||||||
|
|
||||||
@ -265,10 +258,7 @@ static int xfrm_ae_print(const struct sockaddr_nl *who,
|
|||||||
|
|
||||||
static void xfrm_print_addr(FILE *fp, int family, xfrm_address_t *a)
|
static void xfrm_print_addr(FILE *fp, int family, xfrm_address_t *a)
|
||||||
{
|
{
|
||||||
char buf[256];
|
fprintf(fp, "%s", rt_addr_n2a(family, sizeof(*a), a));
|
||||||
|
|
||||||
buf[0] = 0;
|
|
||||||
fprintf(fp, "%s", rt_addr_n2a(family, sizeof(*a), a, buf, sizeof(buf)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int xfrm_mapping_print(const struct sockaddr_nl *who,
|
static int xfrm_mapping_print(const struct sockaddr_nl *who,
|
||||||
|
|||||||
11
lib/utils.c
11
lib/utils.c
@ -702,7 +702,7 @@ int __get_user_hz(void)
|
|||||||
return sysconf(_SC_CLK_TCK);
|
return sysconf(_SC_CLK_TCK);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *rt_addr_n2a(int af, int len, const void *addr, char *buf, int buflen)
|
const char *rt_addr_n2a_r(int af, int len, const void *addr, char *buf, int buflen)
|
||||||
{
|
{
|
||||||
switch (af) {
|
switch (af) {
|
||||||
case AF_INET:
|
case AF_INET:
|
||||||
@ -725,6 +725,13 @@ const char *rt_addr_n2a(int af, int len, const void *addr, char *buf, int buflen
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *rt_addr_n2a(int af, int len, const void *addr)
|
||||||
|
{
|
||||||
|
static char buf[256];
|
||||||
|
|
||||||
|
return rt_addr_n2a_r(af, len, addr, buf, 256);
|
||||||
|
}
|
||||||
|
|
||||||
int read_family(const char *name)
|
int read_family(const char *name)
|
||||||
{
|
{
|
||||||
int family = AF_UNSPEC;
|
int family = AF_UNSPEC;
|
||||||
@ -832,7 +839,7 @@ const char *format_host_r(int af, int len, const void *addr,
|
|||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return rt_addr_n2a(af, len, addr, buf, buflen);
|
return rt_addr_n2a_r(af, len, addr, buf, buflen);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *format_host(int af, int len, const void *addr)
|
const char *format_host(int af, int len, const void *addr)
|
||||||
|
|||||||
@ -394,7 +394,6 @@ static void flower_print_ip_addr(FILE *f, char *name, __be16 eth_type,
|
|||||||
struct rtattr *addr6_attr,
|
struct rtattr *addr6_attr,
|
||||||
struct rtattr *mask6_attr)
|
struct rtattr *mask6_attr)
|
||||||
{
|
{
|
||||||
SPRINT_BUF(b1);
|
|
||||||
struct rtattr *addr_attr;
|
struct rtattr *addr_attr;
|
||||||
struct rtattr *mask_attr;
|
struct rtattr *mask_attr;
|
||||||
int family;
|
int family;
|
||||||
@ -418,16 +417,14 @@ static void flower_print_ip_addr(FILE *f, char *name, __be16 eth_type,
|
|||||||
return;
|
return;
|
||||||
fprintf(f, "\n %s %s", name, rt_addr_n2a(family,
|
fprintf(f, "\n %s %s", name, rt_addr_n2a(family,
|
||||||
RTA_PAYLOAD(addr_attr),
|
RTA_PAYLOAD(addr_attr),
|
||||||
RTA_DATA(addr_attr),
|
RTA_DATA(addr_attr)));
|
||||||
b1, sizeof(b1)));
|
|
||||||
if (!mask_attr || RTA_PAYLOAD(mask_attr) != len)
|
if (!mask_attr || RTA_PAYLOAD(mask_attr) != len)
|
||||||
return;
|
return;
|
||||||
bits = __mask_bits(RTA_DATA(mask_attr), len);
|
bits = __mask_bits(RTA_DATA(mask_attr), len);
|
||||||
if (bits < 0)
|
if (bits < 0)
|
||||||
fprintf(f, "/%s", rt_addr_n2a(family,
|
fprintf(f, "/%s", rt_addr_n2a(family,
|
||||||
RTA_PAYLOAD(mask_attr),
|
RTA_PAYLOAD(mask_attr),
|
||||||
RTA_DATA(mask_attr),
|
RTA_DATA(mask_attr)));
|
||||||
b1, sizeof(b1)));
|
|
||||||
else if (bits < len * 8)
|
else if (bits < len * 8)
|
||||||
fprintf(f, "/%d", bits);
|
fprintf(f, "/%d", bits);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user