mirror of
https://github.com/xdp-project/bpf-examples.git
synced 2024-05-06 15:54:53 +00:00
Perform various fixes and tweaks: - Rename several defines to make them more informative - Remove unrolling of loop in BPF programs - Reuse defines for program sections between userspace and kernel space programs - Perform fork+exec to run bpf_egress_loader script instead of system() - Add comment to copied scripts indicating I've modified them - Add pping.h and pping_helpers.h as dependencies in Makefile Also, add a brief description of what PPing is and how it works to README Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
88 lines
1.9 KiB
Bash
Executable File
88 lines
1.9 KiB
Bash
Executable File
#!/bin/bash
|
|
#
|
|
# Author: Jesper Dangaaard Brouer <netoptimizer@brouer.com>
|
|
# License: GPLv2
|
|
#
|
|
# Modified by Simon Sundberg <simon.sundberg@kau.se> to add support
|
|
# of optional section (--sec) option and changed default BPF_OBJ
|
|
#
|
|
basedir=`dirname $0`
|
|
source ${basedir}/functions.sh
|
|
|
|
root_check_run_with_sudo "$@"
|
|
|
|
# Use common parameters
|
|
source ${basedir}/parameters.sh
|
|
|
|
export TC=/sbin/tc
|
|
|
|
# This can be changed via --file or --obj
|
|
if [[ -z ${BPF_OBJ} ]]; then
|
|
# Fallback default
|
|
BPF_OBJ=pping_kern_tc.o
|
|
fi
|
|
|
|
# This can be changed via --sec
|
|
if [[ -z ${SEC} ]]; then
|
|
# Fallback default
|
|
SEC=pping_egress
|
|
fi
|
|
|
|
info "Applying TC-BPF egress setup on device: $DEV with object file: $BPF_OBJ"
|
|
|
|
function tc_remove_clsact()
|
|
{
|
|
local device=${1:-$DEV}
|
|
shift
|
|
|
|
# Removing qdisc clsact, also deletes all filters
|
|
call_tc_allow_fail qdisc del dev "$device" clsact 2> /dev/null
|
|
}
|
|
|
|
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}
|
|
local section=${3:-$SEC}
|
|
shift 3
|
|
|
|
call_tc filter add dev "$device" pref 2 handle 2 \
|
|
egress bpf da obj "$objfile" sec "$section"
|
|
}
|
|
|
|
function tc_egress_list()
|
|
{
|
|
local device=${1:-$DEV}
|
|
|
|
call_tc filter show dev "$device" egress
|
|
}
|
|
|
|
if [[ -n $REMOVE ]]; then
|
|
tc_remove_clsact $DEV
|
|
exit 0
|
|
fi
|
|
|
|
tc_init_clsact $DEV
|
|
tc_egress_bpf_attach $DEV $BPF_OBJ $SEC
|
|
|
|
# Practical to list egress filters after setup.
|
|
# (It's a common mistake to have several progs loaded)
|
|
if [[ -n $LIST ]]; then
|
|
info "Listing egress filter on device"
|
|
tc_egress_list $DEV
|
|
fi
|