Browse code

tcp: enable runtime changing for most of the cfg vars

- following tcp config variables can now be changes at runtime:
connect_timeout, send_timeout, connection_lifetime,
max_connections (can be decreased, it cannot be increased more
then the startup value), conn_wq_max, wq_max, crlf_ping,
accept_aliases, alias_flags, new_conn_alias_flags.
- the following variables can be changes but they will affect only
new connections opened by ser: delayed_ack, syncnt, linger2,
keepalive, keepidle, keepintvl, keepcnt
(for the ser.cfg equivalent, just add tcp_ in front of the
variable name; for help and grep NEWS)

- updated core.tcp_options to dump all the tcp config options

Andrei Pelinescu-Onciul authored on 05/03/2009 17:20:53
Showing 2 changed files
... ...
@@ -565,14 +565,17 @@ static void core_tcp_options(rpc_t* rpc, void* c)
565 565
 	if (!tcp_disable){
566 566
 		tcp_options_get(&t);
567 567
 		rpc->add(c, "{", &handle);
568
-		rpc->struct_add(handle, "ddddddddddddddd",
568
+		rpc->struct_add(handle, "dddddddddddddddddddddd",
569
+			"connect_timeout", t.connect_timeout_s,
570
+			"send_timeout",  t.send_timeout_s,
571
+			"connection_lifetime",  t.con_lifetime_s,
572
+			"max_connections(soft)", t.max_connections,
569 573
 			"fd_cache",		t.fd_cache,
570
-			"tcp_buf_write",	t.tcp_buf_write,
571
-			"tcp_connect_wait",	t.tcp_connect_wait,
572
-			"tcpconn_wq_max",	t.tcpconn_wq_max,
573
-			"tcp_wq_max",	t.tcp_wq_max,
574
-			"tcp_wq_timeout",	TICKS_TO_S(t.tcp_wq_timeout),
575
-			
574
+			"async",		t.tcp_buf_write,
575
+			"connect_wait",	t.tcp_connect_wait,
576
+			"conn_wq_max",	t.tcpconn_wq_max,
577
+			"wq_max",		t.tcp_wq_max,
578
+			"wq_timeout",	TICKS_TO_S(t.tcp_wq_timeout),
576 579
 			"defer_accept",	t.defer_accept,
577 580
 			"delayed_ack",	t.delayed_ack,
578 581
 			"syncnt",		t.syncnt,
... ...
@@ -581,7 +584,10 @@ static void core_tcp_options(rpc_t* rpc, void* c)
581 581
 			"keepidle",		t.keepidle,
582 582
 			"keepintvl",	t.keepintvl,
583 583
 			"keepcnt",		t.keepcnt,
584
-			"crlf_ping",	t.crlf_ping
584
+			"crlf_ping",	t.crlf_ping,
585
+			"accept_aliases", t.accept_aliases,
586
+			"alias_flags",	t.alias_flags,
587
+			"new_conn_alias_flags",	t.new_conn_alias_flags
585 588
 		);
586 589
 	}else{
587 590
 		rpc->fault(c, 500, "tcp support disabled");
... ...
@@ -65,20 +65,28 @@ 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);
72
+
73
+
74
+
68 75
 /* cfg_group_tcp description (for the config framework)*/
69 76
 static cfg_def_t tcp_cfg_def[] = {
70 77
 	/*   name        , type |input type| chg type, min, max, fixup, proc. cbk 
71 78
 	      description */
72
-	{ "connect_timeout", CFG_VAR_INT | CFG_READONLY, -1,
73
-						TICKS_TO_S(MAX_TCP_CON_LIFETIME),         0,         0,
79
+	{ "connect_timeout", CFG_VAR_INT | CFG_ATOMIC,  -1,
80
+						TICKS_TO_S(MAX_TCP_CON_LIFETIME),  fix_connect_to,   0,
74 81
 		"used only in non-async mode, in seconds"},
75
-	{ "send_timeout", CFG_VAR_INT | CFG_READONLY,   -1,
76
-						TICKS_TO_S(MAX_TCP_CON_LIFETIME),         0,         0,
82
+	{ "send_timeout", CFG_VAR_INT | CFG_ATOMIC,   -1,
83
+						TICKS_TO_S(MAX_TCP_CON_LIFETIME),   fix_send_to,     0,
77 84
 		"in seconds"},
78
-	{ "connection_lifetime", CFG_VAR_INT | CFG_READONLY,   -1,
79
-						TICKS_TO_S(MAX_TCP_CON_LIFETIME),         0,         0,
85
+	{ "connection_lifetime", CFG_VAR_INT | CFG_ATOMIC,   -1,
86
+						TICKS_TO_S(MAX_TCP_CON_LIFETIME),   fix_con_lt,      0,
80 87
 		"connection lifetime (in seconds)"},
81
-	{ "max_connections", CFG_VAR_INT | CFG_READONLY, 0,  (1U<<31)-1, 0,      0,
88
+	{ "max_connections", CFG_VAR_INT | CFG_ATOMIC, 0, (1U<<31)-1,
89
+													       fix_max_conns,    0,
82 90
 		"maximum connection number, soft limit"},
83 91
 	{ "fd_cache",     CFG_VAR_INT | CFG_READONLY,    0,   1,      0,         0,
84 92
 		"file descriptor cache for tcp_send"},
... ...
@@ -87,36 +95,36 @@ static cfg_def_t tcp_cfg_def[] = {
87 87
 		"async mode for writes and connects"},
88 88
 	{ "connect_wait", CFG_VAR_INT | CFG_READONLY,    0,   1,      0,         0,
89 89
 		"parallel simultaneous connects to the same dst. (0) or one connect"},
90
-	{ "conn_wq_max",  CFG_VAR_INT | CFG_READONLY,    0, 1024*1024, 0,        0,
90
+	{ "conn_wq_max",  CFG_VAR_INT | CFG_ATOMIC,      0, 1024*1024, 0,        0,
91 91
 		"maximum bytes queued for write per connection (depends on async)"},
92
-	{ "wq_max",       CFG_VAR_INT | CFG_READONLY,    0,  1<<30,    0,        0,
92
+	{ "wq_max",       CFG_VAR_INT | CFG_ATOMIC,      0,  1<<30,    0,        0,
93 93
 		"maximum bytes queued for write allowed globally (depends on async)"},
94 94
 	/* see also wq_timeout below */
95 95
 	/* tcp socket options */
96 96
 	{ "defer_accept", CFG_VAR_INT | CFG_READONLY,    0,   3600,   0,         0,
97 97
 		"0/1 on linux, seconds on freebsd (see docs)"},
98
-	{ "delayed_ack",  CFG_VAR_INT | CFG_READONLY,    0,      1,   0,         0,
98
+	{ "delayed_ack",  CFG_VAR_INT | CFG_ATOMIC,      0,      1,   0,         0,
99 99
 		"initial ack will be delayed and sent with the first data segment"},
100
-	{ "syncnt",       CFG_VAR_INT | CFG_READONLY,    0,      1,   0,         0,
100
+	{ "syncnt",       CFG_VAR_INT | CFG_ATOMIC,      0,   1024,   0,         0,
101 101
 		"number of syn retransmissions before aborting a connect (0=not set)"},
102
-	{ "linger2",      CFG_VAR_INT | CFG_READONLY,    0,   3600,   0,         0,
102
+	{ "linger2",      CFG_VAR_INT | CFG_ATOMIC,      0,   3600,   0,         0,
103 103
 		"lifetime of orphaned sockets in FIN_WAIT2 state in s (0=not set)"},
104
-	{ "keepalive",    CFG_VAR_INT | CFG_READONLY,    0,      1,   0,         0,
104
+	{ "keepalive",    CFG_VAR_INT | CFG_ATOMIC,      0,      1,   0,         0,
105 105
 		"enables/disables keepalives for tcp"},
106
-	{ "keepidle",     CFG_VAR_INT | CFG_READONLY,    0, 24*3600,  0,         0,
106
+	{ "keepidle",     CFG_VAR_INT | CFG_ATOMIC,      0, 24*3600,  0,         0,
107 107
 		"time before sending a keepalive if the connection is idle (linux)"},
108
-	{ "keepintvl",    CFG_VAR_INT | CFG_READONLY,    0, 24*3600,  0,         0,
108
+	{ "keepintvl",    CFG_VAR_INT | CFG_ATOMIC,      0, 24*3600,  0,         0,
109 109
 		"time interval between keepalive probes on failure (linux)"},
110
-	{ "keepcnt",     CFG_VAR_INT | CFG_READONLY,    0,    1<<10,  0,         0,
110
+	{ "keepcnt",     CFG_VAR_INT | CFG_ATOMIC,       0,    1<<10,  0,        0,
111 111
 		"number of failed keepalives before dropping the connection (linux)"},
112 112
 	/* other options */
113
-	{ "crlf_ping",   CFG_VAR_INT | CFG_READONLY,    0,        1,  0,         0,
113
+	{ "crlf_ping",   CFG_VAR_INT | CFG_ATOMIC,      0,        1,  0,         0,
114 114
 		"enable responding to CRLF SIP-level keepalives "},
115
-	{ "accept_aliases", CFG_VAR_INT | CFG_READONLY, 0,        1,  0,         0,
115
+	{ "accept_aliases", CFG_VAR_INT | CFG_ATOMIC,   0,        1,  0,         0,
116 116
 		"turn on/off tcp aliases (see tcp_accept_aliases) "},
117
-	{ "alias_flags", CFG_VAR_INT | CFG_READONLY,    0,        0,  0,         0,
117
+	{ "alias_flags", CFG_VAR_INT | CFG_ATOMIC,      0,        2,  0,         0,
118 118
 		"flags used for adding new aliases (FORCE_ADD:1 , REPLACE:2) "},
119
-	{ "new_conn_alias_flags", CFG_VAR_INT | CFG_READONLY, 0,  0,  0,         0,
119
+	{ "new_conn_alias_flags", CFG_VAR_INT | CFG_ATOMIC, 0,    2,  0,         0,
120 120
 		"flags for the def. aliases for a new conn. (FORCE_ADD:1, REPLACE:2 "},
121 121
 	/* internal and/or "fixed" versions of some vars
122 122
 	   (not supposed to be writeable, read will provide only debugging value*/
... ...
@@ -203,6 +211,61 @@ static void fix_timeout(char* name, int* to, int default_val, unsigned max_val)
203 203
 
204 204
 
205 205
 
206
+static int fix_connect_to(void* cfg_h, str* name, void** val)
207
+{
208
+	int v;
209
+	v=(int)(long)*val;
210
+	fix_timeout("tcp_connect_timeout", &v, DEFAULT_TCP_CONNECT_TIMEOUT,
211
+						TICKS_TO_S(MAX_TCP_CON_LIFETIME));
212
+	*val=(void*)(long)v;
213
+	return 0;
214
+}
215
+
216
+
217
+static int fix_send_to(void* cfg_h, str* name, void** val)
218
+{
219
+	int v;
220
+	v=(int)(long)*val;
221
+	fix_timeout("tcp_send_timeout", &v, DEFAULT_TCP_SEND_TIMEOUT,
222
+						TICKS_TO_S(MAX_TCP_CON_LIFETIME));
223
+	*val=(void*)(long)v;
224
+#ifdef TCP_BUF_WRITE
225
+	((struct cfg_group_tcp*)cfg_h)->tcp_wq_timeout=S_TO_TICKS(v);
226
+#endif /* TCP_BUF_WRITE */
227
+	return 0;
228
+}
229
+
230
+
231
+static int fix_con_lt(void* cfg_h, str* name, void** val)
232
+{
233
+	int v;
234
+	v=(int)(long)*val;
235
+	fix_timeout("tcp_connection_lifetime", &v,
236
+						TICKS_TO_S(MAX_TCP_CON_LIFETIME),
237
+						TICKS_TO_S(MAX_TCP_CON_LIFETIME));
238
+	*val=(void*)(long)v;
239
+#ifdef TCP_BUF_WRITE
240
+	((struct cfg_group_tcp*)cfg_h)->con_lifetime=S_TO_TICKS(v);
241
+#endif /* TCP_BUF_WRITE */
242
+	return 0;
243
+}
244
+
245
+
246
+static int fix_max_conns(void* cfg_h, str* name, void** val)
247
+{
248
+	int v;
249
+	v=(int)(long)*val;
250
+	if (v>tcp_max_connections){
251
+		INFO("cannot override hard tcp_max_connections limit, please"
252
+				" restart and increase tcp_max_connections in the cfg.\n");
253
+		v=tcp_max_connections;
254
+	}
255
+	*val=(void*)(long)v;
256
+	return 0;
257
+}
258
+
259
+
260
+
206 261
 /* checks & warns if some tcp_option cannot be enabled */
207 262
 void tcp_options_check()
208 263
 {
... ...
@@ -276,7 +339,7 @@ void tcp_options_check()
276 276
 
277 277
 void tcp_options_get(struct cfg_group_tcp* t)
278 278
 {
279
-	*t=tcp_default_cfg;
279
+	*t=*(struct cfg_group_tcp*)tcp_cfg;
280 280
 }
281 281
 
282 282