Mercurial > hg > nginx
comparison src/event/ngx_event_quic_transport.c @ 8356:42198f77ac85 quic
Removed support of drafts older than currently latest 27.
author | Vladimir Homutov <vl@nginx.com> |
---|---|
date | Thu, 23 Apr 2020 11:50:20 +0300 |
parents | dd84c9cef75b |
children | 05b8dd5d9f7e |
comparison
equal
deleted
inserted
replaced
8355:ad3a6f069498 | 8356:42198f77ac85 |
---|---|
59 static u_char *ngx_quic_parse_int(u_char *pos, u_char *end, uint64_t *out); | 59 static u_char *ngx_quic_parse_int(u_char *pos, u_char *end, uint64_t *out); |
60 static u_char *ngx_quic_parse_int_multi(u_char *pos, u_char *end, ...); | 60 static u_char *ngx_quic_parse_int_multi(u_char *pos, u_char *end, ...); |
61 static void ngx_quic_build_int(u_char **pos, uint64_t value); | 61 static void ngx_quic_build_int(u_char **pos, uint64_t value); |
62 | 62 |
63 static u_char *ngx_quic_read_uint8(u_char *pos, u_char *end, uint8_t *value); | 63 static u_char *ngx_quic_read_uint8(u_char *pos, u_char *end, uint8_t *value); |
64 /*static*/ u_char *ngx_quic_read_uint16(u_char *pos, u_char *end, uint16_t *value); // usage depends on NGX_QUIC_VERSION | |
65 static u_char *ngx_quic_read_uint32(u_char *pos, u_char *end, uint32_t *value); | 64 static u_char *ngx_quic_read_uint32(u_char *pos, u_char *end, uint32_t *value); |
66 static u_char *ngx_quic_read_bytes(u_char *pos, u_char *end, size_t len, | 65 static u_char *ngx_quic_read_bytes(u_char *pos, u_char *end, size_t len, |
67 u_char **out); | 66 u_char **out); |
68 static u_char *ngx_quic_copy_bytes(u_char *pos, u_char *end, size_t len, | 67 static u_char *ngx_quic_copy_bytes(u_char *pos, u_char *end, size_t len, |
69 u_char *dst); | 68 u_char *dst); |
180 | 179 |
181 return pos + 1; | 180 return pos + 1; |
182 } | 181 } |
183 | 182 |
184 | 183 |
185 /*static*/ ngx_inline u_char * | |
186 ngx_quic_read_uint16(u_char *pos, u_char *end, uint16_t *value) | |
187 { | |
188 if ((size_t)(end - pos) < sizeof(uint16_t)) { | |
189 return NULL; | |
190 } | |
191 | |
192 *value = ngx_quic_parse_uint16(pos); | |
193 | |
194 return pos + sizeof(uint16_t); | |
195 } | |
196 | |
197 | |
198 static ngx_inline u_char * | 184 static ngx_inline u_char * |
199 ngx_quic_read_uint32(u_char *pos, u_char *end, uint32_t *value) | 185 ngx_quic_read_uint32(u_char *pos, u_char *end, uint32_t *value) |
200 { | 186 { |
201 if ((size_t)(end - pos) < sizeof(uint32_t)) { | 187 if ((size_t)(end - pos) < sizeof(uint32_t)) { |
202 return NULL; | 188 return NULL; |
1450 | 1436 |
1451 ngx_int_t | 1437 ngx_int_t |
1452 ngx_quic_parse_transport_params(u_char *p, u_char *end, ngx_quic_tp_t *tp, | 1438 ngx_quic_parse_transport_params(u_char *p, u_char *end, ngx_quic_tp_t *tp, |
1453 ngx_log_t *log) | 1439 ngx_log_t *log) |
1454 { | 1440 { |
1441 uint64_t id, len; | |
1455 ngx_int_t rc; | 1442 ngx_int_t rc; |
1456 | 1443 |
1457 #if (NGX_QUIC_DRAFT_VERSION < 27) | |
1458 | |
1459 uint16_t id, len, tp_len; | |
1460 | |
1461 p = ngx_quic_read_uint16(p, end, &tp_len); | |
1462 if (p == NULL) { | |
1463 ngx_log_error(NGX_LOG_INFO, log, 0, | |
1464 "failed to parse total transport params length"); | |
1465 return NGX_ERROR; | |
1466 } | |
1467 | |
1468 while (p < end) { | 1444 while (p < end) { |
1469 | 1445 p = ngx_quic_parse_int(p, end, &id); |
1470 p = ngx_quic_read_uint16(p, end, &id); | |
1471 if (p == NULL) { | 1446 if (p == NULL) { |
1472 ngx_log_error(NGX_LOG_INFO, log, 0, | 1447 ngx_log_error(NGX_LOG_INFO, log, 0, |
1473 "failed to parse transport param id"); | 1448 "failed to parse transport param id"); |
1474 return NGX_ERROR; | 1449 return NGX_ERROR; |
1475 } | 1450 } |
1476 | 1451 |
1477 p = ngx_quic_read_uint16(p, end, &len); | 1452 p = ngx_quic_parse_int(p, end, &len); |
1478 if (p == NULL) { | 1453 if (p == NULL) { |
1479 ngx_log_error(NGX_LOG_INFO, log, 0, | 1454 ngx_log_error(NGX_LOG_INFO, log, 0, |
1480 "failed to parse transport param id 0x%xi length", id); | 1455 "failed to parse transport param id 0x%xi length", id); |
1481 return NGX_ERROR; | 1456 return NGX_ERROR; |
1482 } | 1457 } |
1489 return NGX_ERROR; | 1464 return NGX_ERROR; |
1490 } | 1465 } |
1491 | 1466 |
1492 if (rc == NGX_DECLINED) { | 1467 if (rc == NGX_DECLINED) { |
1493 ngx_log_error(NGX_LOG_INFO, log, 0, | 1468 ngx_log_error(NGX_LOG_INFO, log, 0, |
1494 "unknown transport param id 0x%xi, skipped", id); | 1469 "unknown transport param id 0x%xi,skipped", id); |
1495 } | 1470 } |
1496 | 1471 |
1497 p += len; | 1472 p += len; |
1498 }; | 1473 } |
1499 | |
1500 #else | |
1501 | |
1502 uint64_t id, len; | |
1503 | |
1504 while (p < end) { | |
1505 p = ngx_quic_parse_int(p, end, &id); | |
1506 if (p == NULL) { | |
1507 ngx_log_error(NGX_LOG_INFO, log, 0, | |
1508 "failed to parse transport param id"); | |
1509 return NGX_ERROR; | |
1510 } | |
1511 | |
1512 p = ngx_quic_parse_int(p, end, &len); | |
1513 if (p == NULL) { | |
1514 ngx_log_error(NGX_LOG_INFO, log, 0, | |
1515 "failed to parse transport param id 0x%xi length", id); | |
1516 return NGX_ERROR; | |
1517 } | |
1518 | |
1519 rc = ngx_quic_parse_transport_param(p, p + len, id, tp); | |
1520 | |
1521 if (rc == NGX_ERROR) { | |
1522 ngx_log_error(NGX_LOG_INFO, log, 0, | |
1523 "failed to parse transport param id 0x%xi data", id); | |
1524 return NGX_ERROR; | |
1525 } | |
1526 | |
1527 if (rc == NGX_DECLINED) { | |
1528 ngx_log_error(NGX_LOG_INFO, log, 0, | |
1529 "unknown transport param id 0x%xi,skipped", id); | |
1530 } | |
1531 | |
1532 p += len; | |
1533 | |
1534 } | |
1535 | |
1536 #endif | |
1537 | 1474 |
1538 if (p != end) { | 1475 if (p != end) { |
1539 ngx_log_error(NGX_LOG_INFO, log, 0, | 1476 ngx_log_error(NGX_LOG_INFO, log, 0, |
1540 "trailing garbage in transport parameters: %ui bytes", | 1477 "trailing garbage in transport parameters: %ui bytes", |
1541 end - p); | 1478 end - p); |
1542 return NGX_ERROR; | 1479 return NGX_ERROR; |
1543 } | 1480 } |
1544 | 1481 |
1545 | |
1546 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, log, 0, | 1482 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, log, 0, |
1547 "client transport parameters parsed successfully"); | 1483 "client transport parameters parsed successfully"); |
1548 | 1484 |
1549 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, log, 0, | 1485 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, log, 0, |
1550 "disable active migration: %ui", | 1486 "disable active migration: %ui", |
1638 ssize_t | 1574 ssize_t |
1639 ngx_quic_create_transport_params(u_char *pos, u_char *end, ngx_quic_tp_t *tp) | 1575 ngx_quic_create_transport_params(u_char *pos, u_char *end, ngx_quic_tp_t *tp) |
1640 { | 1576 { |
1641 u_char *p; | 1577 u_char *p; |
1642 size_t len; | 1578 size_t len; |
1643 | |
1644 #if (NGX_QUIC_DRAFT_VERSION < 27) | |
1645 | |
1646 /* older drafts with static transport parameters encoding */ | |
1647 | |
1648 #define ngx_quic_tp_len(id, value) \ | |
1649 4 + ngx_quic_varint_len(value) | |
1650 | |
1651 #define ngx_quic_tp_vint(id, value) \ | |
1652 do { \ | |
1653 p = ngx_quic_write_uint16(p, id); \ | |
1654 p = ngx_quic_write_uint16(p, ngx_quic_varint_len(value)); \ | |
1655 ngx_quic_build_int(&p, value); \ | |
1656 } while (0) | |
1657 | |
1658 #else | |
1659 | 1579 |
1660 /* recent drafts with variable integer transport parameters encoding */ | 1580 /* recent drafts with variable integer transport parameters encoding */ |
1661 | 1581 |
1662 #define ngx_quic_tp_len(id, value) \ | 1582 #define ngx_quic_tp_len(id, value) \ |
1663 ngx_quic_varint_len(id) \ | 1583 ngx_quic_varint_len(id) \ |
1669 ngx_quic_build_int(&p, id); \ | 1589 ngx_quic_build_int(&p, id); \ |
1670 ngx_quic_build_int(&p, ngx_quic_varint_len(value)); \ | 1590 ngx_quic_build_int(&p, ngx_quic_varint_len(value)); \ |
1671 ngx_quic_build_int(&p, value); \ | 1591 ngx_quic_build_int(&p, value); \ |
1672 } while (0) | 1592 } while (0) |
1673 | 1593 |
1674 #endif | |
1675 | |
1676 p = pos; | 1594 p = pos; |
1677 | 1595 |
1678 len = ngx_quic_tp_len(NGX_QUIC_TP_ACTIVE_CONNECTION_ID_LIMIT, | 1596 len = ngx_quic_tp_len(NGX_QUIC_TP_ACTIVE_CONNECTION_ID_LIMIT, |
1679 tp->active_connection_id_limit); | 1597 tp->active_connection_id_limit); |
1680 | 1598 |
1697 | 1615 |
1698 len += ngx_quic_tp_len(NGX_QUIC_TP_MAX_IDLE_TIMEOUT, | 1616 len += ngx_quic_tp_len(NGX_QUIC_TP_MAX_IDLE_TIMEOUT, |
1699 tp->max_idle_timeout); | 1617 tp->max_idle_timeout); |
1700 | 1618 |
1701 if (pos == NULL) { | 1619 if (pos == NULL) { |
1702 #if (NGX_QUIC_DRAFT_VERSION < 27) | |
1703 len += 2; | |
1704 #endif | |
1705 return len; | 1620 return len; |
1706 } | 1621 } |
1707 | |
1708 #if (NGX_QUIC_DRAFT_VERSION < 27) | |
1709 /* TLS extension length */ | |
1710 p = ngx_quic_write_uint16(p, len); | |
1711 #endif | |
1712 | 1622 |
1713 ngx_quic_tp_vint(NGX_QUIC_TP_ACTIVE_CONNECTION_ID_LIMIT, | 1623 ngx_quic_tp_vint(NGX_QUIC_TP_ACTIVE_CONNECTION_ID_LIMIT, |
1714 tp->active_connection_id_limit); | 1624 tp->active_connection_id_limit); |
1715 | 1625 |
1716 ngx_quic_tp_vint(NGX_QUIC_TP_INITIAL_MAX_DATA, | 1626 ngx_quic_tp_vint(NGX_QUIC_TP_INITIAL_MAX_DATA, |