From nobody Wed Dec 25 01:45:58 2024 X-Original-To: dev-commits-src-all@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 4YHvjf5Jyxz5h0T0; Wed, 25 Dec 2024 01:45:58 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4YHvjf39Qfz4sRQ; Wed, 25 Dec 2024 01:45:58 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1735091158; 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=ba9gzzmGMLQqv0NEJCnMnCYob6fO6LuhaFixFrwd9j8=; b=HZJga/Vo8ICunYRPu2DXCCzIJFAVCvjmQj6Pv7HCzoT3IXXiZbrHBP8aj/kWL6PIHmvbWw qrllf6DahtZ+E/PmdEzZw+4iFVwu33xSq7vcX3l9JNjwQgSo8BUfbaOpdu2f6SoCkX39bT RT7nU7agXP13F4g1fEQcCQ1tDe39mCTlsV+oLCLLgMFTZkPP3d6oUie8vA5V1LkaKmm2ga 4dT+MfqIOZK0MZN1ufoJgfjWW8VkZNsUOEjaENdf2xEUYIwyw7A/QFQ1jsl9I6Blqk+tDf lDQe50+vBa/e49T/euaSSwcsVOrOvFQv+c1FmB99Bcejzhbs7hhTTHFXNE4vUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1735091158; 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=ba9gzzmGMLQqv0NEJCnMnCYob6fO6LuhaFixFrwd9j8=; b=dnC4VJcBh/vEUq4xQEm5vRQTLf3Sn/ObOgaT3fZ6XRL+dUzxACVp7AeDVSV+zVqm0uIKCn JRdHjYpBVJdU1S5yLFpIc3w7RcuUKLS9IcUWTHIg05Umzl3ulCn9LrAqakEFy/ASqdQWho myRR1r8sF4sWO6Y03FL/AwtGWnpL0dHcADA7W++rnQ9ov3lzLbqAi4CPGpUQANOku3U3uW YUaTmQkdy5iNLAgNTAv9QJM+oOLbfvzN8Qa5KSFVnskpAeicLBDOusQ4+XvKUWG6Um4KgK zgPuHEmxnzB1grDNQz6fTZRbtVJAHcAJSKZR0IJ8t+Kqv6rh1a1bt4Kv0FHnTw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1735091158; a=rsa-sha256; cv=none; b=FT+fLKF8LwZQxn4BTfqBZMhuJezhyhYL/uqQhXY9+NuXIoaUPRzI1EzBB0PUgXadotFNX4 7qe5rU2Rzhen5lbsCEA0FOBxYdQf2hRUdQHZXcpKPhOhH2nYT5Axr8Vjr/IqFstJS+49Ms yjYSU8ypResAVnDZJHk0jP0AXZRKGRc1BWvgZ0CLiqui90DCDjD3F5q7Ek9oSHq5fe+5Ho gep5XIg8T8dFjmtnPrP/rc/15yslhX7wqIUJ0V4L0FY08Gv5l/KS0+xudiUIaOU+yGOuHl ldukNWESxfQHE44dpb4clvhrBTUWUxSTHv6wc2SZqqYjO+FYPl9ltqwXaiTwTg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4YHvjf2md3z14dc; Wed, 25 Dec 2024 01:45:58 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 4BP1jw5P022130; Wed, 25 Dec 2024 01:45:58 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4BP1jwCA022127; Wed, 25 Dec 2024 01:45:58 GMT (envelope-from git) Date: Wed, 25 Dec 2024 01:45:58 GMT Message-Id: <202412250145.4BP1jwCA022127@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Rick Macklem Subject: git: 400fcd1d4fc8 - stable/14 - mount_nfs.c: Add an NFS mount option to set a port# for Mount List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: rmacklem X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 400fcd1d4fc85212526e9f304e4e90b5668316be Auto-Submitted: auto-generated The branch stable/14 has been updated by rmacklem: URL: https://cgit.FreeBSD.org/src/commit/?id=400fcd1d4fc85212526e9f304e4e90b5668316be commit 400fcd1d4fc85212526e9f304e4e90b5668316be Author: Rick Macklem AuthorDate: 2024-12-11 23:07:05 +0000 Commit: Rick Macklem CommitDate: 2024-12-25 01:44:40 +0000 mount_nfs.c: Add an NFS mount option to set a port# for Mount Normally mount_nfs acquires the port# for the NFS server's Mount protocol (mountd(8)) via rpcbind/portmapper for NFSv3 mounts. This patch adds a new mount option, so that the mount command can specify the port# and avoid using rpcbind for NFSv3 mounts. The new option is called "mountport" since that is what Linux calls their mount option for the same semantics. PR: 282481 (cherry picked from commit 0e8a36a2ab1223ffb0cbdfd49383d8cf978cfa74) --- sbin/mount_nfs/mount_nfs.c | 56 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 49 insertions(+), 7 deletions(-) diff --git a/sbin/mount_nfs/mount_nfs.c b/sbin/mount_nfs/mount_nfs.c index f2f22e0a0ccd..5c194a1c3676 100644 --- a/sbin/mount_nfs/mount_nfs.c +++ b/sbin/mount_nfs/mount_nfs.c @@ -120,6 +120,7 @@ static u_char *fh = NULL; static int fhsize = 0; static int secflavor = -1; static int got_principal = 0; +static in_port_t mntproto_port = 0; static enum mountmode { ANY, @@ -372,6 +373,13 @@ main(int argc, char *argv[]) softintr = true; } else if (strcmp(opt, "intr") == 0) { softintr = true; + } else if (strcmp(opt, "mountport") == 0) { + num = strtol(val, &p, 10); + if (*p || num <= 0 || num > IPPORT_MAX) + errx(1, "illegal port num -- " + "%s", val); + mntproto_port = num; + pass_flag_to_nmount=0; } if (pass_flag_to_nmount) { build_iovec(&iov, &iovlen, opt, @@ -912,11 +920,47 @@ tryagain: return (TRYRET_SUCCESS); } + /* + * malloc() and copy the address, so that it can be used for + * nfsargs below. + */ + addrlen = nfs_nb.len; + addr = malloc(addrlen); + if (addr == NULL) + err(1, "malloc"); + bcopy(nfs_nb.buf, addr, addrlen); + /* Send the MOUNTPROC_MNT RPC to get the root filehandle. */ try.tv_sec = 10; try.tv_usec = 0; - clp = clnt_tp_create(hostp, MOUNTPROG, mntvers, nconf_mnt); + if (mntproto_port != 0) { + struct sockaddr *sad; + struct sockaddr_in *sin; + struct sockaddr_in6 *sin6; + + sad = (struct sockaddr *)nfs_nb.buf; + switch (sad->sa_family) { + case AF_INET: + sin = (struct sockaddr_in *)nfs_nb.buf; + sin->sin_port = htons(mntproto_port); + break; + case AF_INET6: + sin6 = (struct sockaddr_in6 *)nfs_nb.buf; + sin6->sin6_port = htons(mntproto_port); + break; + default: + snprintf(errbuf, sizeof(errbuf), + "Mnt port bad addr family %d\n", sad->sa_family); + return (TRYRET_LOCALERR); + } + clp = clnt_tli_create(RPC_ANYFD, nconf_mnt, &nfs_nb, MOUNTPROG, + mntvers, 0, 0); + } else { + /* Get the Mount protocol port# via rpcbind. */ + clp = clnt_tp_create(hostp, MOUNTPROG, mntvers, nconf_mnt); + } if (clp == NULL) { + free(addr); snprintf(errbuf, sizeof errbuf, "[%s] %s:%s: %s", netid_mnt, hostp, spec, clnt_spcreateerror("RPCMNT: clnt_create")); return (returncode(rpc_createerr.cf_stat, @@ -926,10 +970,10 @@ tryagain: nfhret.auth = secflavor; nfhret.vers = mntvers; clntstat = clnt_call(clp, MOUNTPROC_MNT, (xdrproc_t)xdr_dir, spec, - (xdrproc_t)xdr_fh, &nfhret, - try); + (xdrproc_t)xdr_fh, &nfhret, try); auth_destroy(clp->cl_auth); if (clntstat != RPC_SUCCESS) { + free(addr); if (clntstat == RPC_PROGVERSMISMATCH && trymntmode == ANY) { clnt_destroy(clp); trymntmode = V2; @@ -944,6 +988,7 @@ tryagain: clnt_destroy(clp); if (nfhret.stat != 0) { + free(addr); snprintf(errbuf, sizeof errbuf, "[%s] %s:%s: %s", netid_mnt, hostp, spec, strerror(nfhret.stat)); return (TRYRET_REMOTEERR); @@ -953,13 +998,10 @@ tryagain: * Store the filehandle and server address in nfsargsp, making * sure to copy any locally allocated structures. */ - addrlen = nfs_nb.len; - addr = malloc(addrlen); fhsize = nfhret.fhsize; fh = malloc(fhsize); - if (addr == NULL || fh == NULL) + if (fh == NULL) err(1, "malloc"); - bcopy(nfs_nb.buf, addr, addrlen); bcopy(nfhret.nfh, fh, fhsize); build_iovec(iov, iovlen, "addr", addr, addrlen);