From dde1bcab63ba56a0202fee0b2dc4bd115aa192a3 Mon Sep 17 00:00:00 2001 From: Arnaud Lacombe Date: Fri, 18 Mar 2011 17:34:23 -0400 Subject: [PATCH] Honors WITHOUT_JAIL This patch fixes buildworld when libjail is not included in the build, as it should be if WITHOUT_JAIL defined. Compile-tested, not runtime check done. Signed-off-by: Arnaud Lacombe --- lib/Makefile | 6 +++- sbin/ifconfig/Makefile | 10 ++++- sbin/ifconfig/ifconfig.c | 31 ---------------- sbin/ifconfig/vnet.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 104 insertions(+), 34 deletions(-) create mode 100644 sbin/ifconfig/vnet.c diff --git a/lib/Makefile b/lib/Makefile index 4fef1bb..9d88880 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -77,7 +77,7 @@ SUBDIR= ${SUBDIR_ORDERED} \ ${_librpcsec_gss} \ libipsec \ ${_libipx} \ - libjail \ + ${_libjail} \ libkiconv \ liblzma \ libmagic \ @@ -165,6 +165,10 @@ _libiconv_modules= libiconv_modules _libipx= libipx .endif +.if ${MK_JAIL} != "no" +_libjail= libjail +.endif + .if ${MK_LIBTHR} != "no" _libthr= libthr .endif diff --git a/sbin/ifconfig/Makefile b/sbin/ifconfig/Makefile index 77491f2..5ff9208 100644 --- a/sbin/ifconfig/Makefile +++ b/sbin/ifconfig/Makefile @@ -28,8 +28,14 @@ SRCS+= ifgre.c # GRE keys etc SRCS+= ifgif.c # GIF reversed header workaround SRCS+= ifieee80211.c regdomain.c # SIOC[GS]IEEE80211 support -DPADD+= ${LIBBSDXML} ${LIBJAIL} ${LIBSBUF} -LDADD+= -lbsdxml -ljail -lsbuf +DPADD+= ${LIBBSDXML} ${LIBSBUF} +LDADD+= -lbsdxml -lsbuf + +.if ${MK_JAIL} != "no" +SRCS+= vnet.c +DPADD+= ${LIBJAIL} +LDADD+= -ljail +.endif SRCS+= ifcarp.c # SIOC[GS]VH support SRCS+= ifgroup.c # ... diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c index 7c5d351..00c8d9f 100644 --- a/sbin/ifconfig/ifconfig.c +++ b/sbin/ifconfig/ifconfig.c @@ -66,7 +66,6 @@ static const char rcsid[] = #include #include #include -#include #include #include #include @@ -664,34 +663,6 @@ deletetunnel(const char *vname, int param, int s, const struct afswtch *afp) } static void -setifvnet(const char *jname, int dummy __unused, int s, - const struct afswtch *afp) -{ - struct ifreq my_ifr; - - memcpy(&my_ifr, &ifr, sizeof(my_ifr)); - my_ifr.ifr_jid = jail_getid(jname); - if (my_ifr.ifr_jid < 0) - errx(1, "%s", jail_errmsg); - if (ioctl(s, SIOCSIFVNET, &my_ifr) < 0) - err(1, "SIOCSIFVNET"); -} - -static void -setifrvnet(const char *jname, int dummy __unused, int s, - const struct afswtch *afp) -{ - struct ifreq my_ifr; - - memcpy(&my_ifr, &ifr, sizeof(my_ifr)); - my_ifr.ifr_jid = jail_getid(jname); - if (my_ifr.ifr_jid < 0) - errx(1, "%s", jail_errmsg); - if (ioctl(s, SIOCSIFRVNET, &my_ifr) < 0) - err(1, "SIOCSIFRVNET(%d, %s)", my_ifr.ifr_jid, my_ifr.ifr_name); -} - -static void setifnetmask(const char *addr, int dummy __unused, int s, const struct afswtch *afp) { @@ -1133,8 +1104,6 @@ static struct cmd basic_cmds[] = { DEF_CMD_ARG2("tunnel", settunnel), DEF_CMD("-tunnel", 0, deletetunnel), DEF_CMD("deletetunnel", 0, deletetunnel), - DEF_CMD_ARG("vnet", setifvnet), - DEF_CMD_ARG("-vnet", setifrvnet), DEF_CMD("link0", IFF_LINK0, setifflags), DEF_CMD("-link0", -IFF_LINK0, setifflags), DEF_CMD("link1", IFF_LINK1, setifflags), diff --git a/sbin/ifconfig/vnet.c b/sbin/ifconfig/vnet.c new file mode 100644 index 0000000..d386d14 --- /dev/null +++ b/sbin/ifconfig/vnet.c @@ -0,0 +1,91 @@ +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. 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. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. + */ + +#ifndef lint +static const char rcsid[] = + "$FreeBSD$"; +#endif /* not lint */ + +#include +#include +#include + +#include +#include + +#include +#include +#include + +#include "ifconfig.h" + +static void +setifvnet(const char *jname, int dummy __unused, int s, + const struct afswtch *afp) +{ + struct ifreq my_ifr; + + memcpy(&my_ifr, &ifr, sizeof(my_ifr)); + my_ifr.ifr_jid = jail_getid(jname); + if (my_ifr.ifr_jid < 0) + errx(1, "%s", jail_errmsg); + if (ioctl(s, SIOCSIFVNET, &my_ifr) < 0) + err(1, "SIOCSIFVNET"); +} + +static void +setifrvnet(const char *jname, int dummy __unused, int s, + const struct afswtch *afp) +{ + struct ifreq my_ifr; + + memcpy(&my_ifr, &ifr, sizeof(my_ifr)); + my_ifr.ifr_jid = jail_getid(jname); + if (my_ifr.ifr_jid < 0) + errx(1, "%s", jail_errmsg); + if (ioctl(s, SIOCSIFRVNET, &my_ifr) < 0) + err(1, "SIOCSIFRVNET(%d, %s)", my_ifr.ifr_jid, my_ifr.ifr_name); +} + +static struct cmd vnet_cmds[] = +{ + DEF_CMD_ARG("vnet", setifvnet), + DEF_CMD_ARG("-vnet", setifrvnet), +}; + +static __constructor void +vnet_ctor(void) +{ +#define N(a) (sizeof(a) / sizeof(a[0])) + size_t i; + + for (i = 0; i < N(vnet_cmds); i++) + cmd_register(&vnet_cmds[i]); +#undef N +} -- 1.7.4.1.313.gd7c59.dirty