Skip to content

net/interfaces: improve default route detection - #5940

Merged
knyar merged 2 commits into
mainfrom
knyar/macos-bsd-routing
Oct 19, 2022
Merged

knyar merged 2 commits into
mainfrom
knyar/macos-bsd-routing

Conversation

@knyar

@knyar knyar commented Oct 14, 2022 •

Copy link
Copy Markdown
Contributor

Instead of treating any interface with a non-ifscope route as a potential default gateway, now verify that a given route is actually a default route (0.0.0.0/0 or ::/0). Only applies to macOS and FreeBSD.

I would suggest reviewing each commit separately.

Fixes #5879

@knyar
knyar requested a review from bradfitz October 14, 2022 15:45
@knyar
knyar marked this pull request as ready for review October 14, 2022 15:45
@knyar
knyar force-pushed the knyar/macos-bsd-routing branch from cc70123 to 9fe1278 Compare October 18, 2022 17:51
Comment thread net/interfaces/interfaces_bsd.go Resolved
Comment on lines +120 to +128
if len(rm.Addrs) <= unix.RTAX_NETMASK {
return false
}

dst := rm.Addrs[unix.RTAX_DST]
netmask := rm.Addrs[unix.RTAX_NETMASK]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume RTAX_DST is less than RTAX_NETMASK? :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, added a comment to clarify this.

knyar added 2 commits October 19, 2022 10:49
Instead of treating any interface with a non-ifscope route as a
potential default gateway, now verify that a given route is
actually a default route (0.0.0.0/0 or ::/0).

Fixes #5879

Signed-off-by: Anton Tolchanov <[email protected]>
@knyar
knyar force-pushed the knyar/macos-bsd-routing branch from 9fe1278 to 7c09b9a Compare October 19, 2022 09:55
@knyar
knyar merged commit d499afa into main Oct 19, 2022
@knyar
knyar deleted the knyar/macos-bsd-routing branch October 19, 2022 10:10
andrew-d added a commit that referenced this pull request Jan 25, 2023
…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
andrew-d added a commit that referenced this pull request Jan 25, 2023
…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
andrew-d added a commit that referenced this pull request Jan 25, 2023
…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
andrew-d added a commit that referenced this pull request Jan 25, 2023
…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
andrew-d added a commit that referenced this pull request Jan 26, 2023
…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
andrew-d added a commit that referenced this pull request Jan 27, 2023
…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
coadler pushed a commit to coder/tailscale that referenced this pull request Feb 2, 2023
…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 tailscale#5719
Updates tailscale#5940

Signed-off-by: Andrew Dunham <[email protected]>
Change-Id: Ib4c919471f377b7a08cd3413f8e8caacb29fee0b
mihaip pushed a commit that referenced this pull request Feb 8, 2023
…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
(cherry picked from commit 2703d69,
with the CurrentCapabilityVersion change reverted)
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 this pull request may close these issues.

High CPU and network bandwidth usage at special gateways

2 participants