Basic specfile taken from F10
[iproute2.git] / ip / iproute.c
index 1e23e49..6a2ea05 100644 (file)
 #endif
 
 
+static const char *mx_names[RTAX_MAX+1] = {
+       [RTAX_MTU]      = "mtu",
+       [RTAX_WINDOW]   = "window",
+       [RTAX_RTT]      = "rtt",
+       [RTAX_RTTVAR]   = "rttvar",
+       [RTAX_SSTHRESH] = "ssthresh",
+       [RTAX_CWND]     = "cwnd",
+       [RTAX_ADVMSS]   = "advmss",
+       [RTAX_REORDERING]="reordering",
+       [RTAX_HOPLIMIT] = "hoplimit",
+       [RTAX_INITCWND] = "initcwnd",
+       [RTAX_FEATURES] = "features",
+       [RTAX_RTO_MIN]  = "rto_min",
+};
 static void usage(void) __attribute__((noreturn));
 
 static void usage(void)
@@ -56,16 +70,19 @@ static void usage(void)
        fprintf(stderr, "INFO_SPEC := NH OPTIONS FLAGS [ nexthop NH ]...\n");
        fprintf(stderr, "NH := [ via ADDRESS ] [ dev STRING ] [ weight NUMBER ] NHFLAGS\n");
        fprintf(stderr, "OPTIONS := FLAGS [ mtu NUMBER ] [ advmss NUMBER ]\n");
-       fprintf(stderr, "           [ rtt NUMBER ] [ rttvar NUMBER ]\n");
-       fprintf(stderr, "           [ window NUMBER] [ cwnd NUMBER ] [ ssthresh NUMBER ]\n");
-       fprintf(stderr, "           [ realms REALM ]\n");
+       fprintf(stderr, "           [ rtt TIME ] [ rttvar TIME ]\n");
+       fprintf(stderr, "           [ window NUMBER] [ cwnd NUMBER ] [ initcwnd NUMBER ]\n");
+       fprintf(stderr, "           [ ssthresh NUMBER ] [ realms REALM ] [ src ADDRESS ]\n");
+       fprintf(stderr, "           [ rto_min TIME ]\n");
        fprintf(stderr, "TYPE := [ unicast | local | broadcast | multicast | throw |\n");
        fprintf(stderr, "          unreachable | prohibit | blackhole | nat ]\n");
        fprintf(stderr, "TABLE_ID := [ local | main | default | all | NUMBER ]\n");
        fprintf(stderr, "SCOPE := [ host | link | global | NUMBER ]\n");
        fprintf(stderr, "FLAGS := [ equalize ]\n");
+       fprintf(stderr, "MP_ALGO := { rr | drr | random | wrandom }\n");
        fprintf(stderr, "NHFLAGS := [ onlink | pervasive ]\n");
        fprintf(stderr, "RTPROTO := [ kernel | boot | static | NUMBER ]\n");
+       fprintf(stderr, "TIME := NUMBER[s|ms|us|ns|j]\n");
        exit(-1);
 }
 
@@ -73,11 +90,11 @@ static void usage(void)
 static struct
 {
        int tb;
+       int cloned;
        int flushed;
        char *flushb;
        int flushp;
        int flushe;
-       struct rtnl_handle *rth;
        int protocol, protocolmask;
        int scope, scopemask;
        int type, typemask;
@@ -95,8 +112,8 @@ static struct
 
 static int flush_update(void)
 {
-       if (rtnl_send(filter.rth, filter.flushb, filter.flushp) < 0) {
-               perror("Failed to send flush request\n");
+       if (rtnl_send_check(&rth, filter.flushb, filter.flushp) < 0) {
+               perror("Failed to send flush request");
                return -1;
        }
        filter.flushp = 0;
@@ -115,8 +132,10 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
        inet_prefix prefsrc;
        inet_prefix via;
        int host_len = -1;
+       static int ip6_multiple_tables;
+       __u32 table;
        SPRINT_BUF(b1);
-       
+       static int hz;
 
        if (n->nlmsg_type != RTM_NEWROUTE && n->nlmsg_type != RTM_DELROUTE) {
                fprintf(stderr, "Not a route: %08x %08x %08x\n",
@@ -140,27 +159,36 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
        else if (r->rtm_family == AF_IPX)
                host_len = 80;
 
-       if (r->rtm_family == AF_INET6) {
+       parse_rtattr(tb, RTA_MAX, RTM_RTA(r), len);
+       table = rtm_get_table(r, tb);
+
+       if (r->rtm_family == AF_INET6 && table != RT_TABLE_MAIN)
+               ip6_multiple_tables = 1;
+
+       if (r->rtm_family == AF_INET6 && !ip6_multiple_tables) {
+               if (filter.cloned) {
+                       if (!(r->rtm_flags&RTM_F_CLONED))
+                               return 0;
+               }
                if (filter.tb) {
-                       if (filter.tb < 0) {
-                               if (!(r->rtm_flags&RTM_F_CLONED))
-                                       return 0;
-                       } else {
-                               if (r->rtm_flags&RTM_F_CLONED)
+                       if (!filter.cloned && r->rtm_flags&RTM_F_CLONED)
+                               return 0;
+                       if (filter.tb == RT_TABLE_LOCAL) {
+                               if (r->rtm_type != RTN_LOCAL)
                                        return 0;
-                               if (filter.tb == RT_TABLE_LOCAL) {
-                                       if (r->rtm_type != RTN_LOCAL)
-                                               return 0;
-                               } else if (filter.tb == RT_TABLE_MAIN) {
-                                       if (r->rtm_type == RTN_LOCAL)
-                                               return 0;
-                               } else {
+                       } else if (filter.tb == RT_TABLE_MAIN) {
+                               if (r->rtm_type == RTN_LOCAL)
                                        return 0;
-                               }
+                       } else {
+                               return 0;
                        }
                }
        } else {
-               if (filter.tb > 0 && filter.tb != r->rtm_table)
+               if (filter.cloned) {
+                       if (!(r->rtm_flags&RTM_F_CLONED))
+                               return 0;
+               }
+               if (filter.tb > 0 && filter.tb != table)
                        return 0;
        }
        if ((filter.protocol^r->rtm_protocol)&filter.protocolmask)
@@ -190,8 +218,6 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
        if (filter.rprefsrc.family && r->rtm_family != filter.rprefsrc.family)
                return 0;
 
-       parse_rtattr(tb, RTA_MAX, RTM_RTA(r), len);
-
        memset(&dst, 0, sizeof(dst));
        dst.family = r->rtm_family;
        if (tb[RTA_DST])
@@ -206,13 +232,13 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
                memset(&via, 0, sizeof(via));
                via.family = r->rtm_family;
                if (tb[RTA_GATEWAY])
-                       memcpy(&via.data, RTA_DATA(tb[RTA_GATEWAY]), host_len);
+                       memcpy(&via.data, RTA_DATA(tb[RTA_GATEWAY]), host_len/8);
        }
        if (filter.rprefsrc.bitlen>0) {
                memset(&prefsrc, 0, sizeof(prefsrc));
                prefsrc.family = r->rtm_family;
                if (tb[RTA_PREFSRC])
-                       memcpy(&prefsrc.data, RTA_DATA(tb[RTA_PREFSRC]), host_len);
+                       memcpy(&prefsrc.data, RTA_DATA(tb[RTA_PREFSRC]), host_len/8);
        }
 
        if (filter.rdst.family && inet_addr_match(&dst, &filter.rdst, filter.rdst.bitlen))
@@ -252,7 +278,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
                if ((oif^filter.oif)&filter.oifmask)
                        return 0;
        }
-       if (filter.flushb && 
+       if (filter.flushb &&
            r->rtm_family == AF_INET6 &&
            r->rtm_dst_len == 0 &&
            r->rtm_type == RTN_UNREACHABLE &&
@@ -270,7 +296,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
                memcpy(fn, n, n->nlmsg_len);
                fn->nlmsg_type = RTM_DELROUTE;
                fn->nlmsg_flags = NLM_F_REQUEST;
-               fn->nlmsg_seq = ++filter.rth->seq;
+               fn->nlmsg_seq = ++rth.seq;
                filter.flushp = (((char*)fn) + n->nlmsg_len) - filter.flushb;
                filter.flushed++;
                if (show_stats < 2)
@@ -324,8 +350,9 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
                SPRINT_BUF(b1);
                fprintf(fp, "tos %s ", rtnl_dsfield_n2a(r->rtm_tos, b1, sizeof(b1)));
        }
+
        if (tb[RTA_GATEWAY] && filter.rvia.bitlen != host_len) {
-               fprintf(fp, "via %s ", 
+               fprintf(fp, "via %s ",
                        format_host(r->rtm_family,
                                    RTA_PAYLOAD(tb[RTA_GATEWAY]),
                                    RTA_DATA(tb[RTA_GATEWAY]),
@@ -335,8 +362,8 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
                fprintf(fp, "dev %s ", ll_index_to_name(*(int*)RTA_DATA(tb[RTA_OIF])));
 
        if (!(r->rtm_flags&RTM_F_CLONED)) {
-               if (r->rtm_table != RT_TABLE_MAIN && !filter.tb)
-                       fprintf(fp, " table %s ", rtnl_rttable_n2a(r->rtm_table, b1, sizeof(b1)));
+               if (table != RT_TABLE_MAIN && !filter.tb)
+                       fprintf(fp, " table %s ", rtnl_rttable_n2a(table, b1, sizeof(b1)));
                if (r->rtm_protocol != RTPROT_BOOT && filter.protocolmask != -1)
                        fprintf(fp, " proto %s ", rtnl_rtprot_n2a(r->rtm_protocol, b1, sizeof(b1)));
                if (r->rtm_scope != RT_SCOPE_UNIVERSE && filter.scopemask != -1)
@@ -346,7 +373,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
                /* Do not use format_host(). It is our local addr
                   and symbolic name will not be useful.
                 */
-               fprintf(fp, " src %s ", 
+               fprintf(fp, " src %s ",
                        rt_addr_n2a(r->rtm_family,
                                    RTA_PAYLOAD(tb[RTA_PREFSRC]),
                                    RTA_DATA(tb[RTA_PREFSRC]),
@@ -408,7 +435,6 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
                        fprintf(fp, "%s%x> ", first ? "<" : "", flags);
                if (tb[RTA_CACHEINFO]) {
                        struct rta_cacheinfo *ci = RTA_DATA(tb[RTA_CACHEINFO]);
-                       static int hz;
                        if (!hz)
                                hz = get_user_hz();
                        if (ci->rta_expires != 0)
@@ -435,7 +461,6 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
                if (tb[RTA_CACHEINFO])
                        ci = RTA_DATA(tb[RTA_CACHEINFO]);
                if ((r->rtm_flags & RTM_F_CLONED) || (ci && ci->rta_expires)) {
-                       static int hz;
                        if (!hz)
                                hz = get_user_hz();
                        if (r->rtm_flags & RTM_F_CLONED)
@@ -467,42 +492,32 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
                if (mxrta[RTAX_LOCK])
                        mxlock = *(unsigned*)RTA_DATA(mxrta[RTAX_LOCK]);
 
-               for (i=2; i<=RTAX_MAX; i++) {
-                       static char *mx_names[] = 
-                       {
-                               "mtu",
-                               "window",
-                               "rtt",
-                               "rttvar",
-                               "ssthresh",
-                               "cwnd",
-                               "advmss",
-                               "reordering",
-                       };
-                       static int hz;
+               for (i=2; i<= RTAX_MAX; i++) {
                        if (mxrta[i] == NULL)
                                continue;
                        if (!hz)
                                hz = get_hz();
-                       if (i-2 < sizeof(mx_names)/sizeof(char*))
-                               fprintf(fp, " %s", mx_names[i-2]);
+
+                       if (i < sizeof(mx_names)/sizeof(char*) && mx_names[i])
+                               fprintf(fp, " %s", mx_names[i]);
                        else
                                fprintf(fp, " metric %d", i);
                        if (mxlock & (1<<i))
                                fprintf(fp, " lock");
 
-                       if (i != RTAX_RTT && i != RTAX_RTTVAR)
+                       if (i != RTAX_RTT && i != RTAX_RTTVAR &&
+                           i != RTAX_RTO_MIN)
                                fprintf(fp, " %u", *(unsigned*)RTA_DATA(mxrta[i]));
                        else {
-                               unsigned val = *(unsigned*)RTA_DATA(mxrta[i]);
+                               unsigned long long val = *(unsigned*)RTA_DATA(mxrta[i]);
 
                                val *= 1000;
                                if (i == RTAX_RTT)
                                        val /= 8;
-                               else
+                               else if (i == RTAX_RTTVAR)
                                        val /= 4;
                                if (val >= hz)
-                                       fprintf(fp, " %ums", val/hz);
+                                       fprintf(fp, " %llums", val/hz);
                                else
                                        fprintf(fp, " %.2fms", (float)val/hz);
                        }
@@ -532,12 +547,24 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
                        if (nh->rtnh_len > sizeof(*nh)) {
                                parse_rtattr(tb, RTA_MAX, RTNH_DATA(nh), nh->rtnh_len - sizeof(*nh));
                                if (tb[RTA_GATEWAY]) {
-                                       fprintf(fp, " via %s ", 
+                                       fprintf(fp, " via %s ",
                                                format_host(r->rtm_family,
                                                            RTA_PAYLOAD(tb[RTA_GATEWAY]),
                                                            RTA_DATA(tb[RTA_GATEWAY]),
                                                            abuf, sizeof(abuf)));
                                }
+                               if (tb[RTA_FLOW]) {
+                                       __u32 to = *(__u32*)RTA_DATA(tb[RTA_FLOW]);
+                                       __u32 from = to>>16;
+                                       to &= 0xFFFF;
+                                       fprintf(fp, " realm%s ", from ? "s" : "");
+                                       if (from) {
+                                               fprintf(fp, "%s/",
+                                                       rtnl_rtrealm_n2a(from, b1, sizeof(b1)));
+                                       }
+                                       fprintf(fp, "%s",
+                                               rtnl_rtrealm_n2a(to, b1, sizeof(b1)));
+                               }
                        }
                        if (r->rtm_flags&RTM_F_CLONED && r->rtm_type == RTN_MULTICAST) {
                                fprintf(fp, " %s", ll_index_to_name(nh->rtnh_ifindex));
@@ -587,6 +614,13 @@ int parse_one_nh(struct rtattr *rta, struct rtnexthop *rtnh, int *argcp, char **
                        rtnh->rtnh_hops = w - 1;
                } else if (strcmp(*argv, "onlink") == 0) {
                        rtnh->rtnh_flags |= RTNH_F_ONLINK;
+               } else if (matches(*argv, "realms") == 0) {
+                       __u32 realm;
+                       NEXT_ARG();
+                       if (get_rt_realms(&realm, *argv))
+                               invarg("\"realm\" value is invalid\n", *argv);
+                       rta_addattr32(rta, 4096, RTA_FLOW, realm);
+                       rtnh->rtnh_len += sizeof(struct rtattr) + 4;
                } else
                        break;
        }
@@ -616,9 +650,6 @@ int parse_nexthops(struct nlmsghdr *n, struct rtmsg *r, int argc, char **argv)
                }
                memset(rtnh, 0, sizeof(*rtnh));
                rtnh->rtnh_len = sizeof(*rtnh);
-               rtnh->rtnh_ifindex = 0;
-               rtnh->rtnh_flags = 0;
-               rtnh->rtnh_hops = 0;
                rta->rta_len += rtnh->rtnh_len;
                parse_one_nh(rta, rtnh, &argc, &argv);
                rtnh = RTNH_NEXT(rtnh);
@@ -632,7 +663,6 @@ int parse_nexthops(struct nlmsghdr *n, struct rtmsg *r, int argc, char **argv)
 
 int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
 {
-       struct rtnl_handle rth;
        struct {
                struct nlmsghdr         n;
                struct rtmsg            r;
@@ -649,6 +679,7 @@ int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
        int table_ok = 0;
        int proto_ok = 0;
        int type_ok = 0;
+       int raw = 0;
 
        memset(&req, 0, sizeof(req));
 
@@ -709,7 +740,7 @@ int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
                                invarg("\"metric\" value is invalid\n", *argv);
                        addattr32(&req.n, sizeof(req), RTA_PRIORITY, metric);
                } else if (strcmp(*argv, "scope") == 0) {
-                       int scope = 0;
+                       __u32 scope = 0;
                        NEXT_ARG();
                        if (rtnl_rtscope_a2n(&scope, *argv))
                                invarg("invalid \"scope\" value\n", *argv);
@@ -756,9 +787,19 @@ int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
                                mxlock |= (1<<RTAX_RTT);
                                NEXT_ARG();
                        }
-                       if (get_unsigned(&rtt, *argv, 0))
+                       if (get_jiffies(&rtt, *argv, 0, &raw))
                                invarg("\"rtt\" value is invalid\n", *argv);
-                       rta_addattr32(mxrta, sizeof(mxbuf), RTAX_RTT, rtt);
+                       rta_addattr32(mxrta, sizeof(mxbuf), RTAX_RTT, 
+                               (raw) ? rtt : rtt * 8);
+               } else if (strcmp(*argv, "rto_min") == 0) {
+                       unsigned rto_min;
+                       NEXT_ARG();
+                       mxlock |= (1<<RTAX_RTO_MIN);
+                       if (get_jiffies(&rto_min, *argv, 0, &raw))
+                               invarg("\"rto_min\" value is invalid\n",
+                                      *argv);
+                       rta_addattr32(mxrta, sizeof(mxbuf), RTAX_RTO_MIN,
+                                     rto_min);
                } else if (matches(*argv, "window") == 0) {
                        unsigned win;
                        NEXT_ARG();
@@ -779,6 +820,16 @@ int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
                        if (get_unsigned(&win, *argv, 0))
                                invarg("\"cwnd\" value is invalid\n", *argv);
                        rta_addattr32(mxrta, sizeof(mxbuf), RTAX_CWND, win);
+               } else if (matches(*argv, "initcwnd") == 0) {
+                       unsigned win;
+                       NEXT_ARG();
+                       if (strcmp(*argv, "lock") == 0) {
+                               mxlock |= (1<<RTAX_INITCWND);
+                               NEXT_ARG();
+                       }
+                       if (get_unsigned(&win, *argv, 0))
+                               invarg("\"initcwnd\" value is invalid\n", *argv);
+                       rta_addattr32(mxrta, sizeof(mxbuf), RTAX_INITCWND, win);
                } else if (matches(*argv, "rttvar") == 0) {
                        unsigned win;
                        NEXT_ARG();
@@ -786,9 +837,10 @@ int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
                                mxlock |= (1<<RTAX_RTTVAR);
                                NEXT_ARG();
                        }
-                       if (get_unsigned(&win, *argv, 0))
+                       if (get_jiffies(&win, *argv, 0, &raw))
                                invarg("\"rttvar\" value is invalid\n", *argv);
-                       rta_addattr32(mxrta, sizeof(mxbuf), RTAX_RTTVAR, win);
+                       rta_addattr32(mxrta, sizeof(mxbuf), RTAX_RTTVAR,
+                               (raw) ? win : win * 4);
                } else if (matches(*argv, "ssthresh") == 0) {
                        unsigned win;
                        NEXT_ARG();
@@ -814,18 +866,23 @@ int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
                        nhs_ok = 1;
                        break;
                } else if (matches(*argv, "protocol") == 0) {
-                       int prot;
+                       __u32 prot;
                        NEXT_ARG();
                        if (rtnl_rtprot_a2n(&prot, *argv))
                                invarg("\"protocol\" value is invalid\n", *argv);
                        req.r.rtm_protocol = prot;
                        proto_ok =1;
                } else if (matches(*argv, "table") == 0) {
-                       int tid;
+                       __u32 tid;
                        NEXT_ARG();
                        if (rtnl_rttable_a2n(&tid, *argv))
                                invarg("\"table\" value is invalid\n", *argv);
-                       req.r.rtm_table = tid;
+                       if (tid < 256)
+                               req.r.rtm_table = tid;
+                       else {
+                               req.r.rtm_table = RT_TABLE_UNSPEC;
+                               addattr32(&req.n, sizeof(req), RTA_TABLE, tid);
+                       }
                        table_ok = 1;
                } else if (strcmp(*argv, "dev") == 0 ||
                           strcmp(*argv, "oif") == 0) {
@@ -860,9 +917,6 @@ int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
                argc--; argv++;
        }
 
-       if (rtnl_open(&rth, 0) < 0)
-               exit(1);
-
        if (d || nhs_ok)  {
                int idx;
 
@@ -956,7 +1010,7 @@ static int iproute_flush_cache(void)
        }
 
        len = strlen (buffer);
-               
+
        if ((write (flush_fd, (void *)buffer, len)) < len) {
                fprintf (stderr, "Cannot flush routing cache\n");
                return -1;
@@ -969,7 +1023,6 @@ static int iproute_flush_cache(void)
 static int iproute_list_or_flush(int argc, char **argv, int flush)
 {
        int do_ipv6 = preferred_family;
-       struct rtnl_handle rth;
        char *id = NULL;
        char *od = NULL;
 
@@ -983,23 +1036,23 @@ static int iproute_list_or_flush(int argc, char **argv, int flush)
 
        while (argc > 0) {
                if (matches(*argv, "table") == 0) {
-                       int tid;
+                       __u32 tid;
                        NEXT_ARG();
                        if (rtnl_rttable_a2n(&tid, *argv)) {
                                if (strcmp(*argv, "all") == 0) {
-                                       tid = 0;
+                                       filter.tb = 0;
                                } else if (strcmp(*argv, "cache") == 0) {
-                                       tid = -1;
+                                       filter.cloned = 1;
                                } else if (strcmp(*argv, "help") == 0) {
                                        usage();
                                } else {
                                        invarg("table id value is invalid\n", *argv);
                                }
-                       }
-                       filter.tb = tid;
+                       } else
+                               filter.tb = tid;
                } else if (matches(*argv, "cached") == 0 ||
                           matches(*argv, "cloned") == 0) {
-                       filter.tb = -1;
+                       filter.cloned = 1;
                } else if (strcmp(*argv, "tos") == 0 ||
                           matches(*argv, "dsfield") == 0) {
                        __u32 tos;
@@ -1009,7 +1062,7 @@ static int iproute_list_or_flush(int argc, char **argv, int flush)
                        filter.tos = tos;
                        filter.tosmask = -1;
                } else if (matches(*argv, "protocol") == 0) {
-                       int prot = 0;
+                       __u32 prot = 0;
                        NEXT_ARG();
                        filter.protocolmask = -1;
                        if (rtnl_rtprot_a2n(&prot, *argv)) {
@@ -1020,7 +1073,7 @@ static int iproute_list_or_flush(int argc, char **argv, int flush)
                        }
                        filter.protocol = prot;
                } else if (matches(*argv, "scope") == 0) {
-                       int scope = 0;
+                       __u32 scope = 0;
                        NEXT_ARG();
                        filter.scopemask = -1;
                        if (rtnl_rtscope_a2n(&scope, *argv)) {
@@ -1103,9 +1156,6 @@ static int iproute_list_or_flush(int argc, char **argv, int flush)
        if (do_ipv6 == AF_UNSPEC && filter.tb)
                do_ipv6 = AF_INET;
 
-       if (rtnl_open(&rth, 0) < 0)
-               exit(1);
-
        ll_init_map(&rth);
 
        if (id || od)  {
@@ -1134,7 +1184,7 @@ static int iproute_list_or_flush(int argc, char **argv, int flush)
                char flushb[4096-512];
                time_t start = time(0);
 
-               if (filter.tb == -1) {
+               if (filter.cloned) {
                        if (do_ipv6 != AF_INET6) {
                                iproute_flush_cache();
                                if (show_stats)
@@ -1147,7 +1197,6 @@ static int iproute_list_or_flush(int argc, char **argv, int flush)
                filter.flushb = flushb;
                filter.flushp = 0;
                filter.flushe = sizeof(flushb);
-               filter.rth = &rth;
 
                for (;;) {
                        if (rtnl_wilddump_request(&rth, do_ipv6, RTM_GETROUTE) < 0) {
@@ -1160,11 +1209,12 @@ static int iproute_list_or_flush(int argc, char **argv, int flush)
                                exit(1);
                        }
                        if (filter.flushed == 0) {
-                               if (round == 0) {
-                                       if (filter.tb != -1 || do_ipv6 == AF_INET6)
-                                               fprintf(stderr, "Nothing to flush.\n");
-                               } else if (show_stats)
-                                       printf("*** Flush is complete after %d round%s ***\n", round, round>1?"s":"");
+                               if (show_stats) {
+                                       if (round == 0 && (!filter.cloned || do_ipv6 == AF_INET6))
+                                               printf("Nothing to flush.\n");
+                                       else
+                                               printf("*** Flush is complete after %d round%s ***\n", round, round>1?"s":"");
+                               }
                                fflush(stdout);
                                return 0;
                        }
@@ -1185,7 +1235,7 @@ static int iproute_list_or_flush(int argc, char **argv, int flush)
                }
        }
 
-       if (filter.tb != -1) {
+       if (!filter.cloned) {
                if (rtnl_wilddump_request(&rth, do_ipv6, RTM_GETROUTE) < 0) {
                        perror("Cannot send dump request");
                        exit(1);
@@ -1208,7 +1258,6 @@ static int iproute_list_or_flush(int argc, char **argv, int flush)
 
 int iproute_get(int argc, char **argv)
 {
-       struct rtnl_handle rth;
        struct {
                struct nlmsghdr         n;
                struct rtmsg            r;
@@ -1234,7 +1283,7 @@ int iproute_get(int argc, char **argv)
        req.r.rtm_src_len = 0;
        req.r.rtm_dst_len = 0;
        req.r.rtm_tos = 0;
-       
+
        while (argc > 0) {
                if (strcmp(*argv, "tos") == 0 ||
                    matches(*argv, "dsfield") == 0) {
@@ -1288,9 +1337,6 @@ int iproute_get(int argc, char **argv)
                exit(1);
        }
 
-       if (rtnl_open(&rth, 0) < 0)
-               exit(1);
-
        ll_init_map(&rth);
 
        if (idev || odev)  {
@@ -1379,7 +1425,7 @@ int do_iproute(int argc, char **argv)
 {
        if (argc < 1)
                return iproute_list_or_flush(0, NULL, 0);
-       
+
        if (matches(*argv, "add") == 0)
                return iproute_modify(RTM_NEWROUTE, NLM_F_CREATE|NLM_F_EXCL,
                                      argc-1, argv+1);