Changeset 2578
- Timestamp:
- 08/08/07 22:05:26 (1 year ago)
- Files:
-
- trunk/AUTHORS (modified) (1 diff)
- trunk/configure.ac (modified) (3 diffs)
- trunk/ensc_wrappers/wrappers-vserver.hc (modified) (1 diff)
- trunk/kernel/inode_cmd.h (modified) (2 diffs)
- trunk/kernel/network.h (modified) (3 diffs)
- trunk/kernel/network_cmd.h (modified) (1 diff)
- trunk/lib/Makefile-files (modified) (2 diffs)
- trunk/lib/syscall_ctxcreate-v13.hc (modified) (1 diff)
- trunk/lib/syscall_ctxcreate-v21.hc (added)
- trunk/lib/syscall_ctxcreate.c (modified) (2 diffs)
- trunk/lib/syscall_fgetiattr-v22.hc (added)
- trunk/lib/syscall_fgetiattr.c (added)
- trunk/lib/syscall_fsetiattr-v22.hc (added)
- trunk/lib/syscall_fsetiattr.c (added)
- trunk/lib/syscall_netadd-net.hc (modified) (1 diff)
- trunk/lib/syscall_netadd-netv2.hc (added)
- trunk/lib/syscall_netadd.c (modified) (3 diffs)
- trunk/lib/syscall_netremove-net.hc (modified) (1 diff)
- trunk/lib/syscall_netremove-netv2.hc (added)
- trunk/lib/syscall_netremove.c (modified) (3 diffs)
- trunk/lib/syscall_setsched-v22.hc (added)
- trunk/lib/syscall_setsched.c (modified) (1 diff)
- trunk/lib/vserver-internal.h (modified) (4 diffs)
- trunk/lib/vserver.h (modified) (8 diffs)
- trunk/lib_internal/sys_unshare.h (added)
- trunk/src/chbind.c (modified) (3 diffs)
- trunk/src/naddress.c (modified) (16 diffs)
- trunk/src/rpm-fake.c (modified) (1 diff)
- trunk/src/vcontext.c (modified) (1 diff)
- trunk/vserver-start/main.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/AUTHORS
r2283 r2578 1 1 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de> 2 Daniel Hokka Zakrisson <daniel@hozac.com> trunk/configure.ac
r2567 r2578 227 227 AH_TEMPLATE(VC_ENABLE_API_NET, [Enable support for network context API]) 228 228 AH_TEMPLATE(VC_ENABLE_API_V21, [Enable support for API of vserver 2.1.x]) 229 AH_TEMPLATE(VC_ENABLE_API_V22, [Enable support for API of vserver 2.2.x]) 230 AH_TEMPLATE(VC_ENABLE_API_V23, [Enable support for API of vserver 2.3.x]) 231 AH_TEMPLATE(VC_ENABLE_API_NETV2, [Enable support for new networking API]) 229 232 AH_TEMPLATE(VC_ENABLE_API_OLDPROC, [Enable API for a backward compatible /proc parsing]) 230 233 AH_TEMPLATE(VC_ENABLE_API_OLDUTS, [Enable API for a backward compatible uts handling]) … … 233 236 AC_ARG_ENABLE([apis], 234 237 [AC_HELP_STRING([--enable-apis=APIS], 235 [enable support for the given apis; possible values are: legacy,compat,v11,fscompat,v13obs,v13,net, ALL,NOLEGACY (default: v13,net,v21)])],238 [enable support for the given apis; possible values are: legacy,compat,v11,fscompat,v13obs,v13,net,v21,v22,v23,netv2 ALL,NOLEGACY (default: v13,net,v21,v22,v23,netv2)])], 236 239 [], 237 [enable_apis=v13,net,v21 ])238 239 test x"$enable_apis" != xALL || enable_apis='legacy,compat,v11,fscompat,v13obs,v13,net,v21 '240 test x"$enable_apis" != xNOLEGACY || enable_apis='compat,v11,fscompat,v13,net,v21 '240 [enable_apis=v13,net,v21,v22,v23,netv2]) 241 242 test x"$enable_apis" != xALL || enable_apis='legacy,compat,v11,fscompat,v13obs,v13,net,v21,v22,v23,netv2' 243 test x"$enable_apis" != xNOLEGACY || enable_apis='compat,v11,fscompat,v13,net,v21,v22,v23,netv2' 241 244 enable_api_oldproc= 242 245 enable_api_olduts= … … 264 267 (net) AC_DEFINE(VC_ENABLE_API_NET, 1);; 265 268 (v21) AC_DEFINE(VC_ENABLE_API_V21, 1);; 269 (v22) AC_DEFINE(VC_ENABLE_API_V22, 1);; 270 (v23) AC_DEFINE(VC_ENABLE_API_V23, 1);; 271 (netv2) AC_DEFINE(VC_ENABLE_API_NETV2, 1);; 266 272 (oldproc) enable_api_oldproc=2;; 267 273 (olduts) enable_api_olduts=2;; trunk/ensc_wrappers/wrappers-vserver.hc
r2501 r2578 50 50 51 51 inline static WRAPPER_DECL xid_t 52 Evc_ctx_create(xid_t xid )52 Evc_ctx_create(xid_t xid, struct vc_ctx_flags *flags) 53 53 { 54 register xid_t res = vc_ctx_create(xid );54 register xid_t res = vc_ctx_create(xid, flags); 55 55 FatalErrnoError(res==VC_NOCTX, "vc_ctx_create()"); 56 56 return res; trunk/kernel/inode_cmd.h
r2413 r2578 5 5 /* inode vserver commands */ 6 6 7 #define VCMD_get_iattr_v0 VC_CMD(INODE, 1, 0)8 #define VCMD_set_iattr_v0 VC_CMD(INODE, 2, 0)9 10 7 #define VCMD_get_iattr VC_CMD(INODE, 1, 1) 11 8 #define VCMD_set_iattr VC_CMD(INODE, 2, 1) 12 9 13 struct vcmd_ctx_iattr_v0 { 14 /* device handle in id */ 15 uint64_t ino; 16 uint32_t xid; 17 uint32_t flags; 18 uint32_t mask; 19 }; 10 #define VCMD_fget_iattr VC_CMD(INODE, 3, 0) 11 #define VCMD_fset_iattr VC_CMD(INODE, 4, 0) 20 12 21 13 struct vcmd_ctx_iattr_v1 { … … 26 18 }; 27 19 20 struct vcmd_ctx_fiattr_v0 { 21 uint32_t xid; 22 uint32_t flags; 23 uint32_t mask; 24 }; 25 28 26 29 27 #endif /* _VX_INODE_CMD_H */ trunk/kernel/network.h
r2413 r2578 7 7 #define MAX_N_CONTEXT 65535 /* Arbitrary limit */ 8 8 9 #define NX_DYNAMIC_ID ((uint32_t)-1) /* id for dynamic context */10 11 9 #define NB_IPV4ROOT 16 12 10 … … 14 12 /* network flags */ 15 13 16 #define NXF_INFO_ LOCK 0x0000000114 #define NXF_INFO_PRIVATE 0x00000008 17 15 18 #define NXF_STATE_SETUP (1ULL<<32) 19 #define NXF_STATE_ADMIN (1ULL<<34) 16 #define NXF_SINGLE_IP 0x00000100 20 17 21 #define NXF_SC_HELPER (1ULL<<36) 22 #define NXF_PERSISTENT (1ULL<<38) 18 #define NXF_HIDE_NETIF 0x02000000 23 19 24 #define NXF_ONE_TIME (0x0005ULL<<32) 20 #define NXF_STATE_SETUP (1ULL << 32) 21 #define NXF_STATE_ADMIN (1ULL << 34) 22 23 #define NXF_SC_HELPER (1ULL << 36) 24 #define NXF_PERSISTENT (1ULL << 38) 25 26 #define NXF_ONE_TIME (0x0005ULL << 32) 25 27 26 28 #define NXF_INIT_SET (NXF_STATE_ADMIN) … … 29 31 /* address types */ 30 32 31 #define NXA_TYPE_IPV4 132 #define NXA_TYPE_IPV6 233 #define NXA_TYPE_IPV4 0x0001 34 #define NXA_TYPE_IPV6 0x0002 33 35 34 #define NXA_MOD_BCAST (1<<8) 36 #define NXA_TYPE_NONE 0x0000 37 #define NXA_TYPE_ANY 0x00FF 35 38 36 #define NXA_TYPE_ANY ((uint16_t)-1) 39 #define NXA_TYPE_ADDR 0x0003 40 #define NXA_TYPE_MASK 0x0013 41 #define NXA_TYPE_RANGE 0x0023 42 43 #define NXA_MOD_BCAST 0x0100 44 #define NXA_MOD_LBACK 0x0200 37 45 38 46 trunk/kernel/network_cmd.h
r2413 r2578 25 25 #define VCMD_net_migrate VC_CMD(NETMIG, 1, 0) 26 26 27 #define VCMD_net_add VC_CMD(NETALT, 1, 0)28 #define VCMD_net_remove VC_CMD(NETALT, 2, 0)27 #define VCMD_net_add_v0 VC_CMD(NETALT, 1, 0) 28 #define VCMD_net_remove_v0 VC_CMD(NETALT, 2, 0) 29 29 30 30 struct vcmd_net_addr_v0 { 31 31 uint16_t type; 32 32 uint16_t count; 33 uint32_t ip[4]; 34 uint32_t mask[4]; 35 /* more to come */ 33 struct in_addr ip[4]; 34 struct in_addr mask[4]; 35 }; 36 37 #define VCMD_net_add_ipv4 VC_CMD(NETALT, 1, 1) 38 #define VCMD_net_remove_ipv4 VC_CMD(NETALT, 2, 1) 39 40 struct vcmd_net_addr_ipv4_v1 { 41 uint16_t type; 42 uint16_t flags; 43 struct in_addr ip; 44 struct in_addr mask; 45 }; 46 47 #define VCMD_net_add_ipv6 VC_CMD(NETALT, 3, 1) 48 #define VCMD_net_remove_ipv6 VC_CMD(NETALT, 4, 1) 49 50 struct vcmd_net_addr_ipv6_v1 { 51 uint16_t type; 52 uint16_t flags; 53 uint32_t prefix; 54 struct in6_addr ip; 55 struct in6_addr mask; 56 }; 57 58 #define VCMD_add_match_ipv4 VC_CMD(NETALT, 5, 0) 59 #define VCMD_get_match_ipv4 VC_CMD(NETALT, 6, 0) 60 61 struct vcmd_match_ipv4_v0 { 62 uint16_t type; 63 uint16_t flags; 64 uint16_t parent; 65 uint16_t prefix; 66 struct in_addr ip; 67 struct in_addr ip2; 68 struct in_addr mask; 69 }; 70 71 #define VCMD_add_match_ipv6 VC_CMD(NETALT, 7, 0) 72 #define VCMD_get_match_ipv6 VC_CMD(NETALT, 8, 0) 73 74 struct vcmd_match_ipv6_v0 { 75 uint16_t type; 76 uint16_t flags; 77 uint16_t parent; 78 uint16_t prefix; 79 struct in6_addr ip; 80 struct in6_addr ip2; 81 struct in6_addr mask; 36 82 }; 37 83 trunk/lib/Makefile-files
r2568 r2578 134 134 lib/syscall_getccaps-v21.hc \ 135 135 lib/syscall_getsched.c \ 136 lib/syscall_getsched-v21.hc 136 lib/syscall_getsched-v21.hc \ 137 lib/syscall_ctxcreate-v21.hc 138 139 lib_v22_SRCS = lib/syscall_setsched-v22.hc \ 140 lib/syscall_fsetiattr.c \ 141 lib/syscall_fsetiattr-v22.hc \ 142 lib/syscall_fgetiattr.c \ 143 lib/syscall_fgetiattr-v22.hc 144 145 lib_netv2_SRCS = lib/syscall_netadd-netv2.hc \ 146 lib/syscall_netremove-netv2.hc 137 147 138 148 if ENSC_HAVE_C99_COMPILER … … 181 191 $(lib_v13_SRCS) \ 182 192 $(lib_v21_SRCS) \ 193 $(lib_v22_SRCS) \ 194 $(lib_netv2_SRCS) \ 183 195 $(ensc_fmt_SRCS) 184 196 trunk/lib/syscall_ctxcreate-v13.hc
r2193 r2578 22 22 23 23 static inline ALWAYSINLINE xid_t 24 vc_ctx_create_v13(xid_t xid )24 vc_ctx_create_v13(xid_t xid, struct vc_ctx_flags *flags) 25 25 { 26 26 xid_t res = vserver(VCMD_ctx_create_v0, CTX_USER2KERNEL(xid), 0); 27 27 28 if (flags) { 29 /* no sane way to report errors here */ 30 vc_set_cflags(xid, flags); 31 } 32 28 33 return CTX_KERNEL2USER(res); 29 34 } trunk/lib/syscall_ctxcreate.c
r2207 r2578 22 22 23 23 #include "vserver.h" 24 #include "virtual.h" 25 26 #if defined(VC_ENABLE_API_V13) && defined(VC_ENABLE_API_V21) 27 # define VC_MULTIVERSION_SYSCALL 1 28 #endif 24 29 #include "vserver-internal.h" 25 #include "virtual.h"26 30 27 31 #if defined(VC_ENABLE_API_V13) … … 29 33 #endif 30 34 31 #if defined(VC_ENABLE_API_V13) 35 #if defined(VC_ENABLE_API_V21) 36 # include "syscall_ctxcreate-v21.hc" 37 #endif 38 39 #if defined(VC_ENABLE_API_V13) || defined(VC_ENABLE_API_V21) 32 40 xid_t 33 vc_ctx_create(xid_t xid )41 vc_ctx_create(xid_t xid, struct vc_ctx_flags *flags) 34 42 { 35 CALL_VC(CALL_VC_V13A(vc_ctx_create, xid)); 43 CALL_VC(CALL_VC_V21 (vc_ctx_create, xid, flags), 44 CALL_VC_V13A(vc_ctx_create, xid, flags)); 36 45 } 37 46 #endif trunk/lib/syscall_netadd-net.hc
r2249 r2578 22 22 23 23 static inline ALWAYSINLINE int 24 vc_net_add_net(nid_t nid, struct vc_net_ nxconst *info)24 vc_net_add_net(nid_t nid, struct vc_net_addr const *info) 25 25 { 26 26 struct vcmd_net_addr_v0 k_info; 27 27 size_t i; 28 28 29 k_info.type = NETTYPE_USER2KERNEL(info->type); 30 k_info.count = info->count; 31 for (i = 0; i < sizeof(k_info.ip) / sizeof(*k_info.ip); i++) 32 k_info.ip[i] = info->ip[i]; 33 for (i = 0; i < sizeof(k_info.mask) / sizeof(*k_info.mask); i++) 34 k_info.mask[i] = info->mask[i]; 35 36 return vserver(VCMD_net_add, NID_USER2KERNEL(nid), &k_info); 29 k_info.type = info->vna_type & (VC_NXA_TYPE_IPV4|VC_NXA_TYPE_IPV6); 30 k_info.count = 1; 31 switch (info->vna_type & ~VC_NXA_TYPE_ADDR) { 32 case VC_NXA_TYPE_IPV4: 33 k_info.ip[0].s_addr = info->vna_v4_ip.s_addr; 34 k_info.mask[0].s_addr = info->vna_v4_mask.s_addr; 35 break; 36 case VC_NXA_TYPE_IPV6: 37 for (i = 0; i < 4; i++) 38 k_info.ip[i].s_addr = info->vna_v6_ip.s6_addr32[i]; 39 k_info.mask[0].s_addr = info->vna_prefix; 40 break; 41 default: 42 errno = EINVAL; 43 return -1; 44 } 45 46 return vserver(VCMD_net_add_v0, NID_USER2KERNEL(nid), &k_info); 37 47 } trunk/lib/syscall_netadd.c
r2249 r2578 21 21 #endif 22 22 23 #include <string.h> 24 23 25 #include "vserver.h" 26 #include "virtual.h" 27 28 #if defined(VC_ENABLE_API_NET) && defined(VC_ENABLE_API_NETV2) 29 # define VC_MULTIVERSION_SYSCALL 1 30 #endif 24 31 #include "vserver-internal.h" 25 #include "virtual.h"26 32 27 33 #if defined(VC_ENABLE_API_NET) … … 29 35 #endif 30 36 31 #if defined(VC_ENABLE_API_NET) 37 #if defined(VC_ENABLE_API_NETV2) 38 # include "syscall_netadd-netv2.hc" 39 #endif 40 41 #if defined(VC_ENABLE_API_NET) || defined(VC_ENABLE_API_NETV2) 32 42 int 33 vc_net_add(nid_t nid, struct vc_net_ nxconst *info)43 vc_net_add(nid_t nid, struct vc_net_addr const *info) 34 44 { 35 45 if (info==0) { … … 38 48 } 39 49 40 CALL_VC(CALL_VC_NET(vc_net_add, nid, info)); 50 CALL_VC(CALL_VC_NETV2(vc_net_add, nid, info), 51 CALL_VC_NET (vc_net_add, nid, info)); 41 52 } 42 53 #endif trunk/lib/syscall_netremove-net.hc
r2249 r2578 22 22 23 23 static inline ALWAYSINLINE int 24 vc_net_remove_net(nid_t nid, struct vc_net_ nxconst *info)24 vc_net_remove_net(nid_t nid, struct vc_net_addr const *info) 25 25 { 26 26 struct vcmd_net_addr_v0 k_info; 27 27 size_t i; 28 28 29 k_info.type = NETTYPE_USER2KERNEL(info->type); 30 k_info.count = info->count; 31 for (i = 0; i < sizeof(k_info.ip) / sizeof(*k_info.ip); i++) 32 k_info.ip[i] = info->ip[i]; 33 for (i = 0; i < sizeof(k_info.mask) / sizeof(*k_info.mask); i++) 34 k_info.mask[i] = info->mask[i]; 35 36 return vserver(VCMD_net_remove, NID_USER2KERNEL(nid), &k_info); 29 k_info.type = info->vna_type & (VC_NXA_TYPE_IPV4|VC_NXA_TYPE_IPV6); 30 k_info.count = 1; 31 switch (info->vna_type) { 32 case VC_NXA_TYPE_IPV4 | VC_NXA_TYPE_ADDR: 33 k_info.ip[0].s_addr = info->vna_v4_ip.s_addr; 34 k_info.mask[0].s_addr = info->vna_v4_mask.s_addr; 35 break; 36 case VC_NXA_TYPE_IPV6 | VC_NXA_TYPE_ADDR: 37 for (i = 0; i < 4; i++) 38 k_info.ip[i].s_addr = info->vna_v6_ip.s6_addr32[i]; 39 k_info.mask[0].s_addr = info->vna_prefix; 40 break; 41 case VC_NXA_TYPE_ANY: 42 k_info.type = (uint16_t) -1; 43 k_info.count = -1; 44 break; 45 default: 46 errno = EINVAL; 47 return -1; 48 } 49 50 return vserver(VCMD_net_remove_v0, NID_USER2KERNEL(nid), &k_info); 37 51 } trunk/lib/syscall_netremove.c
r2249 r2578 21 21 #endif 22 22 23 #include <string.h> 24 23 25 #include "vserver.h" 26 #include "virtual.h" 27 28 #if defined(VC_ENABLE_API_NET) && defined(VC_ENABLE_API_NETV2) 29 # define VC_MULTIVERSION_SYSCALL 1 30 #endif 24 31 #include "vserver-internal.h" 25 #include "virtual.h"26 32 27 33 #if defined(VC_ENABLE_API_NET) … … 29 35 #endif 30 36 31 #if defined(VC_ENABLE_API_NET) 37 #if defined(VC_ENABLE_API_NETV2) 38 # include "syscall_netremove-netv2.hc" 39 #endif 40 41 #if defined(VC_ENABLE_API_NET) || defined(VC_ENABLE_API_NETV2) 32 42 int 33 vc_net_remove(nid_t nid, struct vc_net_ nxconst *info)43 vc_net_remove(nid_t nid, struct vc_net_addr const *info) 34 44 { 35 45 if (info==0) { … … 38 48 } 39 49 40 CALL_VC(CALL_VC_NET(vc_net_remove, nid, info)); 50 CALL_VC(CALL_VC_NETV2(vc_net_remove, nid, info), 51 CALL_VC_NET (vc_net_remove, nid, info)); 41 52 } 42 53 #endif trunk/lib/syscall_setsched.c
r2367 r2578 39 39 #endif 40 40 41 #ifdef VC_ENABLE_API_V22 42 # include "syscall_setsched-v22.hc" 43 #endif 44 41 45 int 42 46 vc_set_sched(xid_t xid, struct vc_set_sched const *data) 43 47 { 44 CALL_VC(CALL_VC_V21 (vc_set_sched,xid,data), 48 CALL_VC(CALL_VC_V22 (vc_set_sched,xid,data), 49 CALL_VC_V21 (vc_set_sched,xid,data), 45 50 CALL_VC_V13B (vc_set_sched,xid,data), 46 51 CALL_VC_V13OBS(vc_set_sched,xid,data)); trunk/lib/vserver-internal.h
r2446 r2578 51 51 do { \ 52 52 int ver = utilvserver_checkCompatVersion(); \ 53 uint_least32_t conf = utilvserver_checkCompatConfig(); \53 uint_least32_t UNUSED conf = utilvserver_checkCompatConfig(); \ 54 54 if (ver==-1) return -1; \ 55 55 VC_SUFFIX, __VA_ARGS__, VC_PREFIX; \ … … 115 115 #endif 116 116 117 #if def VC_ENABLE_API_V21117 #if defined(VC_ENABLE_API_V21) || defined(VC_ENABLE_API_V22) || defined(VC_ENABLE_API_V23) 118 118 # define CALL_VC_SPACES(F,...) CALL_VC_GENERAL_CONFIG(VC_VCI_SPACES, spaces, F, __VA_ARGS__) 119 119 #else 120 120 # define CALL_VC_SPACES(F,...) CALL_VC_NOOP 121 #endif 122 123 #ifdef VC_ENABLE_API_V22 124 # define CALL_VC_V22(F,...) CALL_VC_GENERAL(0x00020200, v22, F, __VA_ARGS__) 125 #else 126 # define CALL_VC_V22(F,...) CALL_VC_NOOP 127 #endif 128 129 #ifdef VC_ENABLE_API_V23 130 # define CALL_VC_V23(F,...) CALL_VC_GENERAL(0x00020300, v23, F, __VA_ARGS__) 131 #else 132 # define CALL_VC_V23(F,...) CALL_VC_NOOP 121 133 #endif 122 134 … … 125 137 #else 126 138 # define CALL_VC_NET(F,...) CALL_VC_NOOP 139 #endif 140 141 #if defined(VC_ENABLE_API_NETV2) 142 # define CALL_VC_NETV2(F,...) CALL_VC_GENERAL_CONFIG(VC_VCI_NETV2, netv2, F, __VA_ARGS__) 143 #else 144 # define CALL_VC_NETV2(F,...) CALL_VC_NOOP 127 145 #endif 128 146 … … 206 224 #endif 207 225 208 #if 1209 # define NETTYPE_USER2KERNEL(X) ((X)==vcNET_IPV4 ? NXA_TYPE_IPV4 : \210 (X)==vcNET_IPV6 ? NXA_TYPE_IPV6 : \211 (X)==vcNET_IPV4B ? (NXA_TYPE_IPV4 | NXA_MOD_BCAST) : \212 (X)==vcNET_IPV6B ? (NXA_TYPE_IPV6 | NXA_MOD_BCAST) : \213 (X)==vcNET_ANY ? NXA_TYPE_ANY : \214 (X))215 # define NETTYPE_KERNEL2USER(X) ((X)==NXA_TYPE_IPV4 ? vcNET_IPV4 : \216 (X)==NXA_TYPE_IPV6 ? vcNET_IPV6 : \217 (X)==(NXA_TYPE_IPV4|NXA_MOD_BCAST) ? vcNET_IPV4B : \218 (X)==(NXA_TYPE_IPV6|NXA_MOD_BCAST) ? vcNET_IPV6B : \219 (X)==NXA_TYPE_ANY ? vcNET_ANY : \220 (X))221 #else222 # define NETTYPE_USER2KERNEL(X) (X)223 # define NETTYPE_KERNEL2USER(X) (X)224 #endif225 226 226 #define CDLIM_USER2KERNEL(X) ((X)==VC_CDLIM_UNSET ? CDLIM_UNSET : \ 227 227 (X)==VC_CDLIM_INFINITY ? CDLIM_INFINITY : \ trunk/lib/vserver.h
r2568 r2578 30 30 #include <sys/types.h> 31 31 #include <sched.h> 32 #include <netinet/in.h> 32 33 33 34 #ifndef IS_DOXYGEN … … 260 261 #define VC_VCI_NO_DYNAMIC (1 << 0) 261 262 #define VC_VCI_SPACES (1 << 10) 263 #define VC_VCI_NETV2 (1 << 11) 262 264 263 265 … … 272 274 #define VC_VXM_SET_INIT 0x00000001 273 275 #define VC_VXM_SET_REAPER 0x00000002 276 277 278 // the network address flags 279 #define VC_NXA_TYPE_IPV4 0x0001 280 #define VC_NXA_TYPE_IPV6 0x0002 281 282 #define VC_NXA_TYPE_NONE 0x0000 283 #define VC_NXA_TYPE_ANY 0x00FF 284 285 #define VC_NXA_TYPE_ADDR 0x0010 286 #define VC_NXA_TYPE_MASK 0x0020 287 #define VC_NXA_TYPE_RANGE 0x0040 288 289 #define VC_NXA_MOD_BCAST 0x0100 290 #define VC_NXA_MOD_LBACK 0x0200 274 291 275 292 … … 394 411 * \returns the xid of the created context, or VC_NOCTX on errors. \c errno 395 412 * will be set appropriately. */ 396 xid_t vc_ctx_create(xid_t xid );413 xid_t vc_ctx_create(xid_t xid, struct vc_ctx_flags *flags); 397 414 398 415 /** \brief Moves the current process into the specified context. … … 602 619 int vc_get_nx_info(nid_t nid, struct vc_nx_info *) VC_ATTR_NONNULL((2)); 603 620 604 typedef enum { vcNET_IPV4=1, vcNET_IPV6=2, 605 vcNET_IPV4B=0x101, vcNET_IPV6B=0x102, 606 vcNET_ANY=~0 } vc_net_nx_type; 607 608 struct vc_net_nx { 609 vc_net_nx_type type; 610 size_t count; 611 uint32_t ip[4]; 612 uint32_t mask[4]; 621 struct vc_net_addr { 622 uint16_t vna_type; 623 uint16_t vna_flags; 624 uint16_t vna_prefix; 625 uint16_t vna_parent; 626 union { 627 struct { 628 struct in_addr ip; 629 struct in_addr mask; 630 } ipv4; 631 struct { 632 struct in6_addr ip; 633 struct in6_addr mask; 634 } ipv6; 635 } u; 636 #define vna_v4_ip u.ipv4.ip 637 #define vna_v4_mask u.ipv4.mask 638 #define vna_v6_ip u.ipv6.ip 639 #define vna_v6_mask u.ipv6.mask 613 640 }; 614 641 … … 621 648 int vc_net_migrate(nid_t nid); 622 649 623 int vc_net_add(nid_t nid, struct vc_net_ nxconst *info);624 int vc_net_remove(nid_t nid, struct vc_net_ nxconst *info);650 int vc_net_add(nid_t nid, struct vc_net_addr const *info); 651 int vc_net_remove(nid_t nid, struct vc_net_addr const *info); 625 652 626 653 int vc_get_nflags(nid_t, struct vc_net_flags *); … … 640 667 int vc_set_iattr(char const *filename, xid_t xid, 641 668 uint_least32_t flags, uint_least32_t mask) VC_ATTR_NONNULL((1)); 669 670 int vc_fset_iattr(int fd, xid_t xid, 671 uint_least32_t flags, uint_least32_t mask); 642 672 643 673 /** \brief Returns information about attributes and assigned context of a file. … … 670 700 uint_least32_t * /*@null@*/ flags, 671 701 uint_least32_t * /*@null@*/ mask) VC_ATTR_NONNULL((1)); 702 703 int vc_fget_iattr(int fd, xid_t * /*@null@*/ xid, 704 uint_least32_t * /*@null@*/ flags, 705 uint_least32_t * /*@null@*/ mask) VC_ATTR_NONNULL((4)); 672 706 673 707 /** \brief Returns the context of \c filename trunk/src/chbind.c
r2557 r2578 243 243 } 244 244 245 #if defined(VC_ENABLE_API_NET)246 static void247 make_nx(nid_t nid, uint32_t bcast, size_t nbaddrs, struct vc_ip_mask_pair *ips)248 {249 size_t i;250 struct vc_net_nx addr;251 252 if (nid == VC_DYNAMIC_NID) {253 nid = vc_net_create(VC_DYNAMIC_NID);254 if (nid == (nid_t) -1) {255 perror("chbind: vc_net_create()");256 exit(wrapper_exit_code);257 }258 }259 else {260 if (vc_net_create(nid) == (nid_t) -1) {261 if (errno == EEXIST) {262 if (vc_net_migrate(nid) != 0) {263 perror("chbind: vc_net_migrate()");264 exit(wrapper_exit_code);265 }266 else267 return;268 }269 else {270 perror("chbind: vc_net_create()");271 exit(wrapper_exit_code);272 }273 }274 }275 276 addr.type = vcNET_IPV4B;277 addr.count = 1;278 addr.ip[0] = bcast;279 addr.mask[0] = 0;280 281 if (vc_net_add(nid, &addr) != 1) {282 perror("chbind: vc_net_add()");283 exit(wrapper_exit_code);284 }285 286 for (i = 0; i < nbaddrs; i++) {287 addr.type = vcNET_IPV4;288 addr.count = 1;289 addr.ip[0] = ips[i].ip;290 addr.mask[0] = ips[i].mask;291 292 if (vc_net_add(nid, &addr) != 1) {293 perror("chbind: vc_net_add()");294 exit(wrapper_exit_code);295 }296 }297 }298 #endif299 300 245 int main (int argc, char *argv[]) 301 246 { … … 316 261 case CMD_SILENT : is_silent = true; break; 317 262 case CMD_BCAST : readBcast(optarg, &bcast); break; 318 #if defined(VC_ENABLE_API_NET)319 case CMD_NID : nid = Evc_nidopt2nid(optarg,true); break;320 #else321 263 case CMD_NID : WRITE_MSG(2, "WARNING: --nid is not supported by this version\n"); break; 322 #endif323 264 case CMD_IP : 324 265 if (nbaddrs>=nb_ipv4root) { … … 343 284 } 344 285 345 #if !defined(VC_ENABLE_API_ NET) && !defined(VC_ENABLE_API_COMPAT) && !defined(VC_ENABLE_API_LEGACY)346 # error can not build 'chbind' without network virtualization API286 #if !defined(VC_ENABLE_API_COMPAT) && !defined(VC_ENABLE_API_LEGACY) 287 # warning building a dummy chbind-compat with no available APIs 347 288 #endif 348 289 349 #if defined(VC_ENABLE_API_NET)350 if (vc_isSupported(vcFEATURE_VNET)) {351 make_nx(nid, bcast, nbaddrs, ips);352 }353 else354 #endif355 290 #if defined(VC_ENABLE_API_COMPAT) || defined(VC_ENABLE_API_LEGACY) 356 291 if (vc_set_ipv4root(bcast,nbaddrs,ips)!=0) { trunk/src/naddress.c
r2570 r2578 58 58 #define CMD_IP 0x2010 59 59 #define CMD_BCAST 0x2011 60 #define CMD_MASK 0x2012 61 #define CMD_RANGE 0x2013 62 #define CMD_LBACK 0x2014 60 63 61 64 int wrapper_exit_code = 255; … … 72 75 { "nid", required_argument, 0, CMD_NID }, 73 76 { "ip", required_argument, 0, CMD_IP }, 77 { "mask", required_argument, 0, CMD_MASK }, 78 { "range", required_argument, 0, CMD_RANGE }, 74 79 { "bcast", required_argument, 0, CMD_BCAST }, 80 { "lback", required_argument, 0, CMD_LBACK }, 75 81 { 0,0,0,0 } 76 82 }; 77 83 78 84 struct vc_ips { 79 struct vc_net_ nxa;85 struct vc_net_addr a; 80 86 struct vc_ips *next; 81 87 }; … … 198 204 199 205 static int 200 convertAddress(const char *str, vc_net_nx_type*type, void *dst)206 convertAddress(const char *str, uint16_t *type, void *dst) 201 207 { 202 208 int ret; 203 if (type) *type = vcNET_IPV4;209 if (type) *type = VC_NXA_TYPE_IPV4; 204 210 ret = inet_pton(AF_INET, str, dst); 205 211 if (ret==0) { 206 if (type) *type = vcNET_IPV6;212 if (type) *type = VC_NXA_TYPE_IPV6; 207 213 ret = inet_pton(AF_INET6, str, dst); 208 214 } … … 211 217 212 218 static void 213 readIP(char const *str, struct vc_ips **ips) 214 { 215 if (ifconfig_getaddr(str, &(*ips)->a.ip[0], &(*ips)->a.mask[0], NULL)==-1) { 219 ipv6PrefixToMask(struct in6_addr *mask, int prefix) 220 { 221 int i; 222 mask->s6_addr32[0] = mask->s6_addr32[1] = mask->s6_addr32[2] = mask->s6_addr32[3] = 0; 223 for (i = 0; (i << 3) < prefix; i++) { 224 mask->s6_addr[i] = 0xff; 225 } 226 if ((i << 3) > prefix) 227 mask->s6_addr[i-1] = ~((1 << (prefix & 0x07)) - 1); 228 } 229 230 static int 231 maskToPrefix(void *data, int limit) 232 { 233 uint8_t *mask = data; 234 int prefix; 235 for (prefix = 0; prefix < limit && mask[prefix >> 3] & (1 << (prefix & 0x07)); prefix++) 236 ; 237 return prefix; 238 } 239 240 static void 241 readIP(char const *str, struct vc_ips **ips, uint16_t type) 242 { 243 if (ifconfig_getaddr(str, &(*ips)->a.vna_v4_ip.s_addr, &(*ips)->a.vna_v4_mask.s_addr, NULL)==-1) { 216 244 char *pt; 217 245 char tmpopt[strlen(str)+1]; 218 uint32_t *mask = (*ips)->a.mask;219 246 220 247 strcpy(tmpopt,str); … … 223 250 *pt++ = '\0'; 224 251 225 if (convertAddress(tmpopt, &(*ips)->a. type, (*ips)->a.ip) == -1) {252 if (convertAddress(tmpopt, &(*ips)->a.vna_type, &(*ips)->a.vna_v4_ip.s_addr) == -1) { 226 253 WRITE_MSG(2, "Invalid IP number '"); 227 254 WRITE_STR(2, tmpopt); … … 231 258 232 259 if (pt==0) { 233 switch ((*ips)->a.type) { 234 case vcNET_IPV4: 235 mask[0] = htonl(0xffffff00); 260 switch ((*ips)->a.vna_type) { 261 case VC_NXA_TYPE_IPV4: 262 (*ips)->a.vna_v4_mask.s_addr = htonl(0xffffff00); 263 (*ips)->a.vna_prefix = 24; 236 264 break; 237 case vcNET_IPV6: 238 mask[0] = 64; 265 case VC_NXA_TYPE_IPV6: 266 (*ips)->a.vna_prefix = 64; 267 (*ips)->a.vna_v6_mask.s6_addr32[0] = (*ips)->a.vna_v6_mask.s6_addr32[1] = 0xffffffff; 268 (*ips)->a.vna_v6_mask.s6_addr32[2] = (*ips)->a.vna_v6_mask.s6_addr32[3] = 0x00000000; 239 269 break; 240 270 default: break; … … 246 276 unsigned long sz, limit = 0; 247 277 248 switch ((*ips)->a. type) {249 case vcNET_IPV4: limit = 32;break;250 case vcNET_IPV6: limit = 128;break;251 default: break;278 switch ((*ips)->a.vna_type) { 279 case VC_NXA_TYPE_IPV4: limit = 32; break; 280 case VC_NXA_TYPE_IPV6: limit = 128; break; 281 default: break; 252 282 } 253 283 … … 259 289 } 260 290 261 switch ((*ips)->a.type) { 262 case vcNET_IPV4: 263 mask[0] = htonl(~((1 << (32 - sz)) - 1)); 291 (*ips)->a.vna_prefix = sz; 292 switch ((*ips)->a.vna_type) { 293 case VC_NXA_TYPE_IPV4: 294 (*ips)->a.vna_v4_mask.s_addr = htonl(~((1 << (32 - sz)) - 1)); 264 295 break; 265 case vcNET_IPV6:266 mask[0] = sz;296 case VC_NXA_TYPE_IPV6: 297 ipv6PrefixToMask(&(*ips)->a.vna_v6_mask, (*ips)->a.vna_prefix); 267 298 break; 268 299 default: break; 269 300 } 270 301 } 271 else { 272 if (convertAddress(pt, NULL, &(*ips)->a.mask) == -1) { 302 else { 303 int af, limit; 304 void *mask; 305 switch ((*ips)->a.vna_type) { 306 case VC_NXA_TYPE_IPV4: 307 af = AF_INET; 308 mask = &(*ips)->a.vna_v4_mask.s_addr; 309 limit = 32; 310 break; 311 case VC_NXA_TYPE_IPV6: 312 af = AF_INET6; 313 mask = (*ips)->a.vna_v6_mask.s6_addr32; 314 limit = 128; 315 break; 316 default: 317 return; 318 } 319 if (inet_pton(af, pt, mask) < 0) { 273 320 WRITE_MSG(2, "Invalid netmask '"); 274 321 WRITE_STR(2, pt); … … 276 323 exit(wrapper_exit_code); 277 324 } 325 (*ips)->a.vna_prefix = maskToPrefix(mask, limit); 278 326 } 279 327 } 280 328 } 281 329 else 282 (*ips)->a. type = vcNET_IPV4;283 284 (*ips)->a.count = 1; 330 (*ips)->a.vna_type = VC_NXA_TYPE_IPV4; 331 (*ips)->a.vna_type |= type; 332 285 333 (*ips)->next = calloc(1, sizeof(struct vc_ips)); 286 334 *ips = (*ips)->next; … … 292 340 uint32_t bcast; 293 341 if (ifconfig_getaddr(str, NULL, NULL, &bcast)==-1){ 294 if ( convertAddress(str, NULL, &bcast) == -1) {342 if (inet_pton(AF_INET, str, &bcast) < 0) { 295 343 WRITE_MSG(2, "Invalid broadcast number '"); 296 344 WRITE_STR(2, optarg); … … 299 347 }
