This is an automated email from the ASF dual-hosted git repository.

masaori pushed a commit to branch quic-latest
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/quic-latest by this push:
     new ac60e73  Make sure length of scid is 18 bytes
ac60e73 is described below

commit ac60e738390cb19871955a3017c1f14bd7cf5297
Author: Masaori Koshiba <[email protected]>
AuthorDate: Fri Jun 15 14:00:04 2018 +0900

    Make sure length of scid is 18 bytes
---
 iocore/net/quic/QUICConfig.cc               |   6 ++
 iocore/net/quic/QUICConfig.h                |   6 +-
 iocore/net/quic/QUICPacket.h                |   4 +-
 iocore/net/quic/QUICTypes.cc                |  78 +++++++++++++-----
 iocore/net/quic/QUICTypes.h                 |  20 ++---
 iocore/net/quic/test/test_QUICInvariants.cc | 121 +++++++++++++++++++++++-----
 6 files changed, 180 insertions(+), 55 deletions(-)

diff --git a/iocore/net/quic/QUICConfig.cc b/iocore/net/quic/QUICConfig.cc
index 6010b23..b03d1bb 100644
--- a/iocore/net/quic/QUICConfig.cc
+++ b/iocore/net/quic/QUICConfig.cc
@@ -336,6 +336,12 @@ QUICConfigParams::cc_loss_reduction_factor() const
   return _cc_loss_reduction_factor;
 }
 
+uint8_t
+QUICConfigParams::scid_len()
+{
+  return QUICConfigParams::_scid_len;
+}
+
 //
 // QUICConfig
 //
diff --git a/iocore/net/quic/QUICConfig.h b/iocore/net/quic/QUICConfig.h
index 5b403bb..204cc18 100644
--- a/iocore/net/quic/QUICConfig.h
+++ b/iocore/net/quic/QUICConfig.h
@@ -44,7 +44,6 @@ public:
   uint16_t initial_max_uni_streams_in() const;
   uint16_t initial_max_uni_streams_out() const;
   uint32_t server_id() const;
-  static int connection_table_size();
   uint32_t max_alt_connection_ids() const;
   uint32_t stateless_retry() const;
   uint32_t vn_exercise_enabled() const;
@@ -69,10 +68,13 @@ public:
   uint32_t cc_minimum_window() const;
   float cc_loss_reduction_factor() const;
 
-  static const uint8_t SCIL = 5;
+  static int connection_table_size();
+  static uint8_t scid_len();
 
 private:
   static int _connection_table_size;
+  // TODO: make configurable
+  static const uint8_t _scid_len = 18; //< Length of Source Connection ID
 
   // FIXME Fill appropriate default values in RecordsConfig.cc
   uint32_t _no_activity_timeout_in  = 0;
diff --git a/iocore/net/quic/QUICPacket.h b/iocore/net/quic/QUICPacket.h
index f95c9bf..2d022e8 100644
--- a/iocore/net/quic/QUICPacket.h
+++ b/iocore/net/quic/QUICPacket.h
@@ -291,8 +291,8 @@ public:
   const uint8_t *payload() const;
   bool is_retransmittable() const;
 
-  static QUICConnectionId destination_connection_id(const uint8_t *packet);
-  static QUICConnectionId source_connection_id(const uint8_t *packet);
+  [[deprecated]] static QUICConnectionId destination_connection_id(const 
uint8_t *packet);
+  [[deprecated]] static QUICConnectionId source_connection_id(const uint8_t 
*packet);
 
   /*
    * Size of whole QUIC packet (header + payload + integrity check)
diff --git a/iocore/net/quic/QUICTypes.cc b/iocore/net/quic/QUICTypes.cc
index faf3bb6..8bafd4b 100644
--- a/iocore/net/quic/QUICTypes.cc
+++ b/iocore/net/quic/QUICTypes.cc
@@ -273,7 +273,7 @@ QUICFiveTuple::protocol() const
 QUICConnectionId
 QUICConnectionId::ZERO()
 {
-  uint8_t zero[18] = {0};
+  uint8_t zero[MAX_LENGTH] = {0};
   return QUICConnectionId(zero, sizeof(zero));
 }
 
@@ -309,13 +309,13 @@ QUICConnectionId::randomize()
 {
   std::random_device rnd;
   uint32_t x;
-  for (int i = sizeof(this->_id) - 1; i >= 0; --i) {
+  for (int i = QUICConfigParams::scid_len(); i >= 0; --i) {
     if (i % 4 == 0) {
       x = rnd();
     }
     this->_id[i] = (x >> (8 * (i % 4))) & 0xFF;
   }
-  this->_len = 18;
+  this->_len = QUICConfigParams::scid_len();
 }
 
 uint64_t
@@ -356,7 +356,7 @@ QUICInvariants::is_version_negotiation(QUICVersion v)
 bool
 QUICInvariants::version(QUICVersion &dst, const uint8_t *buf, uint64_t buf_len)
 {
-  if (!QUICInvariants::is_long_header(buf) || buf_len < 
QUICInvariants::LH_DCIL_OFFSET) {
+  if (!QUICInvariants::is_long_header(buf) || buf_len < 
QUICInvariants::LH_CIL_OFFSET) {
     return false;
   }
 
@@ -366,19 +366,47 @@ QUICInvariants::version(QUICVersion &dst, const uint8_t 
*buf, uint64_t buf_len)
 }
 
 bool
+QUICInvariants::dcil(uint8_t &dst, const uint8_t *buf, uint64_t buf_len)
+{
+  ink_assert(QUICInvariants::is_long_header(buf));
+
+  if (buf_len < QUICInvariants::LH_CIL_OFFSET) {
+    return false;
+  }
+
+  dst = buf[QUICInvariants::LH_CIL_OFFSET] >> 4;
+
+  return true;
+}
+
+bool
+QUICInvariants::scil(uint8_t &dst, const uint8_t *buf, uint64_t buf_len)
+{
+  ink_assert(QUICInvariants::is_long_header(buf));
+
+  if (buf_len < QUICInvariants::LH_CIL_OFFSET) {
+    return false;
+  }
+
+  dst = buf[QUICInvariants::LH_CIL_OFFSET] & 0x0F;
+
+  return true;
+}
+
+bool
 QUICInvariants::dcid(QUICConnectionId &dst, const uint8_t *buf, uint64_t 
buf_len)
 {
-  uint8_t dcil       = 0;
-  size_t dcid_offset = 0;
+  uint8_t dcid_offset = 0;
+  uint8_t dcid_len    = 0;
 
   if (QUICInvariants::is_long_header(buf)) {
-    if (buf_len < QUICInvariants::LH_DCIL_OFFSET) {
+    uint8_t dcil = 0;
+    if (!QUICInvariants::dcil(dcil, buf, buf_len)) {
       return false;
     }
 
-    dcil = buf[QUICInvariants::LH_DCIL_OFFSET] >> 4;
     if (dcil) {
-      dcil += QUICInvariants::CIL_BASE;
+      dcid_len = dcil + QUICInvariants::CIL_BASE;
     } else {
       dst = QUICConnectionId::ZERO();
       return true;
@@ -387,15 +415,15 @@ QUICInvariants::dcid(QUICConnectionId &dst, const uint8_t 
*buf, uint64_t buf_len
     dcid_offset = QUICInvariants::LH_DCID_OFFSET;
   } else {
     // remote dcil is local scil
-    dcil        = QUICConfigParams::SCIL + QUICInvariants::CIL_BASE;
+    dcid_len    = QUICConfigParams::scid_len();
     dcid_offset = QUICInvariants::SH_DCID_OFFSET;
   }
 
-  if (dcid_offset + dcil > buf_len) {
+  if (dcid_offset + dcid_len > buf_len) {
     return false;
   }
 
-  dst = QUICTypeUtil::read_QUICConnectionId(buf + dcid_offset, dcil);
+  dst = QUICTypeUtil::read_QUICConnectionId(buf + dcid_offset, dcid_len);
 
   return true;
 }
@@ -405,29 +433,39 @@ QUICInvariants::scid(QUICConnectionId &dst, const uint8_t 
*buf, uint64_t buf_len
 {
   ink_assert(QUICInvariants::is_long_header(buf));
 
-  if (buf_len < QUICInvariants::LH_DCIL_OFFSET) {
+  if (buf_len < QUICInvariants::LH_CIL_OFFSET) {
+    return false;
+  }
+
+  uint8_t scid_offset = QUICInvariants::LH_DCID_OFFSET;
+  uint8_t scid_len    = 0;
+
+  uint8_t dcil = 0;
+  if (!QUICInvariants::dcil(dcil, buf, buf_len)) {
     return false;
   }
 
-  uint8_t dcil = buf[QUICInvariants::LH_DCIL_OFFSET] >> 4;
   if (dcil) {
-    dcil += CIL_BASE;
+    scid_offset += (dcil + QUICInvariants::CIL_BASE);
+  }
+
+  uint8_t scil = 0;
+  if (!QUICInvariants::scil(scil, buf, buf_len)) {
+    return false;
   }
 
-  uint8_t scid_offset = QUICInvariants::LH_DCID_OFFSET + dcil;
-  uint8_t scil        = buf[QUICInvariants::LH_DCIL_OFFSET] & 0x0F;
   if (scil) {
-    scil += CIL_BASE;
+    scid_len = scil + QUICInvariants::CIL_BASE;
   } else {
     dst = QUICConnectionId::ZERO();
     return true;
   }
 
-  if (scid_offset + scil > buf_len) {
+  if (scid_offset + scid_len > buf_len) {
     return false;
   }
 
-  dst = QUICTypeUtil::read_QUICConnectionId(buf + scid_offset, scil);
+  dst = QUICTypeUtil::read_QUICConnectionId(buf + scid_offset, scid_len);
 
   return true;
 }
diff --git a/iocore/net/quic/QUICTypes.h b/iocore/net/quic/QUICTypes.h
index 307a447..278398d 100644
--- a/iocore/net/quic/QUICTypes.h
+++ b/iocore/net/quic/QUICTypes.h
@@ -249,7 +249,7 @@ public:
 
 private:
   uint64_t _hashcode() const;
-  uint8_t _id[18];
+  uint8_t _id[MAX_LENGTH];
   uint8_t _len = 0;
 };
 
@@ -317,7 +317,7 @@ class QUICTypeUtil
 {
 public:
   [[deprecated]] static bool has_long_header(const uint8_t *buf);
-  static bool has_connection_id(const uint8_t *buf);
+  [[deprecated]] static bool has_connection_id(const uint8_t *buf);
   static bool is_supported_version(QUICVersion version);
   static QUICStreamType detect_stream_type(QUICStreamId id);
 
@@ -349,14 +349,16 @@ public:
   static bool is_long_header(const uint8_t *buf);
   static bool is_version_negotiation(QUICVersion v);
   static bool version(QUICVersion &dst, const uint8_t *buf, uint64_t buf_len);
+  static bool dcil(uint8_t &dst, const uint8_t *buf, uint64_t buf_len);
+  static bool scil(uint8_t &dst, const uint8_t *buf, uint64_t buf_len);
   static bool dcid(QUICConnectionId &dst, const uint8_t *buf, uint64_t 
buf_len);
   static bool scid(QUICConnectionId &dst, const uint8_t *buf, uint64_t 
buf_len);
 
-  const static size_t CIL_BASE          = 3;
-  const static size_t LH_VERSION_OFFSET = 1;
-  const static size_t LH_DCIL_OFFSET    = 5;
-  const static size_t LH_DCID_OFFSET    = 6;
-  const static size_t SH_DCID_OFFSET    = 1;
-  const static size_t LH_MIN_LEN        = 6;
-  const static size_t SH_MIN_LEN        = 1;
+  static const size_t CIL_BASE          = 3;
+  static const size_t LH_VERSION_OFFSET = 1;
+  static const size_t LH_CIL_OFFSET     = 5;
+  static const size_t LH_DCID_OFFSET    = 6;
+  static const size_t SH_DCID_OFFSET    = 1;
+  static const size_t LH_MIN_LEN        = 6;
+  static const size_t SH_MIN_LEN        = 1;
 };
diff --git a/iocore/net/quic/test/test_QUICInvariants.cc 
b/iocore/net/quic/test/test_QUICInvariants.cc
index 4f7ad05..dc1c8d7 100644
--- a/iocore/net/quic/test/test_QUICInvariants.cc
+++ b/iocore/net/quic/test/test_QUICInvariants.cc
@@ -27,30 +27,101 @@
 
 TEST_CASE("Long Header - regular case", "[quic]")
 {
-  const uint8_t buf[] = {
-    0x80,                                           // Long header, Type: NONE
-    0x11, 0x22, 0x33, 0x44,                         // Version
-    0x55,                                           // DCIL/SCIL
-    0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, // Destination Connection 
ID
-    0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, // Source Connection ID
-  };
-  uint64_t buf_len = sizeof(buf);
-
   const uint8_t raw_dcid[] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
   const uint8_t raw_scid[] = {0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18};
   QUICConnectionId expected_dcid(raw_dcid, 8);
   QUICConnectionId expected_scid(raw_scid, 8);
 
-  QUICVersion version   = 0;
-  QUICConnectionId dcid = QUICConnectionId::ZERO();
-  QUICConnectionId scid = QUICConnectionId::ZERO();
+  SECTION("dcid & scid")
+  {
+    const uint8_t buf[] = {
+      0x80,                                           // Long header, Type: 
NONE
+      0x11, 0x22, 0x33, 0x44,                         // Version
+      0x55,                                           // DCIL/SCIL
+      0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, // Destination 
Connection ID
+      0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, // Source Connection ID
+    };
+    uint64_t buf_len = sizeof(buf);
 
-  CHECK(QUICInvariants::version(version, buf, buf_len));
-  CHECK(version == 0x11223344);
-  CHECK(QUICInvariants::dcid(dcid, buf, buf_len));
-  CHECK(dcid == expected_dcid);
-  CHECK(QUICInvariants::scid(scid, buf, buf_len));
-  CHECK(scid == expected_scid);
+    QUICVersion version   = 0;
+    uint8_t dcil          = 0;
+    uint8_t scil          = 0;
+    QUICConnectionId dcid = QUICConnectionId::ZERO();
+    QUICConnectionId scid = QUICConnectionId::ZERO();
+
+    CHECK(QUICInvariants::version(version, buf, buf_len));
+    CHECK(version == 0x11223344);
+
+    CHECK(QUICInvariants::dcil(dcil, buf, buf_len));
+    CHECK(dcil == 5);
+    CHECK(QUICInvariants::dcid(dcid, buf, buf_len));
+    CHECK(dcid == expected_dcid);
+
+    CHECK(QUICInvariants::scil(scil, buf, buf_len));
+    CHECK(scil == 5);
+    CHECK(QUICInvariants::scid(scid, buf, buf_len));
+    CHECK(scid == expected_scid);
+  }
+
+  SECTION("omitted dcid")
+  {
+    const uint8_t buf[] = {
+      0x80,                                           // Long header, Type: 
NONE
+      0x11, 0x22, 0x33, 0x44,                         // Version
+      0x05,                                           // DCIL/SCIL
+      0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, // Source Connection ID
+    };
+    uint64_t buf_len = sizeof(buf);
+
+    QUICVersion version   = 0;
+    uint8_t dcil          = 0;
+    uint8_t scil          = 0;
+    QUICConnectionId dcid = QUICConnectionId::ZERO();
+    QUICConnectionId scid = QUICConnectionId::ZERO();
+
+    CHECK(QUICInvariants::version(version, buf, buf_len));
+    CHECK(version == 0x11223344);
+
+    CHECK(QUICInvariants::dcil(dcil, buf, buf_len));
+    CHECK(dcil == 0);
+    CHECK(QUICInvariants::dcid(dcid, buf, buf_len));
+    CHECK(dcid == QUICConnectionId::ZERO());
+
+    CHECK(QUICInvariants::scil(scil, buf, buf_len));
+    CHECK(scil == 5);
+    CHECK(QUICInvariants::scid(scid, buf, buf_len));
+    CHECK(scid == expected_scid);
+  }
+
+  SECTION("omitted scid")
+  {
+    const uint8_t buf[] = {
+      0x80,                                           // Long header, Type: 
NONE
+      0x11, 0x22, 0x33, 0x44,                         // Version
+      0x50,                                           // DCIL/SCIL
+      0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, // Destination 
Connection ID
+    };
+    uint64_t buf_len = sizeof(buf);
+
+    QUICVersion version   = 0;
+    uint8_t dcil          = 0;
+    uint8_t scil          = 0;
+    QUICConnectionId dcid = QUICConnectionId::ZERO();
+    QUICConnectionId scid = QUICConnectionId::ZERO();
+
+    CHECK(QUICInvariants::version(version, buf, buf_len));
+    CHECK(version == 0x11223344);
+
+    CHECK(QUICInvariants::dcil(dcil, buf, buf_len));
+    CHECK(dcil == 5);
+    CHECK(QUICInvariants::dcid(dcid, buf, buf_len));
+    CHECK(dcid == expected_dcid);
+
+    CHECK(QUICInvariants::scil(scil, buf, buf_len));
+    CHECK(scil == 0);
+    CHECK(QUICInvariants::scid(scid, buf, buf_len));
+    CHECK(scid == QUICConnectionId::ZERO());
+  }
 }
 
 TEST_CASE("Long Header - error cases", "[quic]")
@@ -116,16 +187,23 @@ TEST_CASE("Long Header - error cases", "[quic]")
   }
 }
 
+// When ATS change QUICConfigParams::_scid_len shorter, this test should be 
failed
 TEST_CASE("Short Header - regular case", "[quic]")
 {
   const uint8_t buf[] = {
     0x00,                                           // Long header, Type: NONE
-    0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, // Destination Connection 
ID
+    0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, // Destination Connection 
ID (144)
+    0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, //
+    0x10, 0x11,                                     //
   };
   uint64_t buf_len = sizeof(buf);
 
-  const uint8_t raw_dcid[] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
-  QUICConnectionId expected_dcid(raw_dcid, 8);
+  const uint8_t raw_dcid[] = {
+    0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, //
+    0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, //
+    0x10, 0x11,                                     //
+  };
+  QUICConnectionId expected_dcid(raw_dcid, 18);
 
   QUICConnectionId dcid = QUICConnectionId::ZERO();
 
@@ -133,7 +211,6 @@ TEST_CASE("Short Header - regular case", "[quic]")
   CHECK(dcid == expected_dcid);
 }
 
-// When ATS change QUICConfigParams::SCIL, this test should be failed
 TEST_CASE("Short Header - error case", "[quic]")
 {
   const uint8_t buf[] = {

-- 
To stop receiving notification emails like this one, please contact
[email protected].

Reply via email to