forked from tailscale/tailscale
-
Notifications
You must be signed in to change notification settings - Fork 4
fix: stop selecting direct connections with too-small MTU #85
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
bede4fb
feat: pad disco ping/pong and enable path mtu on Windows
spikecurtis 1bab46f
feat: set path MTU discover on Linux
spikecurtis ef3f81d
feat: set IP_DONTFRAG on macOS
spikecurtis c89c6b7
logs and comments
spikecurtis 4686156
fix: check Disco Ping/Pong length in unit tests
spikecurtis 6923084
restyle constant defs on Windows
spikecurtis b824a9c
make ping/pong test explicit
spikecurtis 4ec7ef5
import ordering
spikecurtis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package magicsock | ||
|
||
import ( | ||
"net" | ||
|
||
"golang.org/x/sys/unix" | ||
"tailscale.com/types/logger" | ||
"tailscale.com/types/nettype" | ||
) | ||
|
||
func tryPreventFragmentation(pconn nettype.PacketConn, logf logger.Logf, network string) { | ||
if c, ok := pconn.(*net.UDPConn); ok { | ||
s, err := c.SyscallConn() | ||
if err != nil { | ||
logf("magicsock: dontfrag: failed to get syscall conn: %v", err) | ||
} | ||
level := unix.IPPROTO_IP | ||
option := unix.IP_DONTFRAG | ||
if network == "udp6" { | ||
level = unix.IPPROTO_IPV6 | ||
option = unix.IPV6_DONTFRAG | ||
} | ||
err = s.Control(func(fd uintptr) { | ||
err := unix.SetsockoptInt(int(fd), level, option, 1) | ||
if err != nil { | ||
logf("magicsock: dontfrag: SetsockoptInt failed: %v", err) | ||
} | ||
}) | ||
if err != nil { | ||
logf("magicsock: dontfrag: control connection failed: %v", err) | ||
} | ||
logf("magicsock: dontfrag: success on %s", pconn.LocalAddr().String()) | ||
return | ||
} | ||
logf("magicsock: dontfrag: failed because it was not a UDPConn") | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package magicsock | ||
|
||
import ( | ||
"net" | ||
|
||
"golang.org/x/sys/windows" | ||
"tailscale.com/types/logger" | ||
"tailscale.com/types/nettype" | ||
) | ||
|
||
// https://github.com/tpn/winsdk-10/blob/9b69fd26ac0c7d0b83d378dba01080e93349c2ed/Include/10.0.16299.0/shared/ws2ipdef.h | ||
const ( | ||
IP_MTU_DISCOVER = 71 // IPV6_MTU_DISCOVER has the same value, which is nice. | ||
IP_PMTUDISC_DO = 1 | ||
) | ||
|
||
func tryPreventFragmentation(pconn nettype.PacketConn, logf logger.Logf, network string) { | ||
if c, ok := pconn.(*net.UDPConn); ok { | ||
s, err := c.SyscallConn() | ||
if err != nil { | ||
logf("magicsock: dontfrag: failed to get syscall conn: %v", err) | ||
} | ||
level := windows.IPPROTO_IP | ||
if network == "udp6" { | ||
level = windows.IPPROTO_IPV6 | ||
} | ||
err = s.Control(func(fd uintptr) { | ||
err := windows.SetsockoptInt(windows.Handle(fd), level, IP_MTU_DISCOVER, IP_PMTUDISC_DO) | ||
if err != nil { | ||
logf("magicsock: dontfrag: SetsockoptInt failed: %v", err) | ||
} | ||
}) | ||
if err != nil { | ||
logf("magicsock: dontfrag: control connection failed: %v", err) | ||
} | ||
logf("magicsock: dontfrag: success on %s", pconn.LocalAddr().String()) | ||
return | ||
} | ||
logf("magicsock: dontfrag: failed because it was not a UDPConn") | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we expect the end of the ping payload to be a bunch of 00s we should probably test that, either by changing the
want
for each of the ping/pong cases to be the full value or by some other methodThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't care that it's zeros per se, but I'll add a check that it's the padded length.