From f8546bbbce807fe2536a529e8d9ba01280fcef4b Mon Sep 17 00:00:00 2001 From: Jesper Dangaard Brouer Date: Sun, 8 Nov 2020 12:18:08 +0100 Subject: [PATCH] Add shell script for easier loading TC BPF egress program Signed-off-by: Jesper Dangaard Brouer --- traffic-pacing-edt/bpf_egress_loader.sh | 58 +++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100755 traffic-pacing-edt/bpf_egress_loader.sh diff --git a/traffic-pacing-edt/bpf_egress_loader.sh b/traffic-pacing-edt/bpf_egress_loader.sh new file mode 100755 index 0000000..66740fd --- /dev/null +++ b/traffic-pacing-edt/bpf_egress_loader.sh @@ -0,0 +1,58 @@ +#!/bin/bash +# +# +basedir=`dirname $0` +source ${basedir}/functions.sh + +root_check_run_with_sudo "$@" + +export TC=/sbin/tc +VERBOSE=1 + +DEV=$1 +if [[ -z "$DEV" ]]; then + err 1 "Must specify DEV as argument" +fi + +# TODO: take this as input +BPF_OBJ=edt_pacer01.o + +info "Applying TC-BPF egress setup on device: $DEV with object file: $BPF_OBJ" + +function tc_init_clsact() +{ + local device=${1:-$DEV} + shift + + # TODO: find method that avoids flushing (all users) + + # Also deletes all filters + call_tc_allow_fail qdisc del dev "$device" clsact 2> /dev/null + + # Load qdisc clsact which allow us to attach BPF-progs as TC filters + call_tc qdisc add dev "$device" clsact +} + +function tc_egress_bpf_attach() +{ + local device=${1:-$DEV} + local objfile=${2:-$BPF_OBJ} + shift 2 + + # TODO: Handle selecting program 'sec' + call_tc filter add dev "$device" pref 2 handle 2 \ + egress bpf da obj "$objfile" +} + +function tc_egress_list() +{ + local device=${1:-$DEV} + + call_tc filter show dev "$device" egress +} + +tc_init_clsact $DEV +tc_egress_bpf_attach $DEV $BPF_OBJ + +info "Listing egress filter on device" +tc_egress_list $DEV