]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
lib/utils: introduce rt_addr_n2a_rta()
authorPhil Sutter <phil@nwl.cc>
Tue, 22 Mar 2016 18:35:18 +0000 (19:35 +0100)
committerStephen Hemminger <stephen@networkplumber.org>
Sun, 27 Mar 2016 17:37:35 +0000 (10:37 -0700)
This simple macro eases calling rt_addr_n2a() with data from an rt_attr
pointer.

Signed-off-by: Phil Sutter <phil@nwl.cc>
include/utils.h
ip/iplink_bond.c
ip/ipmroute.c
ip/ipprefix.c
ip/iproute.c
ip/iproute_lwtunnel.c
ip/iprule.c
ip/link_ip6tnl.c
tc/f_flower.c

index ebb80c9c20b6d0d832c0a6fa97519329642edb36..ef81d00f3d70d835b81dfc6c059e4679aa5944a1 100644 (file)
@@ -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);
index 7da58e4556c073e008e9b774128e88e56ab92cc6..fe83479a091a899fc8cd41c5113ffcb8072b5005 100644 (file)
@@ -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, ",");
                }
index 2b9f892a62630cbf2731a8a4878a60cff10c43f7..c33cdcbbde21bb8dc6e52002fa31ae11a4349da8 100644 (file)
@@ -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) ");
 
index 4d986dbc1a5d1c5c335cb1ab4ec741f2e8924af3..a833efcf67c4a801db72cde5575b3922b9bba728 100644 (file)
@@ -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)
index 67d551b54d00cba3d3971e8b408edfbdb931b0a8..8224d7ffa94bf20d0d4fffbb173b11b51612801e 100644 (file)
@@ -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]));
index 56af9e4e92ecd15be1c1b5c4dfe1a57cc37642a9..3baac7720816899e0e18fda0af493bc78a6d5747 100644 (file)
@@ -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]));
index ac570440d663397ebbff30cf5c491d80d751868c..7cb19e4d5ebd04a2125a1f5d4161a96266111810 100644 (file)
@@ -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]));
index 4b32fe5aa80886757c7e3dc6c31ae8a9ed36c3cb..8a31d0dcd1883ba54f097aa47764aa0517277729 100644 (file)
@@ -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])) {
index 40f8c595b2eecebf89c695afc619c062746f34f5..306f056c1b662b391da78be137eac267b2b33bff 100644 (file)
@@ -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);
 }