|
33 | 33 | chomp $ipv4; |
34 | 34 | } |
35 | 35 |
|
| 36 | +my $instDir = qx(limactl list "$instance" --yq .dir); |
| 37 | +chomp $instDir; |
| 38 | + |
36 | 39 | # If $instance is a filename, add our portForwards to it to enable testing |
37 | 40 | if (-f $instance) { |
38 | 41 | open(my $fh, "+< $instance") or die "Can't open $instance for read/write: $!"; |
|
94 | 97 | s/sshLocalPort/$sshLocalPort/g; |
95 | 98 | s/ipv4/$ipv4/g; |
96 | 99 | s/ipv6/$ipv6/g; |
| 100 | + s/\{\{\.Dir\}\}/$instDir/g; |
97 | 101 | # forward: 127.0.0.1 899 → 127.0.0.1 799 |
98 | 102 | # ignore: 127.0.0.2 8888 |
99 | | - /^(forward|ignore):\s+([0-9.:]+)\s+(\d+)(?:\s+→)?(?:\s+([0-9.:]+)(?:\s+(\d+))?)?/; |
| 103 | + /^(forward|ignore):\s+([0-9.:]+)\s+(\d+)(?:\s+→)?(?:\s+(?:([0-9.:]+)(?:\s+(\d+))|(\/\S+))?)?/; |
100 | 104 | 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); |
| 105 | + my %test; @test{qw(mode guest_ip guest_port host_ip host_port host_socket)} = ($1, $2, $3, $4, $5, $6); |
| 106 | + |
102 | 107 | $test{host_ip} ||= "127.0.0.1"; |
103 | 108 | $test{host_port} ||= $test{guest_port}; |
104 | | - if ($test{mode} eq "forward" && $test{host_port} < 1024 && $Config{osname} ne "darwin") { |
| 109 | + $test{host_socket} ||= ""; |
| 110 | + if ($test{mode} eq "forward" && $test{host_socket} eq "" && $test{host_port} < 1024 && $Config{osname} ne "darwin") { |
105 | 111 | printf "🚧 Not supported on $Config{osname}: # $_\n"; |
106 | 112 | next; |
107 | 113 | } |
|
115 | 121 | } |
116 | 122 |
|
117 | 123 | my $remote = JoinHostPort($test{guest_ip},$test{guest_port}); |
118 | | - my $local = JoinHostPort($test{host_ip},$test{host_port}); |
| 124 | + my $local = $test{host_socket} eq "" ? JoinHostPort($test{host_ip},$test{host_port}) : $test{host_socket}; |
119 | 125 | if ($test{mode} eq "ignore") { |
120 | 126 | $test{log_msg} = "Not forwarding TCP $remote"; |
121 | 127 | } |
|
163 | 169 | # Try to reach each listener from the host |
164 | 170 | foreach my $test (@test) { |
165 | 171 | next if $test->{host_port} == $sshLocalPort; |
166 | | - my $nc = "nc -w 1 $test->{host_ip} $test->{host_port}"; |
| 172 | + my $nc = $test->{host_socket} eq "" ? "nc -w 1 $test->{host_ip} $test->{host_port}" : "nc -w 1 -U $test->{host_socket}"; |
167 | 173 | open(my $netcat, "| $nc") or die "Can't run '$nc': $!"; |
168 | 174 | print $netcat "$test->{log_msg}\n"; |
169 | 175 | # Don't check for errors on close; macOS nc seems to return non-zero exit code even on success |
|
175 | 181 | seek($log, $ha_log_size, 0) or die "Can't seek $ha_log to $ha_log_size: $!"; |
176 | 182 | my %seen; |
177 | 183 | while (<$log>) { |
178 | | - $seen{$1}++ if /(Forwarding TCP from .*? to (\d.*?|\[.*?\]):\d+)/; |
| 184 | + $seen{$1}++ if /(Forwarding TCP from .*? to ((\d.*?|\[.*?\]):\d+|\/[^"]+))/; |
179 | 185 | $seen{$1}++ if /(Not forwarding TCP .*?:\d+)/; |
180 | 186 | } |
181 | 187 | close $log or die; |
@@ -342,3 +348,8 @@ sub JoinHostPort { |
342 | 348 | - guestIPMustBeZero: true |
343 | 349 | guestPort: 8888 |
344 | 350 | hostIP: 0.0.0.0 |
| 351 | +
|
| 352 | +- guestPort: 5000 |
| 353 | + hostSocket: "{{.Dir}}/sock/port5000.sock" |
| 354 | +
|
| 355 | + # forward: 127.0.0.1 5000 → {{.Dir}}/sock/port5000.sock |
0 commit comments