From: Alexander Graf <agraf@suse.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 2/3] net: Add option to prefer bootp/dhcp serverip
Date: Thu, 14 Jun 2018 12:04:25 +0200 [thread overview]
Message-ID: <20180614100426.40511-3-agraf@suse.de> (raw)
In-Reply-To: <20180614100426.40511-1-agraf@suse.de>
Currently we can choose between 2 different types of behavior for the
serverip variable:
1) Always overwrite it with the DHCP server IP address (default)
2) Ignore what the DHCP server says (CONFIG_BOOTP_SERVERIP)
This patch adds a 3rd option:
3) Use serverip from DHCP if no serverip is given
(CONFIG_BOOTP_PREFER_SERVERIP)
With this new option, we can have the default case that a boot file gets
loaded from the DHCP provided TFTP server work while allowing users to
specify their own serverip variable to explicitly use a different tftp
server.
Signed-off-by: Alexander Graf <agraf@suse.de>
---
v1 -> v2:
- remove README entry
- improve Kconfig help texts
---
cmd/Kconfig | 11 +++++++++++
net/bootp.c | 7 ++++++-
2 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/cmd/Kconfig b/cmd/Kconfig
index e283cb9a8a..80a5af8a0c 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -1121,6 +1121,17 @@ config BOOTP_HOSTNAME
help
The name may or may not be qualified with the local domain name.
+config BOOTP_PREFER_SERVERIP
+ bool "Serverip variable takes precedent over DHCP server IP.
+ default n
+ depends on CMD_BOOTP
+ help
+ By default a BOOTP/DHCP reply will overwrite the 'serverip' variable.
+
+ With this option enabled, the 'serverip' variable in the environment
+ takes precedence over DHCP server IP and will only be set by the DHCP
+ server if not already set in the environment.
+
config BOOTP_SUBNETMASK
bool "Request & store 'netmask' from BOOTP/DHCP server"
default y
diff --git a/net/bootp.c b/net/bootp.c
index f3da8572b7..154c71d694 100644
--- a/net/bootp.c
+++ b/net/bootp.c
@@ -147,9 +147,14 @@ static void store_net_params(struct bootp_hdr *bp)
{
#if !defined(CONFIG_BOOTP_SERVERIP)
struct in_addr tmp_ip;
+ bool overwrite_serverip = true;
+
+#if defined(CONFIG_BOOTP_PREFER_SERVERIP)
+ overwrite_serverip = false;
+#endif
net_copy_ip(&tmp_ip, &bp->bp_siaddr);
- if (tmp_ip.s_addr != 0)
+ if (tmp_ip.s_addr != 0 && (overwrite_serverip || !net_server_ip.s_addr))
net_copy_ip(&net_server_ip, &bp->bp_siaddr);
memcpy(net_server_ethaddr,
((struct ethernet_hdr *)net_rx_packet)->et_src, 6);
--
2.12.3
next prev parent reply other threads:[~2018-06-14 10:04 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-14 10:04 [U-Boot] [PATCH v2 0/3] net: Sanitize DHCP variable override Alexander Graf
2018-06-14 10:04 ` [U-Boot] [PATCH v2 1/3] net: Prefer command line arguments Alexander Graf
2018-06-14 16:34 ` Joe Hershberger
2018-06-14 10:04 ` Alexander Graf [this message]
2018-06-14 16:57 ` [U-Boot] [PATCH v2 2/3] net: Add option to prefer bootp/dhcp serverip Joe Hershberger
2018-06-14 10:04 ` [U-Boot] [PATCH v2 3/3] ax25: Switch to CONFIG_BOOTP_PREFER_SERVERIP Alexander Graf
2018-06-14 16:58 ` Joe Hershberger
2018-06-15 8:24 ` Alexander Graf
2018-06-15 20:08 ` Joe Hershberger
2018-06-15 20:33 ` Alexander Graf
2018-06-15 20:36 ` Joe Hershberger
2018-06-15 20:39 ` Alexander Graf
[not found] ` <752D002CFF5D0F4FA35C0100F1D73F3F6B7A657C@ATCPCS16.andestech.com>
2018-06-15 6:12 ` [U-Boot] [PATCH v2 0/3] net: Sanitize DHCP variable override Rick Chen
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=20180614100426.40511-3-agraf@suse.de \
--to=agraf@suse.de \
--cc=u-boot@lists.denx.de \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox