All of lore.kernel.org
 help / color / mirror / Atom feed
From: mjohnson459@gmail.com
To: iwd@lists.01.org
Subject: [PATCH] Send hostname as part of DHCP request.
Date: Fri, 18 Jun 2021 14:00:06 +0000	[thread overview]
Message-ID: <20210618140006.2820.65634@ml01.vlan13.01.org> (raw)

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

This is based on a previous patch by Roberto Santalla Fernández.

A new config is introduced into the network config file under IPv4
called SendHostname. If this is set to true then we add the hostname
into all DHCP requests. The default is false.
---
 src/iwd.network.rst |  6 ++++++
 src/netconfig.c     | 15 +++++++++++++++
 2 files changed, 21 insertions(+)

diff --git a/src/iwd.network.rst b/src/iwd.network.rst
index 083b2103..472caca8 100644
--- a/src/iwd.network.rst
+++ b/src/iwd.network.rst
@@ -322,6 +322,12 @@ network configuration with the static addresses.
        `optional`. DomainName setting can be used to override the DomainName
        value obtained from the DHCP server.
 
+   * - SendHostname
+     - Values: true, **false**
+
+       Configures DHCP to include the hostname in the request. This setting
+       is disabled by default.
+
 The group ``[IPv6]`` contains settings for Internet Protocol version 6 (IPv6)
 network configuration.
 
diff --git a/src/netconfig.c b/src/netconfig.c
index 316431ee..eb6d80ff 100644
--- a/src/netconfig.c
+++ b/src/netconfig.c
@@ -1004,6 +1004,8 @@ bool netconfig_configure(struct netconfig *netconfig,
 				netconfig_notify_func_t notify, void *user_data)
 {
 	char *mdns;
+	char hostname[HOST_NAME_MAX + 1];
+	bool send_hostname;
 
 	netconfig->dns4_overrides = l_settings_get_string_list(active_settings,
 							"IPv4", "DNS", ' ');
@@ -1044,6 +1046,19 @@ bool netconfig_configure(struct netconfig *netconfig,
 	l_dhcp6_client_set_address(netconfig->dhcp6_client, ARPHRD_ETHER,
 							mac_address, ETH_ALEN);
 
+	if (!l_settings_get_bool(active_settings,
+					"IPv4", "SendHostname", &send_hostname))
+		send_hostname = false;
+
+	if (send_hostname) {
+		if (gethostname(hostname, sizeof(hostname)) == 0) {
+			l_dhcp_client_set_hostname(
+				netconfig->dhcp_client, hostname);
+		} else {
+			l_warn("netconfig: Unable to get hostname");
+		}
+	}
+
 	netconfig_ipv4_select_and_install(netconfig);
 
 	netconfig_ipv6_select_and_install(netconfig);
-- 
2.25.1

             reply	other threads:[~2021-06-18 14:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-18 14:00 mjohnson459 [this message]
2021-06-18 15:22 ` [PATCH] Send hostname as part of DHCP request Denis Kenzior
2021-06-18 15:49   ` Michael Johnson
2021-06-18 17:40   ` [PATCH v2] " Michael Johnson
2021-06-18 18:11     ` Denis Kenzior

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=20210618140006.2820.65634@ml01.vlan13.01.org \
    --to=mjohnson459@gmail.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 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.