瀏覽代碼

sctp: add module interface for sctp transport

- sctp support is now implemented as a standalone module
- the core still needs SCTP=1 (now default) and -DUSE_SCTP to get the
  hooks enabled
Daniel-Constantin Mierla 12 年之前
父節點
當前提交
d60d411365

+ 16 - 0
modules/sctp/Makefile

@@ -0,0 +1,16 @@
+# $Id$
+#
+# WARNING: do not run this directly, it should be run by the master Makefile
+
+include ../../Makefile.defs
+auto_gen=
+NAME=sctp.so
+LIBS=
+
+ifeq ($(OS), linux)
+LIBS+=-lsctp
+endif
+
+DEFS+=-DKAMAILIO_MOD_INTERFACE
+
+include ../../Makefile.modules

+ 1 - 1
modules/sctp/sctp_ev.h

@@ -41,7 +41,7 @@
 
 #else /* USE_SCTP_EV */
 
-#include "ip_addr.h"
+#include "../../ip_addr.h"
 
 
 /** an association has either been opened or closed.

+ 78 - 0
modules/sctp/sctp_mod.c

@@ -0,0 +1,78 @@
+/**
+ * $Id$
+ *
+ * Copyright (C) 2008 iptelorg GmbH
+ * Copyright (C) 2013 Daniel-Constantin Mierla (asipto.com)
+ *
+ * This file is part of Kamailio, a free SIP server.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "../../sr_module.h"
+#include "../../dprint.h"
+
+#include "sctp_options.h"
+#include "sctp_rpc.h"
+
+MODULE_VERSION
+
+static int mod_init(void);
+
+static cmd_export_t cmds[]={
+	{0, 0, 0, 0, 0, 0}
+};
+
+static param_export_t params[]={
+	{0, 0, 0}
+};
+
+struct module_exports exports = {
+	"sctp",
+	DEFAULT_DLFLAGS, /* dlopen flags */
+	cmds,
+	params,
+	0,
+	0,              /* exported MI functions */
+	0,              /* exported pseudo-variables */
+	0,              /* extra processes */
+	mod_init,       /* module initialization function */
+	0,              /* response function */
+	0,              /* destroy function */
+	0               /* per child init function */
+};
+
+
+static int mod_init(void)
+{
+#ifdef USE_SCTP
+	if (sctp_register_cfg()){
+		LOG(L_CRIT, "could not register the sctp configuration\n");
+		return -1;
+	}
+	if (sctp_register_rpc()){
+		LOG(L_CRIT, "could not register the sctp rpc commands\n");
+		return -1;
+	}
+	return 0;
+#else /* USE_SCTP */
+	LOG(L_CRIT, "sctp core support not enabled\n");
+	return -1;
+#endif /* USE_SCTP */
+}

+ 5 - 3
modules/sctp/sctp_options.c

@@ -44,9 +44,11 @@
 #include <errno.h>
 
 #include "sctp_options.h"
-#include "dprint.h"
-#include "cfg/cfg.h"
-#include "socket_info.h"
+
+#include "../../dprint.h"
+#include "../../cfg/cfg.h"
+#include "../../socket_info.h"
+
 #include "sctp_server.h"
 
 struct cfg_group_sctp sctp_default_cfg;

+ 175 - 0
modules/sctp/sctp_rpc.c

@@ -0,0 +1,175 @@
+/* 
+ * $Id$
+ * 
+ * Copyright (C) 2009 iptelorg GmbH
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include "../../rpc_lookup.h"
+#include "../../socket_info.h"
+#include "../../globals.h"
+#include "../../config.h"
+
+#ifdef USE_SCTP
+#include "sctp_options.h"
+#include "sctp_server.h"
+#endif
+
+
+static const char* core_sctp_options_doc[] = {
+	"Returns active sctp options. With one parameter"
+	" it returns the sctp options set in the kernel for a specific socket"
+	"(debugging), with 0 filled in for non-kernel related options."
+	" The parameter can be: \"default\" | \"first\" | address[:port] ."
+	" With no parameters it returns ser's idea of the current sctp options"
+	 " (intended non-debugging use).",
+	/* Documentation string */
+	0                                 /* Method signature(s) */
+};
+
+static void core_sctp_options(rpc_t* rpc, void* c)
+{
+#ifdef USE_SCTP
+	void *handle;
+	struct cfg_group_sctp t;
+	char* param;
+	struct socket_info* si;
+	char* host;
+	str hs;
+	int hlen;
+	int port;
+	int proto;
+
+	param=0;
+	if (!sctp_disable){
+		/* look for optional socket parameter */
+		if (rpc->scan(c, "*s", &param)>0){
+			si=0;
+			if (strcasecmp(param, "default")==0){
+				si=sendipv4_sctp?sendipv4_sctp:sendipv6_sctp;
+			}else if (strcasecmp(param, "first")==0){
+				si=sctp_listen;
+			}else{
+				if (parse_phostport(param, &host, &hlen, &port, &proto)!=0){
+					rpc->fault(c, 500, "bad param (use address, address:port,"
+										" default or first)");
+					return;
+				}
+				if (proto && proto!=PROTO_SCTP){
+					rpc->fault(c, 500, "bad protocol in param (only SCTP"
+										" allowed)");
+					return;
+				}
+				hs.s=host;
+				hs.len=hlen;
+				si=grep_sock_info(&hs, port, PROTO_SCTP);
+				if (si==0){
+					rpc->fault(c, 500, "not listening on sctp %s", param);
+					return;
+				}
+			}
+			if (si==0 || si->socket==-1){
+				rpc->fault(c, 500, "could not find a sctp socket");
+				return;
+			}
+			memset(&t, 0, sizeof(t));
+			if (sctp_get_cfg_from_sock(si->socket, &t)!=0){
+				rpc->fault(c, 500, "failed to get socket options");
+				return;
+			}
+		}else{
+			sctp_options_get(&t);
+		}
+		rpc->add(c, "{", &handle);
+		rpc->struct_add(handle, "ddddddddddddddddddd",
+			"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_tracking",	t.assoc_tracking,
+			"sctp_assoc_reuse",	t.assoc_reuse,
+			"sctp_max_assocs", t.max_assocs,
+			"sctp_srto_initial",	t.srto_initial,
+			"sctp_srto_max",		t.srto_max,
+			"sctp_srto_min",		t.srto_min,
+			"sctp_asocmaxrxt",	t.asocmaxrxt,
+			"sctp_init_max_attempts",	t.init_max_attempts,
+			"sctp_init_max_timeo",t.init_max_timeo,
+			"sctp_hbinterval",	t.hbinterval,
+			"sctp_pathmaxrxt",	t.pathmaxrxt,
+			"sctp_sack_delay",	t.sack_delay,
+			"sctp_sack_freq",	t.sack_freq,
+			"sctp_max_burst",	t.max_burst
+		);
+	}else{
+		rpc->fault(c, 500, "sctp support disabled");
+	}
+#else
+	rpc->fault(c, 500, "sctp support not compiled");
+#endif
+}
+
+
+
+static const char* core_sctpinfo_doc[] = {
+	"Returns sctp related info.",    /* Documentation string */
+	0                               /* Method signature(s) */
+};
+
+static void core_sctpinfo(rpc_t* rpc, void* c)
+{
+#ifdef USE_SCTP
+	void *handle;
+	struct sctp_gen_info i;
+
+	if (!sctp_disable){
+		sctp_get_info(&i);
+		rpc->add(c, "{", &handle);
+		rpc->struct_add(handle, "ddd",
+			"opened_connections", i.sctp_connections_no,
+			"tracked_connections", i.sctp_tracked_no,
+			"total_connections", i.sctp_total_connections
+		);
+	}else{
+		rpc->fault(c, 500, "sctp support disabled");
+	}
+#else
+	rpc->fault(c, 500, "sctp support not compiled");
+#endif
+}
+
+
+/*
+ * RPC Methods exported by this module
+ */
+static rpc_export_t scp_rpc_methods[] = {
+	{"core.sctp_options",      core_sctp_options,      core_sctp_options_doc,
+		0},
+	{"core.sctp_info",         core_sctpinfo,          core_sctpinfo_doc,   0},
+
+	{0, 0, 0, 0}
+};
+
+
+int sctp_register_rpc(void)
+{
+	if (rpc_register_array(scp_rpc_methods)!=0)
+	{
+		LM_ERR("failed to register RPC commands\n");
+		return -1;
+	}
+
+	return 0;
+}

+ 24 - 0
modules/sctp/sctp_rpc.h

@@ -0,0 +1,24 @@
+/* 
+ * $Id$
+ * 
+ * Copyright (C) 2009 iptelorg GmbH
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef __sctp_rpc_h__
+#define __sctp_rpc_h__
+
+int sctp_register_rpc(void);
+
+#endif

+ 14 - 12
modules/sctp/sctp_server.c

@@ -52,20 +52,22 @@
 #include "sctp_sockopts.h"
 #include "sctp_server.h"
 #include "sctp_options.h"
-#include "globals.h"
-#include "config.h"
-#include "dprint.h"
-#include "receive.h"
-#include "mem/mem.h"
-#include "ip_addr.h"
-#include "cfg/cfg_struct.h"
+
+#include "../../globals.h"
+#include "../../config.h"
+#include "../../dprint.h"
+#include "../../receive.h"
+#include "../../mem/mem.h"
+#include "../../ip_addr.h"
+#include "../../cfg/cfg_struct.h"
 #ifdef USE_DST_BLACKLIST
-#include "dst_blacklist.h"
+#include "../../dst_blacklist.h"
 #endif /* USE_DST_BLACKLIST */
-#include "timer_ticks.h"
-#include "clist.h"
-#include "error.h"
-#include "timer.h"
+#include "../../timer_ticks.h"
+#include "../../clist.h"
+#include "../../error.h"
+#include "../../timer.h"
+
 #include "sctp_stats.h"
 #include "sctp_ev.h"
 

+ 1 - 1
modules/sctp/sctp_server.h

@@ -27,7 +27,7 @@
 #ifndef _sctp_server_h
 #define _sctp_server_h
 
-#include "ip_addr.h"
+#include "../../ip_addr.h"
 
 struct sctp_gen_info{
 	int sctp_connections_no;

+ 2 - 1
modules/sctp/sctp_stats.c

@@ -31,7 +31,8 @@
 
 #ifdef USE_SCTP_STATS
 
-#include "counters.h"
+#include "../../counters.h"
+
 #include "sctp_server.h"
 
 struct sctp_counters_h sctp_cnts_h;

+ 1 - 1
modules/sctp/sctp_stats.h

@@ -50,7 +50,7 @@
 
 #else /* USE_SCTP_STATS */
 
-#include "counters.h"
+#include "../../counters.h"
 
 struct sctp_counters_h {
 	counter_handle_t established;