Skip to content

Commit

Permalink
samples: pktgen: fix append mode failed issue
Browse files Browse the repository at this point in the history
Each sample script sources functions.sh before parameters.sh
which makes $APPEND undefined when trapping EXIT no matter in
append mode or not. Due to this when sample scripts finished
they always do "pgctrl reset" which resets pktgen config.

So move trap to each script after sourcing parameters.sh
and trap EXIT explicitly.

Signed-off-by: J.J. Martzki <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
Martzki authored and davem330 committed Jul 3, 2023
1 parent f56d1ee commit a27ac53
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 6 deletions.
13 changes: 7 additions & 6 deletions samples/pktgen/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,13 @@ function pgset() {
fi
}

if [[ -z "$APPEND" ]]; then
if [[ $EUID -eq 0 ]]; then
# Cleanup pktgen setup on exit if thats not "append mode"
trap 'pg_ctrl "reset"' EXIT
fi
fi
function trap_exit()
{
# Cleanup pktgen setup on exit if thats not "append mode"
if [[ -z "$APPEND" ]] && [[ $EUID -eq 0 ]]; then
trap 'pg_ctrl "reset"' EXIT
fi
}

## -- General shell tricks --

Expand Down
4 changes: 4 additions & 0 deletions samples/pktgen/pktgen_bench_xmit_mode_netif_receive.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ root_check_run_with_sudo "$@"

# Parameter parsing via include
source ${basedir}/parameters.sh

# Trap EXIT first
trap_exit

# Using invalid DST_MAC will cause the packets to get dropped in
# ip_rcv() which is part of the test
if [ -z "$DEST_IP" ]; then
Expand Down
4 changes: 4 additions & 0 deletions samples/pktgen/pktgen_bench_xmit_mode_queue_xmit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ root_check_run_with_sudo "$@"

# Parameter parsing via include
source ${basedir}/parameters.sh

# Trap EXIT first
trap_exit

if [ -z "$DEST_IP" ]; then
[ -z "$IP6" ] && DEST_IP="198.18.0.42" || DEST_IP="FD00::1"
fi
Expand Down
4 changes: 4 additions & 0 deletions samples/pktgen/pktgen_sample01_simple.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ root_check_run_with_sudo "$@"
# - go look in parameters.sh to see which setting are avail
# - required param is the interface "-i" stored in $DEV
source ${basedir}/parameters.sh

# Trap EXIT first
trap_exit

#
# Set some default params, if they didn't get set
if [ -z "$DEST_IP" ]; then
Expand Down
3 changes: 3 additions & 0 deletions samples/pktgen/pktgen_sample02_multiqueue.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ root_check_run_with_sudo "$@"
# Required param: -i dev in $DEV
source ${basedir}/parameters.sh

# Trap EXIT first
trap_exit

[ -z "$COUNT" ] && COUNT="100000" # Zero means indefinitely

# Base Config
Expand Down
4 changes: 4 additions & 0 deletions samples/pktgen/pktgen_sample03_burst_single_flow.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ root_check_run_with_sudo "$@"

# Parameter parsing via include
source ${basedir}/parameters.sh

# Trap EXIT first
trap_exit

# Set some default params, if they didn't get set
if [ -z "$DEST_IP" ]; then
[ -z "$IP6" ] && DEST_IP="198.18.0.42" || DEST_IP="FD00::1"
Expand Down
4 changes: 4 additions & 0 deletions samples/pktgen/pktgen_sample04_many_flows.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ root_check_run_with_sudo "$@"

# Parameter parsing via include
source ${basedir}/parameters.sh

# Trap EXIT first
trap_exit

# Set some default params, if they didn't get set
if [ -z "$DEST_IP" ]; then
[ -z "$IP6" ] && DEST_IP="198.18.0.42" || DEST_IP="FD00::1"
Expand Down
4 changes: 4 additions & 0 deletions samples/pktgen/pktgen_sample05_flow_per_thread.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ root_check_run_with_sudo "$@"

# Parameter parsing via include
source ${basedir}/parameters.sh

# Trap EXIT first
trap_exit

# Set some default params, if they didn't get set
if [ -z "$DEST_IP" ]; then
[ -z "$IP6" ] && DEST_IP="198.18.0.42" || DEST_IP="FD00::1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ root_check_run_with_sudo "$@"
# Required param: -i dev in $DEV
source ${basedir}/parameters.sh

# Trap EXIT first
trap_exit

# Base Config
[ -z "$COUNT" ] && COUNT="20000000" # Zero means indefinitely
[ -z "$CLONE_SKB" ] && CLONE_SKB="0"
Expand Down

0 comments on commit a27ac53

Please sign in to comment.