Mercurial > hg > nginx-quic
annotate src/event/ngx_event_udp.c @ 8711:be08b858086a quic
HTTP/3: http3_hq directive and NGX_HTTP_V3_HQ macro.
Listen quic parameter is no longer supported.
author | Roman Arutyunyan <arut@nginx.com> |
---|---|
date | Sat, 04 Dec 2021 10:52:55 +0300 |
parents | e7a2d3914877 |
children | ce6d9cf0f567 |
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> |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
11 |
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 #if !(NGX_WIN32) |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
14 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
15 static void ngx_close_accepted_udp_connection(ngx_connection_t *c); |
7286 | 16 static ssize_t ngx_udp_shared_recv(ngx_connection_t *c, u_char *buf, |
17 size_t size); | |
8198
45db1b5c1706
QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents:
7440
diff
changeset
|
18 static ngx_int_t ngx_create_udp_connection(ngx_connection_t *c); |
7286 | 19 static ngx_connection_t *ngx_lookup_udp_connection(ngx_listening_t *ls, |
8382
db58c7ef1d7c
QUIC: do not handle empty dcid.
Roman Arutyunyan <arut@nginx.com>
parents:
8381
diff
changeset
|
20 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
|
21 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
22 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
23 void |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
24 ngx_event_recvmsg(ngx_event_t *ev) |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
25 { |
8381
d62a16fff3a4
QUIC: do not reallocate c->sockaddr.
Roman Arutyunyan <arut@nginx.com>
parents:
8198
diff
changeset
|
26 size_t len; |
7285
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
27 ssize_t n; |
8198
45db1b5c1706
QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents:
7440
diff
changeset
|
28 ngx_str_t key; |
7286 | 29 ngx_buf_t buf; |
7285
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
30 ngx_log_t *log; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
31 ngx_err_t err; |
8384
c61fcdc1b8e3
UDP: extended datagram context.
Vladimir Homutov <vl@nginx.com>
parents:
8383
diff
changeset
|
32 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
|
33 ngx_event_t *rev, *wev; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
34 struct iovec iov[1]; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
35 struct msghdr msg; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
36 ngx_sockaddr_t sa, lsa; |
8384
c61fcdc1b8e3
UDP: extended datagram context.
Vladimir Homutov <vl@nginx.com>
parents:
8383
diff
changeset
|
37 ngx_udp_dgram_t dgram; |
c61fcdc1b8e3
UDP: extended datagram context.
Vladimir Homutov <vl@nginx.com>
parents:
8383
diff
changeset
|
38 struct sockaddr *local_sockaddr; |
7285
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
39 ngx_listening_t *ls; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
40 ngx_event_conf_t *ecf; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
41 ngx_connection_t *c, *lc; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
42 static u_char buffer[65535]; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
43 |
8513
e7a2d3914877
Core: added separate function for local source address cmsg.
Vladimir Homutov <vl@nginx.com>
parents:
8401
diff
changeset
|
44 #if (NGX_HAVE_ADDRINFO_CMSG) |
e7a2d3914877
Core: added separate function for local source address cmsg.
Vladimir Homutov <vl@nginx.com>
parents:
8401
diff
changeset
|
45 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
|
46 #endif |
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 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
|
49 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
|
50 return; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
51 } |
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 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
|
54 } |
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 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
|
57 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
58 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
|
59 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
|
60 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
61 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
62 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
|
63 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
|
64 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
|
65 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
66 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ev->log, 0, |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
67 "recvmsg on %V, ready: %d", &ls->addr_text, ev->available); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
68 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
69 do { |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
70 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
|
71 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
72 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
|
73 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
|
74 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
75 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
|
76 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
|
77 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
|
78 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
|
79 |
8513
e7a2d3914877
Core: added separate function for local source address cmsg.
Vladimir Homutov <vl@nginx.com>
parents:
8401
diff
changeset
|
80 #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
|
81 if (ls->wildcard) { |
8513
e7a2d3914877
Core: added separate function for local source address cmsg.
Vladimir Homutov <vl@nginx.com>
parents:
8401
diff
changeset
|
82 msg.msg_control = &msg_control; |
e7a2d3914877
Core: added separate function for local source address cmsg.
Vladimir Homutov <vl@nginx.com>
parents:
8401
diff
changeset
|
83 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
|
84 |
8513
e7a2d3914877
Core: added separate function for local source address cmsg.
Vladimir Homutov <vl@nginx.com>
parents:
8401
diff
changeset
|
85 ngx_memzero(&msg_control, sizeof(msg_control)); |
e7a2d3914877
Core: added separate function for local source address cmsg.
Vladimir Homutov <vl@nginx.com>
parents:
8401
diff
changeset
|
86 } |
7285
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
87 #endif |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
88 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
89 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
|
90 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
91 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
|
92 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
|
93 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
94 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
|
95 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, ev->log, err, |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
96 "recvmsg() not ready"); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
97 return; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
98 } |
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 ngx_log_error(NGX_LOG_ALERT, ev->log, err, "recvmsg() failed"); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
101 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
102 return; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
103 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
104 |
8513
e7a2d3914877
Core: added separate function for local source address cmsg.
Vladimir Homutov <vl@nginx.com>
parents:
8401
diff
changeset
|
105 #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
|
106 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
|
107 ngx_log_error(NGX_LOG_ALERT, ev->log, 0, |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
108 "recvmsg() truncated data"); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
109 continue; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
110 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
111 #endif |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
112 |
8384
c61fcdc1b8e3
UDP: extended datagram context.
Vladimir Homutov <vl@nginx.com>
parents:
8383
diff
changeset
|
113 dgram.sockaddr = msg.msg_name; |
c61fcdc1b8e3
UDP: extended datagram context.
Vladimir Homutov <vl@nginx.com>
parents:
8383
diff
changeset
|
114 dgram.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
|
115 |
8384
c61fcdc1b8e3
UDP: extended datagram context.
Vladimir Homutov <vl@nginx.com>
parents:
8383
diff
changeset
|
116 if (dgram.socklen > (socklen_t) sizeof(ngx_sockaddr_t)) { |
c61fcdc1b8e3
UDP: extended datagram context.
Vladimir Homutov <vl@nginx.com>
parents:
8383
diff
changeset
|
117 dgram.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
|
118 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
119 |
8384
c61fcdc1b8e3
UDP: extended datagram context.
Vladimir Homutov <vl@nginx.com>
parents:
8383
diff
changeset
|
120 if (dgram.socklen == 0) { |
7285
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
121 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
122 /* |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
123 * on Linux recvmsg() returns zero msg_namelen |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
124 * when receiving packets from unbound AF_UNIX sockets |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
125 */ |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
126 |
8384
c61fcdc1b8e3
UDP: extended datagram context.
Vladimir Homutov <vl@nginx.com>
parents:
8383
diff
changeset
|
127 dgram.socklen = sizeof(struct sockaddr); |
7285
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
128 ngx_memzero(&sa, sizeof(struct sockaddr)); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
129 sa.sockaddr.sa_family = ls->sockaddr->sa_family; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
130 } |
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 |
8513
e7a2d3914877
Core: added separate function for local source address cmsg.
Vladimir Homutov <vl@nginx.com>
parents:
8401
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 { |
8513
e7a2d3914877
Core: added separate function for local source address cmsg.
Vladimir Homutov <vl@nginx.com>
parents:
8401
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 |
8384
c61fcdc1b8e3
UDP: extended datagram context.
Vladimir Homutov <vl@nginx.com>
parents:
8383
diff
changeset
|
155 key.data = (u_char *) dgram.sockaddr; |
c61fcdc1b8e3
UDP: extended datagram context.
Vladimir Homutov <vl@nginx.com>
parents:
8383
diff
changeset
|
156 key.len = dgram.socklen; |
8382
db58c7ef1d7c
QUIC: do not handle empty dcid.
Roman Arutyunyan <arut@nginx.com>
parents:
8381
diff
changeset
|
157 |
db58c7ef1d7c
QUIC: do not handle empty dcid.
Roman Arutyunyan <arut@nginx.com>
parents:
8381
diff
changeset
|
158 #if (NGX_HAVE_UNIX_DOMAIN) |
db58c7ef1d7c
QUIC: do not handle empty dcid.
Roman Arutyunyan <arut@nginx.com>
parents:
8381
diff
changeset
|
159 |
8384
c61fcdc1b8e3
UDP: extended datagram context.
Vladimir Homutov <vl@nginx.com>
parents:
8383
diff
changeset
|
160 if (dgram.sockaddr->sa_family == AF_UNIX) { |
c61fcdc1b8e3
UDP: extended datagram context.
Vladimir Homutov <vl@nginx.com>
parents:
8383
diff
changeset
|
161 struct sockaddr_un *saun = (struct sockaddr_un *) dgram.sockaddr; |
8382
db58c7ef1d7c
QUIC: do not handle empty dcid.
Roman Arutyunyan <arut@nginx.com>
parents:
8381
diff
changeset
|
162 |
8384
c61fcdc1b8e3
UDP: extended datagram context.
Vladimir Homutov <vl@nginx.com>
parents:
8383
diff
changeset
|
163 if (dgram.socklen <= (socklen_t) offsetof(struct sockaddr_un, |
c61fcdc1b8e3
UDP: extended datagram context.
Vladimir Homutov <vl@nginx.com>
parents:
8383
diff
changeset
|
164 sun_path) |
8382
db58c7ef1d7c
QUIC: do not handle empty dcid.
Roman Arutyunyan <arut@nginx.com>
parents:
8381
diff
changeset
|
165 || saun->sun_path[0] == '\0') |
db58c7ef1d7c
QUIC: do not handle empty dcid.
Roman Arutyunyan <arut@nginx.com>
parents:
8381
diff
changeset
|
166 { |
db58c7ef1d7c
QUIC: do not handle empty dcid.
Roman Arutyunyan <arut@nginx.com>
parents:
8381
diff
changeset
|
167 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, ngx_cycle->log, 0, |
db58c7ef1d7c
QUIC: do not handle empty dcid.
Roman Arutyunyan <arut@nginx.com>
parents:
8381
diff
changeset
|
168 "unbound unix socket"); |
db58c7ef1d7c
QUIC: do not handle empty dcid.
Roman Arutyunyan <arut@nginx.com>
parents:
8381
diff
changeset
|
169 key.len = 0; |
db58c7ef1d7c
QUIC: do not handle empty dcid.
Roman Arutyunyan <arut@nginx.com>
parents:
8381
diff
changeset
|
170 } |
db58c7ef1d7c
QUIC: do not handle empty dcid.
Roman Arutyunyan <arut@nginx.com>
parents:
8381
diff
changeset
|
171 } |
db58c7ef1d7c
QUIC: do not handle empty dcid.
Roman Arutyunyan <arut@nginx.com>
parents:
8381
diff
changeset
|
172 |
db58c7ef1d7c
QUIC: do not handle empty dcid.
Roman Arutyunyan <arut@nginx.com>
parents:
8381
diff
changeset
|
173 #endif |
8198
45db1b5c1706
QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents:
7440
diff
changeset
|
174 |
45db1b5c1706
QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents:
7440
diff
changeset
|
175 #if (NGX_QUIC) |
45db1b5c1706
QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents:
7440
diff
changeset
|
176 if (ls->quic) { |
45db1b5c1706
QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents:
7440
diff
changeset
|
177 if (ngx_quic_get_packet_dcid(ev->log, buffer, n, &key) != NGX_OK) { |
45db1b5c1706
QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents:
7440
diff
changeset
|
178 goto next; |
45db1b5c1706
QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents:
7440
diff
changeset
|
179 } |
45db1b5c1706
QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents:
7440
diff
changeset
|
180 } |
45db1b5c1706
QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents:
7440
diff
changeset
|
181 #endif |
45db1b5c1706
QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents:
7440
diff
changeset
|
182 |
8382
db58c7ef1d7c
QUIC: do not handle empty dcid.
Roman Arutyunyan <arut@nginx.com>
parents:
8381
diff
changeset
|
183 c = ngx_lookup_udp_connection(ls, &key, local_sockaddr, local_socklen); |
7286 | 184 |
185 if (c) { | |
186 | |
187 #if (NGX_DEBUG) | |
188 if (c->log->log_level & NGX_LOG_DEBUG_EVENT) { | |
189 ngx_log_handler_pt handler; | |
190 | |
191 handler = c->log->handler; | |
192 c->log->handler = NULL; | |
193 | |
194 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0, | |
195 "recvmsg: fd:%d n:%z", c->fd, n); | |
196 | |
197 c->log->handler = handler; | |
198 } | |
199 #endif | |
200 | |
201 ngx_memzero(&buf, sizeof(ngx_buf_t)); | |
202 | |
203 buf.pos = buffer; | |
204 buf.last = buffer + n; | |
8383
385d511b5064
QUIC: fixed udp buffer initialization.
Vladimir Homutov <vl@nginx.com>
parents:
8382
diff
changeset
|
205 buf.start = buf.pos; |
385d511b5064
QUIC: fixed udp buffer initialization.
Vladimir Homutov <vl@nginx.com>
parents:
8382
diff
changeset
|
206 buf.end = buffer + sizeof(buffer); |
7286 | 207 |
208 rev = c->read; | |
209 | |
8384
c61fcdc1b8e3
UDP: extended datagram context.
Vladimir Homutov <vl@nginx.com>
parents:
8383
diff
changeset
|
210 dgram.buffer = &buf; |
c61fcdc1b8e3
UDP: extended datagram context.
Vladimir Homutov <vl@nginx.com>
parents:
8383
diff
changeset
|
211 |
c61fcdc1b8e3
UDP: extended datagram context.
Vladimir Homutov <vl@nginx.com>
parents:
8383
diff
changeset
|
212 c->udp->dgram = &dgram; |
7440
6d4bc025c5a7
Prevented scheduling events on a shared connection.
Roman Arutyunyan <arut@nginx.com>
parents:
7393
diff
changeset
|
213 |
7286 | 214 rev->ready = 1; |
7440
6d4bc025c5a7
Prevented scheduling events on a shared connection.
Roman Arutyunyan <arut@nginx.com>
parents:
7393
diff
changeset
|
215 rev->active = 0; |
7286 | 216 |
217 rev->handler(rev); | |
218 | |
7391
27559d4a5151
Stream: fixed possible use of a freed connection.
Vladimir Homutov <vl@nginx.com>
parents:
7286
diff
changeset
|
219 if (c->udp) { |
8384
c61fcdc1b8e3
UDP: extended datagram context.
Vladimir Homutov <vl@nginx.com>
parents:
8383
diff
changeset
|
220 c->udp->dgram = NULL; |
7391
27559d4a5151
Stream: fixed possible use of a freed connection.
Vladimir Homutov <vl@nginx.com>
parents:
7286
diff
changeset
|
221 } |
27559d4a5151
Stream: fixed possible use of a freed connection.
Vladimir Homutov <vl@nginx.com>
parents:
7286
diff
changeset
|
222 |
7286 | 223 rev->ready = 0; |
7440
6d4bc025c5a7
Prevented scheduling events on a shared connection.
Roman Arutyunyan <arut@nginx.com>
parents:
7393
diff
changeset
|
224 rev->active = 1; |
7286 | 225 |
226 goto next; | |
227 } | |
228 | |
7285
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
229 #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
|
230 (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
|
231 #endif |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
232 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
233 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
|
234 - 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
|
235 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
236 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
|
237 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
|
238 return; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
239 } |
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 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
|
242 c->type = SOCK_DGRAM; |
8384
c61fcdc1b8e3
UDP: extended datagram context.
Vladimir Homutov <vl@nginx.com>
parents:
8383
diff
changeset
|
243 c->socklen = dgram.socklen; |
7285
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
244 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
245 #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
|
246 (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
|
247 #endif |
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->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
|
250 if (c->pool == NULL) { |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
251 ngx_close_accepted_udp_connection(c); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
252 return; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
253 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
254 |
8384
c61fcdc1b8e3
UDP: extended datagram context.
Vladimir Homutov <vl@nginx.com>
parents:
8383
diff
changeset
|
255 len = dgram.socklen; |
8381
d62a16fff3a4
QUIC: do not reallocate c->sockaddr.
Roman Arutyunyan <arut@nginx.com>
parents:
8198
diff
changeset
|
256 |
d62a16fff3a4
QUIC: do not reallocate c->sockaddr.
Roman Arutyunyan <arut@nginx.com>
parents:
8198
diff
changeset
|
257 #if (NGX_QUIC) |
d62a16fff3a4
QUIC: do not reallocate c->sockaddr.
Roman Arutyunyan <arut@nginx.com>
parents:
8198
diff
changeset
|
258 if (ls->quic) { |
d62a16fff3a4
QUIC: do not reallocate c->sockaddr.
Roman Arutyunyan <arut@nginx.com>
parents:
8198
diff
changeset
|
259 len = NGX_SOCKADDRLEN; |
d62a16fff3a4
QUIC: do not reallocate c->sockaddr.
Roman Arutyunyan <arut@nginx.com>
parents:
8198
diff
changeset
|
260 } |
d62a16fff3a4
QUIC: do not reallocate c->sockaddr.
Roman Arutyunyan <arut@nginx.com>
parents:
8198
diff
changeset
|
261 #endif |
d62a16fff3a4
QUIC: do not reallocate c->sockaddr.
Roman Arutyunyan <arut@nginx.com>
parents:
8198
diff
changeset
|
262 |
d62a16fff3a4
QUIC: do not reallocate c->sockaddr.
Roman Arutyunyan <arut@nginx.com>
parents:
8198
diff
changeset
|
263 c->sockaddr = ngx_palloc(c->pool, len); |
7285
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
264 if (c->sockaddr == NULL) { |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
265 ngx_close_accepted_udp_connection(c); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
266 return; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
267 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
268 |
8384
c61fcdc1b8e3
UDP: extended datagram context.
Vladimir Homutov <vl@nginx.com>
parents:
8383
diff
changeset
|
269 ngx_memcpy(c->sockaddr, dgram.sockaddr, dgram.socklen); |
7285
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 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
|
272 if (log == NULL) { |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
273 ngx_close_accepted_udp_connection(c); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
274 return; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
275 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
276 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
277 *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
|
278 |
7286 | 279 c->recv = ngx_udp_shared_recv; |
7285
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
280 c->send = ngx_udp_send; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
281 c->send_chain = ngx_udp_send_chain; |
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 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
|
284 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
|
285 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
|
286 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
287 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
|
288 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
|
289 if (local_sockaddr == NULL) { |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
290 ngx_close_accepted_udp_connection(c); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
291 return; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
292 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
293 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
294 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
|
295 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
296 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
297 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
|
298 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
|
299 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
300 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
|
301 if (c->buffer == NULL) { |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
302 ngx_close_accepted_udp_connection(c); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
303 return; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
304 } |
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 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
|
307 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
308 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
|
309 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
|
310 |
7440
6d4bc025c5a7
Prevented scheduling events on a shared connection.
Roman Arutyunyan <arut@nginx.com>
parents:
7393
diff
changeset
|
311 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
|
312 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
|
313 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
314 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
|
315 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
|
316 |
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 * 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
|
319 * 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
|
320 * |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
321 * 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
|
322 * - 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
|
323 * 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
|
324 */ |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
325 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
326 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
|
327 |
8396
fdc3d40979b0
Introduced the "keepalive_time" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7440
diff
changeset
|
328 c->start_time = ngx_current_msec; |
fdc3d40979b0
Introduced the "keepalive_time" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7440
diff
changeset
|
329 |
7285
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
330 #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
|
331 (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
|
332 #endif |
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 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
|
335 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
|
336 if (c->addr_text.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 ngx_close_accepted_udp_connection(c); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
338 return; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
339 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
340 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
341 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
|
342 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
|
343 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
|
344 if (c->addr_text.len == 0) { |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
345 ngx_close_accepted_udp_connection(c); |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
346 return; |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
347 } |
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 #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
|
351 { |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
352 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
|
353 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
|
354 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
355 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
|
356 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
357 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
|
358 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
|
359 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
|
360 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
|
361 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
362 ngx_log_debug4(NGX_LOG_DEBUG_EVENT, log, 0, |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
363 "*%uA recvmsg: %V fd:%d n:%z", |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
364 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
|
365 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
366 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
367 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
368 #endif |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
369 |
8198
45db1b5c1706
QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents:
7440
diff
changeset
|
370 if (ngx_create_udp_connection(c) != NGX_OK) { |
7286 | 371 ngx_close_accepted_udp_connection(c); |
372 return; | |
373 } | |
374 | |
7285
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
375 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
|
376 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
|
377 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
378 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
|
379 |
7286 | 380 next: |
381 | |
7285
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
382 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
|
383 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
|
384 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
385 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
386 } 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
|
387 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
388 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
389 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
390 static void |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
391 ngx_close_accepted_udp_connection(ngx_connection_t *c) |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
392 { |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
393 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
|
394 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
395 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
|
396 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
397 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
|
398 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
|
399 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
400 |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
401 #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
|
402 (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
|
403 #endif |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
404 } |
88a624c9b491
Events: moved ngx_recvmsg() to new file src/event/ngx_event_udp.c.
Roman Arutyunyan <arut@nginx.com>
parents:
diff
changeset
|
405 |
7286 | 406 |
407 static ssize_t | |
408 ngx_udp_shared_recv(ngx_connection_t *c, u_char *buf, size_t size) | |
409 { | |
410 ssize_t n; | |
411 ngx_buf_t *b; | |
412 | |
8384
c61fcdc1b8e3
UDP: extended datagram context.
Vladimir Homutov <vl@nginx.com>
parents:
8383
diff
changeset
|
413 if (c->udp == NULL || c->udp->dgram == NULL) { |
7286 | 414 return NGX_AGAIN; |
415 } | |
416 | |
8384
c61fcdc1b8e3
UDP: extended datagram context.
Vladimir Homutov <vl@nginx.com>
parents:
8383
diff
changeset
|
417 b = c->udp->dgram->buffer; |
7286 | 418 |
419 n = ngx_min(b->last - b->pos, (ssize_t) size); | |
420 | |
421 ngx_memcpy(buf, b->pos, n); | |
422 | |
8384
c61fcdc1b8e3
UDP: extended datagram context.
Vladimir Homutov <vl@nginx.com>
parents:
8383
diff
changeset
|
423 c->udp->dgram = NULL; |
7440
6d4bc025c5a7
Prevented scheduling events on a shared connection.
Roman Arutyunyan <arut@nginx.com>
parents:
7393
diff
changeset
|
424 |
7286 | 425 c->read->ready = 0; |
7440
6d4bc025c5a7
Prevented scheduling events on a shared connection.
Roman Arutyunyan <arut@nginx.com>
parents:
7393
diff
changeset
|
426 c->read->active = 1; |
7286 | 427 |
428 return n; | |
429 } | |
430 | |
431 | |
432 void | |
433 ngx_udp_rbtree_insert_value(ngx_rbtree_node_t *temp, | |
434 ngx_rbtree_node_t *node, ngx_rbtree_node_t *sentinel) | |
435 { | |
436 ngx_int_t rc; | |
437 ngx_connection_t *c, *ct; | |
438 ngx_rbtree_node_t **p; | |
439 ngx_udp_connection_t *udp, *udpt; | |
440 | |
441 for ( ;; ) { | |
442 | |
443 if (node->key < temp->key) { | |
444 | |
445 p = &temp->left; | |
446 | |
447 } else if (node->key > temp->key) { | |
448 | |
449 p = &temp->right; | |
450 | |
451 } else { /* node->key == temp->key */ | |
452 | |
453 udp = (ngx_udp_connection_t *) node; | |
454 c = udp->connection; | |
455 | |
456 udpt = (ngx_udp_connection_t *) temp; | |
457 ct = udpt->connection; | |
458 | |
8198
45db1b5c1706
QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents:
7440
diff
changeset
|
459 rc = ngx_memn2cmp(udp->key.data, udpt->key.data, |
45db1b5c1706
QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents:
7440
diff
changeset
|
460 udp->key.len, udpt->key.len); |
7286 | 461 |
462 if (rc == 0 && c->listening->wildcard) { | |
463 rc = ngx_cmp_sockaddr(c->local_sockaddr, c->local_socklen, | |
464 ct->local_sockaddr, ct->local_socklen, 1); | |
465 } | |
466 | |
467 p = (rc < 0) ? &temp->left : &temp->right; | |
468 } | |
469 | |
470 if (*p == sentinel) { | |
471 break; | |
472 } | |
473 | |
474 temp = *p; | |
475 } | |
476 | |
477 *p = node; | |
478 node->parent = temp; | |
479 node->left = sentinel; | |
480 node->right = sentinel; | |
481 ngx_rbt_red(node); | |
482 } | |
483 | |
484 | |
485 static ngx_int_t | |
8198
45db1b5c1706
QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents:
7440
diff
changeset
|
486 ngx_create_udp_connection(ngx_connection_t *c) |
7286 | 487 { |
8198
45db1b5c1706
QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents:
7440
diff
changeset
|
488 ngx_str_t key; |
7286 | 489 ngx_pool_cleanup_t *cln; |
490 ngx_udp_connection_t *udp; | |
491 | |
8198
45db1b5c1706
QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents:
7440
diff
changeset
|
492 #if (NGX_QUIC) |
45db1b5c1706
QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents:
7440
diff
changeset
|
493 if (c->listening->quic) { |
45db1b5c1706
QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents:
7440
diff
changeset
|
494 return NGX_OK; |
45db1b5c1706
QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents:
7440
diff
changeset
|
495 } |
45db1b5c1706
QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents:
7440
diff
changeset
|
496 #endif |
45db1b5c1706
QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents:
7440
diff
changeset
|
497 |
7286 | 498 if (c->udp) { |
499 return NGX_OK; | |
500 } | |
501 | |
502 udp = ngx_pcalloc(c->pool, sizeof(ngx_udp_connection_t)); | |
503 if (udp == NULL) { | |
504 return NGX_ERROR; | |
505 } | |
506 | |
507 cln = ngx_pool_cleanup_add(c->pool, 0); | |
508 if (cln == NULL) { | |
509 return NGX_ERROR; | |
510 } | |
511 | |
512 cln->data = c; | |
513 cln->handler = ngx_delete_udp_connection; | |
514 | |
8382
db58c7ef1d7c
QUIC: do not handle empty dcid.
Roman Arutyunyan <arut@nginx.com>
parents:
8381
diff
changeset
|
515 key.data = (u_char *) c->sockaddr; |
db58c7ef1d7c
QUIC: do not handle empty dcid.
Roman Arutyunyan <arut@nginx.com>
parents:
8381
diff
changeset
|
516 key.len = c->socklen; |
8198
45db1b5c1706
QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents:
7440
diff
changeset
|
517 |
45db1b5c1706
QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents:
7440
diff
changeset
|
518 ngx_insert_udp_connection(c, udp, &key); |
7286 | 519 |
520 c->udp = udp; | |
521 | |
522 return NGX_OK; | |
523 } | |
524 | |
525 | |
7393
4698cede59ff
Stream: proxy_requests directive.
Vladimir Homutov <vl@nginx.com>
parents:
7391
diff
changeset
|
526 void |
8198
45db1b5c1706
QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents:
7440
diff
changeset
|
527 ngx_insert_udp_connection(ngx_connection_t *c, ngx_udp_connection_t *udp, |
45db1b5c1706
QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents:
7440
diff
changeset
|
528 ngx_str_t *key) |
45db1b5c1706
QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents:
7440
diff
changeset
|
529 { |
45db1b5c1706
QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents:
7440
diff
changeset
|
530 uint32_t hash; |
45db1b5c1706
QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents:
7440
diff
changeset
|
531 |
45db1b5c1706
QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents:
7440
diff
changeset
|
532 ngx_crc32_init(hash); |
45db1b5c1706
QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents:
7440
diff
changeset
|
533 |
45db1b5c1706
QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents:
7440
diff
changeset
|
534 ngx_crc32_update(&hash, key->data, key->len); |
45db1b5c1706
QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents:
7440
diff
changeset
|
535 |
45db1b5c1706
QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents:
7440
diff
changeset
|
536 if (c->listening->wildcard) { |
45db1b5c1706
QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents:
7440
diff
changeset
|
537 ngx_crc32_update(&hash, (u_char *) c->local_sockaddr, c->local_socklen); |
45db1b5c1706
QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents:
7440
diff
changeset
|
538 } |
45db1b5c1706
QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents:
7440
diff
changeset
|
539 |
45db1b5c1706
QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents:
7440
diff
changeset
|
540 ngx_crc32_final(hash); |
45db1b5c1706
QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents:
7440
diff
changeset
|
541 |
45db1b5c1706
QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents:
7440
diff
changeset
|
542 udp->connection = c; |
45db1b5c1706
QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents:
7440
diff
changeset
|
543 udp->key = *key; |
45db1b5c1706
QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents:
7440
diff
changeset
|
544 udp->node.key = hash; |
45db1b5c1706
QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents:
7440
diff
changeset
|
545 |
45db1b5c1706
QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents:
7440
diff
changeset
|
546 ngx_rbtree_insert(&c->listening->rbtree, &udp->node); |
45db1b5c1706
QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents:
7440
diff
changeset
|
547 } |
45db1b5c1706
QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents:
7440
diff
changeset
|
548 |
45db1b5c1706
QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents:
7440
diff
changeset
|
549 |
45db1b5c1706
QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents:
7440
diff
changeset
|
550 void |
7286 | 551 ngx_delete_udp_connection(void *data) |
552 { | |
553 ngx_connection_t *c = data; | |
554 | |
7393
4698cede59ff
Stream: proxy_requests directive.
Vladimir Homutov <vl@nginx.com>
parents:
7391
diff
changeset
|
555 if (c->udp == NULL) { |
4698cede59ff
Stream: proxy_requests directive.
Vladimir Homutov <vl@nginx.com>
parents:
7391
diff
changeset
|
556 return; |
4698cede59ff
Stream: proxy_requests directive.
Vladimir Homutov <vl@nginx.com>
parents:
7391
diff
changeset
|
557 } |
4698cede59ff
Stream: proxy_requests directive.
Vladimir Homutov <vl@nginx.com>
parents:
7391
diff
changeset
|
558 |
7286 | 559 ngx_rbtree_delete(&c->listening->rbtree, &c->udp->node); |
7391
27559d4a5151
Stream: fixed possible use of a freed connection.
Vladimir Homutov <vl@nginx.com>
parents:
7286
diff
changeset
|
560 |
27559d4a5151
Stream: fixed possible use of a freed connection.
Vladimir Homutov <vl@nginx.com>
parents:
7286
diff
changeset
|
561 c->udp = NULL; |
7286 | 562 } |
563 | |
564 | |
565 static ngx_connection_t * | |
8198
45db1b5c1706
QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents:
7440
diff
changeset
|
566 ngx_lookup_udp_connection(ngx_listening_t *ls, ngx_str_t *key, |
45db1b5c1706
QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents:
7440
diff
changeset
|
567 struct sockaddr *local_sockaddr, socklen_t local_socklen) |
7286 | 568 { |
569 uint32_t hash; | |
570 ngx_int_t rc; | |
571 ngx_connection_t *c; | |
572 ngx_rbtree_node_t *node, *sentinel; | |
573 ngx_udp_connection_t *udp; | |
574 | |
8382
db58c7ef1d7c
QUIC: do not handle empty dcid.
Roman Arutyunyan <arut@nginx.com>
parents:
8381
diff
changeset
|
575 if (key->len == 0) { |
db58c7ef1d7c
QUIC: do not handle empty dcid.
Roman Arutyunyan <arut@nginx.com>
parents:
8381
diff
changeset
|
576 return NULL; |
7286 | 577 } |
578 | |
579 node = ls->rbtree.root; | |
580 sentinel = ls->rbtree.sentinel; | |
581 | |
582 ngx_crc32_init(hash); | |
8198
45db1b5c1706
QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents:
7440
diff
changeset
|
583 ngx_crc32_update(&hash, key->data, key->len); |
7286 | 584 |
585 if (ls->wildcard) { | |
586 ngx_crc32_update(&hash, (u_char *) local_sockaddr, local_socklen); | |
587 } | |
588 | |
589 ngx_crc32_final(hash); | |
590 | |
591 while (node != sentinel) { | |
592 | |
593 if (hash < node->key) { | |
594 node = node->left; | |
595 continue; | |
596 } | |
597 | |
598 if (hash > node->key) { | |
599 node = node->right; | |
600 continue; | |
601 } | |
602 | |
603 /* hash == node->key */ | |
604 | |
605 udp = (ngx_udp_connection_t *) node; | |
606 | |
607 c = udp->connection; | |
608 | |
8198
45db1b5c1706
QUIC: connection multiplexing per port.
Roman Arutyunyan <arut@nginx.com>
parents:
7440
diff
changeset
|
609 rc = ngx_memn2cmp(key->data, udp->key.data, key->len, udp->key.len); |
7286 | 610 |
611 if (rc == 0 && ls->wildcard) { | |
612 rc = ngx_cmp_sockaddr(local_sockaddr, local_socklen, | |
613 c->local_sockaddr, c->local_socklen, 1); | |
614 } | |
615 | |
616 if (rc == 0) { | |
8385
9ce6d80df113
QUIC: simplified quic connection dispatching.
Vladimir Homutov <vl@nginx.com>
parents:
8384
diff
changeset
|
617 |
9ce6d80df113
QUIC: simplified quic connection dispatching.
Vladimir Homutov <vl@nginx.com>
parents:
8384
diff
changeset
|
618 #if (NGX_QUIC) |
9ce6d80df113
QUIC: simplified quic connection dispatching.
Vladimir Homutov <vl@nginx.com>
parents:
8384
diff
changeset
|
619 if (ls->quic && c->udp != udp) { |
9ce6d80df113
QUIC: simplified quic connection dispatching.
Vladimir Homutov <vl@nginx.com>
parents:
8384
diff
changeset
|
620 c->udp = udp; |
9ce6d80df113
QUIC: simplified quic connection dispatching.
Vladimir Homutov <vl@nginx.com>
parents:
8384
diff
changeset
|
621 } |
9ce6d80df113
QUIC: simplified quic connection dispatching.
Vladimir Homutov <vl@nginx.com>
parents:
8384
diff
changeset
|
622 #endif |
9ce6d80df113
QUIC: simplified quic connection dispatching.
Vladimir Homutov <vl@nginx.com>
parents:
8384
diff
changeset
|
623 |
7286 | 624 return c; |
625 } | |
626 | |
627 node = (rc < 0) ? node->left : node->right; | |
628 } | |
629 | |
630 return NULL; | |
631 } | |
632 | |
7393
4698cede59ff
Stream: proxy_requests directive.
Vladimir Homutov <vl@nginx.com>
parents:
7391
diff
changeset
|
633 #else |
4698cede59ff
Stream: proxy_requests directive.
Vladimir Homutov <vl@nginx.com>
parents:
7391
diff
changeset
|
634 |
4698cede59ff
Stream: proxy_requests directive.
Vladimir Homutov <vl@nginx.com>
parents:
7391
diff
changeset
|
635 void |
4698cede59ff
Stream: proxy_requests directive.
Vladimir Homutov <vl@nginx.com>
parents:
7391
diff
changeset
|
636 ngx_delete_udp_connection(void *data) |
4698cede59ff
Stream: proxy_requests directive.
Vladimir Homutov <vl@nginx.com>
parents:
7391
diff
changeset
|
637 { |
4698cede59ff
Stream: proxy_requests directive.
Vladimir Homutov <vl@nginx.com>
parents:
7391
diff
changeset
|
638 return; |
4698cede59ff
Stream: proxy_requests directive.
Vladimir Homutov <vl@nginx.com>
parents:
7391
diff
changeset
|
639 } |
4698cede59ff
Stream: proxy_requests directive.
Vladimir Homutov <vl@nginx.com>
parents:
7391
diff
changeset
|
640 |
7286 | 641 #endif |