comparison src/event/ngx_event_quic.c @ 8651:dbad2d6d1898 quic

QUIC: removed ngx_quic_hexdump() macro. Instead, appropriate format specifier for hexadecimal is used in ngx_log_debug(). The STREAM frame "data" debug is moved into ngx_quic_log_frame(), similar to all other frame fields debug.
author Vladimir Homutov <vl@nginx.com>
date Fri, 27 Nov 2020 18:43:36 +0300
parents 05b1ee464350
children e9bd4305e68b
comparison
equal deleted inserted replaced
8650:9dce2978e4fd 8651:dbad2d6d1898
503 503
504 if (f->u.stream.fin) { 504 if (f->u.stream.fin) {
505 p = ngx_slprintf(p, last, " fin:1"); 505 p = ngx_slprintf(p, last, " fin:1");
506 } 506 }
507 507
508 #ifdef NGX_QUIC_DEBUG_FRAMES
509 p = ngx_slprintf(p, last, " data len:%uL %*xs", f->u.stream.length,
510 (size_t) f->u.stream.length, f->u.stream.data);
511 #endif
512
508 break; 513 break;
509 514
510 case NGX_QUIC_FT_MAX_DATA: 515 case NGX_QUIC_FT_MAX_DATA:
511 p = ngx_slprintf(p, last, "MAX_DATA max_data:%uL on recv", 516 p = ngx_slprintf(p, last, "MAX_DATA max_data:%uL on recv",
512 f->u.max_data.max_data); 517 f->u.max_data.max_data);
667 qc = ngx_quic_get_connection(c); 672 qc = ngx_quic_get_connection(c);
668 673
669 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, 674 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0,
670 "quic ngx_quic_set_read_secret() level:%d", level); 675 "quic ngx_quic_set_read_secret() level:%d", level);
671 #ifdef NGX_QUIC_DEBUG_CRYPTO 676 #ifdef NGX_QUIC_DEBUG_CRYPTO
672 ngx_quic_hexdump(c->log, "quic read secret", rsecret, secret_len); 677 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0,
678 "quic read secret len:%uz %*xs", secret_len,
679 secret_len, rsecret);
673 #endif 680 #endif
674 681
675 return ngx_quic_keys_set_encryption_secret(c->pool, 0, qc->keys, level, 682 return ngx_quic_keys_set_encryption_secret(c->pool, 0, qc->keys, level,
676 cipher, rsecret, secret_len); 683 cipher, rsecret, secret_len);
677 } 684 }
689 qc = ngx_quic_get_connection(c); 696 qc = ngx_quic_get_connection(c);
690 697
691 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, 698 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0,
692 "quic ngx_quic_set_write_secret() level:%d", level); 699 "quic ngx_quic_set_write_secret() level:%d", level);
693 #ifdef NGX_QUIC_DEBUG_CRYPTO 700 #ifdef NGX_QUIC_DEBUG_CRYPTO
694 ngx_quic_hexdump(c->log, "quic write secret", wsecret, secret_len); 701 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0,
702 "quic write secret len:%uz %*xs", secret_len,
703 secret_len, wsecret);
695 #endif 704 #endif
696 705
697 return ngx_quic_keys_set_encryption_secret(c->pool, 1, qc->keys, level, 706 return ngx_quic_keys_set_encryption_secret(c->pool, 1, qc->keys, level,
698 cipher, wsecret, secret_len); 707 cipher, wsecret, secret_len);
699 } 708 }
713 qc = ngx_quic_get_connection(c); 722 qc = ngx_quic_get_connection(c);
714 723
715 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, 724 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0,
716 "quic ngx_quic_set_encryption_secrets() level:%d", level); 725 "quic ngx_quic_set_encryption_secrets() level:%d", level);
717 #ifdef NGX_QUIC_DEBUG_CRYPTO 726 #ifdef NGX_QUIC_DEBUG_CRYPTO
718 ngx_quic_hexdump(c->log, "quic read secret", rsecret, secret_len); 727 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0,
728 "quic read secret len:%uz %*xs", secret_len,
729 secret_len, rsecret);
719 #endif 730 #endif
720 731
721 cipher = SSL_get_current_cipher(ssl_conn); 732 cipher = SSL_get_current_cipher(ssl_conn);
722 733
723 if (ngx_quic_keys_set_encryption_secret(c->pool, 0, qc->keys, level, 734 if (ngx_quic_keys_set_encryption_secret(c->pool, 0, qc->keys, level,
730 if (level == ssl_encryption_early_data) { 741 if (level == ssl_encryption_early_data) {
731 return 1; 742 return 1;
732 } 743 }
733 744
734 #ifdef NGX_QUIC_DEBUG_CRYPTO 745 #ifdef NGX_QUIC_DEBUG_CRYPTO
735 ngx_quic_hexdump(c->log, "quic write secret", wsecret, secret_len); 746 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0,
747 "quic write secret len:%uz %*xs", secret_len,
748 secret_len, wsecret);
736 #endif 749 #endif
737 750
738 return ngx_quic_keys_set_encryption_secret(c->pool, 1, qc->keys, level, 751 return ngx_quic_keys_set_encryption_secret(c->pool, 1, qc->keys, level,
739 cipher, wsecret, secret_len); 752 cipher, wsecret, secret_len);
740 } 753 }
1224 pkt.scid = inpkt->dcid; 1237 pkt.scid = inpkt->dcid;
1225 1238
1226 len = ngx_quic_create_version_negotiation(&pkt, buf); 1239 len = ngx_quic_create_version_negotiation(&pkt, buf);
1227 1240
1228 #ifdef NGX_QUIC_DEBUG_PACKETS 1241 #ifdef NGX_QUIC_DEBUG_PACKETS
1229 ngx_quic_hexdump(c->log, "quic vnego packet to send", buf, len); 1242 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0,
1243 "quic vnego packet to send len:%uz %*xs", len, len, buf);
1230 #endif 1244 #endif
1231 1245
1232 (void) c->send(c, buf, len); 1246 (void) c->send(c, buf, len);
1233 1247
1234 return NGX_ERROR; 1248 return NGX_ERROR;
1240 { 1254 {
1241 if (RAND_bytes(id, NGX_QUIC_SERVER_CID_LEN) != 1) { 1255 if (RAND_bytes(id, NGX_QUIC_SERVER_CID_LEN) != 1) {
1242 return NGX_ERROR; 1256 return NGX_ERROR;
1243 } 1257 }
1244 1258
1245 ngx_quic_hexdump(c->log, "quic create server id", 1259 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,
1246 id, NGX_QUIC_SERVER_CID_LEN); 1260 "quic create server id %*xs",
1247 1261 (size_t) NGX_QUIC_SERVER_CID_LEN, id);
1248 return NGX_OK; 1262 return NGX_OK;
1249 } 1263 }
1250 1264
1251 1265
1252 static ngx_int_t 1266 static ngx_int_t
1278 if (ngx_quic_encrypt(&pkt, &res) != NGX_OK) { 1292 if (ngx_quic_encrypt(&pkt, &res) != NGX_OK) {
1279 return NGX_ERROR; 1293 return NGX_ERROR;
1280 } 1294 }
1281 1295
1282 #ifdef NGX_QUIC_DEBUG_PACKETS 1296 #ifdef NGX_QUIC_DEBUG_PACKETS
1283 ngx_quic_hexdump(c->log, "quic packet to send", res.data, res.len); 1297 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,
1298 "quic packet to send len:%uz %xV", res.len, &res);
1284 #endif 1299 #endif
1285 1300
1286 len = c->send(c, res.data, res.len); 1301 len = c->send(c, res.data, res.len);
1287 if (len == NGX_ERROR || (size_t) len != res.len) { 1302 if (len == NGX_ERROR || (size_t) len != res.len) {
1288 return NGX_ERROR; 1303 return NGX_ERROR;
1396 token->len += len; 1411 token->len += len;
1397 1412
1398 EVP_CIPHER_CTX_free(ctx); 1413 EVP_CIPHER_CTX_free(ctx);
1399 1414
1400 #ifdef NGX_QUIC_DEBUG_PACKETS 1415 #ifdef NGX_QUIC_DEBUG_PACKETS
1401 ngx_quic_hexdump(c->log, "quic new token", token->data, token->len); 1416 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,
1417 "quic new token len:%uz %xV", token->len, token);
1402 #endif 1418 #endif
1403 1419
1404 return NGX_OK; 1420 return NGX_OK;
1405 } 1421 }
1406 1422
1566 != NGX_OK) 1582 != NGX_OK)
1567 { 1583 {
1568 return NGX_ERROR; 1584 return NGX_ERROR;
1569 } 1585 }
1570 1586
1571 ngx_quic_hexdump(c->log, "quic stateless reset token", 1587 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,
1572 qc->tp.sr_token, (size_t) NGX_QUIC_SR_TOKEN_LEN); 1588 "quic stateless reset token %*xs",
1589 (size_t) NGX_QUIC_SR_TOKEN_LEN, qc->tp.sr_token);
1573 1590
1574 len = ngx_quic_create_transport_params(NULL, NULL, &qc->tp, &clen); 1591 len = ngx_quic_create_transport_params(NULL, NULL, &qc->tp, &clen);
1575 /* always succeeds */ 1592 /* always succeeds */
1576 1593
1577 p = ngx_pnalloc(c->pool, len); 1594 p = ngx_pnalloc(c->pool, len);
1583 if (len < 0) { 1600 if (len < 0) {
1584 return NGX_ERROR; 1601 return NGX_ERROR;
1585 } 1602 }
1586 1603
1587 #ifdef NGX_QUIC_DEBUG_PACKETS 1604 #ifdef NGX_QUIC_DEBUG_PACKETS
1588 ngx_quic_hexdump(c->log, "quic transport parameters", p, len); 1605 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0,
1606 "quic transport parameters len:%uz %*xs", len, len, p);
1589 #endif 1607 #endif
1590 1608
1591 if (SSL_set_quic_transport_params(ssl_conn, p, len) == 0) { 1609 if (SSL_set_quic_transport_params(ssl_conn, p, len) == 0) {
1592 ngx_log_error(NGX_LOG_INFO, c->log, 0, 1610 ngx_log_error(NGX_LOG_INFO, c->log, 0,
1593 "quic SSL_set_quic_transport_params() failed"); 1611 "quic SSL_set_quic_transport_params() failed");
2071 2089
2072 c->log->action = "processing quic packet"; 2090 c->log->action = "processing quic packet";
2073 2091
2074 qc = ngx_quic_get_connection(c); 2092 qc = ngx_quic_get_connection(c);
2075 2093
2094 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,
2095 "quic packet rx dcid len:%uz %xV",
2096 pkt->dcid.len, &pkt->dcid);
2097
2076 #if (NGX_DEBUG) 2098 #if (NGX_DEBUG)
2077 ngx_quic_hexdump(c->log, "quic packet rx dcid",
2078 pkt->dcid.data, pkt->dcid.len);
2079
2080 if (pkt->level != ssl_encryption_application) { 2099 if (pkt->level != ssl_encryption_application) {
2081 ngx_quic_hexdump(c->log, "quic packet rx scid", pkt->scid.data, 2100 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,
2082 pkt->scid.len); 2101 "quic packet rx scid len:%uz %xV",
2102 pkt->scid.len, &pkt->scid);
2083 } 2103 }
2084 2104
2085 if (pkt->level == ssl_encryption_initial) { 2105 if (pkt->level == ssl_encryption_initial) {
2086 ngx_quic_hexdump(c->log, "quic token", pkt->token.data, pkt->token.len); 2106 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,
2107 "quic token len:%uz %xV",
2108 pkt->token.len, &pkt->token);
2087 } 2109 }
2088 #endif 2110 #endif
2089 2111
2090 if (qc) { 2112 if (qc) {
2091 2113
4518 dcid.data = sid->id; 4540 dcid.data = sid->id;
4519 dcid.len = sid->len; 4541 dcid.len = sid->len;
4520 4542
4521 ngx_insert_udp_connection(c, &sid->udp, &dcid); 4543 ngx_insert_udp_connection(c, &sid->udp, &dcid);
4522 4544
4523 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, 4545 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0,
4524 "quic insert server id seqnum:%uL", sid->seqnum); 4546 "quic insert server id seqnum:%uL id len:%uz %xV",
4525 4547 sid->seqnum, id->len, id);
4526 ngx_quic_hexdump(c->log, "quic server id", id->data, id->len);
4527 4548
4528 return sid; 4549 return sid;
4529 } 4550 }
4530 4551
4531 4552