Commit bdce340cc6a17efe1d980eda378c3b1984059362

Authored by Alexander Graf
Committed by Joe Hershberger
1 parent 449312c1c0

net: Add option to prefer bootp/dhcp serverip

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>

Showing 2 changed files with 16 additions and 1 deletions Side-by-side Diff

... ... @@ -1121,6 +1121,16 @@
1121 1121 help
1122 1122 The name may or may not be qualified with the local domain name.
1123 1123  
  1124 +config BOOTP_PREFER_SERVERIP
  1125 + bool "serverip variable takes precedent over DHCP server IP."
  1126 + depends on CMD_BOOTP
  1127 + help
  1128 + By default a BOOTP/DHCP reply will overwrite the 'serverip' variable.
  1129 +
  1130 + With this option enabled, the 'serverip' variable in the environment
  1131 + takes precedence over DHCP server IP and will only be set by the DHCP
  1132 + server if not already set in the environment.
  1133 +
1124 1134 config BOOTP_SUBNETMASK
1125 1135 bool "Request & store 'netmask' from BOOTP/DHCP server"
1126 1136 default y
... ... @@ -147,9 +147,14 @@
147 147 {
148 148 #if !defined(CONFIG_BOOTP_SERVERIP)
149 149 struct in_addr tmp_ip;
  150 + bool overwrite_serverip = true;
150 151  
  152 +#if defined(CONFIG_BOOTP_PREFER_SERVERIP)
  153 + overwrite_serverip = false;
  154 +#endif
  155 +
151 156 net_copy_ip(&tmp_ip, &bp->bp_siaddr);
152   - if (tmp_ip.s_addr != 0)
  157 + if (tmp_ip.s_addr != 0 && (overwrite_serverip || !net_server_ip.s_addr))
153 158 net_copy_ip(&net_server_ip, &bp->bp_siaddr);
154 159 memcpy(net_server_ethaddr,
155 160 ((struct ethernet_hdr *)net_rx_packet)->et_src, 6);