From: Enrico Scholz Date: Wed, 18 Jan 2006 23:40:15 +0000 (+0000) Subject: applied vnet patch from Daniel Hokka Zakrisson X-Git-Tag: version_0_30_210~32 X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b54bdaad6d45775bc5484069234723f5371d3c56;p=util-vserver.git applied vnet patch from Daniel Hokka Zakrisson (http://savannah.nongnu.org/patch/?func=detailitem&item_id=4799) git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@2249 94cd875c-1c1d-0410-91d2-eb244daf1a30 --- diff --git a/util-vserver/THANKS b/util-vserver/THANKS index 38f5817..9b71130 100644 --- a/util-vserver/THANKS +++ b/util-vserver/THANKS @@ -13,5 +13,8 @@ Olivier Poitrey Herbert Poetzl, for providing the alternative syscall.h implementation +Daniel Hokka Zakrisson + for his patch which adds support for ngnet functionality + all the other people, who contributed to the original 'vserver' package diff --git a/util-vserver/lib/syscall_netadd-net.hc b/util-vserver/lib/syscall_netadd-net.hc index 781d83e..f408d90 100644 --- a/util-vserver/lib/syscall_netadd-net.hc +++ b/util-vserver/lib/syscall_netadd-net.hc @@ -24,9 +24,14 @@ static inline ALWAYSINLINE int vc_net_add_net(nid_t nid, struct vc_net_nx const *info) { struct vcmd_net_addr_v0 k_info; + size_t i; - k_info.type = NETTYPE_USER2KERNEL(info->type); - k_info.count = info->count; + k_info.type = NETTYPE_USER2KERNEL(info->type); + k_info.count = info->count; + for (i = 0; i < sizeof(k_info.ip) / sizeof(*k_info.ip); i++) + k_info.ip[i] = info->ip[i]; + for (i = 0; i < sizeof(k_info.mask) / sizeof(*k_info.mask); i++) + k_info.mask[i] = info->mask[i]; return vserver(VCMD_net_add, NID_USER2KERNEL(nid), &k_info); } diff --git a/util-vserver/lib/syscall_netadd.c b/util-vserver/lib/syscall_netadd.c index 214c8e9..176c93c 100644 --- a/util-vserver/lib/syscall_netadd.c +++ b/util-vserver/lib/syscall_netadd.c @@ -28,7 +28,7 @@ # include "syscall_netadd-net.hc" #endif -#if defined(VC_ENABLE_API_NET) && 0 +#if defined(VC_ENABLE_API_NET) int vc_net_add(nid_t nid, struct vc_net_nx const *info) { diff --git a/util-vserver/lib/syscall_netremove-net.hc b/util-vserver/lib/syscall_netremove-net.hc index 913302a..0ec02e9 100644 --- a/util-vserver/lib/syscall_netremove-net.hc +++ b/util-vserver/lib/syscall_netremove-net.hc @@ -24,9 +24,14 @@ static inline ALWAYSINLINE int vc_net_remove_net(nid_t nid, struct vc_net_nx const *info) { struct vcmd_net_addr_v0 k_info; + size_t i; - k_info.type = NETTYPE_USER2KERNEL(info->type); - k_info.count = info->count; + k_info.type = NETTYPE_USER2KERNEL(info->type); + k_info.count = info->count; + for (i = 0; i < sizeof(k_info.ip) / sizeof(*k_info.ip); i++) + k_info.ip[i] = info->ip[i]; + for (i = 0; i < sizeof(k_info.mask) / sizeof(*k_info.mask); i++) + k_info.mask[i] = info->mask[i]; return vserver(VCMD_net_remove, NID_USER2KERNEL(nid), &k_info); } diff --git a/util-vserver/lib/syscall_netremove.c b/util-vserver/lib/syscall_netremove.c index 36840cb..ef59982 100644 --- a/util-vserver/lib/syscall_netremove.c +++ b/util-vserver/lib/syscall_netremove.c @@ -28,7 +28,7 @@ # include "syscall_netremove-net.hc" #endif -#if defined(VC_ENABLE_API_NET) && 0 +#if defined(VC_ENABLE_API_NET) int vc_net_remove(nid_t nid, struct vc_net_nx const *info) { diff --git a/util-vserver/lib/vserver-internal.h b/util-vserver/lib/vserver-internal.h index 5ab015e..8fb0f13 100644 --- a/util-vserver/lib/vserver-internal.h +++ b/util-vserver/lib/vserver-internal.h @@ -190,16 +190,16 @@ inline static ALWAYSINLINE void vc_noop0() {} #endif #if 1 -# define NETTYPE_USER2KERNEL(X) ((X)==vcNET_IPV4 ? 0 : \ - (X)==vcNET_IPV6 ? 1 : \ - (X)==vcNET_IPV4R ? 2 : \ - (X)==vcNET_IPV6R ? 3 : \ +# define NETTYPE_USER2KERNEL(X) ((X)==vcNET_IPV4 ? NXA_TYPE_IPV4 : \ + (X)==vcNET_IPV6 ? NXA_TYPE_IPV6 : \ + (X)==vcNET_IPV4B ? (NXA_TYPE_IPV4 | NXA_MOD_BCAST) : \ + (X)==vcNET_ANY ? NXA_TYPE_ANY : \ + (X)) +# define NETTYPE_KERNEL2USER(X) ((X)==NXA_TYPE_IPV4 ? vcNET_IPV4 : \ + (X)==NXA_TYPE_IPV6 ? vcNET_IPV6 : \ + (X)==(NXA_TYPE_IPV4|NXA_MOD_BCAST) ? vcNET_IPV4B : \ + (X)==NXA_TYPE_ANY ? vcNET_ANY : \ (X)) -# define NETTYPE_KERNEL2USER(X) ((X)==0 ? vcNET_IPV4 ? : \ - (X)==1 ? vcNET_IPV6 ? : \ - (X)==2 ? vcNET_IPV4R ? : \ - (X)==3 ? vcNET_IPV6R ? : \ - (vc_net_nx_type)(X)) #else # define NETTYPE_USER2KERNEL(X) (X) # define NETTYPE_KERNEL2USER(X) (X) diff --git a/util-vserver/scripts/vserver.functions b/util-vserver/scripts/vserver.functions index 77e15ba..d5e0514 100644 --- a/util-vserver/scripts/vserver.functions +++ b/util-vserver/scripts/vserver.functions @@ -77,13 +77,16 @@ function _generateChbindOptions local vdir="$1" local i local bcast= + local nid= test -n "$_HAVE_INTERFACE_OPTIONS" || _generateInterfaceOptions "$vdir" local f=$vdir/interfaces/bcast getFileValue bcast "$f" + + getFileValue nid "$vdir/ncontext" "$vdir/context" - CHBIND_OPTS=( $SILENT_OPT ${bcast:+--bcast "$bcast"} ) + CHBIND_OPTS=( $SILENT_OPT ${nid:+--nid "$nid"} ${bcast:+--bcast "$bcast"} ) for i in "${INTERFACES[@]}"; do CHBIND_OPTS=( "${CHBIND_OPTS[@]}" --ip "$i" ) diff --git a/util-vserver/src/chbind.c b/util-vserver/src/chbind.c index 285fe1c..497e482 100644 --- a/util-vserver/src/chbind.c +++ b/util-vserver/src/chbind.c @@ -24,6 +24,8 @@ #include "vserver.h" #include "util.h" +#include + #include #include #include @@ -41,6 +43,7 @@ #define ENSC_WRAPPERS_PREFIX "chbind: " #define ENSC_WRAPPERS_IO 1 #define ENSC_WRAPPERS_UNISTD 1 +#define ENSC_WRAPPERS_VSERVER 1 #include "wrappers.h" #define CMD_HELP 0x1000 @@ -49,6 +52,7 @@ #define CMD_SILENT 0x2000 #define CMD_IP 0x2001 #define CMD_BCAST 0x2002 +#define CMD_NID 0x2003 int wrapper_exit_code = 255; @@ -60,6 +64,7 @@ CMDLINE_OPTIONS[] = { { "silent", no_argument, 0, CMD_SILENT }, { "ip", required_argument, 0, CMD_IP }, { "bcast", required_argument, 0, CMD_BCAST }, + { "nid", required_argument, 0, CMD_NID }, { 0,0,0,0 } }; @@ -69,7 +74,7 @@ showHelp(int fd, char const *cmd, int res) WRITE_MSG(fd, "Usage:\n "); WRITE_STR(fd, cmd); WRITE_MSG(fd, - " [--silent] [--ip [/]] [--bcast ] [--] *\n\n" + " [--silent] [--nid ] [--ip [/]] [--bcast ] [--] *\n\n" "Please report bugs to " PACKAGE_BUGREPORT "\n"); exit(res); @@ -237,6 +242,61 @@ readBcast(char const *str, uint32_t *bcast) } } +#if defined(VC_ENABLE_API_NET) +static void +make_nx(nid_t nid, uint32_t bcast, size_t nbaddrs, struct vc_ip_mask_pair *ips) +{ + size_t i; + struct vc_net_nx addr; + + if (nid == VC_DYNAMIC_NID) { + nid = vc_net_create(VC_DYNAMIC_NID); + if (nid == (nid_t) -1) { + perror("chbind: vc_net_create()"); + exit(wrapper_exit_code); + } + } + else { + if (vc_net_create(nid) == (nid_t) -1) { + if (errno == EEXIST) { + if (vc_net_migrate(nid) != 0) { + perror("chbind: vc_net_migrate()"); + exit(wrapper_exit_code); + } + else + return; + } + else { + perror("chbind: vc_net_create()"); + exit(wrapper_exit_code); + } + } + } + + addr.type = vcNET_IPV4B; + addr.count = 1; + addr.ip[0] = bcast; + addr.mask[0] = 0; + + if (vc_net_add(nid, &addr) != 1) { + perror("chbind: vc_net_add()"); + exit(wrapper_exit_code); + } + + for (i = 0; i < nbaddrs; i++) { + addr.type = vcNET_IPV4; + addr.count = 1; + addr.ip[0] = ips[i].ip; + addr.mask[0] = ips[i].mask; + + if (vc_net_add(nid, &addr) != 1) { + perror("chbind: vc_net_add()"); + exit(wrapper_exit_code); + } + } +} +#endif + int main (int argc, char *argv[]) { size_t const nb_ipv4root = vc_get_nb_ipv4root(); @@ -244,6 +304,7 @@ int main (int argc, char *argv[]) struct vc_ip_mask_pair ips[nb_ipv4root]; size_t nbaddrs = 0; uint32_t bcast = 0xffffffff; + nid_t nid = VC_DYNAMIC_NID; while (1) { int c = getopt_long(argc, argv, "+", CMDLINE_OPTIONS, 0); @@ -254,6 +315,11 @@ int main (int argc, char *argv[]) case CMD_VERSION : showVersion(); case CMD_SILENT : is_silent = true; break; case CMD_BCAST : readBcast(optarg, &bcast); break; +#if defined(VC_ENABLE_API_NET) + case CMD_NID : nid = Evc_xidopt2xid(optarg,true); break; +#else + case CMD_NID : WRITE_MSG(2, "WARNING: --nid is not supported by this version\n"); break; +#endif case CMD_IP : if (nbaddrs>=nb_ipv4root) { WRITE_MSG(2, "Too many IP numbers, max 16\n"); @@ -277,6 +343,12 @@ int main (int argc, char *argv[]) } +#if defined(VC_ENABLE_API_NET) + if (vc_isSupported(vcFEATURE_VNET)) { + make_nx(nid, bcast, nbaddrs, ips); + } + else +#endif if (vc_set_ipv4root(bcast,nbaddrs,ips)!=0) { perror("chbind: vc_set_ipv4root()"); exit(wrapper_exit_code);