- new folder src/ to hold the source code for main project applications
- main.c is in src/
- all core files are subfolder are in src/core/
- modules are in src/modules/
- libs are in src/lib/
- application Makefiles are in src/
- application binary is built in src/ (src/kamailio)
1 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,398 +0,0 @@ |
1 |
-/* |
|
2 |
- * Copyright (C) 2007 iptelorg GmbH |
|
3 |
- * |
|
4 |
- * Permission to use, copy, modify, and distribute this software for any |
|
5 |
- * purpose with or without fee is hereby granted, provided that the above |
|
6 |
- * copyright notice and this permission notice appear in all copies. |
|
7 |
- * |
|
8 |
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
9 |
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|
10 |
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|
11 |
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
12 |
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|
13 |
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|
14 |
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
15 |
- */ |
|
16 |
- |
|
17 |
-/*! |
|
18 |
- * \file |
|
19 |
- * \brief Kamailio core :: tcp options |
|
20 |
- * \ingroup core |
|
21 |
- * Module: \ref core |
|
22 |
- */ |
|
23 |
- |
|
24 |
-#include "tcp_options.h" |
|
25 |
-#include "dprint.h" |
|
26 |
-#include "globals.h" |
|
27 |
-#include "timer_ticks.h" |
|
28 |
-#include "cfg/cfg.h" |
|
29 |
-#include "tcp_init.h" /* DEFAULT* */ |
|
30 |
- |
|
31 |
- |
|
32 |
- |
|
33 |
-/* default/initial values for tcp config options |
|
34 |
- NOTE: all the options are initialized in init_tcp_options() |
|
35 |
- depending on compile time defines */ |
|
36 |
-struct cfg_group_tcp tcp_default_cfg; |
|
37 |
- |
|
38 |
- |
|
39 |
- |
|
40 |
-static int fix_connect_to(void* cfg_h, str* gname, str* name, void** val); |
|
41 |
-static int fix_send_to(void* cfg_h, str* gname, str* name, void** val); |
|
42 |
-static int fix_con_lt(void* cfg_h, str* gname, str* name, void** val); |
|
43 |
-static int fix_max_conns(void* cfg_h, str* gname, str* name, void** val); |
|
44 |
-static int fix_max_tls_conns(void* cfg_h, str* gname, str* name, void** val); |
|
45 |
- |
|
46 |
- |
|
47 |
- |
|
48 |
-/* cfg_group_tcp description (for the config framework)*/ |
|
49 |
-static cfg_def_t tcp_cfg_def[] = { |
|
50 |
- /* name , type |input type| chg type, min, max, fixup, proc. cbk |
|
51 |
- description */ |
|
52 |
- { "connect_timeout", CFG_VAR_INT | CFG_ATOMIC, -1, |
|
53 |
- TICKS_TO_S(MAX_TCP_CON_LIFETIME), fix_connect_to, 0, |
|
54 |
- "used only in non-async mode, in seconds"}, |
|
55 |
- { "send_timeout", CFG_VAR_INT | CFG_ATOMIC, -1, |
|
56 |
- MAX_TCP_CON_LIFETIME, fix_send_to, 0, |
|
57 |
- "in seconds"}, |
|
58 |
- { "connection_lifetime", CFG_VAR_INT | CFG_ATOMIC, -1, |
|
59 |
- MAX_TCP_CON_LIFETIME, fix_con_lt, 0, |
|
60 |
- "connection lifetime (in seconds)"}, |
|
61 |
- { "max_connections", CFG_VAR_INT | CFG_ATOMIC, 0, (1U<<31)-1, |
|
62 |
- fix_max_conns, 0, |
|
63 |
- "maximum tcp connections number, soft limit"}, |
|
64 |
- { "max_tls_connections", CFG_VAR_INT | CFG_ATOMIC, 0, (1U<<31)-1, |
|
65 |
- fix_max_tls_conns,0, |
|
66 |
- "maximum tls connections number, soft limit"}, |
|
67 |
- { "no_connect", CFG_VAR_INT | CFG_ATOMIC, 0, 1, 0, 0, |
|
68 |
- "if set only accept new connections, never actively open new ones"}, |
|
69 |
- { "fd_cache", CFG_VAR_INT | CFG_READONLY, 0, 1, 0, 0, |
|
70 |
- "file descriptor cache for tcp_send"}, |
|
71 |
- /* tcp async options */ |
|
72 |
- { "async", CFG_VAR_INT | CFG_READONLY, 0, 1, 0, 0, |
|
73 |
- "async mode for writes and connects"}, |
|
74 |
- { "connect_wait", CFG_VAR_INT | CFG_READONLY, 0, 1, 0, 0, |
|
75 |
- "parallel simultaneous connects to the same dst. (0) or one connect"}, |
|
76 |
- { "conn_wq_max", CFG_VAR_INT | CFG_ATOMIC, 0, 1024*1024, 0, 0, |
|
77 |
- "maximum bytes queued for write per connection (depends on async)"}, |
|
78 |
- { "wq_max", CFG_VAR_INT | CFG_ATOMIC, 0, 1<<30, 0, 0, |
|
79 |
- "maximum bytes queued for write allowed globally (depends on async)"}, |
|
80 |
- /* see also send_timeout above */ |
|
81 |
- /* tcp socket options */ |
|
82 |
- { "defer_accept", CFG_VAR_INT | CFG_READONLY, 0, 3600, 0, 0, |
|
83 |
- "0/1 on linux, seconds on freebsd (see docs)"}, |
|
84 |
- { "delayed_ack", CFG_VAR_INT | CFG_ATOMIC, 0, 1, 0, 0, |
|
85 |
- "initial ack will be delayed and sent with the first data segment"}, |
|
86 |
- { "syncnt", CFG_VAR_INT | CFG_ATOMIC, 0, 1024, 0, 0, |
|
87 |
- "number of syn retransmissions before aborting a connect (0=not set)"}, |
|
88 |
- { "linger2", CFG_VAR_INT | CFG_ATOMIC, 0, 3600, 0, 0, |
|
89 |
- "lifetime of orphaned sockets in FIN_WAIT2 state in s (0=not set)"}, |
|
90 |
- { "keepalive", CFG_VAR_INT | CFG_ATOMIC, 0, 1, 0, 0, |
|
91 |
- "enables/disables keepalives for tcp"}, |
|
92 |
- { "keepidle", CFG_VAR_INT | CFG_ATOMIC, 0, 24*3600, 0, 0, |
|
93 |
- "time before sending a keepalive if the connection is idle (linux)"}, |
|
94 |
- { "keepintvl", CFG_VAR_INT | CFG_ATOMIC, 0, 24*3600, 0, 0, |
|
95 |
- "time interval between keepalive probes on failure (linux)"}, |
|
96 |
- { "keepcnt", CFG_VAR_INT | CFG_ATOMIC, 0, 1<<10, 0, 0, |
|
97 |
- "number of failed keepalives before dropping the connection (linux)"}, |
|
98 |
- /* other options */ |
|
99 |
- { "crlf_ping", CFG_VAR_INT | CFG_ATOMIC, 0, 1, 0, 0, |
|
100 |
- "enable responding to CRLF SIP-level keepalives "}, |
|
101 |
- { "accept_aliases", CFG_VAR_INT | CFG_ATOMIC, 0, 1, 0, 0, |
|
102 |
- "turn on/off tcp aliases (see tcp_accept_aliases) "}, |
|
103 |
- { "alias_flags", CFG_VAR_INT | CFG_ATOMIC, 0, 2, 0, 0, |
|
104 |
- "flags used for adding new aliases (FORCE_ADD:1 , REPLACE:2) "}, |
|
105 |
- { "new_conn_alias_flags", CFG_VAR_INT | CFG_ATOMIC, 0, 2, 0, 0, |
|
106 |
- "flags for the def. aliases for a new conn. (FORCE_ADD:1, REPLACE:2 "}, |
|
107 |
- { "accept_no_cl", CFG_VAR_INT | CFG_ATOMIC, 0, 1, 0, 0, |
|
108 |
- "accept TCP messages without Content-Length "}, |
|
109 |
- /* internal and/or "fixed" versions of some vars |
|
110 |
- (not supposed to be writeable, read will provide only debugging value*/ |
|
111 |
- { "rd_buf_size", CFG_VAR_INT | CFG_ATOMIC, 512, 16777216, 0, 0, |
|
112 |
- "internal read buffer size (should be > max. expected datagram)"}, |
|
113 |
- { "wq_blk_size", CFG_VAR_INT | CFG_ATOMIC, 1, 65535, 0, 0, |
|
114 |
- "internal async write block size (debugging use only for now)"}, |
|
115 |
- {0, 0, 0, 0, 0, 0, 0} |
|
116 |
-}; |
|
117 |
- |
|
118 |
- |
|
119 |
-void* tcp_cfg; /* tcp config handle */ |
|
120 |
- |
|
121 |
-/* set defaults */ |
|
122 |
-void init_tcp_options() |
|
123 |
-{ |
|
124 |
- tcp_default_cfg.connect_timeout_s=DEFAULT_TCP_CONNECT_TIMEOUT; |
|
125 |
- tcp_default_cfg.send_timeout=S_TO_TICKS(DEFAULT_TCP_SEND_TIMEOUT); |
|
126 |
- tcp_default_cfg.con_lifetime=S_TO_TICKS(DEFAULT_TCP_CONNECTION_LIFETIME_S); |
|
127 |
-#ifdef USE_TCP |
|
128 |
- tcp_default_cfg.max_connections=tcp_max_connections; |
|
129 |
- tcp_default_cfg.max_tls_connections=tls_max_connections; |
|
130 |
-#else /*USE_TCP*/ |
|
131 |
- tcp_default_cfg.max_connections=0; |
|
132 |
- tcp_default_cfg.max_tls_connections=0; |
|
133 |
-#endif /*USE_TCP*/ |
|
134 |
-#ifdef TCP_ASYNC |
|
135 |
- tcp_default_cfg.async=1; |
|
136 |
- tcp_default_cfg.tcpconn_wq_max=32*1024; /* 32 k */ |
|
137 |
- tcp_default_cfg.tcp_wq_max=10*1024*1024; /* 10 MB */ |
|
138 |
-#ifdef TCP_CONNECT_WAIT |
|
139 |
- tcp_default_cfg.tcp_connect_wait=1; |
|
140 |
-#endif /* TCP_CONNECT_WAIT */ |
|
141 |
-#endif /* TCP_ASYNC */ |
|
142 |
-#ifdef TCP_FD_CACHE |
|
143 |
- tcp_default_cfg.fd_cache=1; |
|
144 |
-#endif |
|
145 |
-#ifdef HAVE_SO_KEEPALIVE |
|
146 |
- tcp_default_cfg.keepalive=1; |
|
147 |
-#endif |
|
148 |
-/* |
|
149 |
-#if defined HAVE_TCP_DEFER_ACCEPT || defined HAVE_TCP_ACCEPT_FILTER |
|
150 |
- tcp_default_cfg.defer_accept=1; |
|
151 |
-#endif |
|
152 |
-*/ |
|
153 |
-#ifdef HAVE_TCP_QUICKACK |
|
154 |
- tcp_default_cfg.delayed_ack=1; |
|
155 |
-#endif |
|
156 |
- tcp_default_cfg.crlf_ping=1; |
|
157 |
- tcp_default_cfg.accept_aliases=0; /* don't accept aliases by default */ |
|
158 |
- /* flags used for adding new aliases */ |
|
159 |
- tcp_default_cfg.alias_flags=TCP_ALIAS_FORCE_ADD; |
|
160 |
- /* flags used for adding the default aliases of a new tcp connection */ |
|
161 |
- tcp_default_cfg.new_conn_alias_flags=TCP_ALIAS_REPLACE; |
|
162 |
- tcp_default_cfg.rd_buf_size=DEFAULT_TCP_BUF_SIZE; |
|
163 |
- tcp_default_cfg.wq_blk_size=DEFAULT_TCP_WBUF_SIZE; |
|
164 |
-} |
|
165 |
- |
|
166 |
- |
|
167 |
- |
|
168 |
-#define W_OPT_NC(option) \ |
|
169 |
- if (tcp_default_cfg.option){\ |
|
170 |
- WARN("tcp_options: tcp_" #option \ |
|
171 |
- " cannot be enabled (recompile needed)\n"); \ |
|
172 |
- tcp_default_cfg.option=0; \ |
|
173 |
- } |
|
174 |
- |
|
175 |
- |
|
176 |
- |
|
177 |
-#define W_OPT_NS(option) \ |
|
178 |
- if (tcp_default_cfg.option){\ |
|
179 |
- WARN("tcp_options: tcp_" #option \ |
|
180 |
- " cannot be enabled (no OS support)\n"); \ |
|
181 |
- tcp_default_cfg.option=0; \ |
|
182 |
- } |
|
183 |
- |
|
184 |
- |
|
185 |
- |
|
186 |
-/* if *to<0 to=default_val, else if to>max_val to=max_val */ |
|
187 |
-static void fix_timeout(char* name, int* to, int default_val, unsigned max_val) |
|
188 |
-{ |
|
189 |
- if (*to < 0) *to=default_val; |
|
190 |
- else if ((unsigned)*to > max_val){ |
|
191 |
- WARN("%s: timeout too big (%u), the maximum value is %u\n", |
|
192 |
- name, *to, max_val); |
|
193 |
- *to=max_val; |
|
194 |
- } |
|
195 |
-} |
|
196 |
- |
|
197 |
- |
|
198 |
- |
|
199 |
-static int fix_connect_to(void* cfg_h, str* gname, str* name, void** val) |
|
200 |
-{ |
|
201 |
- int v; |
|
202 |
- v=(int)(long)*val; |
|
203 |
- fix_timeout("tcp_connect_timeout", &v, DEFAULT_TCP_CONNECT_TIMEOUT, |
|
204 |
- TICKS_TO_S(MAX_TCP_CON_LIFETIME)); |
|
205 |
- *val=(void*)(long)v; |
|
206 |
- return 0; |
|
207 |
-} |
|
208 |
- |
|
209 |
- |
|
210 |
-static int fix_send_to(void* cfg_h, str* gname, str* name, void** val) |
|
211 |
-{ |
|
212 |
- int v; |
|
213 |
- v=S_TO_TICKS((int)(long)*val); |
|
214 |
- fix_timeout("tcp_send_timeout", &v, S_TO_TICKS(DEFAULT_TCP_SEND_TIMEOUT), |
|
215 |
- MAX_TCP_CON_LIFETIME); |
|
216 |
- *val=(void*)(long)v; |
|
217 |
- return 0; |
|
218 |
-} |
|
219 |
- |
|
220 |
- |
|
221 |
-static int fix_con_lt(void* cfg_h, str* gname, str* name, void** val) |
|
222 |
-{ |
|
223 |
- int v; |
|
224 |
- v=S_TO_TICKS((int)(long)*val); |
|
225 |
- fix_timeout("tcp_connection_lifetime", &v, |
|
226 |
- MAX_TCP_CON_LIFETIME, MAX_TCP_CON_LIFETIME); |
|
227 |
- *val=(void*)(long)v; |
|
228 |
- return 0; |
|
229 |
-} |
|
230 |
- |
|
231 |
- |
|
232 |
-static int fix_max_conns(void* cfg_h, str* gname, str* name, void** val) |
|
233 |
-{ |
|
234 |
- int v; |
|
235 |
- v=(int)(long)*val; |
|
236 |
-#ifdef USE_TCP |
|
237 |
- if (v>tcp_max_connections){ |
|
238 |
- INFO("cannot override hard tcp_max_connections limit, please" |
|
239 |
- " restart and increase tcp_max_connections in the cfg.\n"); |
|
240 |
- v=tcp_max_connections; |
|
241 |
- } |
|
242 |
-#else /* USE_TCP */ |
|
243 |
- if (v){ |
|
244 |
- ERR("TCP support disabled at compile-time, tcp_max_connection is" |
|
245 |
- " hardwired to 0.\n"); |
|
246 |
- v=0; |
|
247 |
- } |
|
248 |
-#endif /*USE_TCP */ |
|
249 |
- *val=(void*)(long)v; |
|
250 |
- return 0; |
|
251 |
-} |
|
252 |
- |
|
253 |
-static int fix_max_tls_conns(void* cfg_h, str* gname, str* name, void** val) |
|
254 |
-{ |
|
255 |
- int v; |
|
256 |
- v=(int)(long)*val; |
|
257 |
-#ifdef USE_TLS |
|
258 |
- if (v>tls_max_connections){ |
|
259 |
- INFO("cannot override hard tls_max_connections limit, please" |
|
260 |
- " restart and increase tls_max_connections in the cfg.\n"); |
|
261 |
- v=tls_max_connections; |
|
262 |
- } |
|
263 |
-#else /* USE_TLS */ |
|
264 |
- if (v){ |
|
265 |
- ERR("TLS support disabled at compile-time, tls_max_connection is" |
|
266 |
- " hardwired to 0.\n"); |
|
267 |
- v=0; |
|
268 |
- } |
|
269 |
-#endif /*USE_TLS */ |
|
270 |
- *val=(void*)(long)v; |
|
271 |
- return 0; |
|
272 |
-} |
|
273 |
- |
|
274 |
- |
|
275 |
- |
|
276 |
-/** fix *val according to the cfg entry "name". |
|
277 |
- * (*val must be integer) |
|
278 |
- * 1. check if *val is between name min..max and if not change it to |
|
279 |
- * the corresp. value |
|
280 |
- * 2. call fixup callback if defined in the cfg |
|
281 |
- * @return 0 on success |
|
282 |
- */ |
|
283 |
-static int tcp_cfg_def_fix(char* name, int* val) |
|
284 |
-{ |
|
285 |
- cfg_def_t* c; |
|
286 |
- str s; |
|
287 |
- |
|
288 |
- for (c=&tcp_cfg_def[0]; c->name; c++){ |
|
289 |
- if (strcmp(name, c->name)==0){ |
|
290 |
- /* found */ |
|
291 |
- if ((c->type & CFG_VAR_INT) && (c->min || c->max)){ |
|
292 |
- if (*val < c->min) *val=c->min; |
|
293 |
- else if (*val > c->max) *val=c->max; |
|
294 |
- if (c->on_change_cb){ |
|
295 |
- s.s=c->name; |
|
296 |
- s.len=strlen(s.s); |
|
297 |
- return c->on_change_cb(&tcp_default_cfg, NULL, &s, (void*)val); |
|
298 |
- } |
|
299 |
- } |
|
300 |
- return 0; |
|
301 |
- } |
|
302 |
- } |
|
303 |
- WARN("tcp config option \"%s\" not found\n", name); |
|
304 |
- return -1; /* not found */ |
|
305 |
-} |
|
306 |
- |
|
307 |
- |
|
308 |
- |
|
309 |
-/* checks & warns if some tcp_option cannot be enabled */ |
|
310 |
-void tcp_options_check() |
|
311 |
-{ |
|
312 |
-#ifndef TCP_FD_CACHE |
|
313 |
- W_OPT_NC(defer_accept); |
|
314 |
-#endif |
|
315 |
- |
|
316 |
-#ifndef TCP_ASYNC |
|
317 |
- W_OPT_NC(async); |
|
318 |
- W_OPT_NC(tcpconn_wq_max); |
|
319 |
- W_OPT_NC(tcp_wq_max); |
|
320 |
-#endif /* TCP_ASYNC */ |
|
321 |
-#ifndef TCP_CONNECT_WAIT |
|
322 |
- W_OPT_NC(tcp_connect_wait); |
|
323 |
-#endif /* TCP_CONNECT_WAIT */ |
|
324 |
- |
|
325 |
- if (tcp_default_cfg.tcp_connect_wait && !tcp_default_cfg.async){ |
|
326 |
- tcp_default_cfg.tcp_connect_wait=0; |
|
327 |
- } |
|
328 |
- |
|
329 |
-#if ! defined HAVE_TCP_DEFER_ACCEPT && ! defined HAVE_TCP_ACCEPT_FILTER |
|
330 |
- W_OPT_NS(defer_accept); |
|
331 |
-#endif |
|
332 |
-#ifndef HAVE_TCP_SYNCNT |
|
333 |
- W_OPT_NS(syncnt); |
|
334 |
-#endif |
|
335 |
-#ifndef HAVE_TCP_LINGER2 |
|
336 |
- W_OPT_NS(linger2); |
|
337 |
-#endif |
|
338 |
-#ifndef HAVE_TCP_KEEPINTVL |
|
339 |
- W_OPT_NS(keepintvl); |
|
340 |
-#endif |
|
341 |
-#ifndef HAVE_TCP_KEEPIDLE |
|
342 |
- W_OPT_NS(keepidle); |
|
343 |
-#endif |
|
344 |
-#ifndef HAVE_TCP_KEEPCNT |
|
345 |
- W_OPT_NS(keepcnt); |
|
346 |
-#endif |
|
347 |
- if (tcp_default_cfg.keepintvl || tcp_default_cfg.keepidle || |
|
348 |
- tcp_default_cfg.keepcnt){ |
|
349 |
- tcp_default_cfg.keepalive=1; /* force on */ |
|
350 |
- } |
|
351 |
-#ifndef HAVE_SO_KEEPALIVE |
|
352 |
- W_OPT_NS(keepalive); |
|
353 |
-#endif |
|
354 |
-#ifndef HAVE_TCP_QUICKACK |
|
355 |
- W_OPT_NS(delayed_ack); |
|
356 |
-#endif |
|
357 |
- /* fix various timeouts */ |
|
358 |
- fix_timeout("tcp_connect_timeout", &tcp_default_cfg.connect_timeout_s, |
|
359 |
- DEFAULT_TCP_CONNECT_TIMEOUT, |
|
360 |
- TICKS_TO_S(MAX_TCP_CON_LIFETIME)); |
|
361 |
- fix_timeout("tcp_send_timeout", &tcp_default_cfg.send_timeout, |
|
362 |
- S_TO_TICKS(DEFAULT_TCP_SEND_TIMEOUT), |
|
363 |
- MAX_TCP_CON_LIFETIME); |
|
364 |
- fix_timeout("tcp_connection_lifetime", &tcp_default_cfg.con_lifetime, |
|
365 |
- MAX_TCP_CON_LIFETIME, MAX_TCP_CON_LIFETIME); |
|
366 |
-#ifdef USE_TCP |
|
367 |
- tcp_default_cfg.max_connections=tcp_max_connections; |
|
368 |
- tcp_default_cfg.max_tls_connections=tls_max_connections; |
|
369 |
-#else /* USE_TCP */ |
|
370 |
- tcp_default_cfg.max_connections=0; |
|
371 |
- tcp_default_cfg.max_tls_connections=0; |
|
372 |
-#endif /* USE_TCP */ |
|
373 |
- tcp_cfg_def_fix("rd_buf_size", (int*)&tcp_default_cfg.rd_buf_size); |
|
374 |
- tcp_cfg_def_fix("wq_blk_size", (int*)&tcp_default_cfg.wq_blk_size); |
|
375 |
-} |
|
376 |
- |
|
377 |
- |
|
378 |
- |
|
379 |
-void tcp_options_get(struct cfg_group_tcp* t) |
|
380 |
-{ |
|
381 |
- *t=*(struct cfg_group_tcp*)tcp_cfg; |
|
382 |
-} |
|
383 |
- |
|
384 |
- |
|
385 |
- |
|
386 |
-/** register tcp config into the configuration framework. |
|
387 |
- * @return 0 on succes, -1 on error*/ |
|
388 |
-int tcp_register_cfg() |
|
389 |
-{ |
|
390 |
- if (cfg_declare("tcp", tcp_cfg_def, &tcp_default_cfg, cfg_sizeof(tcp), |
|
391 |
- &tcp_cfg)) |
|
392 |
- return -1; |
|
393 |
- if (tcp_cfg==0){ |
|
394 |
- BUG("null tcp cfg"); |
|
395 |
- return -1; |
|
396 |
- } |
|
397 |
- return 0; |
|
398 |
-} |
... | ... |
@@ -105,7 +105,7 @@ static cfg_def_t tcp_cfg_def[] = { |
105 | 105 |
{ "new_conn_alias_flags", CFG_VAR_INT | CFG_ATOMIC, 0, 2, 0, 0, |
106 | 106 |
"flags for the def. aliases for a new conn. (FORCE_ADD:1, REPLACE:2 "}, |
107 | 107 |
{ "accept_no_cl", CFG_VAR_INT | CFG_ATOMIC, 0, 1, 0, 0, |
108 |
- "accept TCP messges without Content-Length "}, |
|
108 |
+ "accept TCP messages without Content-Length "}, |
|
109 | 109 |
/* internal and/or "fixed" versions of some vars |
110 | 110 |
(not supposed to be writeable, read will provide only debugging value*/ |
111 | 111 |
{ "rd_buf_size", CFG_VAR_INT | CFG_ATOMIC, 512, 16777216, 0, 0, |
... | ... |
@@ -1,6 +1,4 @@ |
1 | 1 |
/* |
2 |
- * $Id$ |
|
3 |
- * |
|
4 | 2 |
* Copyright (C) 2007 iptelorg GmbH |
5 | 3 |
* |
6 | 4 |
* Permission to use, copy, modify, and distribute this software for any |
... | ... |
@@ -15,18 +13,10 @@ |
15 | 13 |
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
16 | 14 |
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
17 | 15 |
*/ |
18 |
-/* |
|
19 |
- * tcp options |
|
20 |
- * |
|
21 |
- * History: |
|
22 |
- * -------- |
|
23 |
- * 2007-11-28 created by andrei |
|
24 |
- * 2009-03-05 use cfg framework (andrei) |
|
25 |
- */ |
|
26 | 16 |
|
27 | 17 |
/*! |
28 | 18 |
* \file |
29 |
- * \brief SIP-router core :: |
|
19 |
+ * \brief SIP-router core :: tcp options |
|
30 | 20 |
* \ingroup core |
31 | 21 |
* Module: \ref core |
32 | 22 |
*/ |
One typo in the HTTP11CONTINUE response headers
One in the tcp option help string for 'accept_no_cl'
Two in code comments
... | ... |
@@ -115,7 +115,7 @@ static cfg_def_t tcp_cfg_def[] = { |
115 | 115 |
{ "new_conn_alias_flags", CFG_VAR_INT | CFG_ATOMIC, 0, 2, 0, 0, |
116 | 116 |
"flags for the def. aliases for a new conn. (FORCE_ADD:1, REPLACE:2 "}, |
117 | 117 |
{ "accept_no_cl", CFG_VAR_INT | CFG_ATOMIC, 0, 1, 0, 0, |
118 |
- "accept TCP messges without Content-Lenght "}, |
|
118 |
+ "accept TCP messges without Content-Length "}, |
|
119 | 119 |
/* internal and/or "fixed" versions of some vars |
120 | 120 |
(not supposed to be writeable, read will provide only debugging value*/ |
121 | 121 |
{ "rd_buf_size", CFG_VAR_INT | CFG_ATOMIC, 512, 16777216, 0, 0, |
... | ... |
@@ -375,8 +375,10 @@ void tcp_options_check() |
375 | 375 |
MAX_TCP_CON_LIFETIME, MAX_TCP_CON_LIFETIME); |
376 | 376 |
#ifdef USE_TCP |
377 | 377 |
tcp_default_cfg.max_connections=tcp_max_connections; |
378 |
+ tcp_default_cfg.max_tls_connections=tls_max_connections; |
|
378 | 379 |
#else /* USE_TCP */ |
379 | 380 |
tcp_default_cfg.max_connections=0; |
381 |
+ tcp_default_cfg.max_tls_connections=0; |
|
380 | 382 |
#endif /* USE_TCP */ |
381 | 383 |
tcp_cfg_def_fix("rd_buf_size", (int*)&tcp_default_cfg.rd_buf_size); |
382 | 384 |
tcp_cfg_def_fix("wq_blk_size", (int*)&tcp_default_cfg.wq_blk_size); |
- the fixup function was setting to tcp value
... | ... |
@@ -51,6 +51,7 @@ static int fix_connect_to(void* cfg_h, str* gname, str* name, void** val); |
51 | 51 |
static int fix_send_to(void* cfg_h, str* gname, str* name, void** val); |
52 | 52 |
static int fix_con_lt(void* cfg_h, str* gname, str* name, void** val); |
53 | 53 |
static int fix_max_conns(void* cfg_h, str* gname, str* name, void** val); |
54 |
+static int fix_max_tls_conns(void* cfg_h, str* gname, str* name, void** val); |
|
54 | 55 |
|
55 | 56 |
|
56 | 57 |
|
... | ... |
@@ -71,7 +72,7 @@ static cfg_def_t tcp_cfg_def[] = { |
71 | 72 |
fix_max_conns, 0, |
72 | 73 |
"maximum tcp connections number, soft limit"}, |
73 | 74 |
{ "max_tls_connections", CFG_VAR_INT | CFG_ATOMIC, 0, (1U<<31)-1, |
74 |
- fix_max_conns, 0, |
|
75 |
+ fix_max_tls_conns,0, |
|
75 | 76 |
"maximum tls connections number, soft limit"}, |
76 | 77 |
{ "no_connect", CFG_VAR_INT | CFG_ATOMIC, 0, 1, 0, 0, |
77 | 78 |
"if set only accept new connections, never actively open new ones"}, |
... | ... |
@@ -138,6 +139,7 @@ void init_tcp_options() |
138 | 139 |
tcp_default_cfg.max_tls_connections=tls_max_connections; |
139 | 140 |
#else /*USE_TCP*/ |
140 | 141 |
tcp_default_cfg.max_connections=0; |
142 |
+ tcp_default_cfg.max_tls_connections=0; |
|
141 | 143 |
#endif /*USE_TCP*/ |
142 | 144 |
#ifdef TCP_ASYNC |
143 | 145 |
tcp_default_cfg.async=1; |
... | ... |
@@ -258,6 +260,27 @@ static int fix_max_conns(void* cfg_h, str* gname, str* name, void** val) |
258 | 260 |
return 0; |
259 | 261 |
} |
260 | 262 |
|
263 |
+static int fix_max_tls_conns(void* cfg_h, str* gname, str* name, void** val) |
|
264 |
+{ |
|
265 |
+ int v; |
|
266 |
+ v=(int)(long)*val; |
|
267 |
+#ifdef USE_TLS |
|
268 |
+ if (v>tls_max_connections){ |
|
269 |
+ INFO("cannot override hard tls_max_connections limit, please" |
|
270 |
+ " restart and increase tls_max_connections in the cfg.\n"); |
|
271 |
+ v=tls_max_connections; |
|
272 |
+ } |
|
273 |
+#else /* USE_TLS */ |
|
274 |
+ if (v){ |
|
275 |
+ ERR("TLS support disabled at compile-time, tls_max_connection is" |
|
276 |
+ " hardwired to 0.\n"); |
|
277 |
+ v=0; |
|
278 |
+ } |
|
279 |
+#endif /*USE_TLS */ |
|
280 |
+ *val=(void*)(long)v; |
|
281 |
+ return 0; |
|
282 |
+} |
|
283 |
+ |
|
261 | 284 |
|
262 | 285 |
|
263 | 286 |
/** fix *val according to the cfg entry "name". |
- set a limit to active tls connections
- its management is done in tcp code, as tls is encryption layer over
tcp
- tls connections are still counted as tcp connections, thus this limit
cannot exceed tcp_max_connections
- default value 2048
- core.tcp_options lists also the tls connections number
... | ... |
@@ -69,7 +69,10 @@ static cfg_def_t tcp_cfg_def[] = { |
69 | 69 |
"connection lifetime (in seconds)"}, |
70 | 70 |
{ "max_connections", CFG_VAR_INT | CFG_ATOMIC, 0, (1U<<31)-1, |
71 | 71 |
fix_max_conns, 0, |
72 |
- "maximum connection number, soft limit"}, |
|
72 |
+ "maximum tcp connections number, soft limit"}, |
|
73 |
+ { "max_tls_connections", CFG_VAR_INT | CFG_ATOMIC, 0, (1U<<31)-1, |
|
74 |
+ fix_max_conns, 0, |
|
75 |
+ "maximum tls connections number, soft limit"}, |
|
73 | 76 |
{ "no_connect", CFG_VAR_INT | CFG_ATOMIC, 0, 1, 0, 0, |
74 | 77 |
"if set only accept new connections, never actively open new ones"}, |
75 | 78 |
{ "fd_cache", CFG_VAR_INT | CFG_READONLY, 0, 1, 0, 0, |
... | ... |
@@ -132,6 +135,7 @@ void init_tcp_options() |
132 | 135 |
tcp_default_cfg.con_lifetime=S_TO_TICKS(DEFAULT_TCP_CONNECTION_LIFETIME_S); |
133 | 136 |
#ifdef USE_TCP |
134 | 137 |
tcp_default_cfg.max_connections=tcp_max_connections; |
138 |
+ tcp_default_cfg.max_tls_connections=tls_max_connections; |
|
135 | 139 |
#else /*USE_TCP*/ |
136 | 140 |
tcp_default_cfg.max_connections=0; |
137 | 141 |
#endif /*USE_TCP*/ |
- Issue found and fixed by Andrew Miller at Crocodile RCS
... | ... |
@@ -114,7 +114,7 @@ static cfg_def_t tcp_cfg_def[] = { |
114 | 114 |
"accept TCP messges without Content-Lenght "}, |
115 | 115 |
/* internal and/or "fixed" versions of some vars |
116 | 116 |
(not supposed to be writeable, read will provide only debugging value*/ |
117 |
- { "rd_buf_size", CFG_VAR_INT | CFG_ATOMIC, 512, 65536, 0, 0, |
|
117 |
+ { "rd_buf_size", CFG_VAR_INT | CFG_ATOMIC, 512, 16777216, 0, 0, |
|
118 | 118 |
"internal read buffer size (should be > max. expected datagram)"}, |
119 | 119 |
{ "wq_blk_size", CFG_VAR_INT | CFG_ATOMIC, 1, 65535, 0, 0, |
120 | 120 |
"internal async write block size (debugging use only for now)"}, |
- added missing description in tcp options structure
... | ... |
@@ -110,6 +110,8 @@ static cfg_def_t tcp_cfg_def[] = { |
110 | 110 |
"flags used for adding new aliases (FORCE_ADD:1 , REPLACE:2) "}, |
111 | 111 |
{ "new_conn_alias_flags", CFG_VAR_INT | CFG_ATOMIC, 0, 2, 0, 0, |
112 | 112 |
"flags for the def. aliases for a new conn. (FORCE_ADD:1, REPLACE:2 "}, |
113 |
+ { "accept_no_cl", CFG_VAR_INT | CFG_ATOMIC, 0, 1, 0, 0, |
|
114 |
+ "accept TCP messges without Content-Lenght "}, |
|
113 | 115 |
/* internal and/or "fixed" versions of some vars |
114 | 116 |
(not supposed to be writeable, read will provide only debugging value*/ |
115 | 117 |
{ "rd_buf_size", CFG_VAR_INT | CFG_ATOMIC, 512, 65536, 0, 0, |
Please fill in after the :: to explain the function of this file.
Don't try to use tcp_max_connections if tcp support is not
compiled-in.
... | ... |
@@ -121,7 +121,11 @@ void init_tcp_options() |
121 | 121 |
tcp_default_cfg.connect_timeout_s=DEFAULT_TCP_CONNECT_TIMEOUT; |
122 | 122 |
tcp_default_cfg.send_timeout=S_TO_TICKS(DEFAULT_TCP_SEND_TIMEOUT); |
123 | 123 |
tcp_default_cfg.con_lifetime=S_TO_TICKS(DEFAULT_TCP_CONNECTION_LIFETIME_S); |
124 |
+#ifdef USE_TCP |
|
124 | 125 |
tcp_default_cfg.max_connections=tcp_max_connections; |
126 |
+#else /*USE_TCP*/ |
|
127 |
+ tcp_default_cfg.max_connections=0; |
|
128 |
+#endif /*USE_TCP*/ |
|
125 | 129 |
#ifdef TCP_ASYNC |
126 | 130 |
tcp_default_cfg.async=1; |
127 | 131 |
tcp_default_cfg.tcpconn_wq_max=32*1024; /* 32 k */ |
... | ... |
@@ -224,11 +228,19 @@ static int fix_max_conns(void* cfg_h, str* gname, str* name, void** val) |
224 | 228 |
{ |
225 | 229 |
int v; |
226 | 230 |
v=(int)(long)*val; |
231 |
+#ifdef USE_TCP |
|
227 | 232 |
if (v>tcp_max_connections){ |
228 | 233 |
INFO("cannot override hard tcp_max_connections limit, please" |
229 | 234 |
" restart and increase tcp_max_connections in the cfg.\n"); |
230 | 235 |
v=tcp_max_connections; |
231 | 236 |
} |
237 |
+#else /* USE_TCP */ |
|
238 |
+ if (v){ |
|
239 |
+ ERR("TCP support disabled at compile-time, tcp_max_connection is" |
|
240 |
+ " hardwired to 0.\n"); |
|
241 |
+ v=0; |
|
242 |
+ } |
|
243 |
+#endif /*USE_TCP */ |
|
232 | 244 |
*val=(void*)(long)v; |
233 | 245 |
return 0; |
234 | 246 |
} |
... | ... |
@@ -325,7 +337,11 @@ void tcp_options_check() |
325 | 337 |
MAX_TCP_CON_LIFETIME); |
326 | 338 |
fix_timeout("tcp_connection_lifetime", &tcp_default_cfg.con_lifetime, |
327 | 339 |
MAX_TCP_CON_LIFETIME, MAX_TCP_CON_LIFETIME); |
340 |
+#ifdef USE_TCP |
|
328 | 341 |
tcp_default_cfg.max_connections=tcp_max_connections; |
342 |
+#else /* USE_TCP */ |
|
343 |
+ tcp_default_cfg.max_connections=0; |
|
344 |
+#endif /* USE_TCP */ |
|
329 | 345 |
tcp_cfg_def_fix("rd_buf_size", (int*)&tcp_default_cfg.rd_buf_size); |
330 | 346 |
tcp_cfg_def_fix("wq_blk_size", (int*)&tcp_default_cfg.wq_blk_size); |
331 | 347 |
} |
- removed send_timeout_s and wq_timeout and replaced them with send_timeout,
which is now kept only in ticks. This fixes the cfg.set_delayed_int problem
reported by Miklos.
... | ... |
@@ -37,31 +37,6 @@ |
37 | 37 |
NOTE: all the options are initialized in init_tcp_options() |
38 | 38 |
depending on compile time defines */ |
39 | 39 |
struct cfg_group_tcp tcp_default_cfg; |
40 |
-#if 0 |
|
41 |
-{ |
|
42 |
- 1, /* fd_cache, default on */ |
|
43 |
- /* tcp async options */ |
|
44 |
- 0, /* async / tcp_async, default off */ |
|
45 |
- 1, /* tcp_connect_wait - depends on tcp_async */ |
|
46 |
- 32*1024, /* tcpconn_wq_max - max. write queue len per connection (32k) */ |
|
47 |
- 10*1024*1024, /* tcp_wq_max - max. overall queued bytes (10MB)*/ |
|
48 |
- S_TO_TICKS(tcp_send_timeout), /* tcp_wq_timeout - timeout for queued |
|
49 |
- writes, depends on tcp_send_timeout */ |
|
50 |
- /* tcp socket options */ |
|
51 |
- 0, /* defer_accept - on/off*/ |
|
52 |
- 1, /* delayed_ack - delay ack on connect (on/off)*/ |
|
53 |
- 0, /* syncnt - numbers of SYNs retrs. before giving up (0 = OS default) */ |
|
54 |
- 0, /* linger2 - lifetime of orphaned FIN_WAIT2 sockets (0 = OS default)*/ |
|
55 |
- 1, /* keepalive - on/off */ |
|
56 |
- 0, /* keepidle - idle time (s) before tcp starts sending keepalives */ |
|
57 |
- 0, /* keepintvl - interval between keep alives (0 = OS default) */ |
|
58 |
- 0, /* keepcnt - maximum no. of keepalives (0 = OS default)*/ |
|
59 |
- |
|
60 |
- /* other options */ |
|
61 |
- 1 /* crlf_ping - respond to double CRLF ping/keepalive (on/off) */ |
|
62 |
- |
|
63 |
-}; |
|
64 |
-#endif |
|
65 | 40 |
|
66 | 41 |
|
67 | 42 |
|
... | ... |
@@ -80,7 +55,7 @@ static cfg_def_t tcp_cfg_def[] = { |
80 | 55 |
TICKS_TO_S(MAX_TCP_CON_LIFETIME), fix_connect_to, 0, |
81 | 56 |
"used only in non-async mode, in seconds"}, |
82 | 57 |
{ "send_timeout", CFG_VAR_INT | CFG_ATOMIC, -1, |
83 |
- TICKS_TO_S(MAX_TCP_CON_LIFETIME), fix_send_to, 0, |
|
58 |
+ MAX_TCP_CON_LIFETIME, fix_send_to, 0, |
|
84 | 59 |
"in seconds"}, |
85 | 60 |
{ "connection_lifetime", CFG_VAR_INT | CFG_ATOMIC, -1, |
86 | 61 |
MAX_TCP_CON_LIFETIME, fix_con_lt, 0, |
... | ... |
@@ -101,7 +76,7 @@ static cfg_def_t tcp_cfg_def[] = { |
101 | 76 |
"maximum bytes queued for write per connection (depends on async)"}, |
102 | 77 |
{ "wq_max", CFG_VAR_INT | CFG_ATOMIC, 0, 1<<30, 0, 0, |
103 | 78 |
"maximum bytes queued for write allowed globally (depends on async)"}, |
104 |
- /* see also wq_timeout below */ |
|
79 |
+ /* see also send_timeout above */ |
|
105 | 80 |
/* tcp socket options */ |
106 | 81 |
{ "defer_accept", CFG_VAR_INT | CFG_READONLY, 0, 3600, 0, 0, |
107 | 82 |
"0/1 on linux, seconds on freebsd (see docs)"}, |
... | ... |
@@ -130,9 +105,6 @@ static cfg_def_t tcp_cfg_def[] = { |
130 | 105 |
"flags for the def. aliases for a new conn. (FORCE_ADD:1, REPLACE:2 "}, |
131 | 106 |
/* internal and/or "fixed" versions of some vars |
132 | 107 |
(not supposed to be writeable, read will provide only debugging value*/ |
133 |
- { "wq_timeout_ticks", CFG_VAR_INT | CFG_READONLY, 0, |
|
134 |
- MAX_TCP_CON_LIFETIME, 0, 0, |
|
135 |
- "internal send_timeout value in ticks, used in async. mode"}, |
|
136 | 108 |
{ "rd_buf_size", CFG_VAR_INT | CFG_ATOMIC, 512, 65536, 0, 0, |
137 | 109 |
"internal read buffer size (should be > max. expected datagram)"}, |
138 | 110 |
{ "wq_blk_size", CFG_VAR_INT | CFG_ATOMIC, 1, 65535, 0, 0, |
... | ... |
@@ -147,14 +119,13 @@ void* tcp_cfg; /* tcp config handle */ |
147 | 119 |
void init_tcp_options() |
148 | 120 |
{ |
149 | 121 |
tcp_default_cfg.connect_timeout_s=DEFAULT_TCP_CONNECT_TIMEOUT; |
150 |
- tcp_default_cfg.send_timeout_s=DEFAULT_TCP_SEND_TIMEOUT; |
|
122 |
+ tcp_default_cfg.send_timeout=S_TO_TICKS(DEFAULT_TCP_SEND_TIMEOUT); |
|
151 | 123 |
tcp_default_cfg.con_lifetime=S_TO_TICKS(DEFAULT_TCP_CONNECTION_LIFETIME_S); |
152 | 124 |
tcp_default_cfg.max_connections=tcp_max_connections; |
153 | 125 |
#ifdef TCP_ASYNC |
154 | 126 |
tcp_default_cfg.async=1; |
155 | 127 |
tcp_default_cfg.tcpconn_wq_max=32*1024; /* 32 k */ |
156 | 128 |
tcp_default_cfg.tcp_wq_max=10*1024*1024; /* 10 MB */ |
157 |
- tcp_default_cfg.tcp_wq_timeout=S_TO_TICKS(tcp_default_cfg.send_timeout_s); |
|
158 | 129 |
#ifdef TCP_CONNECT_WAIT |
159 | 130 |
tcp_default_cfg.tcp_connect_wait=1; |
160 | 131 |
#endif /* TCP_CONNECT_WAIT */ |
... | ... |
@@ -230,13 +201,10 @@ static int fix_connect_to(void* cfg_h, str* gname, str* name, void** val) |
230 | 201 |
static int fix_send_to(void* cfg_h, str* gname, str* name, void** val) |
231 | 202 |
{ |
232 | 203 |
int v; |
233 |
- v=(int)(long)*val; |
|
234 |
- fix_timeout("tcp_send_timeout", &v, DEFAULT_TCP_SEND_TIMEOUT, |
|
235 |
- TICKS_TO_S(MAX_TCP_CON_LIFETIME)); |
|
204 |
+ v=S_TO_TICKS((int)(long)*val); |
|
205 |
+ fix_timeout("tcp_send_timeout", &v, S_TO_TICKS(DEFAULT_TCP_SEND_TIMEOUT), |
|
206 |
+ MAX_TCP_CON_LIFETIME); |
|
236 | 207 |
*val=(void*)(long)v; |
237 |
-#ifdef TCP_ASYNC |
|
238 |
- ((struct cfg_group_tcp*)cfg_h)->tcp_wq_timeout=S_TO_TICKS(v); |
|
239 |
-#endif /* TCP_ASYNC */ |
|
240 | 208 |
return 0; |
241 | 209 |
} |
242 | 210 |
|
... | ... |
@@ -311,7 +279,6 @@ void tcp_options_check() |
311 | 279 |
W_OPT_NC(async); |
312 | 280 |
W_OPT_NC(tcpconn_wq_max); |
313 | 281 |
W_OPT_NC(tcp_wq_max); |
314 |
- W_OPT_NC(tcp_wq_timeout); |
|
315 | 282 |
#endif /* TCP_ASYNC */ |
316 | 283 |
#ifndef TCP_CONNECT_WAIT |
317 | 284 |
W_OPT_NC(tcp_connect_wait); |
... | ... |
@@ -353,19 +320,14 @@ void tcp_options_check() |
353 | 320 |
fix_timeout("tcp_connect_timeout", &tcp_default_cfg.connect_timeout_s, |
354 | 321 |
DEFAULT_TCP_CONNECT_TIMEOUT, |
355 | 322 |
TICKS_TO_S(MAX_TCP_CON_LIFETIME)); |
356 |
- fix_timeout("tcp_send_timeout", &tcp_default_cfg.send_timeout_s, |
|
357 |
- DEFAULT_TCP_SEND_TIMEOUT, |
|
358 |
- TICKS_TO_S(MAX_TCP_CON_LIFETIME)); |
|
323 |
+ fix_timeout("tcp_send_timeout", &tcp_default_cfg.send_timeout, |
|
324 |
+ S_TO_TICKS(DEFAULT_TCP_SEND_TIMEOUT), |
|
325 |
+ MAX_TCP_CON_LIFETIME); |
|
359 | 326 |
fix_timeout("tcp_connection_lifetime", &tcp_default_cfg.con_lifetime, |
360 | 327 |
MAX_TCP_CON_LIFETIME, MAX_TCP_CON_LIFETIME); |
361 |
- /* compute timeout in ticks */ |
|
362 |
-#ifdef TCP_ASYNC |
|
363 |
- tcp_default_cfg.tcp_wq_timeout=S_TO_TICKS(tcp_default_cfg.send_timeout_s); |
|
364 |
-#endif /* TCP_ASYNC */ |
|
365 | 328 |
tcp_default_cfg.max_connections=tcp_max_connections; |
366 | 329 |
tcp_cfg_def_fix("rd_buf_size", (int*)&tcp_default_cfg.rd_buf_size); |
367 | 330 |
tcp_cfg_def_fix("wq_blk_size", (int*)&tcp_default_cfg.wq_blk_size); |
368 |
- |
|
369 | 331 |
} |
370 | 332 |
|
371 | 333 |
|
... | ... |
@@ -65,10 +65,10 @@ struct cfg_group_tcp tcp_default_cfg; |
65 | 65 |
|
66 | 66 |
|
67 | 67 |
|
68 |
-static int fix_connect_to(void* cfg_h, str* name, void** val); |
|
69 |
-static int fix_send_to(void* cfg_h, str* name, void** val); |
|
70 |
-static int fix_con_lt(void* cfg_h, str* name, void** val); |
|
71 |
-static int fix_max_conns(void* cfg_h, str* name, void** val); |
|
68 |
+static int fix_connect_to(void* cfg_h, str* gname, str* name, void** val); |
|
69 |
+static int fix_send_to(void* cfg_h, str* gname, str* name, void** val); |
|
70 |
+static int fix_con_lt(void* cfg_h, str* gname, str* name, void** val); |
|
71 |
+static int fix_max_conns(void* cfg_h, str* gname, str* name, void** val); |
|
72 | 72 |
|
73 | 73 |
|
74 | 74 |
|
... | ... |
@@ -216,7 +216,7 @@ static void fix_timeout(char* name, int* to, int default_val, unsigned max_val) |
216 | 216 |
|
217 | 217 |
|
218 | 218 |
|
219 |
-static int fix_connect_to(void* cfg_h, str* name, void** val) |
|
219 |
+static int fix_connect_to(void* cfg_h, str* gname, str* name, void** val) |
|
220 | 220 |
{ |
221 | 221 |
int v; |
222 | 222 |
v=(int)(long)*val; |
... | ... |
@@ -227,7 +227,7 @@ static int fix_connect_to(void* cfg_h, str* name, void** val) |
227 | 227 |
} |
228 | 228 |
|
229 | 229 |
|
230 |
-static int fix_send_to(void* cfg_h, str* name, void** val) |
|
230 |
+static int fix_send_to(void* cfg_h, str* gname, str* name, void** val) |
|
231 | 231 |
{ |
232 | 232 |
int v; |
233 | 233 |
v=(int)(long)*val; |
... | ... |
@@ -241,7 +241,7 @@ static int fix_send_to(void* cfg_h, str* name, void** val) |
241 | 241 |
} |
242 | 242 |
|
243 | 243 |
|
244 |
-static int fix_con_lt(void* cfg_h, str* name, void** val) |
|
244 |
+static int fix_con_lt(void* cfg_h, str* gname, str* name, void** val) |
|
245 | 245 |
{ |
246 | 246 |
int v; |
247 | 247 |
v=S_TO_TICKS((int)(long)*val); |
... | ... |
@@ -252,7 +252,7 @@ static int fix_con_lt(void* cfg_h, str* name, void** val) |
252 | 252 |
} |
253 | 253 |
|
254 | 254 |
|
255 |
-static int fix_max_conns(void* cfg_h, str* name, void** val) |
|
255 |
+static int fix_max_conns(void* cfg_h, str* gname, str* name, void** val) |
|
256 | 256 |
{ |
257 | 257 |
int v; |
258 | 258 |
v=(int)(long)*val; |
... | ... |
@@ -288,7 +288,7 @@ static int tcp_cfg_def_fix(char* name, int* val) |
288 | 288 |
if (c->on_change_cb){ |
289 | 289 |
s.s=c->name; |
290 | 290 |
s.len=strlen(s.s); |
291 |
- return c->on_change_cb(&tcp_default_cfg, &s, (void*)val); |
|
291 |
+ return c->on_change_cb(&tcp_default_cfg, NULL, &s, (void*)val); |
|
292 | 292 |
} |
293 | 293 |
} |
294 | 294 |
return 0; |
- the block size used for the async writes can now be configured
both from ser.cfg (tcp_wq_blk_size) and at runtime. This value
has only a little performance impact and only when writes are
delayed. Small values are safer (big values on proxies that
open thousands of connections over slow links would eat up a
lot of memory). For now it's main use is debugging.
... | ... |
@@ -133,6 +133,10 @@ static cfg_def_t tcp_cfg_def[] = { |
133 | 133 |
{ "wq_timeout_ticks", CFG_VAR_INT | CFG_READONLY, 0, |
134 | 134 |
MAX_TCP_CON_LIFETIME, 0, 0, |
135 | 135 |
"internal send_timeout value in ticks, used in async. mode"}, |
136 |
+ { "rd_buf_size", CFG_VAR_INT | CFG_ATOMIC, 512, 65536, 0, 0, |
|
137 |
+ "internal read buffer size (should be > max. expected datagram)"}, |
|
138 |
+ { "wq_blk_size", CFG_VAR_INT | CFG_ATOMIC, 1, 65535, 0, 0, |
|
139 |
+ "internal async write block size (debugging use only for now)"}, |
|
136 | 140 |
{0, 0, 0, 0, 0, 0, 0} |
137 | 141 |
}; |
138 | 142 |
|
... | ... |
@@ -175,6 +179,8 @@ void init_tcp_options() |
175 | 179 |
tcp_default_cfg.alias_flags=TCP_ALIAS_FORCE_ADD; |
176 | 180 |
/* flags used for adding the default aliases of a new tcp connection */ |
177 | 181 |
tcp_default_cfg.new_conn_alias_flags=TCP_ALIAS_REPLACE; |
182 |
+ tcp_default_cfg.rd_buf_size=DEFAULT_TCP_BUF_SIZE; |
|
183 |
+ tcp_default_cfg.wq_blk_size=DEFAULT_TCP_WBUF_SIZE; |
|
178 | 184 |
} |
179 | 185 |
|
180 | 186 |
|
... | ... |
@@ -261,6 +267,39 @@ static int fix_max_conns(void* cfg_h, str* name, void** val) |
261 | 267 |
|
262 | 268 |
|
263 | 269 |
|
270 |
+/** fix *val according to the cfg entry "name". |
|
271 |
+ * (*val must be integer) |
|
272 |
+ * 1. check if *val is between name min..max and if not change it to |
|
273 |
+ * the corresp. value |
|
274 |
+ * 2. call fixup callback if defined in the cfg |
|
275 |
+ * @return 0 on success |
|
276 |
+ */ |
|
277 |
+static int tcp_cfg_def_fix(char* name, int* val) |
|
278 |
+{ |
|
279 |
+ cfg_def_t* c; |
|
280 |
+ str s; |
|
281 |
+ |
|
282 |
+ for (c=&tcp_cfg_def[0]; c->name; c++){ |
|
283 |
+ if (strcmp(name, c->name)==0){ |
|
284 |
+ /* found */ |
|
285 |
+ if ((c->type & CFG_VAR_INT) && (c->min || c->max)){ |
|
286 |
+ if (*val < c->min) *val=c->min; |
|
287 |
+ else if (*val > c->max) *val=c->max; |
|
288 |
+ if (c->on_change_cb){ |
|
289 |
+ s.s=c->name; |
|
290 |
+ s.len=strlen(s.s); |
|
291 |
+ return c->on_change_cb(&tcp_default_cfg, &s, (void*)val); |
|
292 |
+ } |
|
293 |
+ } |
|
294 |
+ return 0; |
|
295 |
+ } |
|
296 |
+ } |
|
297 |
+ WARN("tcp config option \"%s\" not found\n", name); |
|
298 |
+ return -1; /* not found */ |
|
299 |
+} |
|
300 |
+ |
|
301 |
+ |
|
302 |
+ |
|
264 | 303 |
/* checks & warns if some tcp_option cannot be enabled */ |
265 | 304 |
void tcp_options_check() |
266 | 305 |
{ |
... | ... |
@@ -324,6 +363,9 @@ void tcp_options_check() |
324 | 363 |
tcp_default_cfg.tcp_wq_timeout=S_TO_TICKS(tcp_default_cfg.send_timeout_s); |
325 | 364 |
#endif /* TCP_ASYNC */ |
326 | 365 |
tcp_default_cfg.max_connections=tcp_max_connections; |
366 |
+ tcp_cfg_def_fix("rd_buf_size", (int*)&tcp_default_cfg.rd_buf_size); |
|
367 |
+ tcp_cfg_def_fix("wq_blk_size", (int*)&tcp_default_cfg.wq_blk_size); |
|
368 |
+ |
|
327 | 369 |
} |
328 | 370 |
|
329 | 371 |
|
- cfg.set_delayed_int didn't work (fixup tried to modify another
config variable which doesn't work with cfg.set_delayed*)
... | ... |
@@ -83,7 +83,7 @@ static cfg_def_t tcp_cfg_def[] = { |
83 | 83 |
TICKS_TO_S(MAX_TCP_CON_LIFETIME), fix_send_to, 0, |
84 | 84 |
"in seconds"}, |
85 | 85 |
{ "connection_lifetime", CFG_VAR_INT | CFG_ATOMIC, -1, |
86 |
- TICKS_TO_S(MAX_TCP_CON_LIFETIME), fix_con_lt, 0, |
|
86 |
+ MAX_TCP_CON_LIFETIME, fix_con_lt, 0, |
|
87 | 87 |
"connection lifetime (in seconds)"}, |
88 | 88 |
{ "max_connections", CFG_VAR_INT | CFG_ATOMIC, 0, (1U<<31)-1, |
89 | 89 |
fix_max_conns, 0, |
... | ... |
@@ -133,9 +133,6 @@ static cfg_def_t tcp_cfg_def[] = { |
133 | 133 |
{ "wq_timeout_ticks", CFG_VAR_INT | CFG_READONLY, 0, |
134 | 134 |
MAX_TCP_CON_LIFETIME, 0, 0, |
135 | 135 |
"internal send_timeout value in ticks, used in async. mode"}, |
136 |
- { "con_lifetime_ticks", CFG_VAR_INT | CFG_READONLY, 0, |
|
137 |
- MAX_TCP_CON_LIFETIME, 0, 0, |
|
138 |
- "internal connection_lifetime value, converted to ticks"}, |
|
139 | 136 |
{0, 0, 0, 0, 0, 0, 0} |
140 | 137 |
}; |
141 | 138 |
|
... | ... |
@@ -147,7 +144,7 @@ void init_tcp_options() |
147 | 144 |
{ |
148 | 145 |
tcp_default_cfg.connect_timeout_s=DEFAULT_TCP_CONNECT_TIMEOUT; |
149 | 146 |
tcp_default_cfg.send_timeout_s=DEFAULT_TCP_SEND_TIMEOUT; |
150 |
- tcp_default_cfg.con_lifetime_s=DEFAULT_TCP_CONNECTION_LIFETIME_S; |
|
147 |
+ tcp_default_cfg.con_lifetime=S_TO_TICKS(DEFAULT_TCP_CONNECTION_LIFETIME_S); |
|
151 | 148 |