00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00024 #ifndef H_VSERVER_SYSCALL_H
00025 #define H_VSERVER_SYSCALL_H
00026
00027 #include <stdint.h>
00028 #include <stdlib.h>
00029 #include <stdbool.h>
00030 #include <sys/types.h>
00031
00032 #ifndef IS_DOXYGEN
00033 #if defined(__GNUC__)
00034 # define VC_ATTR_UNUSED __attribute__((__unused__))
00035 # define VC_ATTR_NORETURN __attribute__((__noreturn__))
00036 # define VC_ATTR_CONST __attribute__((__const__))
00037 # define VC_ATTR_DEPRECATED __attribute__((__deprecated__))
00038 # if __GNUC__*0x10000 + __GNUC_MINOR__*0x100 + __GNUC_PATCHLEVEL__ >= 0x30300
00039 # define VC_ATTR_NONNULL(ARGS) __attribute__((__nonnull__ ARGS))
00040 # define VC_ATTR_ALWAYSINLINE __attribute__((__always_inline__))
00041 # else
00042 # define VC_ATTR_NONNULL(ARGS)
00043 # define VC_ATTR_ALWAYSINLINE
00044 # endif
00045 # if __GNUC__*0x10000 + __GNUC_MINOR__*0x100 + __GNUC_PATCHLEVEL__ >= 0x30303
00046 # define VC_ATTR_PURE __attribute__((__pure__))
00047 # else
00048 # define VC_ATTR_PURE
00049 # endif
00050 #else
00051 # define VC_ATTR_NONNULL(ARGS)
00052 # define VC_ATTR_UNUSED
00053 # define VC_ATTR_NORETURN
00054 # define VC_ATTR_ALWAYSINLINE
00055 # define VC_ATTR_DEPRECATED
00056 # define VC_ATTR_PURE
00057 # define VC_ATTR_CONST
00058 #endif
00059 #endif // IS_DOXYGEN
00060
00062 #define VC_NOCTX ((xid_t)(-1))
00063 #define VC_NOXID ((xid_t)(-1))
00064
00065 #define VC_DYNAMIC_XID ((xid_t)(-1))
00066
00067 #define VC_SAMECTX ((xid_t)(-2))
00068
00069 #define VC_NONID ((nid_t)(-1))
00070 #define VC_DYNAMIC_NID ((nid_t)(-1))
00071
00072 #define VC_LIM_INFINITY (~0ULL)
00073 #define VC_LIM_KEEP (~1ULL)
00074
00075 #define VC_CDLIM_UNSET (0U)
00076 #define VC_CDLIM_INFINITY (~0U)
00077 #define VC_CDLIM_KEEP (~1U)
00078
00079 #ifndef S_CTX_INFO_LOCK
00080 # define S_CTX_INFO_LOCK 1
00081 #endif
00082
00083 #ifndef S_CTX_INFO_SCHED
00084 # define S_CTX_INFO_SCHED 2
00085 #endif
00086
00087 #ifndef S_CTX_INFO_NPROC
00088 # define S_CTX_INFO_NPROC 4
00089 #endif
00090
00091 #ifndef S_CTX_INFO_PRIVATE
00092 # define S_CTX_INFO_PRIVATE 8
00093 #endif
00094
00095 #ifndef S_CTX_INFO_INIT
00096 # define S_CTX_INFO_INIT 16
00097 #endif
00098
00099 #ifndef S_CTX_INFO_HIDEINFO
00100 # define S_CTX_INFO_HIDEINFO 32
00101 #endif
00102
00103 #ifndef S_CTX_INFO_ULIMIT
00104 # define S_CTX_INFO_ULIMIT 64
00105 #endif
00106
00107 #ifndef S_CTX_INFO_NAMESPACE
00108 # define S_CTX_INFO_NAMESPACE 128
00109 #endif
00110
00111 #define VC_CAP_CHOWN 0
00112 #define VC_CAP_DAC_OVERRIDE 1
00113 #define VC_CAP_DAC_READ_SEARCH 2
00114 #define VC_CAP_FOWNER 3
00115 #define VC_CAP_FSETID 4
00116 #define VC_CAP_KILL 5
00117 #define VC_CAP_SETGID 6
00118 #define VC_CAP_SETUID 7
00119 #define VC_CAP_SETPCAP 8
00120 #define VC_CAP_LINUX_IMMUTABLE 9
00121 #define VC_CAP_NET_BIND_SERVICE 10
00122 #define VC_CAP_NET_BROADCAST 11
00123 #define VC_CAP_NET_ADMIN 12
00124 #define VC_CAP_NET_RAW 13
00125 #define VC_CAP_IPC_LOCK 14
00126 #define VC_CAP_IPC_OWNER 15
00127 #define VC_CAP_SYS_MODULE 16
00128 #define VC_CAP_SYS_RAWIO 17
00129 #define VC_CAP_SYS_CHROOT 18
00130 #define VC_CAP_SYS_PTRACE 19
00131 #define VC_CAP_SYS_PACCT 20
00132 #define VC_CAP_SYS_ADMIN 21
00133 #define VC_CAP_SYS_BOOT 22
00134 #define VC_CAP_SYS_NICE 23
00135 #define VC_CAP_SYS_RESOURCE 24
00136 #define VC_CAP_SYS_TIME 25
00137 #define VC_CAP_SYS_TTY_CONFIG 26
00138 #define VC_CAP_MKNOD 27
00139 #define VC_CAP_LEASE 28
00140 #define VC_CAP_AUDIT_WRITE 29
00141 #define VC_CAP_AUDIT_CONTROL 30
00142
00143 #define VC_IMMUTABLE_FILE_FL 0x0000010lu
00144 #define VC_IMMUTABLE_LINK_FL 0x0008000lu
00145 #define VC_IMMUTABLE_ALL (VC_IMMUTABLE_LINK_FL|VC_IMMUTABLE_FILE_FL)
00146
00147 #define VC_IATTR_XID 0x01000000u
00148
00149 #define VC_IATTR_ADMIN 0x00000001u
00150 #define VC_IATTR_WATCH 0x00000002u
00151 #define VC_IATTR_HIDE 0x00000004u
00152 #define VC_IATTR_FLAGS 0x00000007u
00153
00154 #define VC_IATTR_BARRIER 0x00010000u
00155 #define VC_IATTR_IUNLINK 0x00020000u
00156 #define VC_IATTR_IMMUTABLE 0x00040000u
00157
00158
00159
00160 #define VC_VXF_INFO_LOCK 0x00000001ull
00161 #define VC_VXF_INFO_NPROC 0x00000004ull
00162 #define VC_VXF_INFO_PRIVATE 0x00000008ull
00163 #define VC_VXF_INFO_INIT 0x00000010ull
00164
00165 #define VC_VXF_INFO_HIDEINFO 0x00000020ull
00166 #define VC_VXF_INFO_ULIMIT 0x00000040ull
00167 #define VC_VXF_INFO_NAMESPACE 0x00000080ull
00168
00169 #define VC_VXF_SCHED_HARD 0x00000100ull
00170 #define VC_VXF_SCHED_PRIO 0x00000200ull
00171 #define VC_VXF_SCHED_PAUSE 0x00000400ull
00172
00173 #define VC_VXF_VIRT_MEM 0x00010000ull
00174 #define VC_VXF_VIRT_UPTIME 0x00020000ull
00175 #define VC_VXF_VIRT_CPU 0x00040000ull
00176 #define VC_VXF_VIRT_LOAD 0x00080000ull
00177
00178 #define VC_VXF_HIDE_MOUNT 0x01000000ull
00179 #define VC_VXF_HIDE_NETIF 0x02000000ull
00180
00181 #define VC_VXF_STATE_SETUP (1ULL<<32)
00182 #define VC_VXF_STATE_INIT (1ULL<<33)
00183
00184 #define VC_VXF_FORK_RSS (1ULL<<48)
00185 #define VC_VXF_PROLIFIC (1ULL<<49)
00186
00187 #define VC_VXF_IGNEG_NICE (1ULL<<52)
00188
00189
00190
00191 #define VC_VXC_SET_UTSNAME 0x00000001ull
00192 #define VC_VXC_SET_RLIMIT 0x00000002ull
00193
00194 #define VC_VXC_RAW_ICMP 0x00000100ull
00195 #define VC_VXC_SYSLOG 0x00001000ull
00196
00197 #define VC_VXC_SECURE_MOUNT 0x00010000ull
00198 #define VC_VXC_SECURE_REMOUNT 0x00020000ull
00199 #define VC_VXC_BINARY_MOUNT 0x00040000ull
00200
00201 #define VC_VXC_QUOTA_CTL 0x00100000ull
00202
00203
00204 #define VC_VXSM_FILL_RATE 0x0001
00205 #define VC_VXSM_INTERVAL 0x0002
00206 #define VC_VXSM_TOKENS 0x0010
00207 #define VC_VXSM_TOKENS_MIN 0x0020
00208 #define VC_VXSM_TOKENS_MAX 0x0040
00209 #define VC_VXSM_PRIO_BIAS 0x0100
00210
00211
00212 #define VC_BAD_PERSONALITY ((uint_least32_t)(-1))
00213
00214
00224 #ifdef IS_DOXYGEN
00225 typedef an_unsigned_integer_type xid_t;
00226 typedef an_unsigned_integer_type nid_t;
00227 #endif
00228
00229 #ifdef __cplusplus
00230 extern "C" {
00231 #endif
00232
00233 struct vc_ip_mask_pair {
00234 uint32_t ip;
00235 uint32_t mask;
00236 };
00237
00250 int vc_syscall(uint32_t cmd, xid_t xid, void *data);
00251
00256 int vc_get_version();
00257
00275 xid_t vc_new_s_context(xid_t ctx, unsigned int remove_cap, unsigned int flags);
00276
00280 int vc_set_ipv4root(uint32_t bcast, size_t nb,
00281 struct vc_ip_mask_pair const *ips) VC_ATTR_NONNULL((3));
00282
00289 size_t vc_get_nb_ipv4root() VC_ATTR_CONST VC_ATTR_PURE;
00290
00302 xid_t vc_ctx_create(xid_t xid);
00303
00309 int vc_ctx_migrate(xid_t xid);
00310
00311
00312
00322 typedef uint_least64_t vc_limit_t;
00323
00327 struct vc_rlimit {
00328 vc_limit_t min;
00329 vc_limit_t soft;
00330 vc_limit_t hard;
00331 };
00332
00334 struct vc_rlimit_mask {
00335 uint_least32_t min;
00336 uint_least32_t soft;
00337 uint_least32_t hard;
00338 };
00339
00348 int vc_get_rlimit(xid_t xid, int resource,
00349 struct vc_rlimit *lim) VC_ATTR_NONNULL((3));
00358 int vc_set_rlimit(xid_t xid, int resource,
00359 struct vc_rlimit const *lim) VC_ATTR_NONNULL((3));
00360 int vc_get_rlimit_mask(xid_t xid,
00361 struct vc_rlimit_mask *lim) VC_ATTR_NONNULL((2));
00381 bool vc_parseLimit(char const *str, vc_limit_t *res) VC_ATTR_NONNULL((1,2));
00382
00383
00390 int vc_ctx_kill(xid_t ctx, pid_t pid, int sig);
00391
00392
00393 struct vc_nx_info {
00394 nid_t nid;
00395 };
00396
00397 nid_t vc_get_task_nid(pid_t pid);
00398 int vc_get_nx_info(nid_t nid, struct vc_nx_info *) VC_ATTR_NONNULL((2));
00399
00400 typedef enum { vcNET_IPV4=1, vcNET_IPV6=2,
00401 vcNET_IPV4B=0x101, vcNET_IPV6B=0x102,
00402 vcNET_ANY=~0 } vc_net_nx_type;
00403
00404 struct vc_net_nx {
00405 vc_net_nx_type type;
00406 size_t count;
00407 uint32_t ip[4];
00408 uint32_t mask[4];
00409 };
00410
00411 nid_t vc_net_create(nid_t nid);
00412 int vc_net_migrate(nid_t nid);
00413
00414 int vc_net_add(nid_t nid, struct vc_net_nx const *info);
00415 int vc_net_remove(nid_t nid, struct vc_net_nx const *info);
00416
00417 struct vc_net_flags {
00418 uint_least64_t flagword;
00419 uint_least64_t mask;
00420 };
00421
00422 int vc_get_nflags(nid_t, struct vc_net_flags *);
00423 int vc_set_nflags(nid_t, struct vc_net_flags const *);
00424
00425
00426 struct vc_net_caps {
00427 uint_least64_t ncaps;
00428 uint_least64_t cmask;
00429 };
00430
00431 int vc_get_ncaps(nid_t, struct vc_net_caps *);
00432 int vc_set_ncaps(nid_t, struct vc_net_caps const *);
00433
00434
00435
00436
00437 int vc_set_iattr(char const *filename, xid_t xid,
00438 uint_least32_t flags, uint_least32_t mask) VC_ATTR_NONNULL((1));
00439
00466 int vc_get_iattr(char const *filename, xid_t * xid,
00467 uint_least32_t * flags,
00468 uint_least32_t * mask) VC_ATTR_NONNULL((1));
00469
00470 struct vc_vx_info {
00471 xid_t xid;
00472 pid_t initpid;
00473 };
00474
00482 xid_t vc_get_task_xid(pid_t pid);
00483 int vc_get_vx_info(xid_t xid, struct vc_vx_info *info) VC_ATTR_NONNULL((2));
00484
00485
00486 typedef enum { vcVHI_CONTEXT, vcVHI_SYSNAME, vcVHI_NODENAME,
00487 vcVHI_RELEASE, vcVHI_VERSION, vcVHI_MACHINE,
00488 vcVHI_DOMAINNAME } vc_uts_type;
00489
00490 int vc_set_vhi_name(xid_t xid, vc_uts_type type,
00491 char const *val, size_t len) VC_ATTR_NONNULL((3));
00492 int vc_get_vhi_name(xid_t xid, vc_uts_type type,
00493 char *val, size_t len) VC_ATTR_NONNULL((3));
00494
00496 bool vc_is_dynamic_xid(xid_t xid);
00497
00498 int vc_enter_namespace(xid_t xid);
00499 int vc_set_namespace();
00500 int vc_cleanup_namespace();
00501
00502
00505 struct vc_ctx_flags {
00507 uint_least64_t flagword;
00511 uint_least64_t mask;
00512 };
00513
00515 struct vc_ctx_caps {
00517 uint_least64_t bcaps;
00521 uint_least64_t bmask;
00523 uint_least64_t ccaps;
00527 uint_least64_t cmask;
00528 };
00529
00533 struct vc_err_listparser {
00534 char const *ptr;
00535 size_t len;
00536 };
00537
00538 int vc_get_cflags(xid_t xid, struct vc_ctx_flags *) VC_ATTR_NONNULL((2));
00539 int vc_set_cflags(xid_t xid, struct vc_ctx_flags const *) VC_ATTR_NONNULL((2));
00540
00541 int vc_get_ccaps(xid_t xid, struct vc_ctx_caps *);
00542 int vc_set_ccaps(xid_t xid, struct vc_ctx_caps const *);
00543
00554 uint_least64_t vc_text2bcap(char const *str, size_t len);
00555
00570 char const * vc_lobcap2text(uint_least64_t *val) VC_ATTR_NONNULL((1));
00571
00599 int vc_list2bcap(char const *str, size_t len,
00600 struct vc_err_listparser *err,
00601 struct vc_ctx_caps *cap) VC_ATTR_NONNULL((1,4));
00602
00603 uint_least64_t vc_text2ccap(char const *, size_t len);
00604 char const * vc_loccap2text(uint_least64_t *);
00605 int vc_list2ccap(char const *, size_t len,
00606 struct vc_err_listparser *err,
00607 struct vc_ctx_caps *);
00608
00609 int vc_list2cflag(char const *, size_t len,
00610 struct vc_err_listparser *err,
00611 struct vc_ctx_flags *flags);
00612 uint_least64_t vc_text2cflag(char const *, size_t len);
00613 char const * vc_locflag2text(uint_least64_t *);
00614
00615 uint_least32_t vc_list2cflag_compat(char const *, size_t len,
00616 struct vc_err_listparser *err);
00617 uint_least32_t vc_text2cflag_compat(char const *, size_t len);
00618 char const * vc_hicflag2text_compat(uint_least32_t);
00619
00620 int vc_text2cap(char const *);
00621 char const * vc_cap2text(unsigned int);
00622
00623
00624 int vc_list2nflag(char const *, size_t len,
00625 struct vc_err_listparser *err,
00626 struct vc_net_flags *flags);
00627 uint_least64_t vc_text2nflag(char const *, size_t len);
00628 char const * vc_lonflag2text(uint_least64_t *);
00629
00630 uint_least64_t vc_text2ncap(char const *, size_t len);
00631 char const * vc_loncap2text(uint_least64_t *);
00632 int vc_list2ncap(char const *, size_t len,
00633 struct vc_err_listparser *err,
00634 struct vc_net_caps *);
00635
00636 uint_least64_t vc_get_insecurebcaps() VC_ATTR_CONST;
00637 inline static uint_least64_t vc_get_insecureccaps() {
00638 return ~(VC_VXC_SET_UTSNAME|VC_VXC_RAW_ICMP);
00639 }
00640
00641 inline static int vc_setfilecontext(char const *filename, xid_t xid) {
00642 return vc_set_iattr(filename, xid, 0, VC_IATTR_XID);
00643 }
00644
00645
00646 uint_least32_t vc_text2personalityflag(char const *str,
00647 size_t len) VC_ATTR_NONNULL((1));
00648
00649 char const * vc_lopersonality2text(uint_least32_t *) VC_ATTR_NONNULL((1));
00650
00651 int vc_list2personalityflag(char const *,
00652 size_t len,
00653 uint_least32_t *personality,
00654 struct vc_err_listparser *err) VC_ATTR_NONNULL((1,3));
00655
00656 uint_least32_t vc_str2personalitytype(char const *,
00657 size_t len) VC_ATTR_NONNULL((1));
00658
00672 xid_t vc_getfilecontext(char const *filename) VC_ATTR_NONNULL((1));
00673
00674
00675 struct vc_set_sched {
00676 uint_least32_t set_mask;
00677 int_least32_t fill_rate;
00678 int_least32_t interval;
00679 int_least32_t tokens;
00680 int_least32_t tokens_min;
00681 int_least32_t tokens_max;
00682 int_least32_t priority_bias;
00683 };
00684
00685 int vc_set_sched(xid_t xid, struct vc_set_sched const *);
00686
00687
00688 struct vc_ctx_dlimit {
00689 uint_least32_t space_used;
00690 uint_least32_t space_total;
00691 uint_least32_t inodes_used;
00692 uint_least32_t inodes_total;
00693 uint_least32_t reserved;
00694 };
00695
00696
00698 int vc_add_dlimit(char const *filename, xid_t xid,
00699 uint_least32_t flags) VC_ATTR_NONNULL((1));
00701 int vc_rem_dlimit(char const *filename, xid_t xid,
00702 uint_least32_t flags) VC_ATTR_NONNULL((1));
00703
00705 int vc_set_dlimit(char const *filename, xid_t xid,
00706 uint_least32_t flags,
00707 struct vc_ctx_dlimit const *limits) VC_ATTR_NONNULL((1,4));
00709 int vc_get_dlimit(char const *filename, xid_t xid,
00710 uint_least32_t flags,
00711 struct vc_ctx_dlimit *limits) VC_ATTR_NONNULL((1));
00712
00716 int vc_wait_exit(xid_t xid);
00717
00718 typedef enum { vcFEATURE_VKILL, vcFEATURE_IATTR, vcFEATURE_RLIMIT,
00719 vcFEATURE_COMPAT, vcFEATURE_MIGRATE, vcFEATURE_NAMESPACE,
00720 vcFEATURE_SCHED, vcFEATURE_VINFO, vcFEATURE_VHI,
00721 vcFEATURE_VSHELPER0, vcFEATURE_VSHELPER, vcFEATURE_VWAIT,
00722 vcFEATURE_VNET }
00723 vcFeatureSet;
00724
00725 bool vc_isSupported(vcFeatureSet) VC_ATTR_CONST;
00726 bool vc_isSupportedString(char const *);
00727
00728
00729 typedef enum { vcTYPE_INVALID, vcTYPE_MAIN, vcTYPE_WATCH,
00730 vcTYPE_STATIC, vcTYPE_DYNAMIC }
00731 vcXidType;
00732
00733 vcXidType vc_getXIDType(xid_t xid) VC_ATTR_CONST;
00734
00735
00736
00737 #define VC_LIMIT_VSERVER_NAME_LEN 1024
00738
00739 typedef enum { vcCFG_NONE, vcCFG_AUTO,
00740 vcCFG_LEGACY,
00741 vcCFG_RECENT_SHORT,
00742 vcCFG_RECENT_FULL } vcCfgStyle;
00743
00744
00746 xid_t vc_xidopt2xid(char const *, bool honor_static, char const **err_info);
00747
00748 vcCfgStyle vc_getVserverCfgStyle(char const *id);
00749
00752 char * vc_getVserverName(char const *id, vcCfgStyle style);
00753
00758 char * vc_getVserverCfgDir(char const *id, vcCfgStyle style);
00759
00763 char * vc_getVserverAppDir(char const *id, vcCfgStyle style, char const *app);
00764
00767 char * vc_getVserverVdir(char const *id, vcCfgStyle style, bool physical);
00768
00776 xid_t vc_getVserverCtx(char const *id, vcCfgStyle style,
00777 bool honor_static, bool *is_running);
00778
00783 char * vc_getVserverByCtx(xid_t ctx, vcCfgStyle *style,
00784 char const *revdir);
00785
00786 int vc_compareVserverById(char const *lhs, vcCfgStyle lhs_style,
00787 char const *rhs, vcCfgStyle rhs_style);
00788
00789 #define vcSKEL_INTERFACES 1u
00790 #define vcSKEL_PKGMGMT 2u
00791 #define vcSKEL_FILESYSTEM 4u
00792
00795 int vc_createSkeleton(char const *id, vcCfgStyle style, int flags);
00796
00797
00798 #ifdef __cplusplus
00799 }
00800 #endif
00801
00802 #undef VC_ATTR_PURE
00803 #undef VC_ATTR_ALWAYSINLINE
00804 #undef VC_ATTR_NORETURN
00805 #undef VC_ATTR_UNUSED
00806 #undef VC_ATTR_NONNULL
00807
00808 #endif