From b3ed563f7643a69d735f5ebaa4c8531efd31b556 Mon Sep 17 00:00:00 2001
From: Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>
Date: Tue, 26 May 2020 18:12:58 +0900
Subject: [PATCH] Define NGTCP2_MIN_INITIAL_DCIDLEN

---
 examples/server.cc           | 3 ++-
 lib/includes/ngtcp2/ngtcp2.h | 5 +++++
 lib/ngtcp2_conn.c            | 2 +-
 3 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/examples/server.cc b/examples/server.cc
index 4020e95c..0d5d0d76 100644
--- a/examples/server.cc
+++ b/examples/server.cc
@@ -2390,7 +2390,8 @@ int Server::on_read(Endpoint &ep) {
               continue;
             }
 
-            if (hd.token.base[0] != RETRY_TOKEN_MAGIC && hd.dcid.datalen < 8) {
+            if (hd.token.base[0] != RETRY_TOKEN_MAGIC &&
+                hd.dcid.datalen < NGTCP2_MIN_INITIAL_DCIDLEN) {
               send_stateless_connection_close(&hd, ep, &su.sa, addrlen);
               continue;
             }
diff --git a/lib/includes/ngtcp2/ngtcp2.h b/lib/includes/ngtcp2/ngtcp2.h
index 04b568c1..c8ec9723 100644
--- a/lib/includes/ngtcp2/ngtcp2.h
+++ b/lib/includes/ngtcp2/ngtcp2.h
@@ -320,6 +320,11 @@ typedef uint64_t ngtcp2_duration;
 /* NGTCP2_MIN_CIDLEN is the minimum length of Connection ID. */
 #define NGTCP2_MIN_CIDLEN 1
 
+/* NGTCP2_MIN_INITIAL_DCIDLEN is the minimum length of Destination
+   Connection ID in Client Initial packet if it does not bear token
+   from Retry packet. */
+#define NGTCP2_MIN_INITIAL_DCIDLEN 8
+
 /**
  * @struct
  *
diff --git a/lib/ngtcp2_conn.c b/lib/ngtcp2_conn.c
index c0831da3..caf94dfc 100644
--- a/lib/ngtcp2_conn.c
+++ b/lib/ngtcp2_conn.c
@@ -7845,7 +7845,7 @@ int ngtcp2_accept(ngtcp2_pkt_hd *dest, const uint8_t *pkt, size_t pktlen) {
     if (pktlen < NGTCP2_MIN_INITIAL_PKTLEN) {
       return -1;
     }
-    if (p->token.len == 0 && p->dcid.datalen < 8) {
+    if (p->token.len == 0 && p->dcid.datalen < NGTCP2_MIN_INITIAL_DCIDLEN) {
       return -1;
     }
     break;
-- 
GitLab