From patchwork Wed Jun 6 12:32:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 137825 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp743719lji; Wed, 6 Jun 2018 05:32:34 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLr1YUl+szgxstypnlPznln2qG+z2XA71CEeeNu2EEVqG4aqfwv2orAWqbMgysmz+yWhzia X-Received: by 2002:a50:8b96:: with SMTP id m22-v6mr3610337edm.165.1528288354803; Wed, 06 Jun 2018 05:32:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528288354; cv=none; d=google.com; s=arc-20160816; b=pTGTSC8b5Fqc63ePh2f7+D62GmWcfM/BSC5+Af6Gx4gnYN4ETkh8j1Qr0bOOCdPQa8 qEMdWWZRht+poIGzd1NlHElfdx+nYFxSwbot9ktX+z6Ltf5KhWGeGl3I1F9laCG7+Hwo etdpa8OXZv2YAiyoVPEffVW5oNe8GiCUKW7TN8LCRyJREIXxFVXjErkIW+aAUH3P31aV 4NKsIf7rbnJaMyJkyYaBIoyn4dw3d1MEeQfYd6+UJdm9ZqGgJnPFvcEoXGQEEELCG3Yz 6+B4C+sop0tPlXvAlUm9R+eCN7w06/76zphEup9OrIg5xNVYpvVdRnKh3CFEYD1aPXdc EvVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:message-id:date:to:from :arc-authentication-results; bh=KAp2QL/6TwiQnPTMWv4qaRsbtp7dpJbnEeH+YLPvlk8=; b=TMIJz8cKBVUy7Qc44WOQkRDtgePFLNGg63jHyGSPUFWOyEJwPJWuIAsb+rKkQ4CJvk 8+2S+V8qSNJKzTQQeFe/4oSypcQLNMAxwjz7kBBM8rW83R1qCxy138+I8lTjdGQYMNFe 7AbnBNuyQ6jROPy/WQVH3ndqGb2KlC2QIZyU/MR316Pv4HAsU6LT5IPl/OQIM5xwhKAi 1rZGwFosfLkn9LG1Jjt1qwsrLvl9ztym5AC1ntTusppM7/Od8nr+PZQ57tXYGf4+DdkL iQdiNS2xbfevKZW1McKEOfu3fjCn0qtw/BUVOZbY28u9vx9PhB2jcFdjH2vDRtVxJNhE jZ5w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id i43-v6si1146124ede.243.2018.06.06.05.32.34; Wed, 06 Jun 2018 05:32:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by lists.denx.de (Postfix, from userid 105) id 5C06DC21C57; Wed, 6 Jun 2018 12:32:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_DNSWL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 09DE8C21FDA; Wed, 6 Jun 2018 12:32:08 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id AD0B6C21C38; Wed, 6 Jun 2018 12:32:05 +0000 (UTC) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by lists.denx.de (Postfix) with ESMTPS id 4CA20C21C50 for ; Wed, 6 Jun 2018 12:32:05 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext-too.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id DCDAEAEB5; Wed, 6 Jun 2018 12:32:04 +0000 (UTC) From: Alexander Graf To: u-boot@lists.denx.de Date: Wed, 6 Jun 2018 14:32:01 +0200 Message-Id: <20180606123202.53631-1-agraf@suse.de> X-Mailer: git-send-email 2.12.3 Cc: Joe Hershberger Subject: [U-Boot] [PATCH 1/2] net: Add option to prefer bootp/dhcp serverip X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" 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 --- 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);