ell.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH] netconfig: Add getters for DNS addresses and domain names
@ 2022-06-22  0:57 Andrew Zaborowski
  2022-06-22 20:49 ` Denis Kenzior
  0 siblings, 1 reply; 2+ messages in thread
From: Andrew Zaborowski @ 2022-06-22  0:57 UTC (permalink / raw)
  To: ell

---
 ell/ell.sym     |  2 ++
 ell/netconfig.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++
 ell/netconfig.h |  2 ++
 3 files changed, 77 insertions(+)

diff --git a/ell/ell.sym b/ell/ell.sym
index 38422e7..8f4e59d 100644
--- a/ell/ell.sym
+++ b/ell/ell.sym
@@ -758,6 +758,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:
 	*;
 };
diff --git a/ell/netconfig.c b/ell/netconfig.c
index b4e9802..d4487bd 100644
--- a/ell/netconfig.c
+++ b/ell/netconfig.c
@@ -1808,3 +1808,76 @@ LIB_EXPORT const struct l_queue_entry *l_netconfig_get_routes(
 
 	return l_queue_get_entries(netconfig->routes.current);
 }
+
+static void netconfig_strv_cat(char ***dest, char **src, bool free)
+{
+	unsigned int dest_len;
+	unsigned int src_len;
+
+	if (!src)
+		return;
+
+	if (!free)
+		src = l_strv_copy(src);
+
+	if (!*dest) {
+		*dest = src;
+		return;
+	}
+
+	dest_len = l_strv_length(*dest);
+	src_len = l_strv_length(src);
+	*dest = l_realloc(*dest, sizeof(char *) * (dest_len + src_len + 1));
+	memcpy(*dest + dest_len, src, sizeof(char *) * (src_len + 1));
+	l_free(src);
+}
+
+/* Returns a new strv array to be freed by the caller */
+LIB_EXPORT char **l_netconfig_get_dns_list(struct l_netconfig *netconfig)
+{
+	char **ret = NULL;
+	const struct l_dhcp_lease *v4_lease;
+	const struct l_dhcp6_lease *v6_lease;
+
+	if (netconfig->v4_dns_override)
+		netconfig_strv_cat(&ret, netconfig->v4_dns_override, false);
+	else if ((v4_lease =
+			l_dhcp_client_get_lease(netconfig->dhcp_client)))
+		netconfig_strv_cat(&ret, l_dhcp_lease_get_dns(v4_lease), true);
+
+	if (netconfig->v6_dns_override)
+		netconfig_strv_cat(&ret, netconfig->v6_dns_override, false);
+	else if ((v6_lease =
+			l_dhcp6_client_get_lease(netconfig->dhcp6_client)))
+		netconfig_strv_cat(&ret, l_dhcp6_lease_get_dns(v6_lease), true);
+
+	return ret;
+}
+
+/* Returns a new strv array to be freed by the caller */
+LIB_EXPORT char **l_netconfig_get_domain_names(struct l_netconfig *netconfig)
+{
+	char **ret = NULL;
+	const struct l_dhcp_lease *v4_lease;
+	const struct l_dhcp6_lease *v6_lease;
+
+	if (netconfig->v4_domain_names_override)
+		netconfig_strv_cat(&ret, netconfig->v4_domain_names_override,
+					false);
+	else if ((v4_lease =
+			l_dhcp_client_get_lease(netconfig->dhcp_client)) &&
+			l_dhcp_lease_get_domain_name(v4_lease)) {
+		ret = l_new(char *, 2);
+		ret[0] = l_dhcp_lease_get_domain_name(v4_lease);
+	}
+
+	if (netconfig->v6_dns_override)
+		netconfig_strv_cat(&ret, netconfig->v6_domain_names_override,
+					false);
+	else if ((v6_lease =
+			l_dhcp6_client_get_lease(netconfig->dhcp6_client)))
+		netconfig_strv_cat(&ret, l_dhcp6_lease_get_domains(v6_lease),
+					true);
+
+	return ret;
+}
diff --git a/ell/netconfig.h b/ell/netconfig.h
index d845c55..ac467b6 100644
--- a/ell/netconfig.h
+++ b/ell/netconfig.h
@@ -99,6 +99,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
 }
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] netconfig: Add getters for DNS addresses and domain names
  2022-06-22  0:57 [PATCH] netconfig: Add getters for DNS addresses and domain names Andrew Zaborowski
@ 2022-06-22 20:49 ` Denis Kenzior
  0 siblings, 0 replies; 2+ messages in thread
From: Denis Kenzior @ 2022-06-22 20:49 UTC (permalink / raw)
  To: Andrew Zaborowski, ell

Hi Andrew,

On 6/21/22 19:57, Andrew Zaborowski wrote:
> ---
>   ell/ell.sym     |  2 ++
>   ell/netconfig.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++
>   ell/netconfig.h |  2 ++
>   3 files changed, 77 insertions(+)
> 

Applied, thanks.

Regards,
-Denis


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-06-22 20:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-22  0:57 [PATCH] netconfig: Add getters for DNS addresses and domain names Andrew Zaborowski
2022-06-22 20:49 ` Denis Kenzior

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).