libiproute: handle table ids larger than 255
[oweals/busybox.git] / networking / libiproute / iprule.c
index dba64346f382899d1f054301c07f494680c762c7..8f3f86286466f7165080997fdbf86fb5b6820abe 100644 (file)
@@ -114,7 +114,9 @@ static int FAST_FUNC print_rule(const struct sockaddr_nl *who UNUSED_PARAM,
                printf("iif %s ", (char*)RTA_DATA(tb[RTA_IIF]));
        }
 
-       if (r->rtm_table)
+       if (tb[RTA_TABLE])
+               printf("lookup %s ", rtnl_rttable_n2a(*(uint32_t*)RTA_DATA(tb[RTA_TABLE])));
+       else if (r->rtm_table)
                printf("lookup %s ", rtnl_rttable_n2a(r->rtm_table));
 
        if (tb[RTA_FLOW]) {
@@ -197,9 +199,11 @@ static int iprule_modify(int cmd, char **argv)
        req.n.nlmsg_flags = NLM_F_REQUEST;
        req.r.rtm_family = preferred_family;
        req.r.rtm_protocol = RTPROT_BOOT;
-       req.r.rtm_scope = RT_SCOPE_UNIVERSE;
-       req.r.rtm_table = 0;
-       req.r.rtm_type = RTN_UNSPEC;
+       if (RT_SCOPE_UNIVERSE != 0)
+               req.r.rtm_scope = RT_SCOPE_UNIVERSE;
+       /*req.r.rtm_table = 0; - already is */
+       if (RTN_UNSPEC != 0)
+               req.r.rtm_type = RTN_UNSPEC;
 
        if (cmd == RTM_NEWRULE) {
                req.n.nlmsg_flags |= NLM_F_CREATE|NLM_F_EXCL;
@@ -254,7 +258,12 @@ static int iprule_modify(int cmd, char **argv)
                        NEXT_ARG();
                        if (rtnl_rttable_a2n(&tid, *argv))
                                invarg_1_to_2(*argv, "table ID");
-                       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 (key == ARG_dev ||
                           key == ARG_iif