Changeset 2578

Show
Ignore:
Timestamp:
08/08/07 22:05:26 (1 year ago)
Author:
dhozac
Message:

Add support for the various new APIs in 2.2 and 2.3, in particular, netv2.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/AUTHORS

    r2283 r2578  
    11Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de> 
     2Daniel Hokka Zakrisson <daniel@hozac.com> 
  • trunk/configure.ac

    r2567 r2578  
    227227AH_TEMPLATE(VC_ENABLE_API_NET,      [Enable support for network context API]) 
    228228AH_TEMPLATE(VC_ENABLE_API_V21,      [Enable support for API of vserver 2.1.x]) 
     229AH_TEMPLATE(VC_ENABLE_API_V22,      [Enable support for API of vserver 2.2.x]) 
     230AH_TEMPLATE(VC_ENABLE_API_V23,      [Enable support for API of vserver 2.3.x]) 
     231AH_TEMPLATE(VC_ENABLE_API_NETV2,    [Enable support for new networking API]) 
    229232AH_TEMPLATE(VC_ENABLE_API_OLDPROC,  [Enable API for a backward compatible /proc parsing]) 
    230233AH_TEMPLATE(VC_ENABLE_API_OLDUTS,   [Enable API for a backward compatible uts handling]) 
     
    233236AC_ARG_ENABLE([apis], 
    234237              [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)])], 
    236239              [], 
    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 
     242test x"$enable_apis" != xALL      || enable_apis='legacy,compat,v11,fscompat,v13obs,v13,net,v21,v22,v23,netv2
     243test x"$enable_apis" != xNOLEGACY || enable_apis='compat,v11,fscompat,v13,net,v21,v22,v23,netv2
    241244enable_api_oldproc= 
    242245enable_api_olduts= 
     
    264267                (net)           AC_DEFINE(VC_ENABLE_API_NET,      1);; 
    265268                (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);; 
    266272                (oldproc)       enable_api_oldproc=2;; 
    267273                (olduts)        enable_api_olduts=2;; 
  • trunk/ensc_wrappers/wrappers-vserver.hc

    r2501 r2578  
    5050 
    5151inline static WRAPPER_DECL xid_t 
    52 Evc_ctx_create(xid_t xid
     52Evc_ctx_create(xid_t xid, struct vc_ctx_flags *flags
    5353{ 
    54   register xid_t        res = vc_ctx_create(xid); 
     54  register xid_t        res = vc_ctx_create(xid, flags); 
    5555  FatalErrnoError(res==VC_NOCTX, "vc_ctx_create()"); 
    5656  return res; 
  • trunk/kernel/inode_cmd.h

    r2413 r2578  
    55/*  inode vserver commands */ 
    66 
    7 #define VCMD_get_iattr_v0       VC_CMD(INODE, 1, 0) 
    8 #define VCMD_set_iattr_v0       VC_CMD(INODE, 2, 0) 
    9  
    107#define VCMD_get_iattr          VC_CMD(INODE, 1, 1) 
    118#define VCMD_set_iattr          VC_CMD(INODE, 2, 1) 
    129 
    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) 
    2012 
    2113struct  vcmd_ctx_iattr_v1 { 
     
    2618}; 
    2719 
     20struct  vcmd_ctx_fiattr_v0 { 
     21        uint32_t xid; 
     22        uint32_t flags; 
     23        uint32_t mask; 
     24}; 
     25 
    2826 
    2927#endif  /* _VX_INODE_CMD_H */ 
  • trunk/kernel/network.h

    r2413 r2578  
    77#define MAX_N_CONTEXT   65535   /* Arbitrary limit */ 
    88 
    9 #define NX_DYNAMIC_ID   ((uint32_t)-1)          /* id for dynamic context */ 
    10  
    119#define NB_IPV4ROOT     16 
    1210 
     
    1412/* network flags */ 
    1513 
    16 #define NXF_INFO_LOCK          0x00000001 
     14#define NXF_INFO_PRIVATE       0x00000008 
    1715 
    18 #define NXF_STATE_SETUP         (1ULL<<32) 
    19 #define NXF_STATE_ADMIN         (1ULL<<34) 
     16#define NXF_SINGLE_IP           0x00000100 
    2017 
    21 #define NXF_SC_HELPER           (1ULL<<36) 
    22 #define NXF_PERSISTENT          (1ULL<<38) 
     18#define NXF_HIDE_NETIF          0x02000000 
    2319 
    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) 
    2527 
    2628#define NXF_INIT_SET            (NXF_STATE_ADMIN) 
     
    2931/* address types */ 
    3032 
    31 #define NXA_TYPE_IPV4           
    32 #define NXA_TYPE_IPV6           
     33#define NXA_TYPE_IPV4           0x000
     34#define NXA_TYPE_IPV6           0x000
    3335 
    34 #define NXA_MOD_BCAST           (1<<8) 
     36#define NXA_TYPE_NONE           0x0000 
     37#define NXA_TYPE_ANY            0x00FF 
    3538 
    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 
    3745 
    3846 
  • trunk/kernel/network_cmd.h

    r2413 r2578  
    2525#define VCMD_net_migrate        VC_CMD(NETMIG, 1, 0) 
    2626 
    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) 
    2929 
    3030struct  vcmd_net_addr_v0 { 
    3131        uint16_t type; 
    3232        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 
     40struct  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 
     50struct  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 
     61struct  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 
     74struct  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; 
    3682}; 
    3783 
  • trunk/lib/Makefile-files

    r2568 r2578  
    134134                                lib/syscall_getccaps-v21.hc \ 
    135135                                lib/syscall_getsched.c \ 
    136                                 lib/syscall_getsched-v21.hc 
     136                                lib/syscall_getsched-v21.hc \ 
     137                                lib/syscall_ctxcreate-v21.hc 
     138 
     139lib_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 
     145lib_netv2_SRCS =                lib/syscall_netadd-netv2.hc \ 
     146                                lib/syscall_netremove-netv2.hc 
    137147 
    138148if ENSC_HAVE_C99_COMPILER 
     
    181191                                $(lib_v13_SRCS) \ 
    182192                                $(lib_v21_SRCS) \ 
     193                                $(lib_v22_SRCS) \ 
     194                                $(lib_netv2_SRCS) \ 
    183195                                $(ensc_fmt_SRCS) 
    184196 
  • trunk/lib/syscall_ctxcreate-v13.hc

    r2193 r2578  
    2222 
    2323static inline ALWAYSINLINE xid_t 
    24 vc_ctx_create_v13(xid_t xid
     24vc_ctx_create_v13(xid_t xid, struct vc_ctx_flags *flags
    2525{ 
    2626  xid_t         res = vserver(VCMD_ctx_create_v0, CTX_USER2KERNEL(xid), 0); 
    2727 
     28  if (flags) { 
     29    /* no sane way to report errors here */ 
     30    vc_set_cflags(xid, flags); 
     31  } 
     32 
    2833  return CTX_KERNEL2USER(res); 
    2934} 
  • trunk/lib/syscall_ctxcreate.c

    r2207 r2578  
    2222 
    2323#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 
    2429#include "vserver-internal.h" 
    25 #include "virtual.h" 
    2630 
    2731#if defined(VC_ENABLE_API_V13) 
     
    2933#endif 
    3034 
    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) 
    3240xid_t 
    33 vc_ctx_create(xid_t xid
     41vc_ctx_create(xid_t xid, struct vc_ctx_flags *flags
    3442{ 
    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)); 
    3645} 
    3746#endif 
  • trunk/lib/syscall_netadd-net.hc

    r2249 r2578  
    2222 
    2323static inline ALWAYSINLINE int 
    24 vc_net_add_net(nid_t nid, struct vc_net_nx const *info) 
     24vc_net_add_net(nid_t nid, struct vc_net_addr const *info) 
    2525{ 
    2626  struct vcmd_net_addr_v0               k_info; 
    2727  size_t                                i; 
    2828 
    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); 
    3747} 
  • trunk/lib/syscall_netadd.c

    r2249 r2578  
    2121#endif 
    2222 
     23#include <string.h> 
     24 
    2325#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 
    2431#include "vserver-internal.h" 
    25 #include "virtual.h" 
    2632 
    2733#if defined(VC_ENABLE_API_NET) 
     
    2935#endif 
    3036 
    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) 
    3242int 
    33 vc_net_add(nid_t nid, struct vc_net_nx const *info) 
     43vc_net_add(nid_t nid, struct vc_net_addr const *info) 
    3444{ 
    3545  if (info==0) { 
     
    3848  } 
    3949   
    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)); 
    4152} 
    4253#endif 
  • trunk/lib/syscall_netremove-net.hc

    r2249 r2578  
    2222 
    2323static inline ALWAYSINLINE int 
    24 vc_net_remove_net(nid_t nid, struct vc_net_nx const *info) 
     24vc_net_remove_net(nid_t nid, struct vc_net_addr const *info) 
    2525{ 
    2626  struct vcmd_net_addr_v0               k_info; 
    2727  size_t                                i; 
    2828 
    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); 
    3751} 
  • trunk/lib/syscall_netremove.c

    r2249 r2578  
    2121#endif 
    2222 
     23#include <string.h> 
     24 
    2325#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 
    2431#include "vserver-internal.h" 
    25 #include "virtual.h" 
    2632 
    2733#if defined(VC_ENABLE_API_NET) 
     
    2935#endif 
    3036 
    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) 
    3242int 
    33 vc_net_remove(nid_t nid, struct vc_net_nx const *info) 
     43vc_net_remove(nid_t nid, struct vc_net_addr const *info) 
    3444{ 
    3545  if (info==0) { 
     
    3848  } 
    3949   
    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)); 
    4152} 
    4253#endif 
  • trunk/lib/syscall_setsched.c

    r2367 r2578  
    3939#endif 
    4040 
     41#ifdef VC_ENABLE_API_V22 
     42#  include "syscall_setsched-v22.hc" 
     43#endif 
     44 
    4145int 
    4246vc_set_sched(xid_t xid, struct vc_set_sched const *data) 
    4347{ 
    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), 
    4550          CALL_VC_V13B  (vc_set_sched,xid,data), 
    4651          CALL_VC_V13OBS(vc_set_sched,xid,data)); 
  • trunk/lib/vserver-internal.h

    r2446 r2578  
    5151  do {                                                  \ 
    5252    int ver = utilvserver_checkCompatVersion();         \ 
    53     uint_least32_t conf = utilvserver_checkCompatConfig();    \ 
     53    uint_least32_t UNUSED conf = utilvserver_checkCompatConfig();     \ 
    5454    if (ver==-1) return -1;                             \ 
    5555    VC_SUFFIX, __VA_ARGS__, VC_PREFIX;                  \ 
     
    115115#endif 
    116116 
    117 #ifdef VC_ENABLE_API_V21 
     117#if defined(VC_ENABLE_API_V21) || defined(VC_ENABLE_API_V22) || defined(VC_ENABLE_API_V23) 
    118118#  define CALL_VC_SPACES(F,...) CALL_VC_GENERAL_CONFIG(VC_VCI_SPACES, spaces, F, __VA_ARGS__) 
    119119#else 
    120120#  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 
    121133#endif 
    122134 
     
    125137#else 
    126138#  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 
    127145#endif 
    128146 
     
    206224#endif 
    207225 
    208 #if 1 
    209 #  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 #else 
    222 #  define NETTYPE_USER2KERNEL(X)        (X) 
    223 #  define NETTYPE_KERNEL2USER(X)        (X) 
    224 #endif 
    225  
    226226#define CDLIM_USER2KERNEL(X)            ((X)==VC_CDLIM_UNSET    ? CDLIM_UNSET    : \ 
    227227                                         (X)==VC_CDLIM_INFINITY ? CDLIM_INFINITY : \ 
  • trunk/lib/vserver.h

    r2568 r2578  
    3030#include <sys/types.h> 
    3131#include <sched.h> 
     32#include <netinet/in.h> 
    3233 
    3334#ifndef IS_DOXYGEN 
     
    260261#define VC_VCI_NO_DYNAMIC               (1 << 0) 
    261262#define VC_VCI_SPACES                   (1 << 10) 
     263#define VC_VCI_NETV2                    (1 << 11) 
    262264 
    263265 
     
    272274#define VC_VXM_SET_INIT                 0x00000001 
    273275#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 
    274291 
    275292 
     
    394411     *  \returns the xid of the created context, or VC_NOCTX on errors. \c errno 
    395412     *           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); 
    397414 
    398415    /** \brief   Moves the current process into the specified context. 
     
    602619  int           vc_get_nx_info(nid_t nid, struct vc_nx_info *) VC_ATTR_NONNULL((2)); 
    603620 
    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 
    613640  }; 
    614641 
     
    621648  int           vc_net_migrate(nid_t nid); 
    622649 
    623   int           vc_net_add(nid_t nid, struct vc_net_nx const *info); 
    624   int           vc_net_remove(nid_t nid, struct vc_net_nx const *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); 
    625652 
    626653  int           vc_get_nflags(nid_t, struct vc_net_flags *); 
     
    640667  int           vc_set_iattr(char const *filename, xid_t xid, 
    641668                             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); 
    642672 
    643673    /** \brief   Returns information about attributes and assigned context of a file. 
     
    670700                             uint_least32_t * /*@null@*/ flags, 
    671701                             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)); 
    672706   
    673707  /** \brief   Returns the context of \c filename 
  • trunk/src/chbind.c

    r2557 r2578  
    243243} 
    244244 
    245 #if defined(VC_ENABLE_API_NET) 
    246 static void 
    247 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         else 
    267           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 #endif 
    299  
    300245int main (int argc, char *argv[]) 
    301246{ 
     
    316261      case CMD_SILENT           :  is_silent = true; break; 
    317262      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 #else 
    321263      case CMD_NID              :  WRITE_MSG(2, "WARNING: --nid is not supported by this version\n"); break; 
    322 #endif 
    323264      case CMD_IP               : 
    324265        if (nbaddrs>=nb_ipv4root) { 
     
    343284  } 
    344285   
    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 API 
     286#if !defined(VC_ENABLE_API_COMPAT) && !defined(VC_ENABLE_API_LEGACY) 
     287warning building a dummy chbind-compat with no available APIs 
    347288#endif 
    348289   
    349 #if defined(VC_ENABLE_API_NET) 
    350   if (vc_isSupported(vcFEATURE_VNET)) { 
    351     make_nx(nid, bcast, nbaddrs, ips); 
    352   } 
    353   else 
    354 #endif 
    355290#if defined(VC_ENABLE_API_COMPAT) || defined(VC_ENABLE_API_LEGACY) 
    356291  if (vc_set_ipv4root(bcast,nbaddrs,ips)!=0) { 
  • trunk/src/naddress.c

    </
    r2570 r2578  
    5858#define CMD_IP          0x2010 
    5959#define CMD_BCAST       0x2011 
     60#define CMD_MASK        0x2012 
     61#define CMD_RANGE       0x2013 
     62#define CMD_LBACK       0x2014 
    6063 
    6164int wrapper_exit_code = 255; 
     
    7275  { "nid",      required_argument, 0, CMD_NID }, 
    7376  { "ip",       required_argument, 0, CMD_IP }, 
     77  { "mask",     required_argument, 0, CMD_MASK }, 
     78  { "range",    required_argument, 0, CMD_RANGE }, 
    7479  { "bcast",    required_argument, 0, CMD_BCAST }, 
     80  { "lback",    required_argument, 0, CMD_LBACK }, 
    7581  { 0,0,0,0 } 
    7682}; 
    7783 
    7884struct vc_ips { 
    79   struct vc_net_nx a; 
     85  struct vc_net_addr a; 
    8086  struct vc_ips *next; 
    8187}; 
     
    198204 
    199205static int 
    200 convertAddress(const char *str, vc_net_nx_type *type, void *dst) 
     206convertAddress(const char *str, uint16_t *type, void *dst) 
    201207{ 
    202208  int   ret; 
    203   if (type) *type = vcNET_IPV4; 
     209  if (type) *type = VC_NXA_TYPE_IPV4; 
    204210  ret = inet_pton(AF_INET, str, dst); 
    205211  if (ret==0) { 
    206     if (type) *type = vcNET_IPV6; 
     212    if (type) *type = VC_NXA_TYPE_IPV6; 
    207213    ret = inet_pton(AF_INET6, str, dst); 
    208214  } 
     
    211217 
    212218static 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) { 
     219ipv6PrefixToMask(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 
     230static int 
     231maskToPrefix(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 
     240static void 
     241readIP(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) { 
    216244    char                *pt; 
    217245    char                tmpopt[strlen(str)+1]; 
    218     uint32_t            *mask = (*ips)->a.mask; 
    219246 
    220247    strcpy(tmpopt,str); 
     
    223250      *pt++ = '\0'; 
    224251 
    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) { 
    226253      WRITE_MSG(2, "Invalid IP number '"); 
    227254      WRITE_STR(2, tmpopt); 
     
    231258 
    232259    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; 
    236264          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; 
    239269          break; 
    240270        default: break; 
     
    246276        unsigned long   sz, limit = 0; 
    247277 
    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; 
    252282        } 
    253283 
     
    259289        } 
    260290 
    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)); 
    264295            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)
    267298            break; 
    268299          default: break; 
    269300        } 
    270301      } 
    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) { 
    273320          WRITE_MSG(2, "Invalid netmask '"); 
    274321          WRITE_STR(2, pt); 
     
    276323          exit(wrapper_exit_code); 
    277324        } 
     325        (*ips)->a.vna_prefix = maskToPrefix(mask, limit); 
    278326      } 
    279327    } 
    280328  } 
    281329  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 
    285333  (*ips)->next = calloc(1, sizeof(struct vc_ips)); 
    286334  *ips = (*ips)->next; 
     
    292340  uint32_t bcast; 
    293341  if (ifconfig_getaddr(str, NULL, NULL, &bcast)==-1){ 
    294     if (convertAddress(str, NULL, &bcast) == -1) { 
     342    if (inet_pton(AF_INET, str, &bcast) < 0) { 
    295343      WRITE_MSG(2, "Invalid broadcast number '"); 
    296344      WRITE_STR(2, optarg); 
     
    299347    }