forked from WireGuard/wireguard-go
-
Notifications
You must be signed in to change notification settings - Fork 39
tun: coalesce zero-checksum UDP datagrams in UDP GRO (VXLAN/Cilium) #70
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
Open
cagataygurturk
wants to merge
1
commit into
tailscale:tailscale
Choose a base branch
from
cagataygurturk:udp-gro-zero-checksum
base: tailscale
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -274,6 +274,55 @@ func flipUDP4Checksum(b []byte) []byte { | |
| return b | ||
| } | ||
|
|
||
| // zeroUDP4Checksum clears the UDP checksum field, which per RFC 768 signals | ||
| // "no checksum" for IPv4 UDP. VXLAN encapsulators commonly emit such datagrams. | ||
| func zeroUDP4Checksum(b []byte) []byte { | ||
| at := virtioNetHdrLen + 20 + 6 // 20 byte ipv4 header; udp csum offset is 6 | ||
| b[at] = 0 | ||
| b[at+1] = 0 | ||
| return b | ||
| } | ||
|
|
||
| // Test_handleGRO_zeroChecksumUDPCoalesces verifies that IPv4 UDP datagrams | ||
| // carrying a zero (absent, per RFC 768) checksum are coalesced by UDP GRO, while | ||
| // a genuinely bad checksum is still refused. Zero-checksum outer UDP is the | ||
| // common shape for VXLAN-encapsulated traffic (e.g. Cilium). | ||
| func Test_handleGRO_zeroChecksumUDPCoalesces(t *testing.T) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have a table test in Test_handleGRO that can be extended with this case. Consider also extending Fuzz_handleGRO. |
||
| pktsIn := [][]byte{ | ||
| zeroUDP4Checksum(udp4Packet(ip4PortA, ip4PortB, 100)), // udp4 flow 1, no checksum | ||
| zeroUDP4Checksum(udp4Packet(ip4PortA, ip4PortB, 100)), // udp4 flow 1, no checksum | ||
| zeroUDP4Checksum(udp4Packet(ip4PortA, ip4PortB, 100)), // udp4 flow 1, no checksum | ||
| flipUDP4Checksum(udp4Packet(ip4PortA, ip4PortC, 100)), // udp4 flow 2, genuinely bad checksum | ||
| } | ||
| want := [][]int{ | ||
| {virtioNetHdrLen, 128, 100, 100}, // flow 1: three zero-csum datagrams coalesced | ||
| {virtioNetHdrLen, 128}, // flow 2: bad csum, unmerged | ||
| } | ||
|
|
||
| wi := newGROToWrite() | ||
| pkts := make([][]byte, len(pktsIn)) | ||
| for k, p := range pktsIn { | ||
| pkts[k] = slices.Clone(p) | ||
| } | ||
| if err := handleGRO(pkts, offset, newTCPGROTable(), newUDPGROTable(), 0, &wi); err != nil { | ||
| t.Fatalf("handleGRO: %v", err) | ||
| } | ||
| if len(wi.iovs) != len(want) { | ||
| t.Fatalf("got %d outputs, want %d", len(wi.iovs), len(want)) | ||
| } | ||
| for i, wantFragLens := range want { | ||
| iov := wi.iovs[i] | ||
| if len(iov) != len(wantFragLens) { | ||
| t.Fatalf("output[%d]: got %d fragments, want %d", i, len(iov), len(wantFragLens)) | ||
| } | ||
| for j, wantLen := range wantFragLens { | ||
| if len(iov[j]) != wantLen { | ||
| t.Errorf("output[%d][%d]: got len %d, want %d", i, j, len(iov[j]), wantLen) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func Fuzz_handleGRO(f *testing.F) { | ||
| pkt0 := tcp4Packet(ip4PortA, ip4PortB, header.TCPFlagAck, 100, 1) | ||
| pkt1 := tcp4Packet(ip4PortA, ip4PortB, header.TCPFlagAck, 100, 101) | ||
|
|
||
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.
checksumValid takes the proto field, what benefit do you see in a UDP-specific wrapper?