|
16 | 16 | use warnings; |
17 | 17 |
|
18 | 18 | use Config qw(%Config); |
| 19 | +use File::Spec::Functions qw(catfile); |
19 | 20 | use IO::Handle qw(); |
20 | 21 | use Socket qw(inet_ntoa); |
21 | 22 | use Sys::Hostname qw(hostname); |
|
33 | 34 | chomp $ipv4; |
34 | 35 | } |
35 | 36 |
|
| 37 | +my $instDir = qx(limactl list "$instance" --yq .dir); |
| 38 | +chomp $instDir; |
| 39 | +# platform independent way to add trailing path separator |
| 40 | +my $sockDir = catfile($instDir, "sock", ""); |
| 41 | + |
36 | 42 | # If $instance is a filename, add our portForwards to it to enable testing |
37 | 43 | if (-f $instance) { |
38 | 44 | open(my $fh, "+< $instance") or die "Can't open $instance for read/write: $!"; |
|
94 | 100 | s/sshLocalPort/$sshLocalPort/g; |
95 | 101 | s/ipv4/$ipv4/g; |
96 | 102 | s/ipv6/$ipv6/g; |
| 103 | + s/sockDir\//$sockDir/g; |
97 | 104 | # forward: 127.0.0.1 899 → 127.0.0.1 799 |
98 | 105 | # ignore: 127.0.0.2 8888 |
99 | | - /^(forward|ignore):\s+([0-9.:]+)\s+(\d+)(?:\s+→)?(?:\s+([0-9.:]+)(?:\s+(\d+))?)?/; |
| 106 | + /^(forward|ignore):\s+([0-9.:]+)\s+(\d+)(?:\s+→)?(?:\s+(?:([0-9.:]+)(?:\s+(\d+))|(\S+))?)?/; |
100 | 107 | die "Cannot parse test '$_'" unless $1; |
101 | | - my %test; @test{qw(mode guest_ip guest_port host_ip host_port)} = ($1, $2, $3, $4, $5); |
| 108 | + my %test; @test{qw(mode guest_ip guest_port host_ip host_port host_socket)} = ($1, $2, $3, $4, $5, $6); |
| 109 | + |
102 | 110 | $test{host_ip} ||= "127.0.0.1"; |
103 | 111 | $test{host_port} ||= $test{guest_port}; |
104 | | - if ($test{mode} eq "forward" && $test{host_port} < 1024 && $Config{osname} ne "darwin") { |
| 112 | + $test{host_socket} ||= ""; |
| 113 | + if ($test{mode} eq "forward" && $test{host_socket} eq "" && $test{host_port} < 1024 && $Config{osname} ne "darwin") { |
105 | 114 | printf "🚧 Not supported on $Config{osname}: # $_\n"; |
106 | 115 | next; |
107 | 116 | } |
|
113 | 122 | printf "🚧 Not supported for $instanceType machines: # $_\n"; |
114 | 123 | next; |
115 | 124 | } |
| 125 | + if ($test{host_socket} ne "" && $Config{osname} eq "cygwin") { |
| 126 | + printf "🚧 Not supported on $Config{osname}: # $_\n"; |
| 127 | + next; |
| 128 | + } |
116 | 129 |
|
117 | 130 | my $remote = JoinHostPort($test{guest_ip},$test{guest_port}); |
118 | | - my $local = JoinHostPort($test{host_ip},$test{host_port}); |
| 131 | + my $local = $test{host_socket} eq "" ? JoinHostPort($test{host_ip},$test{host_port}) : $test{host_socket}; |
119 | 132 | if ($test{mode} eq "ignore") { |
120 | 133 | $test{log_msg} = "Not forwarding TCP $remote"; |
121 | 134 | } |
|
163 | 176 | # Try to reach each listener from the host |
164 | 177 | foreach my $test (@test) { |
165 | 178 | next if $test->{host_port} == $sshLocalPort; |
166 | | - my $nc = "nc -w 1 $test->{host_ip} $test->{host_port}"; |
| 179 | + my $nc = $test->{host_socket} eq "" ? "nc -w 1 $test->{host_ip} $test->{host_port}" : "nc -w 1 -U $test->{host_socket}"; |
167 | 180 | open(my $netcat, "| $nc") or die "Can't run '$nc': $!"; |
168 | 181 | print $netcat "$test->{log_msg}\n"; |
169 | 182 | # Don't check for errors on close; macOS nc seems to return non-zero exit code even on success |
|
175 | 188 | seek($log, $ha_log_size, 0) or die "Can't seek $ha_log to $ha_log_size: $!"; |
176 | 189 | my %seen; |
177 | 190 | while (<$log>) { |
178 | | - $seen{$1}++ if /(Forwarding TCP from .*? to (\d.*?|\[.*?\]):\d+)/; |
| 191 | + $seen{$1}++ if /(Forwarding TCP from .*? to ((\d.*?|\[.*?\]):\d+|\/[^"]+))/; |
179 | 192 | $seen{$1}++ if /(Not forwarding TCP .*?:\d+)/; |
180 | 193 | } |
181 | 194 | close $log or die; |
@@ -342,3 +355,8 @@ sub JoinHostPort { |
342 | 355 | - guestIPMustBeZero: true |
343 | 356 | guestPort: 8888 |
344 | 357 | hostIP: 0.0.0.0 |
| 358 | +
|
| 359 | +- guestPort: 5000 |
| 360 | + hostSocket: port5000.sock |
| 361 | +
|
| 362 | + # forward: 127.0.0.1 5000 → sockDir/port5000.sock |
0 commit comments