From ee9c78d129d0b6cf05cc75c74203d5686e87712f Mon Sep 17 00:00:00 2001 From: Alexey Khromov Date: Thu, 17 Apr 2025 21:40:34 +0300 Subject: [PATCH] Added full-duplex all-protocol tests through socat, fixed makefile.in for manual inst --- source/Makefile.in | 2 +- tests/configs/bforceA.conf | 3 +- tests/configs/bforceB.conf | 3 +- tests/configs/genpkt.sh | 0 tests/mktests.sh | 157 ++++++++++++++++++++++++++----------- tests/runbfA.sh | 3 + tests/runbfB.sh | 2 + tests/runbfC.sh | 2 + tests/runbfD.sh | 2 + tests/runbfE.sh | 2 + tests/runbfF.sh | 2 + 11 files changed, 131 insertions(+), 47 deletions(-) mode change 100755 => 100644 tests/configs/genpkt.sh create mode 100755 tests/runbfA.sh create mode 100755 tests/runbfB.sh create mode 100755 tests/runbfC.sh create mode 100755 tests/runbfD.sh create mode 100755 tests/runbfE.sh create mode 100755 tests/runbfF.sh diff --git a/source/Makefile.in b/source/Makefile.in index 742b2b4..807a8ec 100644 --- a/source/Makefile.in +++ b/source/Makefile.in @@ -28,7 +28,7 @@ CONFDIR = @sysconfdir@ BINDIR = @bindir@ LOGDIR = @LOGDIR@ SPOOLDIR = @SPOOLDIR@ -MANDIR = @MANDIR@ +MANDIR = /usr/share/man/man1 DAEMON_LOGFILE = $(LOGDIR)/bf-daemon BFORCE_LOGFILE = $(LOGDIR)/bf-log diff --git a/tests/configs/bforceA.conf b/tests/configs/bforceA.conf index bef2bd6..ae87de2 100644 --- a/tests/configs/bforceA.conf +++ b/tests/configs/bforceA.conf @@ -6,7 +6,7 @@ proto_order %PROTO% #domain schoolnet /var/spool/ftn/schoolnet/ 461 log_file %TESTZONE%/logsA/bf-log debug_file %TESTZONE%/logsA/bf-debug -debug_level modem hshake event freq +debug_level info modem hshake event prot override nodial_flag %TESTZONE%/etc/nodial inbound_directory (Protected) %TESTZONE%/inboundA inbound_directory %TESTZONE%/inbound-unsecureA @@ -19,6 +19,7 @@ status_directory %TESTZONE%/logsA history_file %TESTZONE%/logsA/history password 99:1/2 testpwd1 +override 99:1/2 flags INA:localhost,IFC:59999,IBN:59999 #min_speed_in 1200 #min_speed_out 1200 #session_limit_in 1800 diff --git a/tests/configs/bforceB.conf b/tests/configs/bforceB.conf index 01dbb4a..6f6adc0 100644 --- a/tests/configs/bforceB.conf +++ b/tests/configs/bforceB.conf @@ -6,7 +6,7 @@ proto_order %PROTO% #domain schoolnet /var/spool/ftn/schoolnet/ 461 log_file %TESTZONE%/logsB/bf-log debug_file %TESTZONE%/logsB/bf-debug -debug_level modem hshake event freq +debug_level info modem hshake event prot override nodial_flag %TESTZONE%/etc/nodial inbound_directory (Protected) %TESTZONE%/inboundB inbound_directory %TESTZONE%/inbound-unsecureB @@ -19,6 +19,7 @@ status_directory %TESTZONE%/logsB history_file %TESTZONE%/logsB/history password 99:1/1 testpwd1 +override 99:1/1 flags INA:localhost,IFC:59999,IBN:59999 #min_speed_in 1200 #min_speed_out 1200 #session_limit_in 1800 diff --git a/tests/configs/genpkt.sh b/tests/configs/genpkt.sh old mode 100755 new mode 100644 diff --git a/tests/mktests.sh b/tests/mktests.sh index 5566609..d2fa9c7 100755 --- a/tests/mktests.sh +++ b/tests/mktests.sh @@ -1,52 +1,93 @@ #!/bin/bash # Making tests of BForce -CURDIR=$(pwd) -BFBIN=$(pwd)/../source/bin/bforce +CURDIR="${CURDIR:-$(pwd)}" +BFBIN=${BFBIN:-$(pwd)/../source/bin/bforce} +SOCATCMD=${SOCATCMD:-$(which socat)} function prepconfig() { echo "Preparing configs with $1 as protocol..." - cp ${CURDIR}/configs/bforceA.conf ${CURDIR}/etc/bforceA.conf - sed -i -e "s/%PROTO%/$1/" ${CURDIR}/etc/bforceA.conf - sed -i -e "s#%TESTZONE%#${CURDIR}#" ${CURDIR}/etc/bforceA.conf + if [[ ! -d "${CURDIR}/ftntest" ]] ; + then + echo -n "(o_O) " + else + echo "Dir exists!" + rm -rf ${CURDIR}/ftntest/{etc,inboundA,inboundB,inbound-unsecureA,inbound-unsecureB,logsA,logsB,outboundA,outboundB} + fi - cp ${CURDIR}/configs/bforceB.conf ${CURDIR}/etc/bforceB.conf - sed -i -e "s/%PROTO%/$1/" ${CURDIR}/etc/bforceB.conf - sed -i -e "s#%TESTZONE%#${CURDIR}#" ${CURDIR}/etc/bforceB.conf + mkdir -p "${CURDIR}"/ftntest/{etc,inbound-unsecureA,inbound-unsecureB,inboundA,inboundB,logsA,logsB,outboundA,outboundB} + + cp -f ${CURDIR}/configs/bforceA.conf ${CURDIR}/ftntest/etc/bforceA.conf + sed -i -e "s/%PROTO%/$1/" ${CURDIR}/ftntest/etc/bforceA.conf + sed -i -e "s#%TESTZONE%#${CURDIR}/ftntest#" ${CURDIR}/ftntest/etc/bforceA.conf - cp ${CURDIR}/configs/00010002.cut ${CURDIR}/outboundA/00010002.cut - cp ${CURDIR}/configs/00010001.cut ${CURDIR}/outboundB/00010001.cut + cp -f ${CURDIR}/configs/bforceB.conf ${CURDIR}/ftntest/etc/bforceB.conf + sed -i -e "s/%PROTO%/$1/" ${CURDIR}/ftntest/etc/bforceB.conf + sed -i -e "s#%TESTZONE%#${CURDIR}/ftntest#" ${CURDIR}/ftntest/etc/bforceB.conf + + cp -f ${CURDIR}/configs/00010002.cut ${CURDIR}/ftntest/outboundA/00010002.cut + cp -f ${CURDIR}/configs/00010001.cut ${CURDIR}/ftntest/outboundB/00010001.cut } function testcomm() { - rm -rf ${CURDIR}/inboundA/* - rm -rf ${CURDIR}/inboundB/* + rm -rf ${CURDIR}/ftntest/inboundA/* + rm -rf ${CURDIR}/ftntest/inboundB/* + echo " over ${1}" + # for V1 and V2 + #mkfifo ${CURDIR}/bforceAtoB + #mkfifo ${CURDIR}/bforceBtoA - mkfifo ${CURDIR}/bforceAtoB - mkfifo ${CURDIR}/bforceBtoA - - BFCFGA=${CURDIR}/etc/bforceA.conf - BFCFGB=${CURDIR}/etc/bforceB.conf + BFCFGA=${CURDIR}/ftntest/etc/bforceA.conf + BFCFGB=${CURDIR}/ftntest/etc/bforceB.conf # Works for Linux - - BFCONFIG=${BFCFGA} - BFCONFIG=${BFCFGA} ${BFBIN} -o 99:1/2 > ${CURDIR}/bforceAtoB < ${CURDIR}/bforceBtoA & + # Variant 1 + #BFCONFIG=${BFCFGA} + #BFCONFIG=${BFCFGA} ${BFBIN} -o 99:1/2 > ${CURDIR}/bforceAtoB < ${CURDIR}/bforceBtoA & # - BFCONFIG=${BFCFGB} - BFCONFIG=${BFCFGB} ${BFBIN} -S"CONNECT 9600" auto < ${CURDIR}/bforceAtoB > ${CURDIR}/bforceBtoA + #BFCONFIG=${BFCFGB} + #BFCONFIG=${BFCFGB} ${BFBIN} -S"CONNECT 9600" auto < ${CURDIR}/bforceAtoB > ${CURDIR}/bforceBtoA + # Variant 2 + #${CURDIR}/runbfA.sh ${BFBIN} ${BFCFGA} > ${CURDIR}/bforceAtoB < ${CURDIR}/bforceBtoA & + #${CURDIR}/runbfB.sh ${BFBIN} ${BFCFGB} < ${CURDIR}/bforceAtoB > ${CURDIR}/bforceBtoA + + # Variant 3 works with sockets and pipes - not pty + case ${1} in + "PSTN") + socat -ly -Wlock EXEC:"${CURDIR}/runbfB.sh ${BFBIN} ${BFCFGB}" EXEC:"${CURDIR}/runbfA.sh ${BFBIN} ${BFCFGA}" + sleep 2 + ;; + "IFC") + ${CURDIR}/runbfC.sh ${BFBIN} ${BFCFGA} & + socat -ly -Wlock TCP4-LISTEN:59999 EXEC:"${CURDIR}/runbfD.sh ${BFBIN} ${BFCFGB}" + sleep 2 + ;; + "BKP") + ${CURDIR}/runbfE.sh ${BFBIN} ${BFCFGA} & + socat -ly -Wlock TCP4-LISTEN:59999 EXEC:"${CURDIR}/runbfF.sh ${BFBIN} ${BFCFGB}" + sleep 2 + ;; + esac # For [Free]BSD it need to be replaced - pipes are bidirectional: + # ./ping <&1 | ./pong >&0 - rm ${CURDIR}/{bforceAtoB,bforceBtoA} + # for V1 and V2 + #rm ${CURDIR}/{bforceAtoB,bforceBtoA} ## WE MUST CHECK THAT INBOUND ARE FULL!!! ## - FCNTA=$( find ${CURDIR}/inboundA -name *.pkt | wc -l ) - FCNTB=$( find ${CURDIR}/inboundB -name *.pkt | wc -l ) - DIFFA=$( diff ${CURDIR}/inboundA/*.pkt ${CURDIR}/configs/00010001.cut && echo $? ) - DIFFB=$( diff ${CURDIR}/inboundB/*.pkt ${CURDIR}/configs/00010002.cut && echo $? ) + FCNTA=$( find ${CURDIR}/ftntest/inboundA -name *.pkt | wc -l ) + FCNTB=$( find ${CURDIR}/ftntest/inboundB -name *.pkt | wc -l ) + if [[ "${FCNTA}" -eq "1" ]] + then + DIFFA=$( diff ${CURDIR}/ftntest/inboundA/*.pkt ${CURDIR}/configs/00010001.cut && echo $? ) + fi + if [[ "${FCNTB}" -eq "1" ]] + then + DIFFB=$( diff ${CURDIR}/ftntest/inboundB/*.pkt ${CURDIR}/configs/00010002.cut && echo $? ) + fi if [[ "${DIFFA}" -eq "0" ]] && [[ "${FCNTA}" -eq "1" ]] then @@ -55,48 +96,76 @@ function testcomm() { echo "....Result: OK" else echo "....Failed DiffB" + RES=2 fi else echo "....Failed DiffA" + RES=1 fi - cat ${CURDIR}/logsA/bf-debug >> ${CURDIR}/debugA.log - cat ${CURDIR}/logsB/bf-debug >> ${CURDIR}/debugB.log + if [[ -f ${CURDIR}/ftntest/logsA/bf-debug ]] + then + cat ${CURDIR}/ftntest/logsA/bf-debug >> ${CURDIR}/debugA.log + fi + if [[ -f ${CURDIR}/ftntest/logsB/bf-debug ]] + then + cat ${CURDIR}/ftntest/logsB/bf-debug >> ${CURDIR}/debugB.log + fi + + rm -rf ${CURDIR}/ftntest } -if [[ ! -d "${CURDIR}/inboundA" ]] -then - echo "All clear to begin" -else - echo "Dir exists!" - rm -rf {etc,inboundA,inboundB,inbound-unsecureA,inbound-unsecureB,logsA,logsB,outboundA,outboundB} -fi -mkdir -p "${CURDIR}"/{etc,inbound-unsecureA,inbound-unsecureB,inboundA,inboundB,logsA,logsB,outboundA,outboundB} if [[ ! -f "${BFBIN}" ]] then # No executable to test! echo "No executable to run! Aborting..." + exit -1 else + + if [[ ! -f "${SOCATCMD}" ]] + then + # No socat + echo "No socat cmd! Aborting..." + exit -1 + fi # All doing here - echo "Bforce executable found" + echo "Bforce executable found: ${BFBIN}" + RES=0 prepconfig "ZMO" echo -n "--> Running ZMO test..." - testcomm + testcomm "PSTN" prepconfig "ZAP" echo -n "--> Running ZAP test..." - testcomm + testcomm "PSTN" prepconfig "HYD" echo -n "--> Running Hydra test..." - testcomm + testcomm "PSTN" + + prepconfig "ZMO" + echo -n "--> Running ZMO test..." + testcomm "IFC" + + prepconfig "ZAP" + echo -n "--> Running ZAP test..." + testcomm "IFC" + + prepconfig "HYD" + echo -n "--> Running HYD test..." + testcomm "IFC" + + prepconfig "ZMO" + echo -n "--> Running BINKP test..." + testcomm "BKP" # TODO: make binkd test over netcat possibly fi - - -rm -rf {etc,inboundA,inboundB,inbound-unsecureA,inbound-unsecureB,logsA,logsB,outboundA,outboundB} +# rm -rf ${CURDIR}/ftntest/{etc,inboundA,inboundB,inbound-unsecureA,inbound-unsecureB,logsA,logsB,outboundA,outboundB} +rm -rf ${CURDIR}/ftntest +# printf $RES +exit ${RES} \ No newline at end of file diff --git a/tests/runbfA.sh b/tests/runbfA.sh new file mode 100755 index 0000000..f8de41d --- /dev/null +++ b/tests/runbfA.sh @@ -0,0 +1,3 @@ +#!/bin/bash +BFCONFIG=${2} ${1} -C ${2} -o 99:1/2 + diff --git a/tests/runbfB.sh b/tests/runbfB.sh new file mode 100755 index 0000000..ae0b18f --- /dev/null +++ b/tests/runbfB.sh @@ -0,0 +1,2 @@ +#!/bin/bash +BFCONFIG=${2} ${1} -C ${2} -S"CONNECT 9600" -i auto diff --git a/tests/runbfC.sh b/tests/runbfC.sh new file mode 100755 index 0000000..d672239 --- /dev/null +++ b/tests/runbfC.sh @@ -0,0 +1,2 @@ +#!/bin/bash +BFCONFIG=${2} ${1} -C ${2} -a 127.0.0.1:59999 -u ifcico 99:1/2 \ No newline at end of file diff --git a/tests/runbfD.sh b/tests/runbfD.sh new file mode 100755 index 0000000..c2700d4 --- /dev/null +++ b/tests/runbfD.sh @@ -0,0 +1,2 @@ +#!/bin/bash +BFCONFIG=${2} ${1} -C ${2} -S"" -i auto diff --git a/tests/runbfE.sh b/tests/runbfE.sh new file mode 100755 index 0000000..a28c9ce --- /dev/null +++ b/tests/runbfE.sh @@ -0,0 +1,2 @@ +#!/bin/bash +BFCONFIG=${2} ${1} -C ${2} -a 127.0.0.1:59999 -u binkp 99:1/2 \ No newline at end of file diff --git a/tests/runbfF.sh b/tests/runbfF.sh new file mode 100755 index 0000000..ba012be --- /dev/null +++ b/tests/runbfF.sh @@ -0,0 +1,2 @@ +#!/bin/bash +BFCONFIG=${2} ${1} -C ${2} -i binkp