All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Send hostname as part of DHCP request.
@ 2021-06-18 14:00 mjohnson459
  2021-06-18 15:22 ` Denis Kenzior
  0 siblings, 1 reply; 5+ messages in thread
From: mjohnson459 @ 2021-06-18 14:00 UTC (permalink / raw)
  To: iwd

[-- 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

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

* Re: [PATCH] Send hostname as part of DHCP request.
  2021-06-18 14:00 [PATCH] Send hostname as part of DHCP request mjohnson459
@ 2021-06-18 15:22 ` Denis Kenzior
  2021-06-18 15:49   ` Michael Johnson
  2021-06-18 17:40   ` [PATCH v2] " Michael Johnson
  0 siblings, 2 replies; 5+ messages in thread
From: Denis Kenzior @ 2021-06-18 15:22 UTC (permalink / raw)
  To: iwd

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

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.

> 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...

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

<snip>

> 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");
> +		}

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?

> +	}
> +
>   	netconfig_ipv4_select_and_install(netconfig);
>   
>   	netconfig_ipv6_select_and_install(netconfig);
> 

Regards,
-Denis

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

* Re: [PATCH] Send hostname as part of DHCP request.
  2021-06-18 15:22 ` Denis Kenzior
@ 2021-06-18 15:49   ` Michael Johnson
  2021-06-18 17:40   ` [PATCH v2] " Michael Johnson
  1 sibling, 0 replies; 5+ messages in thread
From: Michael Johnson @ 2021-06-18 15:49 UTC (permalink / raw)
  To: iwd

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

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

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

* [PATCH v2] Send hostname as part of DHCP request.
  2021-06-18 15:22 ` Denis Kenzior
  2021-06-18 15:49   ` Michael Johnson
@ 2021-06-18 17:40   ` Michael Johnson
  2021-06-18 18:11     ` Denis Kenzior
  1 sibling, 1 reply; 5+ messages in thread
From: Michael Johnson @ 2021-06-18 17:40 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 2142 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     | 16 ++++++++++++++++
 2 files changed, 22 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..005316cd 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,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);
-- 
2.25.1

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

* Re: [PATCH v2] Send hostname as part of DHCP request.
  2021-06-18 17:40   ` [PATCH v2] " Michael Johnson
@ 2021-06-18 18:11     ` Denis Kenzior
  0 siblings, 0 replies; 5+ messages in thread
From: Denis Kenzior @ 2021-06-18 18:11 UTC (permalink / raw)
  To: iwd

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

Hi Michael,

On 6/18/21 12:40 PM, Michael Johnson wrote:
> 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

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

end of thread, other threads:[~2021-06-18 18:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-18 14:00 [PATCH] Send hostname as part of DHCP request mjohnson459
2021-06-18 15:22 ` 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

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.