Browse code

tcp: config option to disable active connects

- added new config option to disable active connects. If set ser
will only accept new connection, it will not actively open new
ones.
The option can be set both in ser.cfg (tcp_no_connect=yes) or
at runtime (sercmd cfg.set_now_int tcp no_connect 1).

Andrei Pelinescu-Onciul authored on 05/03/2009 17:21:30
Showing 7 changed files
... ...
@@ -209,12 +209,15 @@ modules:
209 209
                         - t_set_retr(t1, t2) - changes the retransmissions
210 210
                            intervals on the fly, on a per transaction basis.
211 211
 core:
212
+             - most tcp config vars migrated to the dynamic config framework
213
+               (can be changed at runtime, e.g. 
214
+                 sercmd cfg.set_now_int tcp connection_lifetime 180 )
212 215
              - fallback to tcp or other congestion controlled transport 
213 216
                protocol if a forwarded udp sip request is greater then 
214 217
                udp_mtu (config). Default off. See udp_mtu and 
215 218
                udp_mtu_try_proto.
216 219
              - sctp support (one-to-many, work in progress, for now linux
217
-               only with no fallback to one-to-one on full send buffers)
220
+               and freebsd only)
218 221
              - partial cygwin (windows) support revived: core+static modules, 
219 222
                no ipv6, no tcp, no dynamic modules
220 223
              - most of the config variables can now be changed on the fly,
... ...
@@ -233,6 +236,9 @@ core:
233 233
                between the short name and long name in cache as CNAME record
234 234
 
235 235
 new config variables:
236
+  tcp_no_connect = yes/no - disable connects, ser will only accept new 
237
+                     connections, it will never try to open new ones.
238
+                     Default: no, can be changed at runtime.
236 239
   udp_mtu = number - fallback to another protocol (udp_mtu_try_proto must be
237 240
                      set also either globally or per packet) if the constructed
238 241
                      request size is greater then udp_mtu.
... ...
@@ -298,6 +298,7 @@ TCP_CONNECT_TIMEOUT	"tcp_connect_timeout"
298 298
 TCP_CON_LIFETIME	"tcp_connection_lifetime"
299 299
 TCP_POLL_METHOD		"tcp_poll_method"
300 300
 TCP_MAX_CONNECTIONS	"tcp_max_connections"
301
+TCP_NO_CONNECT		"tcp_no_connect"
301 302
 TCP_SOURCE_IPV4		"tcp_source_ipv4"
302 303
 TCP_SOURCE_IPV6		"tcp_source_ipv6"
303 304
 TCP_OPT_FD_CACHE	"tcp_fd_cache"
... ...
@@ -592,6 +593,8 @@ EAT_ABLE	[\ \t\b\r]
592 592
 									return TCP_POLL_METHOD; }
593 593
 <INITIAL>{TCP_MAX_CONNECTIONS}	{ count(); yylval.strval=yytext;
594 594
 									return TCP_MAX_CONNECTIONS; }
595
+<INITIAL>{TCP_NO_CONNECT}		{ count(); yylval.strval=yytext;
596
+									return TCP_NO_CONNECT; }
595 597
 <INITIAL>{TCP_SOURCE_IPV4}		{ count(); yylval.strval=yytext;
596 598
 									return TCP_SOURCE_IPV4; }
597 599
 <INITIAL>{TCP_SOURCE_IPV6}		{ count(); yylval.strval=yytext;
... ...
@@ -351,6 +351,7 @@ static void free_socket_id_lst(struct socket_id* i);
351 351
 %token TCP_CON_LIFETIME
352 352
 %token TCP_POLL_METHOD
353 353
 %token TCP_MAX_CONNECTIONS
354
+%token TCP_NO_CONNECT
354 355
 %token TCP_SOURCE_IPV4
355 356
 %token TCP_SOURCE_IPV6
356 357
 %token TCP_OPT_FD_CACHE
... ...
@@ -839,6 +840,14 @@ assign_stm:
839 839
 		#endif
840 840
 	}
841 841
 	| TCP_MAX_CONNECTIONS EQUAL error { yyerror("number expected"); }
842
+	| TCP_NO_CONNECT EQUAL NUMBER {
843
+		#ifdef USE_TCP
844
+			tcp_default_cfg.no_connect=$3;
845
+		#else
846
+			warn("tcp support not compiled in");
847
+		#endif
848
+	}
849
+	| TCP_NO_CONNECT EQUAL error { yyerror("boolean value expected"); }
842 850
 	| TCP_SOURCE_IPV4 EQUAL ipv4 {
843 851
 		#ifdef USE_TCP
844 852
 			if (tcp_set_src_addr($3)<0)
... ...
@@ -565,11 +565,12 @@ 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, "dddddddddddddddddddddd",
568
+		rpc->struct_add(handle, "ddddddddddddddddddddddd",
569 569
 			"connect_timeout", t.connect_timeout_s,
570 570
 			"send_timeout",  t.send_timeout_s,
571 571
 			"connection_lifetime",  t.con_lifetime_s,
572 572
 			"max_connections(soft)", t.max_connections,
573
+			"no_connect",	t.no_connect,
573 574
 			"fd_cache",		t.fd_cache,
574 575
 			"async",		t.async,
575 576
 			"connect_wait",	t.tcp_connect_wait,
... ...
@@ -1659,6 +1659,9 @@ int tcp_send(struct dest_info* dst, union sockaddr_union* from,
1659 1659
 	}
1660 1660
 no_id:
1661 1661
 		if (unlikely(c==0)){
1662
+			/* check if connect() is disabled */
1663
+			if (cfg_get(tcp, tcp_cfg, no_connect))
1664
+				return -1;
1662 1665
 			DBG("tcp_send: no open tcp connection found, opening new one\n");
1663 1666
 			/* create tcp connection */
1664 1667
 			if (likely(from==0)){
... ...
@@ -88,6 +88,8 @@ static cfg_def_t tcp_cfg_def[] = {
88 88
 	{ "max_connections", CFG_VAR_INT | CFG_ATOMIC, 0, (1U<<31)-1,
89 89
 													       fix_max_conns,    0,
90 90
 		"maximum connection number, soft limit"},
91
+	{ "no_connect",   CFG_VAR_INT | CFG_ATOMIC,      0,   1,      0,         0,
92
+		"if set only accept new connections, never actively open new ones"},
91 93
 	{ "fd_cache",     CFG_VAR_INT | CFG_READONLY,    0,   1,      0,         0,
92 94
 		"file descriptor cache for tcp_send"},
93 95
 	/* tcp async options */
... ...
@@ -115,6 +115,7 @@ struct cfg_group_tcp{
115 115
 	int send_timeout_s; /* in s */
116 116
 	int con_lifetime_s; /* in s */
117 117
 	int max_connections;
118
+	int no_connect; /* do not open any new tcp connection (but accept them) */
118 119
 	int fd_cache; /* on /off */
119 120
 	/* tcp async options */
120 121
 	int async; /* on / off */