]> git.ipfire.org Git - thirdparty/util-linux.git/commit
lsns: add netnsid column
authorMasatake YAMATO <yamato@redhat.com>
Fri, 24 Nov 2017 10:31:03 +0000 (19:31 +0900)
committerKarel Zak <kzak@redhat.com>
Mon, 27 Nov 2017 14:54:49 +0000 (15:54 +0100)
commit4195756e032eb9c9be5ed8ab961ef4d72da7294c
treed4315d108ee9594858ef74c60c64a63d78a097c0
parente72027dadad83567dbc3c3e31e2f77005a3e0d78
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: <BROADCAST,MULTICAST> 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 <yamato@redhat.com>
configure.ac
sys-utils/lsns.c