Mercurial > hg > nginx-quic
comparison src/event/ngx_event_quic.c @ 8078:d45961e062fa quic
QUIC: refactored ngx_quic_retry_input().
The function now returns NGX_DECLINED for packets that need to be ignored
and integrates nicely into ngx_quic_input().
author | Vladimir Homutov <vl@nginx.com> |
---|---|
date | Fri, 04 Sep 2020 15:48:53 +0300 |
parents | 62db595a86b5 |
children | dcbb58e7ed11 |
comparison
equal
deleted
inserted
replaced
8077:62db595a86b5 | 8078:d45961e062fa |
---|---|
1096 struct sockaddr_in6 *sin6; | 1096 struct sockaddr_in6 *sin6; |
1097 #endif | 1097 #endif |
1098 ngx_quic_connection_t *qc; | 1098 ngx_quic_connection_t *qc; |
1099 u_char tdec[NGX_QUIC_MAX_TOKEN_SIZE]; | 1099 u_char tdec[NGX_QUIC_MAX_TOKEN_SIZE]; |
1100 | 1100 |
1101 if (pkt->token.len == 0) { | |
1102 return NGX_ERROR; | |
1103 } | |
1104 | |
1105 qc = c->quic; | 1101 qc = c->quic; |
1106 | 1102 |
1107 /* Retry token */ | 1103 /* Retry token */ |
1108 | 1104 |
1109 if (qc->token.len) { | 1105 if (qc->token.len) { |
1614 pkt.len = b->last - p; | 1610 pkt.len = b->last - p; |
1615 pkt.log = c->log; | 1611 pkt.log = c->log; |
1616 pkt.flags = p[0]; | 1612 pkt.flags = p[0]; |
1617 | 1613 |
1618 if (c->quic->in_retry) { | 1614 if (c->quic->in_retry) { |
1619 return ngx_quic_retry_input(c, &pkt); | 1615 rc = ngx_quic_retry_input(c, &pkt); |
1620 } | 1616 |
1621 | 1617 } else if (ngx_quic_long_pkt(pkt.flags)) { |
1622 if (ngx_quic_long_pkt(pkt.flags)) { | |
1623 | 1618 |
1624 if (ngx_quic_pkt_in(pkt.flags)) { | 1619 if (ngx_quic_pkt_in(pkt.flags)) { |
1625 rc = ngx_quic_initial_input(c, &pkt); | 1620 rc = ngx_quic_initial_input(c, &pkt); |
1626 | 1621 |
1627 } else if (ngx_quic_pkt_hs(pkt.flags)) { | 1622 } else if (ngx_quic_pkt_hs(pkt.flags)) { |
1696 c->log->action = "retrying quic connection"; | 1691 c->log->action = "retrying quic connection"; |
1697 | 1692 |
1698 if (ngx_buf_size(pkt->raw) < NGX_QUIC_MIN_INITIAL_SIZE) { | 1693 if (ngx_buf_size(pkt->raw) < NGX_QUIC_MIN_INITIAL_SIZE) { |
1699 ngx_log_error(NGX_LOG_INFO, c->log, 0, | 1694 ngx_log_error(NGX_LOG_INFO, c->log, 0, |
1700 "quic UDP datagram is too small for initial packet"); | 1695 "quic UDP datagram is too small for initial packet"); |
1701 return NGX_OK; | 1696 return NGX_DECLINED; |
1702 } | 1697 } |
1703 | 1698 |
1704 if (ngx_quic_parse_long_header(pkt) != NGX_OK) { | 1699 if (ngx_quic_parse_long_header(pkt) != NGX_OK) { |
1705 return NGX_DECLINED; | 1700 return NGX_DECLINED; |
1706 } | 1701 } |
1712 } | 1707 } |
1713 | 1708 |
1714 if (ngx_quic_pkt_zrtt(pkt->flags)) { | 1709 if (ngx_quic_pkt_zrtt(pkt->flags)) { |
1715 ngx_log_error(NGX_LOG_INFO, c->log, 0, | 1710 ngx_log_error(NGX_LOG_INFO, c->log, 0, |
1716 "quic discard inflight 0-RTT packet"); | 1711 "quic discard inflight 0-RTT packet"); |
1717 return NGX_OK; | 1712 return NGX_DECLINED; |
1718 } | 1713 } |
1719 | 1714 |
1720 if (!ngx_quic_pkt_in(pkt->flags)) { | 1715 if (!ngx_quic_pkt_in(pkt->flags)) { |
1721 ngx_log_error(NGX_LOG_INFO, c->log, 0, | 1716 ngx_log_error(NGX_LOG_INFO, c->log, 0, |
1722 "quic invalid initial packet: 0x%xd", pkt->flags); | 1717 "quic invalid initial packet: 0x%xd", pkt->flags); |
1723 return NGX_DECLINED; | 1718 return NGX_DECLINED; |
1724 } | 1719 } |
1725 | 1720 |
1726 if (ngx_quic_parse_initial_header(pkt) != NGX_OK) { | 1721 if (ngx_quic_parse_initial_header(pkt) != NGX_OK) { |
1722 return NGX_DECLINED; | |
1723 } | |
1724 | |
1725 if (!pkt->token.len) { | |
1727 return NGX_DECLINED; | 1726 return NGX_DECLINED; |
1728 } | 1727 } |
1729 | 1728 |
1730 if (ngx_quic_new_dcid(c, &pkt->dcid) != NGX_OK) { | 1729 if (ngx_quic_new_dcid(c, &pkt->dcid) != NGX_OK) { |
1731 return NGX_ERROR; | 1730 return NGX_ERROR; |
1771 | 1770 |
1772 if (ngx_quic_payload_handler(c, pkt) != NGX_OK) { | 1771 if (ngx_quic_payload_handler(c, pkt) != NGX_OK) { |
1773 return NGX_ERROR; | 1772 return NGX_ERROR; |
1774 } | 1773 } |
1775 | 1774 |
1776 /* pos is at header end, adjust by actual packet length */ | 1775 return NGX_OK; |
1777 pkt->raw->pos += pkt->len; | |
1778 | |
1779 (void) ngx_quic_skip_zero_padding(pkt->raw); | |
1780 | |
1781 return ngx_quic_input(c, pkt->raw); | |
1782 } | 1776 } |
1783 | 1777 |
1784 | 1778 |
1785 static ngx_int_t | 1779 static ngx_int_t |
1786 ngx_quic_initial_input(ngx_connection_t *c, ngx_quic_header_t *pkt) | 1780 ngx_quic_initial_input(ngx_connection_t *c, ngx_quic_header_t *pkt) |