mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-03 20:27:35 +03:00
qlog when packets are dropped due to unsupported QUIC version
This commit is contained in:
parent
899e1694d7
commit
f58eb47383
5 changed files with 24 additions and 7 deletions
|
@ -42,7 +42,7 @@ func IsVersionNegotiationPacket(b []byte) bool {
|
|||
return b[0]&0x80 > 0 && b[1] == 0 && b[2] == 0 && b[3] == 0 && b[4] == 0
|
||||
}
|
||||
|
||||
var errUnsupportedVersion = errors.New("unsupported version")
|
||||
var ErrUnsupportedVersion = errors.New("unsupported version")
|
||||
|
||||
// The Header is the version independent part of the header
|
||||
type Header struct {
|
||||
|
@ -69,8 +69,8 @@ type Header struct {
|
|||
func ParsePacket(data []byte, shortHeaderConnIDLen int) (*Header, []byte /* packet data */, []byte /* rest */, error) {
|
||||
hdr, err := parseHeader(bytes.NewReader(data), shortHeaderConnIDLen)
|
||||
if err != nil {
|
||||
if err == errUnsupportedVersion {
|
||||
return hdr, nil, nil, nil
|
||||
if err == ErrUnsupportedVersion {
|
||||
return hdr, nil, nil, ErrUnsupportedVersion
|
||||
}
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
|
@ -160,7 +160,7 @@ func (h *Header) parseLongHeader(b *bytes.Reader) error {
|
|||
}
|
||||
// If we don't understand the version, we have no idea how to interpret the rest of the bytes
|
||||
if !protocol.IsSupportedVersion(protocol.SupportedVersions, h.Version) {
|
||||
return errUnsupportedVersion
|
||||
return ErrUnsupportedVersion
|
||||
}
|
||||
|
||||
switch (h.typeByte & 0x30) >> 4 {
|
||||
|
|
|
@ -213,7 +213,7 @@ var _ = Describe("Header Parsing", func() {
|
|||
'f', 'o', 'o', 'b', 'a', 'r', // unspecified bytes
|
||||
}
|
||||
hdr, _, rest, err := ParsePacket(data, 0)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(err).To(MatchError(ErrUnsupportedVersion))
|
||||
Expect(hdr.IsLongHeader).To(BeTrue())
|
||||
Expect(hdr.Version).To(Equal(protocol.VersionNumber(0xdeadbeef)))
|
||||
Expect(hdr.DestConnectionID).To(Equal(protocol.ConnectionID{0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8}))
|
||||
|
|
|
@ -296,7 +296,7 @@ func (s *baseServer) handlePacketImpl(p *receivedPacket) bool /* was the packet
|
|||
// If we're creating a new session, the packet will be passed to the session.
|
||||
// The header will then be parsed again.
|
||||
hdr, _, _, err := wire.ParsePacket(p.data, s.config.ConnectionIDLength)
|
||||
if err != nil {
|
||||
if err != nil && err != wire.ErrUnsupportedVersion {
|
||||
s.logger.Debugf("Error parsing packet: %s", err)
|
||||
return false
|
||||
}
|
||||
|
|
|
@ -710,7 +710,11 @@ func (s *session) handlePacketImpl(rp *receivedPacket) bool {
|
|||
hdr, packetData, rest, err := wire.ParsePacket(p.data, s.srcConnIDLen)
|
||||
if err != nil {
|
||||
if s.qlogger != nil {
|
||||
s.qlogger.DroppedPacket(qlog.PacketTypeNotDetermined, protocol.ByteCount(len(data)), qlog.PacketDropHeaderParseError)
|
||||
dropReason := qlog.PacketDropHeaderParseError
|
||||
if err == wire.ErrUnsupportedVersion {
|
||||
dropReason = qlog.PacketDropUnsupportedVersion
|
||||
}
|
||||
s.qlogger.DroppedPacket(qlog.PacketTypeNotDetermined, protocol.ByteCount(len(data)), dropReason)
|
||||
}
|
||||
s.logger.Debugf("error parsing packet: %s", err)
|
||||
break
|
||||
|
|
|
@ -599,6 +599,19 @@ var _ = Describe("Session", func() {
|
|||
Expect(sess.handlePacketImpl(p)).To(BeFalse())
|
||||
})
|
||||
|
||||
It("drops packets for which the version is unsupported", func() {
|
||||
p := getPacket(&wire.ExtendedHeader{
|
||||
Header: wire.Header{
|
||||
IsLongHeader: true,
|
||||
Type: protocol.PacketTypeHandshake,
|
||||
Version: sess.version + 1,
|
||||
},
|
||||
PacketNumberLen: protocol.PacketNumberLen2,
|
||||
}, nil)
|
||||
qlogger.EXPECT().DroppedPacket(qlog.PacketTypeNotDetermined, protocol.ByteCount(len(p.data)), qlog.PacketDropUnsupportedVersion)
|
||||
Expect(sess.handlePacketImpl(p)).To(BeFalse())
|
||||
})
|
||||
|
||||
It("informs the ReceivedPacketHandler about non-ack-eliciting packets", func() {
|
||||
hdr := &wire.ExtendedHeader{
|
||||
Header: wire.Header{DestConnectionID: srcConnID},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue