comparison src/event/ngx_event_quic.c @ 8656:43f3574b3e6f quic

QUIC: fixed handling of clients connected to wildcard address. The patch replaces c->send() occurences with c->send_chain(), because the latter accounts for the local address, which may be different if the wildcard listener is used. Previously, server sent response to client using address different from one client connected to.
author Vladimir Homutov <vl@nginx.com>
date Mon, 07 Dec 2020 14:06:00 +0300
parents f596a4e5794b
children 2dfc5ef29973
comparison
equal deleted inserted replaced
8655:f596a4e5794b 8656:43f3574b3e6f
331 static ngx_int_t ngx_quic_output_frames(ngx_connection_t *c, 331 static ngx_int_t ngx_quic_output_frames(ngx_connection_t *c,
332 ngx_quic_send_ctx_t *ctx); 332 ngx_quic_send_ctx_t *ctx);
333 static void ngx_quic_free_frames(ngx_connection_t *c, ngx_queue_t *frames); 333 static void ngx_quic_free_frames(ngx_connection_t *c, ngx_queue_t *frames);
334 static ngx_int_t ngx_quic_send_frames(ngx_connection_t *c, 334 static ngx_int_t ngx_quic_send_frames(ngx_connection_t *c,
335 ngx_quic_send_ctx_t *ctx, ngx_queue_t *frames); 335 ngx_quic_send_ctx_t *ctx, ngx_queue_t *frames);
336 static ssize_t ngx_quic_send(ngx_connection_t *c, u_char *buf, size_t len);
336 337
337 static void ngx_quic_set_packet_number(ngx_quic_header_t *pkt, 338 static void ngx_quic_set_packet_number(ngx_quic_header_t *pkt,
338 ngx_quic_send_ctx_t *ctx); 339 ngx_quic_send_ctx_t *ctx);
339 static void ngx_quic_pto_handler(ngx_event_t *ev); 340 static void ngx_quic_pto_handler(ngx_event_t *ev);
340 static void ngx_quic_lost_handler(ngx_event_t *ev); 341 static void ngx_quic_lost_handler(ngx_event_t *ev);
1169 != NGX_OK) 1170 != NGX_OK)
1170 { 1171 {
1171 return NGX_ERROR; 1172 return NGX_ERROR;
1172 } 1173 }
1173 1174
1174 (void) c->send(c, buf, len); 1175 (void) ngx_quic_send(c, buf, len);
1175 1176
1176 return NGX_DECLINED; 1177 return NGX_DECLINED;
1177 } 1178 }
1178 1179
1179 1180
1241 #ifdef NGX_QUIC_DEBUG_PACKETS 1242 #ifdef NGX_QUIC_DEBUG_PACKETS
1242 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0, 1243 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0,
1243 "quic vnego packet to send len:%uz %*xs", len, len, buf); 1244 "quic vnego packet to send len:%uz %*xs", len, len, buf);
1244 #endif 1245 #endif
1245 1246
1246 (void) c->send(c, buf, len); 1247 (void) ngx_quic_send(c, buf, len);
1247 1248
1248 return NGX_ERROR; 1249 return NGX_ERROR;
1249 } 1250 }
1250 1251
1251 1252
1296 #ifdef NGX_QUIC_DEBUG_PACKETS 1297 #ifdef NGX_QUIC_DEBUG_PACKETS
1297 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0, 1298 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,
1298 "quic packet to send len:%uz %xV", res.len, &res); 1299 "quic packet to send len:%uz %xV", res.len, &res);
1299 #endif 1300 #endif
1300 1301
1301 len = c->send(c, res.data, res.len); 1302 len = ngx_quic_send(c, res.data, res.len);
1302 if (len == NGX_ERROR || (size_t) len != res.len) { 1303 if (len == NGX_ERROR) {
1303 return NGX_ERROR; 1304 return NGX_ERROR;
1304 } 1305 }
1305 1306
1306 qc->token = token; 1307 qc->token = token;
1307 #if (NGX_QUIC_DRAFT_VERSION < 28) 1308 #if (NGX_QUIC_DRAFT_VERSION < 28)
4904 if (ngx_quic_encrypt(&pkt, &res) != NGX_OK) { 4905 if (ngx_quic_encrypt(&pkt, &res) != NGX_OK) {
4905 ngx_quic_free_frames(c, frames); 4906 ngx_quic_free_frames(c, frames);
4906 return NGX_ERROR; 4907 return NGX_ERROR;
4907 } 4908 }
4908 4909
4909 len = c->send(c, res.data, res.len); 4910 len = ngx_quic_send(c, res.data, res.len);
4910 if (len == NGX_ERROR || (size_t) len != res.len) { 4911 if (len == NGX_ERROR) {
4911 ngx_quic_free_frames(c, frames); 4912 ngx_quic_free_frames(c, frames);
4912 return NGX_ERROR; 4913 return NGX_ERROR;
4913 } 4914 }
4914 4915
4915 /* len == NGX_OK || NGX_AGAIN */ 4916 /* len == NGX_OK || NGX_AGAIN */
4941 /* no ack is expected for this frames, so we can free them */ 4942 /* no ack is expected for this frames, so we can free them */
4942 ngx_quic_free_frames(c, frames); 4943 ngx_quic_free_frames(c, frames);
4943 } 4944 }
4944 4945
4945 return NGX_OK; 4946 return NGX_OK;
4947 }
4948
4949
4950 static ssize_t
4951 ngx_quic_send(ngx_connection_t *c, u_char *buf, size_t len)
4952 {
4953 ngx_buf_t b;
4954 ngx_chain_t cl, *res;
4955
4956 ngx_memzero(&b, sizeof(ngx_buf_t));
4957
4958 b.pos = b.start = buf;
4959 b.last = b.end = buf + len;
4960 b.last_buf = 1;
4961 b.temporary = 1;
4962
4963 cl.buf = &b;
4964 cl.next= NULL;
4965
4966 res = c->send_chain(c, &cl, 0);
4967 if (res == NGX_CHAIN_ERROR) {
4968 return NGX_ERROR;
4969 }
4970
4971 return len;
4946 } 4972 }
4947 4973
4948 4974
4949 static void 4975 static void
4950 ngx_quic_set_packet_number(ngx_quic_header_t *pkt, ngx_quic_send_ctx_t *ctx) 4976 ngx_quic_set_packet_number(ngx_quic_header_t *pkt, ngx_quic_send_ctx_t *ctx)