[OpenWrt-Devel] [PATCH] netifd v2: Fix source routing for IPv4

Kristian Evensen kristian.evensen at gmail.com
Wed Nov 26 06:16:05 EST 2014


From: Kristian Evensen <kristian.evensen at gmail.com>

According to the OpenWRT Network documentation for route, the 'source' option is
"The preferred source address when sending to destinations covered by the
target". However, netifd currently stores this value in RTA_SRC on
NEWROUTE/DELROUTE.

RTA_SRC is not used by kernel when handling NEWROUTE nor DELROUTE for IPv4
routes. When adding a new IPv4 route, the source is stored in RTA_PREFSRC and
the option works as specified in documentation. For IPv6, the address is still
stored in RTA_SRC as to not break source-destination routing for IPv6.

v2: Limit patch to IPv4, to prevent breaking IPv6 configurations (thanks Steven
Barth)

Signed-off-by: Kristian Evensen <kristian.evensen at gmail.com>
---
 system-linux.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/system-linux.c b/system-linux.c
index 8518f0f..ed69bef 100644
--- a/system-linux.c
+++ b/system-linux.c
@@ -1433,8 +1433,12 @@ static int system_rt(struct device *dev, struct device_route *route, int cmd)
 	if (route->mask)
 		nla_put(msg, RTA_DST, alen, &route->addr);
 
-	if (route->sourcemask)
-		nla_put(msg, RTA_SRC, alen, &route->source);
+	if (route->sourcemask) {
+		if (rtm.rtm_family == AF_INET)
+			nla_put(msg, RTA_PREFSRC, alen, &route->source);
+		else
+			nla_put(msg, RTA_SRC, alen, &route->source);
+	}
 
 	if (route->metric > 0)
 		nla_put_u32(msg, RTA_PRIORITY, route->metric);
-- 
1.8.3.2
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel



More information about the openwrt-devel mailing list