Repository navigation
net/netns: add functionality to bind outgoing sockets based on route table - #7065
Conversation
|
This is the sort of commit that really needs to reference an issue :) |
8933b58 to
8f3711e
Compare
| } | ||
| } | ||
|
|
||
| var bindToDeviceByRoute = envknob.RegisterBool("TS_BIND_TO_DEVICE_BY_ROUTE") |
There was a problem hiding this comment.
Environment variables are annoying to set on macOS and ~impossible on iOS. Should we also add a node attribute that can be used to enable this?
There was a problem hiding this comment.
Yep, good idea; will add.
|
|
||
| // interfaceIndexFor returns the interface index that we should bind to in | ||
| // order to send traffic to the provided address. | ||
| func interfaceIndexFor(addr netip.Addr) (int, error) { |
There was a problem hiding this comment.
Depending on how expensive this is, we could add a cache for this (and invalidate it via LinkMonitor RegisterChangeCallback callback).
There was a problem hiding this comment.
This is pretty expensive, yeah, which is why I'm not planning on enabling this by default. In the long term, I want to move ~all of this to the LinkMonitor by having it maintain a copy of the system's route table so we don't need to re-parse everything.
In the mean time, happy to do this; any suggestions or thoughts on where the callback should be registered, since we don't really have persistent state conveniently available?
There was a problem hiding this comment.
I think for now we don't have to do any of it, was just speculating.
When we do start to do it, triggering the cache invalidation from LocalBackend's linkChange seems like a reasonable place (as far as LocalBackend also enabling this code path to start with).
0a0bf39 to
990d3db
Compare
|
|
||
| // interfaceIndexFor returns the interface index that we should bind to in | ||
| // order to send traffic to the provided address. | ||
| func interfaceIndexFor(addr netip.Addr) (int, error) { |
There was a problem hiding this comment.
I think for now we don't have to do any of it, was just speculating.
When we do start to do it, triggering the cache invalidation from LocalBackend's linkChange seems like a reasonable place (as far as LocalBackend also enabling this code path to start with).
990d3db to
e100711
Compare
|
@mihaip - I wrote a test and refactored this a fair bit; during my testing, I found that it's sometimes possible that the first call to the route APIs returns the gateway IP rather than the interface, and we need to recursively call ourselves (exactly once) to get the interface for a given gateway IP. Mind re-reviewing this? |
…table When turned on via environment variable (off by default), this will use the BSD routing APIs to query what interface index a socket should be bound to, rather than binding to the default interface in all cases. Updates #5719 Updates #5940 Signed-off-by: Andrew Dunham <[email protected]> Change-Id: Ib4c919471f377b7a08cd3413f8e8caacb29fee0b
e100711 to
c3eac0e
Compare
| } | ||
|
|
||
| rm := route.RouteMessage{ | ||
| Version: unix.RTM_VERSION, |
There was a problem hiding this comment.
pin this to a fixed version with comment?
| var buf [2048]byte | ||
| n, err := unix.Read(fd, buf[:]) |
There was a problem hiding this comment.
// safe to do single read because X and smaller than 4KB?
Follow-up to #7065 with some comments from Brad's review. Signed-off-by: Andrew Dunham <[email protected]> Change-Id: Ia1219f4fa25479b2dada38ffe421065b408c5954
Follow-up to #7065 with some comments from Brad's review. Signed-off-by: Andrew Dunham <[email protected]> Change-Id: Ia1219f4fa25479b2dada38ffe421065b408c5954
Follow-up to tailscale#7065 with some comments from Brad's review. Signed-off-by: Andrew Dunham <[email protected]> Change-Id: Ia1219f4fa25479b2dada38ffe421065b408c5954
|
Hi @bradfitz , I've installed tailscale on my Mac via homebrew. I want to enable this feature but couldn't figure out whether I have this feature on my computer (I'm on version 1.72.2) or what to write into nodeAttrs. What's the value to use inside attr part to enable this? |
When turned on via environment variable (off by default), this will use the BSD routing APIs to query what interface index a socket should be bound to, rather than binding to the default interface in all cases.
Updates #5719
Updates #5940
Signed-off-by: Andrew Dunham [email protected]
Change-Id: Ib4c919471f377b7a08cd3413f8e8caacb29fee0b