mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Oleksij Rempel <>
Cc: Oleksij Rempel <>
Subject: [PATCH v1] net: dhcp: send current hostname as part of the DHCP request
Date: Tue, 14 Sep 2021 08:30:01 +0200	[thread overview]
Message-ID: <> (raw)

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 <>
 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);

barebox mailing list

             reply	other threads:[~2021-09-14  6:32 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-14  6:30 Oleksij Rempel [this message]
2021-10-02  9:30 ` Sascha Hauer

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:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \

* 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