From nobody Wed Aug 16 12:32:13 2023 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 4RQnZk2Pw2z4qd54; Wed, 16 Aug 2023 12:32:14 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4RQnZj6zhwz4TFk; Wed, 16 Aug 2023 12:32:13 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1692189134; 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=L4ut3NxO5Ny/TpOt1kPCkpi83B4YQUIM8ZSBiFJyZ0Q=; b=hptau+XfLICKo27BR50DdvteXgXdQonYOazsdTJiTlKijT8sT154oyojjHkejvpZwQfK9m lXbH9R88Sh3aCJyJAoE7mijdtjhO+O4qSdRczNow0OPKBIOj4EAhfOmUs6DsIB7+HSNNn9 voMvjSX+HGz6BF/SJrMJHr7Y8Q+aKGZmSzqC/0rtd5RO8LBS1WnuY0G5l3UC0xvc94zXwO noS4M9P5hwhe5e9r5Lm5uZPx5blGSggJPvyHtHe+edHPHCk/BOy6d9emfsIvPjskenfUhp LglOz/eX5Q+sejqCvVN9323sE7+HHRlqFI/Sf0Mbuq+4EtnLUnv2SPmpHOentg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1692189134; 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=L4ut3NxO5Ny/TpOt1kPCkpi83B4YQUIM8ZSBiFJyZ0Q=; b=ZRiOK8vrvdu59SCxh1ukhdrT3ddOUnJqxj2u81TMzlV6LFGSbTKSCVfb2osEOkf3NAfoUJ J5IhX0Xhks04ZXi2ENa6fMRydSb2F3Guy/ty2O7Hmdpurgrf1SV203PvtAER59qR3N44FV u9nRFaU8dkiyYc5SYg7HaZee2Jem/CLntJFR5g3lM5D55bbN3C8t5xPlfA7kXX7n74xWJ9 y7fLQej3C+DT5tFw14v+bEboEehX+EF00S8iR5ooBZGtv5ZKCF27jHhKT3DFopqDavJpw7 nRiCLXfdsYBBvC3TJTJqQeUqdkhEi2dLiXmpCqfpelWd1mZ4rPKZa3/ecHMdfw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1692189134; a=rsa-sha256; cv=none; b=VLeEbs+AH9EOZDOaBJjP2yRnGunPz9e1HLZZKxjPIt1Xs7JNTmG2e7Zbpa3uaivAU90PeA LP8IVtdf4R/Gx8mmA2PgeEH3P3N4uF9dHMLT33CFu8FEXqXeIcXsL8hSL8uTzkyfTgGh12 lW75veb7/DigJBzPUGOeAWIdBzbXPqxRv4wdO+pQxOlBhsv5I+2oRQzGsy6wTJUWuXIkEs x/xtbBklpIqFN+Norv5OxR8WVuS9j7RCFUN9GJUNWPukVUQzd3Vl+SkAT2plh9e/pv/d2H dG14g/zBcdUTglwdy/nTOY4qCDzCCwyk4koRUXMWMMMFcf4wDX8METLO+0FHBQ== 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 4RQnZj64Z3zs4l; Wed, 16 Aug 2023 12:32:13 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 37GCWD10023359; Wed, 16 Aug 2023 12:32:13 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 37GCWDrb023356; Wed, 16 Aug 2023 12:32:13 GMT (envelope-from git) Date: Wed, 16 Aug 2023 12:32:13 GMT Message-Id: <202308161232.37GCWDrb023356@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Doug Rabson Subject: git: 3af770071046 - stable/13 - ifconfig(8): Teach ifconfig to attach and run itself in a jail 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: dfr X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 3af7700710466b330e54307ff5bc5ea6bb91fec4 Auto-Submitted: auto-generated The branch stable/13 has been updated by dfr: URL: https://cgit.FreeBSD.org/src/commit/?id=3af7700710466b330e54307ff5bc5ea6bb91fec4 commit 3af7700710466b330e54307ff5bc5ea6bb91fec4 Author: Yan Ka Chiu AuthorDate: 2023-05-23 20:39:22 +0000 Commit: Doug Rabson CommitDate: 2023-08-16 12:25:57 +0000 ifconfig(8): Teach ifconfig to attach and run itself in a jail Add -j flag to ifconfig to allow ifconfig to attach and run inside a jail. This allow parent to configure network interfaces of its children even if ifconfig is not available in child's tree (e.g. Linux Jails) Reviewed by: emaste, khng, melifaro Event: Kitchener-Waterloo Hackathon 202305 MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D40213 (cherry picked from commit 7e49aa86a2824e76e9d9becf61db12066bc0d79d) --- sbin/ifconfig/ifconfig.8 | 22 ++++++++++++++++++++++ sbin/ifconfig/ifconfig.c | 40 ++++++++++++++++++++++++++++++++++------ 2 files changed, 56 insertions(+), 6 deletions(-) diff --git a/sbin/ifconfig/ifconfig.8 b/sbin/ifconfig/ifconfig.8 index e7d41da45bec..651d64fb31df 100644 --- a/sbin/ifconfig/ifconfig.8 +++ b/sbin/ifconfig/ifconfig.8 @@ -36,6 +36,7 @@ .Nd configure network interface parameters .Sh SYNOPSIS .Nm +.Op Fl j Ar jail .Op Fl kLmn .Op Fl f Ar type Ns Cm \&: Ns Ar format .Ar interface @@ -49,9 +50,11 @@ .Oc .Op Ar parameters .Nm +.Op Fl j Ar jail .Ar interface .Cm destroy .Nm +.Op Fl j Ar jail .Fl a .Op Fl dkLmuv .Op Fl f Ar type Ns Cm \&: Ns Ar format @@ -61,13 +64,16 @@ .Nm .Fl C .Nm +.Op Fl j Ar jail .Fl g Ar groupname .Nm +.Op Fl j Ar jail .Fl l .Op Fl du .Op Fl g Ar groupname .Op Ar address_family .Nm +.Op Fl j Ar jail .Op Fl dkLmuv .Op Fl f Ar type Ns Cm \&: Ns Ar format .Sh DESCRIPTION @@ -233,6 +239,22 @@ Setting to .Cm all selects all interfaces. +.It Fl j Ar jail +Perform the actions inside the +.Ar jail . +.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 . .It Fl k Print keying information for the .Ar interface , diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c index 6deeebba9f01..f93a97572a78 100644 --- a/sbin/ifconfig/ifconfig.c +++ b/sbin/ifconfig/ifconfig.c @@ -42,6 +42,9 @@ static const char rcsid[] = #include #include +#ifdef JAIL +#include +#endif #include #include #include @@ -189,12 +192,12 @@ usage(void) } fprintf(stderr, - "usage: ifconfig [-f type:format] %sinterface address_family\n" + "usage: ifconfig [-j jail] [-f type:format] %sinterface address_family\n" " [address [dest_address]] [parameters]\n" - " ifconfig interface create\n" - " ifconfig -a %s[-d] [-m] [-u] [-v] [address_family]\n" - " ifconfig -l [-d] [-u] [address_family]\n" - " ifconfig %s[-d] [-m] [-u] [-v]\n", + " ifconfig [-j jail] interface create\n" + " ifconfig [-j jail] -a %s[-d] [-m] [-u] [-v] [address_family]\n" + " ifconfig [-j jail] -l [-d] [-u] [address_family]\n" + " ifconfig [-j jail] %s[-d] [-m] [-u] [-v]\n", options, options, options); exit(1); } @@ -412,12 +415,18 @@ main(int argc, char *argv[]) struct ifreq paifr; const struct sockaddr_dl *sdl; char options[1024], *cp, *envformat, *namecp = NULL; +#ifdef JAIL + char *jail_name = NULL; +#endif struct ifa_queue q = TAILQ_HEAD_INITIALIZER(q); struct ifa_order_elt *cur, *tmp; const char *ifname, *matchgroup, *nogroup; struct option *p; size_t iflen; int flags; +#ifdef JAIL + int jid; +#endif all = downonly = uponly = namesonly = noload = verbose = 0; f_inet = f_inet6 = f_ether = f_addr = NULL; @@ -438,7 +447,7 @@ main(int argc, char *argv[]) atexit(printifnamemaybe); /* Parse leading line options */ - strlcpy(options, "G:adf:klmnuv", sizeof(options)); + strlcpy(options, "G:adf:j:klmnuv", sizeof(options)); for (p = opts; p != NULL; p = p->next) strlcat(options, p->opt, sizeof(options)); while ((c = getopt(argc, argv, options)) != -1) { @@ -459,6 +468,15 @@ main(int argc, char *argv[]) usage(); nogroup = optarg; break; + case 'j': +#ifdef JAIL + if (optarg == NULL) + usage(); + jail_name = optarg; +#else + Perror("not built with jail support"); +#endif + break; case 'k': printkeys++; break; @@ -511,6 +529,16 @@ main(int argc, char *argv[]) if (!namesonly && argc < 1) all = 1; +#ifdef JAIL + if (jail_name) { + jid = jail_getid(jail_name); + if (jid == -1) + Perror("jail not found"); + if (jail_attach(jid) != 0) + Perror("cannot attach to jail"); + } +#endif + /* -a and -l allow an address family arg to limit the output */ if (all || namesonly) { if (argc > 1)