mirror of
				https://github.com/xdp-project/bpf-examples.git
				synced 2024-05-06 15:54:53 +00:00 
			
		
		
		
	Split and rename files so there is one userspace program (pping) and two kernel-space ones (one for XDP and one for TC-BPF). Copy the shell script for loading the TC-BPF program from traffic-pacing-edt folder, but add support for loading a specific section. The XDP and TC-BPF programs do not share the ts_start map, so program does not work. Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
		
			
				
	
	
		
			65 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Bash
		
	
	
	
	
	
			
		
		
	
	
			65 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Bash
		
	
	
	
	
	
| #
 | |
| # Common functions used by scripts in this directory
 | |
| #  - Depending on bash 3 (or higher) syntax
 | |
| #
 | |
| # Author: Jesper Dangaaard Brouer <netoptimizer@brouer.com>
 | |
| # License: GPLv2
 | |
| 
 | |
| ## -- sudo trick --
 | |
| function root_check_run_with_sudo() {
 | |
|     # Trick so, program can be run as normal user, will just use "sudo"
 | |
|     #  call as root_check_run_as_sudo "$@"
 | |
|     if [ "$EUID" -ne 0 ]; then
 | |
| 	if [ -x $0 ]; then # Directly executable use sudo
 | |
| 	    echo "# (Not root, running with sudo)" >&2
 | |
|             sudo "$0" "$@"
 | |
|             exit $?
 | |
| 	fi
 | |
| 	echo "cannot perform sudo run of $0"
 | |
| 	exit 1
 | |
|     fi
 | |
| }
 | |
| 
 | |
| ## -- General shell logging cmds --
 | |
| function err() {
 | |
|     local exitcode=$1
 | |
|     shift
 | |
|     echo -e "ERROR: $@" >&2
 | |
|     exit $exitcode
 | |
| }
 | |
| 
 | |
| function warn() {
 | |
|     echo -e "WARN : $@" >&2
 | |
| }
 | |
| 
 | |
| function info() {
 | |
|     if [[ -n "$VERBOSE" ]]; then
 | |
| 	echo "# $@"
 | |
|     fi
 | |
| }
 | |
| 
 | |
| ## -- Wrapper calls for TC --
 | |
| function _call_tc() {
 | |
|     local allow_fail="$1"
 | |
|     shift
 | |
|     if [[ -n "$VERBOSE" ]]; then
 | |
| 	echo "tc $@"
 | |
|     fi
 | |
|     if [[ -n "$DRYRUN" ]]; then
 | |
| 	return
 | |
|     fi
 | |
|     $TC "$@"
 | |
|     local status=$?
 | |
|     if (( $status != 0 )); then
 | |
| 	if [[ "$allow_fail" == "" ]]; then
 | |
| 	    err 3 "Exec error($status) occurred cmd: \"$TC $@\""
 | |
| 	fi
 | |
|     fi
 | |
| }
 | |
| function call_tc() {
 | |
|     _call_tc "" "$@"
 | |
| }
 | |
| function call_tc_allow_fail() {
 | |
|     _call_tc "allow_fail" "$@"
 | |
| }
 |