[OpenWrt-Devel] [PATCH netifd] interface: set subnet route source when using metric

Philip Craig philipjcraig at gmail.com
Sun Jul 6 21:54:44 EDT 2014


If an interface has a metric set, then netifd deletes the automatic kernel
route for the interface subnet, and adds it back with the metric set.
However, the newly added route didn't have the preferred source set.

Signed-off-by: Philip Craig <philipjcraig at gmail.com>
---
 interface-ip.c |  1 +
 interface-ip.h |  1 +
 system-linux.c | 13 +++++++++++++
 3 files changed, 15 insertions(+)

diff --git a/interface-ip.c b/interface-ip.c
index 587826a..5f8c403 100644
--- a/interface-ip.c
+++ b/interface-ip.c
@@ -456,6 +456,7 @@ interface_handle_subnet_route(struct interface *iface, struct device_addr *addr,
 		if (!(addr->flags & DEVADDR_OFFLINK)) {
 			route.flags &= ~DEVADDR_KERNEL;
 			route.metric = iface->metric;
+			memcpy(&route.prefsrc, &addr->addr, sizeof(route.addr));
 			system_add_route(dev, &route);
 		}
 	} else {
diff --git a/interface-ip.h b/interface-ip.h
index a5612e5..e3eae97 100644
--- a/interface-ip.h
+++ b/interface-ip.h
@@ -121,6 +121,7 @@ struct device_route {
 	unsigned int sourcemask;
 	union if_addr addr;
 	union if_addr source;
+	union if_addr prefsrc;
 };
 
 struct device_source_table {
diff --git a/system-linux.c b/system-linux.c
index 5c960b4..09edefa 100644
--- a/system-linux.c
+++ b/system-linux.c
@@ -1307,6 +1307,7 @@ static int system_rt(struct device *dev, struct device_route *route, int cmd)
 {
 	int alen = ((route->flags & DEVADDR_FAMILY) == DEVADDR_INET4) ? 4 : 16;
 	bool have_gw;
+	bool have_prefsrc;
 	unsigned int flags = 0;
 
 	if (alen == 4)
@@ -1317,6 +1318,15 @@ static int system_rt(struct device *dev, struct device_route *route, int cmd)
 			route->nexthop.in6.s6_addr32[2] ||
 			route->nexthop.in6.s6_addr32[3];
 
+	if (alen == 4)
+		have_prefsrc = !!route->prefsrc.in.s_addr;
+	else
+		have_prefsrc = route->prefsrc.in6.s6_addr32[0] ||
+			route->prefsrc.in6.s6_addr32[1] ||
+			route->prefsrc.in6.s6_addr32[2] ||
+			route->prefsrc.in6.s6_addr32[3];
+
+
 	unsigned int table = (route->flags & (DEVROUTE_TABLE | DEVROUTE_SRCTABLE))
 			? route->table : RT_TABLE_MAIN;
 
@@ -1376,6 +1386,9 @@ static int system_rt(struct device *dev, struct device_route *route, int cmd)
 	if (have_gw)
 		nla_put(msg, RTA_GATEWAY, alen, &route->nexthop);
 
+	if (have_prefsrc)
+		nla_put(msg, RTA_PREFSRC, alen, &route->prefsrc);
+
 	if (dev)
 		nla_put_u32(msg, RTA_OIF, dev->ifindex);
 
-- 
1.9.1
_______________________________________________
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