From nobody Mon Sep 22 12:08:13 2025 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 4cVhhY3T75z67nqg; Mon, 22 Sep 2025 12:08:13 +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 "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4cVhhY2y75z3FZs; Mon, 22 Sep 2025 12:08:13 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1758542893; 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=raY7eKkzD9nsfr1ap9Q5cUUTVrVjPzaruGFldgxvQw0=; b=dO7ktw1qB9b1bmQRWsKLk8Zc7PNX4sOtoldbDbFKwv9t/f61S5yUhQV+LeIJwMA5MGNiUs D5FEC5u2W6vR3I4MoA7Mzjk0qQKb+cf9aB0Grv8V/bS2ACozKGQj4IF7ybo9flsFZaRXsx 5Ev0OH+xGEmGmq76WvUYo1/hUX3p5/ZBG9Cgvw2eMD8d6/bnh1exBQOYJybwwng+zGatSP Hdq9dxBlA541z2gWia/zx5ZK38VtO0rYeOjA36970oVYFTB7p6kbzSpfK97EYGiYx0N9mm o+fY+voIbS5ZJoVE07gE+nnTnws3QMavLHuwHmHeX63VOd5e+ZVroAM+qkylzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1758542893; 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=raY7eKkzD9nsfr1ap9Q5cUUTVrVjPzaruGFldgxvQw0=; b=QnqsfYj41ZpETDAu9DHZYpx2CLv0vgZhWJ2qsNW7zv4t8mQduaOhXR6nAJEGETyQFcIVxx vXbSFkdQLmuAI0QLljbQtPfGkBoIazPXL1UEya927ePnma9W8/HWYQ6fR1mcICcb6qZZa8 yLRBZfGZTxHoa+td4T+Wl6YXK0g8B50geMhrUUdhHKP2WoDMwzjUnmvt87ZKWar/ssPV17 gox3EUpI8PWQvPZpdUQTshDGRy6GJ6Q9dgw/G+BRxgJl1IuBjNGTx8L/wGg4vbNxE6f9+F Rc86kd+XnwU/wCsEAe9nXmGILtF6RTb40lwokvgYLUsCT6pSAIY40oryGuSqVQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1758542893; a=rsa-sha256; cv=none; b=utKbYhI3AvEljahCboaklR54p5YesXz5ap4/vWzYOzji3WwCgKebYAP+eDAUrLsiXXFhln mQORKxRv3y1NbYjFfOckha0X3Wat+HkmNHylhdRIYf7BD4H3rU96xkVCT4B4lCDacoUam1 tgqTLTl8P22nFyY/31LDdmnTQSu9jOBaSa3cXYmYFB/yiAbJOoD4NLw+euBTsdUCEHoOuB 7CVDgJUg+4VLGQ2/MPcZAZ3RwklmJVpNsnH3KU2K8pJKMTkWIq0I+anHTKvFXl7pONHVaV Y3eW5PWH1QQcsN1E8G+Zv8DKPs5IWPTsGTywFUM92MMJddW29Yd2WQZS9VKyeA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4cVhhY2Vydz1037; Mon, 22 Sep 2025 12:08:13 +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 58MC8DsW002328; Mon, 22 Sep 2025 12:08:13 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 58MC8D4J002325; Mon, 22 Sep 2025 12:08:13 GMT (envelope-from git) Date: Mon, 22 Sep 2025 12:08:13 GMT Message-Id: <202509221208.58MC8D4J002325@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Dag-Erling =?utf-8?Q?Sm=C3=B8rgrav?= Subject: git: e1401a283d10 - stable/14 - ifconfig: Enter jail as soon as possible 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: des X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: e1401a283d101acd94d14d769a0a2d80c34a65dc Auto-Submitted: auto-generated The branch stable/14 has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=e1401a283d101acd94d14d769a0a2d80c34a65dc commit e1401a283d101acd94d14d769a0a2d80c34a65dc Author: Dag-Erling Smørgrav AuthorDate: 2025-09-15 17:56:33 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2025-09-22 10:29:54 +0000 ifconfig: Enter jail as soon as possible Some options (in particular, -g) are processed immediately upon being parsed. This will produce the wrong result in combination with -j since we only attach to the jail after we're done parsing arguments. Solve this by attaching to the jail immediately when -j is encountered. The downside is that e.g. `ifconfig -j foo -j bar` would previously attach to jail “bar”, whereas now it will attempt to attach to jail “foo”, and if successful, attempt to attach to jail “bar” within jail “foo”. This may be considered a feature. PR: 289134 MFC after: 1 week Reviewed by: zlei Differential Revision: https://reviews.freebsd.org/D52501 (cherry picked from commit 18fd1443d205aed6be22966125a4820f77571948) --- sbin/ifconfig/ifconfig.8 | 42 +++++++++++++++++++++--------------------- sbin/ifconfig/ifconfig.c | 22 ++++++++-------------- sbin/ifconfig/ifconfig.h | 1 - 3 files changed, 29 insertions(+), 36 deletions(-) diff --git a/sbin/ifconfig/ifconfig.8 b/sbin/ifconfig/ifconfig.8 index 85dad643f588..980d61e9c214 100644 --- a/sbin/ifconfig/ifconfig.8 +++ b/sbin/ifconfig/ifconfig.8 @@ -28,7 +28,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd July 30, 2025 +.Dd September 12, 2025 .Dt IFCONFIG 8 .Os .Sh NAME @@ -36,7 +36,7 @@ .Nd configure network interface parameters .Sh SYNOPSIS .Nm -.Op Fl j Ar jail +.Op Fl j Ar jid .Op Fl DkLmn .Op Fl f Ar type Ns Cm \&: Ns Ar format .Ar interface @@ -50,11 +50,11 @@ .Oc .Op Ar parameters .Nm -.Op Fl j Ar jail +.Op Fl j Ar jid .Ar interface .Cm destroy .Nm -.Op Fl j Ar jail +.Op Fl j Ar jid .Fl a .Op Fl dDkLmuv .Op Fl f Ar type Ns Cm \&: Ns Ar format @@ -64,16 +64,16 @@ .Nm .Fl C .Nm -.Op Fl j Ar jail +.Op Fl j Ar jid .Fl g Ar groupname .Nm -.Op Fl j Ar jail +.Op Fl j Ar jid .Fl l .Op Fl du .Op Fl g Ar groupname .Op Ar address_family .Nm -.Op Fl j Ar jail +.Op Fl j Ar jid .Op Fl dkLmuv .Op Fl f Ar type Ns Cm \&: Ns Ar format .Sh DESCRIPTION @@ -257,22 +257,22 @@ Setting to .Cm all selects all interfaces. -.It Fl j Ar jail -Perform the actions inside the -.Ar jail . +.It Fl j Ar jid +Perform the actions inside the jail specified by +.Ar jid , +which may be either a jail name or a numeric jail ID. .Pp The -.Cm ifconfig -will first attach to the -.Ar jail -(by jail id or jail name) before performing the effects. -.Pp -This allow network interfaces of -.Ar jail -to be configured even if the -.Cm ifconfig -binary is not available in -.Ar jail . +.Nm +utility will attach to the specified jail immediately upon +encountering the option on the command line. +The option may be specified multiple times to attach to a nested jail +(jail within a jail). +.Pp +This makes it possible to configure network interfaces within a vnet +jail even if the +.Nm +binary is not available inside the jail. .It Fl k Print keying information for the .Ar interface , diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c index 9d7a40b9049a..2449d6ca484e 100644 --- a/sbin/ifconfig/ifconfig.c +++ b/sbin/ifconfig/ifconfig.c @@ -472,6 +472,9 @@ args_parse(struct ifconfig_args *args, int argc, char *argv[]) { char options[1024]; struct option *p; +#ifdef JAIL + int jid; +#endif int c; /* Parse leading line options */ @@ -503,7 +506,11 @@ args_parse(struct ifconfig_args *args, int argc, char *argv[]) #ifdef JAIL if (optarg == NULL) usage(); - args->jail_name = optarg; + jid = jail_getid(optarg); + if (jid == -1) + Perror("jail not found"); + if (jail_attach(jid) != 0) + Perror("cannot attach to jail"); #else Perror("not built with jail support"); #endif @@ -620,9 +627,6 @@ main(int ac, char *av[]) { char *envformat; int flags; -#ifdef JAIL - int jid; -#endif struct ifconfig_args _args = {}; struct ifconfig_args *args = &_args; @@ -647,16 +651,6 @@ main(int ac, char *av[]) args_parse(args, ac, av); -#ifdef JAIL - if (args->jail_name) { - jid = jail_getid(args->jail_name); - if (jid == -1) - Perror("jail not found"); - if (jail_attach(jid) != 0) - Perror("cannot attach to jail"); - } -#endif - if (!args->all && !args->namesonly) { /* not listing, need an argument */ args->ifname = args_pop(args); diff --git a/sbin/ifconfig/ifconfig.h b/sbin/ifconfig/ifconfig.h index be333d0ae02f..264e7b82a40e 100644 --- a/sbin/ifconfig/ifconfig.h +++ b/sbin/ifconfig/ifconfig.h @@ -248,7 +248,6 @@ struct ifconfig_args { const char *matchgroup; /* Group name to match */ const char *nogroup; /* Group name to exclude */ const struct afswtch *afp; /* AF we're operating on */ - const char *jail_name; /* Jail name or jail id specified */ }; struct option {