comparison src/event/ngx_event_quic_transport.c @ 8559:a89a58c642ef quic

QUIC: simplified packet header parsing. 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.
author Vladimir Homutov <vl@nginx.com>
date Fri, 25 Sep 2020 21:47:28 +0300
parents 0f37b4ef3cd9
children d0d3fc0697a0
comparison
equal deleted inserted replaced
8558:0f37b4ef3cd9 8559:a89a58c642ef
248 ngx_quic_parse_long_header(ngx_quic_header_t *pkt) 248 ngx_quic_parse_long_header(ngx_quic_header_t *pkt)
249 { 249 {
250 u_char *p, *end; 250 u_char *p, *end;
251 uint8_t idlen; 251 uint8_t idlen;
252 252
253 p = pkt->data; 253 p = pkt->raw->pos;
254 end = pkt->data + pkt->len; 254 end = pkt->data + pkt->len;
255
256 p = ngx_quic_read_uint8(p, end, &pkt->flags);
257 if (p == NULL) {
258 ngx_log_error(NGX_LOG_INFO, pkt->log, 0,
259 "quic packet is too small to read flags");
260 return NGX_ERROR;
261 }
262
263 if (!ngx_quic_long_pkt(pkt->flags)) {
264 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, "quic not a long packet");
265 return NGX_ERROR;
266 }
267 255
268 p = ngx_quic_read_uint32(p, end, &pkt->version); 256 p = ngx_quic_read_uint32(p, end, &pkt->version);
269 if (p == NULL) { 257 if (p == NULL) {
270 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, 258 ngx_log_error(NGX_LOG_INFO, pkt->log, 0,
271 "quic packet is too small to read version"); 259 "quic packet is too small to read version");
471 ngx_int_t 459 ngx_int_t
472 ngx_quic_parse_short_header(ngx_quic_header_t *pkt, ngx_str_t *dcid) 460 ngx_quic_parse_short_header(ngx_quic_header_t *pkt, ngx_str_t *dcid)
473 { 461 {
474 u_char *p, *end; 462 u_char *p, *end;
475 463
476 p = pkt->data; 464 p = pkt->raw->pos;
477 end = pkt->data + pkt->len; 465 end = pkt->data + pkt->len;
478
479 p = ngx_quic_read_uint8(p, end, &pkt->flags);
480 if (p == NULL) {
481 ngx_log_error(NGX_LOG_INFO, pkt->log, 0,
482 "quic packet is too small to read flags");
483 return NGX_ERROR;
484 }
485
486 if (!ngx_quic_short_pkt(pkt->flags)) {
487 ngx_log_error(NGX_LOG_INFO, pkt->log, 0, "quic not a short packet");
488 return NGX_ERROR;
489 }
490 466
491 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, pkt->log, 0, 467 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, pkt->log, 0,
492 "quic short packet flags:%xd", pkt->flags); 468 "quic short packet flags:%xd", pkt->flags);
493 469
494 if (!(pkt->flags & NGX_QUIC_PKT_FIXED_BIT)) { 470 if (!(pkt->flags & NGX_QUIC_PKT_FIXED_BIT)) {