Mercurial > hg > nginx
annotate src/event/quic/ngx_event_quic_udp.c @ 9295:c5623963c29e
Upstream: fixed proxy_no_cache when caching errors.
Caching errors, notably intercepted errors and internally generated
502/504 errors, as well as handling of cache revalidation with 304,
did not take into account u->conf->no_cache predicates configured.
As a result, an error might be cached even if configuration explicitly
says not to. Fix is to check u->conf->no_cache in these cases.
To simplify usage in multiple places, checking u->conf->no_cache is now
done in a separate function. As a minor optimization, u->conf->no_cache
is only checked if u->cacheable is set.
As a side effect, this change also fixes caching errors after
proxy_cache_bypass. Also, during cache revalidation u->cacheable is
now tested, so 304 responses which disable caching won't extend
cacheability of stored responses.
Additionally, when caching internally generated 502/504 errors
u->cacheable is now explicitly updated from u->headers_in.no_cache and
u->headers_in.expired, restoring the behaviour before 8041:0784ab86ad08
(1.23.0) when an error happens while reading the response headers.
Reported by Kirill A. Korinsky,
https://freenginx.org/pipermail/nginx/2024-April/000082.html
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Tue, 25 Jun 2024 21:44:50 +0300 |
parents | 68fa4b86ed46 |
children |
rev | line source |
---|---|
7285
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
1 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
2 /* |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
3 * Copyright (C) Roman Arutyunyan |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
4 * Copyright (C) Nginx, Inc. |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
5 */ |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
6 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
7 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
8 #include <ngx_config.h> |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
9 #include <ngx_core.h> |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
10 #include <ngx_event.h> |
9017
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
11 #include <ngx_event_quic_connection.h> |
7285
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
12 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
13 |
9017
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
14 static void ngx_quic_close_accepted_connection(ngx_connection_t *c); |
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
15 static ngx_connection_t *ngx_quic_lookup_connection(ngx_listening_t *ls, |
8732
db58c7ef1d7c
QUIC: do not handle empty dcid.
Roman Arutyunyan <arut@nginx.com>
parents:
8731
diff
changeset
|
16 ngx_str_t *key, struct sockaddr *local_sockaddr, socklen_t local_socklen); |
7285
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
17 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
18 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
19 void |
9017
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
20 ngx_quic_recvmsg(ngx_event_t *ev) |
7285
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
21 { |
9017
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
22 ssize_t n; |
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
23 ngx_str_t key; |
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
24 ngx_buf_t buf; |
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
25 ngx_log_t *log; |
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
26 ngx_err_t err; |
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
27 socklen_t socklen, local_socklen; |
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
28 ngx_event_t *rev, *wev; |
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
29 struct iovec iov[1]; |
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
30 struct msghdr msg; |
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
31 ngx_sockaddr_t sa, lsa; |
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
32 struct sockaddr *sockaddr, *local_sockaddr; |
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
33 ngx_listening_t *ls; |
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
34 ngx_event_conf_t *ecf; |
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
35 ngx_connection_t *c, *lc; |
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
36 ngx_quic_socket_t *qsock; |
9102
3028db26a0f5
QUIC: resized input datagram buffer from 65535 to 65527.
Roman Arutyunyan <arut@nginx.com>
parents:
9061
diff
changeset
|
37 static u_char buffer[NGX_QUIC_MAX_UDP_PAYLOAD_SIZE]; |
7285
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
38 |
8003
0f6cc8f73744
Core: added function for local source address cmsg.
Vladimir Homutov <vl@nginx.com>
parents:
7820
diff
changeset
|
39 #if (NGX_HAVE_ADDRINFO_CMSG) |
0f6cc8f73744
Core: added function for local source address cmsg.
Vladimir Homutov <vl@nginx.com>
parents:
7820
diff
changeset
|
40 u_char msg_control[CMSG_SPACE(sizeof(ngx_addrinfo_t))]; |
7285
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
41 #endif |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
42 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
43 if (ev->timedout) { |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
44 if (ngx_enable_accept_events((ngx_cycle_t *) ngx_cycle) != NGX_OK) { |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
45 return; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
46 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
47 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
48 ev->timedout = 0; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
49 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
50 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
51 ecf = ngx_event_get_conf(ngx_cycle->conf_ctx, ngx_event_core_module); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
52 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
53 if (!(ngx_event_flags & NGX_USE_KQUEUE_EVENT)) { |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
54 ev->available = ecf->multi_accept; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
55 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
56 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
57 lc = ev->data; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
58 ls = lc->listening; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
59 ev->ready = 0; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
60 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
61 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0, |
9017
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
62 "quic recvmsg on %V, ready: %d", |
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
63 &ls->addr_text, ev->available); |
7285
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
64 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
65 do { |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
66 ngx_memzero(&msg, sizeof(struct msghdr)); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
67 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
68 iov[0].iov_base = (void *) buffer; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
69 iov[0].iov_len = sizeof(buffer); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
70 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
71 msg.msg_name = &sa; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
72 msg.msg_namelen = sizeof(ngx_sockaddr_t); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
73 msg.msg_iov = iov; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
74 msg.msg_iovlen = 1; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
75 |
8003
0f6cc8f73744
Core: added function for local source address cmsg.
Vladimir Homutov <vl@nginx.com>
parents:
7820
diff
changeset
|
76 #if (NGX_HAVE_ADDRINFO_CMSG) |
7285
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
77 if (ls->wildcard) { |
8003
0f6cc8f73744
Core: added function for local source address cmsg.
Vladimir Homutov <vl@nginx.com>
parents:
7820
diff
changeset
|
78 msg.msg_control = &msg_control; |
0f6cc8f73744
Core: added function for local source address cmsg.
Vladimir Homutov <vl@nginx.com>
parents:
7820
diff
changeset
|
79 msg.msg_controllen = sizeof(msg_control); |
7285
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
80 |
8003
0f6cc8f73744
Core: added function for local source address cmsg.
Vladimir Homutov <vl@nginx.com>
parents:
7820
diff
changeset
|
81 ngx_memzero(&msg_control, sizeof(msg_control)); |
8116 | 82 } |
7285
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
83 #endif |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
84 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
85 n = recvmsg(lc->fd, &msg, 0); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
86 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
87 if (n == -1) { |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
88 err = ngx_socket_errno; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
89 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
90 if (err == NGX_EAGAIN) { |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
91 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, ev->log, err, |
9017
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
92 "quic recvmsg() not ready"); |
7285
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
93 return; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
94 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
95 |
9017
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
96 ngx_log_error(NGX_LOG_ALERT, ev->log, err, "quic recvmsg() failed"); |
7285
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
97 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
98 return; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
99 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
100 |
8003
0f6cc8f73744
Core: added function for local source address cmsg.
Vladimir Homutov <vl@nginx.com>
parents:
7820
diff
changeset
|
101 #if (NGX_HAVE_ADDRINFO_CMSG) |
7285
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
102 if (msg.msg_flags & (MSG_TRUNC|MSG_CTRUNC)) { |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
103 ngx_log_error(NGX_LOG_ALERT, ev->log, 0, |
9017
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
104 "quic recvmsg() truncated data"); |
7285
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
105 continue; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
106 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
107 #endif |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
108 |
9017
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
109 sockaddr = msg.msg_name; |
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
110 socklen = msg.msg_namelen; |
7285
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
111 |
9017
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
112 if (socklen > (socklen_t) sizeof(ngx_sockaddr_t)) { |
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
113 socklen = sizeof(ngx_sockaddr_t); |
7285
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
114 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
115 |
9017
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
116 #if (NGX_HAVE_UNIX_DOMAIN) |
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
117 |
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
118 if (sockaddr->sa_family == AF_UNIX) { |
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
119 struct sockaddr_un *saun = (struct sockaddr_un *) sockaddr; |
7285
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
120 |
9017
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
121 if (socklen <= (socklen_t) offsetof(struct sockaddr_un, sun_path) |
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
122 || saun->sun_path[0] == '\0') |
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
123 { |
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
124 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, ngx_cycle->log, 0, |
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
125 "unbound unix socket"); |
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
126 goto next; |
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
127 } |
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
128 } |
7285
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
129 |
9017
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
130 #endif |
7285
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
131 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
132 local_sockaddr = ls->sockaddr; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
133 local_socklen = ls->socklen; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
134 |
8003
0f6cc8f73744
Core: added function for local source address cmsg.
Vladimir Homutov <vl@nginx.com>
parents:
7820
diff
changeset
|
135 #if (NGX_HAVE_ADDRINFO_CMSG) |
7285
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
136 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
137 if (ls->wildcard) { |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
138 struct cmsghdr *cmsg; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
139 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
140 ngx_memcpy(&lsa, local_sockaddr, local_socklen); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
141 local_sockaddr = &lsa.sockaddr; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
142 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
143 for (cmsg = CMSG_FIRSTHDR(&msg); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
144 cmsg != NULL; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
145 cmsg = CMSG_NXTHDR(&msg, cmsg)) |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
146 { |
8003
0f6cc8f73744
Core: added function for local source address cmsg.
Vladimir Homutov <vl@nginx.com>
parents:
7820
diff
changeset
|
147 if (ngx_get_srcaddr_cmsg(cmsg, local_sockaddr) == NGX_OK) { |
7285
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
148 break; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
149 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
150 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
151 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
152 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
153 #endif |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
154 |
9017
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
155 if (ngx_quic_get_packet_dcid(ev->log, buffer, n, &key) != NGX_OK) { |
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
156 goto next; |
8732
db58c7ef1d7c
QUIC: do not handle empty dcid.
Roman Arutyunyan <arut@nginx.com>
parents:
8731
diff
changeset
|
157 } |
db58c7ef1d7c
QUIC: do not handle empty dcid.
Roman Arutyunyan <arut@nginx.com>
parents:
8731
diff
changeset
|
158 |
9017
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
159 c = ngx_quic_lookup_connection(ls, &key, local_sockaddr, local_socklen); |
7286 | 160 |
161 if (c) { | |
162 | |
163 #if (NGX_DEBUG) | |
164 if (c->log->log_level & NGX_LOG_DEBUG_EVENT) { | |
165 ngx_log_handler_pt handler; | |
166 | |
167 handler = c->log->handler; | |
168 c->log->handler = NULL; | |
169 | |
170 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0, | |
9017
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
171 "quic recvmsg: fd:%d n:%z", c->fd, n); |
7286 | 172 |
173 c->log->handler = handler; | |
174 } | |
175 #endif | |
176 | |
177 ngx_memzero(&buf, sizeof(ngx_buf_t)); | |
178 | |
179 buf.pos = buffer; | |
180 buf.last = buffer + n; | |
8733
385d511b5064
QUIC: fixed udp buffer initialization.
Vladimir Homutov <vl@nginx.com>
parents:
8732
diff
changeset
|
181 buf.start = buf.pos; |
385d511b5064
QUIC: fixed udp buffer initialization.
Vladimir Homutov <vl@nginx.com>
parents:
8732
diff
changeset
|
182 buf.end = buffer + sizeof(buffer); |
7286 | 183 |
9017
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
184 qsock = ngx_quic_get_socket(c); |
7286 | 185 |
9111
68fa4b86ed46
QUIC: better sockaddr initialization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9107
diff
changeset
|
186 ngx_memcpy(&qsock->sockaddr, sockaddr, socklen); |
9017
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
187 qsock->socklen = socklen; |
8734
c61fcdc1b8e3
UDP: extended datagram context.
Vladimir Homutov <vl@nginx.com>
parents:
8733
diff
changeset
|
188 |
9017
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
189 c->udp->buffer = &buf; |
7440
6d4bc025c5a7
Prevented scheduling events on a shared connection.
Roman Arutyunyan <arut@nginx.com>
parents:
7393
diff
changeset
|
190 |
9017
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
191 rev = c->read; |
7286 | 192 rev->ready = 1; |
7440
6d4bc025c5a7
Prevented scheduling events on a shared connection.
Roman Arutyunyan <arut@nginx.com>
parents:
7393
diff
changeset
|
193 rev->active = 0; |
7286 | 194 |
195 rev->handler(rev); | |
196 | |
7391
27559d4a5151
Stream: fixed possible use of a freed connection.
Vladimir Homutov <vl@nginx.com>
parents:
7286
diff
changeset
|
197 if (c->udp) { |
9017
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
198 c->udp->buffer = NULL; |
7391
27559d4a5151
Stream: fixed possible use of a freed connection.
Vladimir Homutov <vl@nginx.com>
parents:
7286
diff
changeset
|
199 } |
27559d4a5151
Stream: fixed possible use of a freed connection.
Vladimir Homutov <vl@nginx.com>
parents:
7286
diff
changeset
|
200 |
7286 | 201 rev->ready = 0; |
7440
6d4bc025c5a7
Prevented scheduling events on a shared connection.
Roman Arutyunyan <arut@nginx.com>
parents:
7393
diff
changeset
|
202 rev->active = 1; |
7286 | 203 |
204 goto next; | |
205 } | |
206 | |
7285
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
207 #if (NGX_STAT_STUB) |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
208 (void) ngx_atomic_fetch_add(ngx_stat_accepted, 1); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
209 #endif |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
210 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
211 ngx_accept_disabled = ngx_cycle->connection_n / 8 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
212 - ngx_cycle->free_connection_n; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
213 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
214 c = ngx_get_connection(lc->fd, ev->log); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
215 if (c == NULL) { |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
216 return; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
217 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
218 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
219 c->shared = 1; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
220 c->type = SOCK_DGRAM; |
9017
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
221 c->socklen = socklen; |
7285
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
222 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
223 #if (NGX_STAT_STUB) |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
224 (void) ngx_atomic_fetch_add(ngx_stat_active, 1); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
225 #endif |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
226 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
227 c->pool = ngx_create_pool(ls->pool_size, ev->log); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
228 if (c->pool == NULL) { |
9017
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
229 ngx_quic_close_accepted_connection(c); |
7285
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
230 return; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
231 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
232 |
9017
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
233 c->sockaddr = ngx_palloc(c->pool, NGX_SOCKADDRLEN); |
7285
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
234 if (c->sockaddr == NULL) { |
9017
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
235 ngx_quic_close_accepted_connection(c); |
7285
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
236 return; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
237 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
238 |
9017
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
239 ngx_memcpy(c->sockaddr, sockaddr, socklen); |
7285
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
240 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
241 log = ngx_palloc(c->pool, sizeof(ngx_log_t)); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
242 if (log == NULL) { |
9017
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
243 ngx_quic_close_accepted_connection(c); |
7285
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
244 return; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
245 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
246 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
247 *log = ls->log; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
248 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
249 c->log = log; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
250 c->pool->log = log; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
251 c->listening = ls; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
252 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
253 if (local_sockaddr == &lsa.sockaddr) { |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
254 local_sockaddr = ngx_palloc(c->pool, local_socklen); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
255 if (local_sockaddr == NULL) { |
9017
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
256 ngx_quic_close_accepted_connection(c); |
7285
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
257 return; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
258 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
259 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
260 ngx_memcpy(local_sockaddr, &lsa, local_socklen); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
261 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
262 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
263 c->local_sockaddr = local_sockaddr; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
264 c->local_socklen = local_socklen; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
265 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
266 c->buffer = ngx_create_temp_buf(c->pool, n); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
267 if (c->buffer == NULL) { |
9017
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
268 ngx_quic_close_accepted_connection(c); |
7285
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
269 return; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
270 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
271 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
272 c->buffer->last = ngx_cpymem(c->buffer->last, buffer, n); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
273 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
274 rev = c->read; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
275 wev = c->write; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
276 |
7440
6d4bc025c5a7
Prevented scheduling events on a shared connection.
Roman Arutyunyan <arut@nginx.com>
parents:
7393
diff
changeset
|
277 rev->active = 1; |
7285
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
278 wev->ready = 1; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
279 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
280 rev->log = log; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
281 wev->log = log; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
282 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
283 /* |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
284 * TODO: MT: - ngx_atomic_fetch_add() |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
285 * or protection by critical section or light mutex |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
286 * |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
287 * TODO: MP: - allocated in a shared memory |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
288 * - ngx_atomic_fetch_add() |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
289 * or protection by critical section or light mutex |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
290 */ |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
291 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
292 c->number = ngx_atomic_fetch_add(ngx_connection_counter, 1); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
293 |
7820
fdc3d40979b0
Introduced the "keepalive_time" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7440
diff
changeset
|
294 c->start_time = ngx_current_msec; |
fdc3d40979b0
Introduced the "keepalive_time" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7440
diff
changeset
|
295 |
7285
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
296 #if (NGX_STAT_STUB) |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
297 (void) ngx_atomic_fetch_add(ngx_stat_handled, 1); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
298 #endif |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
299 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
300 if (ls->addr_ntop) { |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
301 c->addr_text.data = ngx_pnalloc(c->pool, ls->addr_text_max_len); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
302 if (c->addr_text.data == NULL) { |
9017
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
303 ngx_quic_close_accepted_connection(c); |
7285
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
304 return; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
305 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
306 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
307 c->addr_text.len = ngx_sock_ntop(c->sockaddr, c->socklen, |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
308 c->addr_text.data, |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
309 ls->addr_text_max_len, 0); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
310 if (c->addr_text.len == 0) { |
9017
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
311 ngx_quic_close_accepted_connection(c); |
7285
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
312 return; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
313 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
314 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
315 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
316 #if (NGX_DEBUG) |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
317 { |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
318 ngx_str_t addr; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
319 u_char text[NGX_SOCKADDR_STRLEN]; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
320 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
321 ngx_debug_accepted_connection(ecf, c); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
322 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
323 if (log->log_level & NGX_LOG_DEBUG_EVENT) { |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
324 addr.data = text; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
325 addr.len = ngx_sock_ntop(c->sockaddr, c->socklen, text, |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
326 NGX_SOCKADDR_STRLEN, 1); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
327 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
328 ngx_log_debug4(NGX_LOG_DEBUG_EVENT, log, 0, |
9017
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
329 "*%uA quic recvmsg: %V fd:%d n:%z", |
7285
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
330 c->number, &addr, c->fd, n); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
331 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
332 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
333 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
334 #endif |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
335 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
336 log->data = NULL; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
337 log->handler = NULL; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
338 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
339 ls->handler(c); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
340 |
7286 | 341 next: |
342 | |
7285
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
343 if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) { |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
344 ev->available -= n; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
345 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
346 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
347 } while (ev->available); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
348 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
349 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
350 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
351 static void |
9017
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
352 ngx_quic_close_accepted_connection(ngx_connection_t *c) |
7285
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
353 { |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
354 ngx_free_connection(c); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
355 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
356 c->fd = (ngx_socket_t) -1; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
357 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
358 if (c->pool) { |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
359 ngx_destroy_pool(c->pool); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
360 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
361 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
362 #if (NGX_STAT_STUB) |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
363 (void) ngx_atomic_fetch_add(ngx_stat_active, -1); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
364 #endif |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
365 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
366 |
7286 | 367 |
368 static ngx_connection_t * | |
9017
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
369 ngx_quic_lookup_connection(ngx_listening_t *ls, ngx_str_t *key, |
8628
45db1b5c1706
QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents:
7440
diff
changeset
|
370 struct sockaddr *local_sockaddr, socklen_t local_socklen) |
7286 | 371 { |
9017
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
372 uint32_t hash; |
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
373 ngx_int_t rc; |
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
374 ngx_connection_t *c; |
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
375 ngx_rbtree_node_t *node, *sentinel; |
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
376 ngx_quic_socket_t *qsock; |
7286 | 377 |
8732
db58c7ef1d7c
QUIC: do not handle empty dcid.
Roman Arutyunyan <arut@nginx.com>
parents:
8731
diff
changeset
|
378 if (key->len == 0) { |
db58c7ef1d7c
QUIC: do not handle empty dcid.
Roman Arutyunyan <arut@nginx.com>
parents:
8731
diff
changeset
|
379 return NULL; |
7286 | 380 } |
381 | |
382 node = ls->rbtree.root; | |
383 sentinel = ls->rbtree.sentinel; | |
9017
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
384 hash = ngx_crc32_long(key->data, key->len); |
7286 | 385 |
386 while (node != sentinel) { | |
387 | |
388 if (hash < node->key) { | |
389 node = node->left; | |
390 continue; | |
391 } | |
392 | |
393 if (hash > node->key) { | |
394 node = node->right; | |
395 continue; | |
396 } | |
397 | |
398 /* hash == node->key */ | |
399 | |
9017
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
400 qsock = (ngx_quic_socket_t *) node; |
7286 | 401 |
9017
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
402 rc = ngx_memn2cmp(key->data, qsock->sid.id, key->len, qsock->sid.len); |
7286 | 403 |
9017
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
404 c = qsock->udp.connection; |
7286 | 405 |
406 if (rc == 0 && ls->wildcard) { | |
407 rc = ngx_cmp_sockaddr(local_sockaddr, local_socklen, | |
408 c->local_sockaddr, c->local_socklen, 1); | |
409 } | |
410 | |
411 if (rc == 0) { | |
9017
c2f5d79cde64
QUIC: separate UDP framework for QUIC.
Roman Arutyunyan <arut@nginx.com>
parents:
9008
diff
changeset
|
412 c->udp = &qsock->udp; |
7286 | 413 return c; |
414 } | |
415 | |
416 node = (rc < 0) ? node->left : node->right; | |
417 } | |
418 | |
419 return NULL; | |
420 } |