]> git.kaiwu.me - nginx.git/commitdiff
QUIC: simplified packet header parsing.
authorVladimir Homutov <vl@nginx.com>
Fri, 25 Sep 2020 18:47:28 +0000 (21:47 +0300)
committerVladimir Homutov <vl@nginx.com>
Fri, 25 Sep 2020 18:47:28 +0000 (21:47 +0300)
Now flags are processed in ngx_quic_input(), and raw->pos points to the first
byte after the flags. Redundant checks from ngx_quic_parse_short_header() and
ngx_quic_parse_long_header() are removed.

src/event/ngx_event_quic.c
src/event/ngx_event_quic_transport.c

index f79ec408f918842edc651f5338065e07b261dd07..04fe56deb8cac7223b1cc3ceb00f4da4f860fdb2 100644 (file)
@@ -1623,6 +1623,7 @@ ngx_quic_input(ngx_connection_t *c, ngx_buf_t *b)
         pkt.len = b->last - p;
         pkt.log = c->log;
         pkt.flags = p[0];
+        pkt.raw->pos++;
 
         if (c->quic->in_retry) {
             rc = ngx_quic_retry_input(c, &pkt);
index be0aed78ddadb8e0ea0239302eb884672687eab1..182b93f611f24e83404de99aa60c34c3e0a0b8dd 100644 (file)
@@ -250,21 +250,9 @@ ngx_quic_parse_long_header(ngx_quic_header_t *pkt)
     u_char   *p, *end;
     uint8_t   idlen;
 
-    p = pkt->data;
+    p = pkt->raw->pos;
     end = pkt->data + pkt->len;
 
-    p = ngx_quic_read_uint8(p, end, &pkt->flags);
-    if (p == NULL) {
-        ngx_log_error(NGX_LOG_INFO, pkt->log, 0,
-                      "quic packet is too small to read flags");
-        return NGX_ERROR;
-    }
-
-    if (!ngx_quic_long_pkt(pkt->flags)) {
-        ngx_log_error(NGX_LOG_INFO, pkt->log, 0, "quic not a long packet");
-        return NGX_ERROR;
-    }
-
     p = ngx_quic_read_uint32(p, end, &pkt->version);
     if (p == NULL) {
         ngx_log_error(NGX_LOG_INFO, pkt->log, 0,
@@ -473,21 +461,9 @@ ngx_quic_parse_short_header(ngx_quic_header_t *pkt, ngx_str_t *dcid)
 {
     u_char  *p, *end;
 
-    p = pkt->data;
+    p = pkt->raw->pos;
     end = pkt->data + pkt->len;
 
-    p = ngx_quic_read_uint8(p, end, &pkt->flags);
-    if (p == NULL) {
-        ngx_log_error(NGX_LOG_INFO, pkt->log, 0,
-                      "quic packet is too small to read flags");
-        return NGX_ERROR;
-    }
-
-    if (!ngx_quic_short_pkt(pkt->flags)) {
-        ngx_log_error(NGX_LOG_INFO, pkt->log, 0, "quic not a short packet");
-        return NGX_ERROR;
-    }
-
     ngx_log_debug1(NGX_LOG_DEBUG_EVENT, pkt->log, 0,
                    "quic short packet flags:%xd", pkt->flags);