Mercurial > hg > nginx-quic
annotate src/core/ngx_crc32.h @ 7440:6d4bc025c5a7
Prevented scheduling events on a shared connection.
A shared connection does not own its file descriptor, which means that
ngx_handle_read_event/ngx_handle_write_event calls should do nothing for it.
Currently the c->shared flag is checked in several places in the stream proxy
module prior to calling these functions. However it was not done everywhere.
Missing checks could lead to calling
ngx_handle_read_event/ngx_handle_write_event on shared connections.
The problem manifested itself when using proxy_upload_rate and resulted in
either duplicate file descriptor error (e.g. with epoll) or incorrect further
udp packet processing (e.g. with kqueue).
The fix is to set and reset the event active flag in a way that prevents
ngx_handle_read_event/ngx_handle_write_event from scheduling socket events.
author | Roman Arutyunyan <arut@nginx.com> |
---|---|
date | Mon, 14 Jan 2019 20:36:23 +0300 |
parents | d620f497c50f |
children |
rev | line source |
---|---|
790 | 1 |
2 /* | |
3 * Copyright (C) Igor Sysoev | |
4412 | 4 * Copyright (C) Nginx, Inc. |
790 | 5 */ |
6 | |
7 | |
8 #ifndef _NGX_CRC32_H_INCLUDED_ | |
9 #define _NGX_CRC32_H_INCLUDED_ | |
10 | |
11 | |
12 #include <ngx_config.h> | |
13 #include <ngx_core.h> | |
14 | |
15 | |
793
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
16 extern uint32_t *ngx_crc32_table_short; |
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
17 extern uint32_t ngx_crc32_table256[]; |
790 | 18 |
19 | |
20 static ngx_inline uint32_t | |
793
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
21 ngx_crc32_short(u_char *p, size_t len) |
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
22 { |
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
23 u_char c; |
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
24 uint32_t crc; |
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
25 |
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
26 crc = 0xffffffff; |
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
27 |
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
28 while (len--) { |
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
29 c = *p++; |
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
30 crc = ngx_crc32_table_short[(crc ^ (c & 0xf)) & 0xf] ^ (crc >> 4); |
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
31 crc = ngx_crc32_table_short[(crc ^ (c >> 4)) & 0xf] ^ (crc >> 4); |
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
32 } |
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
33 |
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
34 return crc ^ 0xffffffff; |
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
35 } |
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
36 |
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
37 |
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
38 static ngx_inline uint32_t |
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
39 ngx_crc32_long(u_char *p, size_t len) |
790 | 40 { |
41 uint32_t crc; | |
42 | |
43 crc = 0xffffffff; | |
44 | |
45 while (len--) { | |
793
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
46 crc = ngx_crc32_table256[(crc ^ *p++) & 0xff] ^ (crc >> 8); |
790 | 47 } |
48 | |
49 return crc ^ 0xffffffff; | |
50 } | |
51 | |
52 | |
1694
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
53 #define ngx_crc32_init(crc) \ |
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
54 crc = 0xffffffff |
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
55 |
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
56 |
1697 | 57 static ngx_inline void |
1694
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
58 ngx_crc32_update(uint32_t *crc, u_char *p, size_t len) |
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
59 { |
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
60 uint32_t c; |
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
61 |
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
62 c = *crc; |
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
63 |
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
64 while (len--) { |
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
65 c = ngx_crc32_table256[(c ^ *p++) & 0xff] ^ (c >> 8); |
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
66 } |
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
67 |
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
68 *crc = c; |
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
69 } |
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
70 |
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
71 |
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
72 #define ngx_crc32_final(crc) \ |
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
73 crc ^= 0xffffffff |
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
74 |
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
75 |
8c696afe46b3
rename ngx_crc32_init() to ngx_crc32_table_init()
Igor Sysoev <igor@sysoev.ru>
parents:
930
diff
changeset
|
76 ngx_int_t ngx_crc32_table_init(void); |
793
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
77 |
8d39da951bbd
split ngx_crc32() to short and long version
Igor Sysoev <igor@sysoev.ru>
parents:
790
diff
changeset
|
78 |
790 | 79 #endif /* _NGX_CRC32_H_INCLUDED_ */ |