Skip to content

Commit

Permalink
net: Add option to prefer bootp/dhcp serverip
Browse files Browse the repository at this point in the history
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 <[email protected]>
Acked-by: Joe Hershberger <[email protected]>
  • Loading branch information
agraf authored and jhershbe committed Jul 2, 2018
1 parent 449312c commit bdce340
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
10 changes: 10 additions & 0 deletions cmd/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -1121,6 +1121,16 @@ 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."
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
Expand Down
7 changes: 6 additions & 1 deletion net/bootp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit bdce340

Please sign in to comment.