mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH v1] net: dhcp: send current hostname as part of the DHCP request
@ 2021-09-14  6:30 Oleksij Rempel
  2021-10-02  9:30 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Oleksij Rempel @ 2021-09-14  6:30 UTC (permalink / raw)
  To: barebox; +Cc: Oleksij Rempel

To be able to use more advanced DHCP server configurations, for example
host name pattern matching, barebox should send some name.

With this patch, barebox will send barebox_hostname, if dhcp.hostname is
not configured.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 net/dhcp.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/net/dhcp.c b/net/dhcp.c
index e701a5f71..427985eca 100644
--- a/net/dhcp.c
+++ b/net/dhcp.c
@@ -444,6 +444,7 @@ static char *global_dhcp_user_class;
 static char *global_dhcp_vendor_id;
 static char *global_dhcp_client_uuid;
 static char *global_dhcp_client_id;
+static char *global_dhcp_hostname;
 static char *global_dhcp_bootfile;
 static char *global_dhcp_oftree_file;
 static char *global_dhcp_rootpath;
@@ -482,6 +483,12 @@ int dhcp_request(struct eth_device *edev, const struct dhcp_req_param *param,
 		dhcp_param.client_uuid = global_dhcp_client_uuid;
 	if (!dhcp_param.client_id)
 		dhcp_param.client_id = global_dhcp_client_id;
+	if (!dhcp_param.hostname) {
+		if (global_dhcp_hostname && strlen(global_dhcp_hostname))
+			dhcp_param.hostname = global_dhcp_hostname;
+		else
+			dhcp_param.hostname = (char *)barebox_get_hostname();
+	}
 	if (!dhcp_param.option224)
 		dhcp_param.option224 = global_dhcp_option224;
 	if (!dhcp_param.retries)
@@ -636,6 +643,7 @@ static int dhcp_global_init(void)
 	globalvar_add_simple_string("dhcp.vendor_id", &global_dhcp_vendor_id);
 	globalvar_add_simple_string("dhcp.client_uuid", &global_dhcp_client_uuid);
 	globalvar_add_simple_string("dhcp.client_id", &global_dhcp_client_id);
+	globalvar_add_simple_string("dhcp.hostname", &global_dhcp_hostname);
 	globalvar_add_simple_string("dhcp.user_class", &global_dhcp_user_class);
 	globalvar_add_simple_string("dhcp.oftree_file", &global_dhcp_oftree_file);
 	globalvar_add_simple_string("dhcp.tftp_server_name", &global_dhcp_tftp_server_name);
-- 
2.30.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


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

end of thread, other threads:[~2021-10-02  9:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-14  6:30 [PATCH v1] net: dhcp: send current hostname as part of the DHCP request Oleksij Rempel
2021-10-02  9:30 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox