diff mbox series

[v3,2/3] net: Add option to prefer bootp/dhcp serverip

Message ID 20180615082929.82491-3-agraf@suse.de
State Accepted
Commit bdce340cc6a17efe1d980eda378c3b1984059362
Headers show
Series net: Sanitize DHCP variable override | expand

Commit Message

Alexander Graf June 15, 2018, 8:29 a.m. UTC
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(-)

Comments

Joe Hershberger June 15, 2018, 8:11 p.m. UTC | #1
On Fri, Jun 15, 2018 at 3:29 AM, Alexander Graf <agraf@suse.de> wrote:
> 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>

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Joe Hershberger July 2, 2018, 7:51 p.m. UTC | #2
Hi Alexander,

https://patchwork.ozlabs.org/patch/929826/ was applied to http://git.denx.de/?p=u-boot/u-boot-net.git

Thanks!
-Joe
diff mbox series

Patch

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 fdcb4374a0..9a2b512e4a 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);