From owner-svn-src-all@freebsd.org Fri Jul 12 00:54:21 2019 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 78C4715E2869; Fri, 12 Jul 2019 00:54:21 +0000 (UTC) (envelope-from jhibbits@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 1AC4A738BF; Fri, 12 Jul 2019 00:54:21 +0000 (UTC) (envelope-from jhibbits@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 0E4636E98; Fri, 12 Jul 2019 00:54:21 +0000 (UTC) (envelope-from jhibbits@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x6C0sKmB082458; Fri, 12 Jul 2019 00:54:20 GMT (envelope-from jhibbits@FreeBSD.org) Received: (from jhibbits@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x6C0sK8F082457; Fri, 12 Jul 2019 00:54:20 GMT (envelope-from jhibbits@FreeBSD.org) Message-Id: <201907120054.x6C0sK8F082457@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jhibbits set sender to jhibbits@FreeBSD.org using -f From: Justin Hibbits Date: Fri, 12 Jul 2019 00:54:20 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r349928 - in head/stand: efi/libefi libsa X-SVN-Group: head X-SVN-Commit-Author: jhibbits X-SVN-Commit-Paths: in head/stand: efi/libefi libsa X-SVN-Commit-Revision: 349928 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 1AC4A738BF X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.93 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.93)[-0.929,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 12 Jul 2019 00:54:21 -0000 Author: jhibbits Date: Fri Jul 12 00:54:20 2019 New Revision: 349928 URL: https://svnweb.freebsd.org/changeset/base/349928 Log: Allow efi loader to get network params from uboot Summary: efi loader does not work with static network parameters. It always uses BOOTP/DHCP and also uses RARP as a fallback. Problems with DHCP servers can cause the loader to fail to populate network parameters. Submitted by: Siddharth Tuli Reviewed by: imp Sponsored by: Juniper Networks, Inc. Differential Revision: https://reviews.freebsd.org/D20811 Modified: head/stand/efi/libefi/efinet.c head/stand/libsa/net.h Modified: head/stand/efi/libefi/efinet.c ============================================================================== --- head/stand/efi/libefi/efinet.c Fri Jul 12 00:50:33 2019 (r349927) +++ head/stand/efi/libefi/efinet.c Fri Jul 12 00:54:20 2019 (r349928) @@ -40,6 +40,8 @@ __FBSDID("$FreeBSD$"); #include #include +#include "dev_net.h" + static EFI_GUID sn_guid = EFI_SIMPLE_NETWORK_PROTOCOL; static void efinet_end(struct netif *); @@ -198,7 +200,75 @@ efinet_get(struct iodesc *desc, void **pkt, time_t tim return (ret); } +/* + * Loader uses BOOTP/DHCP and also uses RARP as a fallback to populate + * network parameters and problems with DHCP servers can cause the loader + * to fail to populate them. Allow the device to ask about the basic + * network parameters and if present use them. + */ static void +efi_env_net_params(struct iodesc *desc) +{ + char *envstr; + in_addr_t ipaddr, mask, gwaddr, serveraddr; + n_long rootaddr; + + if ((envstr = getenv("rootpath")) != NULL) + strlcpy(rootpath, envstr, sizeof(rootpath)); + + /* + * Get network parameters. + */ + envstr = getenv("ipaddr"); + ipaddr = (envstr != NULL) ? inet_addr(envstr) : 0; + + envstr = getenv("netmask"); + mask = (envstr != NULL) ? inet_addr(envstr) : 0; + + envstr = getenv("gatewayip"); + gwaddr = (envstr != NULL) ? inet_addr(envstr) : 0; + + envstr = getenv("serverip"); + serveraddr = (envstr != NULL) ? inet_addr(envstr) : 0; + + /* No network params. */ + if (ipaddr == 0 && mask == 0 && gwaddr == 0 && serveraddr == 0) + return; + + /* Partial network params. */ + if (ipaddr == 0 || mask == 0 || gwaddr == 0 || serveraddr == 0) { + printf("Incomplete network settings from U-Boot\n"); + return; + } + + /* + * Set network parameters. + */ + myip.s_addr = ipaddr; + netmask = mask; + gateip.s_addr = gwaddr; + servip.s_addr = serveraddr; + + /* + * There must be a rootpath. It may be ip:/path or it may be just the + * path in which case the ip needs to be serverip. + */ + rootaddr = net_parse_rootpath(); + if (rootaddr == INADDR_NONE) + rootaddr = serveraddr; + rootip.s_addr = rootaddr; + +#ifdef EFINET_DEBUG + printf("%s: ip=%s\n", __func__, inet_ntoa(myip)); + printf("%s: mask=%s\n", __func__, intoa(netmask)); + printf("%s: gateway=%s\n", __func__, inet_ntoa(gateip)); + printf("%s: server=%s\n", __func__, inet_ntoa(servip)); +#endif + + desc->myip = myip; +} + +static void efinet_init(struct iodesc *desc, void *machdep_hint) { struct netif *nif = desc->io_netif; @@ -206,6 +276,9 @@ efinet_init(struct iodesc *desc, void *machdep_hint) EFI_HANDLE h; EFI_STATUS status; UINT32 mask; + + /* Attempt to get netboot params from env */ + efi_env_net_params(desc); if (nif->nif_driver->netif_ifs[nif->nif_unit].dif_unit < 0) { printf("Invalid network interface %d\n", nif->nif_unit); Modified: head/stand/libsa/net.h ============================================================================== --- head/stand/libsa/net.h Fri Jul 12 00:50:33 2019 (r349927) +++ head/stand/libsa/net.h Fri Jul 12 00:54:20 2019 (r349928) @@ -91,6 +91,7 @@ extern struct in_addr rootip; extern struct in_addr swapip; extern struct in_addr gateip; extern struct in_addr nameip; +extern struct in_addr servip; extern n_long netmask; extern u_int intf_mtu;