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

docker-proxy does not set source IP correctly in UDP mode when bound on 0.0.0.0 #1729

Open
HarmtH opened this issue Apr 24, 2017 · 4 comments

Comments

@HarmtH
Copy link

HarmtH commented Apr 24, 2017

A container is configured to listen for DNS requests on all IP's on port 54:

 /usr/bin/docker-proxy -proto udp -host-ip 0.0.0.0 -host-port 54 -container-ip 172.19.0.2 -container-port 53

When I do a request from another container (in an isolated network from the DNS server container):

root@a9e4256c5510:/# dig google.nl @192.168.0.155 -p 54
;; reply from unexpected source: 172.17.0.1#54, expected 192.168.0.155#54

thinkbox :: work/dockers/bind » sudo tcpdump -n -i docker0
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on docker0, link-type EN10MB (Ethernet), capture size 262144 bytes
16:23:17.239359 IP 172.17.0.2.60735 > 192.168.0.155.54: UDP, length 38
16:23:17.432102 IP 172.17.0.1.54 > 172.17.0.2.60735: UDP, length 200

When I configure the container to just listen on 192.168.0.155:

/usr/bin/docker-proxy -proto udp -host-ip 192.168.0.155 -host-port 54 -container-ip 172.19.0.2 -container-port 53

It works correctly:

thinkbox :: work/dockers/bind » sudo tcpdump -n -i docker0
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on docker0, link-type EN10MB (Ethernet), capture size 262144 bytes
16:22:45.792460 IP 172.17.0.2.44517 > 192.168.0.155.54: UDP, length 38
16:22:45.792847 IP 192.168.0.155.54 > 172.17.0.2.44517: UDP, length 200
@HarmtH
Copy link
Author

HarmtH commented Apr 24, 2017

It seems that transmitting a UDP packet from the source it arrived on it quite a challenge to do in a generic way: http://stackoverflow.com/questions/3062205/setting-the-source-ip-for-a-udp-socket
The last answer to that question seems most helpful: http://stackoverflow.com/a/39013106

@Rahix
Copy link

Rahix commented May 14, 2020

Rahix added a commit to Rahix/lava-docker that referenced this issue May 14, 2020
With UDP, docker sometimes can't route UDP packets to the correct
address because the source address gets mangled [1].  This happens
indeterministically because by default the kernel uses some heuristics
to decide which interface to use.  But in some rare circumstances, those
can fail and a wrong source address is used.  This can be worked around
by explicitly binding to a concrete interface instead of 0.0.0.0.

[1]: moby/libnetwork#1729
Signed-off-by: Harald Seiler <hws@denx.de>
Rahix added a commit to Rahix/lava-docker that referenced this issue May 20, 2020
With UDP, docker sometimes can't route UDP packets to the correct
address because the source address gets mangled [1].  This happens
indeterministically because by default the kernel uses some heuristics
to decide which interface to use.  But in some rare circumstances, those
can fail and a wrong source address is used.  This can be worked around
by explicitly binding to a concrete interface instead of 0.0.0.0.

[1]: moby/libnetwork#1729
Signed-off-by: Harald Seiler <hws@denx.de>
@tsujamin
Copy link

remediating PR is linked, any update on if this can be fixed and merged?

@trmdi
Copy link

trmdi commented Jul 8, 2024

Hello, any update on this issue since the MR above has been Closed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants