nfx/slrp

Can't run v0.3.0 binary in Docker: `panic: As4 called on IPv6 address`

Opened this issue · 7 comments

Seems like some ipv6/ipv4 backward compatibility problem:

$ md5sum ./slrp
d5176f385f243708b347063e46f5c99c  ./slrp

$ cat Dockerfile
ARG ALPINE_VERSION=3.18
FROM alpine:${ALPINE_VERSION} AS runner
RUN apk add --no-cache ca-certificates tzdata
ENV PWD="/app"
ENV SLRP_APP_STATE="$PWD/.slrp/data"
ENV SLRP_APP_SYNC="1m"
ENV SLRP_LOG_LEVEL="info"
ENV SLRP_LOG_FORMAT="pretty"
ENV SLRP_SERVER_ADDR="0.0.0.0:8089"
ENV SLRP_SERVER_READ_TIMEOUT="15s"
ENV SLRP_MITM_ADDR="0.0.0.0:8090"
ENV SLRP_MITM_READ_TIMEOUT="15s"
ENV SLRP_MITM_IDLE_TIMEOUT="15s"
ENV SLRP_MITM_WRITE_TIMEOUT="15s"
ENV SLRP_CHECKER_TIMEOUT="5s"
ENV SLRP_CHECKER_STRATEGY="simple"
ENV SLRP_HISTORY_LIMIT="1000"
WORKDIR $PWD
RUN mkdir ./.slrp
COPY ./slrp $PWD
EXPOSE 8089 8090
CMD ["./slrp"]

$ docker build -t myslrp .
$ docker run myslrp
slrp v0.3.0
5:40AM WRN using clear dialer
5:40AM INF configured proxy checker ip=<my IPv4 address was here> strategy=simple timeout=5
panic: As4 called on IPv6 address

goroutine 1 [running]:
net/netip.Addr.As4({{0xc0001e4240?, 0xeca77d?}, 0xc000010090?})
        /opt/hostedtoolcache/go/1.20.6/x64/src/net/netip/netip.go:692 +0x8e
github.com/nfx/slrp/pmux.NewProxy({0xc0000b61c4?, 0x0?}, {0xeca77d, 0x5})
        /home/runner/work/slrp/slrp/pmux/proxy.go:259 +0x90
github.com/nfx/slrp/pmux.HttpsProxy(...)
        /home/runner/work/slrp/slrp/pmux/proxy.go:276
github.com/nfx/slrp/serve.(*HttpsProxyServer).Proxy(0x18803c0?)
        /home/runner/work/slrp/slrp/serve/https_proxy.go:43 +0x2c
github.com/nfx/slrp/serve.(*MitmProxyServer).Configure(0xc000474240, 0xc0003f7e60?)
        /home/runner/work/slrp/slrp/serve/mitm_proxy.go:45 +0x13c
github.com/nfx/slrp/app.(*Fabric).configureServices(0xc000410680)
        /home/runner/work/slrp/slrp/app/fabric.go:224 +0xdc
github.com/nfx/slrp/app.(*Fabric).Start(0xc000410680, {0x1100600?, 0xc000046038})
        /home/runner/work/slrp/slrp/app/fabric.go:107 +0x765
github.com/nfx/slrp/app.Run(...)
        /home/runner/work/slrp/slrp/app/fabric.go:58
main.main()
        /home/runner/work/slrp/slrp/main.go:34 +0x5d8

Just in case, that shell script does not fix the issue, but helps to still run slrp by picking up the interface with default route:

#!/bin/sh

_term() { 
  echo "Caught SIGTERM signal!" 
  kill -TERM "$child" 2>/dev/null
}

default_iface=$(awk '$2 == 00000000 { print $1 }' /proc/net/route)
listen_ip=$(ip addr show dev "$default_iface" | awk '$1 == "inet" { sub("/.*", "", $2); print $2 }')
echo "Chose IP: ${listen_ip}"
SLRP_MITM_ADDR="${listen_ip}:${MITM_PORT}" SLRP_SERVER_ADDR="${listen_ip}:${SERVER_PORT}" ./slrp

child=$! 
wait "$child"
nfx commented

@tired-engineer Could you try to make a PR to go code?

@nfx, I'll try, probably next week.

Sorry for the delay. I am failing to even simply build the project after just checking out the code, some dependency mess, so I'll pass.

nfx commented

@tired-engineer where's dependency mess? Go or JavaScript?

Heya!
I think its the golang
I'm getting this:

go build -ldflags "-s -w" main.go
package command-line-arguments
        imports github.com/nfx/slrp/dialer
        imports golang.zx2c4.com/wireguard/tun/netstack
        imports gvisor.dev/gvisor/pkg/bufferv2
        imports gvisor.dev/gvisor/pkg/atomicbitops
        imports gvisor.dev/gvisor/pkg/cpuid
        imports gvisor.dev/gvisor/pkg/state
        imports gvisor.dev/gvisor/pkg/state/wire
        imports gvisor.dev/gvisor/pkg/gohacks: build constraints exclude all Go files in /workspaces/slrp/vendor/gvisor.dev/gvisor/pkg/gohacks
make: *** [Makefile:21: build] Error 1