2 * Copyright (c) 2014 Joyent, Inc. All rights reserved.
3 * Use is subject to license terms.
5 * See the IPFILTER.LICENCE file for details on licensing.
16 #include "netinet/ip_fil.h"
19 static ipfzoneobj_t ipzo
;
20 static boolean_t do_setzone
= 0;
21 static int num_setzones
= 0;
29 * Get the zonename if it's the last argument and set the zonename
30 * in ipfzo to it. This is used by ipf(1m) only - all of the other tools
31 * specify the zone with the -z option, and therefore use getzoneopt() below.
34 getzonearg(int argc
, char *argv
[], const char *optstr
)
39 * Don't warn about unknown options - let subsequent calls to
40 * getopt() handle this.
45 * getopt is also used here to set optind so that we can
46 * determine if the last argument belongs to a flag or is
47 * actually a zonename.
49 while ((c
= getopt(argc
, argv
, optstr
)) != -1) {
55 setzonename(argv
[optind
]);
58 * Reset optind and opterr so the next getopt call will go through all
59 * of argv again and warn about unknown options.
66 * Get a -z option from argv and set the zonename in ipfzo accordingly
69 getzoneopt(int argc
, char *argv
[], const char *optstr
)
74 * Don't warn about unknown options - let subsequent calls to
75 * getopt() handle this.
79 while ((c
= getopt(argc
, argv
, optstr
)) != -1) {
81 setzonename_global(optarg
);
88 * Reset optind and opterr so the next getopt call will go through all
89 * of argv again and warn about unknown options.
96 * Set the zonename in ipfzo to the given string: this is the zone all further
100 setzonename(const char *zonename
)
102 memcpy(ipzo
.ipfz_zonename
, zonename
, sizeof (ipzo
.ipfz_zonename
));
108 * Set the zonename in ipfo, and the gz flag. This indicates that we want all
109 * further ioctls to act on the GZ-controlled stack for that zone.
112 setzonename_global(const char *zonename
)
114 setzonename(zonename
);
119 * Set the zone that all further ioctls will operate on. See the "GZ-controlled
120 * and per-zone stacks" note at the top of ip_fil_solaris.c for further
129 if (num_setzones
> 1) {
130 (void) fprintf(stderr
,
131 "Only one of -G and -z may be set\n");
135 if (ipzo
.ipfz_gz
== 1 &&
136 getzoneidbyname(ipzo
.ipfz_zonename
) == GLOBAL_ZONEID
) {
137 (void) fprintf(stderr
,
138 "-G cannot be used with the global zone\n");
142 if (ioctl(fd
, SIOCIPFZONESET
, &ipzo
) == -1) {
145 (void) fprintf(stderr
,
146 "Could not find running zone: %s\n",
150 (void) fprintf(stderr
,
151 "Permission denied setting zone: %s\n",
155 perror("Error setting zone");