|
|
4aca6e |
From bf7031233e6db15ed6e76b0f7efcae8355ce4cd4 Mon Sep 17 00:00:00 2001
|
|
|
4aca6e |
From: Phil Sutter <psutter@redhat.com>
|
|
|
4aca6e |
Date: Fri, 17 Mar 2017 13:20:47 +0100
|
|
|
4aca6e |
Subject: [PATCH] lib/utils: introduce rt_addr_n2a_rta()
|
|
|
4aca6e |
|
|
|
4aca6e |
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1422629
|
|
|
4aca6e |
Upstream Status: iproute2.git commit 7faf1588a755e
|
|
|
4aca6e |
Conflicts: Context changed due to already backported commit
|
|
|
4aca6e |
7cc7cb8a888bf ("ip-route: Prevent some double spaces in
|
|
|
4aca6e |
output").
|
|
|
4aca6e |
* Drop iproute_lwtunnel hunks as we don't support it
|
|
|
4aca6e |
|
|
|
4aca6e |
commit 7faf1588a755edb9c9cabbe1d3211265e9826d28
|
|
|
4aca6e |
Author: Phil Sutter <phil@nwl.cc>
|
|
|
4aca6e |
Date: Tue Mar 22 19:35:18 2016 +0100
|
|
|
4aca6e |
|
|
|
4aca6e |
lib/utils: introduce rt_addr_n2a_rta()
|
|
|
4aca6e |
|
|
|
4aca6e |
This simple macro eases calling rt_addr_n2a() with data from an rt_attr
|
|
|
4aca6e |
pointer.
|
|
|
4aca6e |
|
|
|
4aca6e |
Signed-off-by: Phil Sutter <phil@nwl.cc>
|
|
|
4aca6e |
---
|
|
|
4aca6e |
include/utils.h | 2 ++
|
|
|
4aca6e |
ip/iplink_bond.c | 4 +---
|
|
|
4aca6e |
ip/ipmroute.c | 8 ++------
|
|
|
4aca6e |
ip/ipprefix.c | 14 +++-----------
|
|
|
4aca6e |
ip/iproute.c | 20 +++++++-------------
|
|
|
4aca6e |
ip/iprule.c | 16 ++++++----------
|
|
|
4aca6e |
ip/link_ip6tnl.c | 8 ++------
|
|
|
4aca6e |
tc/f_flower.c | 8 ++------
|
|
|
4aca6e |
9 files changed, 29 insertions(+), 70 deletions(-)
|
|
|
4aca6e |
|
|
|
4aca6e |
diff --git a/include/utils.h b/include/utils.h
|
|
|
4aca6e |
index 28684c5..53a631f 100644
|
|
|
4aca6e |
--- a/include/utils.h
|
|
|
4aca6e |
+++ b/include/utils.h
|
|
|
4aca6e |
@@ -115,6 +115,8 @@ const char *format_host(int af, int lne, const void *addr);
|
|
|
4aca6e |
const char *rt_addr_n2a_r(int af, int len, const void *addr,
|
|
|
4aca6e |
char *buf, int buflen);
|
|
|
4aca6e |
const char *rt_addr_n2a(int af, int len, const void *addr);
|
|
|
4aca6e |
+#define rt_addr_n2a_rta(af, rta) \
|
|
|
4aca6e |
+ rt_addr_n2a(af, RTA_PAYLOAD(rta), RTA_DATA(rta))
|
|
|
4aca6e |
|
|
|
4aca6e |
int read_family(const char *name);
|
|
|
4aca6e |
const char *family_name(int family);
|
|
|
4aca6e |
diff --git a/ip/iplink_bond.c b/ip/iplink_bond.c
|
|
|
4aca6e |
index 6881eda..d4e970d 100644
|
|
|
4aca6e |
--- a/ip/iplink_bond.c
|
|
|
4aca6e |
+++ b/ip/iplink_bond.c
|
|
|
4aca6e |
@@ -421,9 +421,7 @@ static void bond_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
|
|
|
4aca6e |
for (i = 0; i < BOND_MAX_ARP_TARGETS; i++) {
|
|
|
4aca6e |
if (iptb[i])
|
|
|
4aca6e |
fprintf(f, "%s",
|
|
|
4aca6e |
- rt_addr_n2a(AF_INET,
|
|
|
4aca6e |
- RTA_PAYLOAD(iptb[i]),
|
|
|
4aca6e |
- RTA_DATA(iptb[i])));
|
|
|
4aca6e |
+ rt_addr_n2a_rta(AF_INET, iptb[i]));
|
|
|
4aca6e |
if (i < BOND_MAX_ARP_TARGETS-1 && iptb[i+1])
|
|
|
4aca6e |
fprintf(f, ",");
|
|
|
4aca6e |
}
|
|
|
4aca6e |
diff --git a/ip/ipmroute.c b/ip/ipmroute.c
|
|
|
4aca6e |
index 2daecc0..eb480f0 100644
|
|
|
4aca6e |
--- a/ip/ipmroute.c
|
|
|
4aca6e |
+++ b/ip/ipmroute.c
|
|
|
4aca6e |
@@ -114,16 +114,12 @@ int print_mroute(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
|
|
|
4aca6e |
|
|
|
4aca6e |
if (tb[RTA_SRC])
|
|
|
4aca6e |
len = snprintf(obuf, sizeof(obuf),
|
|
|
4aca6e |
- "(%s, ", rt_addr_n2a(family,
|
|
|
4aca6e |
- RTA_PAYLOAD(tb[RTA_SRC]),
|
|
|
4aca6e |
- RTA_DATA(tb[RTA_SRC])));
|
|
|
4aca6e |
+ "(%s, ", rt_addr_n2a_rta(family, tb[RTA_SRC]));
|
|
|
4aca6e |
else
|
|
|
4aca6e |
len = sprintf(obuf, "(unknown, ");
|
|
|
4aca6e |
if (tb[RTA_DST])
|
|
|
4aca6e |
snprintf(obuf + len, sizeof(obuf) - len,
|
|
|
4aca6e |
- "%s)", rt_addr_n2a(family,
|
|
|
4aca6e |
- RTA_PAYLOAD(tb[RTA_DST]),
|
|
|
4aca6e |
- RTA_DATA(tb[RTA_DST])));
|
|
|
4aca6e |
+ "%s)", rt_addr_n2a_rta(family, tb[RTA_DST]));
|
|
|
4aca6e |
else
|
|
|
4aca6e |
snprintf(obuf + len, sizeof(obuf) - len, "unknown) ");
|
|
|
4aca6e |
|
|
|
4aca6e |
diff --git a/ip/ipprefix.c b/ip/ipprefix.c
|
|
|
4aca6e |
index 7b0a762..a1558d2 100644
|
|
|
4aca6e |
--- a/ip/ipprefix.c
|
|
|
4aca6e |
+++ b/ip/ipprefix.c
|
|
|
4aca6e |
@@ -72,19 +72,11 @@ int print_prefix(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
|
|
|
4aca6e |
|
|
|
4aca6e |
parse_rtattr(tb, RTA_MAX, RTM_RTA(prefix), len);
|
|
|
4aca6e |
|
|
|
4aca6e |
- fprintf(fp, "prefix ");
|
|
|
4aca6e |
-
|
|
|
4aca6e |
if (tb[PREFIX_ADDRESS]) {
|
|
|
4aca6e |
- struct in6_addr *pfx;
|
|
|
4aca6e |
-
|
|
|
4aca6e |
- pfx = (struct in6_addr *)RTA_DATA(tb[PREFIX_ADDRESS]);
|
|
|
4aca6e |
-
|
|
|
4aca6e |
- fprintf(fp, "%s", rt_addr_n2a(family,
|
|
|
4aca6e |
- RTA_PAYLOAD(tb[PREFIX_ADDRESS]),
|
|
|
4aca6e |
- pfx));
|
|
|
4aca6e |
+ fprintf(fp, "prefix %s/%u",
|
|
|
4aca6e |
+ rt_addr_n2a_rta(family, tb[PREFIX_ADDRESS]),
|
|
|
4aca6e |
+ prefix->prefix_len);
|
|
|
4aca6e |
}
|
|
|
4aca6e |
- fprintf(fp, "/%u ", prefix->prefix_len);
|
|
|
4aca6e |
-
|
|
|
4aca6e |
fprintf(fp, "dev %s ", ll_index_to_name(prefix->prefix_ifindex));
|
|
|
4aca6e |
|
|
|
4aca6e |
if (prefix->prefix_flags & IF_PREFIX_ONLINK)
|
|
|
4aca6e |
diff --git a/ip/iproute.c b/ip/iproute.c
|
|
|
4aca6e |
index c3006e4..134b146 100644
|
|
|
4aca6e |
--- a/ip/iproute.c
|
|
|
4aca6e |
+++ b/ip/iproute.c
|
|
|
4aca6e |
@@ -356,11 +356,9 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
|
|
|
4aca6e |
|
|
|
4aca6e |
if (tb[RTA_DST]) {
|
|
|
4aca6e |
if (r->rtm_dst_len != host_len) {
|
|
|
4aca6e |
- fprintf(fp, "%s/%u ", rt_addr_n2a(r->rtm_family,
|
|
|
4aca6e |
- RTA_PAYLOAD(tb[RTA_DST]),
|
|
|
4aca6e |
- RTA_DATA(tb[RTA_DST])),
|
|
|
4aca6e |
- r->rtm_dst_len
|
|
|
4aca6e |
- );
|
|
|
4aca6e |
+ fprintf(fp, "%s/%u ",
|
|
|
4aca6e |
+ rt_addr_n2a_rta(r->rtm_family, tb[RTA_DST]),
|
|
|
4aca6e |
+ r->rtm_dst_len);
|
|
|
4aca6e |
} else {
|
|
|
4aca6e |
fprintf(fp, "%s ", format_host(r->rtm_family,
|
|
|
4aca6e |
RTA_PAYLOAD(tb[RTA_DST]),
|
|
|
4aca6e |
@@ -374,11 +372,9 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
|
|
|
4aca6e |
}
|
|
|
4aca6e |
if (tb[RTA_SRC]) {
|
|
|
4aca6e |
if (r->rtm_src_len != host_len) {
|
|
|
4aca6e |
- fprintf(fp, "from %s/%u ", rt_addr_n2a(r->rtm_family,
|
|
|
4aca6e |
- RTA_PAYLOAD(tb[RTA_SRC]),
|
|
|
4aca6e |
- RTA_DATA(tb[RTA_SRC])),
|
|
|
4aca6e |
- r->rtm_src_len
|
|
|
4aca6e |
- );
|
|
|
4aca6e |
+ fprintf(fp, "from %s/%u ",
|
|
|
4aca6e |
+ rt_addr_n2a_rta(r->rtm_family, tb[RTA_SRC]),
|
|
|
4aca6e |
+ r->rtm_src_len);
|
|
|
4aca6e |
} else {
|
|
|
4aca6e |
fprintf(fp, "from %s ", format_host(r->rtm_family,
|
|
|
4aca6e |
RTA_PAYLOAD(tb[RTA_SRC]),
|
|
|
4aca6e |
@@ -419,9 +415,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
|
|
|
4aca6e |
and symbolic name will not be useful.
|
|
|
4aca6e |
*/
|
|
|
4aca6e |
fprintf(fp, "src %s ",
|
|
|
4aca6e |
- rt_addr_n2a(r->rtm_family,
|
|
|
4aca6e |
- RTA_PAYLOAD(tb[RTA_PREFSRC]),
|
|
|
4aca6e |
- RTA_DATA(tb[RTA_PREFSRC])));
|
|
|
4aca6e |
+ rt_addr_n2a_rta(r->rtm_family, tb[RTA_PREFSRC]));
|
|
|
4aca6e |
}
|
|
|
4aca6e |
if (tb[RTA_PRIORITY])
|
|
|
4aca6e |
fprintf(fp, "metric %u ", rta_getattr_u32(tb[RTA_PRIORITY]));
|
|
|
4aca6e |
diff --git a/ip/iprule.c b/ip/iprule.c
|
|
|
4aca6e |
index 87adb3b..4b7de4a 100644
|
|
|
4aca6e |
--- a/ip/iprule.c
|
|
|
4aca6e |
+++ b/ip/iprule.c
|
|
|
4aca6e |
@@ -86,11 +86,9 @@ int print_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
|
|
|
4aca6e |
|
|
|
4aca6e |
if (tb[FRA_SRC]) {
|
|
|
4aca6e |
if (r->rtm_src_len != host_len) {
|
|
|
4aca6e |
- fprintf(fp, "from %s/%u ", rt_addr_n2a(r->rtm_family,
|
|
|
4aca6e |
- RTA_PAYLOAD(tb[FRA_SRC]),
|
|
|
4aca6e |
- RTA_DATA(tb[FRA_SRC])),
|
|
|
4aca6e |
- r->rtm_src_len
|
|
|
4aca6e |
- );
|
|
|
4aca6e |
+ fprintf(fp, "from %s/%u ",
|
|
|
4aca6e |
+ rt_addr_n2a_rta(r->rtm_family, tb[FRA_SRC]),
|
|
|
4aca6e |
+ r->rtm_src_len);
|
|
|
4aca6e |
} else {
|
|
|
4aca6e |
fprintf(fp, "from %s ", format_host(r->rtm_family,
|
|
|
4aca6e |
RTA_PAYLOAD(tb[FRA_SRC]),
|
|
|
4aca6e |
@@ -105,11 +103,9 @@ int print_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
|
|
|
4aca6e |
|
|
|
4aca6e |
if (tb[FRA_DST]) {
|
|
|
4aca6e |
if (r->rtm_dst_len != host_len) {
|
|
|
4aca6e |
- fprintf(fp, "to %s/%u ", rt_addr_n2a(r->rtm_family,
|
|
|
4aca6e |
- RTA_PAYLOAD(tb[FRA_DST]),
|
|
|
4aca6e |
- RTA_DATA(tb[FRA_DST])),
|
|
|
4aca6e |
- r->rtm_dst_len
|
|
|
4aca6e |
- );
|
|
|
4aca6e |
+ fprintf(fp, "to %s/%u ",
|
|
|
4aca6e |
+ rt_addr_n2a_rta(r->rtm_family, tb[FRA_DST]),
|
|
|
4aca6e |
+ r->rtm_dst_len);
|
|
|
4aca6e |
} else {
|
|
|
4aca6e |
fprintf(fp, "to %s ", format_host(r->rtm_family,
|
|
|
4aca6e |
RTA_PAYLOAD(tb[FRA_DST]),
|
|
|
4aca6e |
diff --git a/ip/link_ip6tnl.c b/ip/link_ip6tnl.c
|
|
|
4aca6e |
index 8cd9095..79b5cd1 100644
|
|
|
4aca6e |
--- a/ip/link_ip6tnl.c
|
|
|
4aca6e |
+++ b/ip/link_ip6tnl.c
|
|
|
4aca6e |
@@ -283,16 +283,12 @@ static void ip6tunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb
|
|
|
4aca6e |
|
|
|
4aca6e |
if (tb[IFLA_IPTUN_REMOTE]) {
|
|
|
4aca6e |
fprintf(f, "remote %s ",
|
|
|
4aca6e |
- rt_addr_n2a(AF_INET6,
|
|
|
4aca6e |
- RTA_PAYLOAD(tb[IFLA_IPTUN_REMOTE]),
|
|
|
4aca6e |
- RTA_DATA(tb[IFLA_IPTUN_REMOTE])));
|
|
|
4aca6e |
+ rt_addr_n2a_rta(AF_INET6, tb[IFLA_IPTUN_REMOTE]));
|
|
|
4aca6e |
}
|
|
|
4aca6e |
|
|
|
4aca6e |
if (tb[IFLA_IPTUN_LOCAL]) {
|
|
|
4aca6e |
fprintf(f, "local %s ",
|
|
|
4aca6e |
- rt_addr_n2a(AF_INET6,
|
|
|
4aca6e |
- RTA_PAYLOAD(tb[IFLA_IPTUN_LOCAL]),
|
|
|
4aca6e |
- RTA_DATA(tb[IFLA_IPTUN_LOCAL])));
|
|
|
4aca6e |
+ rt_addr_n2a_rta(AF_INET6, tb[IFLA_IPTUN_LOCAL]));
|
|
|
4aca6e |
}
|
|
|
4aca6e |
|
|
|
4aca6e |
if (tb[IFLA_IPTUN_LINK] && rta_getattr_u32(tb[IFLA_IPTUN_LINK])) {
|
|
|
4aca6e |
diff --git a/tc/f_flower.c b/tc/f_flower.c
|
|
|
4aca6e |
index 5e2dc0d..f0d146f 100644
|
|
|
4aca6e |
--- a/tc/f_flower.c
|
|
|
4aca6e |
+++ b/tc/f_flower.c
|
|
|
4aca6e |
@@ -415,16 +415,12 @@ static void flower_print_ip_addr(FILE *f, char *name, __be16 eth_type,
|
|
|
4aca6e |
}
|
|
|
4aca6e |
if (!addr_attr || RTA_PAYLOAD(addr_attr) != len)
|
|
|
4aca6e |
return;
|
|
|
4aca6e |
- fprintf(f, "\n %s %s", name, rt_addr_n2a(family,
|
|
|
4aca6e |
- RTA_PAYLOAD(addr_attr),
|
|
|
4aca6e |
- RTA_DATA(addr_attr)));
|
|
|
4aca6e |
+ fprintf(f, "\n %s %s", name, rt_addr_n2a_rta(family, addr_attr));
|
|
|
4aca6e |
if (!mask_attr || RTA_PAYLOAD(mask_attr) != len)
|
|
|
4aca6e |
return;
|
|
|
4aca6e |
bits = __mask_bits(RTA_DATA(mask_attr), len);
|
|
|
4aca6e |
if (bits < 0)
|
|
|
4aca6e |
- fprintf(f, "/%s", rt_addr_n2a(family,
|
|
|
4aca6e |
- RTA_PAYLOAD(mask_attr),
|
|
|
4aca6e |
- RTA_DATA(mask_attr)));
|
|
|
4aca6e |
+ fprintf(f, "/%s", rt_addr_n2a_rta(family, mask_attr));
|
|
|
4aca6e |
else if (bits < len * 8)
|
|
|
4aca6e |
fprintf(f, "/%d", bits);
|
|
|
4aca6e |
}
|
|
|
4aca6e |
--
|
|
|
4aca6e |
1.8.3.1
|
|
|
4aca6e |
|