added cflags
[util-vserver.git] / util-vserver / lib / vserver.h
index 92a63f6..eaa2026 100644 (file)
 #if defined(__GNUC__)
 #  define VC_ATTR_UNUSED                __attribute__((__unused__))
 #  define VC_ATTR_NORETURN              __attribute__((__noreturn__))
-#  if __GNUC__>3 || (__GNUC__==3 && __GNUC_MINOR__>=3)
+#  define VC_ATTR_CONST                        __attribute__((__const__))
+#  define VC_ATTR_DEPRECATED           __attribute__((__deprecated__))
+#  if __GNUC__*0x10000 + __GNUC_MINOR__*0x100 + __GNUC_PATCHLEVEL__ >= 0x30300
 #    define VC_ATTR_NONNULL(ARGS)      __attribute__((__nonnull__ ARGS))
 #    define VC_ATTR_ALWAYSINLINE        __attribute__((__always_inline__))
 #  else
 #    define VC_ATTR_NONNULL(ARGS)
 #    define VC_ATTR_ALWAYSINLINE
 #  endif
-#  if __GNUC__>3
+#  if __GNUC__*0x10000 + __GNUC_MINOR__*0x100 + __GNUC_PATCHLEVEL__ >= 0x30303
 #    define VC_ATTR_PURE               __attribute__((__pure__))
 #  else
 #    define VC_ATTR_PURE
@@ -50,7 +52,9 @@
 #  define VC_ATTR_UNUSED
 #  define VC_ATTR_NORETURN
 #  define VC_ATTR_ALWAYSINLINE
+#  define VC_ATTR_DEPRECATED
 #  define VC_ATTR_PURE
+#  define VC_ATTR_CONST
 #endif
 #endif // IS_DOXYGEN
 
 
 // the flags
 #define VC_VXF_INFO_LOCK               0x00000001
-#define VC_VXF_INFO_NPROC              0x00000002
-#define VC_VXF_INFO_PRIVATE            0x00000004
-#define VC_VXF_INFO_INIT               0x00000008
+#define VC_VXF_INFO_NPROC              0x00000004
+#define VC_VXF_INFO_PRIVATE            0x00000008
+#define VC_VXF_INFO_INIT               0x00000010
 
-#define VC_VXF_INFO_HIDE               0x00000010
-#define VC_VXF_INFO_ULIMIT             0x00000020
-#define VC_VXF_INFO_NSPACE             0x00000040
+#define VC_VXF_INFO_HIDEINFO           0x00000020
+#define VC_VXF_INFO_ULIMIT             0x00000040
+#define VC_VXF_INFO_NAMESPACE          0x00000080
 
 #define        VC_VXF_SCHED_HARD               0x00000100
 #define        VC_VXF_SCHED_PRIO               0x00000200
 
 #define VC_VXF_VIRT_MEM                        0x00010000
 #define VC_VXF_VIRT_UPTIME             0x00020000
+#define VC_VXF_VIRT_CPU                        0x00040000
+
+#define VC_VXF_HIDE_MOUNT              0x01000000
+#define VC_VXF_HIDE_NETIF              0x02000000
 
 #define        VC_VXF_STATE_SETUP              (1ULL<<32)
 #define        VC_VXF_STATE_INIT               (1ULL<<33)
 
+// the ccapabilities
+#define VC_VXC_SET_UTSNAME             0x00000001
+#define VC_VXC_SET_RLIMIT              0x00000002
+
+#define VC_VXC_ICMP_PING               0x00000100
+
+#define VC_VXC_SECURE_MOUNT            0x00010000
+
 
 /** \defgroup  syscalls Syscall wrappers
  *  Functions which are calling the vserver syscall directly. */
@@ -218,6 +234,14 @@ extern "C" {
   int  vc_set_ipv4root(uint32_t  bcast, size_t nb,
                        struct vc_ip_mask_pair const *ips) VC_ATTR_NONNULL((3));
 
+    /** \brief  Returns the value of NB_IPV4ROOT.
+     *  \ingroup helper
+     *
+     *  This function returns the value of NB_IPV4ROOT which was used when the
+     *  library was built, but \b not the value which is used by the currently
+     *  running kernel. */
+  size_t       vc_get_nb_ipv4root() VC_ATTR_CONST VC_ATTR_PURE;
+
     /** \brief   Creates a context without starting it.
      *  \ingroup syscalls
      *
@@ -229,14 +253,14 @@ extern "C" {
      *
      * \returns the xid of the created context, or VC_NOCTX on errors. errno
      *          will be set appropriately. */
-  xid_t        vc_create_context(xid_t xid);
+  xid_t        vc_ctx_create(xid_t xid);
 
     /** \brief   Moves the current process into the specified context.
      *  \ingroup syscalls
      *
      *  \param   xid  The new context
      *  \returns 0 on success, -1 on errors */
-  int  vc_migrate_context(xid_t xid);
+  int  vc_ctx_migrate(xid_t xid);
   
     /* rlimit related functions */
   
@@ -248,8 +272,7 @@ extern "C" {
      *                        modified by the vc_set_rlimit() operation.
      *
      *  Else, the interpretation of the value depends on the corresponding
-     *  resource; it might be bytes, pages, seconds or litres of beer.
-     */
+     *  resource; it might be bytes, pages, seconds or litres of beer. */
   typedef uint_least64_t       vc_limit_t;
 
     /** \brief  The limits of a resources.
@@ -361,6 +384,7 @@ extern "C" {
   
   struct  vc_ctx_caps {
       uint_least64_t   bcaps;
+      uint_least64_t   bmask;
       uint_least64_t   ccaps;
       uint_least64_t   cmask;
   };
@@ -370,8 +394,8 @@ extern "C" {
       size_t           len;
   };
  
-  int                  vc_get_flags(xid_t xid, struct vc_ctx_flags *)       VC_ATTR_NONNULL((2));
-  int                  vc_set_flags(xid_t xid, struct vc_ctx_flags const *) VC_ATTR_NONNULL((2));
+  int                  vc_get_cflags(xid_t xid, struct vc_ctx_flags *)       VC_ATTR_NONNULL((2));
+  int                  vc_set_cflags(xid_t xid, struct vc_ctx_flags const *) VC_ATTR_NONNULL((2));
 
   int                  vc_get_ccaps(xid_t xid, struct vc_ctx_caps *);
   int                  vc_set_ccaps(xid_t xid, struct vc_ctx_caps const *);
@@ -388,36 +412,27 @@ extern "C" {
                                     struct vc_err_listparser *err,
                                     struct vc_ctx_caps *);
 
-  int                  vc_list2flag(char const *, size_t len,
+  int                  vc_list2cflag(char const *, size_t len,
                                     struct vc_err_listparser *err,
                                     struct vc_ctx_flags *flags);
-  uint_least64_t       vc_text2flag(char const *, size_t len);
-  char const *         vc_loflag2text(uint_least64_t *);
+  uint_least64_t       vc_text2cflag(char const *, size_t len);
+  char const *         vc_locflag2text(uint_least64_t *);
   
-  uint_least32_t       vc_list2flag_compat(char const *, size_t len,
+  uint_least32_t       vc_list2cflag_compat(char const *, size_t len,
                                            struct vc_err_listparser *err);
-  uint_least32_t       vc_text2flag_compat(char const *, size_t len);
-  char const *         vc_hiflag2text_compat(uint_least32_t);
-  
-  int          vc_text2cap(char const *);
-  char const * vc_cap2text(unsigned int);
-
-  inline static uint_least32_t vc_get_securecaps() {
-    return ( (1<<VC_CAP_LINUX_IMMUTABLE) | (1<<VC_CAP_NET_BROADCAST) |
-            (1<<VC_CAP_NET_ADMIN) | (1<<VC_CAP_NET_RAW) |
-            (1<<VC_CAP_IPC_LOCK) | (1<<VC_CAP_IPC_OWNER) |
-            (1<<VC_CAP_SYS_MODULE) | (1<<VC_CAP_SYS_RAWIO) |
-            (1<<VC_CAP_SYS_PACCT) | (1<<VC_CAP_SYS_ADMIN) |
-            (1<<VC_CAP_SYS_BOOT) | (1<<VC_CAP_SYS_NICE) |
-            (1<<VC_CAP_SYS_RESOURCE) | (1<<VC_CAP_SYS_TIME) |
-            (1<<VC_CAP_MKNOD) | (1<<VC_CAP_QUOTACTL) );
-  }
+  uint_least32_t       vc_text2cflag_compat(char const *, size_t len);
+  char const *         vc_hicflag2text_compat(uint_least32_t);
+
+  uint_least32_t       vc_get_insecurecaps() VC_ATTR_CONST;
+  int                  vc_text2cap(char const *);
+  char const *         vc_cap2text(unsigned int);
+
 
-  inline static int            vc_setfilecontext(char const *filename, xid_t xid) {
+  inline static int    vc_setfilecontext(char const *filename, xid_t xid) {
     return vc_set_iattr(filename, xid, 0, VC_IATTR_XID);
   }
   
-  inline static xid_t          vc_getfilecontext(char const *filename) {
+  inline static xid_t  vc_getfilecontext(char const *filename) {
     xid_t      res;
     if (vc_get_iattr(filename, &res, 0,0)==-1) return VC_NOCTX;
     return res;
@@ -438,12 +453,13 @@ extern "C" {
   
   typedef enum { vcFEATURE_VKILL,  vcFEATURE_IATTR,   vcFEATURE_RLIMIT,
                 vcFEATURE_COMPAT, vcFEATURE_MIGRATE, vcFEATURE_NAMESPACE,
-                vcFEATURE_SCHED,  vcFEATURE_VINFO,   vcFEATURE_VHI }
+                vcFEATURE_SCHED,  vcFEATURE_VINFO,   vcFEATURE_VHI,
+                 vcFEATURE_VSHELPER0, vcFEATURE_VSHELPER }
     vcFeatureSet;
 
-  bool         vc_isSupported(vcFeatureSet);
+  bool         vc_isSupported(vcFeatureSet) VC_ATTR_CONST;
   bool         vc_isSupportedString(char const *);
-  
+
   /* The management part */
 
 #define VC_LIMIT_VSERVER_NAME_LEN      1024
@@ -453,6 +469,10 @@ extern "C" {
                 vcCFG_RECENT_SHORT,
                 vcCFG_RECENT_FULL }            vcCfgStyle;
 
+
+  /** Maps an xid given at '--xid' options to an xid_t */
+  xid_t                vc_xidopt2xid(char const *, bool honor_static, char const **err_info);
+
   vcCfgStyle   vc_getVserverCfgStyle(char const *id);
   
   /** Resolves the name of the vserver. The result will be allocated and must