2003-04-09 03:04:12 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2003 Mike Barcroft <mike@FreeBSD.org>
|
MFp4:
Bring in updated jail support from bz_jail branch.
This enhances the current jail implementation to permit multiple
addresses per jail. In addtion to IPv4, IPv6 is supported as well.
Due to updated checks it is even possible to have jails without
an IP address at all, which basically gives one a chroot with
restricted process view, no networking,..
SCTP support was updated and supports IPv6 in jails as well.
Cpuset support permits jails to be bound to specific processor
sets after creation.
Jails can have an unrestricted (no duplicate protection, etc.) name
in addition to the hostname. The jail name cannot be changed from
within a jail and is considered to be used for management purposes
or as audit-token in the future.
DDB 'show jails' command was added to aid debugging.
Proper compat support permits 32bit jail binaries to be used on 64bit
systems to manage jails. Also backward compatibility was preserved where
possible: for jail v1 syscalls, as well as with user space management
utilities.
Both jail as well as prison version were updated for the new features.
A gap was intentionally left as the intermediate versions had been
used by various patches floating around the last years.
Bump __FreeBSD_version for the afore mentioned and in kernel changes.
Special thanks to:
- Pawel Jakub Dawidek (pjd) for his multi-IPv4 patches
and Olivier Houchard (cognet) for initial single-IPv6 patches.
- Jeff Roberson (jeff) and Randall Stewart (rrs) for their
help, ideas and review on cpuset and SCTP support.
- Robert Watson (rwatson) for lots and lots of help, discussions,
suggestions and review of most of the patch at various stages.
- John Baldwin (jhb) for his help.
- Simon L. Nielsen (simon) as early adopter testing changes
on cluster machines as well as all the testers and people
who provided feedback the last months on freebsd-jail and
other channels.
- My employer, CK Software GmbH, for the support so I could work on this.
Reviewed by: (see above)
MFC after: 3 months (this is just so that I get the mail)
X-MFC Before: 7.2-RELEASE if possible
2008-11-29 14:32:14 +00:00
|
|
|
* Copyright (c) 2008 Bjoern A. Zeeb <bz@FreeBSD.org>
|
2009-05-27 14:30:26 +00:00
|
|
|
* Copyright (c) 2009 James Gritton <jamie@FreeBSD.org>
|
2015-12-22 00:58:35 +00:00
|
|
|
* Copyright (c) 2015 Emmanuel Vadot <manu@bocal.org>
|
2003-04-09 03:04:12 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2009-05-27 14:30:26 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2003-04-09 03:04:12 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/jail.h>
|
2009-05-27 14:30:26 +00:00
|
|
|
#include <sys/socket.h>
|
2003-04-09 03:04:12 +00:00
|
|
|
#include <sys/sysctl.h>
|
|
|
|
|
|
|
|
#include <arpa/inet.h>
|
2009-05-27 14:30:26 +00:00
|
|
|
#include <netinet/in.h>
|
|
|
|
|
2003-04-09 03:04:12 +00:00
|
|
|
#include <err.h>
|
|
|
|
#include <errno.h>
|
2009-06-24 18:18:35 +00:00
|
|
|
#include <jail.h>
|
2003-04-09 03:04:12 +00:00
|
|
|
#include <limits.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
MFp4:
Bring in updated jail support from bz_jail branch.
This enhances the current jail implementation to permit multiple
addresses per jail. In addtion to IPv4, IPv6 is supported as well.
Due to updated checks it is even possible to have jails without
an IP address at all, which basically gives one a chroot with
restricted process view, no networking,..
SCTP support was updated and supports IPv6 in jails as well.
Cpuset support permits jails to be bound to specific processor
sets after creation.
Jails can have an unrestricted (no duplicate protection, etc.) name
in addition to the hostname. The jail name cannot be changed from
within a jail and is considered to be used for management purposes
or as audit-token in the future.
DDB 'show jails' command was added to aid debugging.
Proper compat support permits 32bit jail binaries to be used on 64bit
systems to manage jails. Also backward compatibility was preserved where
possible: for jail v1 syscalls, as well as with user space management
utilities.
Both jail as well as prison version were updated for the new features.
A gap was intentionally left as the intermediate versions had been
used by various patches floating around the last years.
Bump __FreeBSD_version for the afore mentioned and in kernel changes.
Special thanks to:
- Pawel Jakub Dawidek (pjd) for his multi-IPv4 patches
and Olivier Houchard (cognet) for initial single-IPv6 patches.
- Jeff Roberson (jeff) and Randall Stewart (rrs) for their
help, ideas and review on cpuset and SCTP support.
- Robert Watson (rwatson) for lots and lots of help, discussions,
suggestions and review of most of the patch at various stages.
- John Baldwin (jhb) for his help.
- Simon L. Nielsen (simon) as early adopter testing changes
on cluster machines as well as all the testers and people
who provided feedback the last months on freebsd-jail and
other channels.
- My employer, CK Software GmbH, for the support so I could work on this.
Reviewed by: (see above)
MFC after: 3 months (this is just so that I get the mail)
X-MFC Before: 7.2-RELEASE if possible
2008-11-29 14:32:14 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
2015-12-22 00:58:35 +00:00
|
|
|
#include <libxo/xo.h>
|
2003-04-09 03:04:12 +00:00
|
|
|
|
2009-06-24 18:18:35 +00:00
|
|
|
#define JP_USER 0x01000000
|
|
|
|
#define JP_OPT 0x02000000
|
2009-05-27 14:30:26 +00:00
|
|
|
|
Improve IP address list representation in libxo output.
Extract decision-making about special-case printing of certain
jail parameters into a function.
Refactor emitting of IPv4 and IPv6 address lists into a function.
Resulting user-facing changes:
XO_VERSION is bumped to 2.
In verbose mode (-v), IPv4 and IPv6-Addresses are now properly emitted
as separate lists.
This only affects the output in encoding styles, i.e. xml and json.
{ {
"__version": "1", "__version": "2",
"jail-information": { "jail-information": {
"jail": [ "jail": [
{ {
"jid": 166, "jid": 166,
"hostname": "foo.com", "hostname": "foo.com",
"path": "/var/jail/foo", "path": "/var/jail/foo",
"name": "foo", "name": "foo",
"state": "ACTIVE", "state": "ACTIVE",
"cpusetid": 2, "cpusetid": 2,
"ipv4_addrs": [ "ipv4_addrs": [
"10.1.1.1", "10.1.1.1",
"10.1.1.2", "10.1.1.2",
"10.1.1.3", | "10.1.1.3"
> ],
> "ipv6_addrs": [
"fe80::1000:1", "fe80::1000:1",
"fe80::1000:2" "fe80::1000:2"
] ]
} }
] ]
} }
} }
In -n mode, ip4.addr and ip6.addr are formatted in the encoding styles'
native list types, e.g. instead of comma-separated lists, JSON arrays
are printed.
jls -n all --libxo json
...
"ip4.addr": [
"10.1.1.1",
"10.1.1.2",
"10.1.1.3"
],
"ip4.saddrsel": true,
"ip6.addr": [
"fe80::1000:1",
"fe80::1000:2"
],
...
jls -n all --libxo xml
...
<ip4.addr>10.1.1.1</ip4.addr>
<ip4.addr>10.1.1.2</ip4.addr>
<ip4.addr>10.1.1.3</ip4.addr>
<ip4.saddrsel>true</ip4.saddrsel>
<ip6.addr>fe80::1000:1</ip6.addr>
<ip6.addr>fe80::1000:2</ip6.addr>
...
PR: 215008
Submitted by: Christian Schwarz <me@cschwarz.com>
Differential Revision: https://reviews.freebsd.org/D8766
2016-12-24 23:51:27 +00:00
|
|
|
#define JLS_XO_VERSION "2"
|
2015-12-22 00:58:35 +00:00
|
|
|
|
2009-05-27 14:30:26 +00:00
|
|
|
#define PRINT_DEFAULT 0x01
|
|
|
|
#define PRINT_HEADER 0x02
|
|
|
|
#define PRINT_NAMEVAL 0x04
|
|
|
|
#define PRINT_QUOTED 0x08
|
|
|
|
#define PRINT_SKIP 0x10
|
|
|
|
#define PRINT_VERBOSE 0x20
|
2013-05-17 08:48:16 +00:00
|
|
|
#define PRINT_JAIL_NAME 0x40
|
2009-05-27 14:30:26 +00:00
|
|
|
|
2009-06-24 18:18:35 +00:00
|
|
|
static struct jailparam *params;
|
2009-07-25 14:48:57 +00:00
|
|
|
static int *param_parent;
|
2009-05-27 14:30:26 +00:00
|
|
|
static int nparams;
|
2011-05-29 21:03:40 +00:00
|
|
|
#ifdef INET6
|
|
|
|
static int ip6_ok;
|
|
|
|
#endif
|
|
|
|
#ifdef INET
|
|
|
|
static int ip4_ok;
|
|
|
|
#endif
|
2009-05-27 14:30:26 +00:00
|
|
|
|
2009-06-24 18:18:35 +00:00
|
|
|
static int add_param(const char *name, void *value, size_t valuelen,
|
|
|
|
struct jailparam *source, unsigned flags);
|
2009-05-27 14:30:26 +00:00
|
|
|
static int sort_param(const void *a, const void *b);
|
|
|
|
static char *noname(const char *name);
|
|
|
|
static char *nononame(const char *name);
|
|
|
|
static int print_jail(int pflags, int jflags);
|
Improve IP address list representation in libxo output.
Extract decision-making about special-case printing of certain
jail parameters into a function.
Refactor emitting of IPv4 and IPv6 address lists into a function.
Resulting user-facing changes:
XO_VERSION is bumped to 2.
In verbose mode (-v), IPv4 and IPv6-Addresses are now properly emitted
as separate lists.
This only affects the output in encoding styles, i.e. xml and json.
{ {
"__version": "1", "__version": "2",
"jail-information": { "jail-information": {
"jail": [ "jail": [
{ {
"jid": 166, "jid": 166,
"hostname": "foo.com", "hostname": "foo.com",
"path": "/var/jail/foo", "path": "/var/jail/foo",
"name": "foo", "name": "foo",
"state": "ACTIVE", "state": "ACTIVE",
"cpusetid": 2, "cpusetid": 2,
"ipv4_addrs": [ "ipv4_addrs": [
"10.1.1.1", "10.1.1.1",
"10.1.1.2", "10.1.1.2",
"10.1.1.3", | "10.1.1.3"
> ],
> "ipv6_addrs": [
"fe80::1000:1", "fe80::1000:1",
"fe80::1000:2" "fe80::1000:2"
] ]
} }
] ]
} }
} }
In -n mode, ip4.addr and ip6.addr are formatted in the encoding styles'
native list types, e.g. instead of comma-separated lists, JSON arrays
are printed.
jls -n all --libxo json
...
"ip4.addr": [
"10.1.1.1",
"10.1.1.2",
"10.1.1.3"
],
"ip4.saddrsel": true,
"ip6.addr": [
"fe80::1000:1",
"fe80::1000:2"
],
...
jls -n all --libxo xml
...
<ip4.addr>10.1.1.1</ip4.addr>
<ip4.addr>10.1.1.2</ip4.addr>
<ip4.addr>10.1.1.3</ip4.addr>
<ip4.saddrsel>true</ip4.saddrsel>
<ip6.addr>fe80::1000:1</ip6.addr>
<ip6.addr>fe80::1000:2</ip6.addr>
...
PR: 215008
Submitted by: Christian Schwarz <me@cschwarz.com>
Differential Revision: https://reviews.freebsd.org/D8766
2016-12-24 23:51:27 +00:00
|
|
|
static int special_print(int pflags, struct jailparam *param);
|
2015-12-22 00:58:35 +00:00
|
|
|
static void quoted_print(int pflags, char *name, char *value);
|
Improve IP address list representation in libxo output.
Extract decision-making about special-case printing of certain
jail parameters into a function.
Refactor emitting of IPv4 and IPv6 address lists into a function.
Resulting user-facing changes:
XO_VERSION is bumped to 2.
In verbose mode (-v), IPv4 and IPv6-Addresses are now properly emitted
as separate lists.
This only affects the output in encoding styles, i.e. xml and json.
{ {
"__version": "1", "__version": "2",
"jail-information": { "jail-information": {
"jail": [ "jail": [
{ {
"jid": 166, "jid": 166,
"hostname": "foo.com", "hostname": "foo.com",
"path": "/var/jail/foo", "path": "/var/jail/foo",
"name": "foo", "name": "foo",
"state": "ACTIVE", "state": "ACTIVE",
"cpusetid": 2, "cpusetid": 2,
"ipv4_addrs": [ "ipv4_addrs": [
"10.1.1.1", "10.1.1.1",
"10.1.1.2", "10.1.1.2",
"10.1.1.3", | "10.1.1.3"
> ],
> "ipv6_addrs": [
"fe80::1000:1", "fe80::1000:1",
"fe80::1000:2" "fe80::1000:2"
] ]
} }
] ]
} }
} }
In -n mode, ip4.addr and ip6.addr are formatted in the encoding styles'
native list types, e.g. instead of comma-separated lists, JSON arrays
are printed.
jls -n all --libxo json
...
"ip4.addr": [
"10.1.1.1",
"10.1.1.2",
"10.1.1.3"
],
"ip4.saddrsel": true,
"ip6.addr": [
"fe80::1000:1",
"fe80::1000:2"
],
...
jls -n all --libxo xml
...
<ip4.addr>10.1.1.1</ip4.addr>
<ip4.addr>10.1.1.2</ip4.addr>
<ip4.addr>10.1.1.3</ip4.addr>
<ip4.saddrsel>true</ip4.saddrsel>
<ip6.addr>fe80::1000:1</ip6.addr>
<ip6.addr>fe80::1000:2</ip6.addr>
...
PR: 215008
Submitted by: Christian Schwarz <me@cschwarz.com>
Differential Revision: https://reviews.freebsd.org/D8766
2016-12-24 23:51:27 +00:00
|
|
|
static void emit_ip_addr_list(int af_family, const char *list_name,
|
|
|
|
struct jailparam *param);
|
MFp4:
Bring in updated jail support from bz_jail branch.
This enhances the current jail implementation to permit multiple
addresses per jail. In addtion to IPv4, IPv6 is supported as well.
Due to updated checks it is even possible to have jails without
an IP address at all, which basically gives one a chroot with
restricted process view, no networking,..
SCTP support was updated and supports IPv6 in jails as well.
Cpuset support permits jails to be bound to specific processor
sets after creation.
Jails can have an unrestricted (no duplicate protection, etc.) name
in addition to the hostname. The jail name cannot be changed from
within a jail and is considered to be used for management purposes
or as audit-token in the future.
DDB 'show jails' command was added to aid debugging.
Proper compat support permits 32bit jail binaries to be used on 64bit
systems to manage jails. Also backward compatibility was preserved where
possible: for jail v1 syscalls, as well as with user space management
utilities.
Both jail as well as prison version were updated for the new features.
A gap was intentionally left as the intermediate versions had been
used by various patches floating around the last years.
Bump __FreeBSD_version for the afore mentioned and in kernel changes.
Special thanks to:
- Pawel Jakub Dawidek (pjd) for his multi-IPv4 patches
and Olivier Houchard (cognet) for initial single-IPv6 patches.
- Jeff Roberson (jeff) and Randall Stewart (rrs) for their
help, ideas and review on cpuset and SCTP support.
- Robert Watson (rwatson) for lots and lots of help, discussions,
suggestions and review of most of the patch at various stages.
- John Baldwin (jhb) for his help.
- Simon L. Nielsen (simon) as early adopter testing changes
on cluster machines as well as all the testers and people
who provided feedback the last months on freebsd-jail and
other channels.
- My employer, CK Software GmbH, for the support so I could work on this.
Reviewed by: (see above)
MFC after: 3 months (this is just so that I get the mail)
X-MFC Before: 7.2-RELEASE if possible
2008-11-29 14:32:14 +00:00
|
|
|
|
2009-05-27 14:30:26 +00:00
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
MFp4:
Bring in updated jail support from bz_jail branch.
This enhances the current jail implementation to permit multiple
addresses per jail. In addtion to IPv4, IPv6 is supported as well.
Due to updated checks it is even possible to have jails without
an IP address at all, which basically gives one a chroot with
restricted process view, no networking,..
SCTP support was updated and supports IPv6 in jails as well.
Cpuset support permits jails to be bound to specific processor
sets after creation.
Jails can have an unrestricted (no duplicate protection, etc.) name
in addition to the hostname. The jail name cannot be changed from
within a jail and is considered to be used for management purposes
or as audit-token in the future.
DDB 'show jails' command was added to aid debugging.
Proper compat support permits 32bit jail binaries to be used on 64bit
systems to manage jails. Also backward compatibility was preserved where
possible: for jail v1 syscalls, as well as with user space management
utilities.
Both jail as well as prison version were updated for the new features.
A gap was intentionally left as the intermediate versions had been
used by various patches floating around the last years.
Bump __FreeBSD_version for the afore mentioned and in kernel changes.
Special thanks to:
- Pawel Jakub Dawidek (pjd) for his multi-IPv4 patches
and Olivier Houchard (cognet) for initial single-IPv6 patches.
- Jeff Roberson (jeff) and Randall Stewart (rrs) for their
help, ideas and review on cpuset and SCTP support.
- Robert Watson (rwatson) for lots and lots of help, discussions,
suggestions and review of most of the patch at various stages.
- John Baldwin (jhb) for his help.
- Simon L. Nielsen (simon) as early adopter testing changes
on cluster machines as well as all the testers and people
who provided feedback the last months on freebsd-jail and
other channels.
- My employer, CK Software GmbH, for the support so I could work on this.
Reviewed by: (see above)
MFC after: 3 months (this is just so that I get the mail)
X-MFC Before: 7.2-RELEASE if possible
2008-11-29 14:32:14 +00:00
|
|
|
{
|
2015-02-20 20:12:05 +00:00
|
|
|
char *dot, *ep, *jname, *pname;
|
2009-05-27 14:30:26 +00:00
|
|
|
int c, i, jflags, jid, lastjid, pflags, spc;
|
|
|
|
|
2015-12-22 00:58:35 +00:00
|
|
|
argc = xo_parse_args(argc, argv);
|
|
|
|
if (argc < 0)
|
|
|
|
exit(1);
|
|
|
|
|
|
|
|
xo_set_version(JLS_XO_VERSION);
|
2009-05-27 14:30:26 +00:00
|
|
|
jname = NULL;
|
|
|
|
pflags = jflags = jid = 0;
|
2013-05-17 08:48:16 +00:00
|
|
|
while ((c = getopt(argc, argv, "adj:hNnqsv")) >= 0)
|
2009-05-27 14:30:26 +00:00
|
|
|
switch (c) {
|
|
|
|
case 'a':
|
|
|
|
case 'd':
|
|
|
|
jflags |= JAIL_DYING;
|
|
|
|
break;
|
|
|
|
case 'j':
|
|
|
|
jid = strtoul(optarg, &ep, 10);
|
2010-07-08 19:22:52 +00:00
|
|
|
if (!jid || *ep) {
|
|
|
|
jid = 0;
|
2009-05-27 14:30:26 +00:00
|
|
|
jname = optarg;
|
2010-07-08 19:22:52 +00:00
|
|
|
}
|
2009-05-27 14:30:26 +00:00
|
|
|
break;
|
|
|
|
case 'h':
|
2009-07-08 15:57:22 +00:00
|
|
|
pflags = (pflags & ~(PRINT_SKIP | PRINT_VERBOSE)) |
|
|
|
|
PRINT_HEADER;
|
2009-05-27 14:30:26 +00:00
|
|
|
break;
|
2013-05-17 08:48:16 +00:00
|
|
|
case 'N':
|
|
|
|
pflags |= PRINT_JAIL_NAME;
|
|
|
|
break;
|
2009-05-27 14:30:26 +00:00
|
|
|
case 'n':
|
|
|
|
pflags = (pflags & ~PRINT_VERBOSE) | PRINT_NAMEVAL;
|
|
|
|
break;
|
|
|
|
case 'q':
|
|
|
|
pflags |= PRINT_QUOTED;
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
pflags = (pflags & ~(PRINT_HEADER | PRINT_VERBOSE)) |
|
|
|
|
PRINT_NAMEVAL | PRINT_QUOTED | PRINT_SKIP;
|
|
|
|
break;
|
|
|
|
case 'v':
|
2009-07-08 15:57:22 +00:00
|
|
|
pflags = (pflags &
|
|
|
|
~(PRINT_HEADER | PRINT_NAMEVAL | PRINT_SKIP)) |
|
2009-05-27 14:30:26 +00:00
|
|
|
PRINT_VERBOSE;
|
|
|
|
break;
|
|
|
|
default:
|
2015-12-22 00:58:35 +00:00
|
|
|
xo_errx(1, "usage: jls [-dhNnqv] [-j jail] [param ...]");
|
2009-05-27 14:30:26 +00:00
|
|
|
}
|
|
|
|
|
2011-05-29 21:03:40 +00:00
|
|
|
#ifdef INET6
|
|
|
|
ip6_ok = feature_present("inet6");
|
|
|
|
#endif
|
|
|
|
#ifdef INET
|
|
|
|
ip4_ok = feature_present("inet");
|
|
|
|
#endif
|
|
|
|
|
2009-05-27 14:30:26 +00:00
|
|
|
/* Add the parameters to print. */
|
|
|
|
if (optind == argc) {
|
2009-07-08 15:57:22 +00:00
|
|
|
if (pflags & (PRINT_HEADER | PRINT_NAMEVAL))
|
|
|
|
add_param("all", NULL, (size_t)0, NULL, JP_USER);
|
|
|
|
else if (pflags & PRINT_VERBOSE) {
|
2009-06-24 18:18:35 +00:00
|
|
|
add_param("jid", NULL, (size_t)0, NULL, JP_USER);
|
|
|
|
add_param("host.hostname", NULL, (size_t)0, NULL,
|
|
|
|
JP_USER);
|
|
|
|
add_param("path", NULL, (size_t)0, NULL, JP_USER);
|
|
|
|
add_param("name", NULL, (size_t)0, NULL, JP_USER);
|
|
|
|
add_param("dying", NULL, (size_t)0, NULL, JP_USER);
|
|
|
|
add_param("cpuset.id", NULL, (size_t)0, NULL, JP_USER);
|
2011-05-29 21:03:40 +00:00
|
|
|
#ifdef INET
|
|
|
|
if (ip4_ok)
|
|
|
|
add_param("ip4.addr", NULL, (size_t)0, NULL,
|
|
|
|
JP_USER);
|
|
|
|
#endif
|
|
|
|
#ifdef INET6
|
|
|
|
if (ip6_ok)
|
|
|
|
add_param("ip6.addr", NULL, (size_t)0, NULL,
|
|
|
|
JP_USER | JP_OPT);
|
|
|
|
#endif
|
2009-05-27 14:30:26 +00:00
|
|
|
} else {
|
2009-07-08 15:57:22 +00:00
|
|
|
pflags |= PRINT_DEFAULT;
|
2013-05-17 08:48:16 +00:00
|
|
|
if (pflags & PRINT_JAIL_NAME)
|
|
|
|
add_param("name", NULL, (size_t)0, NULL, JP_USER);
|
|
|
|
else
|
|
|
|
add_param("jid", NULL, (size_t)0, NULL, JP_USER);
|
2011-05-29 21:03:40 +00:00
|
|
|
#ifdef INET
|
|
|
|
if (ip4_ok)
|
|
|
|
add_param("ip4.addr", NULL, (size_t)0, NULL,
|
|
|
|
JP_USER);
|
|
|
|
#endif
|
2009-06-24 18:18:35 +00:00
|
|
|
add_param("host.hostname", NULL, (size_t)0, NULL,
|
|
|
|
JP_USER);
|
|
|
|
add_param("path", NULL, (size_t)0, NULL, JP_USER);
|
2009-05-27 14:30:26 +00:00
|
|
|
}
|
2015-02-20 19:48:24 +00:00
|
|
|
} else {
|
|
|
|
pflags &= ~PRINT_VERBOSE;
|
2009-05-27 14:30:26 +00:00
|
|
|
while (optind < argc)
|
2009-06-24 18:18:35 +00:00
|
|
|
add_param(argv[optind++], NULL, (size_t)0, NULL,
|
|
|
|
JP_USER);
|
2015-02-20 19:48:24 +00:00
|
|
|
}
|
2009-05-27 14:30:26 +00:00
|
|
|
|
|
|
|
if (pflags & PRINT_SKIP) {
|
2009-07-25 14:48:57 +00:00
|
|
|
/* Check for parameters with jailsys parents. */
|
2009-05-27 14:30:26 +00:00
|
|
|
for (i = 0; i < nparams; i++) {
|
2009-06-24 18:18:35 +00:00
|
|
|
if ((params[i].jp_flags & JP_USER) &&
|
|
|
|
(dot = strchr(params[i].jp_name, '.'))) {
|
2015-02-20 20:12:05 +00:00
|
|
|
pname = alloca((dot - params[i].jp_name) + 1);
|
|
|
|
strlcpy(pname, params[i].jp_name,
|
|
|
|
(dot - params[i].jp_name) + 1);
|
|
|
|
param_parent[i] = add_param(pname,
|
2009-07-25 14:48:57 +00:00
|
|
|
NULL, (size_t)0, NULL, JP_OPT);
|
2009-05-27 14:30:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-24 18:18:35 +00:00
|
|
|
/* Add the index key parameters. */
|
2009-05-27 14:30:26 +00:00
|
|
|
if (jid != 0)
|
2009-06-24 18:18:35 +00:00
|
|
|
add_param("jid", &jid, sizeof(jid), NULL, 0);
|
2009-05-27 14:30:26 +00:00
|
|
|
else if (jname != NULL)
|
2009-06-24 18:18:35 +00:00
|
|
|
add_param("name", jname, strlen(jname), NULL, 0);
|
2009-05-27 14:30:26 +00:00
|
|
|
else
|
2009-06-24 18:18:35 +00:00
|
|
|
add_param("lastjid", &lastjid, sizeof(lastjid), NULL, 0);
|
2009-05-27 14:30:26 +00:00
|
|
|
|
|
|
|
/* Print a header line if requested. */
|
2015-12-22 00:58:35 +00:00
|
|
|
if (pflags & PRINT_VERBOSE) {
|
|
|
|
xo_emit("{T:/%3s}{T:JID}{P: }{T:Hostname}{Pd:/%22s}{T:Path}\n",
|
|
|
|
"", "");
|
|
|
|
xo_emit("{P:/%8s}{T:Name}{Pd:/%26s}{T:State}\n", "", "");
|
|
|
|
xo_emit("{P:/%8s}{T:CPUSetID}\n", "");
|
|
|
|
xo_emit("{P:/%8s}{T:IP Address(es)}\n", "");
|
|
|
|
}
|
2009-05-27 14:30:26 +00:00
|
|
|
else if (pflags & PRINT_DEFAULT)
|
2013-05-17 08:48:16 +00:00
|
|
|
if (pflags & PRINT_JAIL_NAME)
|
2015-12-22 00:58:35 +00:00
|
|
|
xo_emit("{P: }{T:JID/%-15s}{P: }{T:IP Address/%-15s}"
|
|
|
|
"{P: }{T:Hostname/%-29s}{P: }{T:Path}\n");
|
2013-05-17 08:48:16 +00:00
|
|
|
else
|
2015-12-22 00:58:35 +00:00
|
|
|
xo_emit("{T:JID/%6s}{P: }{T:IP Address}{P:/%6s}"
|
|
|
|
"{T:Hostname}{P:/%22s}{T:Path}\n", "", "");
|
2009-05-27 14:30:26 +00:00
|
|
|
else if (pflags & PRINT_HEADER) {
|
|
|
|
for (i = spc = 0; i < nparams; i++)
|
2009-06-24 18:18:35 +00:00
|
|
|
if (params[i].jp_flags & JP_USER) {
|
2009-05-27 14:30:26 +00:00
|
|
|
if (spc)
|
2015-12-22 00:58:35 +00:00
|
|
|
xo_emit("{P: }");
|
2009-05-27 14:30:26 +00:00
|
|
|
else
|
|
|
|
spc = 1;
|
2015-12-22 00:58:35 +00:00
|
|
|
xo_emit(params[i].jp_name);
|
2009-05-27 14:30:26 +00:00
|
|
|
}
|
2015-12-22 00:58:35 +00:00
|
|
|
xo_emit("{P:\n}");
|
2009-05-27 14:30:26 +00:00
|
|
|
}
|
|
|
|
|
2015-12-22 00:58:35 +00:00
|
|
|
xo_open_container("jail-information");
|
|
|
|
xo_open_list("jail");
|
2015-10-21 05:37:09 +00:00
|
|
|
/* Fetch the jail(s) and print the parameters. */
|
2009-05-27 14:30:26 +00:00
|
|
|
if (jid != 0 || jname != NULL) {
|
2009-06-24 18:18:35 +00:00
|
|
|
if (print_jail(pflags, jflags) < 0)
|
2015-12-22 00:58:35 +00:00
|
|
|
xo_errx(1, "%s", jail_errmsg);
|
2008-12-14 16:56:47 +00:00
|
|
|
} else {
|
2009-05-27 14:30:26 +00:00
|
|
|
for (lastjid = 0;
|
|
|
|
(lastjid = print_jail(pflags, jflags)) >= 0; )
|
|
|
|
;
|
2009-06-24 18:18:35 +00:00
|
|
|
if (errno != 0 && errno != ENOENT)
|
2015-12-22 00:58:35 +00:00
|
|
|
xo_errx(1, "%s", jail_errmsg);
|
2008-12-14 16:56:47 +00:00
|
|
|
}
|
2015-12-22 00:58:35 +00:00
|
|
|
xo_close_list("jail");
|
|
|
|
xo_close_container("jail-information");
|
|
|
|
xo_finish();
|
2009-05-27 14:30:26 +00:00
|
|
|
return (0);
|
MFp4:
Bring in updated jail support from bz_jail branch.
This enhances the current jail implementation to permit multiple
addresses per jail. In addtion to IPv4, IPv6 is supported as well.
Due to updated checks it is even possible to have jails without
an IP address at all, which basically gives one a chroot with
restricted process view, no networking,..
SCTP support was updated and supports IPv6 in jails as well.
Cpuset support permits jails to be bound to specific processor
sets after creation.
Jails can have an unrestricted (no duplicate protection, etc.) name
in addition to the hostname. The jail name cannot be changed from
within a jail and is considered to be used for management purposes
or as audit-token in the future.
DDB 'show jails' command was added to aid debugging.
Proper compat support permits 32bit jail binaries to be used on 64bit
systems to manage jails. Also backward compatibility was preserved where
possible: for jail v1 syscalls, as well as with user space management
utilities.
Both jail as well as prison version were updated for the new features.
A gap was intentionally left as the intermediate versions had been
used by various patches floating around the last years.
Bump __FreeBSD_version for the afore mentioned and in kernel changes.
Special thanks to:
- Pawel Jakub Dawidek (pjd) for his multi-IPv4 patches
and Olivier Houchard (cognet) for initial single-IPv6 patches.
- Jeff Roberson (jeff) and Randall Stewart (rrs) for their
help, ideas and review on cpuset and SCTP support.
- Robert Watson (rwatson) for lots and lots of help, discussions,
suggestions and review of most of the patch at various stages.
- John Baldwin (jhb) for his help.
- Simon L. Nielsen (simon) as early adopter testing changes
on cluster machines as well as all the testers and people
who provided feedback the last months on freebsd-jail and
other channels.
- My employer, CK Software GmbH, for the support so I could work on this.
Reviewed by: (see above)
MFC after: 3 months (this is just so that I get the mail)
X-MFC Before: 7.2-RELEASE if possible
2008-11-29 14:32:14 +00:00
|
|
|
}
|
|
|
|
|
2009-05-27 14:30:26 +00:00
|
|
|
static int
|
2009-06-24 18:18:35 +00:00
|
|
|
add_param(const char *name, void *value, size_t valuelen,
|
|
|
|
struct jailparam *source, unsigned flags)
|
MFp4:
Bring in updated jail support from bz_jail branch.
This enhances the current jail implementation to permit multiple
addresses per jail. In addtion to IPv4, IPv6 is supported as well.
Due to updated checks it is even possible to have jails without
an IP address at all, which basically gives one a chroot with
restricted process view, no networking,..
SCTP support was updated and supports IPv6 in jails as well.
Cpuset support permits jails to be bound to specific processor
sets after creation.
Jails can have an unrestricted (no duplicate protection, etc.) name
in addition to the hostname. The jail name cannot be changed from
within a jail and is considered to be used for management purposes
or as audit-token in the future.
DDB 'show jails' command was added to aid debugging.
Proper compat support permits 32bit jail binaries to be used on 64bit
systems to manage jails. Also backward compatibility was preserved where
possible: for jail v1 syscalls, as well as with user space management
utilities.
Both jail as well as prison version were updated for the new features.
A gap was intentionally left as the intermediate versions had been
used by various patches floating around the last years.
Bump __FreeBSD_version for the afore mentioned and in kernel changes.
Special thanks to:
- Pawel Jakub Dawidek (pjd) for his multi-IPv4 patches
and Olivier Houchard (cognet) for initial single-IPv6 patches.
- Jeff Roberson (jeff) and Randall Stewart (rrs) for their
help, ideas and review on cpuset and SCTP support.
- Robert Watson (rwatson) for lots and lots of help, discussions,
suggestions and review of most of the patch at various stages.
- John Baldwin (jhb) for his help.
- Simon L. Nielsen (simon) as early adopter testing changes
on cluster machines as well as all the testers and people
who provided feedback the last months on freebsd-jail and
other channels.
- My employer, CK Software GmbH, for the support so I could work on this.
Reviewed by: (see above)
MFC after: 3 months (this is just so that I get the mail)
X-MFC Before: 7.2-RELEASE if possible
2008-11-29 14:32:14 +00:00
|
|
|
{
|
2009-06-24 18:18:35 +00:00
|
|
|
struct jailparam *param, *tparams;
|
2009-05-27 14:30:26 +00:00
|
|
|
int i, tnparams;
|
|
|
|
|
|
|
|
static int paramlistsize;
|
|
|
|
|
|
|
|
/* The pseudo-parameter "all" scans the list of available parameters. */
|
|
|
|
if (!strcmp(name, "all")) {
|
2009-06-24 18:18:35 +00:00
|
|
|
tnparams = jailparam_all(&tparams);
|
|
|
|
if (tnparams < 0)
|
2015-12-22 00:58:35 +00:00
|
|
|
xo_errx(1, "%s", jail_errmsg);
|
2009-06-24 18:18:35 +00:00
|
|
|
qsort(tparams, (size_t)tnparams, sizeof(struct jailparam),
|
|
|
|
sort_param);
|
|
|
|
for (i = 0; i < tnparams; i++)
|
|
|
|
add_param(tparams[i].jp_name, NULL, (size_t)0,
|
|
|
|
tparams + i, flags);
|
|
|
|
free(tparams);
|
2009-05-27 14:30:26 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for repeat parameters. */
|
|
|
|
for (i = 0; i < nparams; i++)
|
2009-06-24 18:18:35 +00:00
|
|
|
if (!strcmp(name, params[i].jp_name)) {
|
|
|
|
if (value != NULL && jailparam_import_raw(params + i,
|
|
|
|
value, valuelen) < 0)
|
2015-12-22 00:58:35 +00:00
|
|
|
xo_errx(1, "%s", jail_errmsg);
|
2009-06-24 18:18:35 +00:00
|
|
|
params[i].jp_flags |= flags;
|
|
|
|
if (source != NULL)
|
|
|
|
jailparam_free(source, 1);
|
2009-05-27 14:30:26 +00:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make sure there is room for the new param record. */
|
|
|
|
if (!nparams) {
|
|
|
|
paramlistsize = 32;
|
|
|
|
params = malloc(paramlistsize * sizeof(*params));
|
2009-07-25 14:48:57 +00:00
|
|
|
param_parent = malloc(paramlistsize * sizeof(*param_parent));
|
|
|
|
if (params == NULL || param_parent == NULL)
|
2015-12-22 00:58:35 +00:00
|
|
|
xo_err(1, "malloc");
|
2009-05-27 14:30:26 +00:00
|
|
|
} else if (nparams >= paramlistsize) {
|
|
|
|
paramlistsize *= 2;
|
|
|
|
params = realloc(params, paramlistsize * sizeof(*params));
|
2009-07-25 14:48:57 +00:00
|
|
|
param_parent = realloc(param_parent,
|
|
|
|
paramlistsize * sizeof(*param_parent));
|
|
|
|
if (params == NULL || param_parent == NULL)
|
2015-12-22 00:58:35 +00:00
|
|
|
xo_err(1, "realloc");
|
2009-05-27 14:30:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Look up the parameter. */
|
2009-07-25 14:48:57 +00:00
|
|
|
param_parent[nparams] = -1;
|
2009-05-27 14:30:26 +00:00
|
|
|
param = params + nparams++;
|
2009-06-24 18:18:35 +00:00
|
|
|
if (source != NULL) {
|
|
|
|
*param = *source;
|
|
|
|
param->jp_flags |= flags;
|
|
|
|
return param - params;
|
2009-05-27 14:30:26 +00:00
|
|
|
}
|
2015-02-22 00:00:10 +00:00
|
|
|
if (jailparam_init(param, name) < 0 ||
|
|
|
|
(value != NULL ? jailparam_import_raw(param, value, valuelen)
|
2009-06-24 18:18:35 +00:00
|
|
|
: jailparam_import(param, value)) < 0) {
|
|
|
|
if (flags & JP_OPT) {
|
2009-05-27 14:30:26 +00:00
|
|
|
nparams--;
|
2009-06-24 18:18:35 +00:00
|
|
|
return (-1);
|
2009-05-27 14:30:26 +00:00
|
|
|
}
|
2015-12-22 00:58:35 +00:00
|
|
|
xo_errx(1, "%s", jail_errmsg);
|
MFp4:
Bring in updated jail support from bz_jail branch.
This enhances the current jail implementation to permit multiple
addresses per jail. In addtion to IPv4, IPv6 is supported as well.
Due to updated checks it is even possible to have jails without
an IP address at all, which basically gives one a chroot with
restricted process view, no networking,..
SCTP support was updated and supports IPv6 in jails as well.
Cpuset support permits jails to be bound to specific processor
sets after creation.
Jails can have an unrestricted (no duplicate protection, etc.) name
in addition to the hostname. The jail name cannot be changed from
within a jail and is considered to be used for management purposes
or as audit-token in the future.
DDB 'show jails' command was added to aid debugging.
Proper compat support permits 32bit jail binaries to be used on 64bit
systems to manage jails. Also backward compatibility was preserved where
possible: for jail v1 syscalls, as well as with user space management
utilities.
Both jail as well as prison version were updated for the new features.
A gap was intentionally left as the intermediate versions had been
used by various patches floating around the last years.
Bump __FreeBSD_version for the afore mentioned and in kernel changes.
Special thanks to:
- Pawel Jakub Dawidek (pjd) for his multi-IPv4 patches
and Olivier Houchard (cognet) for initial single-IPv6 patches.
- Jeff Roberson (jeff) and Randall Stewart (rrs) for their
help, ideas and review on cpuset and SCTP support.
- Robert Watson (rwatson) for lots and lots of help, discussions,
suggestions and review of most of the patch at various stages.
- John Baldwin (jhb) for his help.
- Simon L. Nielsen (simon) as early adopter testing changes
on cluster machines as well as all the testers and people
who provided feedback the last months on freebsd-jail and
other channels.
- My employer, CK Software GmbH, for the support so I could work on this.
Reviewed by: (see above)
MFC after: 3 months (this is just so that I get the mail)
X-MFC Before: 7.2-RELEASE if possible
2008-11-29 14:32:14 +00:00
|
|
|
}
|
2015-02-22 00:00:10 +00:00
|
|
|
param->jp_flags = flags;
|
2009-05-27 14:30:26 +00:00
|
|
|
return param - params;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
sort_param(const void *a, const void *b)
|
|
|
|
{
|
2009-06-24 18:18:35 +00:00
|
|
|
const struct jailparam *parama, *paramb;
|
2009-05-27 14:30:26 +00:00
|
|
|
char *ap, *bp;
|
2008-12-14 16:56:47 +00:00
|
|
|
|
2009-05-27 14:30:26 +00:00
|
|
|
/* Put top-level parameters first. */
|
|
|
|
parama = a;
|
|
|
|
paramb = b;
|
2009-06-24 18:18:35 +00:00
|
|
|
ap = strchr(parama->jp_name, '.');
|
|
|
|
bp = strchr(paramb->jp_name, '.');
|
2009-05-27 14:30:26 +00:00
|
|
|
if (ap && !bp)
|
|
|
|
return (1);
|
|
|
|
if (bp && !ap)
|
|
|
|
return (-1);
|
2009-06-24 18:18:35 +00:00
|
|
|
return (strcmp(parama->jp_name, paramb->jp_name));
|
MFp4:
Bring in updated jail support from bz_jail branch.
This enhances the current jail implementation to permit multiple
addresses per jail. In addtion to IPv4, IPv6 is supported as well.
Due to updated checks it is even possible to have jails without
an IP address at all, which basically gives one a chroot with
restricted process view, no networking,..
SCTP support was updated and supports IPv6 in jails as well.
Cpuset support permits jails to be bound to specific processor
sets after creation.
Jails can have an unrestricted (no duplicate protection, etc.) name
in addition to the hostname. The jail name cannot be changed from
within a jail and is considered to be used for management purposes
or as audit-token in the future.
DDB 'show jails' command was added to aid debugging.
Proper compat support permits 32bit jail binaries to be used on 64bit
systems to manage jails. Also backward compatibility was preserved where
possible: for jail v1 syscalls, as well as with user space management
utilities.
Both jail as well as prison version were updated for the new features.
A gap was intentionally left as the intermediate versions had been
used by various patches floating around the last years.
Bump __FreeBSD_version for the afore mentioned and in kernel changes.
Special thanks to:
- Pawel Jakub Dawidek (pjd) for his multi-IPv4 patches
and Olivier Houchard (cognet) for initial single-IPv6 patches.
- Jeff Roberson (jeff) and Randall Stewart (rrs) for their
help, ideas and review on cpuset and SCTP support.
- Robert Watson (rwatson) for lots and lots of help, discussions,
suggestions and review of most of the patch at various stages.
- John Baldwin (jhb) for his help.
- Simon L. Nielsen (simon) as early adopter testing changes
on cluster machines as well as all the testers and people
who provided feedback the last months on freebsd-jail and
other channels.
- My employer, CK Software GmbH, for the support so I could work on this.
Reviewed by: (see above)
MFC after: 3 months (this is just so that I get the mail)
X-MFC Before: 7.2-RELEASE if possible
2008-11-29 14:32:14 +00:00
|
|
|
}
|
|
|
|
|
2009-05-27 14:30:26 +00:00
|
|
|
static char *
|
|
|
|
noname(const char *name)
|
MFp4:
Bring in updated jail support from bz_jail branch.
This enhances the current jail implementation to permit multiple
addresses per jail. In addtion to IPv4, IPv6 is supported as well.
Due to updated checks it is even possible to have jails without
an IP address at all, which basically gives one a chroot with
restricted process view, no networking,..
SCTP support was updated and supports IPv6 in jails as well.
Cpuset support permits jails to be bound to specific processor
sets after creation.
Jails can have an unrestricted (no duplicate protection, etc.) name
in addition to the hostname. The jail name cannot be changed from
within a jail and is considered to be used for management purposes
or as audit-token in the future.
DDB 'show jails' command was added to aid debugging.
Proper compat support permits 32bit jail binaries to be used on 64bit
systems to manage jails. Also backward compatibility was preserved where
possible: for jail v1 syscalls, as well as with user space management
utilities.
Both jail as well as prison version were updated for the new features.
A gap was intentionally left as the intermediate versions had been
used by various patches floating around the last years.
Bump __FreeBSD_version for the afore mentioned and in kernel changes.
Special thanks to:
- Pawel Jakub Dawidek (pjd) for his multi-IPv4 patches
and Olivier Houchard (cognet) for initial single-IPv6 patches.
- Jeff Roberson (jeff) and Randall Stewart (rrs) for their
help, ideas and review on cpuset and SCTP support.
- Robert Watson (rwatson) for lots and lots of help, discussions,
suggestions and review of most of the patch at various stages.
- John Baldwin (jhb) for his help.
- Simon L. Nielsen (simon) as early adopter testing changes
on cluster machines as well as all the testers and people
who provided feedback the last months on freebsd-jail and
other channels.
- My employer, CK Software GmbH, for the support so I could work on this.
Reviewed by: (see above)
MFC after: 3 months (this is just so that I get the mail)
X-MFC Before: 7.2-RELEASE if possible
2008-11-29 14:32:14 +00:00
|
|
|
{
|
2009-05-27 14:30:26 +00:00
|
|
|
char *nname, *p;
|
MFp4:
Bring in updated jail support from bz_jail branch.
This enhances the current jail implementation to permit multiple
addresses per jail. In addtion to IPv4, IPv6 is supported as well.
Due to updated checks it is even possible to have jails without
an IP address at all, which basically gives one a chroot with
restricted process view, no networking,..
SCTP support was updated and supports IPv6 in jails as well.
Cpuset support permits jails to be bound to specific processor
sets after creation.
Jails can have an unrestricted (no duplicate protection, etc.) name
in addition to the hostname. The jail name cannot be changed from
within a jail and is considered to be used for management purposes
or as audit-token in the future.
DDB 'show jails' command was added to aid debugging.
Proper compat support permits 32bit jail binaries to be used on 64bit
systems to manage jails. Also backward compatibility was preserved where
possible: for jail v1 syscalls, as well as with user space management
utilities.
Both jail as well as prison version were updated for the new features.
A gap was intentionally left as the intermediate versions had been
used by various patches floating around the last years.
Bump __FreeBSD_version for the afore mentioned and in kernel changes.
Special thanks to:
- Pawel Jakub Dawidek (pjd) for his multi-IPv4 patches
and Olivier Houchard (cognet) for initial single-IPv6 patches.
- Jeff Roberson (jeff) and Randall Stewart (rrs) for their
help, ideas and review on cpuset and SCTP support.
- Robert Watson (rwatson) for lots and lots of help, discussions,
suggestions and review of most of the patch at various stages.
- John Baldwin (jhb) for his help.
- Simon L. Nielsen (simon) as early adopter testing changes
on cluster machines as well as all the testers and people
who provided feedback the last months on freebsd-jail and
other channels.
- My employer, CK Software GmbH, for the support so I could work on this.
Reviewed by: (see above)
MFC after: 3 months (this is just so that I get the mail)
X-MFC Before: 7.2-RELEASE if possible
2008-11-29 14:32:14 +00:00
|
|
|
|
2009-05-27 14:30:26 +00:00
|
|
|
nname = malloc(strlen(name) + 3);
|
|
|
|
if (nname == NULL)
|
2015-12-22 00:58:35 +00:00
|
|
|
xo_err(1, "malloc");
|
2009-05-27 14:30:26 +00:00
|
|
|
p = strrchr(name, '.');
|
|
|
|
if (p != NULL)
|
|
|
|
sprintf(nname, "%.*s.no%s", (int)(p - name), name, p + 1);
|
|
|
|
else
|
|
|
|
sprintf(nname, "no%s", name);
|
|
|
|
return nname;
|
MFp4:
Bring in updated jail support from bz_jail branch.
This enhances the current jail implementation to permit multiple
addresses per jail. In addtion to IPv4, IPv6 is supported as well.
Due to updated checks it is even possible to have jails without
an IP address at all, which basically gives one a chroot with
restricted process view, no networking,..
SCTP support was updated and supports IPv6 in jails as well.
Cpuset support permits jails to be bound to specific processor
sets after creation.
Jails can have an unrestricted (no duplicate protection, etc.) name
in addition to the hostname. The jail name cannot be changed from
within a jail and is considered to be used for management purposes
or as audit-token in the future.
DDB 'show jails' command was added to aid debugging.
Proper compat support permits 32bit jail binaries to be used on 64bit
systems to manage jails. Also backward compatibility was preserved where
possible: for jail v1 syscalls, as well as with user space management
utilities.
Both jail as well as prison version were updated for the new features.
A gap was intentionally left as the intermediate versions had been
used by various patches floating around the last years.
Bump __FreeBSD_version for the afore mentioned and in kernel changes.
Special thanks to:
- Pawel Jakub Dawidek (pjd) for his multi-IPv4 patches
and Olivier Houchard (cognet) for initial single-IPv6 patches.
- Jeff Roberson (jeff) and Randall Stewart (rrs) for their
help, ideas and review on cpuset and SCTP support.
- Robert Watson (rwatson) for lots and lots of help, discussions,
suggestions and review of most of the patch at various stages.
- John Baldwin (jhb) for his help.
- Simon L. Nielsen (simon) as early adopter testing changes
on cluster machines as well as all the testers and people
who provided feedback the last months on freebsd-jail and
other channels.
- My employer, CK Software GmbH, for the support so I could work on this.
Reviewed by: (see above)
MFC after: 3 months (this is just so that I get the mail)
X-MFC Before: 7.2-RELEASE if possible
2008-11-29 14:32:14 +00:00
|
|
|
}
|
2003-04-09 03:04:12 +00:00
|
|
|
|
2009-05-27 14:30:26 +00:00
|
|
|
static char *
|
|
|
|
nononame(const char *name)
|
|
|
|
{
|
|
|
|
char *nname, *p;
|
MFp4:
Bring in updated jail support from bz_jail branch.
This enhances the current jail implementation to permit multiple
addresses per jail. In addtion to IPv4, IPv6 is supported as well.
Due to updated checks it is even possible to have jails without
an IP address at all, which basically gives one a chroot with
restricted process view, no networking,..
SCTP support was updated and supports IPv6 in jails as well.
Cpuset support permits jails to be bound to specific processor
sets after creation.
Jails can have an unrestricted (no duplicate protection, etc.) name
in addition to the hostname. The jail name cannot be changed from
within a jail and is considered to be used for management purposes
or as audit-token in the future.
DDB 'show jails' command was added to aid debugging.
Proper compat support permits 32bit jail binaries to be used on 64bit
systems to manage jails. Also backward compatibility was preserved where
possible: for jail v1 syscalls, as well as with user space management
utilities.
Both jail as well as prison version were updated for the new features.
A gap was intentionally left as the intermediate versions had been
used by various patches floating around the last years.
Bump __FreeBSD_version for the afore mentioned and in kernel changes.
Special thanks to:
- Pawel Jakub Dawidek (pjd) for his multi-IPv4 patches
and Olivier Houchard (cognet) for initial single-IPv6 patches.
- Jeff Roberson (jeff) and Randall Stewart (rrs) for their
help, ideas and review on cpuset and SCTP support.
- Robert Watson (rwatson) for lots and lots of help, discussions,
suggestions and review of most of the patch at various stages.
- John Baldwin (jhb) for his help.
- Simon L. Nielsen (simon) as early adopter testing changes
on cluster machines as well as all the testers and people
who provided feedback the last months on freebsd-jail and
other channels.
- My employer, CK Software GmbH, for the support so I could work on this.
Reviewed by: (see above)
MFC after: 3 months (this is just so that I get the mail)
X-MFC Before: 7.2-RELEASE if possible
2008-11-29 14:32:14 +00:00
|
|
|
|
2009-05-27 14:30:26 +00:00
|
|
|
p = strrchr(name, '.');
|
|
|
|
if (strncmp(p ? p + 1 : name, "no", 2))
|
|
|
|
return NULL;
|
|
|
|
nname = malloc(strlen(name) - 1);
|
|
|
|
if (nname == NULL)
|
2015-12-22 00:58:35 +00:00
|
|
|
xo_err(1, "malloc");
|
2009-05-27 14:30:26 +00:00
|
|
|
if (p != NULL)
|
|
|
|
sprintf(nname, "%.*s.%s", (int)(p - name), name, p + 3);
|
|
|
|
else
|
|
|
|
strcpy(nname, name + 2);
|
|
|
|
return nname;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
print_jail(int pflags, int jflags)
|
|
|
|
{
|
2015-12-22 00:58:35 +00:00
|
|
|
char *nname, *xo_nname;
|
2009-06-24 18:18:35 +00:00
|
|
|
char **param_values;
|
Improve IP address list representation in libxo output.
Extract decision-making about special-case printing of certain
jail parameters into a function.
Refactor emitting of IPv4 and IPv6 address lists into a function.
Resulting user-facing changes:
XO_VERSION is bumped to 2.
In verbose mode (-v), IPv4 and IPv6-Addresses are now properly emitted
as separate lists.
This only affects the output in encoding styles, i.e. xml and json.
{ {
"__version": "1", "__version": "2",
"jail-information": { "jail-information": {
"jail": [ "jail": [
{ {
"jid": 166, "jid": 166,
"hostname": "foo.com", "hostname": "foo.com",
"path": "/var/jail/foo", "path": "/var/jail/foo",
"name": "foo", "name": "foo",
"state": "ACTIVE", "state": "ACTIVE",
"cpusetid": 2, "cpusetid": 2,
"ipv4_addrs": [ "ipv4_addrs": [
"10.1.1.1", "10.1.1.1",
"10.1.1.2", "10.1.1.2",
"10.1.1.3", | "10.1.1.3"
> ],
> "ipv6_addrs": [
"fe80::1000:1", "fe80::1000:1",
"fe80::1000:2" "fe80::1000:2"
] ]
} }
] ]
} }
} }
In -n mode, ip4.addr and ip6.addr are formatted in the encoding styles'
native list types, e.g. instead of comma-separated lists, JSON arrays
are printed.
jls -n all --libxo json
...
"ip4.addr": [
"10.1.1.1",
"10.1.1.2",
"10.1.1.3"
],
"ip4.saddrsel": true,
"ip6.addr": [
"fe80::1000:1",
"fe80::1000:2"
],
...
jls -n all --libxo xml
...
<ip4.addr>10.1.1.1</ip4.addr>
<ip4.addr>10.1.1.2</ip4.addr>
<ip4.addr>10.1.1.3</ip4.addr>
<ip4.saddrsel>true</ip4.saddrsel>
<ip6.addr>fe80::1000:1</ip6.addr>
<ip6.addr>fe80::1000:2</ip6.addr>
...
PR: 215008
Submitted by: Christian Schwarz <me@cschwarz.com>
Differential Revision: https://reviews.freebsd.org/D8766
2016-12-24 23:51:27 +00:00
|
|
|
int i, jid, n, spc;
|
2009-05-27 14:30:26 +00:00
|
|
|
|
2009-06-24 18:18:35 +00:00
|
|
|
jid = jailparam_get(params, nparams, jflags);
|
|
|
|
if (jid < 0)
|
|
|
|
return jid;
|
2015-12-22 00:58:35 +00:00
|
|
|
|
|
|
|
xo_open_instance("jail");
|
|
|
|
|
2009-05-27 14:30:26 +00:00
|
|
|
if (pflags & PRINT_VERBOSE) {
|
2015-12-22 00:58:35 +00:00
|
|
|
xo_emit("{:jid/%6d}{P: }{:hostname/%-29.29s/%s}{P: }"
|
|
|
|
"{:path/%.74s/%s}\n",
|
2009-06-24 18:18:35 +00:00
|
|
|
*(int *)params[0].jp_value,
|
|
|
|
(char *)params[1].jp_value,
|
2015-12-22 00:58:35 +00:00
|
|
|
(char *)params[2].jp_value);
|
|
|
|
xo_emit("{P: }{:name/%-29.29s/%s}{P: }{:state/%.74s}\n",
|
2009-06-24 18:18:35 +00:00
|
|
|
(char *)params[3].jp_value,
|
2015-12-22 00:58:35 +00:00
|
|
|
*(int *)params[4].jp_value ? "DYING" : "ACTIVE");
|
|
|
|
xo_emit("{P: }{:cpusetid/%d}\n", *(int *)params[5].jp_value);
|
2011-05-29 21:03:40 +00:00
|
|
|
n = 6;
|
|
|
|
#ifdef INET
|
2011-08-13 13:49:11 +00:00
|
|
|
if (ip4_ok && !strcmp(params[n].jp_name, "ip4.addr")) {
|
Improve IP address list representation in libxo output.
Extract decision-making about special-case printing of certain
jail parameters into a function.
Refactor emitting of IPv4 and IPv6 address lists into a function.
Resulting user-facing changes:
XO_VERSION is bumped to 2.
In verbose mode (-v), IPv4 and IPv6-Addresses are now properly emitted
as separate lists.
This only affects the output in encoding styles, i.e. xml and json.
{ {
"__version": "1", "__version": "2",
"jail-information": { "jail-information": {
"jail": [ "jail": [
{ {
"jid": 166, "jid": 166,
"hostname": "foo.com", "hostname": "foo.com",
"path": "/var/jail/foo", "path": "/var/jail/foo",
"name": "foo", "name": "foo",
"state": "ACTIVE", "state": "ACTIVE",
"cpusetid": 2, "cpusetid": 2,
"ipv4_addrs": [ "ipv4_addrs": [
"10.1.1.1", "10.1.1.1",
"10.1.1.2", "10.1.1.2",
"10.1.1.3", | "10.1.1.3"
> ],
> "ipv6_addrs": [
"fe80::1000:1", "fe80::1000:1",
"fe80::1000:2" "fe80::1000:2"
] ]
} }
] ]
} }
} }
In -n mode, ip4.addr and ip6.addr are formatted in the encoding styles'
native list types, e.g. instead of comma-separated lists, JSON arrays
are printed.
jls -n all --libxo json
...
"ip4.addr": [
"10.1.1.1",
"10.1.1.2",
"10.1.1.3"
],
"ip4.saddrsel": true,
"ip6.addr": [
"fe80::1000:1",
"fe80::1000:2"
],
...
jls -n all --libxo xml
...
<ip4.addr>10.1.1.1</ip4.addr>
<ip4.addr>10.1.1.2</ip4.addr>
<ip4.addr>10.1.1.3</ip4.addr>
<ip4.saddrsel>true</ip4.saddrsel>
<ip6.addr>fe80::1000:1</ip6.addr>
<ip6.addr>fe80::1000:2</ip6.addr>
...
PR: 215008
Submitted by: Christian Schwarz <me@cschwarz.com>
Differential Revision: https://reviews.freebsd.org/D8766
2016-12-24 23:51:27 +00:00
|
|
|
emit_ip_addr_list(AF_INET, "ipv4_addrs", params + n);
|
2011-05-29 21:03:40 +00:00
|
|
|
n++;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef INET6
|
|
|
|
if (ip6_ok && !strcmp(params[n].jp_name, "ip6.addr")) {
|
Improve IP address list representation in libxo output.
Extract decision-making about special-case printing of certain
jail parameters into a function.
Refactor emitting of IPv4 and IPv6 address lists into a function.
Resulting user-facing changes:
XO_VERSION is bumped to 2.
In verbose mode (-v), IPv4 and IPv6-Addresses are now properly emitted
as separate lists.
This only affects the output in encoding styles, i.e. xml and json.
{ {
"__version": "1", "__version": "2",
"jail-information": { "jail-information": {
"jail": [ "jail": [
{ {
"jid": 166, "jid": 166,
"hostname": "foo.com", "hostname": "foo.com",
"path": "/var/jail/foo", "path": "/var/jail/foo",
"name": "foo", "name": "foo",
"state": "ACTIVE", "state": "ACTIVE",
"cpusetid": 2, "cpusetid": 2,
"ipv4_addrs": [ "ipv4_addrs": [
"10.1.1.1", "10.1.1.1",
"10.1.1.2", "10.1.1.2",
"10.1.1.3", | "10.1.1.3"
> ],
> "ipv6_addrs": [
"fe80::1000:1", "fe80::1000:1",
"fe80::1000:2" "fe80::1000:2"
] ]
} }
] ]
} }
} }
In -n mode, ip4.addr and ip6.addr are formatted in the encoding styles'
native list types, e.g. instead of comma-separated lists, JSON arrays
are printed.
jls -n all --libxo json
...
"ip4.addr": [
"10.1.1.1",
"10.1.1.2",
"10.1.1.3"
],
"ip4.saddrsel": true,
"ip6.addr": [
"fe80::1000:1",
"fe80::1000:2"
],
...
jls -n all --libxo xml
...
<ip4.addr>10.1.1.1</ip4.addr>
<ip4.addr>10.1.1.2</ip4.addr>
<ip4.addr>10.1.1.3</ip4.addr>
<ip4.saddrsel>true</ip4.saddrsel>
<ip6.addr>fe80::1000:1</ip6.addr>
<ip6.addr>fe80::1000:2</ip6.addr>
...
PR: 215008
Submitted by: Christian Schwarz <me@cschwarz.com>
Differential Revision: https://reviews.freebsd.org/D8766
2016-12-24 23:51:27 +00:00
|
|
|
emit_ip_addr_list(AF_INET6, "ipv6_addrs", params + n);
|
2011-05-29 21:03:40 +00:00
|
|
|
n++;
|
MFp4:
Bring in updated jail support from bz_jail branch.
This enhances the current jail implementation to permit multiple
addresses per jail. In addtion to IPv4, IPv6 is supported as well.
Due to updated checks it is even possible to have jails without
an IP address at all, which basically gives one a chroot with
restricted process view, no networking,..
SCTP support was updated and supports IPv6 in jails as well.
Cpuset support permits jails to be bound to specific processor
sets after creation.
Jails can have an unrestricted (no duplicate protection, etc.) name
in addition to the hostname. The jail name cannot be changed from
within a jail and is considered to be used for management purposes
or as audit-token in the future.
DDB 'show jails' command was added to aid debugging.
Proper compat support permits 32bit jail binaries to be used on 64bit
systems to manage jails. Also backward compatibility was preserved where
possible: for jail v1 syscalls, as well as with user space management
utilities.
Both jail as well as prison version were updated for the new features.
A gap was intentionally left as the intermediate versions had been
used by various patches floating around the last years.
Bump __FreeBSD_version for the afore mentioned and in kernel changes.
Special thanks to:
- Pawel Jakub Dawidek (pjd) for his multi-IPv4 patches
and Olivier Houchard (cognet) for initial single-IPv6 patches.
- Jeff Roberson (jeff) and Randall Stewart (rrs) for their
help, ideas and review on cpuset and SCTP support.
- Robert Watson (rwatson) for lots and lots of help, discussions,
suggestions and review of most of the patch at various stages.
- John Baldwin (jhb) for his help.
- Simon L. Nielsen (simon) as early adopter testing changes
on cluster machines as well as all the testers and people
who provided feedback the last months on freebsd-jail and
other channels.
- My employer, CK Software GmbH, for the support so I could work on this.
Reviewed by: (see above)
MFC after: 3 months (this is just so that I get the mail)
X-MFC Before: 7.2-RELEASE if possible
2008-11-29 14:32:14 +00:00
|
|
|
}
|
2011-05-29 21:03:40 +00:00
|
|
|
#endif
|
2013-05-17 08:48:16 +00:00
|
|
|
} else if (pflags & PRINT_DEFAULT) {
|
|
|
|
if (pflags & PRINT_JAIL_NAME)
|
2015-12-22 00:58:35 +00:00
|
|
|
xo_emit("{P: }{:name/%-15s/%s}{P: }",
|
|
|
|
(char *)params[0].jp_value);
|
2013-05-17 08:48:16 +00:00
|
|
|
else
|
2015-12-22 00:58:35 +00:00
|
|
|
xo_emit("{:jid/%6d}{P: }", *(int *)params[0].jp_value);
|
|
|
|
xo_emit("{:ipv4/%-15.15s/%s}{P: }{:hostname/%-29.29s/%s}{P: }{:path/%.74s/%s}\n",
|
2011-05-29 21:03:40 +00:00
|
|
|
#ifdef INET
|
2015-12-22 00:58:35 +00:00
|
|
|
(!ip4_ok || params[1].jp_valuelen == 0) ? ""
|
2009-06-24 18:18:35 +00:00
|
|
|
: inet_ntoa(*(struct in_addr *)params[1].jp_value),
|
2012-03-06 18:39:07 +00:00
|
|
|
(char *)params[2-!ip4_ok].jp_value,
|
|
|
|
(char *)params[3-!ip4_ok].jp_value);
|
2011-05-29 21:03:40 +00:00
|
|
|
#else
|
2011-06-18 09:46:39 +00:00
|
|
|
"-",
|
2012-03-06 18:39:07 +00:00
|
|
|
(char *)params[1].jp_value,
|
|
|
|
(char *)params[2].jp_value);
|
2011-05-29 21:03:40 +00:00
|
|
|
#endif
|
2013-05-17 08:48:16 +00:00
|
|
|
} else {
|
2009-06-24 18:18:35 +00:00
|
|
|
param_values = alloca(nparams * sizeof(*param_values));
|
|
|
|
for (i = 0; i < nparams; i++) {
|
|
|
|
if (!(params[i].jp_flags & JP_USER))
|
|
|
|
continue;
|
|
|
|
param_values[i] = jailparam_export(params + i);
|
|
|
|
if (param_values[i] == NULL)
|
2015-12-22 00:58:35 +00:00
|
|
|
xo_errx(1, "%s", jail_errmsg);
|
2009-06-24 18:18:35 +00:00
|
|
|
}
|
2009-05-27 14:30:26 +00:00
|
|
|
for (i = spc = 0; i < nparams; i++) {
|
2009-06-24 18:18:35 +00:00
|
|
|
if (!(params[i].jp_flags & JP_USER))
|
2009-05-27 14:30:26 +00:00
|
|
|
continue;
|
|
|
|
if ((pflags & PRINT_SKIP) &&
|
2009-06-24 18:18:35 +00:00
|
|
|
((!(params[i].jp_ctltype &
|
|
|
|
(CTLFLAG_WR | CTLFLAG_TUN))) ||
|
2009-07-25 14:48:57 +00:00
|
|
|
(param_parent[i] >= 0 &&
|
|
|
|
*(int *)params[param_parent[i]].jp_value !=
|
|
|
|
JAIL_SYS_NEW)))
|
2009-05-27 14:30:26 +00:00
|
|
|
continue;
|
|
|
|
if (spc)
|
2015-12-22 00:58:35 +00:00
|
|
|
xo_emit("{P: }");
|
2009-05-27 14:30:26 +00:00
|
|
|
else
|
|
|
|
spc = 1;
|
|
|
|
if (pflags & PRINT_NAMEVAL) {
|
|
|
|
/*
|
|
|
|
* Generally "name=value", but for booleans
|
|
|
|
* either "name" or "noname".
|
|
|
|
*/
|
2009-06-24 18:18:35 +00:00
|
|
|
if (params[i].jp_flags &
|
|
|
|
(JP_BOOL | JP_NOBOOL)) {
|
2015-12-22 00:58:35 +00:00
|
|
|
if (*(int *)params[i].jp_value) {
|
|
|
|
asprintf(&xo_nname, "{en:%s/true}", params[i].jp_name);
|
|
|
|
xo_emit(xo_nname);
|
|
|
|
xo_emit("{d:/%s}", params[i].jp_name);
|
|
|
|
}
|
2009-05-27 14:30:26 +00:00
|
|
|
else {
|
2009-06-24 18:18:35 +00:00
|
|
|
nname = (params[i].jp_flags &
|
|
|
|
JP_NOBOOL) ?
|
|
|
|
nononame(params[i].jp_name)
|
|
|
|
: noname(params[i].jp_name);
|
2015-12-22 00:58:35 +00:00
|
|
|
if (params[i].jp_flags & JP_NOBOOL) {
|
|
|
|
asprintf(&xo_nname, "{en:%s/true}", params[i].jp_name);
|
|
|
|
xo_emit(xo_nname);
|
|
|
|
} else {
|
|
|
|
asprintf(&xo_nname, "{en:%s/false}", params[i].jp_name);
|
|
|
|
xo_emit(xo_nname);
|
|
|
|
}
|
|
|
|
xo_emit("{d:/%s}", nname);
|
2009-05-27 14:30:26 +00:00
|
|
|
free(nname);
|
|
|
|
}
|
2015-12-22 00:58:35 +00:00
|
|
|
free(xo_nname);
|
2009-06-24 18:18:35 +00:00
|
|
|
continue;
|
2009-05-27 14:30:26 +00:00
|
|
|
}
|
2015-12-22 00:58:35 +00:00
|
|
|
xo_emit("{d:%s}=", params[i].jp_name);
|
2009-05-27 14:30:26 +00:00
|
|
|
}
|
Improve IP address list representation in libxo output.
Extract decision-making about special-case printing of certain
jail parameters into a function.
Refactor emitting of IPv4 and IPv6 address lists into a function.
Resulting user-facing changes:
XO_VERSION is bumped to 2.
In verbose mode (-v), IPv4 and IPv6-Addresses are now properly emitted
as separate lists.
This only affects the output in encoding styles, i.e. xml and json.
{ {
"__version": "1", "__version": "2",
"jail-information": { "jail-information": {
"jail": [ "jail": [
{ {
"jid": 166, "jid": 166,
"hostname": "foo.com", "hostname": "foo.com",
"path": "/var/jail/foo", "path": "/var/jail/foo",
"name": "foo", "name": "foo",
"state": "ACTIVE", "state": "ACTIVE",
"cpusetid": 2, "cpusetid": 2,
"ipv4_addrs": [ "ipv4_addrs": [
"10.1.1.1", "10.1.1.1",
"10.1.1.2", "10.1.1.2",
"10.1.1.3", | "10.1.1.3"
> ],
> "ipv6_addrs": [
"fe80::1000:1", "fe80::1000:1",
"fe80::1000:2" "fe80::1000:2"
] ]
} }
] ]
} }
} }
In -n mode, ip4.addr and ip6.addr are formatted in the encoding styles'
native list types, e.g. instead of comma-separated lists, JSON arrays
are printed.
jls -n all --libxo json
...
"ip4.addr": [
"10.1.1.1",
"10.1.1.2",
"10.1.1.3"
],
"ip4.saddrsel": true,
"ip6.addr": [
"fe80::1000:1",
"fe80::1000:2"
],
...
jls -n all --libxo xml
...
<ip4.addr>10.1.1.1</ip4.addr>
<ip4.addr>10.1.1.2</ip4.addr>
<ip4.addr>10.1.1.3</ip4.addr>
<ip4.saddrsel>true</ip4.saddrsel>
<ip6.addr>fe80::1000:1</ip6.addr>
<ip6.addr>fe80::1000:2</ip6.addr>
...
PR: 215008
Submitted by: Christian Schwarz <me@cschwarz.com>
Differential Revision: https://reviews.freebsd.org/D8766
2016-12-24 23:51:27 +00:00
|
|
|
if (!special_print(pflags, params + i))
|
2015-12-22 00:58:35 +00:00
|
|
|
quoted_print(pflags, params[i].jp_name, param_values[i]);
|
2009-05-27 14:30:26 +00:00
|
|
|
}
|
2015-12-22 00:58:35 +00:00
|
|
|
xo_emit("{P:\n}");
|
2009-06-24 18:18:35 +00:00
|
|
|
for (i = 0; i < nparams; i++)
|
|
|
|
if (params[i].jp_flags & JP_USER)
|
|
|
|
free(param_values[i]);
|
2003-04-09 03:04:12 +00:00
|
|
|
}
|
2015-12-22 00:58:35 +00:00
|
|
|
|
|
|
|
xo_close_instance("jail");
|
2009-05-27 14:30:26 +00:00
|
|
|
return (jid);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-12-22 00:58:35 +00:00
|
|
|
quoted_print(int pflags, char *name, char *value)
|
2009-05-27 14:30:26 +00:00
|
|
|
{
|
2015-12-22 00:58:35 +00:00
|
|
|
int qc;
|
|
|
|
char *p = value;
|
|
|
|
char *param_name_value;
|
MFp4:
Bring in updated jail support from bz_jail branch.
This enhances the current jail implementation to permit multiple
addresses per jail. In addtion to IPv4, IPv6 is supported as well.
Due to updated checks it is even possible to have jails without
an IP address at all, which basically gives one a chroot with
restricted process view, no networking,..
SCTP support was updated and supports IPv6 in jails as well.
Cpuset support permits jails to be bound to specific processor
sets after creation.
Jails can have an unrestricted (no duplicate protection, etc.) name
in addition to the hostname. The jail name cannot be changed from
within a jail and is considered to be used for management purposes
or as audit-token in the future.
DDB 'show jails' command was added to aid debugging.
Proper compat support permits 32bit jail binaries to be used on 64bit
systems to manage jails. Also backward compatibility was preserved where
possible: for jail v1 syscalls, as well as with user space management
utilities.
Both jail as well as prison version were updated for the new features.
A gap was intentionally left as the intermediate versions had been
used by various patches floating around the last years.
Bump __FreeBSD_version for the afore mentioned and in kernel changes.
Special thanks to:
- Pawel Jakub Dawidek (pjd) for his multi-IPv4 patches
and Olivier Houchard (cognet) for initial single-IPv6 patches.
- Jeff Roberson (jeff) and Randall Stewart (rrs) for their
help, ideas and review on cpuset and SCTP support.
- Robert Watson (rwatson) for lots and lots of help, discussions,
suggestions and review of most of the patch at various stages.
- John Baldwin (jhb) for his help.
- Simon L. Nielsen (simon) as early adopter testing changes
on cluster machines as well as all the testers and people
who provided feedback the last months on freebsd-jail and
other channels.
- My employer, CK Software GmbH, for the support so I could work on this.
Reviewed by: (see above)
MFC after: 3 months (this is just so that I get the mail)
X-MFC Before: 7.2-RELEASE if possible
2008-11-29 14:32:14 +00:00
|
|
|
|
2009-05-27 14:30:26 +00:00
|
|
|
/* An empty string needs quoting. */
|
|
|
|
if (!*p) {
|
2015-12-22 00:58:35 +00:00
|
|
|
asprintf(¶m_name_value, "{k:%s}{d:%s/\"\"}", name, name);
|
|
|
|
xo_emit(param_name_value);
|
|
|
|
free(param_name_value);
|
2009-05-27 14:30:26 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-12-22 00:58:35 +00:00
|
|
|
asprintf(¶m_name_value, "{:%s/%%s}", name);
|
2009-05-27 14:30:26 +00:00
|
|
|
/*
|
|
|
|
* The value will be surrounded by quotes if it contains spaces
|
|
|
|
* or quotes.
|
|
|
|
*/
|
|
|
|
qc = strchr(p, '\'') ? '"'
|
2015-12-22 00:58:35 +00:00
|
|
|
: strchr(p, '"') ? '\''
|
|
|
|
: strchr(p, ' ') || strchr(p, '\t') ? '"'
|
|
|
|
: 0;
|
|
|
|
|
|
|
|
if (qc && pflags & PRINT_QUOTED)
|
|
|
|
xo_emit("{P:/%c}", qc);
|
|
|
|
|
|
|
|
xo_emit(param_name_value, value);
|
|
|
|
|
|
|
|
free(param_name_value);
|
|
|
|
|
|
|
|
if (qc && pflags & PRINT_QUOTED)
|
|
|
|
xo_emit("{P:/%c}", qc);
|
2003-04-09 03:04:12 +00:00
|
|
|
}
|
Improve IP address list representation in libxo output.
Extract decision-making about special-case printing of certain
jail parameters into a function.
Refactor emitting of IPv4 and IPv6 address lists into a function.
Resulting user-facing changes:
XO_VERSION is bumped to 2.
In verbose mode (-v), IPv4 and IPv6-Addresses are now properly emitted
as separate lists.
This only affects the output in encoding styles, i.e. xml and json.
{ {
"__version": "1", "__version": "2",
"jail-information": { "jail-information": {
"jail": [ "jail": [
{ {
"jid": 166, "jid": 166,
"hostname": "foo.com", "hostname": "foo.com",
"path": "/var/jail/foo", "path": "/var/jail/foo",
"name": "foo", "name": "foo",
"state": "ACTIVE", "state": "ACTIVE",
"cpusetid": 2, "cpusetid": 2,
"ipv4_addrs": [ "ipv4_addrs": [
"10.1.1.1", "10.1.1.1",
"10.1.1.2", "10.1.1.2",
"10.1.1.3", | "10.1.1.3"
> ],
> "ipv6_addrs": [
"fe80::1000:1", "fe80::1000:1",
"fe80::1000:2" "fe80::1000:2"
] ]
} }
] ]
} }
} }
In -n mode, ip4.addr and ip6.addr are formatted in the encoding styles'
native list types, e.g. instead of comma-separated lists, JSON arrays
are printed.
jls -n all --libxo json
...
"ip4.addr": [
"10.1.1.1",
"10.1.1.2",
"10.1.1.3"
],
"ip4.saddrsel": true,
"ip6.addr": [
"fe80::1000:1",
"fe80::1000:2"
],
...
jls -n all --libxo xml
...
<ip4.addr>10.1.1.1</ip4.addr>
<ip4.addr>10.1.1.2</ip4.addr>
<ip4.addr>10.1.1.3</ip4.addr>
<ip4.saddrsel>true</ip4.saddrsel>
<ip6.addr>fe80::1000:1</ip6.addr>
<ip6.addr>fe80::1000:2</ip6.addr>
...
PR: 215008
Submitted by: Christian Schwarz <me@cschwarz.com>
Differential Revision: https://reviews.freebsd.org/D8766
2016-12-24 23:51:27 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
special_print(int pflags, struct jailparam *param)
|
|
|
|
{
|
|
|
|
int ip_as_list;
|
|
|
|
|
|
|
|
switch (xo_get_style(NULL)) {
|
|
|
|
case XO_STYLE_JSON:
|
|
|
|
case XO_STYLE_XML:
|
|
|
|
ip_as_list = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ip_as_list = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ip_as_list && param->jp_valuelen == 0) {
|
|
|
|
if (pflags & PRINT_QUOTED)
|
|
|
|
xo_emit("{P:\"\"}");
|
|
|
|
else if (!(pflags & PRINT_NAMEVAL))
|
|
|
|
xo_emit("{P:-}");
|
|
|
|
} else if (ip_as_list && !strcmp(param->jp_name, "ip4.addr")) {
|
|
|
|
emit_ip_addr_list(AF_INET, param->jp_name, param);
|
|
|
|
} else if (ip_as_list && !strcmp(param->jp_name, "ip6.addr")) {
|
|
|
|
emit_ip_addr_list(AF_INET6, param->jp_name, param);
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
emit_ip_addr_list(int af_family, const char *list_name, struct jailparam *param)
|
|
|
|
{
|
|
|
|
char ipbuf[INET6_ADDRSTRLEN];
|
|
|
|
size_t addr_len;
|
|
|
|
const char *emit_str;
|
|
|
|
int ai, count;
|
|
|
|
|
|
|
|
switch (af_family) {
|
|
|
|
case AF_INET:
|
|
|
|
addr_len = sizeof(struct in_addr);
|
|
|
|
emit_str = "{P: }{ql:ipv4_addr}{P:\n}";
|
|
|
|
break;
|
|
|
|
case AF_INET6:
|
|
|
|
addr_len = sizeof(struct in6_addr);
|
|
|
|
emit_str = "{P: }{ql:ipv6_addr}{P:\n}";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
xo_err(1, "unsupported af_family");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
count = param->jp_valuelen / addr_len;
|
|
|
|
|
|
|
|
xo_open_list(list_name);
|
|
|
|
for (ai = 0; ai < count; ai++) {
|
|
|
|
if (inet_ntop(af_family,
|
|
|
|
((uint8_t *)param->jp_value) + addr_len * ai,
|
|
|
|
ipbuf, sizeof(ipbuf)) == NULL) {
|
|
|
|
xo_err(1, "inet_ntop");
|
|
|
|
} else {
|
|
|
|
xo_emit(emit_str, ipbuf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
xo_close_list(list_name);
|
|
|
|
}
|