Skip to content

Commit

Permalink
docker|ci: N_ATTEMPTS, RETRY_DELAY, IFACES params
Browse files Browse the repository at this point in the history
Expose the following ENV variables as optional params tot the
container:

* `N_ATTEMPTS`: number of attempts on loading the BPF program on an
                interface. Default 6.
* `RETRY_DELAY`: delay between attemps. Default: 3
* `IFACES`: interfaces to load the BPF program. Default: "" (all).
  • Loading branch information
msune committed Aug 27, 2024
1 parent c4ac94b commit 8ebd85f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,18 @@ jobs:
grep "Compiling sfunnel with custom ruleset" output || (echo "ERROR: unable to validate it loads custom ruleset via SFUNNEL_RULESET" && exit 1)
grep "$RULE" output || (echo "ERROR: unable to validate it loads custom ruleset via SFUNNEL_RULESET" && exit 1)
- name: "[TEST] Run container with custom params ..."
run: |
set -o pipefail
docker run -e N_ATTEMPTS=7 -e RETRY_DELAY=3 -e IFACES="lo" --privileged sfunnel:latest 2>&1 | tee output
if [ ${PIPESTATUS[0]} -ne 0 ]; then
echo "ERROR: container execution FAILED!"
exit 1
fi
grep "\$N_ATTEMPTS='7'" output || (echo "ERROR: unable to validate it loads params (N_ATTEMPTS)" && exit 1)
grep "\$RETRY_DELAY='3'" output || (echo "ERROR: unable to validate it loads params (RETRY_DELAY)" && exit 1)
grep "\$IFACES='lo'" output || (echo "ERROR: unable to validate it loads params (IFACES)" && exit 1)
- name: "Push to ghcr"
run: |
if [[ "${EXACT_TAG}" != "" ]]; then
Expand Down
23 changes: 19 additions & 4 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@
set -e
#set -x

N_ATTEMPTS=5
RETRY_DELAY=5
#Env variables
N_ATTEMPTS=${N_ATTEMPTS:-6}
RETRY_DELAY=${RETRY_DELAY:-3}

_IFACES=$(ls /sys/class/net | tr "\n" " " | sed 's/\s*$//g')
IFACES=${IFACES:-$_IFACES}

PROG=/opt/sfunnel/src/tc_sfunnel.o

#Compile eBPF program only if rulesset are defined at load time
Expand All @@ -21,7 +26,18 @@ load_prog(){
tc filter add dev $2 ingress bpf da obj $1 sec funnel verbose
}

###
# Splash and useful info
echo "[INFO] sfunnel "
echo "[INFO] ENVs:"
echo " \$N_ATTEMPTS='$N_ATTEMPTS'"
echo " \$RETRY_DELAY='$RETRY_DELAY'"
echo " \$IFACES='$IFACES'"
echo "[INFO] Container info:"
echo " Kernel: $(uname -a)"
echo " Debian: $(cat /etc/debian_version)"
echo " python3: $(python3 --version)"
echo " clang: $(clang --version)"
echo " iproute2: $(ip -V)"

#If SFUNNEL_RULESET is defined, create the file
if [[ "$SFUNNEL_RULESET" != "" ]]; then
Expand All @@ -44,7 +60,6 @@ else
fi

#Load
IFACES=$(ls /sys/class/net | tr "\n" " " | sed 's/\s*$//g')

echo ""
echo -e "[INFO] Attaching BPF program '$PROG' to IFACES={$IFACES} using clsact qdisc...\n"
Expand Down

0 comments on commit 8ebd85f

Please sign in to comment.