[U-Boot] [PATCH 1/2] net: Add option to prefer bootp/dhcp serverip
Alexander Graf
agraf at suse.de
Wed Jun 6 12:32:01 UTC 2018
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 at suse.de>
---
README | 5 +++++
cmd/Kconfig | 9 +++++++++
net/bootp.c | 7 ++++++-
3 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/README b/README
index fb331f910d..d8a99281ca 100644
--- a/README
+++ b/README
@@ -1511,10 +1511,15 @@ The following options need to be configured:
CONFIG_BOOTP_TIMEOFFSET
CONFIG_BOOTP_VENDOREX
CONFIG_BOOTP_MAY_FAIL
+ CONFIG_BOOTP_PREFER_SERVERIP
CONFIG_BOOTP_SERVERIP - TFTP server will be the serverip
environment variable, not the BOOTP server.
+ CONFIG_BOOTP_PREFER_SERVERIP - TFTP server will be the
+ serverip environment variable if previously unset, otherwise
+ the DHCP provided serverip is used.
+
CONFIG_BOOTP_MAY_FAIL - If the DHCP server is not found
after the configured retry count, the call will fail
instead of starting over. This can be used to fail over
diff --git a/cmd/Kconfig b/cmd/Kconfig
index e283cb9a8a..e77a4131b3 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -1121,6 +1121,15 @@ config BOOTP_HOSTNAME
help
The name may or may not be qualified with the local domain name.
+config BOOTP_PREFER_SERVERIP
+ bool "Leave serverip variable in place if existing"
+ default n
+ depends on CMD_BOOTP
+ help
+ By default a BOOTP/DHCP reply will overwrite the tftp target ip
+ address. With this option enabled, it will leave it alone if
+ already specified, but populate it if no serverip is specified.
+
config BOOTP_SUBNETMASK
bool "Request & store 'netmask' from BOOTP/DHCP server"
default y
diff --git a/net/bootp.c b/net/bootp.c
index 9d7cb5d30c..91de4cd426 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
More information about the U-Boot
mailing list