]> git.ipfire.org Git - thirdparty/util-linux.git/blame - tests/ts/lsfd/mkfds-ping
tests: (lsfd) fix typoes in an error name
[thirdparty/util-linux.git] / tests / ts / lsfd / mkfds-ping
CommitLineData
f2713980
MY
1#!/bin/bash
2#
3# Copyright (C) 2023 Masatake YAMATO <yamato@redhat.com>
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#
17TS_TOPDIR="${0%/*}/../.."
18TS_DESC="PING and PINGv6 sockets"
19
20. "$TS_TOPDIR"/functions.sh
21ts_init "$*"
22
23ts_skip_nonroot
24
ca126545
MY
25. "$TS_SELF"/lsfd-functions.bash
26
f2713980
MY
27ts_check_test_command "$TS_CMD_LSFD"
28ts_check_test_command "$TS_HELPER_MKFDS"
ca126545
MY
29ts_check_prog "id"
30
f2713980
MY
31ts_check_native_byteorder
32
33ts_cd "$TS_OUTDIR"
34
35PID=
36FD=3
37EXPR=(
38 '(TYPE == "PING") and (FD == 3)'
39 '(TYPE == "PINGv6") and (FD == 3)'
40)
41FACTORY=(
42 ping
43 ping6
44)
45TYPE=(
46 'PING'
47 'PINGv6'
48)
49COLNS=(
50 INET
51 INET6
52)
53ID=9999
54
ca126545
MY
55range_check()
56{
57 local v=$1
58 local min=$2
59 local max=$3
60
61 [[ $min -le $v && $v -le $max ]]
62 return $?
63}
64
65ping_group_range_check()
66{
67 local g
68 local group_min group_max
69
70 if ! read group_min group_max < /proc/sys/net/ipv4/ping_group_range; then
71 # We can say nothing. Just allow to go ahead.
72 return 0
73 fi
74
75 if [[ -z "$group_min" || -z "$group_max" ]]; then
76 # We can say nothing. Just allow to go ahead.
77 return 0
78 fi
79
80 for g in $(id -G); do
81 if range_check "$g" "$group_min" "$group_max"; then
82 return 0
83 fi
84 done
85
86 return 1
87}
88
89ERRMSG=
f2713980 90for i in 0 1; do
ca126545
MY
91 ERRMSG=$("$TS_HELPER_MKFDS" -c -q "${FACTORY[$i]}" 3 id=$ID 2>&1)
92 ERR="$?"
d2baa1df 93 if [[ "$ERR" == "$EACCES" ]]; then
ca126545
MY
94 case "$ERRMSG" in
95 *bind*)
96 MSG="making ${TYPE[$i]} socket with specifying id is not allowed (blocked by SELinux?)"
97 ;;
98 *socket*)
99 if ! ping_group_range_check; then
100 MSG="the group(s) ($(id -G)) of the process is not in the expected range"
101 MSG+=" [$(cat /proc/sys/net/ipv4/ping_group_range)])"
102 else
103 MSG="$ERRMSG"
104 fi
105 ;;
106 *)
107 MSG="$ERRMSG"
108 ;;
109 esac
110 ts_skip "${MSG}"
111 elif [[ "$ERR" != 0 ]]; then
112 ts_skip "making ${TYPE[$i]} socket is failed ($ERR: $ERRMSG)"
f2713980
MY
113 fi
114done
115
116for i in 0 1; do
117 ts_init_subtest "${FACTORY[$i]}"
118 {
119 coproc MKFDS { "$TS_HELPER_MKFDS" "${FACTORY[$i]}" $FD id=$ID; }
120 if read -r -u "${MKFDS[0]}" PID; then
121 ${TS_CMD_LSFD} -n \
122 -o ASSOC,TYPE,NAME,SOCK.STATE,SOCK.TYPE,${COLNS[$i]}.LADDR,${COLNS[$i]}.RADDR,PING.ID \
123 -p "${PID}" -Q "${EXPR[$i]}"
124 echo "ASSOC,TYPE,NAME,SOCK.STATE,SOCK.TYPE,${COLNS[$i]}.LADDR,${COLNS[$i]}.RADDR,PING.ID": $?
0fec4965 125 echo DONE >&"${MKFDS[1]}"
f2713980
MY
126 fi
127 wait "${MKFDS_PID}"
128
129 coproc MKFDS { "$TS_HELPER_MKFDS" "${FACTORY[$i]}" $FD id=$ID connect=0; }
130 if read -r -u "${MKFDS[0]}" PID; then
131 ${TS_CMD_LSFD} -n \
132 -o ASSOC,TYPE,NAME,SOCK.STATE,SOCK.TYPE,${COLNS[$i]}.LADDR,${COLNS[$i]}.RADDR,PING.ID \
133 -p "${PID}" -Q "${EXPR[$i]}"
134 echo "ASSOC,TYPE,NAME,SOCK.STATE,SOCK.TYPE,${COLNS[$i]}.LADDR,${COLNS[$i]}.RADDR,PING.ID": $?
0fec4965 135 echo DONE >&"${MKFDS[1]}"
f2713980
MY
136 fi
137 } > "$TS_OUTPUT" 2>&1
138 wait "${MKFDS_PID}"
139 ts_finalize_subtest
140done
141
142ts_finalize