git: 4e6cf9ee5808 - stable/13 - nfs: skip bootpc when vfs.root.mountfrom is other than nfs

From: Alfredo Dal'Ava Junior <alfredo_at_FreeBSD.org>
Date: Wed, 05 Oct 2022 21:14:59 UTC
The branch stable/13 has been updated by alfredo:

URL: https://cgit.FreeBSD.org/src/commit/?id=4e6cf9ee58080119fcd248681531ef1ca0fb5d53

commit 4e6cf9ee58080119fcd248681531ef1ca0fb5d53
Author:     Alfredo Dal'Ava Junior <alfredo@FreeBSD.org>
AuthorDate: 2022-05-31 19:03:43 +0000
Commit:     Alfredo Dal'Ava Junior <alfredo@FreeBSD.org>
CommitDate: 2022-10-06 00:13:06 +0000

    nfs: skip bootpc when vfs.root.mountfrom is other than nfs
    
    If "vfs.root.mountfrom" is set and the value is something other
    than "nfs:*", it means the user doesn't want to mount root via nfs,
    there's no reason to continue with bootpc
    
    This fixes the powerpcspe kernel (MPC85XXSPE) that's compiled with
    BOOTP_NFSROOT by default and gets stuck on bootpc/dhcp request loop
    when no DHCP server is available on the network, even when user
    specifies a local disk via "vfs.root.mountfrom" kernel parameter.
    
    Reviewed by:    imp
    MFC after:      2 weeks
    Sponsored by:   Instituto de Pesquisas Eldorado (eldorado.org.br)
    Differential Revision:  https://reviews.freebsd.org/D35098
    
    (cherry picked from commit 3cb9f1976c260821e43e6eae9d46e4ec97a8d4f1)
---
 sys/nfs/bootp_subr.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/sys/nfs/bootp_subr.c b/sys/nfs/bootp_subr.c
index cae6b7c30a71..8ce999ed5f21 100644
--- a/sys/nfs/bootp_subr.c
+++ b/sys/nfs/bootp_subr.c
@@ -1514,6 +1514,7 @@ bootpc_init(void)
 	struct thread *td;
 	int timeout;
 	int delay;
+	char *s;
 
 	timeout = BOOTP_IFACE_WAIT_TIMEOUT * hz;
 	delay = hz / 10;
@@ -1527,6 +1528,21 @@ bootpc_init(void)
 	if (nfs_diskless_valid != 0)
 		return;
 
+	/*
+	 * If "vfs.root.mountfrom" is set and the value is something other
+	 * than "nfs:", it means the user doesn't want to mount root via nfs,
+	 * there's no reason to continue with bootpc
+	 */
+	if ((s = kern_getenv("vfs.root.mountfrom")) != NULL) {
+		if ((strncmp(s, "nfs:", 4)) != 0) {
+			printf("%s: vfs.root.mountfrom set to %s. "
+			       "BOOTP aborted.\n", __func__, s);
+			freeenv(s);
+			return;
+		}
+		freeenv(s);
+	}
+
 	gctx = malloc(sizeof(*gctx), M_TEMP, M_WAITOK | M_ZERO);
 	STAILQ_INIT(&gctx->interfaces);
 	gctx->xid = ~0xFFFF;