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