[SR-Dev] git:ser_core_cvs: tcp: enable runtime changing for most of the cfg vars

Andrei Pelinescu-Onciul andrei at iptel.org
Thu Mar 5 18:33:53 CET 2009


Module: sip-router
Branch: ser_core_cvs
Commit: c0c298d54baae3143a0113a0838fe05dcee7695d
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=c0c298d54baae3143a0113a0838fe05dcee7695d

Author: Andrei Pelinescu-Onciul <andrei at iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei at iptel.org>
Date:   Thu Mar  5 17:20:53 2009 +0000

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

---

 core_cmd.c    |   22 ++++++++----
 tcp_options.c |  105 +++++++++++++++++++++++++++++++++++++++++++++-----------
 2 files changed, 98 insertions(+), 29 deletions(-)

diff --git a/core_cmd.c b/core_cmd.c
index fdb66a0..ccac004 100644
--- a/core_cmd.c
+++ b/core_cmd.c
@@ -565,14 +565,17 @@ static void core_tcp_options(rpc_t* rpc, void* c)
 	if (!tcp_disable){
 		tcp_options_get(&t);
 		rpc->add(c, "{", &handle);
-		rpc->struct_add(handle, "ddddddddddddddd",
+		rpc->struct_add(handle, "dddddddddddddddddddddd",
+			"connect_timeout", t.connect_timeout_s,
+			"send_timeout",  t.send_timeout_s,
+			"connection_lifetime",  t.con_lifetime_s,
+			"max_connections(soft)", t.max_connections,
 			"fd_cache",		t.fd_cache,
-			"tcp_buf_write",	t.tcp_buf_write,
-			"tcp_connect_wait",	t.tcp_connect_wait,
-			"tcpconn_wq_max",	t.tcpconn_wq_max,
-			"tcp_wq_max",	t.tcp_wq_max,
-			"tcp_wq_timeout",	TICKS_TO_S(t.tcp_wq_timeout),
-			
+			"async",		t.tcp_buf_write,
+			"connect_wait",	t.tcp_connect_wait,
+			"conn_wq_max",	t.tcpconn_wq_max,
+			"wq_max",		t.tcp_wq_max,
+			"wq_timeout",	TICKS_TO_S(t.tcp_wq_timeout),
 			"defer_accept",	t.defer_accept,
 			"delayed_ack",	t.delayed_ack,
 			"syncnt",		t.syncnt,
@@ -581,7 +584,10 @@ static void core_tcp_options(rpc_t* rpc, void* c)
 			"keepidle",		t.keepidle,
 			"keepintvl",	t.keepintvl,
 			"keepcnt",		t.keepcnt,
-			"crlf_ping",	t.crlf_ping
+			"crlf_ping",	t.crlf_ping,
+			"accept_aliases", t.accept_aliases,
+			"alias_flags",	t.alias_flags,
+			"new_conn_alias_flags",	t.new_conn_alias_flags
 		);
 	}else{
 		rpc->fault(c, 500, "tcp support disabled");
diff --git a/tcp_options.c b/tcp_options.c
index fa522a1..a292b01 100644
--- a/tcp_options.c
+++ b/tcp_options.c
@@ -65,20 +65,28 @@ struct cfg_group_tcp tcp_default_cfg;
 
 
 
+static int fix_connect_to(void* cfg_h, str* name, void** val);
+static int fix_send_to(void* cfg_h, str* name, void** val);
+static int fix_con_lt(void* cfg_h, str* name, void** val);
+static int fix_max_conns(void* cfg_h, str* name, void** val);
+
+
+
 /* cfg_group_tcp description (for the config framework)*/
 static cfg_def_t tcp_cfg_def[] = {
 	/*   name        , type |input type| chg type, min, max, fixup, proc. cbk 
 	      description */
-	{ "connect_timeout", CFG_VAR_INT | CFG_READONLY, -1,
-						TICKS_TO_S(MAX_TCP_CON_LIFETIME),         0,         0,
+	{ "connect_timeout", CFG_VAR_INT | CFG_ATOMIC,  -1,
+						TICKS_TO_S(MAX_TCP_CON_LIFETIME),  fix_connect_to,   0,
 		"used only in non-async mode, in seconds"},
-	{ "send_timeout", CFG_VAR_INT | CFG_READONLY,   -1,
-						TICKS_TO_S(MAX_TCP_CON_LIFETIME),         0,         0,
+	{ "send_timeout", CFG_VAR_INT | CFG_ATOMIC,   -1,
+						TICKS_TO_S(MAX_TCP_CON_LIFETIME),   fix_send_to,     0,
 		"in seconds"},
-	{ "connection_lifetime", CFG_VAR_INT | CFG_READONLY,   -1,
-						TICKS_TO_S(MAX_TCP_CON_LIFETIME),         0,         0,
+	{ "connection_lifetime", CFG_VAR_INT | CFG_ATOMIC,   -1,
+						TICKS_TO_S(MAX_TCP_CON_LIFETIME),   fix_con_lt,      0,
 		"connection lifetime (in seconds)"},
-	{ "max_connections", CFG_VAR_INT | CFG_READONLY, 0,  (1U<<31)-1, 0,      0,
+	{ "max_connections", CFG_VAR_INT | CFG_ATOMIC, 0, (1U<<31)-1,
+													       fix_max_conns,    0,
 		"maximum connection number, soft limit"},
 	{ "fd_cache",     CFG_VAR_INT | CFG_READONLY,    0,   1,      0,         0,
 		"file descriptor cache for tcp_send"},
@@ -87,36 +95,36 @@ static cfg_def_t tcp_cfg_def[] = {
 		"async mode for writes and connects"},
 	{ "connect_wait", CFG_VAR_INT | CFG_READONLY,    0,   1,      0,         0,
 		"parallel simultaneous connects to the same dst. (0) or one connect"},
-	{ "conn_wq_max",  CFG_VAR_INT | CFG_READONLY,    0, 1024*1024, 0,        0,
+	{ "conn_wq_max",  CFG_VAR_INT | CFG_ATOMIC,      0, 1024*1024, 0,        0,
 		"maximum bytes queued for write per connection (depends on async)"},
-	{ "wq_max",       CFG_VAR_INT | CFG_READONLY,    0,  1<<30,    0,        0,
+	{ "wq_max",       CFG_VAR_INT | CFG_ATOMIC,      0,  1<<30,    0,        0,
 		"maximum bytes queued for write allowed globally (depends on async)"},
 	/* see also wq_timeout below */
 	/* tcp socket options */
 	{ "defer_accept", CFG_VAR_INT | CFG_READONLY,    0,   3600,   0,         0,
 		"0/1 on linux, seconds on freebsd (see docs)"},
-	{ "delayed_ack",  CFG_VAR_INT | CFG_READONLY,    0,      1,   0,         0,
+	{ "delayed_ack",  CFG_VAR_INT | CFG_ATOMIC,      0,      1,   0,         0,
 		"initial ack will be delayed and sent with the first data segment"},
-	{ "syncnt",       CFG_VAR_INT | CFG_READONLY,    0,      1,   0,         0,
+	{ "syncnt",       CFG_VAR_INT | CFG_ATOMIC,      0,   1024,   0,         0,
 		"number of syn retransmissions before aborting a connect (0=not set)"},
-	{ "linger2",      CFG_VAR_INT | CFG_READONLY,    0,   3600,   0,         0,
+	{ "linger2",      CFG_VAR_INT | CFG_ATOMIC,      0,   3600,   0,         0,
 		"lifetime of orphaned sockets in FIN_WAIT2 state in s (0=not set)"},
-	{ "keepalive",    CFG_VAR_INT | CFG_READONLY,    0,      1,   0,         0,
+	{ "keepalive",    CFG_VAR_INT | CFG_ATOMIC,      0,      1,   0,         0,
 		"enables/disables keepalives for tcp"},
-	{ "keepidle",     CFG_VAR_INT | CFG_READONLY,    0, 24*3600,  0,         0,
+	{ "keepidle",     CFG_VAR_INT | CFG_ATOMIC,      0, 24*3600,  0,         0,
 		"time before sending a keepalive if the connection is idle (linux)"},
-	{ "keepintvl",    CFG_VAR_INT | CFG_READONLY,    0, 24*3600,  0,         0,
+	{ "keepintvl",    CFG_VAR_INT | CFG_ATOMIC,      0, 24*3600,  0,         0,
 		"time interval between keepalive probes on failure (linux)"},
-	{ "keepcnt",     CFG_VAR_INT | CFG_READONLY,    0,    1<<10,  0,         0,
+	{ "keepcnt",     CFG_VAR_INT | CFG_ATOMIC,       0,    1<<10,  0,        0,
 		"number of failed keepalives before dropping the connection (linux)"},
 	/* other options */
-	{ "crlf_ping",   CFG_VAR_INT | CFG_READONLY,    0,        1,  0,         0,
+	{ "crlf_ping",   CFG_VAR_INT | CFG_ATOMIC,      0,        1,  0,         0,
 		"enable responding to CRLF SIP-level keepalives "},
-	{ "accept_aliases", CFG_VAR_INT | CFG_READONLY, 0,        1,  0,         0,
+	{ "accept_aliases", CFG_VAR_INT | CFG_ATOMIC,   0,        1,  0,         0,
 		"turn on/off tcp aliases (see tcp_accept_aliases) "},
-	{ "alias_flags", CFG_VAR_INT | CFG_READONLY,    0,        0,  0,         0,
+	{ "alias_flags", CFG_VAR_INT | CFG_ATOMIC,      0,        2,  0,         0,
 		"flags used for adding new aliases (FORCE_ADD:1 , REPLACE:2) "},
-	{ "new_conn_alias_flags", CFG_VAR_INT | CFG_READONLY, 0,  0,  0,         0,
+	{ "new_conn_alias_flags", CFG_VAR_INT | CFG_ATOMIC, 0,    2,  0,         0,
 		"flags for the def. aliases for a new conn. (FORCE_ADD:1, REPLACE:2 "},
 	/* internal and/or "fixed" versions of some vars
 	   (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)
 
 
 
+static int fix_connect_to(void* cfg_h, str* name, void** val)
+{
+	int v;
+	v=(int)(long)*val;
+	fix_timeout("tcp_connect_timeout", &v, DEFAULT_TCP_CONNECT_TIMEOUT,
+						TICKS_TO_S(MAX_TCP_CON_LIFETIME));
+	*val=(void*)(long)v;
+	return 0;
+}
+
+
+static int fix_send_to(void* cfg_h, str* name, void** val)
+{
+	int v;
+	v=(int)(long)*val;
+	fix_timeout("tcp_send_timeout", &v, DEFAULT_TCP_SEND_TIMEOUT,
+						TICKS_TO_S(MAX_TCP_CON_LIFETIME));
+	*val=(void*)(long)v;
+#ifdef TCP_BUF_WRITE
+	((struct cfg_group_tcp*)cfg_h)->tcp_wq_timeout=S_TO_TICKS(v);
+#endif /* TCP_BUF_WRITE */
+	return 0;
+}
+
+
+static int fix_con_lt(void* cfg_h, str* name, void** val)
+{
+	int v;
+	v=(int)(long)*val;
+	fix_timeout("tcp_connection_lifetime", &v,
+						TICKS_TO_S(MAX_TCP_CON_LIFETIME),
+						TICKS_TO_S(MAX_TCP_CON_LIFETIME));
+	*val=(void*)(long)v;
+#ifdef TCP_BUF_WRITE
+	((struct cfg_group_tcp*)cfg_h)->con_lifetime=S_TO_TICKS(v);
+#endif /* TCP_BUF_WRITE */
+	return 0;
+}
+
+
+static int fix_max_conns(void* cfg_h, str* name, void** val)
+{
+	int v;
+	v=(int)(long)*val;
+	if (v>tcp_max_connections){
+		INFO("cannot override hard tcp_max_connections limit, please"
+				" restart and increase tcp_max_connections in the cfg.\n");
+		v=tcp_max_connections;
+	}
+	*val=(void*)(long)v;
+	return 0;
+}
+
+
+
 /* checks & warns if some tcp_option cannot be enabled */
 void tcp_options_check()
 {
@@ -276,7 +339,7 @@ void tcp_options_check()
 
 void tcp_options_get(struct cfg_group_tcp* t)
 {
-	*t=tcp_default_cfg;
+	*t=*(struct cfg_group_tcp*)tcp_cfg;
 }
 
 




More information about the sr-dev mailing list