Wireless Daemon for Linux
 help / color / mirror / Atom feed
From: Tim Kourt <tim.a.kourt@linux.intel.com>
To: iwd@lists.01.org
Subject: [PATCH v2 1/2] netconfig: Add IPv4 domain name helper and installer
Date: Tue, 10 Dec 2019 08:49:02 -0800	[thread overview]
Message-ID: <20191210164903.21122-1-tim.a.kourt@linux.intel.com> (raw)

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

The provided domain name helper allows to override the DHCP lease
option value with the static one from network configuration file.
---
 src/netconfig.c | 34 +++++++++++++++++++++++++++++++++-
 1 file changed, 33 insertions(+), 1 deletion(-)

diff --git a/src/netconfig.c b/src/netconfig.c
index 9d32c37a..e7176444 100644
--- a/src/netconfig.c
+++ b/src/netconfig.c
@@ -251,6 +251,28 @@ static char **netconfig_ipv4_get_dns(struct netconfig *netconfig, uint8_t proto)
 	return NULL;
 }
 
+static char *netconfig_ipv4_get_domain_name(struct netconfig *netconfig,
+								uint8_t proto)
+{
+	const struct l_dhcp_lease *lease;
+	char *domain_name;
+
+	domain_name = l_settings_get_string(netconfig->active_settings,
+							"IPv4", "DomainName");
+	if (domain_name)
+		/* Allow to override the DHCP domain name with setting entry. */
+		return domain_name;
+
+	if (proto != RTPROT_DHCP)
+		return NULL;
+
+	lease = l_dhcp_client_get_lease(netconfig->dhcp_client);
+	if (!lease)
+		return NULL;
+
+	return l_dhcp_lease_get_domain_name(lease);
+}
+
 static struct netconfig_ifaddr *netconfig_ipv6_get_ifaddr(
 						struct netconfig *netconfig,
 						uint8_t proto)
@@ -685,6 +707,7 @@ static void netconfig_ipv4_ifaddr_add_cmd_cb(int error, uint16_t type,
 	struct netconfig *netconfig = user_data;
 	struct netconfig_ifaddr *ifaddr;
 	char **dns;
+	char *domain_name;
 
 	if (error && error != -EEXIST) {
 		l_error("netconfig: Failed to add IP address. "
@@ -709,12 +732,21 @@ static void netconfig_ipv4_ifaddr_add_cmd_cb(int error, uint16_t type,
 	dns = netconfig_ipv4_get_dns(netconfig, netconfig->rtm_protocol);
 	if (!dns) {
 		l_error("netconfig: Failed to obtain DNS addresses.");
-		goto done;
+		goto domain_name;
 	}
 
 	resolve_add_dns(netconfig->ifindex, ifaddr->family, dns);
 	l_strv_free(dns);
 
+domain_name:
+	domain_name = netconfig_ipv4_get_domain_name(netconfig,
+						netconfig->rtm_protocol);
+	if (!domain_name)
+		goto done;
+
+	resolve_add_domain_name(netconfig->ifindex, domain_name);
+	l_free(domain_name);
+
 done:
 	netconfig_ifaddr_destroy(ifaddr);
 }
-- 
2.13.6

             reply	other threads:[~2019-12-10 16:49 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-10 16:49 Tim Kourt [this message]
2019-12-10 16:49 ` [PATCH v2 2/2] resolve: Add systemd-resolved domain name installer Tim Kourt

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=20191210164903.21122-1-tim.a.kourt@linux.intel.com \
    --to=tim.a.kourt@linux.intel.com \
    --cc=iwd@lists.01.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox