diff --git a/connection.go b/connection.go index cacbbf4..25ad6af 100644 --- a/connection.go +++ b/connection.go @@ -294,6 +294,37 @@ func NewDefaultConnection(address string, serverName string, resumptionTicket [] c = NewConnection(serverName, QuicVersion, QuicALPNToken, scid, dcid, udpConn, resumptionTicket) } + var headerOverhead = 8 + if useIPv6 { + headerOverhead += 40 + } else { + headerOverhead += 20 + } + + lAddr := udpConn.LocalAddr().(*net.UDPAddr) + itfs, err := net.Interfaces() + if err != nil { + return nil, err + } + +findMTU: + for _, e := range itfs { + addrs , err := e.Addrs() + if err != nil { + return nil, err + } + for _, a := range addrs { + switch ipNet := a.(type) { + case *net.IPNet: + if ipNet.IP.Equal(lAddr.IP) { + c.InterfaceMTU = e.MTU + c.TLSTPHandler.MaxPacketSize = uint64(c.InterfaceMTU - headerOverhead) + break findMTU + } + } + } + } + c.UseIPv6 = useIPv6 c.Host = udpAddr return c, nil diff --git a/transport_parameters.go b/transport_parameters.go index b70352a..71853db 100644 --- a/transport_parameters.go +++ b/transport_parameters.go @@ -122,6 +122,9 @@ func (h *TLSTransportParameterHandler) GetExtensionData() ([]byte, error) { addParameter(InitialMaxStreamsUni, h.QuicTransportParameters.MaxUniStreams) addParameter(IdleTimeout, h.QuicTransportParameters.IdleTimeout) addParameter(ActiveConnectionIdLimit, h.QuicTransportParameters.ActiveConnectionIdLimit) + if h.QuicTransportParameters.MaxPacketSize > 0 { + addParameter(MaxPacketSize, h.QuicTransportParameters.MaxPacketSize) + } for _, p := range h.QuicTransportParameters.AdditionalParameters { parameters = append(parameters, p) }