| 1 |
#!/bin/bash |
| 2 |
# |
| 3 |
# Copyright (C) 2026 Masatake YAMATO <[email protected]> |
| 4 |
# |
| 5 |
# This file is part of util-linux. |
| 6 |
# |
| 7 |
# This file is free software; you can redistribute it and/or modify |
| 8 |
# it under the terms of the GNU General Public License as published by |
| 9 |
# the Free Software Foundation; either version 2 of the License, or |
| 10 |
# (at your option) any later version. |
| 11 |
# |
| 12 |
# This file is distributed in the hope that it will be useful, |
| 13 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
# GNU General Public License for more details. |
| 16 |
# |
| 17 |
TS_TOPDIR="${0%/*}/../.." |
| 18 |
TS_DESC="SOCK.NETNS of an unbound tcp socket" |
| 19 |
|
| 20 |
. "$TS_TOPDIR"/functions.sh |
| 21 |
ts_init "$*" |
| 22 |
|
| 23 |
ts_skip_nonroot |
| 24 |
ts_skip_docker |
| 25 |
|
| 26 |
. "$TS_SELF/lsfd-functions.bash" |
| 27 |
ts_check_test_command "$TS_CMD_LSFD" |
| 28 |
ts_check_test_command "$TS_HELPER_MKFDS" |
| 29 |
|
| 30 |
ts_cd "$TS_OUTDIR" |
| 31 |
|
| 32 |
PID= |
| 33 |
INODE= |
| 34 |
SOCK_NETNS= |
| 35 |
FD=5 |
| 36 |
|
| 37 |
"$TS_HELPER_MKFDS" --quiet --dont-pause netns "$FD" |
| 38 |
SIOCGSKNS=$? |
| 39 |
if [[ "$SIOCGSKNS" == "$TS_EXIT_NOTSUPP" ]]; then |
| 40 |
ts_skip "ioctl(fd, SIOCGSKNS) is not available" |
| 41 |
elif [[ "$SIOCGSKNS" == "$EPERM" ]]; then |
| 42 |
ts_skip "ioctl(fd, SIOCGSKNS) is not usable" |
| 43 |
else |
| 44 |
echo "ioctl(fd, SIOCGSKNS): $SIOCGSKNS" > "$TS_OUTPUT" |
| 45 |
fi |
| 46 |
|
| 47 |
{ |
| 48 |
coproc MKFDS { "$TS_HELPER_MKFDS" tcp-bare $FD; } |
| 49 |
if read -r -u "${MKFDS[0]}" PID; then |
| 50 |
INODE=$(${TS_CMD_LSFD} -n --raw -o INODE -p "${PID}" -Q "ASSOC == 'net'") |
| 51 |
echo INODE: $? |
| 52 |
SOCK_NETNS=$(${TS_CMD_LSFD} -n --raw -o SOCK.NETNS -p "${PID}" -Q "FD == $FD") |
| 53 |
echo SOCK_NETNS: $? |
| 54 |
if [[ -z "$SOCK_NETNS" ]]; then |
| 55 |
echo "SOCK_NETNS: failed (empty, inode: $INODE)" |
| 56 |
elif [[ "$SOCK_NETNS" == "$INODE" ]]; then |
| 57 |
echo "SOCK_NETNS: OK" |
| 58 |
else |
| 59 |
echo "SOCK_NETNS: failed (inode: $INODE, sock_netns: $SOCK_NETNS)" |
| 60 |
fi |
| 61 |
echo DONE >&"${MKFDS[1]}" |
| 62 |
fi |
| 63 |
wait "${MKFDS_PID}" |
| 64 |
} >> "$TS_OUTPUT" 2>&1 |
| 65 |
|
| 66 |
ts_finalize |