From b7bbdaee15dabc02e4fad1c64bbc3a64aaa3b5d5 Mon Sep 17 00:00:00 2001 From: Enrico Scholz Date: Thu, 22 Apr 2004 20:46:44 +0000 Subject: [PATCH] added network layer functions git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@1501 94cd875c-1c1d-0410-91d2-eb244daf1a30 --- util-vserver/lib/Makefile-files | 32 ++++++++++++++--- util-vserver/lib/ncaps-net.c | 53 +++++++++++++++++++++++++++ util-vserver/lib/ncaps_list-net.c | 38 ++++++++++++++++++++ util-vserver/lib/nflags-net.c | 53 +++++++++++++++++++++++++++ util-vserver/lib/nflags_list-net.c | 38 ++++++++++++++++++++ util-vserver/lib/syscall_getncaps-net.hc | 34 ++++++++++++++++++ util-vserver/lib/syscall_getncaps.c | 42 ++++++++++++++++++++++ util-vserver/lib/syscall_getnflags-net.hc | 34 ++++++++++++++++++ util-vserver/lib/syscall_getnflags.c | 42 ++++++++++++++++++++++ util-vserver/lib/syscall_getnxinfo-net.hc | 34 ++++++++++++++++++ util-vserver/lib/syscall_getnxinfo.c | 42 ++++++++++++++++++++++ util-vserver/lib/syscall_gettasknid-net.hc | 28 +++++++++++++++ util-vserver/lib/syscall_gettasknid.c | 37 +++++++++++++++++++ util-vserver/lib/syscall_netadd-net.hc | 32 +++++++++++++++++ util-vserver/lib/syscall_netadd.c | 42 ++++++++++++++++++++++ util-vserver/lib/syscall_netcreate-net.hc | 29 +++++++++++++++ util-vserver/lib/syscall_netcreate.c | 37 +++++++++++++++++++ util-vserver/lib/syscall_netmigrate-net.hc | 27 ++++++++++++++ util-vserver/lib/syscall_netmigrate.c | 37 +++++++++++++++++++ util-vserver/lib/syscall_netremove-net.hc | 32 +++++++++++++++++ util-vserver/lib/syscall_netremove.c | 42 ++++++++++++++++++++++ util-vserver/lib/syscall_setncaps-net.hc | 32 +++++++++++++++++ util-vserver/lib/syscall_setncaps.c | 42 ++++++++++++++++++++++ util-vserver/lib/syscall_setnflags-net.hc | 37 +++++++++++++++++++ util-vserver/lib/syscall_setnflags.c | 42 ++++++++++++++++++++++ util-vserver/lib/vserver-internal.h | 33 +++++++++++++++++ util-vserver/lib/vserver.h | 57 ++++++++++++++++++++++++++++++ 27 files changed, 1024 insertions(+), 4 deletions(-) create mode 100644 util-vserver/lib/ncaps-net.c create mode 100644 util-vserver/lib/ncaps_list-net.c create mode 100644 util-vserver/lib/nflags-net.c create mode 100644 util-vserver/lib/nflags_list-net.c create mode 100644 util-vserver/lib/syscall_getncaps-net.hc create mode 100644 util-vserver/lib/syscall_getncaps.c create mode 100644 util-vserver/lib/syscall_getnflags-net.hc create mode 100644 util-vserver/lib/syscall_getnflags.c create mode 100644 util-vserver/lib/syscall_getnxinfo-net.hc create mode 100644 util-vserver/lib/syscall_getnxinfo.c create mode 100644 util-vserver/lib/syscall_gettasknid-net.hc create mode 100644 util-vserver/lib/syscall_gettasknid.c create mode 100644 util-vserver/lib/syscall_netadd-net.hc create mode 100644 util-vserver/lib/syscall_netadd.c create mode 100644 util-vserver/lib/syscall_netcreate-net.hc create mode 100644 util-vserver/lib/syscall_netcreate.c create mode 100644 util-vserver/lib/syscall_netmigrate-net.hc create mode 100644 util-vserver/lib/syscall_netmigrate.c create mode 100644 util-vserver/lib/syscall_netremove-net.hc create mode 100644 util-vserver/lib/syscall_netremove.c create mode 100644 util-vserver/lib/syscall_setncaps-net.hc create mode 100644 util-vserver/lib/syscall_setncaps.c create mode 100644 util-vserver/lib/syscall_setnflags-net.hc create mode 100644 util-vserver/lib/syscall_setnflags.c diff --git a/util-vserver/lib/Makefile-files b/util-vserver/lib/Makefile-files index 0f2bfcc..aede7e0 100644 --- a/util-vserver/lib/Makefile-files +++ b/util-vserver/lib/Makefile-files @@ -37,10 +37,10 @@ lib_v11_SRCS = lib/syscall_rlimit.c \ lib/syscall_rlimit-v11.hc \ lib/syscall_kill.c \ lib/syscall_kill-v11.hc -lib_v13_SRCS = lib/syscall_ctxmigrate.c \ - lib/syscall_ctxmigrate-v13.hc \ - lib/syscall_ctxcreate.c \ +lib_v13_SRCS = lib/syscall_ctxcreate.c \ lib/syscall_ctxcreate-v13.hc \ + lib/syscall_ctxmigrate.c \ + lib/syscall_ctxmigrate-v13.hc \ lib/syscall_enternamespace.c \ lib/syscall_enternamespace-v13.hc \ lib/syscall_setnamespace.c \ @@ -53,9 +53,13 @@ lib_v13_SRCS = lib/syscall_ctxmigrate.c \ lib/syscall_setiattr.c \ lib/syscall_setiattr-fscompat.hc \ lib/syscall_setiattr-v13.hc \ + lib/syscall_gettasknid.c \ + lib/syscall_gettasknid-net.hc \ lib/syscall_gettaskxid.c \ lib/syscall_gettaskxid-v13.hc \ lib/syscall_gettaskxid-oldproc.hc \ + lib/syscall_getnxinfo.c \ + lib/syscall_getnxinfo-nid.hc \ lib/syscall_getvxinfo.c \ lib/syscall_getvxinfo-v13.hc \ lib/syscall_getvxinfo-oldproc.hc \ @@ -69,10 +73,26 @@ lib_v13_SRCS = lib/syscall_ctxmigrate.c \ lib/syscall_getccaps-v13.hc \ lib/syscall_getcflags.c \ lib/syscall_getcflags-v13.hc \ + lib/syscall_getncaps.c \ + lib/syscall_getncaps-net.hc \ + lib/syscall_getnflags.c \ + lib/syscall_getnflags-net.hc \ + lib/syscall_netadd-net.hc \ + lib/syscall_netadd.c \ + lib/syscall_netremove-net.hc \ + lib/syscall_netremove.c \ + lib/syscall_netcreate.c \ + lib/syscall_netcreate-net.hc \ + lib/syscall_netmigrate.c \ + lib/syscall_netmigrate-net.hc \ lib/syscall_setccaps.c \ lib/syscall_setccaps-v13.hc \ lib/syscall_setcflags.c \ lib/syscall_setcflags-v13.hc \ + lib/syscall_setncaps.c \ + lib/syscall_setncaps-net.hc \ + lib/syscall_setnflags.c \ + lib/syscall_setnflags-net.hc \ lib/syscall_setsched.c \ lib/syscall_setsched-v13.hc \ lib/bcaps-v13.c \ @@ -80,7 +100,11 @@ lib_v13_SRCS = lib/syscall_ctxmigrate.c \ lib/ccaps-v13.c \ lib/ccaps_list-v13.c \ lib/cflags-v13.c \ - lib/cflags_list-v13.c + lib/cflags_list-v13.c \ + lib/ncaps-net.c \ + lib/ncaps_list-net.c \ + lib/nflags-net.c \ + lib/nflags_list-net.c PKGCONFIG_FILES = lib/util-vserver diff --git a/util-vserver/lib/ncaps-net.c b/util-vserver/lib/ncaps-net.c new file mode 100644 index 0000000..36d6f44 --- /dev/null +++ b/util-vserver/lib/ncaps-net.c @@ -0,0 +1,53 @@ +// $Id$ --*- c -*-- + +// Copyright (C) 2004 Enrico Scholz +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "vserver.h" +#include "internal.h" +#include + +#include +#include + +#define DECL(STR, VAL) { STR, sizeof(STR)-1, VAL } + +static struct Mapping_uint64 const VALUES[] = { +#warning Add the 'ncap' values here +}; + +uint_least64_t +vc_text2ncap(char const *str, size_t len) +{ + ssize_t idx = utilvserver_value2text_uint64(str, len, + VALUES, DIM_OF(VALUES)); + if (idx==-1) return 0; + else return VALUES[idx].val; +} + +char const * +vc_loncap2text(uint_least64_t *val) +{ + ssize_t idx = utilvserver_text2value_uint64(val, + VALUES, DIM_OF(VALUES)); + + if (idx==-1) return 0; + else return VALUES[idx].id; +} diff --git a/util-vserver/lib/ncaps_list-net.c b/util-vserver/lib/ncaps_list-net.c new file mode 100644 index 0000000..dbc3c01 --- /dev/null +++ b/util-vserver/lib/ncaps_list-net.c @@ -0,0 +1,38 @@ +// $Id$ --*- c -*-- + +// Copyright (C) 2004 Enrico Scholz <> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "vserver.h" +#include "internal.h" + +#include + +int +vc_list2ncap(char const *str, size_t len, + struct vc_err_listparser *err, + struct vc_net_caps *caps) +{ + return utilvserver_listparser_uint64(str, len, + err ? &err->ptr : 0, + err ? &err->len : 0, + &caps->ncaps, &caps->cmask, + vc_text2ncap); +} diff --git a/util-vserver/lib/nflags-net.c b/util-vserver/lib/nflags-net.c new file mode 100644 index 0000000..f72a984 --- /dev/null +++ b/util-vserver/lib/nflags-net.c @@ -0,0 +1,53 @@ +// $Id$ --*- c -*-- + +// Copyright (C) 2004 Enrico Scholz +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "vserver.h" +#include "internal.h" +#include + +#include +#include + +#define DECL(STR, VAL) { STR, sizeof(STR)-1, VAL } + +static struct Mapping_uint64 const VALUES[] = { +#warning Add the 'nflags' values here +}; + +uint_least64_t +vc_text2nflag(char const *str, size_t len) +{ + ssize_t idx = utilvserver_value2text_uint64(str, len, + VALUES, DIM_OF(VALUES)); + if (idx==-1) return 0; + else return VALUES[idx].val; +} + +char const * +vc_lonflag2text(uint_least64_t *val) +{ + ssize_t idx = utilvserver_text2value_uint64(val, + VALUES, DIM_OF(VALUES)); + + if (idx==-1) return 0; + else return VALUES[idx].id; +} diff --git a/util-vserver/lib/nflags_list-net.c b/util-vserver/lib/nflags_list-net.c new file mode 100644 index 0000000..c95dd36 --- /dev/null +++ b/util-vserver/lib/nflags_list-net.c @@ -0,0 +1,38 @@ +// $Id$ --*- c -*-- + +// Copyright (C) 2004 Enrico Scholz <> +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "vserver.h" +#include "internal.h" + +#include + +int +vc_list2nflag(char const *str, size_t len, + struct vc_err_listparser *err, + struct vc_net_flags *flags) +{ + return utilvserver_listparser_uint64(str, len, + err ? &err->ptr : 0, + err ? &err->len : 0, + &flags->flagword, &flags->mask, + vc_text2nflag); +} diff --git a/util-vserver/lib/syscall_getncaps-net.hc b/util-vserver/lib/syscall_getncaps-net.hc new file mode 100644 index 0000000..b3f8f81 --- /dev/null +++ b/util-vserver/lib/syscall_getncaps-net.hc @@ -0,0 +1,34 @@ +// $Id$ --*- c -*-- + +// Copyright (C) 2004 Enrico Scholz +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + +#ifdef HAVE_CONFIG_H +# include +#endif + +static inline ALWAYSINLINE int +vc_get_ncaps_net(nid_t nid, struct vc_net_caps *caps) +{ + struct vcmd_net_caps_v0 k_caps; + int res; + + res = vserver(VCMD_get_ncaps, NID_USER2KERNEL(nid), &k_caps); + caps->ncaps = k_caps.ncaps; + caps->cmask = k_caps.cmask; + + return res; +} diff --git a/util-vserver/lib/syscall_getncaps.c b/util-vserver/lib/syscall_getncaps.c new file mode 100644 index 0000000..4c10553 --- /dev/null +++ b/util-vserver/lib/syscall_getncaps.c @@ -0,0 +1,42 @@ +// $Id$ --*- c -*-- + +// Copyright (C) 2004 Enrico Scholz +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "vserver.h" +#include "vserver-internal.h" +#include "linuxvirtual.h" + +#if defined(VC_ENABLE_API_NET) +# include "syscall_getncaps-net.hc" +#endif + +#if defined(VC_ENABLE_API_NET) +int +vc_get_ncaps(nid_t nid, struct vc_net_caps *caps) +{ + if (caps==0) { + errno = EFAULT; + return -1; + } + + CALL_VC(CALL_VC_NET(vc_get_ncaps, nid, caps)); +} +#endif diff --git a/util-vserver/lib/syscall_getnflags-net.hc b/util-vserver/lib/syscall_getnflags-net.hc new file mode 100644 index 0000000..c8fb940 --- /dev/null +++ b/util-vserver/lib/syscall_getnflags-net.hc @@ -0,0 +1,34 @@ +// $Id$ --*- c -*-- + +// Copyright (C) 2004 Enrico Scholz +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + +#ifdef HAVE_CONFIG_H +# include +#endif + +static inline ALWAYSINLINE int +vc_get_nflags_net(nid_t nid, struct vc_net_flags *flags) +{ + struct vcmd_net_flags_v0 k_flags; + int res; + + res = vserver(VCMD_get_nflags, NID_USER2KERNEL(nid), &k_flags); + flags->flagword = k_flags.flagword; + flags->mask = k_flags.mask; + + return res; +} diff --git a/util-vserver/lib/syscall_getnflags.c b/util-vserver/lib/syscall_getnflags.c new file mode 100644 index 0000000..1deca24 --- /dev/null +++ b/util-vserver/lib/syscall_getnflags.c @@ -0,0 +1,42 @@ +// $Id$ --*- c -*-- + +// Copyright (C) 2004 Enrico Scholz +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "vserver.h" +#include "vserver-internal.h" +#include "linuxvirtual.h" + +#if defined(VC_ENABLE_API_NET) +# include "syscall_getnflags-net.hc" +#endif + +#if defined(VC_ENABLE_API_NET) +int +vc_get_nflags(nid_t nid, struct vc_net_flags *flags) +{ + if (flags==0) { + errno = EFAULT; + return -1; + } + + CALL_VC(CALL_VC_NET(vc_get_nflags, nid, flags)); +} +#endif diff --git a/util-vserver/lib/syscall_getnxinfo-net.hc b/util-vserver/lib/syscall_getnxinfo-net.hc new file mode 100644 index 0000000..a8c0918 --- /dev/null +++ b/util-vserver/lib/syscall_getnxinfo-net.hc @@ -0,0 +1,34 @@ +// $Id$ --*- c -*-- + +// Copyright (C) 2004 Enrico Scholz +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + +#ifdef HAVE_CONFIG_H +# include +#endif + +static inline ALWAYSINLINE int +vc_get_nx_info_net(nid_t nid, struct vc_nx_info *info) +{ + struct vcmd_nx_info_v0 res; + int rc; + + rc = vserver(VCMD_nx_info, NID_USER2KERNEL(nid), &res); + if (rc==-1) return -1; + + info->nid = NID_KERNEL2USER(res.nid); + return rc; +} diff --git a/util-vserver/lib/syscall_getnxinfo.c b/util-vserver/lib/syscall_getnxinfo.c new file mode 100644 index 0000000..27d6de1 --- /dev/null +++ b/util-vserver/lib/syscall_getnxinfo.c @@ -0,0 +1,42 @@ +// $Id$ --*- c -*-- + +// Copyright (C) 2004 Enrico Scholz +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "vserver.h" +#include "linuxvirtual.h" +#include "vserver-internal.h" + +#ifdef VC_ENABLE_API_NET +# include "syscall_getnxinfo-net.hc" +#endif + +#ifdef VC_ENABLE_API_NET +int +vc_get_nx_info(nid_t nid, struct vc_nx_info *info) +{ + if (info==0) { + errno = EFAULT; + return -1; + } + + CALL_VC(CALL_VC_NET(vc_get_nx_info, nid, info)); +} +#endif diff --git a/util-vserver/lib/syscall_gettasknid-net.hc b/util-vserver/lib/syscall_gettasknid-net.hc new file mode 100644 index 0000000..67bac49 --- /dev/null +++ b/util-vserver/lib/syscall_gettasknid-net.hc @@ -0,0 +1,28 @@ +// $Id$ --*- c -*-- + +// Copyright (C) 2004 Enrico Scholz +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + +#ifdef HAVE_CONFIG_H +# include +#endif + +static inline ALWAYSINLINE nid_t +vc_get_task_nid_net(pid_t pid) +{ + nid_t res=vserver(VCMD_task_nid, pid, 0); + return NID_KERNEL2USER(res); +} diff --git a/util-vserver/lib/syscall_gettasknid.c b/util-vserver/lib/syscall_gettasknid.c new file mode 100644 index 0000000..3ee0666 --- /dev/null +++ b/util-vserver/lib/syscall_gettasknid.c @@ -0,0 +1,37 @@ +// $Id$ --*- c -*-- + +// Copyright (C) 2004 Enrico Scholz +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "vserver.h" +#include "linuxvirtual.h" +#include "vserver-internal.h" + +#ifdef VC_ENABLE_API_NET +# include "syscall_gettasknid-net.hc" +#endif + +#ifdef VC_ENABLE_API_NET +nid_t +vc_get_task_nid(pid_t pid) +{ + CALL_VC(CALL_VC_NET(vc_get_task_nid, pid)); +} +#endif diff --git a/util-vserver/lib/syscall_netadd-net.hc b/util-vserver/lib/syscall_netadd-net.hc new file mode 100644 index 0000000..2204953 --- /dev/null +++ b/util-vserver/lib/syscall_netadd-net.hc @@ -0,0 +1,32 @@ +// $Id$ --*- c -*-- + +// Copyright (C) 2004 Enrico Scholz +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + +#ifdef HAVE_CONFIG_H +# include +#endif + +static inline ALWAYSINLINE int +vc_net_add_net(nid_t nid, struct vc_net_nx const *info) +{ + struct vcmd_net_nx_v0 k_info; + + k_info.type = NETTYPE_USER2KERNEL(info->type); + k_info.count = info->count; + + 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 new file mode 100644 index 0000000..1619e19 --- /dev/null +++ b/util-vserver/lib/syscall_netadd.c @@ -0,0 +1,42 @@ +// $Id$ --*- c -*-- + +// Copyright (C) 2004 Enrico Scholz +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "vserver.h" +#include "vserver-internal.h" +#include "linuxvirtual.h" + +#if defined(VC_ENABLE_API_NET) +# include "syscall_netadd-net.hc" +#endif + +#if defined(VC_ENABLE_API_NET) && 0 +int +vc_net_add(nid_t nid, struct vc_net_nx const *info) +{ + if (info==0) { + errno = EFAULT; + return -1; + } + + CALL_VC(CALL_VC_NET(vc_net_add, nid, info)); +} +#endif diff --git a/util-vserver/lib/syscall_netcreate-net.hc b/util-vserver/lib/syscall_netcreate-net.hc new file mode 100644 index 0000000..1ce4cd0 --- /dev/null +++ b/util-vserver/lib/syscall_netcreate-net.hc @@ -0,0 +1,29 @@ +// $Id$ --*- c -*-- + +// Copyright (C) 2004 Enrico Scholz +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + +#ifdef HAVE_CONFIG_H +# include +#endif + +static inline ALWAYSINLINE nid_t +vc_net_create_net(nid_t nid) +{ + nid_t res = vserver(VCMD_net_create, NID_USER2KERNEL(nid), 0); + + return NID_KERNEL2USER(res); +} diff --git a/util-vserver/lib/syscall_netcreate.c b/util-vserver/lib/syscall_netcreate.c new file mode 100644 index 0000000..c72e1b4 --- /dev/null +++ b/util-vserver/lib/syscall_netcreate.c @@ -0,0 +1,37 @@ +// $Id$ --*- c -*-- + +// Copyright (C) 2004 Enrico Scholz +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "vserver.h" +#include "vserver-internal.h" +#include "linuxvirtual.h" + +#if defined(VC_ENABLE_API_NET) +# include "syscall_netcreate-net.hc" +#endif + +#if defined(VC_ENABLE_API_NET) +nid_t +vc_net_create(nid_t nid) +{ + CALL_VC(CALL_VC_NET(vc_net_create, nid)); +} +#endif diff --git a/util-vserver/lib/syscall_netmigrate-net.hc b/util-vserver/lib/syscall_netmigrate-net.hc new file mode 100644 index 0000000..833f396 --- /dev/null +++ b/util-vserver/lib/syscall_netmigrate-net.hc @@ -0,0 +1,27 @@ +// $Id$ --*- c -*-- + +// Copyright (C) 2004 Enrico Scholz +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + +#ifdef HAVE_CONFIG_H +# include +#endif + +static inline ALWAYSINLINE int +vc_net_migrate_net(nid_t nid) +{ + return vserver(VCMD_net_migrate, NID_USER2KERNEL(nid), 0); +} diff --git a/util-vserver/lib/syscall_netmigrate.c b/util-vserver/lib/syscall_netmigrate.c new file mode 100644 index 0000000..0649636 --- /dev/null +++ b/util-vserver/lib/syscall_netmigrate.c @@ -0,0 +1,37 @@ +// $Id$ --*- c -*-- + +// Copyright (C) 2004 Enrico Scholz +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "vserver.h" +#include "vserver-internal.h" +#include "linuxvirtual.h" + +#if defined(VC_ENABLE_API_NET) +# include "syscall_netmigrate-net.hc" +#endif + +#if defined(VC_ENABLE_API_NET) +int +vc_net_migrate(nid_t nid) +{ + CALL_VC(CALL_VC_NET(vc_net_migrate, nid)); +} +#endif diff --git a/util-vserver/lib/syscall_netremove-net.hc b/util-vserver/lib/syscall_netremove-net.hc new file mode 100644 index 0000000..5139f0f --- /dev/null +++ b/util-vserver/lib/syscall_netremove-net.hc @@ -0,0 +1,32 @@ +// $Id$ --*- c -*-- + +// Copyright (C) 2004 Enrico Scholz +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + +#ifdef HAVE_CONFIG_H +# include +#endif + +static inline ALWAYSINLINE int +vc_net_remove_net(nid_t nid, struct vc_net_nx const *info) +{ + struct vcmd_net_nx_v0 k_info; + + k_info.type = NETTYPE_USER2KERNEL(info->type); + k_info.count = info->count; + + 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 new file mode 100644 index 0000000..c588432 --- /dev/null +++ b/util-vserver/lib/syscall_netremove.c @@ -0,0 +1,42 @@ +// $Id$ --*- c -*-- + +// Copyright (C) 2004 Enrico Scholz +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "vserver.h" +#include "vserver-internal.h" +#include "linuxvirtual.h" + +#if defined(VC_ENABLE_API_NET) +# include "syscall_netremove-net.hc" +#endif + +#if defined(VC_ENABLE_API_NET) && 0 +int +vc_net_remove(nid_t nid, struct vc_net_nx const *info) +{ + if (info==0) { + errno = EFAULT; + return -1; + } + + CALL_VC(CALL_VC_NET(vc_net_remove, nid, info)); +} +#endif diff --git a/util-vserver/lib/syscall_setncaps-net.hc b/util-vserver/lib/syscall_setncaps-net.hc new file mode 100644 index 0000000..70596dc --- /dev/null +++ b/util-vserver/lib/syscall_setncaps-net.hc @@ -0,0 +1,32 @@ +// $Id$ --*- c -*-- + +// Copyright (C) 2004 Enrico Scholz +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + +#ifdef HAVE_CONFIG_H +# include +#endif + +static inline ALWAYSINLINE int +vc_set_ncaps_net(nid_t nid, struct vc_net_caps const *caps) +{ + struct vcmd_net_caps_v0 k_caps; + + k_caps.ncaps = caps->ncaps; + k_caps.cmask = caps->cmask; + + return vserver(VCMD_set_ncaps, NID_USER2KERNEL(nid), &k_caps); +} diff --git a/util-vserver/lib/syscall_setncaps.c b/util-vserver/lib/syscall_setncaps.c new file mode 100644 index 0000000..3b67004 --- /dev/null +++ b/util-vserver/lib/syscall_setncaps.c @@ -0,0 +1,42 @@ +// $Id$ --*- c -*-- + +// Copyright (C) 2004 Enrico Scholz +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "vserver.h" +#include "vserver-internal.h" +#include "linuxvirtual.h" + +#if defined(VC_ENABLE_API_NET) +# include "syscall_setncaps-net.hc" +#endif + +#if defined(VC_ENABLE_API_NET) +int +vc_set_ncaps(nid_t nid, struct vc_net_caps const *caps) +{ + if (caps==0) { + errno = EFAULT; + return -1; + } + + CALL_VC(CALL_VC_NET(vc_set_ncaps, nid, caps)); +} +#endif diff --git a/util-vserver/lib/syscall_setnflags-net.hc b/util-vserver/lib/syscall_setnflags-net.hc new file mode 100644 index 0000000..69f041d --- /dev/null +++ b/util-vserver/lib/syscall_setnflags-net.hc @@ -0,0 +1,37 @@ +// $Id$ --*- c -*-- + +// Copyright (C) 2004 Enrico Scholz +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + +#ifdef HAVE_CONFIG_H +# include +#endif + +static inline ALWAYSINLINE int +vc_set_nflags_net(nid_t nid, struct vc_net_flags const *flags) +{ + struct vcmd_net_flags_v0 k_flags; + + if (flags==0) { + errno = EFAULT; + return -1; + } + + k_flags.flagword = flags->flagword; + k_flags.mask = flags->mask; + + return vserver(VCMD_set_nflags, NID_USER2KERNEL(nid), &k_flags); +} diff --git a/util-vserver/lib/syscall_setnflags.c b/util-vserver/lib/syscall_setnflags.c new file mode 100644 index 0000000..df40f0c --- /dev/null +++ b/util-vserver/lib/syscall_setnflags.c @@ -0,0 +1,42 @@ +// $Id$ --*- c -*-- + +// Copyright (C) 2004 Enrico Scholz +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "vserver.h" +#include "vserver-internal.h" +#include "linuxvirtual.h" + +#if defined(VC_ENABLE_API_NET) +# include "syscall_setnflags-net.hc" +#endif + +#if defined(VC_ENABLE_API_NET) +int +vc_set_nflags(nid_t nid, struct vc_net_flags const *flags) +{ + if (flags==0) { + errno = EFAULT; + return -1; + } + + CALL_VC(CALL_VC_NET(vc_set_nflags, nid, flags)); +} +#endif diff --git a/util-vserver/lib/vserver-internal.h b/util-vserver/lib/vserver-internal.h index 9e84248..02c5349 100644 --- a/util-vserver/lib/vserver-internal.h +++ b/util-vserver/lib/vserver-internal.h @@ -90,6 +90,12 @@ # define CALL_VC_V13A(F,...) CALL_VC_NOOP #endif +#ifdef VC_ENABLE_API_NET +# define CALL_VC_NET(F,...) CALL_VC_GENERAL(0x00010016, net, F, __VA_ARGS__) +#else +# define CALL_VC_NET(F,...) CALL_VC_NOOP +#endif + #ifdef VC_ENABLE_API_FSCOMPAT # define CALL_VC_FSCOMPAT(F,...) CALL_VC_GENERAL(0x00010000, fscompat, F, __VA_ARGS__) #else @@ -158,6 +164,33 @@ # define VHI_KERNEL2USER(X) (X) #endif +#if 1 +# define NID_KERNEL2USER(X) (((X)==(uint32_t)(-1)) ? VC_NONID : \ + (xid_t)(X)) + +# define NID_USER2KERNEL(X) (((X)==VC_DYNAMIC_NID) ? (uint32_t)(-1) : \ + (uint32_t)(X)) +#else +# define NID_USER2KERNEL(X) (X) +# define NID_KERNEL2USER(X) (X) +#endif + +#if 1 +# define NETTYPE_USER2KERNEL(X) ((X)==vcNET_IPV4 ? 0 : \ + (X)==vcNET_IPV6 ? 1 : \ + (X)==vcNET_IPV4R ? 2 : \ + (X)==vcNET_IPV6R ? 3 : \ + (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) +#endif + #define EXT2_IOC_GETCONTEXT _IOR('x', 1, long) #define EXT2_IOC_SETCONTEXT _IOW('x', 2, long) diff --git a/util-vserver/lib/vserver.h b/util-vserver/lib/vserver.h index eaa2026..0f7f1fa 100644 --- a/util-vserver/lib/vserver.h +++ b/util-vserver/lib/vserver.h @@ -65,6 +65,9 @@ /** the value which means the current ctx */ #define VC_SAMECTX ((xid_t)(-2)) +#define VC_NONID ((nid_t)(-1)) +#define VC_DYNAMIC_NID ((nid_t)(-1)) + #define VC_LIM_INFINITY (~0ULL) #define VC_LIM_KEEP (~1ULL) @@ -192,6 +195,7 @@ #ifdef IS_DOXYGEN typedef an_unsigned_integer_type xid_t; +typedef an_unsigned_integer_type nid_t; #endif #ifdef __cplusplus @@ -344,6 +348,47 @@ extern "C" { int vc_ctx_kill(xid_t ctx, pid_t pid, int sig); + struct vc_nx_info { + nid_t nid; + }; + + nid_t vc_get_task_nid(pid_t pid); + int vc_get_nx_info(nid_t nid, struct vc_nx_info *) VC_ATTR_NONNULL((2)); + + typedef enum { vcNET_IPV4, vcNET_IPV6, vcNET_IPV4R, vcNET_IPV6R } vc_net_nx_type; + + struct vc_net_nx { + vc_net_nx_type type; + size_t count; + uint32_t ip; + uint32_t mask; + }; + + nid_t vc_net_create(nid_t nid); + int vc_net_migrate(nid_t nid); + + int vc_net_add(nid_t nid, struct vc_net_nx const *info); + int vc_net_remove(nid_t nid, struct vc_net_nx const *info); + + struct vc_net_flags { + uint_least64_t flagword; + uint_least64_t mask; + }; + + int vc_get_nflags(nid_t, struct vc_net_flags *); + int vc_set_nflags(nid_t, struct vc_net_flags const *); + + + struct vc_net_caps { + uint_least64_t ncaps; + uint_least64_t cmask; + }; + + int vc_get_ncaps(nid_t, struct vc_net_caps *); + int vc_set_ncaps(nid_t, struct vc_net_caps const *); + + + int vc_set_iattr(char const *filename, xid_t xid, uint_least32_t flags, uint_least32_t mask) VC_ATTR_NONNULL((1)); @@ -427,7 +472,19 @@ extern "C" { int vc_text2cap(char const *); char const * vc_cap2text(unsigned int); + + int vc_list2nflag(char const *, size_t len, + struct vc_err_listparser *err, + struct vc_net_flags *flags); + uint_least64_t vc_text2nflag(char const *, size_t len); + char const * vc_lonflag2text(uint_least64_t *); + uint_least64_t vc_text2ncap(char const *, size_t len); + char const * vc_loncap2text(uint_least64_t *); + int vc_list2ncap(char const *, size_t len, + struct vc_err_listparser *err, + struct vc_net_caps *); + inline static int vc_setfilecontext(char const *filename, xid_t xid) { return vc_set_iattr(filename, xid, 0, VC_IATTR_XID); } -- 1.8.1.5