[PATCH 3/5] netconfig: Return SLAAC+DHCP6 DNS info from getters

Andrew Zaborowski <[email protected]>
Newsgroups dev.linux.lists.ell
Message-ID <[email protected]>
In l_netconfig_get_dns_list(), l_netconfig_get_domain_names() return
both the DNS information from Router Advertisements if any, and from the
l_dhcp6_client lease if any, to cover the SLAAC+DHCP6 mode and other
possible corner cases.
---
 ell/netconfig.c | 47 ++++++++++++++++++++++++++++++-----------------
 1 file changed, 30 insertions(+), 17 deletions(-)

diff --git a/ell/netconfig.c b/ell/netconfig.c
index e54e2f9..7aac5ad 100644
--- a/ell/netconfig.c
+++ b/ell/netconfig.c
@@ -1209,6 +1209,20 @@ process_nondefault_routes:
 			netconfig_remove_icmp6_route(nc, rd);
 	}
 
+	/*
+	 * Do this first so that any changes are included in the event
+	 * emitted next, be it UPDATE or CONFIGURE.
+	 */
+	if (r->n_dns || r->n_domains) {
+		if (!nc->slaac_dnses && r->n_dns)
+			nc->slaac_dnses = l_queue_new();
+
+		if (!nc->slaac_domains && r->n_domains)
+			nc->slaac_domains = l_queue_new();
+
+		dns_updated = netconfig_process_slaac_dns_info(nc, r);
+	}
+
 	/*
 	 * For lack of a better policy, select between DHCPv6 and SLAAC based
 	 * on the first RA received.  Prefer DHCPv6.
@@ -1245,14 +1259,6 @@ process_nondefault_routes:
 		} else
 			nc->v6_auto_method = NETCONFIG_V6_METHOD_SLAAC;
 
-		/*
-		 * Do this first so that any changes are included in the
-		 * CONFIGURE event emitted next.
-		 */
-		nc->slaac_dnses = l_queue_new();
-		nc->slaac_domains = l_queue_new();
-		netconfig_process_slaac_dns_info(nc, r);
-
 		/*
 		 * The DAD for the link-local address may be still running
 		 * but again we can generate the global address already and
@@ -1287,7 +1293,6 @@ process_nondefault_routes:
 	 * and allows us to extend its lifetime.
 	 */
 	netconfig_set_slaac_address_lifetimes(nc, r);
-	dns_updated = netconfig_process_slaac_dns_info(nc, r);
 
 emit_event:
 	/*
@@ -2411,14 +2416,18 @@ append_v6:
 	if (!netconfig->v6_configured)
 		goto done;
 
-	if (netconfig->v6_dns_override)
+	if (netconfig->v6_dns_override) {
 		netconfig_strv_cat(&ret, netconfig->v6_dns_override, false);
-	else if (netconfig->v6_auto_method == NETCONFIG_V6_METHOD_DHCP &&
+		goto done;
+	}
+
+	if (L_IN_SET(netconfig->v6_auto_method, NETCONFIG_V6_METHOD_DHCP,
+				NETCONFIG_V6_METHOD_SLAAC_DHCP) &&
 			(v6_lease = l_dhcp6_client_get_lease(
 						netconfig->dhcp6_client)))
 		netconfig_strv_cat(&ret, l_dhcp6_lease_get_dns(v6_lease), true);
-	else if (netconfig->v6_auto_method == NETCONFIG_V6_METHOD_SLAAC &&
-			!l_queue_isempty(netconfig->slaac_dnses)) {
+
+	if (!l_queue_isempty(netconfig->slaac_dnses)) {
 		unsigned int dest_len = l_strv_length(ret);
 		unsigned int src_len = l_queue_length(netconfig->slaac_dnses);
 		char **i;
@@ -2468,16 +2477,20 @@ append_v6:
 	if (!netconfig->v6_configured)
 		goto done;
 
-	if (netconfig->v6_domain_names_override)
+	if (netconfig->v6_domain_names_override) {
 		netconfig_strv_cat(&ret, netconfig->v6_domain_names_override,
 					false);
-	else if (netconfig->v6_auto_method == NETCONFIG_V6_METHOD_DHCP &&
+		goto done;
+	}
+
+	if (L_IN_SET(netconfig->v6_auto_method, NETCONFIG_V6_METHOD_DHCP,
+				NETCONFIG_V6_METHOD_SLAAC_DHCP) &&
 			(v6_lease = l_dhcp6_client_get_lease(
 						netconfig->dhcp6_client)))
 		netconfig_strv_cat(&ret, l_dhcp6_lease_get_domains(v6_lease),
 					true);
-	else if (netconfig->v6_auto_method == NETCONFIG_V6_METHOD_SLAAC &&
-			!l_queue_isempty(netconfig->slaac_domains)) {
+
+	if (!l_queue_isempty(netconfig->slaac_domains)) {
 		unsigned int dest_len = l_strv_length(ret);
 		unsigned int src_len = l_queue_length(netconfig->slaac_domains);
 		char **i;
-- 
2.34.1
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.