blob: 66bc76e65ebb3267f96b69652e3e1ce50b70b731 [file] [log] [blame]
Brad Bishop6e60e8b2018-02-01 10:27:11 -05001From ce4bc1ed048233e89ee4cb95830bf6f01d523d1e Mon Sep 17 00:00:00 2001
2From: Denys Vlasenko <vda.linux@googlemail.com>
3Date: Wed, 30 Dec 2015 17:32:51 +0100
4Subject: [PATCH] iproute: support "scope". Closes 8561
5
6function old new delta
7iproute_modify 1051 1120 +69
8
9Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
10
11Upstream-Status: Backport
12Modified patch to build against busybox 1.24.1:
13- s/invarg_1_to_2/invarg
14Signed-off-by: André Draszik <adraszik@tycoint.com>
15---
16 networking/libiproute/iproute.c | 52 ++++++++++++++++++++++++++---------------
17 1 file changed, 33 insertions(+), 19 deletions(-)
18
19diff --git a/networking/libiproute/iproute.c b/networking/libiproute/iproute.c
20index d232ee6fd..82827488f 100644
21--- a/networking/libiproute/iproute.c
22+++ b/networking/libiproute/iproute.c
23@@ -313,12 +313,13 @@ static int FAST_FUNC print_route(const struct sockaddr_nl *who UNUSED_PARAM,
24 static int iproute_modify(int cmd, unsigned flags, char **argv)
25 {
26 static const char keywords[] ALIGN1 =
27- "src\0""via\0""mtu\0""lock\0""protocol\0"IF_FEATURE_IP_RULE("table\0")
28+ "src\0""via\0""mtu\0""lock\0""scope\0""protocol\0"IF_FEATURE_IP_RULE("table\0")
29 "dev\0""oif\0""to\0""metric\0""onlink\0";
30 enum {
31 ARG_src,
32 ARG_via,
33 ARG_mtu, PARM_lock,
34+ ARG_scope,
35 ARG_protocol,
36 IF_FEATURE_IP_RULE(ARG_table,)
37 ARG_dev,
38@@ -344,6 +345,7 @@ IF_FEATURE_IP_RULE(ARG_table,)
39 unsigned mxlock = 0;
40 char *d = NULL;
41 smalluint ok = 0;
42+ smalluint scope_ok = 0;
43 int arg;
44
45 memset(&req, 0, sizeof(req));
46@@ -352,15 +354,18 @@ IF_FEATURE_IP_RULE(ARG_table,)
47 req.n.nlmsg_flags = NLM_F_REQUEST | flags;
48 req.n.nlmsg_type = cmd;
49 req.r.rtm_family = preferred_family;
50- if (RT_TABLE_MAIN) /* if it is zero, memset already did it */
51+ if (RT_TABLE_MAIN != 0) /* if it is zero, memset already did it */
52 req.r.rtm_table = RT_TABLE_MAIN;
53- if (RT_SCOPE_NOWHERE)
54+ if (RT_SCOPE_NOWHERE != 0)
55 req.r.rtm_scope = RT_SCOPE_NOWHERE;
56
57 if (cmd != RTM_DELROUTE) {
58- req.r.rtm_protocol = RTPROT_BOOT;
59- req.r.rtm_scope = RT_SCOPE_UNIVERSE;
60- req.r.rtm_type = RTN_UNICAST;
61+ if (RTPROT_BOOT != 0)
62+ req.r.rtm_protocol = RTPROT_BOOT;
63+ if (RT_SCOPE_UNIVERSE != 0)
64+ req.r.rtm_scope = RT_SCOPE_UNIVERSE;
65+ if (RTN_UNICAST != 0)
66+ req.r.rtm_type = RTN_UNICAST;
67 }
68
69 mxrta->rta_type = RTA_METRICS;
70@@ -393,6 +398,13 @@ IF_FEATURE_IP_RULE(ARG_table,)
71 }
72 mtu = get_unsigned(*argv, "mtu");
73 rta_addattr32(mxrta, sizeof(mxbuf), RTAX_MTU, mtu);
74+ } else if (arg == ARG_scope) {
75+ uint32_t scope;
76+ NEXT_ARG();
77+ if (rtnl_rtscope_a2n(&scope, *argv))
78+ invarg(*argv, "scope");
79+ req.r.rtm_scope = scope;
80+ scope_ok = 1;
81 } else if (arg == ARG_protocol) {
82 uint32_t prot;
83 NEXT_ARG();
84@@ -469,20 +481,22 @@ IF_FEATURE_IP_RULE(ARG_table,)
85 addattr_l(&req.n, sizeof(req), RTA_METRICS, RTA_DATA(mxrta), RTA_PAYLOAD(mxrta));
86 }
87
88- if (req.r.rtm_type == RTN_LOCAL || req.r.rtm_type == RTN_NAT)
89- req.r.rtm_scope = RT_SCOPE_HOST;
90- else
91- if (req.r.rtm_type == RTN_BROADCAST
92- || req.r.rtm_type == RTN_MULTICAST
93- || req.r.rtm_type == RTN_ANYCAST
94- ) {
95- req.r.rtm_scope = RT_SCOPE_LINK;
96- }
97- else if (req.r.rtm_type == RTN_UNICAST || req.r.rtm_type == RTN_UNSPEC) {
98- if (cmd == RTM_DELROUTE)
99- req.r.rtm_scope = RT_SCOPE_NOWHERE;
100- else if (!(ok & gw_ok))
101+ if (!scope_ok) {
102+ if (req.r.rtm_type == RTN_LOCAL || req.r.rtm_type == RTN_NAT)
103+ req.r.rtm_scope = RT_SCOPE_HOST;
104+ else
105+ if (req.r.rtm_type == RTN_BROADCAST
106+ || req.r.rtm_type == RTN_MULTICAST
107+ || req.r.rtm_type == RTN_ANYCAST
108+ ) {
109 req.r.rtm_scope = RT_SCOPE_LINK;
110+ }
111+ else if (req.r.rtm_type == RTN_UNICAST || req.r.rtm_type == RTN_UNSPEC) {
112+ if (cmd == RTM_DELROUTE)
113+ req.r.rtm_scope = RT_SCOPE_NOWHERE;
114+ else if (!(ok & gw_ok))
115+ req.r.rtm_scope = RT_SCOPE_LINK;
116+ }
117 }
118
119 if (req.r.rtm_family == AF_UNSPEC) {
120--
1212.11.0
122