Browse code

- fixed identation - added modified RTP-Proxy (rtpproxy.tar.gz, based on latest git, needs some cleanup) (please note, that you have to have libcurl-dev and libxmlrpc-client (same as for Kamailio-mi_xmlrpc) installed) - some simple testing files (sample config, command line parameters for pjsua (used for testing) and rtpproxy)

Carsten Bock authored on 19/08/2010 17:55:01
Showing 5 changed files
... ...
@@ -407,7 +407,7 @@ static param_export_t params[] = {
407 407
 	{"rtpproxy_disable_tout", INT_PARAM, &rtpproxy_disable_tout },
408 408
 	{"rtpproxy_retr",         INT_PARAM, &rtpproxy_retr         },
409 409
 	{"rtpproxy_tout",         INT_PARAM, &rtpproxy_tout         },
410
-	{"timeout_socket",    STR_PARAM, &timeout_socket_str.s  },
410
+	{"timeout_socket",    	  STR_PARAM, &timeout_socket_str.s  },
411 411
 	{0, 0, 0}
412 412
 };
413 413
 
414 414
new file mode 100644
... ...
@@ -0,0 +1,3 @@
1
+./pjsua-i686-pc-linux-gnu --registrar=sip:localhost --id=sip:1@localhost --realm=localhost --username=1 --password=none --local-port=15060 --null-audio --auto-answer=200
2
+
3
+./pjsua-i686-pc-linux-gnu --registrar=sip:localhost --id=sip:2@localhost --realm=localhost --username=2 --password=none --local-port=15061 --null-audio sip:1@localhost
0 4
new file mode 100644
... ...
@@ -0,0 +1 @@
1
+./rtpproxy -T 10 -f -F -i -l 195.71.4.179 -s udp:*:22222 -d DBUG
0 2
new file mode 100644
... ...
@@ -0,0 +1,359 @@
1
+#!KAMAILIO
2
+
3
+# ----------------- Error-Logging ---------------
4
+debug=2
5
+log_stderror=no
6
+#configure the /etc/syslog.conf for this feature
7
+#log_facility=LOG_LOCAL1
8
+
9
+# ----------------- Basic-Settings ---------------
10
+fork=yes
11
+children=2
12
+check_via=no
13
+dns=no
14
+rev_dns=no
15
+listen=127.0.0.1
16
+
17
+port=5060
18
+
19
+sip_warning=0
20
+
21
+############################
22
+# TCP-Support
23
+############################
24
+disable_tcp=yes
25
+
26
+disable_core_dump=yes
27
+auto_aliases=no
28
+tos=0x80
29
+
30
+# ------------------ module loading ----------------------------------
31
+mpath="/usr/local/lib/kamailio/modules_k/:/usr/local/lib/kamailio/modules/"
32
+# To Check/modufy the maximum forwards
33
+loadmodule "maxfwd.so"
34
+# Transaction-Module
35
+loadmodule "tm.so"
36
+# For Stateless replies
37
+loadmodule "sl.so"
38
+# Extended Logging
39
+loadmodule "xlog.so"
40
+# Record-/Loose-Routing-Module (RFC3261)
41
+loadmodule "rr.so"
42
+# NAT-Traversal
43
+loadmodule "nathelper.so"
44
+loadmodule "rtpproxy.so"
45
+# Generic Utilities (formerly options.so and uri.so)
46
+loadmodule "siputils.so"
47
+# MI-FIFO-Wrapper
48
+loadmodule "mi_fifo.so"
49
+# MI-XML-RPC-Wrapper
50
+loadmodule "mi_rpc.so"
51
+loadmodule "mi_xmlrpc.so"
52
+
53
+# Module for Pseudo-Variables
54
+loadmodule "pv.so"
55
+# Module for Dialog 
56
+loadmodule "dialog.so"
57
+# Sanity: Check if request is ok by syntax
58
+loadmodule "sanity.so"
59
+# Textops provides the method "is_method"
60
+loadmodule "textops.so"
61
+# UAC provides the method "uac_replace_from"
62
+loadmodule "uac.so"
63
+loadmodule "kex.so"
64
+loadmodule "tmx.so"
65
+loadmodule "usrloc.so"
66
+loadmodule "registrar.so"
67
+
68
+# ----------------- Settings for Nathelper ---------------
69
+# Nathelper: RTP-Proxy-List
70
+modparam("rtpproxy", "rtpproxy_sock", "udp:localhost:22222")
71
+# Nathelper: RTP-Proxy Timeout
72
+modparam("rtpproxy", "rtpproxy_tout", 3)
73
+modparam("rtpproxy", "timeout_socket", "http://localhost:8000/RPC2")
74
+
75
+# ----------------- Settings for max-fwd ---------------
76
+# Max-Forward-Module: Set the maximum to 20
77
+modparam("maxfwd", "max_limit", 20)
78
+
79
+# ----------------- Settings for rr ---------------
80
+# RR Module: Enable the From-Tag in RR-Header
81
+modparam("rr", "append_fromtag", 1)
82
+
83
+# ----------------- Settings for mi_fifo-Wrapper ---------------
84
+modparam("mi_fifo", "fifo_name", "/tmp/kamailio_fifo")
85
+
86
+# ----------------- Settings for mi_XML_RPC ---------------
87
+# The Port for incoming XML-RPC requests
88
+modparam("mi_xmlrpc", "port", 8000)
89
+# Method-Response: A single string parameter should be replied.
90
+# See: http://www.openser.org/docs/modules/1.2.x/mi_xmlrpc.html#AEN102
91
+modparam("mi_xmlrpc", "reply_option", 1)
92
+# The size of the Buffer used to create the XML-RPC-Request-Node
93
+modparam("mi_xmlrpc", "buffer_size",  8192)
94
+# The logfile for the xml-rpc server 
95
+# #modparam("mi_xmlrpc", "log_file", "/tmp/openser_xmlrpc")
96
+
97
+# ----------------- Settings for Dialog-Module ---------------
98
+# The Name of the Tag in the RR-Route-Header (default "did")
99
+modparam("dialog", "rr_param", "rtp")
100
+# Flag to be used for marking if a dialog should be constructed for the current request (make sense only for initial requests).
101
+modparam("dialog", "dlg_flag", 1)
102
+# The default dialog timeout (in seconds) if no custom one is set. Default value is "43200 (12 hours)".
103
+modparam("dialog", "default_timeout", 7230)
104
+
105
+# How the seqential requests should be matched against the known dialogs.
106
+# The modes are a combination between matching based on a cookie (DID) stored as cookie in Record-Route header and the matching based on SIP elements (as in RFC3261).
107
+# The supported modes are:
108
+# 0 - DID_ONLY - the match is done exclusivly based on DID (default);
109
+# 1 - DID_FALLBACK - the match is first tried based on DID and if not present, it will fallback to SIP matching;
110
+# 2 - DID_NONE - the match is done exclusivly based on SIP elements; no DID information is added in RR.
111
+modparam("dialog", "dlg_match_mode", 1)
112
+# Describe how to push into the DB the dialogs' information from memory.
113
+# The supported modes are:
114
+# 0 - NO_DB - the memory content is not flushed into DB;
115
+# 1 - REALTIME - any dialog information changes will be reflected into the database immediatly.
116
+# 2 - DELAYED - the dialog information changes will be flushed into DB periodically, based on a timre routine.
117
+modparam("dialog", "db_mode", 0)
118
+# The interval (seconds) at which to update dialogs' information if you chose to store the dialogs' info at a given interval.
119
+# A too short interval will generate intensiv database operations, a too large one will not notice short dialogs.
120
+# Default value is "60".
121
+# modparam("dialog", "db_update_period", 100)
122
+# The number of dialogs to be fetched per loop
123
+#modparam("dialog", "db_fetch_rows", 120)
124
+
125
+modparam("registrar", "max_expires", 60);
126
+modparam("registrar", "received_avp", "$avp(i:100)");
127
+modparam("nathelper", "received_avp", "$avp(i:100)");
128
+
129
+route {
130
+	if (!is_method("REGISTER"))
131
+		xlog("L_ERR", "$rm from $fU to $rU ($ci)\n");
132
+	route(1);
133
+	
134
+	##################################################################################################################
135
+	# Subsequential requests
136
+	###############################################################################################################
137
+	if (has_totag() && !is_method("REGISTER")) {
138
+		route(2);
139
+	}
140
+
141
+	##################################################################################################################
142
+	# Record-Route, damit alle Nachrichten ueber diesen SIP-Proxy laufen
143
+	###############################################################################################################
144
+	if (!is_method("REGISTER|MESSAGE")) record_route();
145
+
146
+	if (loose_route()) {
147
+		# This is not from a proxy, decline the request. This is not allowed.
148
+		log(1, "Preloaded Route, not to ourselfs\n");
149
+		if (!is_method("ACK")) send_reply("403", "Preload Route denied");
150
+		exit;
151
+	}
152
+
153
+	##################################################################################################################
154
+	# BYE and ACK Requests should always have an To-Tag, if they follow RFC
155
+	###############################################################################################################
156
+	if (is_method("BYE")) {
157
+		send_reply("400", "Missing to-tag");
158
+		exit;
159
+	}
160
+	if (is_method("ACK")) {
161
+		exit;		
162
+	}
163
+
164
+	##################################################################################################################
165
+	# We only allow INVITE's towards the Class IV, no other methods allowed:
166
+	# RFC: 21.4.6 405 Method Not Allowed
167
+	# The method specified in the Request-Line is understood, but not allowed for the address identified by the Request-URI.
168
+	###############################################################################################################
169
+	if (is_method("REGISTER")) {
170
+		fix_nated_register();
171
+		save("location");
172
+		exit;
173
+	}
174
+
175
+
176
+	##################################################################################################################
177
+	# We only allow INVITE's towards the Class IV, no other methods allowed:
178
+	# RFC: 21.4.6 405 Method Not Allowed
179
+	# The method specified in the Request-Line is understood, but not allowed for the address identified by the Request-URI.
180
+	###############################################################################################################
181
+	if (!is_method("INVITE")) {
182
+		send_reply("405", "Method Not Allowed");
183
+		exit;
184
+	}
185
+	fix_nated_contact();
186
+
187
+	if (!lookup("location")) {
188
+		send_reply("404", "Not found");
189
+		exit;
190
+	}
191
+
192
+	##################################################################################################################
193
+	# The dialog module should be aware of this dialog:
194
+	###############################################################################################################
195
+	setflag(1);
196
+
197
+	##################################################################################################################
198
+	# Use RTP-Proxy
199
+	###############################################################################################################
200
+	if (!force_rtp_proxy("arf")) {
201
+		sl_send_reply("503", "No RTP-Relay available");
202
+		exit;
203
+	}
204
+	t_on_reply("1");
205
+
206
+	# Relay this statefully
207
+	t_relay();
208
+
209
+	exit;	
210
+}
211
+
212
+##################################################################################################################
213
+# Route for standard-checks (e. g. too many hops, re-transmits, CANCEL without a transaction)
214
+###############################################################################################################
215
+route[1] {
216
+	##################################################################################################################
217
+	# Sanity: Check if the syntax of the request is ok
218
+	# The following checks are available:
219
+	#
220
+	# * ruri sip version - (1) - checks if the SIP version in the request URI is supported, currently only 2.0.
221
+	# * ruri scheme - (2) - checks if the URI scheme of the request URI is supported (sip[s]|tel[s]) by Kamailio.
222
+	# * required headers - (4) -checks if the minimum set of required headers to, from, cseq, callid and via is 
223
+	#	present in the request.
224
+	# * via sip version - (8) - not working because parser fails already when another version then 2.0 is present.
225
+	# * via protocol - (16) - not working because parser fails already if an unsupported transport is present.
226
+	# * cseq method - (32) - checks if the method from the cseq header is equal to the request method.
227
+	# * cseq value - (64) - checks if the number in the cseq header is a valid unsigend integer.
228
+	# * content length - (128) - checks if the size of the body matches with the value from the content length header.
229
+	# * expires value - (256) - checks if the value of the expires header is a valid unsigned integer.
230
+	# * proxy require - (512) - checks if all items of the proxy require header are present in the list of the
231
+	#	extensions from the module parameter proxy_require.
232
+	# * parse uri's - (1024) - checks if the specified URIs are present and parseable by the Kamailio parsers
233
+	# * digest credentials (2048) Check all instances of digest credentials in a message. The test checks whether
234
+	#	there are all required digest parameters and have meaningful values. 
235
+	###############################################################################################################
236
+	if (is_method("INVITE")) {
237
+		# Checks: 1, 2, 4, 32, 64, 128, 1024 (with all URI's)
238
+		if (!sanity_check("1255")) {
239
+			xlog("malformed message from $si:$sp ($rm)\n");
240
+			exit;
241
+		}	
242
+	} else if (is_method("REGISTER")) {
243
+		# Checks: 1, 2, 4, 32, 64, 256, 1024 (with all URI's)
244
+		if (!sanity_check("1383")) {
245
+			xlog("malformed message from $si:$sp ($rm)\n");
246
+			exit;
247
+		}	
248
+	}
249
+
250
+	##################################################################################################################
251
+	# Check for too many hops
252
+	###############################################################################################################
253
+	if (!mf_process_maxfwd_header("20")) {
254
+	 	if (!is_method("ACK")) send_reply("483","To Many Hops");
255
+	 	exit;
256
+	};
257
+	
258
+	##################################################################################################################
259
+	# Standard-Options-Requests beantworten
260
+	###############################################################################################################
261
+	# xlog("L_ERR", "$rm $ru ($rU)\n");
262
+	if (is_method("OPTIONS")) {
263
+		# xlog("L_ERR", "$$rU not set or ping: $rU\n");
264
+		options_reply();
265
+		exit;
266
+	}	
267
+
268
+	##################################################################################################################
269
+	# Check for Re-Transmissions (nicht bei ACK/CANCEL)
270
+	###############################################################################################################
271
+	if (!is_method("CANCEL|ACK|PRACK")) {
272
+		if (t_check_trans()) {
273
+			# log(1, "Re-Transmission detected, message dropped.\n");
274
+			# Drop the message silently.
275
+			exit;
276
+		}
277
+	}
278
+
279
+	##################################################################################################################
280
+	# CANCEL without Transaction? Drop it. Otherwise: relay them.
281
+	###############################################################################################################
282
+	if (is_method("CANCEL")) {
283
+		# In case the INVITE is not finally processed (and so no TA is available), the SIP-UA must re-transmit.
284
+		if (!t_check_trans()) {
285
+			# No according transaction exists, just relay the cancel.
286
+			if (!forward()) {
287
+				xlog("L_ERR", "Unable to forward $rm $ru\n"); 
288
+			}
289
+			exit;
290
+		}
291
+		# There is a Transaction for this CANCEL
292
+		if (!t_relay()) {
293
+			exit;
294
+		}
295
+		exit;
296
+	}
297
+}
298
+
299
+##################################################################################################################
300
+# Route processing subsequential requests
301
+###############################################################################################################
302
+route[2] {
303
+	##################################################################################################################
304
+	# Record-Route, damit alle Nachrichten �ber diesen SIP-Proxy laufen
305
+	###############################################################################################################
306
+	if (!is_method("MESSAGE")) record_route();
307
+	
308
+	##################################################################################################################
309
+	# Loose-Routing (RFC3261)
310
+	###############################################################################################################
311
+	# Record-Route-Header entfernen
312
+	if (!loose_route()) {
313
+		##################################################################################################################
314
+		# Non loose, but stateful ACK: Relay.
315
+		###############################################################################################################
316
+		if (is_method("ACK") && (!t_check_trans())) {
317
+			forward();
318
+			exit;
319
+		}
320
+	}
321
+		
322
+	##################################################################################################################
323
+	# Retrieve NAT-Information from URI
324
+	# + NAT-Handling
325
+	###############################################################################################################
326
+	t_on_reply("1");
327
+
328
+	# This is a BYE? Tear down session on the RTP-Proxy.
329
+	if (is_method("BYE")) {
330
+		xlog("L_ERR", "RTP-Statistic: $rtpstat\n");
331
+		unforce_rtp_proxy();
332
+	}
333
+
334
+	# Relay this statefully
335
+	t_relay();
336
+	# Exit here.
337
+	exit;	
338
+}
339
+
340
+##################################################################################################################
341
+# Antwort-Route (Nathelper/RTP-Proxy)
342
+###############################################################################################################
343
+onreply_route[1] {	
344
+	# A Transaction from a NATed Client to a NATed Client? Use the RTP-Proxy!
345
+	if (status=~"(180)|(183)|(2[0-9][0-9])") {
346
+		fix_nated_contact();
347
+		# Content-Length prüfen
348
+		if (!search("^Content-Length:[ ]*0")) {
349
+			force_rtp_proxy("arf");
350
+                }
351
+        }
352
+}
353
+
354
+#route[XMLRPC]{
355
+#	if search("^User-Agent:.*xmlrpclib"))
356
+#		set_reply_close();
357
+#	set_reply_no_connect(); # optional
358
+#	dispatch_rpc();
359
+#}
0 360
new file mode 100644
1 361
Binary files /dev/null and b/modules_k/rtpproxy/test/rtpproxy.tar.gz differ