Skip to content

Commit 6fa58aa

Browse files
committed
TUN-5623: Configure quic max datagram frame size to 1350 bytes for none Windows platforms
1 parent ef3152f commit 6fa58aa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+11652
-57
lines changed

connection/quic_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,8 +560,7 @@ func serveSession(ctx context.Context, qc *QUICConnection, edgeQUICSession quic.
560560
}()
561561

562562
// Send a message to the quic session on edge side, it should be deumx to this datagram session
563-
muxedPayload, err := quicpogs.SuffixSessionID(sessionID, payload)
564-
require.NoError(t, err)
563+
muxedPayload := append(payload, sessionID[:]...)
565564
err = edgeQUICSession.SendMessage(muxedPayload)
566565
require.NoError(t, err)
567566

datagramsession/session.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func (s *Session) dstToTransport(buffer []byte) error {
114114
s.log.Debug().
115115
Str("session", s.ID.String()).
116116
Int("len", n).
117-
Uint("mtu", s.transport.MTU()).
117+
Int("mtu", s.transport.MTU()).
118118
Msg("dropped packet exceeding MTU")
119119
}
120120
}

datagramsession/transport.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ type transport interface {
99
// ReceiveFrom reads the next datagram from the transport
1010
ReceiveFrom() (uuid.UUID, []byte, error)
1111
// Max transmission unit to receive from the transport
12-
MTU() uint
12+
MTU() int
1313
}

datagramsession/transport_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ func (mt *mockQUICTransport) ReceiveFrom() (uuid.UUID, []byte, error) {
2222
return mt.reqChan.Receive(context.Background())
2323
}
2424

25-
func (mt *mockQUICTransport) MTU() uint {
26-
return 1217
25+
func (mt *mockQUICTransport) MTU() int {
26+
return 1280
2727
}
2828

2929
func (mt *mockQUICTransport) newRequest(ctx context.Context, sessionID uuid.UUID, payload []byte) error {

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ require (
7878
github.com/lucasb-eyer/go-colorful v1.0.3 // indirect
7979
github.com/marten-seemann/qtls-go1-16 v0.1.4 // indirect
8080
github.com/marten-seemann/qtls-go1-17 v0.1.0 // indirect
81+
github.com/marten-seemann/qtls-go1-18 v0.1.0-beta.1 // indirect
8182
github.com/mattn/go-isatty v0.0.12 // indirect
8283
github.com/mattn/go-runewidth v0.0.8 // indirect
8384
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
@@ -98,3 +99,5 @@ require (
9899
)
99100

100101
replace github.com/urfave/cli/v2 => github.com/ipostelnik/cli/v2 v2.3.1-0.20210324024421-b6ea8234fe3d
102+
103+
replace github.com/lucas-clemente/quic-go => github.com/chungthuang/quic-go v0.24.1-0.20220110095058-981dc498cb62

go.sum

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@ github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+
125125
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
126126
github.com/cheekybits/genny v1.0.0 h1:uGGa4nei+j20rOSeDeP5Of12XVm7TGUd4dJA9RDitfE=
127127
github.com/cheekybits/genny v1.0.0/go.mod h1:+tQajlRqAUrPI7DOSpB0XAqZYtQakVtB7wXkRAgjxjQ=
128+
github.com/chungthuang/quic-go v0.24.1-0.20220106111256-154e7d8a89a9 h1:sHrAhwM2NHkb/5z7+cxDFMCvG3WnSAPbjqSbujLB3nU=
129+
github.com/chungthuang/quic-go v0.24.1-0.20220106111256-154e7d8a89a9/go.mod h1:YtzP8bxRVCBlO77yRanE264+fY/T2U9ZlW1AaHOsMOg=
130+
github.com/chungthuang/quic-go v0.24.1-0.20220106164320-fc99d36b9daa h1:QSi2gWSBtNtCH2/8Y6zFs4H5bnrHQQxFCzl7zJsPp28=
131+
github.com/chungthuang/quic-go v0.24.1-0.20220106164320-fc99d36b9daa/go.mod h1:YtzP8bxRVCBlO77yRanE264+fY/T2U9ZlW1AaHOsMOg=
132+
github.com/chungthuang/quic-go v0.24.1-0.20220110095058-981dc498cb62 h1:PLTB4iA6sOgAItzQY642tYdcGKfG/7i2gu93JQGgUcM=
133+
github.com/chungthuang/quic-go v0.24.1-0.20220110095058-981dc498cb62/go.mod h1:YtzP8bxRVCBlO77yRanE264+fY/T2U9ZlW1AaHOsMOg=
128134
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
129135
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
130136
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
@@ -440,6 +446,8 @@ github.com/marten-seemann/qtls-go1-16 v0.1.4 h1:xbHbOGGhrenVtII6Co8akhLEdrawwB2i
440446
github.com/marten-seemann/qtls-go1-16 v0.1.4/go.mod h1:gNpI2Ol+lRS3WwSOtIUUtRwZEQMXjYK+dQSBFbethAk=
441447
github.com/marten-seemann/qtls-go1-17 v0.1.0 h1:P9ggrs5xtwiqXv/FHNwntmuLMNq3KaSIG93AtAZ48xk=
442448
github.com/marten-seemann/qtls-go1-17 v0.1.0/go.mod h1:fz4HIxByo+LlWcreM4CZOYNuz3taBQ8rN2X6FqvaWo8=
449+
github.com/marten-seemann/qtls-go1-18 v0.1.0-beta.1 h1:EnzzN9fPUkUck/1CuY1FlzBaIYMoiBsdwTNmNGkwUUM=
450+
github.com/marten-seemann/qtls-go1-18 v0.1.0-beta.1/go.mod h1:PUhIQk19LoFt2174H4+an8TYvWOGjb/hHwphBeaDHwI=
443451
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
444452
github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8=
445453
github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=

origin/tunnel.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,7 @@ func ServeQUIC(
526526
MaxIncomingUniStreams: connection.MaxConcurrentStreams,
527527
KeepAlive: true,
528528
EnableDatagrams: true,
529+
MaxDatagramFrameSize: quicpogs.MaxDatagramFrameSize,
529530
Tracer: quicpogs.NewClientTracer(connLogger.Logger(), connIndex),
530531
}
531532

quic/datagram.go

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ import (
99
)
1010

1111
const (
12-
// Max datagram frame size is limited to 1220 https://github.com/lucas-clemente/quic-go/blob/v0.24.0/internal/protocol/params.go#L138
13-
// However, 3 more bytes are reserved https://github.com/lucas-clemente/quic-go/blob/v0.24.0/internal/wire/datagram_frame.go#L61
14-
MaxDatagramFrameSize = 1217
15-
sessionIDLen = len(uuid.UUID{})
12+
sessionIDLen = len(uuid.UUID{})
1613
)
1714

1815
type DatagramMuxer struct {
@@ -34,11 +31,11 @@ func NewDatagramMuxer(quicSession quic.Session) (*DatagramMuxer, error) {
3431
// SendTo suffix the session ID to the payload so the other end of the QUIC session can demultiplex
3532
// the payload from multiple datagram sessions
3633
func (dm *DatagramMuxer) SendTo(sessionID uuid.UUID, payload []byte) error {
37-
if len(payload) > MaxDatagramFrameSize-sessionIDLen {
34+
if len(payload) > maxDatagramPayloadSize {
3835
// TODO: TUN-5302 return ICMP packet too big message
3936
return fmt.Errorf("origin UDP payload has %d bytes, which exceeds transport MTU %d", len(payload), dm.MTU())
4037
}
41-
msgWithID, err := SuffixSessionID(sessionID, payload)
38+
msgWithID, err := suffixSessionID(sessionID, payload)
4239
if err != nil {
4340
return errors.Wrap(err, "Failed to suffix session ID to datagram, it will be dropped")
4441
}
@@ -56,17 +53,17 @@ func (dm *DatagramMuxer) ReceiveFrom() (uuid.UUID, []byte, error) {
5653
if err != nil {
5754
return uuid.Nil, nil, err
5855
}
59-
return ExtractSessionID(msg)
56+
return extractSessionID(msg)
6057
}
6158

6259
// Maximum application payload to send to / receive from QUIC datagram frame
63-
func (dm *DatagramMuxer) MTU() uint {
64-
return uint(MaxDatagramFrameSize - sessionIDLen)
60+
func (dm *DatagramMuxer) MTU() int {
61+
return maxDatagramPayloadSize
6562
}
6663

6764
// Each QUIC datagram should be suffixed with session ID.
68-
// ExtractSessionID extracts the session ID and a slice with only the payload
69-
func ExtractSessionID(b []byte) (uuid.UUID, []byte, error) {
65+
// extractSessionID extracts the session ID and a slice with only the payload
66+
func extractSessionID(b []byte) (uuid.UUID, []byte, error) {
7067
msgLen := len(b)
7168
if msgLen < sessionIDLen {
7269
return uuid.Nil, nil, fmt.Errorf("session ID has %d bytes, but data only has %d", sessionIDLen, len(b))
@@ -82,7 +79,7 @@ func ExtractSessionID(b []byte) (uuid.UUID, []byte, error) {
8279

8380
// SuffixSessionID appends the session ID at the end of the payload. Suffix is more performant than prefix because
8481
// the payload slice might already have enough capacity to append the session ID at the end
85-
func SuffixSessionID(sessionID uuid.UUID, b []byte) ([]byte, error) {
82+
func suffixSessionID(sessionID uuid.UUID, b []byte) ([]byte, error) {
8683
if len(b)+len(sessionID) > MaxDatagramFrameSize {
8784
return nil, fmt.Errorf("datagram size exceed %d", MaxDatagramFrameSize)
8885
}

quic/datagram_test.go

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"encoding/pem"
1111
"math/big"
1212
"testing"
13+
"time"
1314

1415
"github.com/google/uuid"
1516
"github.com/lucas-clemente/quic-go"
@@ -23,11 +24,11 @@ var (
2324

2425
func TestSuffixThenRemoveSessionID(t *testing.T) {
2526
msg := []byte(t.Name())
26-
msgWithID, err := SuffixSessionID(testSessionID, msg)
27+
msgWithID, err := suffixSessionID(testSessionID, msg)
2728
require.NoError(t, err)
2829
require.Len(t, msgWithID, len(msg)+sessionIDLen)
2930

30-
sessionID, msgWithoutID, err := ExtractSessionID(msgWithID)
31+
sessionID, msgWithoutID, err := extractSessionID(msgWithID)
3132
require.NoError(t, err)
3233
require.Equal(t, msg, msgWithoutID)
3334
require.Equal(t, testSessionID, sessionID)
@@ -36,26 +37,27 @@ func TestSuffixThenRemoveSessionID(t *testing.T) {
3637
func TestRemoveSessionIDError(t *testing.T) {
3738
// message is too short to contain session ID
3839
msg := []byte("test")
39-
_, _, err := ExtractSessionID(msg)
40+
_, _, err := extractSessionID(msg)
4041
require.Error(t, err)
4142
}
4243

4344
func TestSuffixSessionIDError(t *testing.T) {
4445
msg := make([]byte, MaxDatagramFrameSize-sessionIDLen)
45-
_, err := SuffixSessionID(testSessionID, msg)
46+
_, err := suffixSessionID(testSessionID, msg)
4647
require.NoError(t, err)
4748

4849
msg = make([]byte, MaxDatagramFrameSize-sessionIDLen+1)
49-
_, err = SuffixSessionID(testSessionID, msg)
50+
_, err = suffixSessionID(testSessionID, msg)
5051
require.Error(t, err)
5152
}
5253

5354
func TestMaxDatagramPayload(t *testing.T) {
54-
payload := make([]byte, MaxDatagramFrameSize-sessionIDLen)
55+
payload := make([]byte, maxDatagramPayloadSize)
5556

5657
quicConfig := &quic.Config{
57-
KeepAlive: true,
58-
EnableDatagrams: true,
58+
KeepAlive: true,
59+
EnableDatagrams: true,
60+
MaxDatagramFrameSize: MaxDatagramFrameSize,
5961
}
6062
quicListener := newQUICListener(t, quicConfig)
6163
defer quicListener.Close()
@@ -65,13 +67,19 @@ func TestMaxDatagramPayload(t *testing.T) {
6567
errGroup.Go(func() error {
6668
// Accept quic connection
6769
quicSession, err := quicListener.Accept(ctx)
68-
require.NoError(t, err)
70+
if err != nil {
71+
return err
72+
}
6973

7074
muxer, err := NewDatagramMuxer(quicSession)
71-
require.NoError(t, err)
75+
if err != nil {
76+
return err
77+
}
7278

7379
sessionID, receivedPayload, err := muxer.ReceiveFrom()
74-
require.NoError(t, err)
80+
if err != nil {
81+
return err
82+
}
7583
require.Equal(t, testSessionID, sessionID)
7684
require.True(t, bytes.Equal(payload, receivedPayload))
7785

@@ -89,13 +97,19 @@ func TestMaxDatagramPayload(t *testing.T) {
8997
require.NoError(t, err)
9098

9199
muxer, err := NewDatagramMuxer(quicSession)
92-
require.NoError(t, err)
100+
if err != nil {
101+
return err
102+
}
93103

104+
// Wait a few milliseconds for MTU discovery to take place
105+
time.Sleep(time.Millisecond * 100)
94106
err = muxer.SendTo(testSessionID, payload)
95-
require.NoError(t, err)
107+
if err != nil {
108+
return err
109+
}
96110

97111
// Payload larger than transport MTU, should return an error
98-
largePayload := append(payload, byte(1))
112+
largePayload := make([]byte, MaxDatagramFrameSize)
99113
err = muxer.SendTo(testSessionID, largePayload)
100114
require.Error(t, err)
101115

quic/param_unix.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//go:build !windows
2+
3+
package quic
4+
5+
const (
6+
MaxDatagramFrameSize = 1350
7+
// maxDatagramPayloadSize is the maximum packet size allowed by warp client
8+
maxDatagramPayloadSize = 1280
9+
)

0 commit comments

Comments
 (0)