From nobody Fri Sep 11 05:04:26 2026 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hh2XC2clNz6rbFS for ; Fri, 11 Sep 2026 05:04:27 +0000 (UTC) (envelope-from git@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) key-exchange x25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "YR2" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4hh2XB6wyTz4BqX for ; Fri, 11 Sep 2026 05:04:26 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1789103067; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=S0ktIVAouurbZluYOUzhdsYur/yKIR3HPVAtoqILL4c=; b=YcoPMk8SQp7cSM6Z1n8N1msYmzIrNYKH1nrTOHxZt6l75ltXAQn+U+u1rDQWHdGgRf+PR2 dOD4g1eaUot9ZgcZ10gW5J3tgB0lB/W+ZAYywVK+FrI6ZimT5b/BoPgIhKWXVzLw9f4H8V eW6t3xClsXi+41KXf7LndpeDmjMPn7TzQjZAZ5bp13iL6xgpJHtw8Y1Kbv12N6jYCUqbtg bSs+BIrLKeMRL5JfG84wyBym9+09mmlgm8pzkoU5yDSgXBWUxuxbx6SxJvfHRIpVpMaRPk XzvR8XumNPMr5z0SEOl3fYJZou7SNvcPI8549Yr5yoiWKsXiftPmdNIytlL9pg== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1789103067; b=aOYORjXf6O52erj2lIqbuT7gCJ9IgRmAUAt2v19sxSsYeLkwghtgCTC8JBoe9F4vuF2hMY a99X6MCm9MIe0frtHwKDvDJ1IrFtUabbt16SwufWptsLzLVlaNN3SdsbOd5cfv5BjirUSX l81b/E+tYi6D6heq6Es54I/ht4uBiUVYLYR0jzqpZyRL4+aqJK5RZxfHwIg54GiitegqAD B603RhrhqnrIJ2IZbUgYE1mzkmM73TGVGAQndCUpMGT/HaRRle/U+7IjSJMdU3oq0IfMo/ pU0Ub9wyY9X8PG8wA14816yBsTEf/7UQMDJp3kOf/PRPjnhdAXNXS5pew4U0dg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1789103067; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=S0ktIVAouurbZluYOUzhdsYur/yKIR3HPVAtoqILL4c=; b=VFEgX2l1HqCOqqhBUE+DB5Joaus0ov0X6p7rW0iroRpiMh05wU3aLMp7wk4hhtwGthjN83 5tdSlpEIVdlWW5CRzhGTlc9LROJskqMs7MtFVaQfvAh7CwKAX98g0M09EYBbBlNLpjWs6+ aJgwCbWqEXmR0DAOsRyCWYmcDGQ7x4ObNCHWEyCB6KYvSk3MaCIZb3rtT0x8kmovYPItVv bh7IQtR/AYbNay1BEAv5xGhg/n6dhSylk6U4IdrxfSmWjlbZ0kxfMsFUwdBMN5Cta9l1wL ooK3vOGd0SpiWjCMSq831H6O8Cy8Mcl2aExhyQzT0RD8g00kVC/pnE4/i00q1Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hh2XB5vGNzyx1 for ; Fri, 11 Sep 2026 05:04:26 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 3bf0a by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Fri, 11 Sep 2026 05:04:26 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: e6b997c73c41 - main - loader: add standalone network configuration List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: e6b997c73c41dd8cf42afbc86215fe9c312d5096 Auto-Submitted: auto-generated Date: Fri, 11 Sep 2026 05:04:26 +0000 Message-Id: <6aa38bda.3bf0a.5b1dce00@gitrepo.freebsd.org> The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=e6b997c73c41dd8cf42afbc86215fe9c312d5096 commit e6b997c73c41dd8cf42afbc86215fe9c312d5096 Author: Warner Losh AuthorDate: 2026-09-11 04:14:06 +0000 Commit: Warner Losh CommitDate: 2026-09-11 04:15:28 +0000 loader: add standalone network configuration Allow callers to obtain DHCP configuration without opening a network file, enabling loader.efi to discover an initmd URL before handing the interface back to firmware HTTP. Differential Revision: https://reviews.freebsd.org/D59429 Sponsored by: Netflix --- stand/common/dev_net.c | 83 ++++++++++++++++++++++++++++++++++---------------- stand/common/dev_net.h | 1 + 2 files changed, 57 insertions(+), 27 deletions(-) diff --git a/stand/common/dev_net.c b/stand/common/dev_net.c index d1c48d40691a..897b09c648eb 100644 --- a/stand/common/dev_net.c +++ b/stand/common/dev_net.c @@ -82,6 +82,7 @@ static int net_strategy(void *, int, daddr_t, size_t, char *, size_t *); static int net_print(int); static int net_getparams(int sock); +static void net_setparams(int sock); struct devsw netdev = { .dv_name = "net", @@ -118,7 +119,6 @@ net_init(void) static int net_open(struct open_file *f, ...) { - struct iodesc *d; va_list args; struct devdesc *dev; const char *devname; /* Device part of file name (or NULL). */ @@ -161,38 +161,36 @@ net_open(struct open_file *f, ...) return (error); } } - /* - * Set the variables required by the kernel's nfs_diskless - * mechanism. This is the minimum set of variables required to - * mount a root filesystem without needing to obtain additional - * info from bootp or other sources. - */ - d = socktodesc(netdev_sock); - setenv("boot.netif.hwaddr", ether_sprintf(d->myea), 1); - setenv("boot.netif.ip", inet_ntoa(myip), 1); - setenv("boot.netif.netmask", intoa(netmask), 1); - setenv("boot.netif.gateway", inet_ntoa(gateip), 1); - setenv("boot.netif.server", inet_ntoa(rootip), 1); - if (netproto == NET_TFTP) { - setenv("boot.tftproot.server", inet_ntoa(rootip), 1); - setenv("boot.tftproot.path", rootpath, 1); - } else if (netproto == NET_NFS) { - setenv("boot.nfsroot.server", inet_ntoa(rootip), 1); - setenv("boot.nfsroot.path", rootpath, 1); - } - if (intf_mtu != 0) { - char mtu[16]; - snprintf(mtu, sizeof(mtu), "%u", intf_mtu); - setenv("boot.netif.mtu", mtu, 1); - } - - DEBUG_PRINTF(1,("%s: netproto=%d\n", __func__, netproto)); + net_setparams(netdev_sock); } netdev_opens++; dev->d_opendata = &netdev_sock; return (error); } +/* + * Configure a network interface without opening a file on it. This is used + * by consumers which need DHCP configuration before switching to a firmware + * network protocol. + */ +int +net_configure(struct devdesc *dev) +{ + int error, sock; + + sock = netif_open(dev); + if (sock < 0) + return (ENXIO); + + error = 0; + if (rootip.s_addr == 0) + error = net_getparams(sock); + if (error == 0) + net_setparams(sock); + netif_close(sock); + return (error); +} + static int net_close(struct open_file *f) { @@ -319,6 +317,37 @@ exit: return (0); } +static void +net_setparams(int sock) +{ + struct iodesc *d; + + /* + * Set the variables required by the kernel's nfs_diskless mechanism. + */ + d = socktodesc(sock); + setenv("boot.netif.hwaddr", ether_sprintf(d->myea), 1); + setenv("boot.netif.ip", inet_ntoa(myip), 1); + setenv("boot.netif.netmask", intoa(netmask), 1); + setenv("boot.netif.gateway", inet_ntoa(gateip), 1); + setenv("boot.netif.server", inet_ntoa(rootip), 1); + if (netproto == NET_TFTP) { + setenv("boot.tftproot.server", inet_ntoa(rootip), 1); + setenv("boot.tftproot.path", rootpath, 1); + } else if (netproto == NET_NFS) { + setenv("boot.nfsroot.server", inet_ntoa(rootip), 1); + setenv("boot.nfsroot.path", rootpath, 1); + } + if (intf_mtu != 0) { + char mtu[16]; + + snprintf(mtu, sizeof(mtu), "%u", intf_mtu); + setenv("boot.netif.mtu", mtu, 1); + } + + DEBUG_PRINTF(1,("%s: netproto=%d\n", __func__, netproto)); +} + static int net_print(int verbose) { diff --git a/stand/common/dev_net.h b/stand/common/dev_net.h index 189508854dc5..5cf6652c96af 100644 --- a/stand/common/dev_net.h +++ b/stand/common/dev_net.h @@ -29,6 +29,7 @@ extern struct devsw netdev; +int net_configure(struct devdesc *); uint32_t net_parse_rootpath(void); #endif