Browse code

sctp: assoc_reuse option

Association reuse for replies can now be turned off (the default
is on). Config name: sctp_assoc_reuse, real time name: assoc_reuse
(sercmd cfg.set_now_int sctp assoc_reuse 0).

Andrei Pelinescu-Onciul authored on 15/06/2009 22:34:55
Showing 6 changed files
... ...
@@ -338,6 +338,7 @@ SCTP_SOCKET_SNDBUF	"sctp_socket_sndbuf"|"sctp_socket_send_buffer"
338 338
 SCTP_AUTOCLOSE	"sctp_autoclose"
339 339
 SCTP_SEND_TTL	"sctp_send_ttl"
340 340
 SCTP_SEND_RETRIES	"sctp_send_retries"
341
+SCTP_ASSOC_REUSE	"sctp_assoc_reuse"
341 342
 SCTP_SRTO_INITIAL	"sctp_srto_initial"
342 343
 SCTP_SRTO_MAX		"sctp_srto_max"
343 344
 SCTP_SRTO_MIN		"sctp_srto_min"
... ...
@@ -679,6 +680,8 @@ EAT_ABLE	[\ \t\b\r]
679 679
 										return SCTP_SEND_TTL; }
680 680
 <INITIAL>{SCTP_SEND_RETRIES}	{ count(); yylval.strval=yytext;
681 681
 										return SCTP_SEND_RETRIES; }
682
+<INITIAL>{SCTP_ASSOC_REUSE}		{ count(); yylval.strval=yytext;
683
+										return SCTP_ASSOC_REUSE; }
682 684
 <INITIAL>{SCTP_SRTO_INITIAL}	{ count(); yylval.strval=yytext;
683 685
 										return SCTP_SRTO_INITIAL; }
684 686
 <INITIAL>{SCTP_SRTO_MAX}	{ count(); yylval.strval=yytext;
... ...
@@ -402,6 +402,7 @@ static void free_socket_id_lst(struct socket_id* i);
402 402
 %token SCTP_AUTOCLOSE
403 403
 %token SCTP_SEND_TTL
404 404
 %token SCTP_SEND_RETRIES
405
+%token SCTP_ASSOC_REUSE
405 406
 %token SCTP_SRTO_INITIAL
406 407
 %token SCTP_SRTO_MAX
407 408
 %token SCTP_SRTO_MIN
... ...
@@ -1204,6 +1205,20 @@ assign_stm:
1204 1204
 		#endif
1205 1205
 	}
1206 1206
 	| SCTP_SEND_RETRIES EQUAL error { yyerror("number expected"); }
1207
+	| SCTP_ASSOC_REUSE EQUAL NUMBER {
1208
+		#ifdef USE_SCTP
1209
+			#ifdef SCTP_CONN_REUSE
1210
+				sctp_default_cfg.assoc_reuse=$3;
1211
+			#else
1212
+				if ($3)
1213
+					warn("sctp association reuse (SCTP_CONN_REUSE) support"
1214
+							" not compiled in");
1215
+			#endif /* SCTP_CONN_REUSE */
1216
+		#else
1217
+			warn("sctp support not compiled in");
1218
+		#endif /* USE_SCTP */
1219
+	}
1220
+	| SCTP_ASSOC_REUSE EQUAL error { yyerror("number expected"); }
1207 1221
 	| SCTP_SRTO_INITIAL EQUAL NUMBER {
1208 1222
 			IF_SCTP(sctp_default_cfg.srto_initial=$3);
1209 1223
 	}
... ...
@@ -613,12 +613,13 @@ static void core_sctp_options(rpc_t* rpc, void* c)
613 613
 	if (!sctp_disable){
614 614
 		sctp_options_get(&t);
615 615
 		rpc->add(c, "{", &handle);
616
-		rpc->struct_add(handle, "dddddddddddddddd",
616
+		rpc->struct_add(handle, "ddddddddddddddddd",
617 617
 			"sctp_socket_rcvbuf",	t.so_rcvbuf,
618 618
 			"sctp_socket_sndbuf",	t.so_sndbuf,
619 619
 			"sctp_autoclose",		t.autoclose,
620 620
 			"sctp_send_ttl",	t.send_ttl,
621 621
 			"sctp_send_retries",	t.send_retries,
622
+			"sctp_assoc_reuse",	t.assoc_reuse,
622 623
 			"sctp_srto_initial",	t.srto_initial,
623 624
 			"sctp_srto_max",		t.srto_max,
624 625
 			"sctp_srto_min",		t.srto_min,
... ...
@@ -48,6 +48,7 @@ struct cfg_group_sctp sctp_default_cfg;
48 48
 
49 49
 
50 50
 static int set_autoclose(void* cfg_h, str* gname, str* name, void** val);
51
+static int set_assoc_reuse(void* cfg_h, str* gname, str* name, void** val);
51 52
 static int set_srto_initial(void* cfg_h, str* gname, str* name, void** val);
52 53
 static int set_srto_max(void* cfg_h, str* gname, str* name, void** val);
53 54
 static int set_srto_min(void* cfg_h, str* gname, str* name, void** val);
... ...
@@ -76,6 +77,8 @@ static cfg_def_t sctp_cfg_def[] = {
76 76
 		"milliseconds before aborting a send" },
77 77
 	{ "send_retries", CFG_VAR_INT| CFG_ATOMIC, 0, MAX_SCTP_SEND_RETRIES, 0, 0,
78 78
 		"re-send attempts on failure" },
79
+	{ "assoc_reuse", CFG_VAR_INT| CFG_ATOMIC, 0, 1, set_assoc_reuse, 0,
80
+		"connection/association reuse (for now used only for replies)" },
79 81
 	{ "srto_initial", CFG_VAR_INT| CFG_ATOMIC, 0, 1<<30, set_srto_initial, 0,
80 82
 		"initial value of the retr. timeout, used in RTO calculations,"
81 83
 			" in msecs" },
... ...
@@ -120,6 +123,11 @@ void init_sctp_options()
120 120
 	sctp_default_cfg.autoclose=DEFAULT_SCTP_AUTOCLOSE; /* in seconds */
121 121
 	sctp_default_cfg.send_ttl=DEFAULT_SCTP_SEND_TTL;   /* in milliseconds */
122 122
 	sctp_default_cfg.send_retries=DEFAULT_SCTP_SEND_RETRIES;
123
+#ifdef SCTP_CONN_REUSE
124
+	sctp_default_cfg.assoc_reuse=1; /* on by default */
125
+#else
126
+	sctp_default_cfg.assoc_reuse=0;
127
+#endif /* SCTP_CONN_REUSE */
123 128
 #endif
124 129
 }
125 130
 
... ...
@@ -210,6 +218,19 @@ static int set_autoclose(void* cfg_h, str* gname, str* name, void** val)
210 210
 
211 211
 
212 212
 
213
+static int set_assoc_reuse(void* cfg_h, str* gname, str* name, void** val)
214
+{
215
+#ifndef SCTP_CONN_REUSE
216
+	if ((int)(long)(*val)!=0){
217
+		ERR("no SCTP_CONN_REUSE support, please recompile with it enabled\n");
218
+		return -1;
219
+	}
220
+#endif /* SCTP_AUTOCLOSE */
221
+	return 0;
222
+}
223
+
224
+
225
+
213 226
 static int set_srto_initial(void* cfg_h, str* gname, str* name, void** val)
214 227
 {
215 228
 #ifdef SCTP_RTOINFO
... ...
@@ -28,6 +28,11 @@
28 28
 #ifndef _sctp_options_h
29 29
 #define _sctp_options_h
30 30
 
31
+#ifndef NO_SCTP_CONN_REUSE
32
+/* SCTP connection reuse by default */
33
+#define SCTP_CONN_REUSE
34
+#endif
35
+
31 36
 #define DEFAULT_SCTP_AUTOCLOSE 180 /* seconds */
32 37
 #define DEFAULT_SCTP_SEND_TTL  32000 /* in ms (32s)  */
33 38
 #define DEFAULT_SCTP_SEND_RETRIES 0
... ...
@@ -40,6 +45,7 @@ struct cfg_group_sctp{
40 40
 	unsigned int autoclose; /* in seconds */
41 41
 	unsigned int send_ttl; /* in milliseconds */
42 42
 	unsigned int send_retries;
43
+	int assoc_reuse; /* reuse the request connection for sending the reply*/
43 44
 	unsigned int srto_initial; /** initial retr. timeout */
44 45
 	unsigned int srto_max;     /** max retr. timeout */
45 46
 	unsigned int srto_min;     /** min retr. timeout */
... ...
@@ -892,7 +892,6 @@ error:
892 892
 #endif /* USE_SCTP_OO */
893 893
 
894 894
 
895
-#define SCTP_CONN_REUSE /* FIXME */
896 895
 #ifdef SCTP_CONN_REUSE
897 896
 
898 897
 /* we  need SCTP_ADDR_HASH for being able to make inquires related to existing
... ...
@@ -2462,7 +2461,8 @@ static int sctp_msg_send_raw(struct dest_info* dst, char* buf, unsigned len,
2462 2462
 	/* if dst->id is set it means we want to send on association with
2463 2463
 	   ser id dst->id if still opened and only if closed use dst->to */
2464 2464
 	assoc_id=0;
2465
-	if ((dst->id) && (assoc_id=sctp_con_get_assoc(dst->id, &si, &to, 0))){
2465
+	if (cfg_get(sctp, sctp_cfg, assoc_reuse) && (dst->id) &&
2466
+			(assoc_id=sctp_con_get_assoc(dst->id, &si, &to, 0))){
2466 2467
 		DBG("sctp: sending on sctp assoc_id %d (ser id %d)\n",
2467 2468
 				assoc_id, dst->id);
2468 2469
 		sinfo->sinfo_assoc_id=assoc_id;