Mercurial > hg > nginx-quic
comparison src/event/quic/ngx_event_quic_migration.c @ 8721:501f28679d56 quic
QUIC: refactored ngx_quic_frame_sendto() function.
The function now takes path as an argument to deal with associated
restrictions and update sent counter.
author | Vladimir Homutov <vl@nginx.com> |
---|---|
date | Thu, 09 Dec 2021 12:40:14 +0300 |
parents | bb1d1d9d76e2 |
children | 02a9ad88e2df |
comparison
equal
deleted
inserted
replaced
8720:0ee56d2eac44 | 8721:501f28679d56 |
---|---|
22 | 22 |
23 ngx_int_t | 23 ngx_int_t |
24 ngx_quic_handle_path_challenge_frame(ngx_connection_t *c, | 24 ngx_quic_handle_path_challenge_frame(ngx_connection_t *c, |
25 ngx_quic_path_challenge_frame_t *f) | 25 ngx_quic_path_challenge_frame_t *f) |
26 { | 26 { |
27 off_t max, pad; | |
28 ssize_t sent; | |
29 ngx_quic_path_t *path; | 27 ngx_quic_path_t *path; |
30 ngx_quic_frame_t frame, *fp; | 28 ngx_quic_frame_t frame, *fp; |
31 ngx_quic_socket_t *qsock; | 29 ngx_quic_socket_t *qsock; |
32 ngx_quic_connection_t *qc; | 30 ngx_quic_connection_t *qc; |
33 | 31 |
47 path = qsock->path; | 45 path = qsock->path; |
48 | 46 |
49 /* | 47 /* |
50 * An endpoint MUST expand datagrams that contain a PATH_RESPONSE frame | 48 * An endpoint MUST expand datagrams that contain a PATH_RESPONSE frame |
51 * to at least the smallest allowed maximum datagram size of 1200 bytes. | 49 * to at least the smallest allowed maximum datagram size of 1200 bytes. |
52 * ... | 50 */ |
53 * An endpoint MUST NOT expand the datagram containing the PATH_RESPONSE | 51 if (ngx_quic_frame_sendto(c, &frame, 1200, path) != NGX_OK) { |
54 * if the resulting data exceeds the anti-amplification limit. | 52 return NGX_ERROR; |
55 */ | 53 } |
56 if (path->state != NGX_QUIC_PATH_VALIDATED) { | |
57 max = path->received * 3; | |
58 max = (path->sent >= max) ? 0 : max - path->sent; | |
59 pad = ngx_min(1200, max); | |
60 | |
61 } else { | |
62 pad = 1200; | |
63 } | |
64 | |
65 sent = ngx_quic_frame_sendto(c, &frame, pad, path->sockaddr, path->socklen); | |
66 if (sent < 0) { | |
67 return NGX_ERROR; | |
68 } | |
69 | |
70 path->sent += sent; | |
71 | 54 |
72 if (qsock == qc->socket) { | 55 if (qsock == qc->socket) { |
73 /* | 56 /* |
74 * RFC 9000, 9.3.3. Off-Path Packet Forwarding | 57 * RFC 9000, 9.3.3. Off-Path Packet Forwarding |
75 * | 58 * |
533 | 516 |
534 | 517 |
535 static ngx_int_t | 518 static ngx_int_t |
536 ngx_quic_send_path_challenge(ngx_connection_t *c, ngx_quic_path_t *path) | 519 ngx_quic_send_path_challenge(ngx_connection_t *c, ngx_quic_path_t *path) |
537 { | 520 { |
538 off_t max, pad; | |
539 ssize_t sent; | |
540 ngx_quic_frame_t frame; | 521 ngx_quic_frame_t frame; |
541 | 522 |
542 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0, | 523 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0, |
543 "quic path #%uL send path challenge tries:%ui", | 524 "quic path #%uL send path challenge tries:%ui", |
544 path->seqnum, path->tries); | 525 path->seqnum, path->tries); |
556 * unless the anti-amplification limit for the path does not permit | 537 * unless the anti-amplification limit for the path does not permit |
557 * sending a datagram of this size. | 538 * sending a datagram of this size. |
558 */ | 539 */ |
559 | 540 |
560 /* same applies to PATH_RESPONSE frames */ | 541 /* same applies to PATH_RESPONSE frames */ |
561 | 542 if (ngx_quic_frame_sendto(c, &frame, 1200, path) != NGX_OK) { |
562 max = path->received * 3; | 543 return NGX_ERROR; |
563 max = (path->sent >= max) ? 0 : max - path->sent; | 544 } |
564 pad = ngx_min(1200, max); | |
565 | |
566 sent = ngx_quic_frame_sendto(c, &frame, pad, path->sockaddr, path->socklen); | |
567 if (sent < 0) { | |
568 return NGX_ERROR; | |
569 } | |
570 | |
571 path->sent += sent; | |
572 | 545 |
573 ngx_memcpy(frame.u.path_challenge.data, path->challenge2, 8); | 546 ngx_memcpy(frame.u.path_challenge.data, path->challenge2, 8); |
574 | 547 |
575 max = (path->sent >= max) ? 0 : max - path->sent; | 548 if (ngx_quic_frame_sendto(c, &frame, 1200, path) != NGX_OK) { |
576 pad = ngx_min(1200, max); | 549 return NGX_ERROR; |
577 | 550 } |
578 sent = ngx_quic_frame_sendto(c, &frame, pad, path->sockaddr, path->socklen); | |
579 if (sent < 0) { | |
580 return NGX_ERROR; | |
581 } | |
582 | |
583 path->sent += sent; | |
584 | 551 |
585 return NGX_OK; | 552 return NGX_OK; |
586 } | 553 } |
587 | 554 |
588 | 555 |