aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYan Ka Chiu <nyan@myuji.xyz>2023-05-23 20:39:22 +0000
committerDoug Rabson <dfr@FreeBSD.org>2023-08-16 12:25:57 +0000
commit3af7700710466b330e54307ff5bc5ea6bb91fec4 (patch)
treec1e13be4dff9a0f29964cba10f8a8051ef76e384
parent0fbf21482f5a594d26314e1354df4dd691bc6401 (diff)
downloadsrc-3af7700710466b330e54307ff5bc5ea6bb91fec4.tar.gz
src-3af7700710466b330e54307ff5bc5ea6bb91fec4.zip
-rw-r--r--sbin/ifconfig/ifconfig.822
-rw-r--r--sbin/ifconfig/ifconfig.c40
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 <sys/param.h>
#include <sys/ioctl.h>
+#ifdef JAIL
+#include <sys/jail.h>
+#endif
#include <sys/module.h>
#include <sys/linker.h>
#include <sys/queue.h>
@@ -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)