Skip to content

Commit 25b327d

Browse files
author
Florian Westphal
committed
selftests: nft_concat_range: add socat support
There are different flavors of 'nc' around, this script fails on my test vm because 'nc' is 'nmap-ncat' which isn't 100% compatible. Add socat support and use it if available. Signed-off-by: Florian Westphal <[email protected]>
1 parent 39aebed commit 25b327d

File tree

1 file changed

+53
-12
lines changed

1 file changed

+53
-12
lines changed

tools/testing/selftests/netfilter/nft_concat_range.sh

Lines changed: 53 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ src
9191
start 1
9292
count 5
9393
src_delta 2000
94-
tools sendip nc bash
94+
tools sendip socat nc bash
9595
proto udp
9696
9797
race_repeat 3
@@ -116,7 +116,7 @@ src
116116
start 10
117117
count 5
118118
src_delta 2000
119-
tools sendip nc bash
119+
tools sendip socat nc bash
120120
proto udp6
121121
122122
race_repeat 3
@@ -141,7 +141,7 @@ src
141141
start 1
142142
count 5
143143
src_delta 2000
144-
tools sendip nc bash
144+
tools sendip socat nc bash
145145
proto udp
146146
147147
race_repeat 0
@@ -163,7 +163,7 @@ src mac
163163
start 10
164164
count 5
165165
src_delta 2000
166-
tools sendip nc bash
166+
tools sendip socat nc bash
167167
proto udp6
168168
169169
race_repeat 0
@@ -185,7 +185,7 @@ src mac proto
185185
start 10
186186
count 5
187187
src_delta 2000
188-
tools sendip nc bash
188+
tools sendip socat nc bash
189189
proto udp6
190190
191191
race_repeat 0
@@ -207,7 +207,7 @@ src addr4
207207
start 1
208208
count 5
209209
src_delta 2000
210-
tools sendip nc bash
210+
tools sendip socat nc bash
211211
proto udp
212212
213213
race_repeat 3
@@ -227,7 +227,7 @@ src addr6 port
227227
start 10
228228
count 5
229229
src_delta 2000
230-
tools sendip nc
230+
tools sendip socat nc
231231
proto udp6
232232
233233
race_repeat 3
@@ -247,7 +247,7 @@ src mac proto addr4
247247
start 1
248248
count 5
249249
src_delta 2000
250-
tools sendip nc bash
250+
tools sendip socat nc bash
251251
proto udp
252252
253253
race_repeat 0
@@ -264,7 +264,7 @@ src mac
264264
start 1
265265
count 5
266266
src_delta 2000
267-
tools sendip nc bash
267+
tools sendip socat nc bash
268268
proto udp
269269
270270
race_repeat 0
@@ -286,7 +286,7 @@ src mac addr4
286286
start 1
287287
count 5
288288
src_delta 2000
289-
tools sendip nc bash
289+
tools sendip socat nc bash
290290
proto udp
291291
292292
race_repeat 0
@@ -337,7 +337,7 @@ src addr4
337337
start 1
338338
count 5
339339
src_delta 2000
340-
tools sendip nc
340+
tools sendip socat nc
341341
proto udp
342342
343343
race_repeat 3
@@ -363,7 +363,7 @@ src mac
363363
start 1
364364
count 1
365365
src_delta 2000
366-
tools sendip nc bash
366+
tools sendip socat nc bash
367367
proto udp
368368
369369
race_repeat 0
@@ -541,6 +541,24 @@ setup_send_udp() {
541541
dst_port=
542542
src_addr4=
543543
}
544+
elif command -v socat -v >/dev/null; then
545+
send_udp() {
546+
if [ -n "${src_addr4}" ]; then
547+
B ip addr add "${src_addr4}" dev veth_b
548+
__socatbind=",bind=${src_addr4}"
549+
if [ -n "${src_port}" ];then
550+
__socatbind="${__socatbind}:${src_port}"
551+
fi
552+
fi
553+
554+
ip addr add "${dst_addr4}" dev veth_a 2>/dev/null
555+
[ -z "${dst_port}" ] && dst_port=12345
556+
557+
echo "test4" | B socat -t 0.01 STDIN UDP4-DATAGRAM:${dst_addr4}:${dst_port}"${__socatbind}"
558+
559+
src_addr4=
560+
src_port=
561+
}
544562
elif command -v nc >/dev/null; then
545563
if nc -u -w0 1.1.1.1 1 2>/dev/null; then
546564
# OpenBSD netcat
@@ -606,6 +624,29 @@ setup_send_udp6() {
606624
dst_port=
607625
src_addr6=
608626
}
627+
elif command -v socat -v >/dev/null; then
628+
send_udp6() {
629+
ip -6 addr add "${dst_addr6}" dev veth_a nodad \
630+
2>/dev/null
631+
632+
__socatbind6=
633+
634+
if [ -n "${src_addr6}" ]; then
635+
if [ -n "${src_addr6} != "${src_addr6_added} ]; then
636+
B ip addr add "${src_addr6}" dev veth_b nodad
637+
638+
src_addr6_added=${src_addr6}
639+
fi
640+
641+
__socatbind6=",bind=[${src_addr6}]"
642+
643+
if [ -n "${src_port}" ] ;then
644+
__socatbind6="${__socatbind6}:${src_port}"
645+
fi
646+
fi
647+
648+
echo "test6" | B socat -t 0.01 STDIN UDP6-DATAGRAM:[${dst_addr6}]:${dst_port}"${__socatbind6}"
649+
}
609650
elif command -v nc >/dev/null && nc -u -w0 1.1.1.1 1 2>/dev/null; then
610651
# GNU netcat might not work with IPv6, try next tool
611652
send_udp6() {

0 commit comments

Comments
 (0)