Repository navigation
resolved: bind socket to the interface - #12004
antoinefaure wants to merge 1 commit into
Conversation
|
Hello, |
f772f7c to
2956ae6
Compare
There was a problem hiding this comment.
IP_UNICAST_IF has no effect on anything but IPv4 UDP. I would remove this. We don't know what effect it might have on stream sockets (and similar) in the future.
You say Secondly: Newer kernels provide Lastly, can somebody elaborate what exactly the per-interface option in resolved is doing? The patch looks good to me, but I would prefer having some more context on why exactly it is needed? Thanks! |
|
Hello @dvdhrm The long version is the issue #11935 I will have a look at Concerning the per-interface resolution: you can receive DNS servers through DHCP, so you can have specific servers that are joinable only through one interface. In my case it was problematic using a 3G dongle on an embedded system that also has an ethernet connection. The network operator provides us with a DNS server on a public IP (94.x.x.x), but the resolutions are accepted only through the 3G network. At the moment, when I ask resolved to resolve a hostname using this server, it will try to do it through the ethernet link, and our requests are dropped. Do you have any idea why the CI is broken ? It seems unrelated to what I've modified :s |
Meh, ignore it, someone with sufficient access will restart it ;) Can you explain why
If you just happended to try both and one worked, that is fine. I just want to understand why exactly this is needed. |
No no, please do not ignore the CI failures. These are caused by this PR. The test script |
|
master...b1tninja:dns_bind_addr any desire to collaborate on this? I got the ifname moved into the manager struct, just need to wire up config parsing.... does anyone see any usefulness in looking up the interface by address? An empty string will unbind the socket from the device/interface, but would a keyword / other config param be more user friendly? Since currently the default is "lo" |
|
@antoinefaure So I checked the kernel sources again |
(Just to mention that: #12024 moved systemd over to using SO_BINDTOIFINDEX where available) |
2956ae6 to
f9a1c99
Compare
|
Hello, I force pushed with the following changes:
|
|
@dvdhrm When using IP_UNICAST_IF the request is not always sent using the DNS server's interface. It is quite easy to reproduce :
This is not very problematic on a computer where the 2 interfaces have access to internet, but as described in the issue #11935 this is problematic when the secondary connection is a 3G dongle for example. I think IP_UNICAST_IF does respect the routing rules, whereas SO_BINDTODEVICE does not but instead guarantees to use the asked interface. As @poettering said in the issue, this is poorly documented and the difference between the 2 socket options is not very clear |
When using a DNS server associated to a link, make sure to use this link to send the request. IP_UNICAST_IF is overridden by the configured routes, and therefore doesn't guarantee that the request will go on the desired interface. To use SO_BINDTODEVICE we need to keep the capability CAP_NET_RAW
f9a1c99 to
56efb7b
Compare
|
I posted #17535 now which contains a commit that issues the SO_BINDTOINDEX sockopt before calling connect() and then undoes it right after. THis should give the right behaviour, as it means the routing decision done in connect() will take the binding into account, but the other SO_BINDTOINDE semantics we won't be affected by. Ideally this would be fixed in the kernel, i.e. connect() should really take the IP_UNICAST_IF ifindex into account when doing its routing decision, but after checking the kernel sources, it currently really does not. Anyway, closing in favour of #17535 |
Apparently, IF_UNICAST_IF does not influence the routing decisions done during connect(). But SO_BINDTODEVICE/SO_BINDTOINDEX does, which however brings a lot of other semantics with it, we are not so interested in (i.e. it doesn't not allow packets from any other iface to us, even if routing otherwise allows it). Hence, let's bind to the ifindex immediately before the connect() and unbind right after again, so that we get the semantics we want, but not the ones we don't. Fixes: systemd#11935 Replaces: systemd#12004
Apparently, IF_UNICAST_IF does not influence the routing decisions done during connect(). But SO_BINDTODEVICE/SO_BINDTOINDEX does, which however brings a lot of other semantics with it, we are not so interested in (i.e. it doesn't not allow packets from any other iface to us, even if routing otherwise allows it). Hence, let's bind to the ifindex immediately before the connect() and unbind right after again, so that we get the semantics we want, but not the ones we don't. Fixes: systemd#11935 Replaces: systemd#12004 (cherry picked from commit d301c52)
This pull request resolves #11935
TL;DR :
When using a DNS server associated to a link, make sure to use this link to send the request.
IP_UNICAST_IFis overridden by the configured routes, and therefore doesn't guarantee that the request will go on the desired interface.To use
SO_BINDTODEVICEwe need to keep the capabilityCAP_NET_RAW