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