Commit Graph

6 Commits

Author SHA1 Message Date
gsotelo
32d34c472c docs: fix type in comment
Signed-off-by: gsotelo <gsotelo.se@gmail.com>
2026-01-05 15:27:23 +01:00
Albin Kerouanton
6c6174b371 cmd/docker-proxy: UDP: reply to clients with original daddr
When a UDP server is running on a multihomed server, as is the case with
pretty much _all_ Docker hosts (eg. eth0 + docker0), the kernel has to
choose which source address is used when replying to a UDP client. But
that process is based on heuristics and is fallible.

If the address picked doesn't match the original destination address
used by the client, it'll drop the datagram and return an ICMP Port
Unreachable.

To prevent that, we need to:

- `setsockopt(IP_PKTINFO)` on proxy's sockets.
- Extract the original destination address from an ancillary message
  every time a new 'UDP connection' is 'established' (ie. every time we
  insert a new entry into the UDP conntrack table).
- And finally, pass a control message containing the desired source
  address to the kernel, every time we send a response back to the
  client.

Also, update the inline comment on read errors in `(*UDPProxy).Run()`.
This comment was misleadingly referencing ECONNREFUSED - Linux's UDP
implementation never returns this error (see [1]). Instead, state why
`net.ErrClosed` is perfectly fine and doesn't need to be logged
(although, docker-proxy currently logs to nowhere).

[1]: https://github.com/search?q=repo%3Atorvalds%2Flinux+ECONNREFUSED+path%3A%2F%5Enet%5C%2F%28ipv4%7Cipv6%29%5C%2F%28udp%7Ctcp%29%2F&type=code

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2024-10-15 12:42:15 +02:00
Cory Snider
7a8663c9ea cmd/docker-proxy: drop FrontendAddr() method
It was only used in tests.

Signed-off-by: Cory Snider <csnider@mirantis.com>
2024-08-05 14:04:05 +01:00
Cory Snider
88fb0c9fec cmd/docker-proxy: drop unused BackendAddr() method
Signed-off-by: Cory Snider <csnider@mirantis.com>
2024-08-05 14:04:05 +01:00
Rob Murray
ba2f3c0a98 cmd/docker-proxy: pass open listener to proxy impl
In preparation for the daemon passing a listen fd, add command line
option -use-listen-fd to indicate that the fd is present (as fd 4).

If the new flag isn't given, open the listener as normal.

Refactor the TCP and UDP proxies to be constructed with an existing
TCPListener or UDPConn, respectively. Lift the responsibilty of opening
the listener to the entrypoint. Per the Single Responsibility Principle,
this structure affords changing how the listener is created without
having to touch the proxy implementations.

Co-authored-by: Cory Snider <csnider@mirantis.com>
Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-08-05 14:04:04 +01:00
Rob Murray
e0c7a839a8 Only build docker-proxy for Linux
Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-08-05 14:04:04 +01:00