From 4195756e032eb9c9be5ed8ab961ef4d72da7294c Mon Sep 17 00:00:00 2001 From: Masatake YAMATO Date: Fri, 24 Nov 2017 19:31:03 +0900 Subject: lsns: add netnsid column Linux network subsystem assigns an unique integer to a network namespace. term0# ip netns add UTIL-LINUX-LSNS-TEST-NS term0# ip netns list UTIL-LINUX-LSNS-TEST-NS term0# ip link add name lsns-vetha type veth peer name lsns-vethb term0 # ip link set lsns-vethb netns UTIL-LINUX-LSNS-TEST-NS term0# ip netns list UTIL-LINUX-LSNS-TEST-NS (id: 0) term0# ip link show dev lsns-vetha 230: lsns-vetha@if229: mtu 1500 qdisc noop ... link/ether 3e:27:68:ba:b3:95 brd ff:ff:ff:ff:ff:ff link-netnsid 0 In this example 0 is assigned to UTIL-LINUX-LSNS-TEST-NS net namespace. The name, UTIL-LINUX-LSNS-TEST-NS, and it semantics is given and defined by iproute2 in userland; and nothing to do with util-linux. However, the id, 0, is managed in linux kernel. If lsns can show the ids, it helps users understand the state of network namespaces. This commit adds NETNSID column to the output. Here is an example of session: term0# ip netns exec UTIL-LINUX-LSNS-TEST-NS cat (Open another terminal) term1# ./lsns --type net NS TYPE NPROCS PID USER NETNSID COMMAND 4026531993 net 383 1 root unassigned /usr/lib/systemd/... 4026532433 net 1 1219 rtkit unassigned /usr/libexec/rtkit-daemon 4026532562 net 1 18201 root 0 cat 0 is shown as NETNSID for the cat process. For the initial name space, "unassigned" is printed. For the namespaces other type than net, "n/a" is printed. If an error occurred during getting the id, "n/a" is printed. Changes in V2: * Remove wrongly used & operators. * Make netnsid field empty if value for the column is not available. Suggested by Karel Zak. * Remove redundant condtion for checking the avaiablebility of netlink socket. Suggested by Karel Zak. Signed-off-by: Masatake YAMATO --- configure.ac | 1 + 1 file changed, 1 insertion(+) (limited to 'configure.ac') diff --git a/configure.ac b/configure.ac index 28fd7760c..79a1fd3b1 100644 --- a/configure.ac +++ b/configure.ac @@ -234,6 +234,7 @@ AC_CHECK_HEADERS([ \ linux/tiocl.h \ linux/version.h \ linux/securebits.h \ + linux/net_namespace.h \ locale.h \ mntent.h \ net/if.h \ -- cgit v1.2.3-55-g7522