ip netns: Identify netns for the current process
As 'ip' util will share the same netns from the caller
process then we can just look at /proc/self/.. to show
the netns of the current process by:
ip netns id
Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
This commit is contained in:
parent
18f39a3a02
commit
0948adc01a
22
ip/ipnetns.c
22
ip/ipnetns.c
|
|
@ -59,7 +59,7 @@ static int usage(void)
|
||||||
fprintf(stderr, "Usage: ip netns list\n");
|
fprintf(stderr, "Usage: ip netns list\n");
|
||||||
fprintf(stderr, " ip netns add NAME\n");
|
fprintf(stderr, " ip netns add NAME\n");
|
||||||
fprintf(stderr, " ip netns delete NAME\n");
|
fprintf(stderr, " ip netns delete NAME\n");
|
||||||
fprintf(stderr, " ip netns identify PID\n");
|
fprintf(stderr, " ip netns identify [PID]\n");
|
||||||
fprintf(stderr, " ip netns pids NAME\n");
|
fprintf(stderr, " ip netns pids NAME\n");
|
||||||
fprintf(stderr, " ip netns exec NAME cmd ...\n");
|
fprintf(stderr, " ip netns exec NAME cmd ...\n");
|
||||||
fprintf(stderr, " ip netns monitor\n");
|
fprintf(stderr, " ip netns monitor\n");
|
||||||
|
|
@ -299,19 +299,17 @@ static int netns_identify(int argc, char **argv)
|
||||||
struct dirent *entry;
|
struct dirent *entry;
|
||||||
|
|
||||||
if (argc < 1) {
|
if (argc < 1) {
|
||||||
fprintf(stderr, "No pid specified\n");
|
pidstr = "self";
|
||||||
return -1;
|
} else if (argc > 1) {
|
||||||
}
|
|
||||||
if (argc > 1) {
|
|
||||||
fprintf(stderr, "extra arguments specified\n");
|
fprintf(stderr, "extra arguments specified\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
} else {
|
||||||
pidstr = argv[0];
|
pidstr = argv[0];
|
||||||
|
if (!is_pid(pidstr)) {
|
||||||
if (!is_pid(pidstr)) {
|
fprintf(stderr, "Specified string '%s' is not a pid\n",
|
||||||
fprintf(stderr, "Specified string '%s' is not a pid\n",
|
pidstr);
|
||||||
pidstr);
|
return -1;
|
||||||
return -1;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(net_path, sizeof(net_path), "/proc/%s/ns/net", pidstr);
|
snprintf(net_path, sizeof(net_path), "/proc/%s/ns/net", pidstr);
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ ip-netns \- process network namespace management
|
||||||
|
|
||||||
.ti -8
|
.ti -8
|
||||||
.BR "ip netns identify"
|
.BR "ip netns identify"
|
||||||
.I PID
|
.RI "[ " PID " ]"
|
||||||
|
|
||||||
.ti -8
|
.ti -8
|
||||||
.BR "ip netns pids"
|
.BR "ip netns pids"
|
||||||
|
|
@ -85,10 +85,11 @@ persists until it has no more users. ip netns delete may fail if
|
||||||
the mount point is in use in another mount namespace.
|
the mount point is in use in another mount namespace.
|
||||||
|
|
||||||
.TP
|
.TP
|
||||||
.B ip netns identify PID - Report network namespaces names for process
|
.B ip netns identify [PID] - Report network namespaces names for process
|
||||||
.sp
|
.sp
|
||||||
This command walks through /var/run/netns and finds all the network
|
This command walks through /var/run/netns and finds all the network
|
||||||
namespace names for network namespace of the specified process.
|
namespace names for network namespace of the specified process, if PID is
|
||||||
|
not specified then the current process will be used.
|
||||||
|
|
||||||
.TP
|
.TP
|
||||||
.B ip netns pids NAME - Report processes in the named network namespace
|
.B ip netns pids NAME - Report processes in the named network namespace
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue