aboutsummaryrefslogtreecommitdiffstats
path: root/meta/recipes-core/busybox/busybox/0001-libiproute-handle-table-ids-larger-than-255.patch
blob: f05c316ef690f140827a4b76f2e4a7372a4a6547 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
Subject: [PATCH v2] 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.

Upstream-Status: Submitted [http://lists.busybox.net/pipermail/busybox/2016-December/084989.html]

Signed-off-by: Lukasz Nowak <lnowak@tycoint.com>
---
 networking/libiproute/iproute.c | 27 +++++++++++++++++++++------
 networking/libiproute/iprule.c  | 11 +++++++++--
 2 files changed, 30 insertions(+), 8 deletions(-)

diff --git a/networking/libiproute/iproute.c b/networking/libiproute/iproute.c
index 48dc6e3..bdd17da 100644
--- a/networking/libiproute/iproute.c
+++ b/networking/libiproute/iproute.c
@@ -66,7 +66,8 @@ static int FAST_FUNC print_route(const struct sockaddr_nl *who UNUSED_PARAM,
 	inet_prefix dst;
 	inet_prefix src;
 	int host_len = -1;
-
+	uint32_t tid;
+	
 	if (n->nlmsg_type != RTM_NEWROUTE && n->nlmsg_type != RTM_DELROUTE) {
 		fprintf(stderr, "Not a route: %08x %08x %08x\n",
 			n->nlmsg_len, n->nlmsg_type, n->nlmsg_flags);
@@ -78,6 +79,14 @@ static int FAST_FUNC print_route(const struct sockaddr_nl *who UNUSED_PARAM,
 	if (len < 0)
 		bb_error_msg_and_die("wrong nlmsg len %d", len);
 
+	memset(tb, 0, sizeof(tb));
+	parse_rtattr(tb, RTA_MAX, RTM_RTA(r), len);
+
+	if (tb[RTA_TABLE])
+		tid = *(uint32_t *)RTA_DATA(tb[RTA_TABLE]);
+	else
+		tid = r->rtm_table;
+
 	if (r->rtm_family == AF_INET6)
 		host_len = 128;
 	else if (r->rtm_family == AF_INET)
@@ -107,7 +116,7 @@ static int FAST_FUNC print_route(const struct sockaddr_nl *who UNUSED_PARAM,
 			}
 		}
 	} else {
-		if (G_filter.tb > 0 && G_filter.tb != r->rtm_table) {
+		if (G_filter.tb > 0 && G_filter.tb != tid) {
 			return 0;
 		}
 	}
@@ -136,10 +145,8 @@ static int FAST_FUNC print_route(const struct sockaddr_nl *who UNUSED_PARAM,
 		return 0;
 	}
 
-	memset(tb, 0, sizeof(tb));
 	memset(&src, 0, sizeof(src));
 	memset(&dst, 0, sizeof(dst));
-	parse_rtattr(tb, RTA_MAX, RTM_RTA(r), len);
 
 	if (tb[RTA_SRC]) {
 		src.bitlen = r->rtm_src_len;
@@ -258,7 +265,10 @@ static int FAST_FUNC print_route(const struct sockaddr_nl *who UNUSED_PARAM,
 	if (tb[RTA_OIF]) {
 		printf("dev %s ", ll_index_to_name(*(int*)RTA_DATA(tb[RTA_OIF])));
 	}
-
+#if ENABLE_FEATURE_IP_RULE
+	if (tid && tid != RT_TABLE_MAIN && !G_filter.tb)
+		printf("table %s ", rtnl_rttable_n2a(tid));
+#endif
 	/* Todo: parse & show "proto kernel", "scope link" here */
 
 	if (tb[RTA_PREFSRC] && /*G_filter.rprefsrc.bitlen - always 0*/ 0 != host_len) {
@@ -419,7 +429,12 @@ IF_FEATURE_IP_RULE(ARG_table,)
 			NEXT_ARG();
 			if (rtnl_rttable_a2n(&tid, *argv))
 				invarg_1_to_2(*argv, "table");
-			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);
+			}
 #endif
 		} else if (arg == ARG_dev || arg == ARG_oif) {
 			NEXT_ARG();
diff --git a/networking/libiproute/iprule.c b/networking/libiproute/iprule.c
index dba6434..6836ff7 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,
 		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]) {
@@ -254,7 +256,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
-- 
2.1.0