]> git.proxmox.com Git - mirror_iproute2.git/commitdiff
add a source addres length parameter to rt_addr_n2a
authorEric W. Biederman <ebiederm@xmission.com>
Sun, 15 Mar 2015 19:48:32 +0000 (14:48 -0500)
committerStephen Hemminger <shemming@brocade.com>
Tue, 24 Mar 2015 22:45:23 +0000 (15:45 -0700)
For some address families (like AF_PACKET) it is helpful to have the
length when prenting the address.

Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
include/utils.h
ip/iplink_bond.c
ip/ipmroute.c
ip/ipprefix.c
ip/iproute.c
ip/iprule.c
ip/iptunnel.c
ip/ipxfrm.c
ip/link_ip6tnl.c
ip/xfrm_monitor.c
lib/utils.c

index 59b228045a9a6fd257564c4cc127d421ea02617c..f9a7e32dea9dd20fa1c848f8681e0fc145fd7ba1 100644 (file)
@@ -106,7 +106,7 @@ extern int af_byte_len(int af);
 
 extern const char *format_host(int af, int len, const void *addr,
                               char *buf, int buflen);
-extern const char *rt_addr_n2a(int af, const void *addr,
+extern const char *rt_addr_n2a(int af, int len, const void *addr,
                               char *buf, int buflen);
 
 void missarg(const char *) __attribute__((noreturn));
index 3009ec912e23b6f806122c0cf02394bcd1750796..a573f92b03a048a0dc68cb4b1d942b3235d317c5 100644 (file)
@@ -415,6 +415,7 @@ static void bond_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
                        if (iptb[i])
                                fprintf(f, "%s",
                                        rt_addr_n2a(AF_INET,
+                                                   RTA_PAYLOAD(iptb[i]),
                                                    RTA_DATA(iptb[i]),
                                                    buf,
                                                    INET_ADDRSTRLEN));
index b4ed9f15fda5e8349fa6188c77d8f105888cabb0..13ac892512d0222ced62bfffa34c8b10997bcd31 100644 (file)
@@ -116,6 +116,7 @@ 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]),
                                                    abuf, sizeof(abuf)));
        else
@@ -123,6 +124,7 @@ int print_mroute(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
        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]),
                                            abuf, sizeof(abuf)));
        else
index 02c0efce68363403c8030f394a9cf276f5687f03..26b59615121778fdc2cd40b25e76114fc0a9ea30 100644 (file)
@@ -80,7 +80,9 @@ int print_prefix(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
                pfx = (struct in6_addr *)RTA_DATA(tb[PREFIX_ADDRESS]);
 
                memset(abuf, '\0', sizeof(abuf));
-               fprintf(fp, "%s", rt_addr_n2a(family, pfx,
+               fprintf(fp, "%s", rt_addr_n2a(family,
+                                             RTA_PAYLOAD(tb[PREFIX_ADDRESS]),
+                                             pfx,
                                              abuf, sizeof(abuf)));
        }
        fprintf(fp, "/%u ", prefix->prefix_len);
index 35418af364427b2e29c6725eae8d2d93672449c0..c73a36433436966c545e8bf9d720918daf18474f 100644 (file)
@@ -339,8 +339,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_DATA(tb[RTA_DST]),
-                                                        abuf, sizeof(abuf)),
+                                                      RTA_PAYLOAD(tb[RTA_DST]),
+                                                      RTA_DATA(tb[RTA_DST]),
+                                                      abuf, sizeof(abuf)),
                                r->rtm_dst_len
                                );
                } else {
@@ -358,8 +359,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_DATA(tb[RTA_SRC]),
-                                                        abuf, sizeof(abuf)),
+                                                      RTA_PAYLOAD(tb[RTA_SRC]),
+                                                      RTA_DATA(tb[RTA_SRC]),
+                                                      abuf, sizeof(abuf)),
                                r->rtm_src_len
                                );
                } else {
@@ -401,6 +403,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
                 */
                fprintf(fp, " src %s ",
                        rt_addr_n2a(r->rtm_family,
+                                   RTA_PAYLOAD(tb[RTA_PREFSRC]),
                                    RTA_DATA(tb[RTA_PREFSRC]),
                                    abuf, sizeof(abuf)));
        }
index 54ed7536e0642fc849496886be6c0f343565d0d3..967969c0e60e2f281ce1d4a1b45ac7b27091e757 100644 (file)
@@ -82,8 +82,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_DATA(tb[FRA_SRC]),
-                                                        abuf, sizeof(abuf)),
+                                                      RTA_PAYLOAD(tb[FRA_SRC]),
+                                                      RTA_DATA(tb[FRA_SRC]),
+                                                      abuf, sizeof(abuf)),
                                r->rtm_src_len
                                );
                } else {
@@ -102,8 +103,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_DATA(tb[FRA_DST]),
-                                                        abuf, sizeof(abuf)),
+                                                      RTA_PAYLOAD(tb[FRA_DST]),
+                                                      RTA_DATA(tb[FRA_DST]),
+                                                      abuf, sizeof(abuf)),
                                r->rtm_dst_len
                                );
                } else {
index caf8a28e62e88e76988280ec600833fae3c6a7ba..29188c4503709b823d3aafa8c215e2a389280936 100644 (file)
@@ -343,7 +343,7 @@ static void print_tunnel(struct ip_tunnel_parm *p)
               p->name,
               tnl_strproto(p->iph.protocol),
               p->iph.daddr ? format_host(AF_INET, 4, &p->iph.daddr, s1, sizeof(s1))  : "any",
-              p->iph.saddr ? rt_addr_n2a(AF_INET, &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)) {
                struct ip_tunnel_prl prl[16];
index 95f91a537759f90a07832537c92969d46d8a2921..9aaf58d5b5eaa65679ee72459371066c952148a7 100644 (file)
@@ -288,10 +288,10 @@ void xfrm_id_info_print(xfrm_address_t *saddr, struct xfrm_id *id,
                fputs(title, fp);
 
        memset(abuf, '\0', sizeof(abuf));
-       fprintf(fp, "src %s ", rt_addr_n2a(family,
+       fprintf(fp, "src %s ", rt_addr_n2a(family, sizeof(*saddr),
                                           saddr, abuf, sizeof(abuf)));
        memset(abuf, '\0', sizeof(abuf));
-       fprintf(fp, "dst %s", rt_addr_n2a(family,
+       fprintf(fp, "dst %s", rt_addr_n2a(family, sizeof(id->daddr),
                                          &id->daddr, abuf, sizeof(abuf)));
        fprintf(fp, "%s", _SL_);
 
@@ -455,11 +455,15 @@ void xfrm_selector_print(struct xfrm_selector *sel, __u16 family,
                fputs(prefix, fp);
 
        memset(abuf, '\0', sizeof(abuf));
-       fprintf(fp, "src %s/%u ", rt_addr_n2a(f, &sel->saddr, abuf, sizeof(abuf)),
+       fprintf(fp, "src %s/%u ",
+               rt_addr_n2a(f, sizeof(sel->saddr), &sel->saddr,
+                           abuf, sizeof(abuf)),
                sel->prefixlen_s);
 
        memset(abuf, '\0', sizeof(abuf));
-       fprintf(fp, "dst %s/%u ", rt_addr_n2a(f, &sel->daddr, abuf, sizeof(abuf)),
+       fprintf(fp, "dst %s/%u ",
+               rt_addr_n2a(f, sizeof(sel->daddr), &sel->daddr,
+                           abuf, sizeof(abuf)),
                sel->prefixlen_d);
 
        if (sel->proto)
@@ -755,7 +759,8 @@ void xfrm_xfrma_print(struct rtattr *tb[], __u16 family,
 
                memset(abuf, '\0', sizeof(abuf));
                fprintf(fp, "addr %s",
-                       rt_addr_n2a(family, &e->encap_oa, abuf, sizeof(abuf)));
+                       rt_addr_n2a(family, sizeof(e->encap_oa), &e->encap_oa,
+                                   abuf, sizeof(abuf)));
                fprintf(fp, "%s", _SL_);
        }
 
@@ -783,7 +788,7 @@ void xfrm_xfrma_print(struct rtattr *tb[], __u16 family,
 
                memset(abuf, '\0', sizeof(abuf));
                fprintf(fp, "%s",
-                       rt_addr_n2a(family, coa,
+                       rt_addr_n2a(family, sizeof(*coa), coa,
                                    abuf, sizeof(abuf)));
                fprintf(fp, "%s", _SL_);
        }
index 5ed3d5a23fb52d09d0d3c4cb64e1dfac110c91b3..cf59a9338f5738add81536eb13a37027c33f787e 100644 (file)
@@ -285,6 +285,7 @@ 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]),
                                    s1, sizeof(s1)));
        }
@@ -292,6 +293,7 @@ static void ip6tunnel_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb
        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]),
                                    s1, sizeof(s1)));
        }
index 50116a7b5433be61bce8058f202373fbefebdf61..b2b2d6e27a45b7bbb1fcbb69274f9223fe9814ab 100644 (file)
@@ -227,7 +227,8 @@ static void xfrm_usersa_print(const struct xfrm_usersa_id *sa_id, __u32 reqid, F
 
        buf[0] = 0;
        fprintf(fp, "dst %s ",
-               rt_addr_n2a(sa_id->family, &sa_id->daddr, buf, sizeof(buf)));
+               rt_addr_n2a(sa_id->family, sizeof(sa_id->daddr), &sa_id->daddr,
+                           buf, sizeof(buf)));
 
        fprintf(fp, " reqid 0x%x", reqid);
 
@@ -246,7 +247,8 @@ static int xfrm_ae_print(const struct sockaddr_nl *who,
        xfrm_ae_flags_print(id->flags, arg);
        fprintf(fp,"\n\t");
        memset(abuf, '\0', sizeof(abuf));
-       fprintf(fp, "src %s ", rt_addr_n2a(id->sa_id.family, &id->saddr,
+       fprintf(fp, "src %s ", rt_addr_n2a(id->sa_id.family,
+                                          sizeof(id->saddr), &id->saddr,
                                           abuf, sizeof(abuf)));
 
        xfrm_usersa_print(&id->sa_id, id->reqid, fp);
@@ -262,7 +264,7 @@ static void xfrm_print_addr(FILE *fp, int family, xfrm_address_t *a)
        char buf[256];
 
        buf[0] = 0;
-       fprintf(fp, "%s", rt_addr_n2a(family, a, buf, sizeof(buf)));
+       fprintf(fp, "%s", rt_addr_n2a(family, sizeof(*a), a, buf, sizeof(buf)));
 }
 
 static int xfrm_mapping_print(const struct sockaddr_nl *who,
index 0d08a86872c9c1f27908e5b5a9b4cd9856bef469..88ef4bac2bca2e27d3e28132ad1c243b99923f1f 100644 (file)
@@ -636,7 +636,7 @@ int __get_user_hz(void)
        return sysconf(_SC_CLK_TCK);
 }
 
-const char *rt_addr_n2a(int af, const void *addr, char *buf, int buflen)
+const char *rt_addr_n2a(int af, int len, const void *addr, char *buf, int buflen)
 {
        switch (af) {
        case AF_INET:
@@ -723,7 +723,7 @@ const char *format_host(int af, int len, const void *addr,
                        return n;
        }
 #endif
-       return rt_addr_n2a(af, addr, buf, buflen);
+       return rt_addr_n2a(af, len, addr, buf, buflen);
 }