]> git.proxmox.com Git - mirror_iproute2.git/blobdiff - ip/ipmroute.c
mroute: Add table id attribute for kernel side filtering
[mirror_iproute2.git] / ip / ipmroute.c
index 03087b6c439b3176b11e564469671d7fcc87985b..b29c78e4cc86c96a5c562c9356c637a0212fa18c 100644 (file)
@@ -52,7 +52,7 @@ struct rtfilter {
        inet_prefix msrc;
 } filter;
 
-int print_mroute(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
+int print_mroute(struct nlmsghdr *n, void *arg)
 {
        struct rtmsg *r = NLMSG_DATA(n);
        int len = n->nlmsg_len;
@@ -75,10 +75,11 @@ int print_mroute(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
                fprintf(stderr, "BUG: wrong nlmsg len %d\n", len);
                return -1;
        }
+
        if (r->rtm_type != RTN_MULTICAST) {
-               fprintf(stderr, "Not a multicast route (type: %s)\n",
-                       rtnl_rtntype_n2a(r->rtm_type, b1, sizeof(b1)));
-               return 0;
+               fprintf(stderr,
+                       "Non multicast route received, kernel does support IP multicast?\n");
+               return -1;
        }
 
        parse_rtattr(tb, RTA_MAX, RTM_RTA(r), len);
@@ -180,13 +181,13 @@ int print_mroute(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
        if (show_stats && tb[RTA_MFC_STATS]) {
                struct rta_mfc_stats *mfcs = RTA_DATA(tb[RTA_MFC_STATS]);
 
-               print_string(PRINT_FP, NULL, "%s", _SL_);
-               print_uint(PRINT_ANY, "packets", "  %"PRIu64" packets,",
+               print_nl();
+               print_u64(PRINT_ANY, "packets", "  %"PRIu64" packets,",
                           mfcs->mfcs_packets);
-               print_uint(PRINT_ANY, "bytes", " %"PRIu64" bytes", mfcs->mfcs_bytes);
+               print_u64(PRINT_ANY, "bytes", " %"PRIu64" bytes", mfcs->mfcs_bytes);
 
                if (mfcs->mfcs_wrong_if)
-                       print_uint(PRINT_ANY, "wrong_if",
+                       print_u64(PRINT_ANY, "wrong_if",
                                   ", %"PRIu64" arrived on wrong iif.",
                                   mfcs->mfcs_wrong_if);
        }
@@ -219,21 +220,36 @@ void ipmroute_reset_filter(int ifindex)
        filter.iif = ifindex;
 }
 
+static int iproute_dump_filter(struct nlmsghdr *nlh, int reqlen)
+{
+       int err;
+
+       if (filter.tb) {
+               err = addattr32(nlh, reqlen, RTA_TABLE, filter.tb);
+               if (err)
+                       return err;
+       }
+
+       return 0;
+}
+
 static int mroute_list(int argc, char **argv)
 {
        char *id = NULL;
-       int family;
+       int family = preferred_family;
 
        ipmroute_reset_filter(0);
-       if (preferred_family == AF_UNSPEC)
-               family = AF_INET;
-       else
-               family = AF_INET6;
-       if (family == AF_INET) {
+       if (family == AF_INET || family == AF_UNSPEC) {
+               family = RTNL_FAMILY_IPMR;
                filter.af = RTNL_FAMILY_IPMR;
                filter.tb = RT_TABLE_DEFAULT;  /* for backward compatibility */
-       } else
+       } else if (family == AF_INET6) {
+               family = RTNL_FAMILY_IP6MR;
                filter.af = RTNL_FAMILY_IP6MR;
+       } else {
+               /* family does not have multicast routing */
+               return 0;
+       }
 
        filter.msrc.family = filter.mdst.family = family;
 
@@ -282,7 +298,7 @@ static int mroute_list(int argc, char **argv)
                filter.iif = idx;
        }
 
-       if (rtnl_wilddump_request(&rth, filter.af, RTM_GETROUTE) < 0) {
+       if (rtnl_routedump_req(&rth, filter.af, iproute_dump_filter) < 0) {
                perror("Cannot send dump request");
                return 1;
        }