Browse code

modules/outbound: Updated examples (edge proxy and registrar) in documentation

Peter Dunkley authored on 24/04/2013 20:04:24
Showing 2 changed files
... ...
@@ -112,6 +112,7 @@ children=4
112 112
 alias="example.com"
113 113
 mpath="/usr/lib64/kamailio/modules"
114 114
 tcp_connection_lifetime=30 # FLOW_TIMER + 10
115
+force_rport=yes
115 116
 
116 117
 
117 118
 ####### Modules Section ########
... ...
@@ -168,26 +169,31 @@ request_route {
168 169
                 if (is_method("INVITE|SUBSCRIBE"))
169 170
                         record_route();
170 171
 
171
-                if ($si == "REGISTRAR_IP" && $sp == "REGISTRAR_PORT") {
172
+                if (@via[2] == "") {
173
+                        # From client so route to registrar...
174
+
175
+                        if ($rU == $null) {
176
+                                sl_send_reply("484", "Address Incomplete");
177
+                                exit;
178
+                        }
179
+                        remove_hf("Route");
180
+                        $du = "sip:REGISTRAR_IP:REGISTRAR_PORT";
181
+                } else {
182
+                        # From registrar so route using "Route:" headers...
183
+
172 184
                         if (!loose_route()) {
173 185
                                 switch($rc) {
174 186
                                 case -2:
175 187
                                         sl_send_reply("403", "Forbidden");
176 188
                                         exit;
177 189
                                 default:
190
+                                        xlog("L_ERR", "in request_route\n");
178 191
                                         sl_reply_error();
179 192
                                         exit;
180 193
                                 }
181 194
                         }
182 195
 
183 196
                         t_on_failure("FAIL_OUTBOUND");
184
-                } else {
185
-                        if ($rU == $null) {
186
-                                sl_send_reply("484", "Address Incomplete");
187
-                                exit;
188
-                        }
189
-                        remove_hf("Route");
190
-                        $du = "sip:REGISTRAR_IP:REGISTRAR_PORT";
191 197
                 }
192 198
         }
193 199
 
... ...
@@ -254,30 +260,160 @@ onreply_route {
254 260
         }
255 261
 }
256 262
 
257
-failure_route[FAIL_OUTBOUND]{
263
+failure_route[FAIL_OUTBOUND] {
258 264
         if (t_branch_timeout() || !t_branch_replied()) {
259 265
                 send_reply("430", "Flow Failed");
260 266
         }
261 267
 }
262 268
 
263 269
    Example 1.2. Registrar Configuration
264
-...
270
+MAILIO
271
+#
272
+# Registrar configuration
273
+#
274
+
275
+
276
+####### Global Parameters #########
277
+
278
+debug=2
279
+log_stderror=no
280
+log_facility=LOG_LOCAL0
281
+fork=yes
282
+children=4
283
+alias="example.com"
284
+mpath="/usr/lib64/kamailio/modules"
285
+
286
+
287
+####### Modules Section ########
288
+
265 289
 loadmodule "tm.so"
266
-...
290
+loadmodule "tmx.so"
291
+loadmodule "sl.so"
292
+loadmodule "rr.so"
293
+loadmodule "pv.so"
294
+loadmodule "maxfwd.so"
295
+loadmodule "xlog.so"
296
+loadmodule "sanity.so"
297
+loadmodule "ctl.so"
298
+loadmodule "mi_rpc.so"
299
+loadmodule "mi_fifo.so"
300
+loadmodule "textops.so"
301
+loadmodule "siputils.so"
302
+loadmodule "usrloc.so"
267 303
 loadmodule "registrar.so"
268
-...
269
-modparam("tm", "contacts_avp", "tm_contacts")
304
+
305
+# ----------------- setting module-specific parameters ---------------
306
+
307
+# ----- mi_fifo params -----
308
+modparam("mi_fifo", "fifo_name", "/tmp/kamailio_fifo")
309
+
310
+
311
+# ----- tm params -----
312
+modparam("tm", "failure_reply_mode", 3)
313
+modparam("tm", "restart_fr_on_each_reply", 0)
270 314
 modparam("tm", "contact_flows_avp", "tm_contact_flows")
271
-...
315
+modparam("tm", "contacts_avp", "tm_contacts")
316
+
317
+# ----- rr params -----
318
+modparam("rr", "append_fromtag", 0)
319
+
320
+# ----- registrar params -----
272 321
 modparam("registrar", "use_path", 1)
273
-modparam("registrar", "path_mode", 2)
274
-modparam("registrar", "outbound_mode", 2)
275
-...
322
+modparam("registrar", "gruu_enabled", 1)
323
+modparam("registrar", "outbound_mode", 1)
324
+
325
+
326
+####### Routing Logic ########
327
+
328
+request_route {
329
+        route(REQINIT);
330
+
331
+        if (is_method("CANCEL")) {
332
+                if (t_check_trans()) {
333
+                        route(RELAY);
334
+                }
335
+                exit;
336
+        }
337
+
338
+        route(WITHINDLG);
339
+
340
+        t_check_trans();
341
+
342
+        remove_hf("Route");
343
+        if (is_method("INVITE|SUBSCRIBE"))
344
+                record_route();
345
+
346
+        route(REGISTRAR);
347
+
348
+        if ($rU==$null) {
349
+                xlog("L_INFO", "Address Incomplete\n");
350
+                send_reply("484","Address Incomplete");
351
+                exit;
352
+        }
353
+
354
+        route(LOCATION);
355
+}
356
+
357
+
358
+route[RELAY] {
359
+        if (!t_relay()) {
360
+                xlog("L_ERR", "t_relay() failed\n");
361
+                sl_reply_error();
362
+        }
363
+        exit;
364
+}
365
+
366
+route[REQINIT] {
367
+        if (!mf_process_maxfwd_header("10")) {
368
+                xlog("L_INFO", "Too Many Hops\n");
369
+                send_reply("483","Too Many Hops");
370
+                exit;
371
+        }
372
+
373
+        if(!sanity_check("1511", "7"))
374
+        {
375
+                xlog("Malformed SIP message from $si:$sp\n");
376
+                exit;
377
+        }
378
+}
379
+
380
+route[WITHINDLG] {
381
+        if (has_totag()) {
382
+                if (loose_route()) {
383
+                        if (is_method("NOTIFY")) {
384
+                                record_route();
385
+                        }
386
+                        route(RELAY);
387
+                } else {
388
+                        if (is_method("ACK")) {
389
+                                if (t_check_trans()) {
390
+                                        route(RELAY);
391
+                                        exit;
392
+                                } else {
393
+                                        exit;
394
+                                }
395
+                        }
396
+                        xlog("L_INFO", "Not Found");
397
+                        send_reply("404","Not Found");
398
+                }
399
+                exit;
400
+        }
401
+}
402
+
403
+route[REGISTRAR] {
404
+        if (is_method("REGISTER"))
405
+        {
406
+                if (!save("location")) {
407
+                        xlog("L_ERR", "Unable to save location\n");
408
+                        sl_reply_error();
409
+                }
410
+                exit;
411
+        }
412
+}
413
+
276 414
 route[LOCATION] {
277
-...
278 415
         if (!lookup("location")) {
279 416
                 $var(rc) = $rc;
280
-                route(TOVOICEMAIL);
281 417
                 t_newtran();
282 418
                 switch ($var(rc)) {
283 419
                         case -1:
... ...
@@ -290,35 +426,49 @@ route[LOCATION] {
290 426
                 }
291 427
         }
292 428
 
293
-        if (!t_load_contacts()) {
294
-                send_reply("500", "Server Internal Error");
429
+        if (!t_load_contacts() || !t_next_contacts()) {
430
+                xlog("L_ERR", "t_(load|next)_contacts() failed\n");
431
+                sl_reply_error();
295 432
                 exit;
296 433
         }
297 434
 
298
-        if (!t_next_contacts()) {
299
-                send_reply("500", "Server Internal Error");
300
-                exit;
301
-        }
435
+        t_on_failure("FAIL_TRANSACTION");
436
+        t_on_branch_failure("FAIL-BRANCH");
437
+        route(RELAY);
438
+        exit;
439
+}
302 440
 
303
-        t_on_failure("FAIL_OUTBOUND");
304
-...
441
+onreply_route {
442
+        if (!t_check_trans()) {
443
+                drop;
444
+        }
305 445
 }
306
-...
307
-failure_route[FAIL_OUTBOUND] {
308
-        if (t_check_status("408|430")) {
309
-                if (!t_next_contact_flows() && !t_next_contacts()) {
310
-                        send_reply("500", "Server Internal Error");
446
+
447
+failure_route[FAIL_TRANSACTION] {
448
+        if (!t_check_status("6[0-9][0-9]")) {
449
+                if (t_next_contacts()) {
450
+                        t_relay();
311 451
                         exit;
312 452
                 }
313
-        } else if (!t_next_contacts()) {
314
-                send_reply("500", "Server Internal Error");
453
+        }
454
+
455
+        if (t_check_status("430")) {
456
+                t_reply("480", "Temporarily Unavailable");
315 457
                 exit;
316 458
         }
459
+}
317 460
 
318
-        t_on_failure("FAIL_OUTBOUND");
319
-        route(RELAY);
461
+event_route[tm:branch-failure:FAIL-BRANCH] {
462
+        if (t_check_status("403|430")
463
+                        || (t_branch_timeout() && !t_branch_replied())) {
464
+                unregister("location", "$tu", "$T_reply_ruid");
465
+
466
+                if (t_next_contact_flow()) {
467
+                        t_on_branch_failure("FAIL-BRANCH");
468
+                        t_relay();
469
+                }
470
+        }
320 471
 }
321
-...
322 472
 
323 473
 2. Dependencies
324 474
 
... ...
@@ -69,6 +69,7 @@ children=4
69 69
 alias="example.com"
70 70
 mpath="/usr/lib64/kamailio/modules"
71 71
 tcp_connection_lifetime=30 # FLOW_TIMER + 10
72
+force_rport=yes
72 73
 
73 74
 
74 75
 ####### Modules Section ########
... ...
@@ -125,26 +126,31 @@ request_route {
125 126
 		if (is_method("INVITE|SUBSCRIBE"))
126 127
 			record_route();
127 128
 
128
-		if ($si == "REGISTRAR_IP" && $sp == "REGISTRAR_PORT") {
129
+		if (@via[2] == "") {
130
+			# From client so route to registrar...
131
+
132
+			if ($rU == $null) {
133
+				sl_send_reply("484", "Address Incomplete");
134
+				exit;
135
+			}
136
+			remove_hf("Route");
137
+			$du = "sip:REGISTRAR_IP:REGISTRAR_PORT";
138
+		} else {
139
+			# From registrar so route using "Route:" headers...
140
+
129 141
 			if (!loose_route()) {
130 142
 				switch($rc) {
131 143
 				case -2:
132 144
 					sl_send_reply("403", "Forbidden");
133 145
 					exit;
134 146
 				default:
147
+					xlog("L_ERR", "in request_route\n");
135 148
 					sl_reply_error();
136 149
 					exit;
137 150
 				}
138 151
 			}
139 152
 
140 153
 			t_on_failure("FAIL_OUTBOUND");
141
-		} else {
142
-			if ($rU == $null) {
143
-				sl_send_reply("484", "Address Incomplete");
144
-				exit;
145
-			}
146
-			remove_hf("Route");
147
-			$du = "sip:REGISTRAR_IP:REGISTRAR_PORT";
148 154
 		}
149 155
 	}
150 156
 
... ...
@@ -211,7 +217,7 @@ onreply_route {
211 217
 	}
212 218
 }
213 219
 
214
-failure_route[FAIL_OUTBOUND]{
220
+failure_route[FAIL_OUTBOUND] {
215 221
 	if (t_branch_timeout() || !t_branch_replied()) {
216 222
 		send_reply("430", "Flow Failed");
217 223
 	}
... ...
@@ -221,23 +227,153 @@ failure_route[FAIL_OUTBOUND]{
221 227
 	<example>
222 228
 	<title>Registrar Configuration</title>
223 229
 	<programlisting><![CDATA[
224
-...
230
+MAILIO
231
+#
232
+# Registrar configuration
233
+#
234
+
235
+
236
+####### Global Parameters #########
237
+
238
+debug=2
239
+log_stderror=no
240
+log_facility=LOG_LOCAL0
241
+fork=yes
242
+children=4
243
+alias="example.com"
244
+mpath="/usr/lib64/kamailio/modules"
245
+
246
+
247
+####### Modules Section ########
248
+
225 249
 loadmodule "tm.so"
226
-...
250
+loadmodule "tmx.so"
251
+loadmodule "sl.so"
252
+loadmodule "rr.so"
253
+loadmodule "pv.so"
254
+loadmodule "maxfwd.so"
255
+loadmodule "xlog.so"
256
+loadmodule "sanity.so"
257
+loadmodule "ctl.so"
258
+loadmodule "mi_rpc.so"
259
+loadmodule "mi_fifo.so"
260
+loadmodule "textops.so"
261
+loadmodule "siputils.so"
262
+loadmodule "usrloc.so"
227 263
 loadmodule "registrar.so"
228
-...
229
-modparam("tm", "contacts_avp", "tm_contacts")
264
+
265
+# ----------------- setting module-specific parameters ---------------
266
+
267
+# ----- mi_fifo params -----
268
+modparam("mi_fifo", "fifo_name", "/tmp/kamailio_fifo")
269
+
270
+
271
+# ----- tm params -----
272
+modparam("tm", "failure_reply_mode", 3)
273
+modparam("tm", "restart_fr_on_each_reply", 0)
230 274
 modparam("tm", "contact_flows_avp", "tm_contact_flows")
231
-...
275
+modparam("tm", "contacts_avp", "tm_contacts")
276
+
277
+# ----- rr params -----
278
+modparam("rr", "append_fromtag", 0)
279
+
280
+# ----- registrar params -----
232 281
 modparam("registrar", "use_path", 1)
233
-modparam("registrar", "path_mode", 2)
234
-modparam("registrar", "outbound_mode", 2)
235
-...
282
+modparam("registrar", "gruu_enabled", 1)
283
+modparam("registrar", "outbound_mode", 1)
284
+
285
+
286
+####### Routing Logic ########
287
+
288
+request_route {
289
+	route(REQINIT);
290
+
291
+	if (is_method("CANCEL")) {
292
+		if (t_check_trans()) {
293
+			route(RELAY);
294
+		}
295
+		exit;
296
+	}
297
+
298
+	route(WITHINDLG);
299
+
300
+	t_check_trans();
301
+
302
+	remove_hf("Route");
303
+	if (is_method("INVITE|SUBSCRIBE"))
304
+		record_route();
305
+
306
+	route(REGISTRAR);
307
+
308
+	if ($rU==$null) {
309
+		xlog("L_INFO", "Address Incomplete\n");
310
+		send_reply("484","Address Incomplete");
311
+		exit;
312
+	}
313
+
314
+	route(LOCATION);
315
+}
316
+
317
+
318
+route[RELAY] {
319
+	if (!t_relay()) {
320
+		xlog("L_ERR", "t_relay() failed\n");
321
+		sl_reply_error();
322
+	}
323
+	exit;
324
+}
325
+
326
+route[REQINIT] {
327
+	if (!mf_process_maxfwd_header("10")) {
328
+		xlog("L_INFO", "Too Many Hops\n");
329
+		send_reply("483","Too Many Hops");
330
+		exit;
331
+	}
332
+
333
+	if(!sanity_check("1511", "7"))
334
+	{
335
+		xlog("Malformed SIP message from $si:$sp\n");
336
+		exit;
337
+	}
338
+}
339
+
340
+route[WITHINDLG] {
341
+	if (has_totag()) {
342
+		if (loose_route()) {
343
+			if (is_method("NOTIFY")) {
344
+				record_route();
345
+			}
346
+			route(RELAY);
347
+		} else {
348
+			if (is_method("ACK")) {
349
+				if (t_check_trans()) {
350
+					route(RELAY);
351
+					exit;
352
+				} else {
353
+					exit;
354
+				}
355
+			}
356
+			xlog("L_INFO", "Not Found");
357
+			send_reply("404","Not Found");
358
+		}
359
+		exit;
360
+	}
361
+}
362
+
363
+route[REGISTRAR] {
364
+	if (is_method("REGISTER"))
365
+	{
366
+		if (!save("location")) {
367
+			xlog("L_ERR", "Unable to save location\n");
368
+			sl_reply_error();
369
+		}
370
+		exit;
371
+	}
372
+}
373
+
236 374
 route[LOCATION] {
237
-...
238 375
 	if (!lookup("location")) {
239 376
 		$var(rc) = $rc;
240
-		route(TOVOICEMAIL);
241 377
 		t_newtran();
242 378
 		switch ($var(rc)) {
243 379
 			case -1:
... ...
@@ -250,35 +386,49 @@ route[LOCATION] {
250 386
 		}
251 387
 	}
252 388
 
253
-	if (!t_load_contacts()) {
254
-		send_reply("500", "Server Internal Error");
389
+	if (!t_load_contacts() || !t_next_contacts()) {
390
+		xlog("L_ERR", "t_(load|next)_contacts() failed\n");
391
+		sl_reply_error();
255 392
 		exit;
256 393
 	}
257 394
 
258
-	if (!t_next_contacts()) {
259
-		send_reply("500", "Server Internal Error");
260
-		exit;
261
-	}
395
+	t_on_failure("FAIL_TRANSACTION");
396
+	t_on_branch_failure("FAIL-BRANCH");
397
+	route(RELAY);
398
+	exit;
399
+}
262 400
 
263
-	t_on_failure("FAIL_OUTBOUND");
264
-...
401
+onreply_route {
402
+	if (!t_check_trans()) {
403
+		drop;
404
+	}
265 405
 }
266
-...
267
-failure_route[FAIL_OUTBOUND] {
268
-	if (t_check_status("408|430")) {
269
-		if (!t_next_contact_flows() && !t_next_contacts()) {
270
-			send_reply("500", "Server Internal Error");
406
+
407
+failure_route[FAIL_TRANSACTION] {
408
+	if (!t_check_status("6[0-9][0-9]")) {
409
+		if (t_next_contacts()) {
410
+			t_relay();
271 411
 			exit;
272 412
 		}
273
-	} else if (!t_next_contacts()) {
274
-		send_reply("500", "Server Internal Error");
413
+	}
414
+
415
+	if (t_check_status("430")) {
416
+		t_reply("480", "Temporarily Unavailable");
275 417
 		exit;
276 418
 	}
419
+}
277 420
 
278
-	t_on_failure("FAIL_OUTBOUND");
279
-	route(RELAY);
421
+event_route[tm:branch-failure:FAIL-BRANCH] {
422
+	if (t_check_status("403|430")
423
+			|| (t_branch_timeout() && !t_branch_replied())) {
424
+		unregister("location", "$tu", "$T_reply_ruid");
425
+
426
+		if (t_next_contact_flow()) {
427
+			t_on_branch_failure("FAIL-BRANCH");
428
+			t_relay();
429
+		}
430
+	}
280 431
 }
281
-...
282 432
 ]]></programlisting>
283 433
 	</example>
284 434
 	</section>