Vadim Kochan | eb67e44 | 2014-12-24 23:04:08 +0200 | [diff] [blame] | 1 | #ifndef __NAMESPACE_H__ |
| 2 | #define __NAMESPACE_H__ 1 |
| 3 | |
| 4 | #include <sched.h> |
| 5 | #include <sys/mount.h> |
Nicolas Dichtel | b765eda | 2015-04-22 10:27:06 +0200 | [diff] [blame] | 6 | #include <unistd.h> |
Nicolas Dichtel | 1ff6b16 | 2015-01-15 11:36:25 +0100 | [diff] [blame] | 7 | #include <sys/syscall.h> |
Vadim Kochan | eb67e44 | 2014-12-24 23:04:08 +0200 | [diff] [blame] | 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 |
Nicolas Dichtel | ffff693 | 2015-01-15 11:36:24 +0100 | [diff] [blame] | 35 | static inline int setns(int fd, int nstype) |
Vadim Kochan | eb67e44 | 2014-12-24 23:04:08 +0200 | [diff] [blame] | 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 | |
Stephen Hemminger | 892e212 | 2015-08-13 14:09:58 -0700 | [diff] [blame] | 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); |
Vadim Kochan | e998e11 | 2015-01-18 16:10:17 +0200 | [diff] [blame] | 49 | |
| 50 | struct netns_func { |
| 51 | int (*func)(char *nsname, void *arg); |
| 52 | void *arg; |
| 53 | }; |
Vadim Kochan | eb67e44 | 2014-12-24 23:04:08 +0200 | [diff] [blame] | 54 | |
| 55 | #endif /* __NAMESPACE_H__ */ |