mirror of
https://git.zx2c4.com/wireguard-go
synced 2025-10-05 16:47:02 +08:00
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>
This commit is contained in:

committed by
Jason A. Donenfeld

parent
6f895be10d
commit
aad7fca9c5
@@ -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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user