summaryrefslogtreecommitdiffhomepage
path: root/tun/tcp_offload_linux_test.go
diff options
context:
space:
mode:
authorJordan Whited <jordan@tailscale.com>2023-03-24 15:09:47 -0700
committerJason A. Donenfeld <Jason@zx2c4.com>2023-03-25 23:13:26 +0100
commitaad7fca9c504effdaf3c77dd635e85c94dc4521d (patch)
tree979f44489e900643a8d8499516987b14563f7cab /tun/tcp_offload_linux_test.go
parent6f895be10d741d138ec240d3c53acf3afde44b6c (diff)
tun: disqualify tcp4 packets w/IP options from coalescing
IP options were not being compared prior to coalescing. They are not commonly used. Disqualification due to nonzero options is in line with the kernel. Reviewed-by: Denton Gentry <dgentry@tailscale.com> Signed-off-by: Jordan Whited <jordan@tailscale.com> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'tun/tcp_offload_linux_test.go')
-rw-r--r--tun/tcp_offload_linux_test.go50
1 files changed, 50 insertions, 0 deletions
diff --git a/tun/tcp_offload_linux_test.go b/tun/tcp_offload_linux_test.go
index 11f9e53..046e177 100644
--- a/tun/tcp_offload_linux_test.go
+++ b/tun/tcp_offload_linux_test.go
@@ -271,3 +271,53 @@ func Test_handleGRO(t *testing.T) {
})
}
}
+
+func Test_isTCP4NoIPOptions(t *testing.T) {
+ valid := tcp4Packet(ip4PortA, ip4PortB, header.TCPFlagAck, 100, 1)[virtioNetHdrLen:]
+ invalidLen := valid[:39]
+ invalidHeaderLen := make([]byte, len(valid))
+ copy(invalidHeaderLen, valid)
+ invalidHeaderLen[0] = 0x46
+ invalidProtocol := make([]byte, len(valid))
+ copy(invalidProtocol, valid)
+ invalidProtocol[9] = unix.IPPROTO_TCP + 1
+
+ tests := []struct {
+ name string
+ b []byte
+ want bool
+ }{
+ {
+ "valid",
+ valid,
+ true,
+ },
+ {
+ "invalid length",
+ invalidLen,
+ false,
+ },
+ {
+ "invalid version",
+ []byte{0x00},
+ false,
+ },
+ {
+ "invalid header len",
+ invalidHeaderLen,
+ false,
+ },
+ {
+ "invalid protocol",
+ invalidProtocol,
+ false,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if got := isTCP4NoIPOptions(tt.b); got != tt.want {
+ t.Errorf("isTCP4NoIPOptions() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}