]> git.proxmox.com Git - mirror_iproute2.git/commitdiff
ip: route: fix multicast route dumps
authorNikolay Aleksandrov <nikolay@cumulusnetworks.com>
Sat, 20 Aug 2016 12:53:10 +0000 (14:53 +0200)
committerStephen Hemminger <stephen@networkplumber.org>
Thu, 1 Sep 2016 15:41:37 +0000 (08:41 -0700)
If we have multicast routes and do ip route show table all we'll get the
following output:
 ...
 multicast ???/32 from ???/32  table default  proto static  iif eth0
The "???" are because the rtm_family is set to RTNL_FAMILY_IPMR instead
(or RTNL_FAMILY_IP6MR for ipv6). Add a simple workaround that returns the
real family based on the rtm_type (always RTN_MULTICAST for ipmr routes)
and the rtm_family. Similar workaround is already used in ipmroute, and
we can use this helper there as well.

After the patch the output is:
multicast 239.10.10.10/32 from 0.0.0.0/32  table default  proto static  iif eth0

Also fix a minor whitespace error and switch to tabs.

Reported-by: Satish Ashok <sashok@cumulusnetworks.com>
Signed-off-by: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
include/utils.h
ip/ipmroute.c
ip/iproute.c
lib/utils.c

index 82f1aa7de16a05af60e89e7e6911e6e68b99a4f5..1b4f939cbd8c379b81579f6c92dd789197dcd285 100644 (file)
@@ -249,5 +249,6 @@ int do_each_netns(int (*func)(char *nsname, void *arg), void *arg,
 
 char *int_to_str(int val, char *buf);
 int get_guid(__u64 *guid, const char *arg);
+int get_real_family(int rtm_type, int rtm_family);
 
 #endif /* __UTILS_H__ */
index 5d6922a23ae667532dbb284f9bf699ae24408b1d..133367a2388d6f561d1a8eb100bf23f54c80c7e5 100644 (file)
@@ -112,7 +112,7 @@ int print_mroute(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
                        return 0;
        }
 
-       family = r->rtm_family == RTNL_FAMILY_IPMR ? AF_INET : AF_INET6;
+       family = get_real_family(r->rtm_type, r->rtm_family);
 
        if (n->nlmsg_type == RTM_DELROUTE)
                fprintf(fp, "Deleted ");
index 4d7da0233046d65bc70bb9529d76c75eb2ce4e84..0bc0136860a9a020de835ac79c2c0abb421de7f7 100644 (file)
@@ -311,7 +311,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
        struct rtmsg *r = NLMSG_DATA(n);
        int len = n->nlmsg_len;
        struct rtattr *tb[RTA_MAX+1];
-       int host_len;
+       int host_len, family;
        __u32 table;
 
        SPRINT_BUF(b1);
@@ -363,13 +363,14 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
                fprintf(fp, "%s ", rtnl_rtntype_n2a(r->rtm_type, b1, sizeof(b1)));
 
        if (tb[RTA_DST]) {
+               family = get_real_family(r->rtm_type, r->rtm_family);
                if (r->rtm_dst_len != host_len) {
                        fprintf(fp, "%s/%u ",
-                               rt_addr_n2a_rta(r->rtm_family, tb[RTA_DST]),
+                               rt_addr_n2a_rta(family, tb[RTA_DST]),
                                r->rtm_dst_len);
                } else {
                        fprintf(fp, "%s ",
-                               format_host_rta(r->rtm_family, tb[RTA_DST]));
+                               format_host_rta(family, tb[RTA_DST]));
                }
        } else if (r->rtm_dst_len) {
                fprintf(fp, "0/%d ", r->rtm_dst_len);
@@ -377,13 +378,14 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
                fprintf(fp, "default ");
        }
        if (tb[RTA_SRC]) {
+               family = get_real_family(r->rtm_type, r->rtm_family);
                if (r->rtm_src_len != host_len) {
                        fprintf(fp, "from %s/%u ",
-                               rt_addr_n2a_rta(r->rtm_family, tb[RTA_SRC]),
+                               rt_addr_n2a_rta(family, tb[RTA_SRC]),
                                r->rtm_src_len);
                } else {
                        fprintf(fp, "from %s ",
-                               format_host_rta(r->rtm_family, tb[RTA_SRC]));
+                               format_host_rta(family, tb[RTA_SRC]));
                }
        } else if (r->rtm_src_len) {
                fprintf(fp, "from 0/%u ", r->rtm_src_len);
index 966047460af11265b9a5e74705febe050c5ab8ea..9ada7737f14d6b3439a1913a36b5a032ef3333c9 100644 (file)
@@ -1156,3 +1156,12 @@ int get_guid(__u64 *guid, const char *arg)
 
        return 0;
 }
+
+/* This is a necessary workaround for multicast route dumps */
+int get_real_family(int rtm_type, int rtm_family)
+{
+       if (rtm_type != RTN_MULTICAST)
+               return rtm_family;
+
+       return rtm_family == RTNL_FAMILY_IPMR ? AF_INET : AF_INET6;
+}