浏览代码

sctp: connection reuse & connection tracking

- support for sctp connection tracking and true sctp connection
  reuse for replies.
  We need this to support reply connection reuse with asymmetric
  sctp peers (while there is no reason not to use the same port on
  sctp for sending and receiving messages and it should be
  strongly discouraged to do so, we never now with what
  implementation we'll have to deal).
  What  makes this particularly complex is the not-yet-complete
  sctp API, the slight but important behaviour
  differences between its linux, freebsd and solaris
  implementations and the fact that is more geared towards serial
  single threaded application rather then parallel-processing
  multi-process or multi-threaded ones.

- keep track of the number of active and tracked sctp connections

- blacklist moved into sctp_handles_assoc_change()
Andrei Pelinescu-Onciul 16 年之前
父节点
当前提交
31fd952ba8
共有 5 个文件被更改,包括 1047 次插入7 次删除
  1. 10 1
      forward.c
  2. 8 0
      main.c
  3. 14 6
      msg_translator.c
  4. 1004 0
      sctp_server.c
  5. 11 0
      sctp_server.h

+ 10 - 1
forward.c

@@ -641,11 +641,20 @@ int forward_reply(struct sip_msg* msg)
 	dst.comp=msg->via2->comp_no;
 	dst.comp=msg->via2->comp_no;
 #endif
 #endif
 
 
+#if defined USE_TCP || defined USE_SCTP
+	if (
 #ifdef USE_TCP
 #ifdef USE_TCP
-	if (dst.proto==PROTO_TCP
+			dst.proto==PROTO_TCP
 #ifdef USE_TLS
 #ifdef USE_TLS
 			|| dst.proto==PROTO_TLS
 			|| dst.proto==PROTO_TLS
 #endif
 #endif
+#ifdef USE_SCTP
+			||
+#endif /* USE_SCTP */
+#endif /* USE_TCP */
+#ifdef USE_SCTP
+			dst.proto==PROTO_SCTP
+#endif /* USE_SCTP */
 			){
 			){
 		/* find id in i param if it exists */
 		/* find id in i param if it exists */
 		if (msg->via1->i && msg->via1->i->value.s){
 		if (msg->via1->i && msg->via1->i->value.s){

+ 8 - 0
main.c

@@ -1959,6 +1959,14 @@ try_again:
 		}
 		}
 	}
 	}
 #endif /* USE_TCP */
 #endif /* USE_TCP */
+#ifdef USE_SCTP
+	if (!sctp_disable){
+		if (init_sctp()<0){
+			LOG(L_CRIT, "Could not initialize sctp, exiting...\n");
+			goto error;
+		}
+	}
+#endif /* USE_SCTP */
 	/* init_daemon? */
 	/* init_daemon? */
 	if (!dont_fork){
 	if (!dont_fork){
 		if ( daemonize(argv[0]) <0 ) goto error;
 		if ( daemonize(argv[0]) <0 ) goto error;

+ 14 - 6
msg_translator.c

@@ -2287,7 +2287,7 @@ char* create_via_hf( unsigned int *len,
 	char* via;
 	char* via;
 	str extra_params;
 	str extra_params;
 	struct hostport hp;
 	struct hostport hp;
-#ifdef USE_TCP
+#if defined USE_TCP || defined USE_SCTP
 	char* id_buf;
 	char* id_buf;
 	unsigned int id_len;
 	unsigned int id_len;
 
 
@@ -2299,13 +2299,21 @@ char* create_via_hf( unsigned int *len,
 	extra_params.s=0;
 	extra_params.s=0;
 
 
 
 
-#ifdef USE_TCP
+#if defined USE_TCP || defined USE_SCTP
 	/* add id if tcp */
 	/* add id if tcp */
-	if (msg
-	&& ((msg->rcv.proto==PROTO_TCP)
+	if (msg && (
+#ifdef USE_TCP
+		(msg->rcv.proto==PROTO_TCP)
 #ifdef USE_TLS
 #ifdef USE_TLS
 			|| (msg->rcv.proto==PROTO_TLS)
 			|| (msg->rcv.proto==PROTO_TLS)
 #endif
 #endif
+#ifdef USE_SCTP
+			||
+#endif /* USE_SCTP */
+#endif /* USE_TCP */
+#ifdef USE_SCTP
+			(msg->rcv.proto==PROTO_SCTP)
+#endif /* USE_SCTP */
 			)){
 			)){
 		if  ((id_buf=id_builder(msg, &id_len))==0){
 		if  ((id_buf=id_builder(msg, &id_len))==0){
 			LOG(L_ERR, "ERROR: create_via_hf:"
 			LOG(L_ERR, "ERROR: create_via_hf:"
@@ -2318,13 +2326,13 @@ char* create_via_hf( unsigned int *len,
 		extra_params.s=id_buf;
 		extra_params.s=id_buf;
 		extra_params.len=id_len;
 		extra_params.len=id_len;
 	}
 	}
-#endif
+#endif /* USE_TCP || USE_SCTP */
 
 
 	set_hostport(&hp, msg);
 	set_hostport(&hp, msg);
 	via = via_builder( len, send_info, branch,
 	via = via_builder( len, send_info, branch,
 							extra_params.len?&extra_params:0, &hp);
 							extra_params.len?&extra_params:0, &hp);
 
 
-#ifdef USE_TCP
+#if defined USE_TCP || defined USE_SCTP
 	/* we do not need id_buf any more, the id is already in the new via header */
 	/* we do not need id_buf any more, the id is already in the new via header */
 	if (id_buf) pkg_free(id_buf);
 	if (id_buf) pkg_free(id_buf);
 #endif
 #endif

文件差异内容过多而无法显示
+ 1004 - 0
sctp_server.c


+ 11 - 0
sctp_server.h

@@ -29,12 +29,23 @@
 
 
 #include "ip_addr.h"
 #include "ip_addr.h"
 
 
+struct sctp_gen_info{
+	int sctp_connections_no;
+	int sctp_tracked_no;
+	int sctp_total_connections;
+};
+
+int init_sctp();
+void destroy_sctp();
 int sctp_check_compiled_sockopts(char* buf, int size);
 int sctp_check_compiled_sockopts(char* buf, int size);
 int sctp_check_support();
 int sctp_check_support();
 int sctp_init_sock(struct socket_info* sock_info);
 int sctp_init_sock(struct socket_info* sock_info);
 int sctp_rcv_loop();
 int sctp_rcv_loop();
 int sctp_msg_send(struct dest_info* dst, char* buf, unsigned len);
 int sctp_msg_send(struct dest_info* dst, char* buf, unsigned len);
 
 
+/* generic sctp information (stats a.s.o) */
+void sctp_get_info(struct sctp_gen_info* sinf);
+
 void destroy_sctp();
 void destroy_sctp();
 
 
 #endif /* _sctp_server_h */
 #endif /* _sctp_server_h */

部分文件因为文件数量过多而无法显示