2020-06-27 16:56:56 +00:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# Copyright (C) 2020 William Dauchy
|
|
|
|
#
|
|
|
|
# This program 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 program 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.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2020-09-15 19:06:19 +00:00
|
|
|
# we start server in ns1, but listen in ns2, and test client from ns3
|
|
|
|
|
2020-06-27 16:56:56 +00:00
|
|
|
SERV="${SERV:-../src/ocserv}"
|
|
|
|
PIDFILE=ocserv-pid.$$.tmp
|
2020-09-15 19:06:19 +00:00
|
|
|
CLIPID=oc-pid.$$.tmp
|
2020-06-27 16:56:56 +00:00
|
|
|
srcdir=${srcdir:-.}
|
2020-09-15 19:06:19 +00:00
|
|
|
OUTFILE=ss.$$.tmp
|
2020-06-27 16:56:56 +00:00
|
|
|
SS=$(which ss)
|
|
|
|
|
|
|
|
function finish {
|
|
|
|
set +e
|
|
|
|
echo " * Cleaning up..."
|
2020-09-15 19:06:19 +00:00
|
|
|
test -f "${CLIPID}" && kill $(cat ${CLIPID}) >/dev/null 2>&1
|
|
|
|
test -n "${CLIPID}" && rm -f ${CLIPID} >/dev/null 2>&1
|
2020-06-27 16:56:56 +00:00
|
|
|
test -n "${PID}" && kill ${PID} >/dev/null 2>&1
|
|
|
|
test -n "${PIDFILE}" && rm -f ${PIDFILE} >/dev/null 2>&1
|
|
|
|
test -n "${CONFIG}" && rm -f ${CONFIG} >/dev/null 2>&1
|
|
|
|
test -n "${OUTFILE}" && rm -f ${OUTFILE} >/dev/null 2>&1
|
|
|
|
}
|
|
|
|
trap finish EXIT
|
|
|
|
|
2023-12-26 12:26:58 +00:00
|
|
|
. `dirname $0`/random-net.sh
|
|
|
|
. `dirname $0`/random-net2.sh
|
2020-06-27 16:56:56 +00:00
|
|
|
. `dirname $0`/common.sh
|
|
|
|
. `dirname $0`/ns.sh
|
2020-09-15 19:06:19 +00:00
|
|
|
LISTEN_NS=$NSNAME2
|
2020-06-27 16:56:56 +00:00
|
|
|
|
2020-08-09 10:05:51 +00:00
|
|
|
eval "${GETPORT}"
|
|
|
|
|
2020-06-27 16:56:56 +00:00
|
|
|
update_config test-namespace-listen.config
|
|
|
|
if test "$VERBOSE" = 1;then
|
|
|
|
DEBUG="-d 3"
|
|
|
|
fi
|
|
|
|
|
2020-09-15 19:06:19 +00:00
|
|
|
${CMDNS1} ${SERV} -p ${PIDFILE} -f -c ${CONFIG} ${DEBUG} & PID=$!
|
|
|
|
|
|
|
|
sleep 5
|
2020-06-27 16:56:56 +00:00
|
|
|
|
2020-09-15 19:06:19 +00:00
|
|
|
echo "server: check listen tcp"
|
|
|
|
${SS} -N ${LISTEN_NS} -nt -o state listening sport = :${PORT} src ${ADDRESS} > ${OUTFILE}
|
|
|
|
grep -E "0[ ]+[0-9]+[ ]+${ADDRESS}:${PORT}[ ]+.*?:\*" ${OUTFILE}
|
|
|
|
if test $? != 0; then
|
|
|
|
echo "server: check listen tcp failed"
|
|
|
|
cat ${OUTFILE}
|
|
|
|
exit 1
|
|
|
|
fi
|
2020-06-27 16:56:56 +00:00
|
|
|
|
2020-09-15 19:06:19 +00:00
|
|
|
echo "server: check listen udp"
|
|
|
|
${SS} -N ${LISTEN_NS} -nu -o state unconnected sport = :${PORT} src ${ADDRESS} > ${OUTFILE}
|
|
|
|
grep -E "0[ ]+0[ ]+${ADDRESS}:${PORT}[ ]+.*?:\*" ${OUTFILE}
|
|
|
|
if test $? != 0; then
|
|
|
|
echo "server: check listen udp failed"
|
|
|
|
cat ${OUTFILE}
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo " connecting to server"
|
2023-06-02 01:37:46 +00:00
|
|
|
(echo "test" | ${CMDNS3} $OPENCONNECT $ADDRESS:$PORT -u "test" --servercert=pin-sha256:xp3scfzy3rOQsv9NcOve/8YVVv+pHr4qNCXEXrNl5s8= --pid-file=${CLIPID} -b) ||
|
2020-09-15 19:06:19 +00:00
|
|
|
fail $PID "could not connect to server"
|
2020-06-27 16:56:56 +00:00
|
|
|
sleep 5
|
|
|
|
|
2020-09-15 19:06:19 +00:00
|
|
|
echo "server: check estab tcp"
|
|
|
|
${SS} -N ${LISTEN_NS} -nt -o state established sport = :${PORT} src ${ADDRESS} dst ${CLI_ADDRESS2} > ${OUTFILE}
|
|
|
|
grep -E "0[ ]+0[ ]+${ADDRESS}:${PORT}[ ]+${CLI_ADDRESS2}:[0-9]+" ${OUTFILE}
|
|
|
|
if test $? != 0; then
|
|
|
|
echo "server: check estab tcp failed"
|
|
|
|
cat ${OUTFILE}
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "server: check estab udp"
|
|
|
|
${SS} -N ${LISTEN_NS} -nu -o state established sport = :${PORT} src ${ADDRESS} dst ${CLI_ADDRESS2} > ${OUTFILE}
|
|
|
|
grep -E "0[ ]+0[ ]+${ADDRESS}:${PORT}[ ]+${CLI_ADDRESS2}:[0-9]+" ${OUTFILE}
|
|
|
|
if test $? != 0; then
|
|
|
|
echo "server: check estab udp failed"
|
|
|
|
cat ${OUTFILE}
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "client: check estab tcp"
|
|
|
|
${SS} -N ${NSNAME3} -nt -o state established dport = :${PORT} src ${CLI_ADDRESS2} dst ${ADDRESS} > ${OUTFILE}
|
|
|
|
grep -E "0[ ]+0[ ]+${CLI_ADDRESS2}:[0-9]+[ ]+${ADDRESS}:${PORT}" ${OUTFILE}
|
|
|
|
if test $? != 0; then
|
|
|
|
echo "client: check estab tcp failed"
|
|
|
|
cat ${OUTFILE}
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "client: check estab udp"
|
|
|
|
${SS} -N ${NSNAME3} -nu -o state established dport = :${PORT} src ${CLI_ADDRESS2} dst ${ADDRESS} > ${OUTFILE}
|
|
|
|
grep -E "0[ ]+0[ ]+${CLI_ADDRESS2}:[0-9]+[ ]+${ADDRESS}:${PORT}" ${OUTFILE}
|
2020-06-27 16:56:56 +00:00
|
|
|
if test $? != 0; then
|
2020-09-15 19:06:19 +00:00
|
|
|
echo "client: check estab udp failed"
|
|
|
|
cat ${OUTFILE}
|
2020-06-27 16:56:56 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2020-09-15 19:06:19 +00:00
|
|
|
kill $(cat ${CLIPID})
|
|
|
|
kill ${PID}
|
2020-06-27 16:56:56 +00:00
|
|
|
wait
|
|
|
|
|
|
|
|
exit 0
|