Commit 7faf1588 authored by Phil Sutter's avatar Phil Sutter Committed by Stephen Hemminger

lib/utils: introduce rt_addr_n2a_rta()

This simple macro eases calling rt_addr_n2a() with data from an rt_attr
pointer.
Signed-off-by: default avatarPhil Sutter <phil@nwl.cc>
parent d49f934c
......@@ -130,6 +130,8 @@ const char *format_host(int af, int lne, const void *addr);
const char *rt_addr_n2a_r(int af, int len, const void *addr,
char *buf, int buflen);
const char *rt_addr_n2a(int af, int len, const void *addr);
#define rt_addr_n2a_rta(af, rta) \
rt_addr_n2a(af, RTA_PAYLOAD(rta), RTA_DATA(rta))
int read_family(const char *name);
const char *family_name(int family);
......
......@@ -422,9 +422,7 @@ static void bond_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
for (i = 0; i < BOND_MAX_ARP_TARGETS; i++) {
if (iptb[i])
fprintf(f, "%s",
rt_addr_n2a(AF_INET,
RTA_PAYLOAD(iptb[i]),
RTA_DATA(iptb[i])));
rt_addr_n2a_rta(AF_INET, iptb[i]));
if (i < BOND_MAX_ARP_TARGETS-1 && iptb[i+1])
fprintf(f, ",");
}
......
......@@ -123,16 +123,12 @@ int print_mroute(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
if (tb[RTA_SRC])
len = snprintf(obuf, sizeof(obuf),
"(%s, ", rt_addr_n2a(family,
RTA_PAYLOAD(tb[RTA_SRC]),
RTA_DATA(tb[RTA_SRC])));
"(%s, ", rt_addr_n2a_rta(family, tb[RTA_SRC]));
else
len = sprintf(obuf, "(unknown, ");
if (tb[RTA_DST])
snprintf(obuf + len, sizeof(obuf) - len,
"%s)", rt_addr_n2a(family,
RTA_PAYLOAD(tb[RTA_DST]),
RTA_DATA(tb[RTA_DST])));
"%s)", rt_addr_n2a_rta(family, tb[RTA_DST]));
else
snprintf(obuf + len, sizeof(obuf) - len, "unknown) ");
......
......@@ -71,19 +71,11 @@ int print_prefix(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
parse_rtattr(tb, RTA_MAX, RTM_RTA(prefix), len);
fprintf(fp, "prefix ");
if (tb[PREFIX_ADDRESS]) {
struct in6_addr *pfx;
pfx = (struct in6_addr *)RTA_DATA(tb[PREFIX_ADDRESS]);
fprintf(fp, "%s", rt_addr_n2a(family,
RTA_PAYLOAD(tb[PREFIX_ADDRESS]),
pfx));
fprintf(fp, "prefix %s/%u",
rt_addr_n2a_rta(family, tb[PREFIX_ADDRESS]),
prefix->prefix_len);
}
fprintf(fp, "/%u ", prefix->prefix_len);
fprintf(fp, "dev %s ", ll_index_to_name(prefix->prefix_ifindex));
if (prefix->prefix_flags & IF_PREFIX_ONLINK)
......
......@@ -370,11 +370,9 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
if (tb[RTA_DST]) {
if (r->rtm_dst_len != host_len) {
fprintf(fp, "%s/%u ", rt_addr_n2a(r->rtm_family,
RTA_PAYLOAD(tb[RTA_DST]),
RTA_DATA(tb[RTA_DST])),
r->rtm_dst_len
);
fprintf(fp, "%s/%u ",
rt_addr_n2a_rta(r->rtm_family, tb[RTA_DST]),
r->rtm_dst_len);
} else {
fprintf(fp, "%s ",
format_host_rta(r->rtm_family, tb[RTA_DST]));
......@@ -386,11 +384,9 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
}
if (tb[RTA_SRC]) {
if (r->rtm_src_len != host_len) {
fprintf(fp, "from %s/%u ", rt_addr_n2a(r->rtm_family,
RTA_PAYLOAD(tb[RTA_SRC]),
RTA_DATA(tb[RTA_SRC])),
r->rtm_src_len
);
fprintf(fp, "from %s/%u ",
rt_addr_n2a_rta(r->rtm_family, tb[RTA_SRC]),
r->rtm_src_len);
} else {
fprintf(fp, "from %s ",
format_host_rta(r->rtm_family, tb[RTA_SRC]));
......@@ -439,9 +435,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
and symbolic name will not be useful.
*/
fprintf(fp, " src %s ",
rt_addr_n2a(r->rtm_family,
RTA_PAYLOAD(tb[RTA_PREFSRC]),
RTA_DATA(tb[RTA_PREFSRC])));
rt_addr_n2a_rta(r->rtm_family, tb[RTA_PREFSRC]));
}
if (tb[RTA_PRIORITY])
fprintf(fp, " metric %u ", rta_getattr_u32(tb[RTA_PRIORITY]));
......
......@@ -77,15 +77,11 @@ static void print_encap_ip(FILE *fp, struct rtattr *encap)
if (tb[LWTUNNEL_IP_SRC])
fprintf(fp, "src %s ",
rt_addr_n2a(AF_INET,
RTA_PAYLOAD(tb[LWTUNNEL_IP_SRC]),
RTA_DATA(tb[LWTUNNEL_IP_SRC])));
rt_addr_n2a_rta(AF_INET, tb[LWTUNNEL_IP_SRC]));
if (tb[LWTUNNEL_IP_DST])
fprintf(fp, "dst %s ",
rt_addr_n2a(AF_INET,
RTA_PAYLOAD(tb[LWTUNNEL_IP_DST]),
RTA_DATA(tb[LWTUNNEL_IP_DST])));
rt_addr_n2a_rta(AF_INET, tb[LWTUNNEL_IP_DST]));
if (tb[LWTUNNEL_IP_TTL])
fprintf(fp, "ttl %d ", rta_getattr_u8(tb[LWTUNNEL_IP_TTL]));
......@@ -112,7 +108,6 @@ static void print_encap_ila(FILE *fp, struct rtattr *encap)
static void print_encap_ip6(FILE *fp, struct rtattr *encap)
{
struct rtattr *tb[LWTUNNEL_IP6_MAX+1];
char abuf[256];
parse_rtattr_nested(tb, LWTUNNEL_IP6_MAX, encap);
......@@ -121,17 +116,11 @@ static void print_encap_ip6(FILE *fp, struct rtattr *encap)
if (tb[LWTUNNEL_IP6_SRC])
fprintf(fp, "src %s ",
rt_addr_n2a(AF_INET6,
RTA_PAYLOAD(tb[LWTUNNEL_IP6_SRC]),
RTA_DATA(tb[LWTUNNEL_IP6_SRC]),
abuf, sizeof(abuf)));
rt_addr_n2a_rta(AF_INET6, tb[LWTUNNEL_IP6_SRC]));
if (tb[LWTUNNEL_IP6_DST])
fprintf(fp, "dst %s ",
rt_addr_n2a(AF_INET6,
RTA_PAYLOAD(tb[LWTUNNEL_IP6_DST]),
RTA_DATA(tb[LWTUNNEL_IP6_DST]),
abuf, sizeof(abuf)));
rt_addr_n2a_rta(AF_INET6, tb[LWTUNNEL_IP6_DST]));
if (tb[LWTUNNEL_IP6_HOPLIMIT])
fprintf(fp, "hoplimit %d ", rta_getattr_u8(tb[LWTUNNEL_IP6_HOPLIMIT]));
......
......@@ -83,11 +83,9 @@ int print_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
if (tb[FRA_SRC]) {
if (r->rtm_src_len != host_len) {
fprintf(fp, "from %s/%u ", rt_addr_n2a(r->rtm_family,
RTA_PAYLOAD(tb[FRA_SRC]),
RTA_DATA(tb[FRA_SRC])),
r->rtm_src_len
);
fprintf(fp, "from %s/%u ",
rt_addr_n2a_rta(r->rtm_family, tb[FRA_SRC]),
r->rtm_src_len);
} else {
fprintf(fp, "from %s ",
format_host_rta(r->rtm_family, tb[FRA_SRC]));
......@@ -100,11 +98,9 @@ int print_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
if (tb[FRA_DST]) {
if (r->rtm_dst_len != host_len) {
fprintf(fp, "to %s/%u ", rt_addr_n2a(r->rtm_family,
RTA_PAYLOAD(tb[FRA_DST]),
RTA_DATA(tb[FRA_DST])),
r->rtm_dst_len
);
fprintf(fp, "to %s/%u ",
rt_addr_n2a_rta(r->rtm_family, tb[FRA_DST]),
r->rtm_dst_len);
} else {
fprintf(fp, "to %s ",
format_host_rta(r->rtm_family, tb[FRA_DST]));
......
......@@ -289,16 +289,12 @@ static void ip6tunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb
if (tb[IFLA_IPTUN_REMOTE]) {
fprintf(f, "remote %s ",
rt_addr_n2a(AF_INET6,
RTA_PAYLOAD(tb[IFLA_IPTUN_REMOTE]),
RTA_DATA(tb[IFLA_IPTUN_REMOTE])));
rt_addr_n2a_rta(AF_INET6, tb[IFLA_IPTUN_REMOTE]));
}
if (tb[IFLA_IPTUN_LOCAL]) {
fprintf(f, "local %s ",
rt_addr_n2a(AF_INET6,
RTA_PAYLOAD(tb[IFLA_IPTUN_LOCAL]),
RTA_DATA(tb[IFLA_IPTUN_LOCAL])));
rt_addr_n2a_rta(AF_INET6, tb[IFLA_IPTUN_LOCAL]));
}
if (tb[IFLA_IPTUN_LINK] && rta_getattr_u32(tb[IFLA_IPTUN_LINK])) {
......
......@@ -415,16 +415,12 @@ static void flower_print_ip_addr(FILE *f, char *name, __be16 eth_type,
}
if (!addr_attr || RTA_PAYLOAD(addr_attr) != len)
return;
fprintf(f, "\n %s %s", name, rt_addr_n2a(family,
RTA_PAYLOAD(addr_attr),
RTA_DATA(addr_attr)));
fprintf(f, "\n %s %s", name, rt_addr_n2a_rta(family, addr_attr));
if (!mask_attr || RTA_PAYLOAD(mask_attr) != len)
return;
bits = __mask_bits(RTA_DATA(mask_attr), len);
if (bits < 0)
fprintf(f, "/%s", rt_addr_n2a(family,
RTA_PAYLOAD(mask_attr),
RTA_DATA(mask_attr)));
fprintf(f, "/%s", rt_addr_n2a_rta(family, mask_attr));
else if (bits < len * 8)
fprintf(f, "/%d", bits);
}
......
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