Browse code

modules/outbound: updated edge proxy example in README

Peter Dunkley authored on 29/03/2013 01:08:02
Showing 2 changed files
... ...
@@ -99,61 +99,126 @@ make all
99 99
    “tcp_connection_lifetime”.
100 100
 
101 101
    Example 1.2. Edge Proxy Configuration
102
-...
103
-#!define FLOW_TIMER     20
104
-...
105
-tcp_connection_lifetime=FLOW_TIMER+10
106
-...
107
-loadmodule "websocket.so"
102
+#!KAMAILIO
103
+#
104
+# Edge proxy configuration
105
+#
106
+
107
+#!subst "/REGISTRAR_IP/192.168.122.3/"
108
+#!subst "/REGISTRAR_PORT/5060/"
109
+#!substdef "/FLOW_TIMER/20/"
110
+
111
+####### Global Parameters #########
112
+
113
+debug=2
114
+log_stderror=no
115
+log_facility=LOG_LOCAL0
116
+fork=yes
117
+children=4
118
+alias="example.com"
119
+mpath="/usr/lib64/kamailio/modules"
120
+tcp_connection_lifetime=30 # FLOW_TIMER + 10
121
+
122
+
123
+####### Modules Section ########
124
+
125
+loadmodule "tm.so"
126
+loadmodule "sl.so"
108 127
 loadmodule "outbound.so"
109 128
 loadmodule "rr.so"
110 129
 loadmodule "path.so"
111
-...
112
-modparam("websocket", "keepalive_timeout", FLOW_TIMER+5)
113
-...
114
-route {
115
-        route(REQINIT);
116
-        ...
117
-        t_check_trans();
130
+loadmodule "pv.so"
131
+loadmodule "maxfwd.so"
132
+loadmodule "xlog.so"
133
+loadmodule "sanity.so"
134
+loadmodule "ctl.so"
135
+loadmodule "mi_rpc.so"
136
+loadmodule "mi_fifo.so"
137
+loadmodule "textops.so"
138
+loadmodule "siputils.so"
118 139
 
119
-        if (is_method("INVITE|SUBSCRIBE")) {
120
-                record_route();
140
+# ----------------- setting module-specific parameters ---------------
121 141
 
122
-                if ($rU==$null) {
123
-                        sl_send_reply("484", "Address Incomplete");
124
-                        exit;
125
-                }
142
+# ----- mi_fifo params -----
143
+modparam("mi_fifo", "fifo_name", "/tmp/kamailio_fifo")
126 144
 
127
-                if (!loose_route()) {
128
-                        switch($rc) {
129
-                        case -2:
130
-                                # Flow-token has been tampered with
131
-                                sl_send_reply("403", "Forbidden");
132
-                                exit;
133
-                        case -1:
134
-                                # Handle -1 here if all dialog forming requests
135
-                                # must be outbound routed
136
-                        }
145
+# ----- tm params -----
146
+modparam("tm", "failure_reply_mode", 3)
147
+
148
+# ----- rr params -----
149
+modparam("rr", "append_fromtag", 0)
150
+
151
+
152
+####### Routing Logic ########
153
+
154
+request_route {
155
+        route(REQINIT);
156
+
157
+        if (is_method("CANCEL")) {
158
+                if (t_check_trans()) {
159
+                        route(RELAY);
137 160
                 }
161
+                exit;
162
+        }
138 163
 
139
-                t_on_failure("FAIL_OUTBOUND");
140
-                route(RELAY);
141
-        } else if (is_method("REGISTER")) {
164
+        route(WITHINDLG);
165
+
166
+        t_check_trans();
167
+
168
+        if (is_method("REGISTER")) {
169
+                remove_hf("Route");
142 170
                 add_path();
143
-                if (!t_relay("### Registrar ###")) {
144
-                        sl_reply_error();
171
+                $du = "sip:REGISTRAR_IP:REGISTRAR_PORT";
172
+        } else {
173
+                if (is_method("INVITE|SUBSCRIBE"))
174
+                        record_route();
175
+
176
+                if ($si == "REGISTRAR_IP" && $sp == "REGISTRAR_PORT") {
177
+                        if (!loose_route()) {
178
+                                switch($rc) {
179
+                                case -2:
180
+                                        sl_send_reply("403", "Forbidden");
181
+                                        exit;
182
+                                default:
183
+                                        sl_reply_error();
184
+                                        exit;
185
+                                }
186
+                        }
187
+
188
+                        t_on_failure("FAIL_OUTBOUND");
189
+                } else {
190
+                        if ($rU == $null) {
191
+                                sl_send_reply("484", "Address Incomplete");
192
+                                exit;
193
+                        }
194
+                        remove_hf("Route");
195
+                        $du = "sip:REGISTRAR_IP:REGISTRAR_PORT";
145 196
                 }
146
-                exit;
147 197
         }
198
+
199
+        route(RELAY);
148 200
 }
149 201
 
150 202
 route[RELAY] {
151 203
         if (!t_relay()) {
152
-                sl_send_reply("430", "Flow Failed");
204
+                sl_reply_error();
153 205
         }
154 206
         exit;
155 207
 }
156
-...
208
+
209
+route[REQINIT] {
210
+        if (!mf_process_maxfwd_header("10")) {
211
+                sl_send_reply("483","Too Many Hops");
212
+                exit;
213
+        }
214
+
215
+        if(!sanity_check("1511", "7"))
216
+        {
217
+                xlog("Malformed SIP message from $si:$sp\n");
218
+                exit;
219
+        }
220
+}
221
+
157 222
 route[WITHINDLG] {
158 223
         if (has_totag()) {
159 224
                 if (!loose_route()) {
... ...
@@ -161,44 +226,44 @@ route[WITHINDLG] {
161 226
                         case -2:
162 227
                                 sl_send_reply("403", "Forbidden");
163 228
                                 exit;
164
-                        case -1:
229
+                        default:
165 230
                                 if (is_method("ACK")) {
166
-                                        if (t_check_trans()) {
167
-                                                t_relay();
231
+                                        if ( t_check_trans() ) {
232
+                                                route(RELAY);
168 233
                                                 exit;
169 234
                                         } else {
170 235
                                                 exit;
171 236
                                         }
172 237
                                 }
173
-                                sl_send_reply("404", "Not Found");
238
+                                sl_send_reply("404","Not Found");
174 239
                         }
175 240
                 } else {
241
+                        if (is_method("NOTIFY")) {
242
+                                record_route();
243
+                        }
176 244
                         route(RELAY);
177 245
                 }
178 246
                 exit;
179 247
         }
180 248
 }
181
-...
249
+
182 250
 onreply_route {
183 251
         if (!t_check_trans()) {
184 252
                 drop;
185 253
         }
186 254
 
187
-        if ($rm == "REGISTER" && $rs >= 200 && $rs <= 299)
188
-        {
255
+        if ($rm == "REGISTER" && $rs >= 200 && $rs <= 299) {
256
+                remove_hf("Flow-Timer");
189 257
                 if ($(hdr(Require)[*])=~"outbound")
190 258
                         insert_hf("Flow-Timer: FLOW_TIMER\r\n", "Call-ID");
191 259
         }
192
-
193
-...
194 260
 }
195 261
 
196
-failure_route[FAIL_OUTBOUND] {
262
+failure_route[FAIL_OUTBOUND]{
197 263
         if (t_branch_timeout() || !t_branch_replied()) {
198 264
                 send_reply("430", "Flow Failed");
199 265
         }
200 266
 }
201
-...
202 267
 
203 268
    Example 1.3. Registrar Configuration
204 269
 ...
... ...
@@ -57,61 +57,126 @@ make all
57 57
 	<example>
58 58
 	<title>Edge Proxy Configuration</title>
59 59
 	<programlisting><![CDATA[
60
-...
61
-#!define FLOW_TIMER	20
62
-...
63
-tcp_connection_lifetime=FLOW_TIMER+10
64
-...
65
-loadmodule "websocket.so"
60
+#!KAMAILIO
61
+#
62
+# Edge proxy configuration
63
+#
64
+
65
+#!subst "/REGISTRAR_IP/192.168.122.3/"
66
+#!subst "/REGISTRAR_PORT/5060/"
67
+#!substdef "/FLOW_TIMER/20/"
68
+
69
+####### Global Parameters #########
70
+
71
+debug=2
72
+log_stderror=no
73
+log_facility=LOG_LOCAL0
74
+fork=yes
75
+children=4
76
+alias="example.com"
77
+mpath="/usr/lib64/kamailio/modules"
78
+tcp_connection_lifetime=30 # FLOW_TIMER + 10
79
+
80
+
81
+####### Modules Section ########
82
+
83
+loadmodule "tm.so"
84
+loadmodule "sl.so"
66 85
 loadmodule "outbound.so"
67 86
 loadmodule "rr.so"
68 87
 loadmodule "path.so"
69
-...
70
-modparam("websocket", "keepalive_timeout", FLOW_TIMER+5)
71
-...
72
-route {
88
+loadmodule "pv.so"
89
+loadmodule "maxfwd.so"
90
+loadmodule "xlog.so"
91
+loadmodule "sanity.so"
92
+loadmodule "ctl.so"
93
+loadmodule "mi_rpc.so"
94
+loadmodule "mi_fifo.so"
95
+loadmodule "textops.so"
96
+loadmodule "siputils.so"
97
+
98
+# ----------------- setting module-specific parameters ---------------
99
+
100
+# ----- mi_fifo params -----
101
+modparam("mi_fifo", "fifo_name", "/tmp/kamailio_fifo")
102
+
103
+# ----- tm params -----
104
+modparam("tm", "failure_reply_mode", 3)
105
+
106
+# ----- rr params -----
107
+modparam("rr", "append_fromtag", 0)
108
+
109
+
110
+####### Routing Logic ########
111
+
112
+request_route {
73 113
 	route(REQINIT);
74
-	...
114
+
115
+	if (is_method("CANCEL")) {
116
+		if (t_check_trans()) {
117
+			route(RELAY);
118
+		}
119
+		exit;
120
+	}
121
+
122
+	route(WITHINDLG);
123
+
75 124
 	t_check_trans();
76 125
 
77
-	if (is_method("INVITE|SUBSCRIBE")) {
78
-		record_route();
126
+	if (is_method("REGISTER")) {
127
+		remove_hf("Route");
128
+		add_path();
129
+		$du = "sip:REGISTRAR_IP:REGISTRAR_PORT";
130
+	} else {
131
+		if (is_method("INVITE|SUBSCRIBE"))
132
+			record_route();
79 133
 
80
-		if ($rU==$null) {
81
-			sl_send_reply("484", "Address Incomplete");
82
-			exit;
83
-		}
134
+		if ($si == "REGISTRAR_IP" && $sp == "REGISTRAR_PORT") {
135
+			if (!loose_route()) {
136
+				switch($rc) {
137
+				case -2:
138
+					sl_send_reply("403", "Forbidden");
139
+					exit;
140
+				default:
141
+					sl_reply_error();
142
+					exit;
143
+				}
144
+			}
84 145
 
85
-		if (!loose_route()) {
86
-			switch($rc) {
87
-			case -2:
88
-				# Flow-token has been tampered with
89
-				sl_send_reply("403", "Forbidden");
146
+			t_on_failure("FAIL_OUTBOUND");
147
+		} else {
148
+			if ($rU == $null) {
149
+				sl_send_reply("484", "Address Incomplete");
90 150
 				exit;
91
-			case -1:
92
-				# Handle -1 here if all dialog forming requests
93
-				# must be outbound routed
94 151
 			}
152
+			remove_hf("Route");
153
+			$du = "sip:REGISTRAR_IP:REGISTRAR_PORT";
95 154
 		}
96
-
97
-		t_on_failure("FAIL_OUTBOUND");
98
-		route(RELAY);
99
-	} else if (is_method("REGISTER")) {
100
-		add_path();
101
-		if (!t_relay("### Registrar ###")) {
102
-			sl_reply_error();
103
-		}
104
-		exit;
105 155
 	}
156
+
157
+	route(RELAY);
106 158
 }
107 159
 
108 160
 route[RELAY] {
109 161
 	if (!t_relay()) {
110
-		sl_send_reply("430", "Flow Failed");
162
+		sl_reply_error();
111 163
 	}
112 164
 	exit;
113 165
 }
114
-...
166
+
167
+route[REQINIT] {
168
+	if (!mf_process_maxfwd_header("10")) {
169
+		sl_send_reply("483","Too Many Hops");
170
+		exit;
171
+	}
172
+
173
+	if(!sanity_check("1511", "7"))
174
+	{
175
+		xlog("Malformed SIP message from $si:$sp\n");
176
+		exit;
177
+	}
178
+}
179
+
115 180
 route[WITHINDLG] {
116 181
 	if (has_totag()) {
117 182
 		if (!loose_route()) {
... ...
@@ -119,44 +184,44 @@ route[WITHINDLG] {
119 184
 			case -2:
120 185
 				sl_send_reply("403", "Forbidden");
121 186
 				exit;
122
-			case -1:
187
+			default:
123 188
 				if (is_method("ACK")) {
124
-					if (t_check_trans()) {
125
-						t_relay();
189
+					if ( t_check_trans() ) {
190
+						route(RELAY);
126 191
 						exit;
127 192
 					} else {
128 193
 						exit;
129 194
 					}
130 195
 				}
131
-				sl_send_reply("404", "Not Found");
196
+				sl_send_reply("404","Not Found");
132 197
 			}
133 198
 		} else {
199
+			if (is_method("NOTIFY")) {
200
+				record_route();
201
+			}
134 202
 			route(RELAY);
135 203
 		}
136 204
 		exit;
137 205
 	}
138 206
 }
139
-...
207
+
140 208
 onreply_route {
141 209
 	if (!t_check_trans()) {
142 210
 		drop;
143 211
 	}
144 212
 
145
-	if ($rm == "REGISTER" && $rs >= 200 && $rs <= 299)
146
-	{
213
+	if ($rm == "REGISTER" && $rs >= 200 && $rs <= 299) {
214
+		remove_hf("Flow-Timer");
147 215
 		if ($(hdr(Require)[*])=~"outbound")
148 216
 			insert_hf("Flow-Timer: FLOW_TIMER\r\n", "Call-ID");
149 217
 	}
150
-
151
-...
152 218
 }
153 219
 
154
-failure_route[FAIL_OUTBOUND] {
220
+failure_route[FAIL_OUTBOUND]{
155 221
 	if (t_branch_timeout() || !t_branch_replied()) {
156 222
 		send_reply("430", "Flow Failed");
157 223
 	}
158 224
 }
159
-...
160 225
 ]]></programlisting>
161 226
 	</example>
162 227
 	<example>