All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Zaborowski <andrew.zaborowski at intel.com>
To: ell at lists.01.org
Subject: [PATCH 09/12] netconfig: Add getters for DNS addresses and domain names
Date: Thu, 21 Apr 2022 17:45:22 +0200	[thread overview]
Message-ID: <20220421154525.1416984-9-andrew.zaborowski@intel.com> (raw)
In-Reply-To: 20220421154525.1416984-1-andrew.zaborowski@intel.com

[-- Attachment #1: Type: text/plain, Size: 3297 bytes --]

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

diff --git a/ell/ell.sym b/ell/ell.sym
index 0f9f884..0ce604b 100644
--- a/ell/ell.sym
+++ b/ell/ell.sym
@@ -755,6 +755,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 d242375..e757103 100644
--- a/ell/netconfig.c
+++ b/ell/netconfig.c
@@ -1325,3 +1325,67 @@ LIB_EXPORT const struct l_queue_entry *l_netconfig_get_routes(
 
 	return l_queue_get_entries(netconfig->routes.current);
 }
+
+/* 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;
+
+#define CONCAT(dest, src, free)		\
+	do {				\
+		char **tmp = src;	\
+		tmp = free ? tmp : l_strv_copy(tmp);	\
+		if (!dest)		\
+			dest = tmp;	\
+		else if (tmp) {		\
+			unsigned int destlen = l_strv_length(dest);	\
+			unsigned int srclen = l_strv_length(tmp);	\
+			dest = l_realloc(dest, sizeof(char *) *	\
+				(destlen + srclen + 1));	\
+			memcpy(dest + destlen, tmp, sizeof(char *) *	\
+					(srclen + 1));	\
+			l_free(tmp);	\
+		}			\
+	} while (0)
+
+	if (netconfig->v4_dns_override)
+		CONCAT(ret, netconfig->v4_dns_override, false);
+	else if ((v4_lease =
+			l_dhcp_client_get_lease(netconfig->dhcp_client)))
+		CONCAT(ret, l_dhcp_lease_get_dns(v4_lease), true);
+
+	if (netconfig->v6_dns_override)
+		CONCAT(ret, netconfig->v6_dns_override, false);
+	else if ((v6_lease =
+			l_dhcp6_client_get_lease(netconfig->dhcp6_client)))
+		CONCAT(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)
+		CONCAT(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)
+		CONCAT(ret, netconfig->v6_domain_names_override, false);
+	else if ((v6_lease =
+			l_dhcp6_client_get_lease(netconfig->dhcp6_client)))
+		CONCAT(ret, l_dhcp6_lease_get_domains(v6_lease), true);
+
+	return ret;
+}
diff --git a/ell/netconfig.h b/ell/netconfig.h
index 7796a2f..8bb0c0e 100644
--- a/ell/netconfig.h
+++ b/ell/netconfig.h
@@ -97,6 +97,8 @@ const struct l_queue_entry *l_netconfig_get_routes(
 				const struct l_queue_entry **out_added,
 				const struct l_queue_entry **out_updated,
 				const struct l_queue_entry **out_removed);
+char **l_netconfig_get_dns_list(struct l_netconfig *netconfig);
+char **l_netconfig_get_domain_names(struct l_netconfig *netconfig);
 
 #ifdef __cplusplus
 }
-- 
2.32.0

                 reply	other threads:[~2022-04-21 15:45 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220421154525.1416984-9-andrew.zaborowski@intel.com \
    --to=unknown@example.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.