Skip to contentSkip to conversation

selftests/openvswitch: guard command substitutions against empty output

PATCH Superseded Minxi Hou 3 participants 3 messages Jun 1 – Jun 9

Subsystems (4)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Minxi Hou

author
#0 lore raw

PATCH 1/1 selftests/openvswitch: guard command substitutions against empty output

When ip-link output is unavailable, when the upcall daemon log has not been written yet, or when pahole does not know the OVS drop subsystem ID, the affected command substitutions silently produce empty strings. The caller then passes empty sha= or pid= arguments to ovs_add_flow, or matches against wrong drop reason codes, all without a diagnostic.

Add [ -z ] guards immediately after each assignment. For test_arp_ping, also align the MAC extraction to use awk '/link\/ether/' as in test_pop_vlan. The drop_reason guard returns ksft_skip because an absent subsystem ID is an environment issue, not a test failure.

---
 .../selftests/net/openvswitch/openvswitch.sh     | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
tools/testing/selftests/net/openvswitch/openvswitch.sh +14 -2
index 8cd5b3d894ab..67f508facc91 100755
@@ -305,6 +305,8 @@ test_psample() {
 	# sFlow / IPFIX.
 	nlpid=$(grep -E "listening on upcall packet handler" \
             $ovs_dir/s0.out | cut -d ":" -f 2 | tr -d ' ')
+	[ -z "$nlpid" ] && \
+		{ info "failed to get upcall PID"; return 1; }
 
 	ovs_add_flow "test_psample" psample \
             "in_port(2),eth(),eth_type(0x0800),ipv4()" \
@@ -338,6 +340,10 @@ test_drop_reason() {
 	ovs_drop_subsys=$(pahole -C skb_drop_reason_subsys |
 			      awk '/OPENVSWITCH/ { print $3; }' |
 			      tr -d ,)
+	if [ -z "$ovs_drop_subsys" ]; then
+		info "failed to get OVS drop subsys ID"
+		return $ksft_skip
+	fi
 
 	sbx_add "test_drop_reason" || return $?
 
@@ -436,13 +442,19 @@ test_arp_ping () {
 	# Setup client namespace
 	ip netns exec client ip addr add 172.31.110.10/24 dev c1
 	ip netns exec client ip link set c1 up
-	HW_CLIENT=`ip netns exec client ip link show dev c1 | grep -E 'link/ether [0-9a-f:]+' | awk '{print $2;}'`
+	HW_CLIENT=$(ip netns exec client ip link show dev c1 \
+		| awk '/link\/ether/ {print $2}')
+	[ -z "$HW_CLIENT" ] && \
+		{ info "failed to get client hwaddr"; return 1; }
 	info "Client hwaddr: $HW_CLIENT"
 
 	# Setup server namespace
 	ip netns exec server ip addr add 172.31.110.20/24 dev s1
 	ip netns exec server ip link set s1 up
-	HW_SERVER=`ip netns exec server ip link show dev s1 | grep -E 'link/ether [0-9a-f:]+' | awk '{print $2;}'`
+	HW_SERVER=$(ip netns exec server ip link show dev s1 \
+		| awk '/link\/ether/ {print $2}')
+	[ -z "$HW_SERVER" ] && \
+		{ info "failed to get server hwaddr"; return 1; }
 	info "Server hwaddr: $HW_SERVER"
 
 	ovs_add_flow "test_arp_ping" arpping \
Signature · 1 line
2.54.0
maintainer
#1 lore raw
Quoted 6 lines · Minxi Hou

When ip-link output is unavailable, when the upcall daemon log has not been written yet, or when pahole does not know the OVS drop subsystem ID, the affected command substitutions silently produce empty strings. The caller then passes empty sha= or pid= arguments to ovs_add_flow, or matches against wrong drop reason codes, all without a diagnostic.

Quoted 6 lines

Add [ -z ] guards immediately after each assignment. For test_arp_ping, also align the MAC extraction to use awk '/link\/ether/' as in test_pop_vlan. The drop_reason guard returns ksft_skip because an absent subsystem ID is an environment issue, not a test failure.

IMHO this is net-next material.

@Aaron, @Eelco, @Ilya: WDYT?

/P

maintainer
#2 lore raw
Quoted 12 lines · Paolo Abeni
Quoted 11 lines · Minxi Hou

When ip-link output is unavailable, when the upcall daemon log has not been written yet, or when pahole does not know the OVS drop subsystem ID, the affected command substitutions silently produce empty strings. The caller then passes empty sha= or pid= arguments to ovs_add_flow, or matches against wrong drop reason codes, all without a diagnostic.

Add [ -z ] guards immediately after each assignment. For test_arp_ping, also align the MAC extraction to use awk '/link\/ether/' as in test_pop_vlan. The drop_reason guard returns ksft_skip because an absent subsystem ID is an environment issue, not a test failure.

Quoted 5 lines
Quoted 1 line

IMHO this is net-next material.

@Aaron, @Eelco, @Ilya: WDYT?

Agreed.

Quoted 1 line

/P