1#!/bin/bash 2# SPDX-License-Identifier: BSD-3-Clause 3 4# check required parameters 5SGW_REQ_VARS="SGW_PATH SGW_PORT_CFG SGW_WAIT_DEV" 6for reqvar in ${SGW_REQ_VARS} 7do 8 if [[ -z "${!reqvar}" ]]; then 9 echo "Required parameter ${reqvar} is empty" 10 exit 127 11 fi 12done 13 14# check if SGW_PATH point to an executable 15if [[ ! -x ${SGW_PATH} ]]; then 16 echo "${SGW_PATH} is not executable" 17 exit 127 18fi 19 20# setup SGW_LCORE 21SGW_LCORE=${SGW_LCORE:-0} 22 23# setup config and output filenames 24SGW_OUT_FILE=./ipsec-secgw.out1 25SGW_CFG_FILE=$(mktemp) 26 27# setup secgw parameters 28SGW_CMD_EAL_PRM="--lcores=${SGW_LCORE} -n 4" 29SGW_CMD_CFG="(0,0,${SGW_LCORE}),(1,0,${SGW_LCORE})" 30SGW_CMD_PRM="-p 0x3 -u 1 -P --config=\"${SGW_CMD_CFG}\"" 31 32# start ipsec-secgw 33secgw_start() 34{ 35 SGW_EXEC_FILE=$(mktemp) 36 cat <<EOF > ${SGW_EXEC_FILE} 37stdbuf -o0 ${SGW_PATH} ${SGW_CMD_EAL_PRM} ${CRYPTO_DEV} \ 38${SGW_PORT_CFG} ${SGW_EAL_XPRM} \ 39-- ${SGW_CMD_PRM} ${SGW_CMD_XPRM} -f ${SGW_CFG_FILE} > \ 40${SGW_OUT_FILE} 2>&1 & 41p=\$! 42echo \$p 43EOF 44 45 cat ${SGW_EXEC_FILE} 46 cat ${SGW_CFG_FILE} 47 SGW_PID=`/bin/bash -x ${SGW_EXEC_FILE}` 48 49 # wait till ipsec-secgw start properly 50 i=0 51 st=1 52 while [[ $i -ne 10 && $st -ne 0 ]]; do 53 sleep 1 54 ifconfig ${SGW_WAIT_DEV} 55 st=$? 56 let i++ 57 done 58} 59 60# stop ipsec-secgw and cleanup 61secgw_stop() 62{ 63 kill ${SGW_PID} 64 rm -f ${SGW_EXEC_FILE} 65 rm -f ${SGW_CFG_FILE} 66} 67