瀏覽代碼

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 16 年之前
父節點
當前提交
61d0ee5518
共有 6 個文件被更改,包括 49 次插入3 次删除
  1. 3 0
      cfg.lex
  2. 15 0
      cfg.y
  3. 2 1
      core_cmd.c
  4. 21 0
      sctp_options.c
  5. 6 0
      sctp_options.h
  6. 2 2
      sctp_server.c

+ 3 - 0
cfg.lex

@@ -338,6 +338,7 @@ SCTP_SOCKET_SNDBUF	"sctp_socket_sndbuf"|"sctp_socket_send_buffer"
 SCTP_AUTOCLOSE	"sctp_autoclose"
 SCTP_SEND_TTL	"sctp_send_ttl"
 SCTP_SEND_RETRIES	"sctp_send_retries"
+SCTP_ASSOC_REUSE	"sctp_assoc_reuse"
 SCTP_SRTO_INITIAL	"sctp_srto_initial"
 SCTP_SRTO_MAX		"sctp_srto_max"
 SCTP_SRTO_MIN		"sctp_srto_min"
@@ -679,6 +680,8 @@ EAT_ABLE	[\ \t\b\r]
 										return SCTP_SEND_TTL; }
 <INITIAL>{SCTP_SEND_RETRIES}	{ count(); yylval.strval=yytext;
 										return SCTP_SEND_RETRIES; }
+<INITIAL>{SCTP_ASSOC_REUSE}		{ count(); yylval.strval=yytext;
+										return SCTP_ASSOC_REUSE; }
 <INITIAL>{SCTP_SRTO_INITIAL}	{ count(); yylval.strval=yytext;
 										return SCTP_SRTO_INITIAL; }
 <INITIAL>{SCTP_SRTO_MAX}	{ count(); yylval.strval=yytext;

+ 15 - 0
cfg.y

@@ -402,6 +402,7 @@ static void free_socket_id_lst(struct socket_id* i);
 %token SCTP_AUTOCLOSE
 %token SCTP_SEND_TTL
 %token SCTP_SEND_RETRIES
+%token SCTP_ASSOC_REUSE
 %token SCTP_SRTO_INITIAL
 %token SCTP_SRTO_MAX
 %token SCTP_SRTO_MIN
@@ -1204,6 +1205,20 @@ assign_stm:
 		#endif
 	}
 	| SCTP_SEND_RETRIES EQUAL error { yyerror("number expected"); }
+	| SCTP_ASSOC_REUSE EQUAL NUMBER {
+		#ifdef USE_SCTP
+			#ifdef SCTP_CONN_REUSE
+				sctp_default_cfg.assoc_reuse=$3;
+			#else
+				if ($3)
+					warn("sctp association reuse (SCTP_CONN_REUSE) support"
+							" not compiled in");
+			#endif /* SCTP_CONN_REUSE */
+		#else
+			warn("sctp support not compiled in");
+		#endif /* USE_SCTP */
+	}
+	| SCTP_ASSOC_REUSE EQUAL error { yyerror("number expected"); }
 	| SCTP_SRTO_INITIAL EQUAL NUMBER {
 			IF_SCTP(sctp_default_cfg.srto_initial=$3);
 	}

+ 2 - 1
core_cmd.c

@@ -613,12 +613,13 @@ static void core_sctp_options(rpc_t* rpc, void* c)
 	if (!sctp_disable){
 		sctp_options_get(&t);
 		rpc->add(c, "{", &handle);
-		rpc->struct_add(handle, "dddddddddddddddd",
+		rpc->struct_add(handle, "ddddddddddddddddd",
 			"sctp_socket_rcvbuf",	t.so_rcvbuf,
 			"sctp_socket_sndbuf",	t.so_sndbuf,
 			"sctp_autoclose",		t.autoclose,
 			"sctp_send_ttl",	t.send_ttl,
 			"sctp_send_retries",	t.send_retries,
+			"sctp_assoc_reuse",	t.assoc_reuse,
 			"sctp_srto_initial",	t.srto_initial,
 			"sctp_srto_max",		t.srto_max,
 			"sctp_srto_min",		t.srto_min,

+ 21 - 0
sctp_options.c

@@ -48,6 +48,7 @@ struct cfg_group_sctp sctp_default_cfg;
 
 
 static int set_autoclose(void* cfg_h, str* gname, str* name, void** val);
+static int set_assoc_reuse(void* cfg_h, str* gname, str* name, void** val);
 static int set_srto_initial(void* cfg_h, str* gname, str* name, void** val);
 static int set_srto_max(void* cfg_h, str* gname, str* name, void** val);
 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[] = {
 		"milliseconds before aborting a send" },
 	{ "send_retries", CFG_VAR_INT| CFG_ATOMIC, 0, MAX_SCTP_SEND_RETRIES, 0, 0,
 		"re-send attempts on failure" },
+	{ "assoc_reuse", CFG_VAR_INT| CFG_ATOMIC, 0, 1, set_assoc_reuse, 0,
+		"connection/association reuse (for now used only for replies)" },
 	{ "srto_initial", CFG_VAR_INT| CFG_ATOMIC, 0, 1<<30, set_srto_initial, 0,
 		"initial value of the retr. timeout, used in RTO calculations,"
 			" in msecs" },
@@ -120,6 +123,11 @@ void init_sctp_options()
 	sctp_default_cfg.autoclose=DEFAULT_SCTP_AUTOCLOSE; /* in seconds */
 	sctp_default_cfg.send_ttl=DEFAULT_SCTP_SEND_TTL;   /* in milliseconds */
 	sctp_default_cfg.send_retries=DEFAULT_SCTP_SEND_RETRIES;
+#ifdef SCTP_CONN_REUSE
+	sctp_default_cfg.assoc_reuse=1; /* on by default */
+#else
+	sctp_default_cfg.assoc_reuse=0;
+#endif /* SCTP_CONN_REUSE */
 #endif
 }
 
@@ -210,6 +218,19 @@ static int set_autoclose(void* cfg_h, str* gname, str* name, void** val)
 
 
 
+static int set_assoc_reuse(void* cfg_h, str* gname, str* name, void** val)
+{
+#ifndef SCTP_CONN_REUSE
+	if ((int)(long)(*val)!=0){
+		ERR("no SCTP_CONN_REUSE support, please recompile with it enabled\n");
+		return -1;
+	}
+#endif /* SCTP_AUTOCLOSE */
+	return 0;
+}
+
+
+
 static int set_srto_initial(void* cfg_h, str* gname, str* name, void** val)
 {
 #ifdef SCTP_RTOINFO

+ 6 - 0
sctp_options.h

@@ -28,6 +28,11 @@
 #ifndef _sctp_options_h
 #define _sctp_options_h
 
+#ifndef NO_SCTP_CONN_REUSE
+/* SCTP connection reuse by default */
+#define SCTP_CONN_REUSE
+#endif
+
 #define DEFAULT_SCTP_AUTOCLOSE 180 /* seconds */
 #define DEFAULT_SCTP_SEND_TTL  32000 /* in ms (32s)  */
 #define DEFAULT_SCTP_SEND_RETRIES 0
@@ -40,6 +45,7 @@ struct cfg_group_sctp{
 	unsigned int autoclose; /* in seconds */
 	unsigned int send_ttl; /* in milliseconds */
 	unsigned int send_retries;
+	int assoc_reuse; /* reuse the request connection for sending the reply*/
 	unsigned int srto_initial; /** initial retr. timeout */
 	unsigned int srto_max;     /** max retr. timeout */
 	unsigned int srto_min;     /** min retr. timeout */

+ 2 - 2
sctp_server.c

@@ -892,7 +892,6 @@ error:
 #endif /* USE_SCTP_OO */
 
 
-#define SCTP_CONN_REUSE /* FIXME */
 #ifdef SCTP_CONN_REUSE
 
 /* 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,
 	/* if dst->id is set it means we want to send on association with
 	   ser id dst->id if still opened and only if closed use dst->to */
 	assoc_id=0;
-	if ((dst->id) && (assoc_id=sctp_con_get_assoc(dst->id, &si, &to, 0))){
+	if (cfg_get(sctp, sctp_cfg, assoc_reuse) && (dst->id) &&
+			(assoc_id=sctp_con_get_assoc(dst->id, &si, &to, 0))){
 		DBG("sctp: sending on sctp assoc_id %d (ser id %d)\n",
 				assoc_id, dst->id);
 		sinfo->sinfo_assoc_id=assoc_id;