parallel: Allow IPv6 and _ in hostname.

This commit is contained in:
Ole Tange 2022-11-02 12:37:25 +01:00
parent b6302404fa
commit 53e3f5b7a3
3 changed files with 55 additions and 6 deletions

View file

@ -6919,7 +6919,7 @@ sub new($$) {
if($s =~ s/^(.*) //) { $sshcommand = $1; }
# [user:pass@]server:port
if($s =~ s/([^@]+)@//) {
if($s =~ s/^([^@]+)@//) {
my $userpw = $1;
# user[:pass]
if($userpw =~ s/:(.*)//) {
@ -6932,13 +6932,40 @@ sub new($$) {
}
$user = $userpw;
}
# [server]:port
if($s =~ s/([-a-z0-9.]+)//i) { $host = $1; }
if(not $s =~ /:.*:/
and
$s =~ s/^([-a-z0-9._]+)//i) {
# Not IPv6 (IPv6 has 2 or more ':')
$host = $1;
} elsif($s =~ s/^(\\[\[\]box0-9a-f.]+)//i) {
# RFC2673 allows for:
# \[b11010000011101] \[o64072/14] \[xd074/14] \[208.116.0.0/14]
$host = $1;
} elsif($s =~ s/^\[([0-9a-f:]+)\]//i
or
$s =~ s/^([0-9a-f:]+)//i) {
# RFC5952
# [2001:db8::1]:80
# 2001:db8::1.80
# 2001:db8::1p80
# 2001:db8::1#80
# 2001:db8::1:80 - not supported
# 2001:db8::1 port 80 - not supported
$host = $1;
}
# [:port]
if($s =~ s/:(\w+)//i) { $port = $1; }
if($s =~ s/^:(\w+)//i) {
$port = $1;
} elsif($s =~ s/^[p\.\#](\w+)//i) {
# RFC5952
# 2001:db8::1.80
# 2001:db8::1p80
# 2001:db8::1#80
$port = $1;
}
if($s and $s ne ':') {
::die_bug("SSHLogin parser failed on '$origs' => '$s'");
}
@ -6949,7 +6976,7 @@ sub new($$) {
($user && $user."@").
($host && $host).
($port && ":$port");
if($s eq ':') {
if($host eq ':') {
$local = 1;
$string = ":";
} else {

View file

@ -588,6 +588,27 @@ par_keeporder_roundrobin() {
fi
}
par_test_ipv6_format() {
echo '### Host as IPv6 address'
(
ifconfig |
# Get IPv6 addresses of local server
perl -nE '/inet6 ([0-9a-f:]+) .*(host|global)/ and
map {say $1,$_,22; say $1,$_,"ssh"} qw(: . # p q)' |
# 9999::9999:9999:22 => [9999::9999:9999]:22
# 9999::9999:9999q22 => 9999::9999:9999
perl -pe 's/(.*):(22|ssh)$/[$1]:$2/;s/q.*//;'
ifconfig |
# Get IPv4 addresses
perl -nE '/inet (\S+) / and
map {say $1,$_,22; say $1,$_,"ssh"} qw(: q)' |
# 9.9.9.9q22 => 9.9.9.9
perl -pe 's/q.*//;'
) |
parallel -j30 --delay 0.1 --argsep , parallel -S {} true ::: 1 ||
echo Failed
}
# was -j6 before segfault circus
export -f $(compgen -A function | grep par_)
compgen -A function | grep par_ | sort |

View file

@ -1858,3 +1858,4 @@ par_test_detected_shell test_known_shell_pipe yash Global::shell /usr/bin/yash
par_test_detected_shell test_known_shell_pipe zsh Global::shell /usr/bin/zsh
par_test_diff_roundrobin_k ### test there is difference on -k
par_test_diff_roundrobin_k OK
par_test_ipv6_format ### Host as IPv6 address