Skip to contentSkip to conversation

netconfig: Add missing NULL check for routes from RA

PATCH In review Andrew Zaborowski 2 participants 16 messages May 20, 2022

lore
Share & tools
lore

Andrew Zaborowski

author
#0 lore raw

PATCH 1/15 netconfig: Add missing NULL check for routes from RA

Fixes 7a137bcac31e ("netconfig: Create routes from Router Advertisements")
---
 ell/netconfig.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
ell/netconfig.c +3 -2
index f39f88f..8026c81 100644
@@ -573,8 +573,9 @@ static struct l_rtnl_route *netconfig_add_icmp6_route(struct l_netconfig *nc,
 {
 	struct l_rtnl_route *rt;
 
-	rt = netconfig_route_new(nc, AF_INET6, dst->address, dst->prefix_len,
-					gateway, RTPROT_RA);
+	rt = netconfig_route_new(nc, AF_INET6, dst ? dst->address : NULL,
+					dst ? dst->prefix_len : 0, gateway,
+					RTPROT_RA);
 	if (L_WARN_ON(!rt))
 		return NULL;
 
Signature · 1 line
2.32.0
author
#1 lore raw

PATCH 2/15 netconfig: Avoid returning internal l_queues

Return const struct l_queue_entry pointers instead.

---
 ell/netconfig.c | 35 ++++++++++++++++++-----------------
 ell/netconfig.h | 20 +++++++++++---------
 2 files changed, 29 insertions(+), 26 deletions(-)
ell/netconfig.c +18 -17
index 8026c81..2a1b3ed 100644
@@ -1249,37 +1249,38 @@ LIB_EXPORT void l_netconfig_apply_rtnl(struct l_netconfig *netconfig,
 					NULL, NULL, NULL);
 }
 
-LIB_EXPORT struct l_queue *l_netconfig_get_addresses(
-						struct l_netconfig *netconfig,
-						struct l_queue **out_added,
-						struct l_queue **out_updated,
-						struct l_queue **out_removed)
+LIB_EXPORT const struct l_queue_entry *l_netconfig_get_addresses(
+					struct l_netconfig *netconfig,
+					const struct l_queue_entry **out_added,
+					const struct l_queue_entry **out_updated,
+					const struct l_queue_entry **out_removed)
 {
 	if (out_added)
-		*out_added = netconfig->addresses.added;
+		*out_added = l_queue_get_entries(netconfig->addresses.added);
 
 	if (out_updated)
-		*out_updated = netconfig->addresses.updated;
+		*out_updated = l_queue_get_entries(netconfig->addresses.updated);
 
 	if (out_removed)
-		*out_removed = netconfig->addresses.removed;
+		*out_removed = l_queue_get_entries(netconfig->addresses.removed);
 
-	return netconfig->addresses.current;
+	return l_queue_get_entries(netconfig->addresses.current);
 }
 
-LIB_EXPORT struct l_queue *l_netconfig_get_routes(struct l_netconfig *netconfig,
-						struct l_queue **out_added,
-						struct l_queue **out_updated,
-						struct l_queue **out_removed)
+LIB_EXPORT const struct l_queue_entry *l_netconfig_get_routes(
+					struct l_netconfig *netconfig,
+					const struct l_queue_entry **out_added,
+					const struct l_queue_entry **out_updated,
+					const struct l_queue_entry **out_removed)
 {
 	if (out_added)
-		*out_added = netconfig->routes.added;
+		*out_added = l_queue_get_entries(netconfig->routes.added);
 
 	if (out_updated)
-		*out_updated = netconfig->routes.updated;
+		*out_updated = l_queue_get_entries(netconfig->routes.updated);
 
 	if (out_removed)
-		*out_removed = netconfig->routes.removed;
+		*out_removed = l_queue_get_entries(netconfig->routes.removed);
 
-	return netconfig->routes.current;
+	return l_queue_get_entries(netconfig->routes.current);
 }
ell/netconfig.h +11 -9
index a50a895..7796a2f 100644
@@ -33,7 +33,7 @@ struct l_dhcp_client;
 struct l_dhcp6_client;
 struct l_icmp6_client;
 struct l_netlink;
-struct l_queue;
+struct l_queue_entry;
 struct l_netconfig;
 struct l_rtnl_address;
 struct l_rtnl_route;
@@ -87,14 +87,16 @@ void l_netconfig_set_event_handler(struct l_netconfig *netconfig,
 
 void l_netconfig_apply_rtnl(struct l_netconfig *netconfig,
 				struct l_netlink *rtnl);
-struct l_queue *l_netconfig_get_addresses(struct l_netconfig *netconfig,
-					struct l_queue **out_added,
-					struct l_queue **out_updated,
-					struct l_queue **out_removed);
-struct l_queue *l_netconfig_get_routes(struct l_netconfig *netconfig,
-					struct l_queue **out_added,
-					struct l_queue **out_updated,
-					struct l_queue **out_removed);
+const struct l_queue_entry *l_netconfig_get_addresses(
+				struct l_netconfig *netconfig,
+				const struct l_queue_entry **out_added,
+				const struct l_queue_entry **out_updated,
+				const struct l_queue_entry **out_removed);
+const struct l_queue_entry *l_netconfig_get_routes(
+				struct l_netconfig *netconfig,
+				const struct l_queue_entry **out_added,
+				const struct l_queue_entry **out_updated,
+				const struct l_queue_entry **out_removed);
 
 #ifdef __cplusplus
 }
Signature · 1 line
2.32.0
author
#2 lore raw

PATCH 3/15 examples: Update netconfig method calls

In reply to Andrew Zaborowski
---
 examples/netconfig-test.c | 29 ++++++++++++++---------------
 1 file changed, 14 insertions(+), 15 deletions(-)
examples/netconfig-test.c +14 -15
index d75e4ad..aba63f9 100644
@@ -61,16 +61,14 @@ static void signal_handler(uint32_t signo, void *user_data)
 }
 
 static void log_addresses(const char *af_str, const char *action,
-				struct l_queue *list)
+				const struct l_queue_entry *entry)
 {
-	const struct l_queue_entry *entry;
-
-	if (l_queue_isempty(list))
+	if (!entry)
 		return;
 
 	l_info("[netconfig%s] Addresses %s:", af_str, action);
 
-	for (entry = l_queue_get_entries(list); entry; entry = entry->next) {
+	for (; entry; entry = entry->next) {
 		struct l_rtnl_address *addr = entry->data;
 		char ip_str[INET6_ADDRSTRLEN];
 
@@ -83,25 +81,26 @@ static void log_addresses(const char *af_str, const char *action,
 }
 
 static void log_routes(const char *af_str, const char *action,
-			struct l_queue *list)
+			const struct l_queue_entry *entry)
 {
-	const struct l_queue_entry *entry;
-
-	if (l_queue_isempty(list))
+	if (!entry)
 		return;
 
 	l_info("[netconfig%s] Routes %s:", af_str, action);
 
-	for (entry = l_queue_get_entries(list); entry; entry = entry->next) {
+	for (; entry; entry = entry->next) {
 		struct l_rtnl_route *rt = entry->data;
-		char subnet_str[INET6_ADDRSTRLEN];
+		char subnet_str[INET6_ADDRSTRLEN] = "unknown";
 		char gateway_str[INET6_ADDRSTRLEN];
 		uint8_t prefix_len;
+		bool onlink;
 
 		l_rtnl_route_get_dst(rt, subnet_str, &prefix_len);
-		l_rtnl_route_get_gateway(rt, gateway_str);
-		l_info("[netconfig%s] \t%s/%i, gateway %s, orig lifetime %i s",
-			af_str, subnet_str, prefix_len, gateway_str,
+		onlink = !l_rtnl_route_get_gateway(rt, gateway_str);
+		l_info("[netconfig%s] \t%s/%i, %s%s, orig lifetime %i s",
+			af_str, subnet_str, prefix_len,
+			onlink ? "onlink" : "next-hop ",
+			onlink ? "" : gateway_str,
 			l_rtnl_route_get_lifetime(rt));
 	}
 }
@@ -110,7 +109,7 @@ static void event_handler(struct l_netconfig *netconfig, uint8_t family,
 				enum l_netconfig_event event, void *user_data)
 {
 	const char *af_str = family == AF_INET ? "v4" : "v6";
-	struct l_queue *added, *updated, *removed;
+	const struct l_queue_entry *added, *updated, *removed;
 
 	switch (event) {
 	case L_NETCONFIG_EVENT_CONFIGURE:
Signature · 1 line
2.32.0
author
#3 lore raw

PATCH 4/15 rtnl: Keep one global RTNL connection

In reply to Andrew Zaborowski

To avoid keeping multiple RTNL sockets open, have a singleton l_netlink rtnl object managed by rtnl.c and available for anyone who needs it to request a reference.
---
In this version l_rtnl_get() and l_rtnl_put() take an optional rtnl pointer to save the reference to, but I'm happy to drop the parameter or use a different style API. The parameter allows the user to easily request the rtnl object lazily as in patch 5.

 ell/ell.sym |  2 ++
 ell/rtnl.c  | 41 +++++++++++++++++++++++++++++++++++++++++
 ell/rtnl.h  |  3 +++
 3 files changed, 46 insertions(+)
ell/ell.sym +2 -0
index 0f9f884..ea4d06c 100644
@@ -688,6 +688,8 @@ global:
 	l_rtnl_ifaddr_delete;
 	l_rtnl_neighbor_get_hwaddr;
 	l_rtnl_neighbor_set_hwaddr;
+	l_rtnl_get;
+	l_rtnl_put;
 	/* icmp6 */
 	l_icmp6_client_new;
 	l_icmp6_client_free;
ell/rtnl.c +41 -0

50 lines not on this page · raw message

ell/rtnl.h +3 -0
index 2617b1c..4409339 100644
@@ -226,6 +226,9 @@ uint32_t l_rtnl_neighbor_set_hwaddr(struct l_netlink *rtnl, int ifindex,
 					void *user_data,
 					l_netlink_destroy_func_t destroy);
 
+struct l_netlink *l_rtnl_get(struct l_netlink **ptr);
+void l_rtnl_put(struct l_netlink **ptr);
+
 #ifdef __cplusplus
 }
 #endif
Signature · 1 line
2.32.0
author
#4 lore raw

PATCH 5/15 netconfig: Use an internal rtnl socket for l_netconfig_apply_rtnl

In reply to Andrew Zaborowski

Since we'll need to keep an internal RTNL socket for DHCPv6 functionality anyway, change l_netconfig_apply_rtnl's signature to not require an rtnl parameter.

---
 ell/netconfig.c | 24 ++++++++++++++++--------
 ell/netconfig.h |  3 +--
 2 files changed, 17 insertions(+), 10 deletions(-)
ell/netconfig.c +16 -8
index 2a1b3ed..f1cbbb9 100644
@@ -64,6 +64,7 @@ struct l_netconfig {
 	char **v6_dns_override;
 	char **v6_domain_names_override;
 
+	struct l_netlink *rtnl;
 	bool started;
 	struct l_idle *do_static_work;
 	bool v4_configured;
@@ -1166,6 +1167,8 @@ LIB_EXPORT void l_netconfig_stop(struct l_netconfig *netconfig)
 
 	l_dhcp_client_stop(netconfig->dhcp_client);
 	l_dhcp6_client_stop(netconfig->dhcp6_client);
+
+	l_rtnl_put(&netconfig->rtnl);
 }
 
 LIB_EXPORT struct l_dhcp_client *l_netconfig_get_dhcp_client(
@@ -1211,41 +1214,46 @@ LIB_EXPORT void l_netconfig_set_event_handler(struct l_netconfig *netconfig,
 	netconfig->handler.destroy = destroy;
 }
 
-LIB_EXPORT void l_netconfig_apply_rtnl(struct l_netconfig *netconfig,
-					struct l_netlink *rtnl)
+LIB_EXPORT void l_netconfig_apply_rtnl(struct l_netconfig *netconfig)
 {
 	const struct l_queue_entry *entry;
 
 	for (entry = l_queue_get_entries(netconfig->addresses.removed); entry;
 			entry = entry->next)
-		l_rtnl_ifaddr_delete(rtnl, netconfig->ifindex, entry->data,
+		l_rtnl_ifaddr_delete(l_rtnl_get(&netconfig->rtnl),
+					netconfig->ifindex, entry->data,
 					NULL, NULL, NULL);
 
 	for (entry = l_queue_get_entries(netconfig->addresses.added); entry;
 			entry = entry->next)
-		l_rtnl_ifaddr_add(rtnl, netconfig->ifindex, entry->data,
+		l_rtnl_ifaddr_add(l_rtnl_get(&netconfig->rtnl),
+					netconfig->ifindex, entry->data,
 					NULL, NULL, NULL);
 
 	/* We can use l_rtnl_ifaddr_add here since that uses NLM_F_REPLACE */
 	for (entry = l_queue_get_entries(netconfig->addresses.updated); entry;
 			entry = entry->next)
-		l_rtnl_ifaddr_add(rtnl, netconfig->ifindex, entry->data,
+		l_rtnl_ifaddr_add(l_rtnl_get(&netconfig->rtnl),
+					netconfig->ifindex, entry->data,
 					NULL, NULL, NULL);
 
 	for (entry = l_queue_get_entries(netconfig->routes.removed); entry;
 			entry = entry->next)
-		l_rtnl_route_delete(rtnl, netconfig->ifindex, entry->data,
+		l_rtnl_route_delete(l_rtnl_get(&netconfig->rtnl),
+					netconfig->ifindex, entry->data,
 					NULL, NULL, NULL);
 
 	for (entry = l_queue_get_entries(netconfig->routes.added); entry;
 			entry = entry->next)
-		l_rtnl_route_add(rtnl, netconfig->ifindex, entry->data,
+		l_rtnl_route_add(l_rtnl_get(&netconfig->rtnl),
+					netconfig->ifindex, entry->data,
 					NULL, NULL, NULL);
 
 	/* We can use l_rtnl_route_add here since that uses NLM_F_REPLACE */
 	for (entry = l_queue_get_entries(netconfig->routes.updated); entry;
 			entry = entry->next)
-		l_rtnl_route_add(rtnl, netconfig->ifindex, entry->data,
+		l_rtnl_route_add(l_rtnl_get(&netconfig->rtnl),
+					netconfig->ifindex, entry->data,
 					NULL, NULL, NULL);
 }
 
ell/netconfig.h +1 -2
index 7796a2f..fddbac1 100644
@@ -85,8 +85,7 @@ void l_netconfig_set_event_handler(struct l_netconfig *netconfig,
 					void *user_data,
 					l_netconfig_destroy_cb_t destroy);
 
-void l_netconfig_apply_rtnl(struct l_netconfig *netconfig,
-				struct l_netlink *rtnl);
+void l_netconfig_apply_rtnl(struct l_netconfig *netconfig);
 const struct l_queue_entry *l_netconfig_get_addresses(
 				struct l_netconfig *netconfig,
 				const struct l_queue_entry **out_added,
Signature · 1 line
2.32.0
author
#5 lore raw

PATCH 6/15 examples: Update netconfig method calls

In reply to Andrew Zaborowski
---
 examples/netconfig-test.c | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)
examples/netconfig-test.c +1 -12
index aba63f9..39b6fa4 100644
@@ -40,7 +40,6 @@
 #include <ell/ell.h>
 
 static bool apply;
-static struct l_netlink *rtnl;
 
 static void do_debug(const char *str, void *user_data)
 {
@@ -138,7 +137,7 @@ static void event_handler(struct l_netconfig *netconfig, uint8_t family,
 	log_routes(af_str, "removed", removed);
 
 	if (apply)
-		l_netconfig_apply_rtnl(netconfig, rtnl);
+		l_netconfig_apply_rtnl(netconfig);
 }
 
 static const struct option main_options[] = {
@@ -180,14 +179,6 @@ int main(int argc, char *argv[])
 	if (!l_main_init())
 		return EXIT_FAILURE;
 
-	if (apply) {
-		rtnl = l_netlink_new(NETLINK_ROUTE);
-		if (!rtnl) {
-			fprintf(stderr, "l_netlink_new(NETLINK_ROUTE) error\n");
-			return EXIT_FAILURE;
-		}
-	}
-
 	l_log_set_stderr();
 	l_debug_enable("*");
 
@@ -202,7 +193,5 @@ int main(int argc, char *argv[])
 	l_netconfig_destroy(netconfig);
 	l_main_exit();
 
-	l_netlink_destroy(rtnl);
-
 	return EXIT_SUCCESS;
 }
Signature · 1 line
2.32.0
author
#6 lore raw

PATCH 7/15 netconfig: Expire addresses and routes

In reply to Andrew Zaborowski

Start differentiating between routes/addresses being removed and those expiring. Generally if we're committing the routes through RTNL, the lifetimes are submitted to the kernel and the kernel should expire them for us on the kernel side. In that case there's no need to send an RTM_DELROUTE/RTM_DELADDR. That should apply to routes received in Router Advertisements as well as addresses and routes from expiring DHCP leases and DHCPv6 leases.

For routes/addresses being removed because a router is going offline and signals that by setting the lifetime to 0 in an RA, or as a result of L_DHCP_CLIENT_EVENT_IP_CHANGED and similar, us or the user do need to send RTM_DELROUTE/RTM_DELADDR. To differentiate between the two cases (removal and expiry) pass two separate lists to the user.

Add checks for expired IPv6 routes in the ICMPv6 event handler to avoid using timers for that. We have no bound on the number of routes (yet) so we avoid keeping potentially many timers or keeping one timer tracking multiple expiry times which would add a little complexity (but might be acceptable.)

---
 ell/netconfig.c | 166 ++++++++++++++++++++++++++++++++++++++++++------
 ell/netconfig.h |   6 +-
 2 files changed, 152 insertions(+), 20 deletions(-)
ell/netconfig.c +148 -18
index f1cbbb9..77af8c9 100644
@@ -72,6 +72,7 @@ struct l_netconfig {
 	bool v6_configured;
 	struct l_icmp6_client *icmp6_client;
 	struct l_dhcp6_client *dhcp6_client;
+	struct l_idle *signal_expired_work;
 
 	/* These objects, if not NULL, are owned by @addresses and @routes */
 	struct l_rtnl_address *v4_address;
@@ -92,10 +93,14 @@ struct l_netconfig {
 		 * for example those that only have their lifetime updated.
 		 *
 		 * Any entries in @added and @updated are owned by @current.
+		 * Entries in @removed need to be removed with an
+		 * RTM_DELADD/RTM_DELROUTE while those in @expired are only
+		 * informative as the kernel will have removed them already.
 		 */
 		struct l_queue *added;
 		struct l_queue *updated;
 		struct l_queue *removed;
+		struct l_queue *expired;
 	} addresses, routes;
 
 	struct {
@@ -116,10 +121,14 @@ static void netconfig_update_cleanup(struct l_netconfig *nc)
 	l_queue_clear(nc->addresses.updated, NULL);
 	l_queue_clear(nc->addresses.removed,
 			(l_queue_destroy_func_t) l_rtnl_address_free);
+	l_queue_clear(nc->addresses.expired,
+			(l_queue_destroy_func_t) l_rtnl_address_free);
 	l_queue_clear(nc->routes.added, NULL);
 	l_queue_clear(nc->routes.updated, NULL);
 	l_queue_clear(nc->routes.removed,
 			(l_queue_destroy_func_t) l_rtnl_route_free);
+	l_queue_clear(nc->routes.expired,
+			(l_queue_destroy_func_t) l_rtnl_route_free);
 }
 
 static void netconfig_emit_event(struct l_netconfig *nc, uint8_t family,
@@ -163,6 +172,24 @@ static struct l_rtnl_route *netconfig_route_new(struct l_netconfig *nc,
 	return rt;
 }
 
+static void netconfig_signal_expired(struct l_idle *idle, void *user_data)
+{
+	struct l_netconfig *nc = user_data;
+
+	l_idle_remove(l_steal_ptr(nc->signal_expired_work));
+
+	/*
+	 * If the idle work was scheduled from within l_netconfig_get_routes
+	 * or netconfig_icmp6_event_handler, the user is likely to have
+	 * already received an event and had a chance to process the expired
+	 * routes list.  In that case there's no need to emit a new event,
+	 * and the list will have been emptied in netconfig_update_cleanup()
+	 * anyway.
+	 */
+	if (!l_queue_isempty(nc->routes.expired))
+		netconfig_emit_event(nc, AF_INET6, L_NETCONFIG_EVENT_UPDATE);
+}
+
 static void netconfig_add_v4_routes(struct l_netconfig *nc, const char *ip,
 					uint8_t prefix_len, const char *gateway,
 					uint8_t rtm_protocol)
@@ -241,6 +268,19 @@ static void netconfig_add_v6_static_routes(struct l_netconfig *nc,
 	l_queue_push_tail(nc->routes.added, v6_default_route);
 }
 
+static bool netconfig_address_exists(struct l_queue *list,
+					const struct l_rtnl_address *address)
+{
+	const struct l_queue_entry *entry;
+
+	for (entry = l_queue_get_entries(list); entry;
+			entry = entry->next)
+		if ((const struct l_rtnl_address *) entry->data == address)
+			return true;
+
+	return false;
+}
+
 static bool netconfig_route_exists(struct l_queue *list,
 					const struct l_rtnl_route *route)
 {
@@ -297,13 +337,15 @@ static void netconfig_set_dhcp_lifetimes(struct l_netconfig *nc, bool updated)
 	l_rtnl_address_set_lifetimes(nc->v4_address, 0, lifetime);
 	l_rtnl_address_set_expiry(nc->v4_address, 0, expiry);
 
-	if (updated)
+	if (updated && !netconfig_address_exists(nc->addresses.added,
+							nc->v4_address))
 		l_queue_push_tail(nc->addresses.updated, nc->v4_address);
 
 	l_rtnl_route_set_lifetime(nc->v4_subnet_route, lifetime);
 	l_rtnl_route_set_expiry(nc->v4_subnet_route, expiry);
 
-	if (updated)
+	if (updated && !netconfig_route_exists(nc->routes.added,
+						nc->v4_subnet_route))
 		l_queue_push_tail(nc->routes.updated, nc->v4_subnet_route);
 
 	if (!nc->v4_default_route)
@@ -312,23 +354,42 @@ static void netconfig_set_dhcp_lifetimes(struct l_netconfig *nc, bool updated)
 	l_rtnl_route_set_lifetime(nc->v4_default_route, lifetime);
 	l_rtnl_route_set_expiry(nc->v4_default_route, expiry);
 
-	if (updated)
+	if (updated && !netconfig_route_exists(nc->routes.added,
+						nc->v4_default_route))
 		l_queue_push_tail(nc->routes.updated, nc->v4_default_route);
 }
 
-static void netconfig_remove_dhcp_address_routes(struct l_netconfig *nc)
+static void netconfig_remove_dhcp_address_routes(struct l_netconfig *nc,
+							bool expired)
 {
+	struct l_queue *routes =
+		expired ? nc->routes.expired : nc->routes.removed;
+
 	l_queue_remove(nc->addresses.current, nc->v4_address);
-	l_queue_push_tail(nc->addresses.removed, nc->v4_address);
+	l_queue_remove(nc->addresses.updated, nc->v4_address);
+
+	if (!l_queue_remove(nc->addresses.added, nc->v4_address))
+		l_queue_push_tail(
+			expired ? nc->addresses.expired : nc->addresses.removed,
+			nc->v4_address);
+
 	nc->v4_address = NULL;
 
 	l_queue_remove(nc->routes.current, nc->v4_subnet_route);
-	l_queue_push_tail(nc->routes.removed, nc->v4_subnet_route);
+	l_queue_remove(nc->routes.updated, nc->v4_subnet_route);
+
+	if (!l_queue_remove(nc->routes.added, nc->v4_subnet_route))
+		l_queue_push_tail(routes, nc->v4_subnet_route);
+
 	nc->v4_subnet_route = NULL;
 
 	if (nc->v4_default_route) {
 		l_queue_remove(nc->routes.current, nc->v4_default_route);
-		l_queue_push_tail(nc->routes.removed, nc->v4_default_route);
+		l_queue_remove(nc->routes.updated, nc->v4_default_route);
+
+		if (!l_queue_remove(nc->routes.added, nc->v4_default_route))
+			l_queue_push_tail(routes, nc->v4_default_route);
+
 		nc->v4_default_route = NULL;
 	}
 }
@@ -344,7 +405,7 @@ static void netconfig_dhcp_event_handler(struct l_dhcp_client *client,
 		if (L_WARN_ON(!nc->v4_configured))
 			break;
 
-		netconfig_remove_dhcp_address_routes(nc);
+		netconfig_remove_dhcp_address_routes(nc, false);
 		netconfig_add_dhcp_address_routes(nc);
 		netconfig_set_dhcp_lifetimes(nc, false);
 		netconfig_emit_event(nc, AF_INET, L_NETCONFIG_EVENT_UPDATE);
@@ -369,7 +430,7 @@ static void netconfig_dhcp_event_handler(struct l_dhcp_client *client,
 		if (L_WARN_ON(!nc->v4_configured))
 			break;
 
-		netconfig_remove_dhcp_address_routes(nc);
+		netconfig_remove_dhcp_address_routes(nc, true);
 		nc->v4_configured = false;
 
 		if (l_dhcp_client_start(nc->dhcp_client))
@@ -450,14 +511,21 @@ static void netconfig_set_dhcp6_address_lifetimes(struct l_netconfig *nc,
 					start_time + p * L_USEC_PER_SEC,
 					start_time + v * L_USEC_PER_SEC);
 
-	if (updated)
+	if (updated && !netconfig_address_exists(nc->addresses.added,
+							nc->v6_address))
 		l_queue_push_tail(nc->addresses.updated, nc->v6_address);
 }
 
-static void netconfig_remove_dhcp6_address(struct l_netconfig *nc)
+static void netconfig_remove_dhcp6_address(struct l_netconfig *nc, bool expired)
 {
 	l_queue_remove(nc->addresses.current, nc->v6_address);
-	l_queue_push_tail(nc->addresses.removed, nc->v6_address);
+	l_queue_remove(nc->addresses.updated, nc->v6_address);
+
+	if (!l_queue_remove(nc->addresses.added, nc->v6_address))
+		l_queue_push_tail(
+			expired ? nc->addresses.expired : nc->addresses.removed,
+			nc->v6_address);
+
 	nc->v6_address = NULL;
 }
 
@@ -481,7 +549,7 @@ static void netconfig_dhcp6_event_handler(struct l_dhcp6_client *client,
 		if (L_WARN_ON(!nc->v6_configured))
 			break;
 
-		netconfig_remove_dhcp6_address(nc);
+		netconfig_remove_dhcp6_address(nc, false);
 		netconfig_add_dhcp6_address(nc);
 		netconfig_set_dhcp6_address_lifetimes(nc, false);
 		netconfig_emit_event(nc, AF_INET6, L_NETCONFIG_EVENT_UPDATE);
@@ -490,7 +558,7 @@ static void netconfig_dhcp6_event_handler(struct l_dhcp6_client *client,
 		if (L_WARN_ON(!nc->v6_configured))
 			break;
 
-		netconfig_remove_dhcp6_address(nc);
+		netconfig_remove_dhcp6_address(nc, true);
 		nc->v6_configured = false;
 
 		if (l_dhcp6_client_start(nc->dhcp6_client))
@@ -529,6 +597,49 @@ static void netconfig_dhcp6_event_handler(struct l_dhcp6_client *client,
 	}
 }
 
+static uint64_t now;
+
+static bool netconfig_check_route_expired(void *data, void *user_data)
+{
+	struct l_netconfig *nc = user_data;
+	struct l_rtnl_route *route = data;
+	uint64_t expiry_time = l_rtnl_route_get_expiry(route);
+
+	if (!expiry_time || now < expiry_time)
+		return false;
+
+	/*
+	 * Since we set lifetimes on the routes we submit to the kernel with
+	 * RTM_NEWROUTE, we count on them being deleted automatically so no
+	 * need to send an RTM_DELROUTE.  We signal the fact that the route
+	 * expired to the user by having it on the expired list but there's
+	 * nothing that the user needs to do with the routes on that list
+	 * like they do with the added, updated and removed lists.
+	 *
+	 * If for some reason the route is still on the added list, drop it
+	 * from there and there's nothing to notify the user of.
+	 */
+	if (!l_queue_remove(nc->routes.added, route))
+		l_queue_push_tail(nc->routes.expired, route);
+
+	l_queue_remove(nc->routes.updated, route);
+	l_queue_remove(nc->routes.removed, route);
+	return true;
+}
+
+static void netconfig_expire_routes(struct l_netconfig *nc)
+{
+	now = l_time_now();
+
+	if (l_queue_foreach_remove(nc->routes.current,
+					netconfig_check_route_expired, nc) &&
+			!l_queue_isempty(nc->routes.expired) &&
+			!nc->signal_expired_work)
+		nc->signal_expired_work = l_idle_create(
+						netconfig_signal_expired,
+						nc, NULL);
+}
+
 static struct l_rtnl_route *netconfig_find_icmp6_route(
 						struct l_netconfig *nc,
 						const uint8_t *gateway,
@@ -635,7 +746,10 @@ static void netconfig_remove_icmp6_route(struct l_netconfig *nc,
 						struct l_rtnl_route *route)
 {
 	l_queue_remove(nc->routes.current, route);
-	l_queue_push_tail(nc->routes.removed, route);
+	l_queue_remove(nc->routes.updated, route);
+
+	if (!l_queue_remove(nc->routes.added, route))
+		l_queue_push_tail(nc->routes.removed, route);
 }
 
 static void netconfig_icmp6_event_handler(struct l_icmp6_client *client,
@@ -662,6 +776,8 @@ static void netconfig_icmp6_event_handler(struct l_icmp6_client *client,
 	if (nc->v6_gateway_override)
 		return;
 
+	netconfig_expire_routes(nc);
+
 	/* Process the default gateway information */
 	default_route = netconfig_find_icmp6_route(nc, r->address, NULL);
 
@@ -724,7 +840,8 @@ static void netconfig_icmp6_event_handler(struct l_icmp6_client *client,
 	 */
 	if (!l_queue_isempty(nc->routes.added) ||
 			!l_queue_isempty(nc->routes.updated) ||
-			!l_queue_isempty(nc->routes.removed))
+			!l_queue_isempty(nc->routes.removed) ||
+			!l_queue_isempty(nc->routes.expired))
 		netconfig_emit_event(nc, AF_INET6, L_NETCONFIG_EVENT_UPDATE);
 }
 
@@ -1155,6 +1272,9 @@ LIB_EXPORT void l_netconfig_stop(struct l_netconfig *netconfig)
 	if (netconfig->do_static_work)
 		l_idle_remove(l_steal_ptr(netconfig->do_static_work));
 
+	if (netconfig->signal_expired_work)
+		l_idle_remove(l_steal_ptr(netconfig->signal_expired_work));
+
 	netconfig_update_cleanup(netconfig);
 	l_queue_clear(netconfig->routes.current,
 			(l_queue_destroy_func_t) l_rtnl_route_free);
@@ -1261,7 +1381,8 @@ LIB_EXPORT const struct l_queue_entry *l_netconfig_get_addresses(
 					struct l_netconfig *netconfig,
 					const struct l_queue_entry **out_added,
 					const struct l_queue_entry **out_updated,
-					const struct l_queue_entry **out_removed)
+					const struct l_queue_entry **out_removed,
+					const struct l_queue_entry **out_expired)
 {
 	if (out_added)
 		*out_added = l_queue_get_entries(netconfig->addresses.added);
@@ -1272,6 +1393,9 @@ LIB_EXPORT const struct l_queue_entry *l_netconfig_get_addresses(
 	if (out_removed)
 		*out_removed = l_queue_get_entries(netconfig->addresses.removed);
 
+	if (out_expired)
+		*out_expired = l_queue_get_entries(netconfig->addresses.expired);
+
 	return l_queue_get_entries(netconfig->addresses.current);
 }
 
@@ -1279,8 +1403,11 @@ LIB_EXPORT const struct l_queue_entry *l_netconfig_get_routes(
 					struct l_netconfig *netconfig,
 					const struct l_queue_entry **out_added,
 					const struct l_queue_entry **out_updated,
-					const struct l_queue_entry **out_removed)
+					const struct l_queue_entry **out_removed,
+					const struct l_queue_entry **out_expired)
 {
+	netconfig_expire_routes(netconfig);
+
 	if (out_added)
 		*out_added = l_queue_get_entries(netconfig->routes.added);
 
@@ -1290,5 +1417,8 @@ LIB_EXPORT const struct l_queue_entry *l_netconfig_get_routes(
 	if (out_removed)
 		*out_removed = l_queue_get_entries(netconfig->routes.removed);
 
+	if (out_expired)
+		*out_expired = l_queue_get_entries(netconfig->routes.expired);
+
 	return l_queue_get_entries(netconfig->routes.current);
 }
ell/netconfig.h +4 -2
index fddbac1..69100a2 100644
@@ -90,12 +90,14 @@ const struct l_queue_entry *l_netconfig_get_addresses(
 				struct l_netconfig *netconfig,
 				const struct l_queue_entry **out_added,
 				const struct l_queue_entry **out_updated,
-				const struct l_queue_entry **out_removed);
+				const struct l_queue_entry **out_removed,
+				const struct l_queue_entry **out_expired);
 const struct l_queue_entry *l_netconfig_get_routes(
 				struct l_netconfig *netconfig,
 				const struct l_queue_entry **out_added,
 				const struct l_queue_entry **out_updated,
-				const struct l_queue_entry **out_removed);
+				const struct l_queue_entry **out_removed,
+				const struct l_queue_entry **out_expired);
 
 #ifdef __cplusplus
 }
Signature · 1 line
2.32.0
author
#7 lore raw

PATCH 8/15 examples: Update netconfig method calls

In reply to Andrew Zaborowski
---
 examples/netconfig-test.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
examples/netconfig-test.c +6 -3
index 39b6fa4..45455dc 100644
@@ -108,7 +108,7 @@ static void event_handler(struct l_netconfig *netconfig, uint8_t family,
 				enum l_netconfig_event event, void *user_data)
 {
 	const char *af_str = family == AF_INET ? "v4" : "v6";
-	const struct l_queue_entry *added, *updated, *removed;
+	const struct l_queue_entry *added, *updated, *removed, *expired;
 
 	switch (event) {
 	case L_NETCONFIG_EVENT_CONFIGURE:
@@ -126,15 +126,18 @@ static void event_handler(struct l_netconfig *netconfig, uint8_t family,
 		return;
 	}
 
-	l_netconfig_get_addresses(netconfig, &added, &updated, &removed);
+	l_netconfig_get_addresses(netconfig, &added, &updated,
+					&removed, &expired);
 	log_addresses(af_str, "added", added);
 	log_addresses(af_str, "updated", updated);
 	log_addresses(af_str, "removed", removed);
+	log_addresses(af_str, "expired", expired);
 
-	l_netconfig_get_routes(netconfig, &added, &updated, &removed);
+	l_netconfig_get_routes(netconfig, &added, &updated, &removed, &expired);
 	log_routes(af_str, "added", added);
 	log_routes(af_str, "updated", updated);
 	log_routes(af_str, "removed", removed);
+	log_routes(af_str, "expired", expired);
 
 	if (apply)
 		l_netconfig_apply_rtnl(netconfig);
Signature · 1 line
2.32.0
author
#8 lore raw

PATCH 9/15 netconfig: Add getters for DNS addresses and domain names

In reply to Andrew Zaborowski
---
 ell/ell.sym     |  2 ++
 ell/netconfig.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++
 ell/netconfig.h |  2 ++
 3 files changed, 68 insertions(+)
ell/ell.sym +2 -0
index ea4d06c..3b11f41 100644
@@ -757,6 +757,8 @@ global:
 	l_netconfig_apply_rtnl;
 	l_netconfig_get_addresses;
 	l_netconfig_get_routes;
+	l_netconfig_get_dns_list;
+	l_netconfig_get_domain_names;
 local:
 	*;
 };
ell/netconfig.c +64 -0

67 lines not on this page · raw message

ell/netconfig.h +2 -0
index 69100a2..0b1182d 100644
@@ -98,6 +98,8 @@ const struct l_queue_entry *l_netconfig_get_routes(
 				const struct l_queue_entry **out_updated,
 				const struct l_queue_entry **out_removed,
 				const struct l_queue_entry **out_expired);
+char **l_netconfig_get_dns_list(struct l_netconfig *netconfig);
+char **l_netconfig_get_domain_names(struct l_netconfig *netconfig);
 
 #ifdef __cplusplus
 }
Signature · 1 line
2.32.0
author
#9 lore raw

PATCH 10/15 netconfig: Wait for link-local address before DHCPv6

In reply to Andrew Zaborowski

Keep one global rtnl instance instead of one per interface so that we can have just one RTM_NEWADDR listener. On l_netconfig_start dump existing IPv6 addresses and wait until a link-local address is added so it can be used as the source address for our DHCPv6 frames.

---
 ell/netconfig.c | 149 +++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 146 insertions(+), 3 deletions(-)
ell/netconfig.c +146 -3
index 63ad154..e3ca85a 100644
@@ -65,6 +65,7 @@ struct l_netconfig {
 	char **v6_domain_names_override;
 
 	struct l_netlink *rtnl;
+	unsigned int ifaddr6_dump_cmd_id;
 	bool started;
 	struct l_idle *do_static_work;
 	bool v4_configured;
@@ -115,6 +116,9 @@ union netconfig_addr {
 	struct in6_addr v6;
 };
 
+static struct l_queue *addr_wait_list;
+static unsigned int rtnl_id;
+
 static void netconfig_update_cleanup(struct l_netconfig *nc)
 {
 	l_queue_clear(nc->addresses.added, NULL);
@@ -1202,6 +1206,117 @@ static void netconfig_do_static_config(struct l_idle *idle, void *user_data)
 	}
 }
 
+static void netconfig_rtnl_unregister(void *user_data)
+{
+	struct l_netlink *rtnl = user_data;
+
+	if (!addr_wait_list || !l_queue_isempty(addr_wait_list))
+		return;
+
+	l_queue_destroy(l_steal_ptr(addr_wait_list), NULL);
+	l_netlink_unregister(rtnl, rtnl_id);
+	rtnl_id = 0;
+}
+
+static void netconfig_addr_wait_unregister(struct l_netconfig *nc,
+						bool in_notify)
+{
+	if (nc->ifaddr6_dump_cmd_id) {
+		unsigned int cmd_id = nc->ifaddr6_dump_cmd_id;
+
+		nc->ifaddr6_dump_cmd_id = 0;
+		l_netlink_cancel(nc->rtnl, cmd_id);
+	}
+
+	if (!l_queue_remove(addr_wait_list, nc))
+		return;
+
+	if (!l_queue_isempty(addr_wait_list))
+		return;
+
+	/* We can't do l_netlink_unregister() inside a notification */
+	if (in_notify)
+		l_idle_oneshot(netconfig_rtnl_unregister, nc->rtnl, NULL);
+	else
+		netconfig_rtnl_unregister(nc->rtnl);
+}
+
+static void netconfig_ifaddr_ipv6_added(struct l_netconfig *nc,
+					const struct ifaddrmsg *ifa,
+					uint32_t len)
+{
+	struct in6_addr in6;
+	_auto_(l_free) char *ip = NULL;
+
+	if (ifa->ifa_flags & IFA_F_TENTATIVE)
+		return;
+
+	if (!nc->started)
+		return;
+
+	l_rtnl_ifaddr6_extract(ifa, len, &ip);
+	inet_pton(AF_INET6, ip, &in6);
+
+	if (!IN6_IS_ADDR_LINKLOCAL(&in6))
+		return;
+
+	netconfig_addr_wait_unregister(nc, true);
+
+	l_dhcp6_client_set_link_local_address(nc->dhcp6_client, ip);
+
+	/*
+	 * Only now that we have a link-local address start actual DHCPv6
+	 * setup.
+	 */
+	if (l_dhcp6_client_start(nc->dhcp6_client))
+		return;
+
+	netconfig_emit_event(nc, AF_INET6, L_NETCONFIG_EVENT_FAILED);
+}
+
+static void netconfig_ifaddr_ipv6_notify(uint16_t type, const void *data,
+						uint32_t len, void *user_data)
+{
+	const struct ifaddrmsg *ifa = data;
+	uint32_t bytes = len - NLMSG_ALIGN(sizeof(struct ifaddrmsg));
+	const struct l_queue_entry *entry, *next;
+
+	switch (type) {
+	case RTM_NEWADDR:
+		/* Iterate safely since elements may be removed */
+		for (entry = l_queue_get_entries(addr_wait_list); entry;
+				entry = next) {
+			struct l_netconfig *nc = entry->data;
+
+			next = entry->next;
+			netconfig_ifaddr_ipv6_added(nc, ifa, bytes);
+		}
+
+		break;
+	}
+}
+
+static void netconfig_ifaddr_ipv6_dump_cb(int error, uint16_t type,
+						const void *data, uint32_t len,
+						void *user_data)
+{
+	struct l_netconfig *nc = user_data;
+
+	if (!nc->ifaddr6_dump_cmd_id || !nc->started)
+		return;
+
+	if (error) {
+		netconfig_addr_wait_unregister(nc, false);
+		netconfig_emit_event(nc, AF_INET6, L_NETCONFIG_EVENT_FAILED);
+		return;
+	}
+
+	if (type != RTM_NEWADDR)
+		return;
+
+	netconfig_ifaddr_ipv6_notify(type, data, len, user_data);
+}
+
 LIB_EXPORT bool l_netconfig_start(struct l_netconfig *netconfig)
 {
 	if (unlikely(!netconfig || netconfig->started))
@@ -1244,14 +1359,40 @@ configure_ipv6:
 		goto done;
 	}
 
-	if (!l_dhcp6_client_start(netconfig->dhcp6_client))
-		goto stop_ipv4;
+	/*
+	 * We only care about being on addr_wait_list if we're waiting for
+	 * the link-local address for DHCP6.  Add ourself to the list here
+	 * before we start the dump, instead of after it ends, to eliminate
+	 * the possibility of missing an RTM_NEWADDR between the end of
+	 * the dump command and registering for the events.
+	 */
+	if (!addr_wait_list) {
+		addr_wait_list = l_queue_new();
+
+		rtnl_id = l_netlink_register(l_rtnl_get(&netconfig->rtnl),
+						RTNLGRP_IPV6_IFADDR,
+						netconfig_ifaddr_ipv6_notify,
+						netconfig, NULL);
+		if (!rtnl_id)
+			goto unregister;
+	}
+
+	netconfig->ifaddr6_dump_cmd_id = l_rtnl_ifaddr6_dump(
+						l_rtnl_get(&netconfig->rtnl),
+						netconfig_ifaddr_ipv6_dump_cb,
+						netconfig, NULL);
+	if (!netconfig->ifaddr6_dump_cmd_id)
+		goto unregister;
+
+	l_queue_push_tail(addr_wait_list, netconfig);
 
 done:
 	netconfig->started = true;
 	return true;
 
-stop_ipv4:
+unregister:
+	netconfig_addr_wait_unregister(netconfig, false);
+
 	if (netconfig->v4_enabled) {
 		if (netconfig->v4_static_addr)
 			l_idle_remove(l_steal_ptr(netconfig->do_static_work));
@@ -1275,6 +1416,8 @@ LIB_EXPORT void l_netconfig_stop(struct l_netconfig *netconfig)
 	if (netconfig->signal_expired_work)
 		l_idle_remove(l_steal_ptr(netconfig->signal_expired_work));
 
+	netconfig_addr_wait_unregister(netconfig, false);
+
 	netconfig_update_cleanup(netconfig);
 	l_queue_clear(netconfig->routes.current,
 			(l_queue_destroy_func_t) l_rtnl_route_free);
Signature · 1 line
2.32.0
author
#10 lore raw

PATCH 11/15 netconfig: Write /proc/sys/net files to enable IPv6

In reply to Andrew Zaborowski

Write the accept_ra setting to 0. On l_netconfig_start if the existing address dump command finds no link-local address then also try resetting disable_ipv6 and toggling addr_gen_mode to trigger the kernel to generate a link-local address.

---
 ell/netconfig.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 63 insertions(+), 3 deletions(-)
ell/netconfig.c +63 -3
index e3ca85a..ef3227b 100644
@@ -28,6 +28,12 @@
 #include <netinet/ip.h>
 #include <arpa/inet.h>
 #include <netinet/icmp6.h>
+#include <net/if.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
 
 #include "private.h"
 #include "useful.h"
@@ -849,6 +855,30 @@ static void netconfig_icmp6_event_handler(struct l_icmp6_client *client,
 		netconfig_emit_event(nc, AF_INET6, L_NETCONFIG_EVENT_UPDATE);
 }
 
+static int netconfig_proc_write_ipv6_setting(struct l_netconfig *nc,
+						const char *setting,
+						const char *value)
+{
+	char ifname[IF_NAMESIZE];
+	_auto_(l_free) char *filename = NULL;
+	int fd;
+	int r;
+
+	if (unlikely(!if_indextoname(nc->ifindex, ifname)))
+		return -errno;
+
+	filename = l_strdup_printf("/proc/sys/net/ipv6/conf/%s/%s",
+					ifname, setting);
+
+	fd = L_TFR(open(filename, O_WRONLY));
+	if (unlikely(fd < 0))
+		return -errno;
+
+	r = L_TFR(write(fd, value, strlen(value)));
+	L_TFR(close(fd));
+	return r;
+}
+
 LIB_EXPORT struct l_netconfig *l_netconfig_new(uint32_t ifindex)
 {
 	struct l_netconfig *nc;
@@ -881,6 +911,9 @@ LIB_EXPORT struct l_netconfig *l_netconfig_new(uint32_t ifindex)
 					netconfig_icmp6_event_handler,
 					nc, NULL);
 
+	/* Disable in-kernel autoconfiguration for the interface */
+	netconfig_proc_write_ipv6_setting(nc, "accept_ra", "0");
+
 	return nc;
 }
 
@@ -1317,6 +1350,32 @@ static void netconfig_ifaddr_ipv6_dump_cb(int error, uint16_t type,
 	netconfig_ifaddr_ipv6_notify(type, data, len, user_data);
 }
 
+static void netconfig_ifaddr_ipv6_dump_done_cb(void *user_data)
+{
+	struct l_netconfig *nc = user_data;
+
+	/*
+	 * Handle the case of no link-local address having been found during
+	 * the dump.  If nc->ifaddr6_dump_cmd_id is 0, we have found one or
+	 * the dump is being cancelled.  Otherwise try disabing the
+	 * "disable_ipv6" setting for the interface since it may have been
+	 * enabled.  Also write "addr_gen_mode" which triggers regerating
+	 * the link-local addresss on the interface in the kernel if it
+	 * was previously removed.
+	 */
+	if (!nc->ifaddr6_dump_cmd_id || !nc->started)
+		return;
+
+	nc->ifaddr6_dump_cmd_id = 0;
+
+	/* "do no generate a link-local address" */
+	netconfig_proc_write_ipv6_setting(nc, "addr_gen_mode", "1");
+	/* "generate address based on EUI64 (default)" */
+	netconfig_proc_write_ipv6_setting(nc, "addr_gen_mode", "0");
+	/* "enable IPv6 operation" */
+	netconfig_proc_write_ipv6_setting(nc, "disable_ipv6", "0");
+}
+
 LIB_EXPORT bool l_netconfig_start(struct l_netconfig *netconfig)
 {
 	if (unlikely(!netconfig || netconfig->started))
@@ -1378,9 +1437,10 @@ configure_ipv6:
 	}
 
 	netconfig->ifaddr6_dump_cmd_id = l_rtnl_ifaddr6_dump(
-						l_rtnl_get(&netconfig->rtnl),
-						netconfig_ifaddr_ipv6_dump_cb,
-						netconfig, NULL);
+					l_rtnl_get(&netconfig->rtnl),
+					netconfig_ifaddr_ipv6_dump_cb,
+					netconfig,
+					netconfig_ifaddr_ipv6_dump_done_cb);
 	if (!netconfig->ifaddr6_dump_cmd_id)
 		goto unregister;
 
Signature · 1 line
2.32.0
author
#11 lore raw

PATCH 12/15 netconfig: Write gateway MAC from DHCP to ARP cache

In reply to Andrew Zaborowski

Write the MAC directly to the ARP table to save an ARP query for the gateway's MAC when it is known from the freshly obtained lease. For practical reasons do this outside of l_netconfig_apply_rtnl().

---
 ell/netconfig.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
ell/netconfig.c +33 -0
index ef3227b..3277f5c 100644
@@ -25,6 +25,7 @@
 #endif
 
 #include <linux/types.h>
+#include <linux/if_ether.h>
 #include <netinet/ip.h>
 #include <arpa/inet.h>
 #include <netinet/icmp6.h>
@@ -404,6 +405,37 @@ static void netconfig_remove_dhcp_address_routes(struct l_netconfig *nc,
 	}
 }
 
+static void netconfig_set_neighbor_entry_cb(int error,
+						uint16_t type, const void *data,
+						uint32_t len, void *user_data)
+{
+	/* Not critical.  TODO: log warning */
+}
+
+static int netconfig_dhcp_gateway_to_arp(struct l_netconfig *nc)
+{
+	const struct l_dhcp_lease *lease =
+		l_dhcp_client_get_lease(nc->dhcp_client);
+	_auto_(l_free) char *server_id = l_dhcp_lease_get_server_id(lease);
+	_auto_(l_free) char *gw = l_dhcp_lease_get_gateway(lease);
+	const uint8_t *server_mac = l_dhcp_lease_get_server_mac(lease);
+	struct in_addr in_gw;
+
+	if (!gw || strcmp(server_id, gw) || !server_mac)
+		return -ENOENT;
+
+	/* Gateway MAC is known, write it into ARP cache to save ARP traffic */
+	in_gw.s_addr = l_dhcp_lease_get_gateway_u32(lease);
+
+	if (!l_rtnl_neighbor_set_hwaddr(l_rtnl_get(&nc->rtnl), nc->ifindex,
+					AF_INET, &in_gw, server_mac, ETH_ALEN,
+					netconfig_set_neighbor_entry_cb, nc,
+					NULL))
+		return -EIO;
+
+	return 0;
+}
+
 static void netconfig_dhcp_event_handler(struct l_dhcp_client *client,
 						enum l_dhcp_client_event event,
 						void *user_data)
@@ -428,6 +460,7 @@ static void netconfig_dhcp_event_handler(struct l_dhcp_client *client,
 		netconfig_set_dhcp_lifetimes(nc, false);
 		nc->v4_configured = true;
 		netconfig_emit_event(nc, AF_INET, L_NETCONFIG_EVENT_CONFIGURE);
+		netconfig_dhcp_gateway_to_arp(nc);
 		break;
 	case L_DHCP_CLIENT_EVENT_LEASE_RENEWED:
 		if (L_WARN_ON(!nc->v4_configured))
Signature · 1 line
2.32.0
author
#12 lore raw

PATCH 13/15 netconfig: Ratelimit route lifetime updates

In reply to Andrew Zaborowski

Optimize away prefix route updates when the expiry time is far enough in the future that we expect to receive at least 10 Router Advertisements before then. For that purpose start keeping an extra record for each route where we save the last time this route was included in an RA and the maximum interval between two RAs with this route seen so far. By working with the maximum intervals we avoid worrying about different RA content policies where some routes may be skipped in some RAs and there even might be multiple routers sending RAs with subsets of the same prefixes.

This new mechanism can be made configurable if desired but it's always enabled for now.

---
 ell/netconfig.c | 183 ++++++++++++++++++++++++++++++++----------------
 1 file changed, 122 insertions(+), 61 deletions(-)
ell/netconfig.c +122 -61
index 3277f5c..af85f71 100644
@@ -81,6 +81,7 @@ struct l_netconfig {
 	struct l_icmp6_client *icmp6_client;
 	struct l_dhcp6_client *dhcp6_client;
 	struct l_idle *signal_expired_work;
+	struct l_queue *icmp_route_data;
 
 	/* These objects, if not NULL, are owned by @addresses and @routes */
 	struct l_rtnl_address *v4_address;
@@ -118,6 +119,13 @@ struct l_netconfig {
 	} handler;
 };
 
+struct netconfig_route_data {
+	struct l_rtnl_route *route;
+	uint64_t last_ra_time;
+	uint64_t kernel_expiry;
+	uint64_t max_ra_interval;
+};
+
 union netconfig_addr {
 	struct in_addr v4;
 	struct in6_addr v6;
@@ -645,10 +653,9 @@ static uint64_t now;
 static bool netconfig_check_route_expired(void *data, void *user_data)
 {
 	struct l_netconfig *nc = user_data;
-	struct l_rtnl_route *route = data;
-	uint64_t expiry_time = l_rtnl_route_get_expiry(route);
+	struct netconfig_route_data *rd = data;
 
-	if (!expiry_time || now < expiry_time)
+	if (!rd->kernel_expiry || now < rd->kernel_expiry)
 		return false;
 
 	/*
@@ -662,11 +669,12 @@ static bool netconfig_check_route_expired(void *data, void *user_data)
 	 * If for some reason the route is still on the added list, drop it
 	 * from there and there's nothing to notify the user of.
 	 */
-	if (!l_queue_remove(nc->routes.added, route))
-		l_queue_push_tail(nc->routes.expired, route);
+	if (!l_queue_remove(nc->routes.added, rd->route))
+		l_queue_push_tail(nc->routes.expired, rd->route);
 
-	l_queue_remove(nc->routes.updated, route);
-	l_queue_remove(nc->routes.removed, route);
+	l_queue_remove(nc->routes.current, rd->route);
+	l_queue_remove(nc->routes.updated, rd->route);
+	l_queue_remove(nc->routes.removed, rd->route);
 	return true;
 }
 
@@ -674,7 +682,7 @@ static void netconfig_expire_routes(struct l_netconfig *nc)
 {
 	now = l_time_now();
 
-	if (l_queue_foreach_remove(nc->routes.current,
+	if (l_queue_foreach_remove(nc->icmp_route_data,
 					netconfig_check_route_expired, nc) &&
 			!l_queue_isempty(nc->routes.expired) &&
 			!nc->signal_expired_work)
@@ -683,31 +691,27 @@ static void netconfig_expire_routes(struct l_netconfig *nc)
 						nc, NULL);
 }
 
-static struct l_rtnl_route *netconfig_find_icmp6_route(
+static struct netconfig_route_data *netconfig_find_icmp6_route(
 						struct l_netconfig *nc,
 						const uint8_t *gateway,
 						const struct route_info *dst)
 {
 	const struct l_queue_entry *entry;
 
-	for (entry = l_queue_get_entries(nc->routes.current); entry;
+	for (entry = l_queue_get_entries(nc->icmp_route_data); entry;
 			entry = entry->next) {
-		struct l_rtnl_route *route = entry->data;
+		struct netconfig_route_data *rd = entry->data;
 		const uint8_t *route_gateway;
 		const uint8_t *route_dst;
 		uint8_t route_prefix_len = 0;
 
-		if (l_rtnl_route_get_family(route) != AF_INET6 ||
-				l_rtnl_route_get_protocol(route) != RTPROT_RA)
-			continue;
-
-		route_gateway = l_rtnl_route_get_gateway_in_addr(route);
+		route_gateway = l_rtnl_route_get_gateway_in_addr(rd->route);
 		if ((gateway || route_gateway) &&
 				(!gateway || !route_gateway ||
 				 memcmp(gateway, route_gateway, 16)))
 			continue;
 
-		route_dst = l_rtnl_route_get_dst_in_addr(route,
+		route_dst = l_rtnl_route_get_dst_in_addr(rd->route,
 							&route_prefix_len);
 		if ((dst || route_prefix_len) &&
 				(!dst || !route_prefix_len ||
@@ -715,17 +719,19 @@ static struct l_rtnl_route *netconfig_find_icmp6_route(
 				 memcmp(dst->address, route_dst, 16)))
 			continue;
 
-		return route;
+		return rd;
 	}
 
 	return NULL;
 }
 
-static struct l_rtnl_route *netconfig_add_icmp6_route(struct l_netconfig *nc,
+static struct netconfig_route_data *netconfig_add_icmp6_route(
+						struct l_netconfig *nc,
 						const uint8_t *gateway,
 						const struct route_info *dst,
 						uint8_t preference)
 {
+	struct netconfig_route_data *rd;
 	struct l_rtnl_route *rt;
 
 	rt = netconfig_route_new(nc, AF_INET6, dst ? dst->address : NULL,
@@ -737,25 +743,73 @@ static struct l_rtnl_route *netconfig_add_icmp6_route(struct l_netconfig *nc,
 	l_rtnl_route_set_preference(rt, preference);
 	l_queue_push_tail(nc->routes.current, rt);
 	l_queue_push_tail(nc->routes.added, rt);
-	return rt;
+
+	rd = l_new(struct netconfig_route_data, 1);
+	rd->route = rt;
+	l_queue_push_tail(nc->icmp_route_data, rd);
+	return rd;
+}
+
+static bool netconfig_check_route_need_update(
+					const struct netconfig_route_data *rd,
+					const struct l_icmp6_router *ra,
+					uint64_t new_expiry,
+					uint64_t old_expiry)
+{
+	/*
+	 * Decide whether the route is close enough to its expiry time that,
+	 * based on the expected Router Advertisement frequency, we should
+	 * notify the user and have them update the route's lifetime in the
+	 * kernel.  This is an optimization to avoid triggering a syscall and
+	 * potentially multiple context-switches in case we expect to have
+	 * many more opportunities to update the lifetime before we even get
+	 * close to the last expiry time we passed to the kernel.  Without
+	 * this we might be wasting a lot of cycles over time if the RAs are
+	 * frequent.
+	 *
+	 * Always update if we have no RA interval information or if the
+	 * expiry is moved forward.
+	 */
+	if (!rd->max_ra_interval || new_expiry < rd->kernel_expiry)
+		return true;
+
+	return rd->kernel_expiry < ra->start_time + rd->max_ra_interval * 10;
 }
 
 static void netconfig_set_icmp6_route_data(struct l_netconfig *nc,
-						struct l_rtnl_route *rt,
-						uint64_t start_time,
+						struct netconfig_route_data *rd,
+						const struct l_icmp6_router *ra,
 						uint32_t preferred_lifetime,
 						uint32_t valid_lifetime,
 						uint32_t mtu, bool updated)
 {
-	uint64_t expiry = start_time + valid_lifetime * L_USEC_PER_SEC;
-	uint64_t old_expiry = l_rtnl_route_get_expiry(rt);
+	uint64_t expiry = ra->start_time + valid_lifetime * L_USEC_PER_SEC;
+	uint64_t old_expiry = l_rtnl_route_get_expiry(rd->route);
 	bool differs = false;
 
-	if (mtu != l_rtnl_route_get_mtu(rt)) {
-		l_rtnl_route_set_mtu(rt, mtu);
+	if (mtu != l_rtnl_route_get_mtu(rd->route)) {
+		l_rtnl_route_set_mtu(rd->route, mtu);
 		differs = true;
 	}
 
+	/*
+	 * The route's lifetime is pretty useless on its own but keep it
+	 * updated with the value from the last RA.  Routers can send the same
+	 * lifetime in every RA, keep decreasing the lifetimes linearly or
+	 * implement any other policy, regardless of whether the resulting
+	 * expiry time varies or not.
+	 */
+	l_rtnl_route_set_lifetime(rd->route, valid_lifetime);
+
+	if (rd->last_ra_time) {
+		uint64_t interval = ra->start_time - rd->last_ra_time;
+
+		if (interval > rd->max_ra_interval)
+			rd->max_ra_interval = interval;
+	}
+
+	rd->last_ra_time = ra->start_time;
+
 	/*
 	 * valid_lifetime of 0 from a route_info means the route is being
 	 * removed so we wouldn't be here.  valid_lifetime of 0xffffffff
@@ -776,23 +830,29 @@ static void netconfig_set_icmp6_route_data(struct l_netconfig *nc,
 	if ((expiry || old_expiry) &&
 			(!expiry || !old_expiry ||
 			 l_time_diff(expiry, old_expiry) > L_USEC_PER_SEC)) {
-		l_rtnl_route_set_lifetime(rt, valid_lifetime);
-		l_rtnl_route_set_expiry(rt, expiry);
-		differs = true;
+		l_rtnl_route_set_expiry(rd->route, expiry);
+
+		differs = differs || !expiry || !old_expiry ||
+			netconfig_check_route_need_update(rd, ra,
+							expiry, old_expiry);
 	}
 
-	if (updated && differs && !netconfig_route_exists(nc->routes.added, rt))
-		l_queue_push_tail(nc->routes.updated, rt);
+	if (updated && differs && !netconfig_route_exists(nc->routes.added,
+								rd->route)) {
+		l_queue_push_tail(nc->routes.updated, rd->route);
+		rd->kernel_expiry = expiry;
+	}
 }
 
 static void netconfig_remove_icmp6_route(struct l_netconfig *nc,
-						struct l_rtnl_route *route)
+						struct netconfig_route_data *rd)
 {
-	l_queue_remove(nc->routes.current, route);
-	l_queue_remove(nc->routes.updated, route);
+	l_queue_remove(nc->icmp_route_data, rd);
+	l_queue_remove(nc->routes.current, rd->route);
+	l_queue_remove(nc->routes.updated, rd->route);
 
-	if (!l_queue_remove(nc->routes.added, route))
-		l_queue_push_tail(nc->routes.removed, route);
+	if (!l_queue_remove(nc->routes.added, rd->route))
+		l_queue_push_tail(nc->routes.removed, rd->route);
 }
 
 static void netconfig_icmp6_event_handler(struct l_icmp6_client *client,
@@ -802,7 +862,7 @@ static void netconfig_icmp6_event_handler(struct l_icmp6_client *client,
 {
 	struct l_netconfig *nc = user_data;
 	const struct l_icmp6_router *r;
-	struct l_rtnl_route *default_route;
+	struct netconfig_route_data *default_rd;
 	unsigned int i;
 
 	if (event != L_ICMP6_CLIENT_EVENT_ROUTER_FOUND)
@@ -822,12 +882,12 @@ static void netconfig_icmp6_event_handler(struct l_icmp6_client *client,
 	netconfig_expire_routes(nc);
 
 	/* Process the default gateway information */
-	default_route = netconfig_find_icmp6_route(nc, r->address, NULL);
+	default_rd = netconfig_find_icmp6_route(nc, r->address, NULL);
 
-	if (!default_route && r->lifetime) {
-		default_route = netconfig_add_icmp6_route(nc, r->address, NULL,
+	if (!default_rd && r->lifetime) {
+		default_rd = netconfig_add_icmp6_route(nc, r->address, NULL,
 								r->pref);
-		if (unlikely(!default_route))
+		if (unlikely(!default_rd))
 			return;
 
 		/*
@@ -835,15 +895,13 @@ static void netconfig_icmp6_event_handler(struct l_icmp6_client *client,
 		 * confused for the special 0xffffffff value in
 		 * netconfig_set_icmp6_route_data.
 		 */
-		netconfig_set_icmp6_route_data(nc, default_route, r->start_time,
-						r->lifetime, r->lifetime,
-						r->mtu, false);
-	} else if (default_route && r->lifetime)
-		netconfig_set_icmp6_route_data(nc, default_route, r->start_time,
-						r->lifetime, r->lifetime,
-						r->mtu, true);
-	else if (default_route && !r->lifetime)
-		netconfig_remove_icmp6_route(nc, default_route);
+		netconfig_set_icmp6_route_data(nc, default_rd, r, r->lifetime,
+						r->lifetime, r->mtu, false);
+	} else if (default_rd && r->lifetime)
+		netconfig_set_icmp6_route_data(nc, default_rd, r, r->lifetime,
+						r->lifetime, r->mtu, true);
+	else if (default_rd && !r->lifetime)
+		netconfig_remove_icmp6_route(nc, default_rd);
 
 	/*
 	 * Process the onlink and offlink routes, from the Router
@@ -853,26 +911,26 @@ static void netconfig_icmp6_event_handler(struct l_icmp6_client *client,
 	for (i = 0; i < r->n_routes; i++) {
 		const struct route_info *info = &r->routes[i];
 		const uint8_t *gateway = info->onlink ? NULL : r->address;
-		struct l_rtnl_route *route =
+		struct netconfig_route_data *rd =
 			netconfig_find_icmp6_route(nc, gateway, info);
 
-		if (!route && info->valid_lifetime) {
-			route = netconfig_add_icmp6_route(nc, gateway, info,
+		if (!rd && info->valid_lifetime) {
+			rd = netconfig_add_icmp6_route(nc, gateway, info,
 							info->preference);
-			if (unlikely(!route))
+			if (unlikely(!rd))
 				continue;
 
-			netconfig_set_icmp6_route_data(nc, route, r->start_time,
+			netconfig_set_icmp6_route_data(nc, rd, r,
 						info->preferred_lifetime,
 						info->valid_lifetime,
 						gateway ? r->mtu : 0, false);
-		} else if (route && info->valid_lifetime)
-			netconfig_set_icmp6_route_data(nc, route, r->start_time,
+		} else if (rd && info->valid_lifetime)
+			netconfig_set_icmp6_route_data(nc, rd, r,
 						info->preferred_lifetime,
 						info->valid_lifetime,
 						gateway ? r->mtu : 0, true);
-		else if (route && !info->valid_lifetime)
-			netconfig_remove_icmp6_route(nc, route);
+		else if (rd && !info->valid_lifetime)
+			netconfig_remove_icmp6_route(nc, rd);
 	}
 
 	/*
@@ -928,6 +986,7 @@ LIB_EXPORT struct l_netconfig *l_netconfig_new(uint32_t ifindex)
 	nc->routes.added = l_queue_new();
 	nc->routes.updated = l_queue_new();
 	nc->routes.removed = l_queue_new();
+	nc->icmp_route_data = l_queue_new();
 
 	nc->dhcp_client = l_dhcp_client_new(ifindex);
 	l_dhcp_client_set_event_handler(nc->dhcp_client,
@@ -977,6 +1036,7 @@ LIB_EXPORT void l_netconfig_destroy(struct l_netconfig *netconfig)
 	l_queue_destroy(netconfig->routes.added, NULL);
 	l_queue_destroy(netconfig->routes.updated, NULL);
 	l_queue_destroy(netconfig->routes.removed, NULL);
+	l_queue_destroy(netconfig->icmp_route_data, NULL);
 	l_free(netconfig);
 }
 
@@ -1512,10 +1572,11 @@ LIB_EXPORT void l_netconfig_stop(struct l_netconfig *netconfig)
 	netconfig_addr_wait_unregister(netconfig, false);
 
 	netconfig_update_cleanup(netconfig);
-	l_queue_clear(netconfig->routes.current,
-			(l_queue_destroy_func_t) l_rtnl_route_free);
 	l_queue_clear(netconfig->addresses.current,
 			(l_queue_destroy_func_t) l_rtnl_address_free);
+	l_queue_clear(netconfig->routes.current,
+			(l_queue_destroy_func_t) l_rtnl_route_free);
+	l_queue_clear(netconfig->icmp_route_data, l_free);
 	netconfig->v4_address = NULL;
 	netconfig->v4_subnet_route = NULL;
 	netconfig->v4_default_route = NULL;
Signature · 1 line
2.32.0
author
#13 lore raw

PATCH 14/15 netconfig: Set a limit on number of routes from ICMPv6

In reply to Andrew Zaborowski

While some networks can be configured in a way that prevents rogue Router Advertisements from reaching clients, add a very basic mechanism to avoid a denial-of-service in such a case by limiting the number of routes we track from RAs. This won't prevent the loss of routing but might prevent OOM crashes or slowdowns.

---
 ell/netconfig.c | 5 +++++
 1 file changed, 5 insertions(+)
ell/netconfig.c +5 -0
index af85f71..f86fcfb 100644
@@ -134,6 +134,8 @@ union netconfig_addr {
 static struct l_queue *addr_wait_list;
 static unsigned int rtnl_id;
 
+static const unsigned int max_icmp6_routes = 100;
+
 static void netconfig_update_cleanup(struct l_netconfig *nc)
 {
 	l_queue_clear(nc->addresses.added, NULL);
@@ -734,6 +736,9 @@ static struct netconfig_route_data *netconfig_add_icmp6_route(
 	struct netconfig_route_data *rd;
 	struct l_rtnl_route *rt;
 
+	if (l_queue_length(nc->icmp_route_data) >= max_icmp6_routes)
+		return NULL;	/* TODO: log a warning the first time */
+
 	rt = netconfig_route_new(nc, AF_INET6, dst ? dst->address : NULL,
 					dst ? dst->prefix_len : 0, gateway,
 					RTPROT_RA);
Signature · 1 line
2.32.0
author
#14 lore raw

PATCH 15/15 netconfig: Start ACD before committing static IPv4

In reply to Andrew Zaborowski

When the IPv4 is configured to be static we can use ACD in order to check that the IP is available and not already in use. If a conflict is found netconfig will be reset and no IP will be set on the interface. The ACD client is left with the default 'defend once' policy, and probes are not turned off. This will increase connection time, but for static IP it is considered the safe approach.

---
 ell/netconfig.c | 71 ++++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 64 insertions(+), 7 deletions(-)
ell/netconfig.c +64 -7
index f86fcfb..c1a686e 100644
@@ -53,6 +53,7 @@
 #include "strv.h"
 #include "net.h"
 #include "net-private.h"
+#include "acd.h"
 #include "netconfig.h"
 
 struct l_netconfig {
@@ -82,6 +83,7 @@ struct l_netconfig {
 	struct l_dhcp6_client *dhcp6_client;
 	struct l_idle *signal_expired_work;
 	struct l_queue *icmp_route_data;
+	struct l_acd *acd;
 
 	/* These objects, if not NULL, are owned by @addresses and @routes */
 	struct l_rtnl_address *v4_address;
@@ -380,8 +382,8 @@ static void netconfig_set_dhcp_lifetimes(struct l_netconfig *nc, bool updated)
 		l_queue_push_tail(nc->routes.updated, nc->v4_default_route);
 }
 
-static void netconfig_remove_dhcp_address_routes(struct l_netconfig *nc,
-							bool expired)
+static void netconfig_remove_v4_address_routes(struct l_netconfig *nc,
+						bool expired)
 {
 	struct l_queue *routes =
 		expired ? nc->routes.expired : nc->routes.removed;
@@ -457,7 +459,7 @@ static void netconfig_dhcp_event_handler(struct l_dhcp_client *client,
 		if (L_WARN_ON(!nc->v4_configured))
 			break;
 
-		netconfig_remove_dhcp_address_routes(nc, false);
+		netconfig_remove_v4_address_routes(nc, false);
 		netconfig_add_dhcp_address_routes(nc);
 		netconfig_set_dhcp_lifetimes(nc, false);
 		netconfig_emit_event(nc, AF_INET, L_NETCONFIG_EVENT_UPDATE);
@@ -483,7 +485,7 @@ static void netconfig_dhcp_event_handler(struct l_dhcp_client *client,
 		if (L_WARN_ON(!nc->v4_configured))
 			break;
 
-		netconfig_remove_dhcp_address_routes(nc, true);
+		netconfig_remove_v4_address_routes(nc, true);
 		nc->v4_configured = false;
 
 		if (l_dhcp_client_start(nc->dhcp_client))
@@ -1318,16 +1320,69 @@ static void netconfig_add_v6_static_address_routes(struct l_netconfig *nc)
 	netconfig_add_v6_static_routes(nc, ip, prefix_len);
 }
 
-static void netconfig_do_static_config(struct l_idle *idle, void *user_data)
+static void netconfig_ipv4_acd_event(enum l_acd_event event, void *user_data)
 {
 	struct l_netconfig *nc = user_data;
 
-	l_idle_remove(l_steal_ptr(nc->do_static_work));
+	switch (event) {
+	case L_ACD_EVENT_AVAILABLE:
+		if (L_WARN_ON(nc->v4_configured))
+			break;
 
-	if (nc->v4_static_addr && !nc->v4_configured) {
 		netconfig_add_v4_static_address_routes(nc);
 		nc->v4_configured = true;
 		netconfig_emit_event(nc, AF_INET, L_NETCONFIG_EVENT_CONFIGURE);
+		break;
+	case L_ACD_EVENT_CONFLICT:
+		if (L_WARN_ON(nc->v4_configured))
+			break;
+
+		/*
+		 * Conflict found, no IP was actually set or routes added so
+		 * just emit the event.
+		 */
+		netconfig_emit_event(nc, AF_INET, L_NETCONFIG_EVENT_FAILED);
+		break;
+	case L_ACD_EVENT_LOST:
+		if (L_WARN_ON(!nc->v4_configured))
+			break;
+
+		/*
+		 * Set IP but lost it some time later.  Reset IPv4 in this
+		 * case and emit the FAILED event since we have no way to
+		 * recover from here.
+		 */
+		netconfig_remove_v4_address_routes(nc, false);
+		nc->v4_configured = false;
+		netconfig_emit_event(nc, AF_INET, L_NETCONFIG_EVENT_FAILED);
+		break;
+	}
+}
+
+static void netconfig_do_static_config(struct l_idle *idle, void *user_data)
+{
+	struct l_netconfig *nc = user_data;
+
+	l_idle_remove(l_steal_ptr(nc->do_static_work));
+
+	if (nc->v4_static_addr && !nc->v4_configured) {
+		char ip[INET_ADDRSTRLEN];
+
+		l_rtnl_address_get_address(nc->v4_static_addr, ip);
+
+		nc->acd = l_acd_new(nc->ifindex);
+                l_acd_set_event_handler(nc->acd, netconfig_ipv4_acd_event, nc,
+					NULL);
+
+		if (!l_acd_start(nc->acd, ip)) {
+			l_acd_destroy(l_steal_ptr(nc->acd));
+
+			/* Configure right now as a fallback */
+			netconfig_add_v4_static_address_routes(nc);
+			nc->v4_configured = true;
+			netconfig_emit_event(nc, AF_INET,
+						L_NETCONFIG_EVENT_CONFIGURE);
+		}
 	}
 
 	if (nc->v6_static_addr && !nc->v6_configured) {
@@ -1590,6 +1645,8 @@ LIB_EXPORT void l_netconfig_stop(struct l_netconfig *netconfig)
 	l_dhcp_client_stop(netconfig->dhcp_client);
 	l_dhcp6_client_stop(netconfig->dhcp6_client);
 
+	l_acd_destroy(l_steal_ptr(netconfig->acd));
+
 	l_rtnl_put(&netconfig->rtnl);
 }
 
Signature · 1 line
2.32.0
#15 lore raw
In reply to Andrew Zaborowski

Hi Andrew,

Quoted 5 lines · Andrew Zaborowski
Fixes 7a137bcac31e ("netconfig: Create routes from Router Advertisements")
---
  ell/netconfig.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)

Patches 1-3 applied, thanks.

Regards,
-Denis