From nobody Tue Jun 13 06:07:45 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 4QgJ4d5kJCz4dDbj; Tue, 13 Jun 2023 06:07:45 +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 4QgJ4d451Wz3jKG; Tue, 13 Jun 2023 06:07:45 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1686636465; 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=ntYPoaGVTPn6bwCXw9KTwTTCS9PixFaQtDF7b4J+rww=; b=DJAAfH0qhUcWexAxGz/uGZnuuaaAKIBoiAlwSJlAVKsUTIZNQEHLjZ7bVbn22FVgFIWpv7 okaUnEnoppSoTsZgrejuTvAEFmW3rWAx5RKCWm3NXve2HXeUti4C59QRRnkrjYCLUG1SyE tR5I64ePHld9iulqVt+ZCCLvWKmXfb8esmzWXy6KhNnFHuHx7hNZKjacOf0KtqAbdDu7iq HhnaAU9B/lHAsZn1eBzbkWTRKl2O+cqmBd1jst2zSyTUjF9ZnUQbd7ZjnuCtIXyG2ENlCB 4Ji8vc3l4iHtR4S+XAW0hEUJ+hMlv3ZaxGv6oAJ8eD9rJ/OgddbZYT4Ui9tFnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1686636465; 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=ntYPoaGVTPn6bwCXw9KTwTTCS9PixFaQtDF7b4J+rww=; b=BBn9QgS+ob5k0V1ooHjz+JZyqszarpupqtQybcGYIO0/+lphjKrjj0msF8czHJtnH9v3cp Em8Owg8kO+u8COpFQUBT884LUbsZFCH1SHD50hgXKg9wMRd9bHxLLTNAvoeU2wDu8GuUp9 mCgc9Fo5Fln7QWMzpBnixI/Kd8YPucxMIhgrXaDGKwk2Nyv/7kEKvEvNeEv2T0lwNNebTh Jyg7lZR6eqxoYBly7iSbl9PfD2YtysnXD4S0Z+OJ9Xz1Zz+e1XMrs64p01Xked3R6sggoK i+xz4dHtgopWj8O/P+DlWas6EP39xx+/tmi8IG5CpgV34gE+n83pfasXhdKIKA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1686636465; a=rsa-sha256; cv=none; b=Q/m3iEGhQIG5Vd0fB5WySI0XmrmC9FYCk+OJDkRO/CJzmWLhebUxZ3A5/xSihPJcqc9eC2 +FPuoJjZWBElSeAuzCsXYVmFEtPjf3hHtBrfcIKS+lmsgkUNqlHQsyP9bBsq88j92XVgC3 +E72XZ6EyoGqukkjORZpDo6gZQoR6F6aFmUmL6QVyBw5+ZgJmYgfl6ivxmudCPC07U0kTh p/qEs1QFYM8oZu8AnHrZHgoy7OXIV/lNZlVyzSDzhE5sRH4MXMDJEpbTAyY45SX3zeVxx5 wP0ygEk0ZIRy3f2mxSjYL6A/BVLLbgAPLyrKh65C2NSGLbGEZ6qp4E0G965sdw== 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 4QgJ4d2JYxz19dg; Tue, 13 Jun 2023 06:07:45 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 35D67jDT099076; Tue, 13 Jun 2023 06:07:45 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 35D67j7n099075; Tue, 13 Jun 2023 06:07:45 GMT (envelope-from git) Date: Tue, 13 Jun 2023 06:07:45 GMT Message-Id: <202306130607.35D67j7n099075@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: "Alexander V. Chernikov" Subject: git: ab4d1b73cbf8 - main - route(8): teach route to attach to jails 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: melifaro X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: ab4d1b73cbf8980dbe05cde7d822010042db8344 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by melifaro: URL: https://cgit.FreeBSD.org/src/commit/?id=ab4d1b73cbf8980dbe05cde7d822010042db8344 commit ab4d1b73cbf8980dbe05cde7d822010042db8344 Author: Yan Ka, Chiu AuthorDate: 2023-06-13 06:05:17 +0000 Commit: Alexander V. Chernikov CommitDate: 2023-06-13 06:06:27 +0000 route(8): teach route to attach to jails Add -j flag to route(8) to allow route to perform actions in a Jail. Differential Revision: https://reviews.freebsd.org/D40377 MFC after: 2 weeks --- sbin/route/Makefile | 5 +++++ sbin/route/route.8 | 5 ++++- sbin/route/route.c | 36 ++++++++++++++++++++++++++++++++++-- 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/sbin/route/Makefile b/sbin/route/Makefile index ddebd2a1d166..d170d0823c91 100644 --- a/sbin/route/Makefile +++ b/sbin/route/Makefile @@ -25,6 +25,11 @@ SRCS+= route_netlink.c CFLAGS+=-DWITHOUT_NETLINK .endif +.if ${MK_JAIL} != "no" && !defined(RESCUE) +CFLAGS+= -DJAIL +LIBADD+= jail +.endif + HAS_TESTS= SUBDIR.${MK_TESTS}+= tests diff --git a/sbin/route/route.8 b/sbin/route/route.8 index afcf55ab44c7..72c22bee23ed 100644 --- a/sbin/route/route.8 +++ b/sbin/route/route.8 @@ -28,7 +28,7 @@ .\" @(#)route.8 8.3 (Berkeley) 3/19/94 .\" $FreeBSD$ .\" -.Dd March 14, 2023 +.Dd June 13, 2023 .Dt ROUTE 8 .Os .Sh NAME @@ -36,6 +36,7 @@ .Nd manually manipulate the routing tables .Sh SYNOPSIS .Nm +.Op Fl j Ar jail .Op Fl dnqtv .Ar command .Oo @@ -91,6 +92,8 @@ Suppress all output from the and .Cm flush commands. +.It Fl j Ar jail +Run inside a jail. .El .Pp The diff --git a/sbin/route/route.c b/sbin/route/route.c index 4002cbe5867b..223b1d6f69dc 100644 --- a/sbin/route/route.c +++ b/sbin/route/route.c @@ -48,6 +48,9 @@ __FBSDID("$FreeBSD$"); #include #include #include +#ifdef JAIL +#include +#endif #include #include #include @@ -63,6 +66,9 @@ __FBSDID("$FreeBSD$"); #include #include #include +#ifdef JAIL +#include +#endif #include #include #include @@ -91,6 +97,9 @@ static struct keytab { }; int verbose, debugonly; +#ifdef JAIL +char * jail_name; +#endif static struct sockaddr_storage so[RTAX_MAX]; static int pid, rtm_addrs; static int nflag, af, aflen, qflag, tflag; @@ -172,7 +181,7 @@ usage(const char *cp) { if (cp != NULL) warnx("bad keyword: %s", cp); - errx(EX_USAGE, "usage: route [-46dnqtv] command [[modifiers] args]"); + errx(EX_USAGE, "usage: route [-j jail] [-46dnqtv] command [[modifiers] args]"); /* NOTREACHED */ } @@ -180,12 +189,15 @@ int main(int argc, char **argv) { int ch; +#ifdef JAIL + int jid; +#endif size_t len; if (argc < 2) usage(NULL); - while ((ch = getopt(argc, argv, "46nqdtv")) != -1) + while ((ch = getopt(argc, argv, "46nqdtvj:")) != -1) switch(ch) { case '4': #ifdef INET @@ -218,6 +230,15 @@ main(int argc, char **argv) case 'd': debugonly = 1; break; + case 'j': +#ifdef JAIL + if (optarg == NULL) + usage(NULL); + jail_name = optarg; +#else + errx(1, "Jail support is not compiled in"); +#endif + break; case '?': default: usage(NULL); @@ -227,6 +248,17 @@ main(int argc, char **argv) pid = getpid(); uid = geteuid(); + +#ifdef JAIL + if (jail_name != NULL) { + jid = jail_getid(jail_name); + if (jid == -1) + errx(1, "Jail not found"); + if (jail_attach(jid) != 0) + errx(1, "Cannot attach to jail"); + } +#endif + #ifdef WITHOUT_NETLINK if (tflag) s = open(_PATH_DEVNULL, O_WRONLY, 0);