pping: Add script for cleaing up leftover tc programs

In case ePPing is not shut down cleanly (ex. when killed with SIGKILL
or OOM killer) it will not be able to detach its eBPF programs, may
remain attached and waste resources. Add a script which can be used
to clean up any remaining programs tc-eBPF programs.

Note, this script should not be run while the any instace of pping is
still running, as that will remove its tc programs and thus its
ability to function properly.

Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
This commit is contained in:
Simon Sundberg
2023-07-07 20:51:32 +02:00
parent 6582f6713c
commit c6751effb0

View File

@@ -0,0 +1,24 @@
#!/bin/bash
interface=$1
if [[ -z "$interface" ]]; then
echo "Usage: $0 <interface>"
exit 0
fi
if [[ ! -e "/sys/class/net/$interface" ]]; then
echo "$interface is not a valid interface" 1>&2
exit 1
fi
for trafdir in "ingress" "egress"; do
prios=$(tc filter show dev "$interface" "$trafdir" | grep pping_tc | cut -f 5 -d ' ')
while IFS= read -r p || [[ -n "$p" ]]; do
if [[ "$p" =~ ^[0-9]+ ]]; then
tc filter del dev "$interface" "$trafdir" prio "$p"
fi
done <<< "$prios"
done