[PATCH 4/4] icmp6: Respect the on-link bit in RA prefixes

Andrew Zaborowski <andrew.zaborowski at intel.com>
Newsgroups dev.linux.lists.ell
Message-ID <[email protected]>
When the on-link bit is not 1 in a prefix option, the packets addressed
to that prefix should go through the router who sent the RA.
---
 ell/icmp6-private.h | 1 +
 ell/icmp6.c         | 9 +++++++--
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/ell/icmp6-private.h b/ell/icmp6-private.h
index 3846bad..38d640f 100644
--- a/ell/icmp6-private.h
+++ b/ell/icmp6-private.h
@@ -23,6 +23,7 @@
 struct route_info {
 	uint8_t address[16];
 	uint8_t prefix_len;
+	bool onlink : 1;
 	uint8_t preference;
 	uint32_t preferred_lifetime;
 	uint32_t valid_lifetime;
diff --git a/ell/icmp6.c b/ell/icmp6.c
index 93c1701..197aa4a 100644
--- a/ell/icmp6.c
+++ b/ell/icmp6.c
@@ -285,11 +285,11 @@ static void icmp6_client_setup_routes(struct l_icmp6_client *client)
 {
 	struct l_icmp6_router *ra = client->ra;
 	struct l_rtnl_route *rt;
-	char buf[INET6_ADDRSTRLEN];
+	char gw_buf[INET6_ADDRSTRLEN];
 	unsigned int i;
 
 	rt = l_rtnl_route_new_gateway(inet_ntop(AF_INET6, ra->address,
-							buf, sizeof(buf)));
+						gw_buf, sizeof(gw_buf)));
 	if (!rt) {
 		CLIENT_DEBUG("Unable to parse RA 'from' address");
 		return;
@@ -308,6 +308,7 @@ static void icmp6_client_setup_routes(struct l_icmp6_client *client)
 
 	for (i = 0; i < ra->n_prefixes; i++) {
 		struct route_info *info = &ra->prefixes[i];
+		char buf[INET6_ADDRSTRLEN];
 
 		if (info->valid_lifetime == 0)
 			continue;
@@ -319,6 +320,9 @@ static void icmp6_client_setup_routes(struct l_icmp6_client *client)
 		if (!rt)
 			continue;
 
+		if (!info->onlink)
+			l_rtnl_route_set_gateway(rt, gw_buf);
+
 		l_rtnl_route_set_preference(rt, info->preference);
 		l_rtnl_route_set_protocol(rt, RTPROT_RA);
 		l_rtnl_route_set_mtu(rt, ra->mtu);
@@ -729,6 +733,7 @@ struct l_icmp6_router *_icmp6_router_parse(const struct nd_router_advert *ra,
 				break;
 
 			i->prefix_len = opts[2];
+			i->onlink = opts[3] & 1;
 			i->valid_lifetime = l_get_be32(opts + 4);
 			i->preferred_lifetime = l_get_be32(opts + 8);
 			memcpy(i->address, opts + 16, 16);
-- 
2.32.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.