Browse code

examples: added outbound edge proxy and registrar example configurations

Peter Dunkley authored on 24/04/2013 20:06:36
Showing 2 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,172 @@
1
+#!KAMAILIO
2
+#
3
+# Edge proxy configuration
4
+#
5
+
6
+#!substdef "!REGISTRAR_IP!a.b.c.d!g"
7
+#!substdef "!REGISTRAR_PORT!5060!g"
8
+#!substdef "!FLOW_TIMER!20!g"
9
+
10
+####### Global Parameters #########
11
+
12
+debug=2
13
+log_stderror=no
14
+log_facility=LOG_LOCAL0
15
+fork=yes
16
+children=4
17
+alias="example.com"
18
+mpath="/usr/lib64/kamailio/modules"
19
+tcp_connection_lifetime=30 # FLOW_TIMER + 10
20
+force_rport=yes
21
+
22
+
23
+####### Modules Section ########
24
+
25
+loadmodule "tm.so"
26
+loadmodule "sl.so"
27
+loadmodule "outbound.so"
28
+loadmodule "rr.so"
29
+loadmodule "path.so"
30
+loadmodule "pv.so"
31
+loadmodule "maxfwd.so"
32
+loadmodule "xlog.so"
33
+loadmodule "sanity.so"
34
+loadmodule "ctl.so"
35
+loadmodule "mi_rpc.so"
36
+loadmodule "mi_fifo.so"
37
+loadmodule "textops.so"
38
+loadmodule "siputils.so"
39
+loadmodule "stun.so"
40
+
41
+# ----------------- setting module-specific parameters ---------------
42
+
43
+# ----- mi_fifo params -----
44
+modparam("mi_fifo", "fifo_name", "/tmp/kamailio_fifo")
45
+
46
+# ----- tm params -----
47
+modparam("tm", "failure_reply_mode", 3)
48
+
49
+# ----- rr params -----
50
+modparam("rr", "append_fromtag", 0)
51
+
52
+
53
+####### Routing Logic ########
54
+
55
+request_route {
56
+	route(REQINIT);
57
+
58
+	if (is_method("CANCEL")) {
59
+		if (t_check_trans()) {
60
+			route(RELAY);
61
+		}
62
+		exit;
63
+	}
64
+
65
+	route(WITHINDLG);
66
+
67
+	t_check_trans();
68
+
69
+	if (is_method("REGISTER")) {
70
+		remove_hf("Route");
71
+		add_path();
72
+		$du = "sip:REGISTRAR_IP:REGISTRAR_PORT";
73
+	} else {
74
+		if (is_method("INVITE|SUBSCRIBE"))
75
+			record_route();
76
+
77
+		if (@via[2] == "") {
78
+			# From client so route to registrar...
79
+
80
+			if ($rU == $null) {
81
+				sl_send_reply("484", "Address Incomplete");
82
+				exit;
83
+			}
84
+			remove_hf("Route");
85
+			$du = "sip:REGISTRAR_IP:REGISTRAR_PORT";
86
+		} else {
87
+			# From registrar so route using "Route:" headers...
88
+
89
+			if (!loose_route()) {
90
+				switch($rc) {
91
+				case -2:
92
+					sl_send_reply("403", "Forbidden");
93
+					exit;
94
+				default:
95
+					xlog("L_ERR", "in request_route\n");
96
+					sl_reply_error();
97
+					exit;
98
+				}
99
+			}
100
+
101
+			t_on_failure("FAIL_OUTBOUND");
102
+		}
103
+	}
104
+
105
+	route(RELAY);
106
+}
107
+
108
+route[RELAY] {
109
+	if (!t_relay()) {
110
+		sl_reply_error();
111
+	}
112
+	exit;
113
+}
114
+
115
+route[REQINIT] {
116
+	if (!mf_process_maxfwd_header("10")) {
117
+		sl_send_reply("483","Too Many Hops");
118
+		exit;
119
+	}
120
+
121
+	if(!sanity_check("1511", "7"))
122
+	{
123
+		xlog("Malformed SIP message from $si:$sp\n");
124
+		exit;
125
+	}
126
+}
127
+
128
+route[WITHINDLG] {
129
+	if (has_totag()) {
130
+		if (!loose_route()) {
131
+			switch($rc) {
132
+			case -2:
133
+				sl_send_reply("403", "Forbidden");
134
+				exit;
135
+			default:
136
+				if (is_method("ACK")) {
137
+					if ( t_check_trans() ) {
138
+						route(RELAY);
139
+						exit;
140
+					} else {
141
+						exit;
142
+					}
143
+				}
144
+				sl_send_reply("404","Not Found");
145
+			}
146
+		} else {
147
+			if (is_method("NOTIFY")) {
148
+				record_route();
149
+			}
150
+			route(RELAY);
151
+		}
152
+		exit;
153
+	}
154
+}
155
+
156
+onreply_route {
157
+	if (!t_check_trans()) {
158
+		drop;
159
+	}
160
+
161
+	if ($rm == "REGISTER" && $rs >= 200 && $rs <= 299) {
162
+		remove_hf("Flow-Timer");
163
+		if ($(hdr(Require)[*])=~"outbound")
164
+			insert_hf("Flow-Timer: FLOW_TIMER\r\n", "Call-ID");
165
+	}
166
+}
167
+
168
+failure_route[FAIL_OUTBOUND] {
169
+	if (t_branch_timeout() || !t_branch_replied()) {
170
+		send_reply("430", "Flow Failed");
171
+	}
172
+}
0 173
new file mode 100644
... ...
@@ -0,0 +1,202 @@
1
+#!KAMAILIO
2
+#
3
+# Registrar configuration
4
+#
5
+
6
+
7
+####### Global Parameters #########
8
+
9
+debug=2
10
+log_stderror=no
11
+log_facility=LOG_LOCAL0
12
+fork=yes
13
+children=4
14
+alias="example.com"
15
+mpath="/usr/lib64/kamailio/modules"
16
+
17
+
18
+####### Modules Section ########
19
+
20
+loadmodule "tm.so"
21
+loadmodule "tmx.so"
22
+loadmodule "sl.so"
23
+loadmodule "rr.so"
24
+loadmodule "pv.so"
25
+loadmodule "maxfwd.so"
26
+loadmodule "xlog.so"
27
+loadmodule "sanity.so"
28
+loadmodule "ctl.so"
29
+loadmodule "mi_rpc.so"
30
+loadmodule "mi_fifo.so"
31
+loadmodule "textops.so"
32
+loadmodule "siputils.so"
33
+loadmodule "usrloc.so"
34
+loadmodule "registrar.so"
35
+
36
+# ----------------- setting module-specific parameters ---------------
37
+
38
+# ----- mi_fifo params -----
39
+modparam("mi_fifo", "fifo_name", "/tmp/kamailio_fifo")
40
+
41
+
42
+# ----- tm params -----
43
+modparam("tm", "failure_reply_mode", 3)
44
+modparam("tm", "restart_fr_on_each_reply", 0)
45
+modparam("tm", "contact_flows_avp", "tm_contact_flows")
46
+modparam("tm", "contacts_avp", "tm_contacts")
47
+
48
+# ----- rr params -----
49
+modparam("rr", "append_fromtag", 0)
50
+
51
+# ----- registrar params -----
52
+modparam("registrar", "use_path", 1)
53
+modparam("registrar", "gruu_enabled", 1)
54
+modparam("registrar", "outbound_mode", 1)
55
+
56
+
57
+####### Routing Logic ########
58
+
59
+request_route {
60
+	route(REQINIT);
61
+
62
+	if (is_method("CANCEL")) {
63
+		if (t_check_trans()) {
64
+			route(RELAY);
65
+		}
66
+		exit;
67
+	}
68
+
69
+	route(WITHINDLG);
70
+
71
+	t_check_trans();
72
+
73
+	remove_hf("Route");
74
+	if (is_method("INVITE|SUBSCRIBE"))
75
+		record_route();
76
+
77
+	route(REGISTRAR);
78
+
79
+	if ($rU==$null) {
80
+		xlog("L_INFO", "Address Incomplete\n");
81
+		send_reply("484","Address Incomplete");
82
+		exit;
83
+	}
84
+
85
+	route(LOCATION);
86
+}
87
+
88
+
89
+route[RELAY] {
90
+	if (!t_relay()) {
91
+		xlog("L_ERR", "t_relay() failed\n");
92
+		sl_reply_error();
93
+	}
94
+	exit;
95
+}
96
+
97
+route[REQINIT] {
98
+	if (!mf_process_maxfwd_header("10")) {
99
+		xlog("L_INFO", "Too Many Hops\n");
100
+		send_reply("483","Too Many Hops");
101
+		exit;
102
+	}
103
+
104
+	if(!sanity_check("1511", "7"))
105
+	{
106
+		xlog("Malformed SIP message from $si:$sp\n");
107
+		exit;
108
+	}
109
+}
110
+
111
+route[WITHINDLG] {
112
+	if (has_totag()) {
113
+		if (loose_route()) {
114
+			if (is_method("NOTIFY")) {
115
+				record_route();
116
+			}
117
+			route(RELAY);
118
+		} else {
119
+			if (is_method("ACK")) {
120
+				if (t_check_trans()) {
121
+					route(RELAY);
122
+					exit;
123
+				} else {
124
+					exit;
125
+				}
126
+			}
127
+			xlog("L_INFO", "Not Found");
128
+			send_reply("404","Not Found");
129
+		}
130
+		exit;
131
+	}
132
+}
133
+
134
+route[REGISTRAR] {
135
+	if (is_method("REGISTER"))
136
+	{
137
+		if (!save("location")) {
138
+			xlog("L_ERR", "Unable to save location\n");
139
+			sl_reply_error();
140
+		}
141
+		exit;
142
+	}
143
+}
144
+
145
+route[LOCATION] {
146
+	if (!lookup("location")) {
147
+		$var(rc) = $rc;
148
+		t_newtran();
149
+		switch ($var(rc)) {
150
+			case -1:
151
+			case -3:
152
+				send_reply("404", "Not Found");
153
+				exit;
154
+			case -2:
155
+				send_reply("405", "Method Not Allowed");
156
+				exit;
157
+		}
158
+	}
159
+
160
+	if (!t_load_contacts() || !t_next_contacts()) {
161
+		xlog("L_ERR", "t_(load|next)_contacts() failed\n");
162
+		sl_reply_error();
163
+		exit;
164
+	}
165
+
166
+	t_on_failure("FAIL_TRANSACTION");
167
+	t_on_branch_failure("FAIL-BRANCH");
168
+	route(RELAY);
169
+	exit;
170
+}
171
+
172
+onreply_route {
173
+	if (!t_check_trans()) {
174
+		drop;
175
+	}
176
+}
177
+
178
+failure_route[FAIL_TRANSACTION] {
179
+	if (!t_check_status("6[0-9][0-9]")) {
180
+		if (t_next_contacts()) {
181
+			t_relay();
182
+			exit;
183
+		}
184
+	}
185
+
186
+	if (t_check_status("430")) {
187
+		t_reply("480", "Temporarily Unavailable");
188
+		exit;
189
+	}
190
+}
191
+
192
+event_route[tm:branch-failure:FAIL-BRANCH] {
193
+	if (t_check_status("403|430")
194
+			|| (t_branch_timeout() && !t_branch_replied())) {
195
+		unregister("location", "$tu", "$T_reply_ruid");
196
+
197
+		if (t_next_contact_flow()) {
198
+			t_on_branch_failure("FAIL-BRANCH");
199
+			t_relay();
200
+		}
201
+	}
202
+}