[PATCH v4 lkp-tests] lib: add transfer_port.sh

Provide a login port for user, determine whether to send the ssh_port message based on the uuid. Signed-off-by: Zhang Yale <ylzhangah@qq.com> --- lib/transfer_port.sh | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100755 lib/transfer_port.sh diff --git a/lib/transfer_port.sh b/lib/transfer_port.sh new file mode 100755 index 00000000..e1eed384 --- /dev/null +++ b/lib/transfer_port.sh @@ -0,0 +1,24 @@ +#!/bin/bash +# uuid + +. $LKP_SRC/lib/http.sh + +sshr_ip=$LKP_SERVER +sshr_port=5050 +[ -n "$sshr_port_len" ] || sshr_port_len=10 +[ -n "$sshr_port_base" ] || sshr_port_base=11333 + +get_port() +{ + [ -n "$uuid" ] || return + for i in $(seq 1 10) + do + port=$(($(date +%s%N)%"$sshr_port_len"+"$sshr_port_base")) + ssh -o StrictHostKeyChecking=no \ + -o ExitOnForwardFailure=yes -o TCPKeepAlive=yes -Nf -R $port:localhost:22 sshr@"$sshr_ip" -p "$sshr_port" &>/dev/null + [ $? -eq 0 ] || continue + echo "$port" + break + done +} + -- 2.23.0

On Wed, Oct 14, 2020 at 05:34:43PM +0800, Zhang Yale wrote:
On Wed, Oct 14, 2020 at 12:26:57PM +0800, Wu Fengguang wrote:
+[ -n "$sshr_port_len" ] || sshr_port_len=10
+ for i in $(seq 1 10)
10 ports are too small range.
Thanks, Fengguang
10 ports is open when I tested. If I modify it with 2000 ports now?
OK. Thanks, Fengguang

On Wed, Oct 14, 2020 at 12:28:20PM +0800, Wu Fengguang wrote:
+[ -n "$sshr_port_base" ] || sshr_port_base=11333
11333 is not a good base for a large range of ports. Please don't use 113xx -- they are reserved for other services.
Thanks, Fengguang
Ok, I got it. I will modify it with 30000. Thanks, Yale

On Wed, Oct 14, 2020 at 05:37:18PM +0800, Zhang Yale wrote:
On Wed, Oct 14, 2020 at 12:28:20PM +0800, Wu Fengguang wrote:
+[ -n "$sshr_port_base" ] || sshr_port_base=11333
11333 is not a good base for a large range of ports. Please don't use 113xx -- they are reserved for other services.
Thanks, Fengguang
Ok, I got it. I will modify it with 30000.
Let's use 50000 -- I just add this sysctl: net.ipv4.ip_local_port_range = 1024 50000 according to https://www.thegeekdiary.com/how-to-reserve-a-port-range-for-a-third-party-a... Thanks, Fengguang
participants (2)
-
Wu Fengguang
-
Zhang Yale