diff --git a/config.go b/config.go index fbd6da17975..1808e9ef48b 100644 --- a/config.go +++ b/config.go @@ -101,6 +101,10 @@ func populateConfig(config *Config) *Config { } else if maxIncomingUniStreams < 0 { maxIncomingUniStreams = 0 } + maxDatagrameFrameSize := config.MaxDatagramFrameSize + if maxDatagrameFrameSize == 0 { + maxDatagrameFrameSize = int64(protocol.DefaultMaxDatagramFrameSize) + } return &Config{ GetConfigForClient: config.GetConfigForClient, @@ -120,6 +124,7 @@ func populateConfig(config *Config) *Config { MaxIncomingUniStreams: maxIncomingUniStreams, TokenStore: config.TokenStore, EnableDatagrams: config.EnableDatagrams, + MaxDatagramFrameSize: maxDatagrameFrameSize, DisablePathMTUDiscovery: config.DisablePathMTUDiscovery, DisableVersionNegotiationPackets: config.DisableVersionNegotiationPackets, Allow0RTT: config.Allow0RTT, diff --git a/config_test.go b/config_test.go index 53482ca48c7..6cd951f88c0 100644 --- a/config_test.go +++ b/config_test.go @@ -83,6 +83,8 @@ var _ = Describe("Config", func() { f.Set(reflect.ValueOf(time.Second)) case "EnableDatagrams": f.Set(reflect.ValueOf(true)) + case "MaxDatagramFrameSize": + f.Set(reflect.ValueOf(int64(1200))) case "DisableVersionNegotiationPackets": f.Set(reflect.ValueOf(true)) case "DisablePathMTUDiscovery": @@ -175,6 +177,7 @@ var _ = Describe("Config", func() { Expect(c.MaxIncomingUniStreams).To(BeEquivalentTo(protocol.DefaultMaxIncomingUniStreams)) Expect(c.DisableVersionNegotiationPackets).To(BeFalse()) Expect(c.DisablePathMTUDiscovery).To(BeFalse()) + Expect(c.MaxDatagramFrameSize).To(BeEquivalentTo(protocol.DefaultMaxDatagramFrameSize)) Expect(c.GetConfigForClient).To(BeNil()) }) diff --git a/connection.go b/connection.go index 6833a7b9468..ae431804951 100644 --- a/connection.go +++ b/connection.go @@ -317,7 +317,7 @@ var newConnection = func( RetrySourceConnectionID: retrySrcConnID, } if s.config.EnableDatagrams { - params.MaxDatagramFrameSize = protocol.MaxDatagramFrameSize + params.MaxDatagramFrameSize = protocol.ByteCount(s.config.MaxDatagramFrameSize) } else { params.MaxDatagramFrameSize = protocol.InvalidByteCount } @@ -430,7 +430,7 @@ var newClientConnection = func( InitialSourceConnectionID: srcConnID, } if s.config.EnableDatagrams { - params.MaxDatagramFrameSize = protocol.MaxDatagramFrameSize + params.MaxDatagramFrameSize = protocol.ByteCount(s.config.MaxDatagramFrameSize) } else { params.MaxDatagramFrameSize = protocol.InvalidByteCount } @@ -1493,7 +1493,7 @@ func (s *connection) handleAckFrame(frame *wire.AckFrame, encLevel protocol.Encr } func (s *connection) handleDatagramFrame(f *wire.DatagramFrame) error { - if f.Length(s.version) > protocol.MaxDatagramFrameSize { + if f.Length(s.version) > protocol.ByteCount(s.config.MaxDatagramFrameSize) { return &qerr.TransportError{ ErrorCode: qerr.ProtocolViolation, ErrorMessage: "DATAGRAM frame too large", diff --git a/interface.go b/interface.go index 7022cac4eab..ed6af8ae179 100644 --- a/interface.go +++ b/interface.go @@ -322,7 +322,9 @@ type Config struct { Allow0RTT bool // Enable QUIC datagram support (RFC 9221). EnableDatagrams bool - Tracer func(context.Context, logging.Perspective, ConnectionID) logging.ConnectionTracer + // Maximum size of QUIC datagram frames (RFC 9221). + MaxDatagramFrameSize int64 + Tracer func(context.Context, logging.Perspective, ConnectionID) logging.ConnectionTracer } type ClientHelloInfo struct { diff --git a/internal/protocol/params.go b/internal/protocol/params.go index 60c8677944c..970fe190a60 100644 --- a/internal/protocol/params.go +++ b/internal/protocol/params.go @@ -132,9 +132,9 @@ const MaxPostHandshakeCryptoFrameSize = 1000 // but must ensure that a maximum size ACK frame fits into one packet. const MaxAckFrameSize ByteCount = 1000 -// MaxDatagramFrameSize is the maximum size of a DATAGRAM frame (RFC 9221). +// DefaultMaxDatagramFrameSize is the maximum size of a DATAGRAM frame (RFC 9221). // The size is chosen such that a DATAGRAM frame fits into a QUIC packet. -const MaxDatagramFrameSize ByteCount = 1200 +const DefaultMaxDatagramFrameSize ByteCount = 1200 // DatagramRcvQueueLen is the length of the receive queue for DATAGRAM frames (RFC 9221) const DatagramRcvQueueLen = 128