aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukasz Nowak <lnowak@tycoint.com>2016-12-13 12:58:31 +0000
committerDenys Vlasenko <vda.linux@googlemail.com>2016-12-18 18:56:49 +0100
commitb42107f21538e39d9a344376372f8261aed589b2 (patch)
tree34f0f4e836067be6c19a931e16d661eb47db162a
parente184a883567ee3fd735644416e4bd683f1894ac5 (diff)
downloadbusybox-w32-b42107f21538e39d9a344376372f8261aed589b2.tar.gz
busybox-w32-b42107f21538e39d9a344376372f8261aed589b2.tar.bz2
busybox-w32-b42107f21538e39d9a344376372f8261aed589b2.zip
libiproute: handle table ids larger than 255
Linux kernel, starting from 2.6.19 allows ip table ids to have 32-bit values. In order to preserve compatibility, the old 8-bit field: rtm_table is still in use when table id is lower than 256. Add support for the 32-bit table id (RTA_TABLE attribute) in: - ip route print - ip route modify - ip rule print - ip rule modify Add printing of table ids to ip route. Changes are compatible with the mainline iproute2 utilities. These changes are required for compatibility with ConnMan, which by default uses table ids greater than 255. function old new delta print_route 1588 1637 +49 do_iproute 2187 2222 +35 do_iprule 955 987 +32 print_rule 617 630 +13 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 4/0 up/down: 129/0) Total: 129 bytes Signed-off-by: Lukasz Nowak <lnowak@tycoint.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--networking/libiproute/iproute.c24
-rw-r--r--networking/libiproute/iprule.c11
2 files changed, 29 insertions, 6 deletions
diff --git a/networking/libiproute/iproute.c b/networking/libiproute/iproute.c
index 48dc6e3d9..0f2b89682 100644
--- a/networking/libiproute/iproute.c
+++ b/networking/libiproute/iproute.c
@@ -66,6 +66,7 @@ static int FAST_FUNC print_route(const struct sockaddr_nl *who UNUSED_PARAM,
66 inet_prefix dst; 66 inet_prefix dst;
67 inet_prefix src; 67 inet_prefix src;
68 int host_len = -1; 68 int host_len = -1;
69 uint32_t tid;
69 70
70 if (n->nlmsg_type != RTM_NEWROUTE && n->nlmsg_type != RTM_DELROUTE) { 71 if (n->nlmsg_type != RTM_NEWROUTE && n->nlmsg_type != RTM_DELROUTE) {
71 fprintf(stderr, "Not a route: %08x %08x %08x\n", 72 fprintf(stderr, "Not a route: %08x %08x %08x\n",
@@ -78,6 +79,14 @@ static int FAST_FUNC print_route(const struct sockaddr_nl *who UNUSED_PARAM,
78 if (len < 0) 79 if (len < 0)
79 bb_error_msg_and_die("wrong nlmsg len %d", len); 80 bb_error_msg_and_die("wrong nlmsg len %d", len);
80 81
82 memset(tb, 0, sizeof(tb));
83 parse_rtattr(tb, RTA_MAX, RTM_RTA(r), len);
84
85 if (tb[RTA_TABLE])
86 tid = *(uint32_t *)RTA_DATA(tb[RTA_TABLE]);
87 else
88 tid = r->rtm_table;
89
81 if (r->rtm_family == AF_INET6) 90 if (r->rtm_family == AF_INET6)
82 host_len = 128; 91 host_len = 128;
83 else if (r->rtm_family == AF_INET) 92 else if (r->rtm_family == AF_INET)
@@ -107,7 +116,7 @@ static int FAST_FUNC print_route(const struct sockaddr_nl *who UNUSED_PARAM,
107 } 116 }
108 } 117 }
109 } else { 118 } else {
110 if (G_filter.tb > 0 && G_filter.tb != r->rtm_table) { 119 if (G_filter.tb > 0 && G_filter.tb != tid) {
111 return 0; 120 return 0;
112 } 121 }
113 } 122 }
@@ -136,10 +145,8 @@ static int FAST_FUNC print_route(const struct sockaddr_nl *who UNUSED_PARAM,
136 return 0; 145 return 0;
137 } 146 }
138 147
139 memset(tb, 0, sizeof(tb));
140 memset(&src, 0, sizeof(src)); 148 memset(&src, 0, sizeof(src));
141 memset(&dst, 0, sizeof(dst)); 149 memset(&dst, 0, sizeof(dst));
142 parse_rtattr(tb, RTA_MAX, RTM_RTA(r), len);
143 150
144 if (tb[RTA_SRC]) { 151 if (tb[RTA_SRC]) {
145 src.bitlen = r->rtm_src_len; 152 src.bitlen = r->rtm_src_len;
@@ -258,6 +265,10 @@ static int FAST_FUNC print_route(const struct sockaddr_nl *who UNUSED_PARAM,
258 if (tb[RTA_OIF]) { 265 if (tb[RTA_OIF]) {
259 printf("dev %s ", ll_index_to_name(*(int*)RTA_DATA(tb[RTA_OIF]))); 266 printf("dev %s ", ll_index_to_name(*(int*)RTA_DATA(tb[RTA_OIF])));
260 } 267 }
268#if ENABLE_FEATURE_IP_RULE
269 if (tid && tid != RT_TABLE_MAIN && !G_filter.tb)
270 printf("table %s ", rtnl_rttable_n2a(tid));
271#endif
261 272
262 /* Todo: parse & show "proto kernel", "scope link" here */ 273 /* Todo: parse & show "proto kernel", "scope link" here */
263 274
@@ -419,7 +430,12 @@ IF_FEATURE_IP_RULE(ARG_table,)
419 NEXT_ARG(); 430 NEXT_ARG();
420 if (rtnl_rttable_a2n(&tid, *argv)) 431 if (rtnl_rttable_a2n(&tid, *argv))
421 invarg_1_to_2(*argv, "table"); 432 invarg_1_to_2(*argv, "table");
422 req.r.rtm_table = tid; 433 if (tid < 256)
434 req.r.rtm_table = tid;
435 else {
436 req.r.rtm_table = RT_TABLE_UNSPEC;
437 addattr32(&req.n, sizeof(req), RTA_TABLE, tid);
438 }
423#endif 439#endif
424 } else if (arg == ARG_dev || arg == ARG_oif) { 440 } else if (arg == ARG_dev || arg == ARG_oif) {
425 NEXT_ARG(); 441 NEXT_ARG();
diff --git a/networking/libiproute/iprule.c b/networking/libiproute/iprule.c
index c486834b0..8f3f86286 100644
--- a/networking/libiproute/iprule.c
+++ b/networking/libiproute/iprule.c
@@ -114,7 +114,9 @@ static int FAST_FUNC print_rule(const struct sockaddr_nl *who UNUSED_PARAM,
114 printf("iif %s ", (char*)RTA_DATA(tb[RTA_IIF])); 114 printf("iif %s ", (char*)RTA_DATA(tb[RTA_IIF]));
115 } 115 }
116 116
117 if (r->rtm_table) 117 if (tb[RTA_TABLE])
118 printf("lookup %s ", rtnl_rttable_n2a(*(uint32_t*)RTA_DATA(tb[RTA_TABLE])));
119 else if (r->rtm_table)
118 printf("lookup %s ", rtnl_rttable_n2a(r->rtm_table)); 120 printf("lookup %s ", rtnl_rttable_n2a(r->rtm_table));
119 121
120 if (tb[RTA_FLOW]) { 122 if (tb[RTA_FLOW]) {
@@ -256,7 +258,12 @@ static int iprule_modify(int cmd, char **argv)
256 NEXT_ARG(); 258 NEXT_ARG();
257 if (rtnl_rttable_a2n(&tid, *argv)) 259 if (rtnl_rttable_a2n(&tid, *argv))
258 invarg_1_to_2(*argv, "table ID"); 260 invarg_1_to_2(*argv, "table ID");
259 req.r.rtm_table = tid; 261 if (tid < 256)
262 req.r.rtm_table = tid;
263 else {
264 req.r.rtm_table = RT_TABLE_UNSPEC;
265 addattr32(&req.n, sizeof(req), RTA_TABLE, tid);
266 }
260 table_ok = 1; 267 table_ok = 1;
261 } else if (key == ARG_dev || 268 } else if (key == ARG_dev ||
262 key == ARG_iif 269 key == ARG_iif