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