From 6354f92ecc529c3f813733c8437768a432975dbc Mon Sep 17 00:00:00 2001 From: Gregory Thiemonge Date: Tue, 19 May 2020 11:22:47 +0200 Subject: [PATCH] Fix netcat option in udp_check.sh for CentOS/RHEL -w (timeout) option doesn't do anything in nmap-ncat (default netcat in CentOS/RHEL) for UDP datagrams, and nmap-ncat has a default idle timeout set to 2 seconds. We can get the same behavior as netcap-openbsd (Debian/Ubuntu) by setting that idle timeout (-i) option to 1 second. This commit detects the flavor of the netcat binary (nmap vs other) and uses it to adapt the parameters. Story: 2007688 Task: 39800 Change-Id: I0100aaa428477f011bd39a90dd4ec98199b4bebc --- octavia/amphorae/backends/utils/udp_check.sh | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/octavia/amphorae/backends/utils/udp_check.sh b/octavia/amphorae/backends/utils/udp_check.sh index 12b4d55a88..37443b053c 100644 --- a/octavia/amphorae/backends/utils/udp_check.sh +++ b/octavia/amphorae/backends/utils/udp_check.sh @@ -1,4 +1,16 @@ #!/bin/bash + nc_cmd=`which nc` -$nc_cmd -uzv -w1 $1 $2 > /dev/null + +nc_flavor=$($nc_cmd --version 2>&1 | grep -o nmap) +case "$nc_flavor" in +nmap) + nc_flavor_opts="-i1" + ;; +*) # default, probably openbsd + nc_flavor_opts="-w1" + ;; +esac + +$nc_cmd -uzv $nc_flavor_opts $1 $2 > /dev/null exit $?