Skip to content

Commit 286cb16

Browse files
committed
[tunnel/netstack] Use host upstream instead of localhost
1 parent 1e2e9bc commit 286cb16

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

pkg/netstack/tcp_forwarder.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,23 @@ func TCPForwarder(ctx context.Context, ipstack *stack.Stack, upstream network.Ne
3333

3434
// Unmap4in6 converts an IPv6 address to an IPv4 address if it is an IPv4-mapped IPv6 address.
3535
// If the address is not an IPv4-mapped IPv6 address, it is returned unchanged.
36+
// If the IPv4 address is zero, returns 127.0.0.1.
3637
// It is following /96 embedding scheme from RFC 6052 (https://datatracker.ietf.org/doc/html/rfc6052#section-2.2).
3738
func Unmap4in6(addr netip.Addr) netip.Addr {
3839
if !addr.Is6() {
3940
return addr
4041
}
4142
b16 := addr.As16()
42-
return netip.AddrFrom4([4]byte{
43+
v4addr := netip.AddrFrom4([4]byte{
4344
b16[12],
4445
b16[13],
4546
b16[14],
4647
b16[15],
4748
})
49+
if !v4addr.IsValid() {
50+
return netip.AddrFrom4([4]byte{127, 0, 0, 1})
51+
}
52+
return v4addr
4853
}
4954

5055
func tcpHandler(ctx context.Context, upstream network.Network) func(req *tcp.ForwarderRequest) {

pkg/tunnel/router/client_netstack.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func (r *NetstackRouter) Start(ctx context.Context) error {
101101

102102
if err := r.tunDev.ForwardTo(ctx, network.Filtered(&network.FilteredNetworkConfig{
103103
DeniedPorts: []uint16{uint16(socksListenPort)},
104-
Upstream: network.Loopback(),
104+
Upstream: network.Host(),
105105
})); err != nil {
106106
return fmt.Errorf("failed to forward to loopback: %w", err)
107107
}

0 commit comments

Comments
 (0)