Skip to contentSkip to conversation

Send hostname as part of DHCP request.

PATCH Superseded [email protected] 3 participants 5 messages Jun 18, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Send hostname as part of DHCP request.

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(+)
src/iwd.network.rst +6 -0
index 083b2103..472caca8 100644
@@ -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.
 
src/netconfig.c +15 -0
index 316431ee..eb6d80ff 100644
@@ -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);
Signature · 1 line
2.25.1
#1 lore raw

Hi,

On 6/18/21 9:00 AM, mjohnson459(a)gmail.com wrote:

Can you include a proper name in the next version so it can be applied? We won't apply patches with just an email address and no proper author name.

Quoted 5 lines

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.

The patch looks fine. Just a small nitpick below...

Quoted 5 lines
---
  src/iwd.network.rst |  6 ++++++
  src/netconfig.c     | 15 +++++++++++++++
  2 files changed, 21 insertions(+)

<snip>

Quoted 18 lines
src/netconfig.c +3 -0
index 316431ee..eb6d80ff 100644
@@ -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,

src/netconfig.c bool netconfig_configure(struct netconfig *netconfig, · line 1059

Quoted 10 lines
src/netconfig.c +10 -0
+					"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");
+		}

Could you also print the errno / strerror() on the failure path so that we can easily see the reason this goes wrong in the logs?

src/netconfig.c bool netconfig_configure(struct netconfig *netconfig, · line 1064

Quoted 6 lines
src/netconfig.c +2 -0
+	}
+
  	netconfig_ipv4_select_and_install(netconfig);
 
  	netconfig_ipv6_select_and_install(netconfig);

Regards,
-Denis

#2 lore raw

Hi,

Sorry, I couldn't get git send-email to work so I just tried to use the lists.01.org interface. I'll make the suggested change and upload a new version and that should included the proper details.

Regards,
Michael

#3 lore raw

PATCH v2 1/1 Send hostname as part of DHCP request.

In reply to Denis Kenzior

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     | 16 ++++++++++++++++
 2 files changed, 22 insertions(+)
src/iwd.network.rst +6 -0
index 083b2103..472caca8 100644
@@ -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.
 
src/netconfig.c +16 -0
index 316431ee..005316cd 100644
@@ -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,20 @@ 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. "
+					"Error %d: %s", errno, strerror(errno));
+		}
+	}
+
 	netconfig_ipv4_select_and_install(netconfig);
 
 	netconfig_ipv6_select_and_install(netconfig);
Signature · 1 line
2.25.1
#4 lore raw

Hi Michael,

Quoted 10 lines · Michael Johnson

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     | 16 ++++++++++++++++
  2 files changed, 22 insertions(+)

Applied, thanks.

Regards,
-Denis