Browse code

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 authored on 15/06/2010 14:31:16
Showing 3 changed files
... ...
@@ -24,16 +24,15 @@
24 24
  *  2007-12-03	Initial version (Miklos)
25 25
  *  2008-01-31  added DNS resolver parameters (Miklos)
26 26
  */
27
-/*!
28
- * \file
29
- * \brief SIP-router core ::  Core configuration parser
30
- * \ingroup core
31
- * Module: \ref core
27
+/** core runtime config.
28
+ * @file cfg_core.c
29
+ * @ingroup core
30
+ * Module: @ref core
32 31
  *
33
- * See 
34
- * - \ref ConfigCoreDoc
35
- * - \ref ConfigEngine
36
- * - \ref cfg_core.h
32
+ * See
33
+ * - @ref ConfigCoreDoc
34
+ * - @ref ConfigEngine
35
+ * - @ref cfg_core.h
37 36
  */
38 37
 /*!
39 38
  * \page ConfigCoreDoc Documentation of configuration parser
... ...
@@ -112,6 +111,8 @@ struct cfg_group_core default_core_cfg = {
112 112
 	DEFAULT_MAX_WHILE_LOOPS, /*!< max_while_loops */
113 113
 	0, /*!< udp_mtu (disabled by default) */
114 114
 	0, /*!< udp_mtu_try_proto -> default disabled */
115
+	0, /**< udp4_raw (disabled by default) */
116
+	1500, /**< udp4_raw_mtu (1500 by default) */
115 117
 	0,  /*!< force_rport */
116 118
 	L_DBG, /*!< memlog */
117 119
 	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 = {
119 119
 
120 120
 void	*core_cfg = &default_core_cfg;
121 121
 
122
+
123
+static int check_raw_sock_support(void* cfg_h, str* gname, str* name,
124
+									void** v)
125
+{
126
+	int val;
127
+	
128
+	val = (int)(long)(*v);
129
+#ifndef USE_RAW_SOCKS
130
+	if (val > 0) {
131
+		ERR("no RAW_SOCKS support, please recompile with it enabled\n");
132
+		return -1;
133
+	}
134
+	return 0;
135
+#else /* USE_RAW_SOCKS */
136
+	if (raw_udp4_send_sock < 0) {
137
+		if (val > 0) {
138
+			ERR("could not intialize raw socket on startup, please "
139
+					"restart as root or with CAP_NET_RAW\n");
140
+			return -1;
141
+		} else if (val < 0) {
142
+			/* auto and no socket => disable */
143
+			*v = (void*)(long)0;
144
+		}
145
+	} else if (val < 0) {
146
+		/* auto and socket => enable */
147
+		*v = (void*)(long)1;
148
+	}
149
+	return 0;
150
+#endif /* USE_RAW_SOCKS */
151
+}
152
+
153
+
154
+
122 155
 cfg_def_t core_cfg_def[] = {
123 156
 	{"debug",		CFG_VAR_INT|CFG_ATOMIC,	0, 0, 0, 0,
124 157
 		"debug level"},
... ...
@@ -177,7 +211,8 @@ cfg_def_t core_cfg_def[] = {
177 177
 	{"dns_search_full_match",	CFG_VAR_INT,	0, 1, 0, 0,
178 178
 		"enable/disable domain name checks against the search list "
179 179
 		"in DNS answers"},
180
-	{"dns_reinit",		CFG_VAR_INT|CFG_INPUT_INT,	1, 1, dns_reinit_fixup, resolv_reinit,
180
+	{"dns_reinit",		CFG_VAR_INT|CFG_INPUT_INT,	1, 1, dns_reinit_fixup,
181
+		resolv_reinit,
181 182
 		"set to 1 in order to reinitialize the DNS resolver"},
182 183
 	/* DNS cache */
183 184
 #ifdef USE_DNS_CACHE
... ...
@@ -222,6 +257,13 @@ cfg_def_t core_cfg_def[] = {
222 222
 			" exceeds udp_mtu"},
223 223
 	{"udp_mtu_try_proto", CFG_VAR_INT, 1, 4, 0, fix_global_req_flags,
224 224
 		"if send size > udp_mtu use proto (1 udp, 2 tcp, 3 tls, 4 sctp)"},
225
+	{"udp4_raw", CFG_VAR_INT | CFG_ATOMIC, -1, 1, check_raw_sock_support, 0,
226
+		"enable/disable using a raw socket for sending UDP IPV4 packets."
227
+		" Should be  faster on multi-CPU linux running machines."},
228
+	{"udp4_raw_mtu", CFG_VAR_INT | CFG_ATOMIC, 28, 65535, 0, 0,
229
+		"set the MTU used when using raw sockets for udp sending."
230
+		" This  value will be used when deciding whether or not to fragment"
231
+		" the packets."},
225 232
 	{"force_rport",     CFG_VAR_INT, 0, 1,  0, fix_global_req_flags,
226 233
 		"force rport for all the received messages" },
227 234
 	{"memlog",		CFG_VAR_INT|CFG_ATOMIC,	0, 0, 0, 0,
... ...
@@ -36,12 +36,11 @@
36 36
  * -------
37 37
  *  2007-12-03	Initial version (Miklos)
38 38
  */
39
-/*!
40
- * \file
41
- * \brief SIP-router core :: Core configuration
42
- * \ingroup core
39
+/** core runtime config.
40
+ * @file cfg_core.h
41
+ * @ingroup core
43 42
  *
44
- * Module: \ref core
43
+ * Module: @ref core
45 44
  */
46 45
 
47 46
 
... ...
@@ -102,6 +101,8 @@ struct cfg_group_core {
102 102
 	int max_while_loops;
103 103
 	int udp_mtu; /*!< maximum send size for udp, if > try another protocol*/
104 104
 	int udp_mtu_try_proto; /*!< if packet> udp_mtu, try proto (e.g. TCP) */
105
+	int udp4_raw; /* use raw sockets for sending on udp ipv 4 */
106
+	int udp4_raw_mtu; /* mtu used when using udp raw socket */
105 107
 	int force_rport; /*!< if set rport will always be forced*/
106 108
 	int memlog; /*!< log level for memory status/summary info */
107 109
 	int mem_summary; /*!< display memory status/summary info on exit */
... ...
@@ -64,6 +64,10 @@ extern struct socket_info* bind_address; /* pointer to the crt. proc.
64 64
 extern struct socket_info* sendipv4; /* ipv4 socket to use when msg.
65 65
 										comes from ipv6*/
66 66
 extern struct socket_info* sendipv6; /* same as above for ipv6 */
67
+#ifdef USE_RAW_SOCKS
68
+extern int raw_udp4_send_sock;
69
+#endif /* USE_RAW_SOCKS */
70
+
67 71
 #ifdef USE_TCP
68 72
 extern struct socket_info* sendipv4_tcp; /* ipv4 socket to use when msg.
69 73
 										comes from ipv6*/