summaryrefslogtreecommitdiffstats
path: root/tests/ts/lsns/netnsid
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 19:10:49 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 19:10:49 +0000
commitcfe5e3905201349e9cf3f95d52ff4bd100bde37d (patch)
treed0baf160cbee3195249d095f85e52d20c21acf02 /tests/ts/lsns/netnsid
parentInitial commit. (diff)
downloadutil-linux-cfe5e3905201349e9cf3f95d52ff4bd100bde37d.tar.xz
util-linux-cfe5e3905201349e9cf3f95d52ff4bd100bde37d.zip
Adding upstream version 2.39.3.upstream/2.39.3
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ts/lsns/netnsid')
-rwxr-xr-xtests/ts/lsns/netnsid97
1 files changed, 97 insertions, 0 deletions
diff --git a/tests/ts/lsns/netnsid b/tests/ts/lsns/netnsid
new file mode 100755
index 0000000..80ccd9b
--- /dev/null
+++ b/tests/ts/lsns/netnsid
@@ -0,0 +1,97 @@
+#!/bin/bash
+#
+# Copyright (C) 2017 Masatake YAMATO <yamato@redhat.com>
+#
+# This file is part of util-linux.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This file is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+
+TS_TOPDIR="${0%/*}/../.."
+TS_DESC="NETNSID compare to ip-link"
+
+. "$TS_TOPDIR"/functions.sh
+ts_init "$*"
+
+ts_check_test_command "$TS_CMD_LSNS"
+ts_check_prog "ip"
+ts_check_prog "dd"
+ts_check_prog "mkfifo"
+ts_check_prog "sed"
+ts_skip_nonroot
+
+grep -q '#define HAVE_LINUX_NET_NAMESPACE_H' ${top_builddir}/config.h || ts_skip "no netns support"
+ts_cd "$TS_OUTDIR"
+
+vetha=lsns-vetha
+vethb=lsns-vethb
+NS=LSNS-TEST-NETNSID-NS
+FIFO=$TS_OUTDIR/FIFO-NETNSID
+NULL=/dev/null
+LOG=/dev/null #/root/foo.log
+
+function cleanup {
+ ip link delete $vetha 2> $NULL || :
+ ip netns delete $NS 2> $NULL || :
+ rm -f $FIFO
+}
+
+echo "==Cleanup" >> $LOG
+cleanup
+
+echo "==Create FIFO" >> $LOG
+mkfifo $FIFO
+
+echo "==Netns ADD" >> $LOG
+if ip netns add $NS &&
+ ip link add name $vetha type veth peer name $vethb &&
+ ip link set $vethb netns $NS &&
+ ! (ip -o link show dev $vetha 2>&1 >$NULL | grep 'Cannot talk to rtnetlink' > $NULL); then
+ echo "===Netns EXEC" >> $LOG
+ ip netns exec $NS dd if=$FIFO bs=1 count=2 of=$NULL 2> $NULL &
+ PID=$!
+ echo "====PID=$PID" >> $LOG
+else
+ cleanup
+ ts_skip "failed to initialize"
+fi
+{
+ echo "==Write to FIFO" >> $LOG
+ dd if=/dev/zero bs=1 count=1 2> $NULL
+ {
+ echo "===IP output" >> $LOG
+ ip -o link show dev $vetha >> $LOG
+
+ IP_ID=$(ip -o link show dev $vetha | sed -ne 's/.* *link-netnsid *\([0-9]*\)/\1/p')
+ echo "====ip show: IP_ID=$IP_ID" >> $LOG
+
+ if [ "x$IP_ID" = "x" ]; then
+ echo "===IP output list id" >> $LOG
+ ip netns list-id >> $LOG
+
+ IP_ID=$(ip netns list-id | awk "/name: $NS/ { print \$2 }")
+ echo "====ip list-id: IP_ID=$IP_ID" >> $LOG
+ fi
+
+ echo "===LSNS output" >> $LOG
+ $TS_CMD_LSNS -o+NETNSID,NSFS --type net >> $LOG
+
+ LSNS_ID=$($TS_CMD_LSNS -n -o NETNSID --type net --task $PID | { read VAL; echo $VAL; } )
+ echo "===LSNS_ID=$LSNS_ID" >> $LOG
+ }
+ dd if=/dev/zero bs=1 count=1 2> $NULL
+} > $FIFO
+
+test "$IP_ID" = "$LSNS_ID"
+echo $? >> $TS_OUTPUT
+
+cleanup
+ts_finalize