fix tun_linux_test.go & a nit

This commit is contained in:
Jay Wren
2025-10-23 16:16:40 -04:00
parent 433c531ae4
commit 0a94f9f990
2 changed files with 13 additions and 12 deletions

View File

@@ -282,7 +282,7 @@ func (f *Interface) listenOut(i int) {
plaintext := make([]byte, udp.MTU) plaintext := make([]byte, udp.MTU)
h := &header.H{} h := &header.H{}
fwPacket := &firewall.Packet{} fwPacket := &firewall.Packet{}
nb := make([]byte, 12, 12) nb := make([]byte, 12)
li.ListenOut(func(fromUdpAddr netip.AddrPort, payload []byte) { li.ListenOut(func(fromUdpAddr netip.AddrPort, payload []byte) {
f.readOutsidePackets(fromUdpAddr, nil, plaintext[:0], payload, h, fwPacket, lhh, nb, i, ctCache.Get(f.l)) f.readOutsidePackets(fromUdpAddr, nil, plaintext[:0], payload, h, fwPacket, lhh, nb, i, ctCache.Get(f.l))

View File

@@ -6,26 +6,27 @@ package overlay
import "testing" import "testing"
var runAdvMSSTests = []struct { var runAdvMSSTests = []struct {
name string name string
tun *tun defaultMTU int
r Route maxMTU int
expected int r Route
expected int
}{ }{
// Standard case, default MTU is the device max MTU // Standard case, default MTU is the device max MTU
{"default", &tun{DefaultMTU: 1440, MaxMTU: 1440}, Route{}, 0}, {"default", 1440, 1440, Route{}, 0},
{"default-min", &tun{DefaultMTU: 1440, MaxMTU: 1440}, Route{MTU: 1440}, 0}, {"default-min", 1440, 1440, Route{MTU: 1440}, 0},
{"default-low", &tun{DefaultMTU: 1440, MaxMTU: 1440}, Route{MTU: 1200}, 1160}, {"default-low", 1440, 1440, Route{MTU: 1200}, 1160},
// Case where we have a route MTU set higher than the default // Case where we have a route MTU set higher than the default
{"route", &tun{DefaultMTU: 1440, MaxMTU: 8941}, Route{}, 1400}, {"route", 1440, 8941, Route{}, 1400},
{"route-min", &tun{DefaultMTU: 1440, MaxMTU: 8941}, Route{MTU: 1440}, 1400}, {"route-min", 1440, 8941, Route{MTU: 1440}, 1400},
{"route-high", &tun{DefaultMTU: 1440, MaxMTU: 8941}, Route{MTU: 8941}, 0}, {"route-high", 1440, 8941, Route{MTU: 8941}, 0},
} }
func TestTunAdvMSS(t *testing.T) { func TestTunAdvMSS(t *testing.T) {
for _, tt := range runAdvMSSTests { for _, tt := range runAdvMSSTests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
o := tt.tun.advMSS(tt.r) o := advMSS(tt.r, tt.defaultMTU, tt.maxMTU)
if o != tt.expected { if o != tt.expected {
t.Errorf("got %d, want %d", o, tt.expected) t.Errorf("got %d, want %d", o, tt.expected)
} }