aboutsummaryrefslogtreecommitdiffstats
path: root/main/busybox/0001-iproute-ensure-scope-is-correctly-initialised.patch
blob: 95c01a3f8dc8c033716d29ef27bdb4136ac4584c (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
From b64e50214e1af64a94bd73f4e70da2a1a7659c75 Mon Sep 17 00:00:00 2001
From: Ron Yorston <rmy@pobox.com>
Date: Fri, 5 Aug 2016 19:39:31 +0100
Subject: [PATCH] iproute: ensure scope is correctly initialised

Code in iproute.c attempted to avoid assigning values to structure
elements which were know to be zero unless the value to be assigned
was non-zero.

Commit ce4bc1ed added some more such cases.  However, the treatment
of req.r.rtm_scope was incorrect.  Although this saved a few bytes it
resulted in incorrect behaviour like:

   $ sudo busybox ip route add 192.168.0.0/24 via 10.98.106.9 dev wlan0
   ip: RTNETLINK answers: Invalid argument

In practice this attempt at optimisation results in no saving, so
remove it.

Reported-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Ron Yorston <rmy@pobox.com>
---
 networking/libiproute/iproute.c | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)

diff --git a/networking/libiproute/iproute.c b/networking/libiproute/iproute.c
index e674e9a..8db9aef 100644
--- a/networking/libiproute/iproute.c
+++ b/networking/libiproute/iproute.c
@@ -356,18 +356,13 @@ IF_FEATURE_IP_RULE(ARG_table,)
 	req.n.nlmsg_flags = NLM_F_REQUEST | flags;
 	req.n.nlmsg_type = cmd;
 	req.r.rtm_family = preferred_family;
-	if (RT_TABLE_MAIN != 0) /* if it is zero, memset already did it */
-		req.r.rtm_table = RT_TABLE_MAIN;
-	if (RT_SCOPE_NOWHERE != 0)
-		req.r.rtm_scope = RT_SCOPE_NOWHERE;
+	req.r.rtm_table = RT_TABLE_MAIN;
+	req.r.rtm_scope = RT_SCOPE_NOWHERE;
 
 	if (cmd != RTM_DELROUTE) {
-		if (RTPROT_BOOT != 0)
-			req.r.rtm_protocol = RTPROT_BOOT;
-		if (RT_SCOPE_UNIVERSE != 0)
-			req.r.rtm_scope = RT_SCOPE_UNIVERSE;
-		if (RTN_UNICAST != 0)
-			req.r.rtm_type = RTN_UNICAST;
+		req.r.rtm_protocol = RTPROT_BOOT;
+		req.r.rtm_scope = RT_SCOPE_UNIVERSE;
+		req.r.rtm_type = RTN_UNICAST;
 	}
 
 	mxrta->rta_type = RTA_METRICS;
-- 
2.9.1