[sr-dev] git:andrei/raw_sock: raw sockets: runtime config support

Andrei Pelinescu-Onciul andrei at iptel.org
Tue Jun 15 16:36:03 CEST 2010


Module: sip-router
Branch: andrei/raw_sock
Commit: 1db67b92772ffbdfe2320774f91b75e87414c462
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=1db67b92772ffbdfe2320774f91b75e87414c462

Author: Andrei Pelinescu-Onciul <andrei at iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei at iptel.org>
Date:   Tue Jun 15 16:31:16 2010 +0200

raw sockets: runtime config support

Usage of raw sockets for send and the used mtu can now be set
at runtime via the 2 new added core config variables:
 udp4_raw and udp4_raw_mtu.
udp4_raw can have 3 values: disabled (0), on (1) and auto (-1). If
set to auto raw sockets will be used if possible.

E.g.:
sercmd cfg.set_now_int core udp4_raw_mtu 576

---

 cfg_core.c |   62 ++++++++++++++++++++++++++++++++++++++++++++++++++---------
 cfg_core.h |   11 +++++----
 globals.h  |    4 +++
 3 files changed, 62 insertions(+), 15 deletions(-)

diff --git a/cfg_core.c b/cfg_core.c
index 101ba9f..7f2018c 100644
--- a/cfg_core.c
+++ b/cfg_core.c
@@ -24,16 +24,15 @@
  *  2007-12-03	Initial version (Miklos)
  *  2008-01-31  added DNS resolver parameters (Miklos)
  */
-/*!
- * \file
- * \brief SIP-router core ::  Core configuration parser
- * \ingroup core
- * Module: \ref core
+/** core runtime config.
+ * @file cfg_core.c
+ * @ingroup core
+ * Module: @ref core
  *
- * See 
- * - \ref ConfigCoreDoc
- * - \ref ConfigEngine
- * - \ref cfg_core.h
+ * See
+ * - @ref ConfigCoreDoc
+ * - @ref ConfigEngine
+ * - @ref cfg_core.h
  */
 /*!
  * \page ConfigCoreDoc Documentation of configuration parser
@@ -112,6 +111,8 @@ struct cfg_group_core default_core_cfg = {
 	DEFAULT_MAX_WHILE_LOOPS, /*!< max_while_loops */
 	0, /*!< udp_mtu (disabled by default) */
 	0, /*!< udp_mtu_try_proto -> default disabled */
+	0, /**< udp4_raw (disabled by default) */
+	1500, /**< udp4_raw_mtu (1500 by default) */
 	0,  /*!< force_rport */
 	L_DBG, /*!< memlog */
 	1 /*!< mem_summary -flags: 0 off, 1 shm/pkg_status, 2 shm/pkg_sums */
@@ -119,6 +120,39 @@ struct cfg_group_core default_core_cfg = {
 
 void	*core_cfg = &default_core_cfg;
 
+
+static int check_raw_sock_support(void* cfg_h, str* gname, str* name,
+									void** v)
+{
+	int val;
+	
+	val = (int)(long)(*v);
+#ifndef USE_RAW_SOCKS
+	if (val > 0) {
+		ERR("no RAW_SOCKS support, please recompile with it enabled\n");
+		return -1;
+	}
+	return 0;
+#else /* USE_RAW_SOCKS */
+	if (raw_udp4_send_sock < 0) {
+		if (val > 0) {
+			ERR("could not intialize raw socket on startup, please "
+					"restart as root or with CAP_NET_RAW\n");
+			return -1;
+		} else if (val < 0) {
+			/* auto and no socket => disable */
+			*v = (void*)(long)0;
+		}
+	} else if (val < 0) {
+		/* auto and socket => enable */
+		*v = (void*)(long)1;
+	}
+	return 0;
+#endif /* USE_RAW_SOCKS */
+}
+
+
+
 cfg_def_t core_cfg_def[] = {
 	{"debug",		CFG_VAR_INT|CFG_ATOMIC,	0, 0, 0, 0,
 		"debug level"},
@@ -177,7 +211,8 @@ cfg_def_t core_cfg_def[] = {
 	{"dns_search_full_match",	CFG_VAR_INT,	0, 1, 0, 0,
 		"enable/disable domain name checks against the search list "
 		"in DNS answers"},
-	{"dns_reinit",		CFG_VAR_INT|CFG_INPUT_INT,	1, 1, dns_reinit_fixup, resolv_reinit,
+	{"dns_reinit",		CFG_VAR_INT|CFG_INPUT_INT,	1, 1, dns_reinit_fixup,
+		resolv_reinit,
 		"set to 1 in order to reinitialize the DNS resolver"},
 	/* DNS cache */
 #ifdef USE_DNS_CACHE
@@ -222,6 +257,13 @@ cfg_def_t core_cfg_def[] = {
 			" exceeds udp_mtu"},
 	{"udp_mtu_try_proto", CFG_VAR_INT, 1, 4, 0, fix_global_req_flags,
 		"if send size > udp_mtu use proto (1 udp, 2 tcp, 3 tls, 4 sctp)"},
+	{"udp4_raw", CFG_VAR_INT | CFG_ATOMIC, -1, 1, check_raw_sock_support, 0,
+		"enable/disable using a raw socket for sending UDP IPV4 packets."
+		" Should be  faster on multi-CPU linux running machines."},
+	{"udp4_raw_mtu", CFG_VAR_INT | CFG_ATOMIC, 28, 65535, 0, 0,
+		"set the MTU used when using raw sockets for udp sending."
+		" This  value will be used when deciding whether or not to fragment"
+		" the packets."},
 	{"force_rport",     CFG_VAR_INT, 0, 1,  0, fix_global_req_flags,
 		"force rport for all the received messages" },
 	{"memlog",		CFG_VAR_INT|CFG_ATOMIC,	0, 0, 0, 0,
diff --git a/cfg_core.h b/cfg_core.h
index 1e86692..1c4b3e7 100644
--- a/cfg_core.h
+++ b/cfg_core.h
@@ -36,12 +36,11 @@
  * -------
  *  2007-12-03	Initial version (Miklos)
  */
-/*!
- * \file
- * \brief SIP-router core :: Core configuration
- * \ingroup core
+/** core runtime config.
+ * @file cfg_core.h
+ * @ingroup core
  *
- * Module: \ref core
+ * Module: @ref core
  */
 
 
@@ -102,6 +101,8 @@ struct cfg_group_core {
 	int max_while_loops;
 	int udp_mtu; /*!< maximum send size for udp, if > try another protocol*/
 	int udp_mtu_try_proto; /*!< if packet> udp_mtu, try proto (e.g. TCP) */
+	int udp4_raw; /* use raw sockets for sending on udp ipv 4 */
+	int udp4_raw_mtu; /* mtu used when using udp raw socket */
 	int force_rport; /*!< if set rport will always be forced*/
 	int memlog; /*!< log level for memory status/summary info */
 	int mem_summary; /*!< display memory status/summary info on exit */
diff --git a/globals.h b/globals.h
index add1f40..40f7214 100644
--- a/globals.h
+++ b/globals.h
@@ -64,6 +64,10 @@ extern struct socket_info* bind_address; /* pointer to the crt. proc.
 extern struct socket_info* sendipv4; /* ipv4 socket to use when msg.
 										comes from ipv6*/
 extern struct socket_info* sendipv6; /* same as above for ipv6 */
+#ifdef USE_RAW_SOCKS
+extern int raw_udp4_send_sock;
+#endif /* USE_RAW_SOCKS */
+
 #ifdef USE_TCP
 extern struct socket_info* sendipv4_tcp; /* ipv4 socket to use when msg.
 										comes from ipv6*/




More information about the sr-dev mailing list