diff mbox series

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

Message ID 20220930135250.534296-4-andrew.zaborowski@intel.com (mailing list archive)
State Accepted, archived
Headers show
Series [1/5] dhcp6: Include Client ID in Information-Request | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success

Commit Message

Andrew Zaborowski Sept. 30, 2022, 1:52 p.m. UTC
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 mbox series

Patch

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;