blob: 51324b21ba0cd5daedcc21249bcd1541fc27dd54 [file] [log] [blame]
Vadim Kochaneb67e442014-12-24 23:04:08 +02001#ifndef __NAMESPACE_H__
2#define __NAMESPACE_H__ 1
3
4#include <sched.h>
5#include <sys/mount.h>
Nicolas Dichtelb765eda2015-04-22 10:27:06 +02006#include <unistd.h>
Nicolas Dichtel1ff6b162015-01-15 11:36:25 +01007#include <sys/syscall.h>
Vadim Kochaneb67e442014-12-24 23:04:08 +02008#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
Nicolas Dichtelffff6932015-01-15 11:36:24 +010035static inline int setns(int fd, int nstype)
Vadim Kochaneb67e442014-12-24 23:04:08 +020036{
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
Stephen Hemminger892e2122015-08-13 14:09:58 -070046int netns_switch(char *netns);
47int netns_get_fd(const char *netns);
48int netns_foreach(int (*func)(char *nsname, void *arg), void *arg);
Vadim Kochane998e112015-01-18 16:10:17 +020049
50struct netns_func {
51 int (*func)(char *nsname, void *arg);
52 void *arg;
53};
Vadim Kochaneb67e442014-12-24 23:04:08 +020054
55#endif /* __NAMESPACE_H__ */