Explorar el Código

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
Andrei Pelinescu-Onciul hace 15 años
padre
commit
1db67b9277
Se han modificado 3 ficheros con 62 adiciones y 15 borrados
  1. 52 10
      cfg_core.c
  2. 6 5
      cfg_core.h
  3. 4 0
      globals.h

+ 52 - 10
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,

+ 6 - 5
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 */

+ 4 - 0
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*/