iproute2/include/namespace.h
<<
>>
Prefs
   1/* SPDX-License-Identifier: GPL-2.0 */
   2#ifndef __NAMESPACE_H__
   3#define __NAMESPACE_H__ 1
   4
   5#include <sched.h>
   6#include <sys/mount.h>
   7#include <unistd.h>
   8#include <sys/syscall.h>
   9#include <errno.h>
  10#include <libnetlink.h>
  11
  12#ifndef NETNS_RUN_DIR
  13#define NETNS_RUN_DIR "/var/run/netns"
  14#endif
  15
  16#ifndef NETNS_ETC_DIR
  17#define NETNS_ETC_DIR "/etc/netns"
  18#endif
  19
  20#ifndef CLONE_NEWNET
  21#define CLONE_NEWNET 0x40000000 /* New network namespace (lo, device, names sockets, etc) */
  22#endif
  23
  24#ifndef MNT_DETACH
  25#define MNT_DETACH      0x00000002      /* Just detach from the tree */
  26#endif /* MNT_DETACH */
  27
  28/* sys/mount.h may be out too old to have these */
  29#ifndef MS_REC
  30#define MS_REC          16384
  31#endif
  32
  33#ifndef MS_SLAVE
  34#define MS_SLAVE        (1 << 19)
  35#endif
  36
  37#ifndef MS_SHARED
  38#define MS_SHARED       (1 << 20)
  39#endif
  40
  41#ifndef HAVE_SETNS
  42static inline int setns(int fd, int nstype)
  43{
  44#ifdef __NR_setns
  45        return syscall(__NR_setns, fd, nstype);
  46#else
  47        errno = ENOSYS;
  48        return -1;
  49#endif
  50}
  51#endif /* HAVE_SETNS */
  52
  53int netns_switch(char *netns);
  54int netns_get_fd(const char *netns);
  55int netns_foreach(int (*func)(char *nsname, void *arg), void *arg);
  56
  57struct netns_func {
  58        int (*func)(char *nsname, void *arg);
  59        void *arg;
  60};
  61
  62int netns_id_from_name(struct rtnl_handle *rtnl, const char *name);
  63int set_netns_id_from_name(struct rtnl_handle *rtnl, const char *name,
  64                           int nsid);
  65char *netns_name_from_id(int32_t id);
  66
  67#endif /* __NAMESPACE_H__ */
  68