Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net: Setting LocalAddr to v4 address in net.Dialer not effective if v6 available #14672

Closed
bong0 opened this issue Mar 6, 2016 · 3 comments
Closed

Comments

@bong0
Copy link

bong0 commented Mar 6, 2016

  1. What version of Go are you using (go version)?
    go version go1.5.3 linux/amd64
  2. What operating system and processor architecture are you using (go env)?
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/bongo/dev/go"
GORACE=""
GOROOT="/usr/lib/golang"
GOTOOLDIR="/usr/lib/golang/pkg/tool/linux_amd64"
GO15VENDOREXPERIMENT=""
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"
  1. What did you do?
    I ran the following code: http://play.golang.org/p/sujhjFG8W2

and did a tcpdump in parallel looking for packages containing my local ipv4 that should be used for connecting:

sudo tcpdump -n ip host 192.168.0.99
[sudo] password for bongo: 
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on wlp3s0, link-type EN10MB (Ethernet), capture size 262144 bytes
  1. What did you expect to see?
    • There should be packages showing up in tcpdump
    • the "actual ip used" line should show a IPv4 address and not IPv6
  2. What did you see instead?
    • "actual ip used" line shows my public v6 address as used for connection
    • there are no packages showing up using the forced LocalAddr as source
  3. What do you wish?
    I wish that
    • forcing of LocalAddr is effective
    • it's possible to assign multiple LocalAddrs (one for v4 one for v6) since I want to use a forced address other than the default one also if a host is available on v6 (dual stack/fallback)
    • the design of http.Transport and on a lower level net.Dialer is not in a way that forcing v4 or v6 only connectivity is possible (at least I tried hard to find a way that's exposed and did not manage to), this should be made possible
  4. What do you suspect to be the reason for this behaviour?
    I believe that somewhere in the source of the net/http library a hardcoded "tcp" automatically chooses IPv6 for connecting though it definitely shouldn't...
@bong0
Copy link
Author

bong0 commented Mar 6, 2016

I quickly tried wrapping the Dial function as described at https://groups.google.com/d/msg/golang-nuts/_VgvTySj25o/-TtM2jYR-0EJ into a Function that sets "tcp4" forcibly but it still has no effect on the outcome.
Full modified source at: http://play.golang.org/p/DhlAe3pJt2

           Dial: (func(network, addr string) (net.Conn, error) {
                    return (&net.Dialer{
                            Timeout:        3 * time.Second,
                            LocalAddr:      nil,
                            DualStack:      false,
                    }).Dial("tcp4", addr)
            }),
local ip to connect 192.168.0.99
actual ip used:  2a02:[redacted]

@bong0
Copy link
Author

bong0 commented Mar 6, 2016

I discovered this may be related to the used http client since when constructing from a http.Client v4 is used.
Closing this issue for now, until I verified that there is still something not working for which the library is not responsible.

@bong0 bong0 closed this as completed Mar 6, 2016
@bong0
Copy link
Author

bong0 commented Mar 6, 2016

Okay, I consider this issue as closed and open up another one for the part of assigning multiple LocalAddrs for DualStack.

This version of pester fixes it: sethgrid/pester#6

@mikioh mikioh changed the title Setting LocalAddr to v4 address in net.Dialer not effective if v6 available net: Setting LocalAddr to v4 address in net.Dialer not effective if v6 available Mar 15, 2016
@golang golang locked and limited conversation to collaborators Mar 19, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants