| 1 |
The Sanity Module - SIP syntax checking |
| 2 |
|
| 3 |
Nils Ohlmeier |
| 4 |
|
| 5 |
iptelorg GmbH |
| 6 |
|
| 7 |
Copyright © 2006 iptelorg GmbH |
| 8 |
__________________________________________________________________ |
| 9 |
|
| 10 |
Table of Contents |
| 11 |
|
| 12 |
1. Admin Guide |
| 13 |
|
| 14 |
1. Overview |
| 15 |
2. Dependencies |
| 16 |
3. Parameters |
| 17 |
|
| 18 |
3.1. default_checks (integer) |
| 19 |
3.2. uri_checks (integer) |
| 20 |
3.3. proxy_require (string) |
| 21 |
3.4. autodrop (integer) |
| 22 |
3.5. noreply (int) |
| 23 |
|
| 24 |
4. Functions |
| 25 |
|
| 26 |
4.1. sanity_check([msg_checks [, uri_checks]]) |
| 27 |
4.2. sanity_reply() |
| 28 |
|
| 29 |
List of Examples |
| 30 |
|
| 31 |
1.1. Set default_checks parameter |
| 32 |
1.2. Set uri_checks parameter |
| 33 |
1.3. Set proxy_require parameter |
| 34 |
1.4. Set autodrop parameter |
| 35 |
1.5. Set noreply parameter |
| 36 |
1.6. sanity_check usage |
| 37 |
1.7. sanity_check usage with parameter |
| 38 |
1.8. sanity_check usage with two parameters |
| 39 |
1.9. sanity_reply usage |
| 40 |
|
| 41 |
Chapter 1. Admin Guide |
| 42 |
|
| 43 |
Table of Contents |
| 44 |
|
| 45 |
1. Overview |
| 46 |
2. Dependencies |
| 47 |
3. Parameters |
| 48 |
|
| 49 |
3.1. default_checks (integer) |
| 50 |
3.2. uri_checks (integer) |
| 51 |
3.3. proxy_require (string) |
| 52 |
3.4. autodrop (integer) |
| 53 |
3.5. noreply (int) |
| 54 |
|
| 55 |
4. Functions |
| 56 |
|
| 57 |
4.1. sanity_check([msg_checks [, uri_checks]]) |
| 58 |
4.2. sanity_reply() |
| 59 |
|
| 60 |
1. Overview |
| 61 |
|
| 62 |
This module aims to implement several sanity checks on incoming |
| 63 |
requests which are suggested or even required by a RFC, but are not |
| 64 |
available yet in the core of Kamailio. |
| 65 |
|
| 66 |
These checks are not required by Kamailio itself for its functionality. |
| 67 |
But on the other side it does not make much sense if a broken request |
| 68 |
traverses through a SIP network if it is rejected sooner or later by a |
| 69 |
SIP device any way. As every sanity check cost extra performance |
| 70 |
because of additional parsing and evaluation it is with this module now |
| 71 |
up to the Kamailio administrator what checks should be done on which |
| 72 |
request. |
| 73 |
|
| 74 |
The following checks are available: |
| 75 |
* ruri sip version - (1) - checks if the SIP version in the request |
| 76 |
URI is supported, currently only 2.0. |
| 77 |
* ruri scheme - (2) - checks if the URI scheme of the request URI is |
| 78 |
supported (sip[s]|tel[s]) by Kamailio |
| 79 |
* required headers - (4) -checks if the minimum set of required |
| 80 |
headers To, From, CSeq, Call-ID and Via is present in the request. |
| 81 |
* via sip version - (8) - disabled. |
| 82 |
* via protocol - (16) - disabled. |
| 83 |
* Cseq method - (32) - checks if the method from the CSeq header is |
| 84 |
equal to the request method. |
| 85 |
* Cseq value - (64) - checks if the number in the CSeq header is a |
| 86 |
valid unsigned integer. |
| 87 |
* content length - (128) - checks if the size of the body matches |
| 88 |
with the value from the Content-Length header. |
| 89 |
* expires value - (256) - checks if the value of the Expires header |
| 90 |
is a valid unsigned integer. |
| 91 |
* proxy require - (512) - checks if all items of the Proxy-Require |
| 92 |
header are present in the list of the extensions from the module |
| 93 |
parameter proxy_require. |
| 94 |
* parse uri's - (1024) - checks if the specified URIs are present and |
| 95 |
parseable by the Kamailio parsers |
| 96 |
* digest credentials (2048) - Check all instances of digest |
| 97 |
credentials in a message. The test checks whether there are all |
| 98 |
required digest parameters and that they have meaningful values. |
| 99 |
NOTE: the message will be considered invalid if the authorization |
| 100 |
scheme differs from "digest", |
| 101 |
* duplicated To/From tags (4096) - checks for the presence of |
| 102 |
duplicated tags in To/From headers. |
| 103 |
* Authorization header (8192) - checks if the Authorization header is |
| 104 |
valid if the scheme is "digest" (see "digest credentials" above), |
| 105 |
always returns success for other schemes. |
| 106 |
* first via header (16384) - checks if the first Via header is |
| 107 |
available, can be parsed and has an address value. |
| 108 |
|
| 109 |
2. Dependencies |
| 110 |
|
| 111 |
The following modules must be loaded before this module: |
| 112 |
* sl - Stateless replies. |
| 113 |
|
| 114 |
3. Parameters |
| 115 |
|
| 116 |
3.1. default_checks (integer) |
| 117 |
3.2. uri_checks (integer) |
| 118 |
3.3. proxy_require (string) |
| 119 |
3.4. autodrop (integer) |
| 120 |
3.5. noreply (int) |
| 121 |
|
| 122 |
3.1. default_checks (integer) |
| 123 |
|
| 124 |
This parameter determines which of the checks from the sanity module |
| 125 |
are executed if no parameter was given to the sanity_check function |
| 126 |
call. By default all implemented checks are included in the execution |
| 127 |
of the sanity_check function. The integer value is the sum of the check |
| 128 |
numbers which should be executed by default. |
| 129 |
|
| 130 |
Default value is “3047”. This resolves to the following list of checks: |
| 131 |
ruri_sip_version (1), ruri_scheme (2), required_headers (4), |
| 132 |
cseq_method (32), cseq_value (64), content_length (128), expires_value |
| 133 |
(256), proxy_require (512), digest credentials (2048). |
| 134 |
|
| 135 |
Example 1.1. Set default_checks parameter |
| 136 |
... |
| 137 |
modparam("sanity", "default_checks", 1) |
| 138 |
... |
| 139 |
|
| 140 |
3.2. uri_checks (integer) |
| 141 |
|
| 142 |
This parameter determines which URIs are going to be checked if the |
| 143 |
'parse uri' will be executed. |
| 144 |
|
| 145 |
Default value is 7. This resolves to the following list of parsed URIs: |
| 146 |
Request URI (1), From URI (2) and To URI (4). Additionally the Contact |
| 147 |
URI can be also checked (8). |
| 148 |
|
| 149 |
Example 1.2. Set uri_checks parameter |
| 150 |
... |
| 151 |
modparam("sanity", "uri_checks", 3) |
| 152 |
... |
| 153 |
|
| 154 |
3.3. proxy_require (string) |
| 155 |
|
| 156 |
This parameter sets the list of supported SIP extensions for this |
| 157 |
Kamailio. The value is expected as a comma separated list (leading and |
| 158 |
trailing whitespaces are stripped from each token) of extensions. This |
| 159 |
list is separated into single tokens. Each token from a proxy require |
| 160 |
header will be compared with the tokens from this list. |
| 161 |
|
| 162 |
Example 1.3. Set proxy_require parameter |
| 163 |
... |
| 164 |
modparam("sanity", "proxy_require", "foo, bar") |
| 165 |
... |
| 166 |
|
| 167 |
3.4. autodrop (integer) |
| 168 |
|
| 169 |
This parameter controls whether the module drops the SIP message |
| 170 |
automatically if the sanity checks fail. Default value is 1 (auto |
| 171 |
drop). If set to 0, sanity_check() function will return -1 (false) to |
| 172 |
configuration file, allowing to write log messages for example - be |
| 173 |
sure you “exit” execution of config without sending a SIP reply because |
| 174 |
it is sent by module itself. |
| 175 |
|
| 176 |
Example 1.4. Set autodrop parameter |
| 177 |
... |
| 178 |
modparam("sanity", "autodrop", 1) |
| 179 |
... |
| 180 |
|
| 181 |
3.5. noreply (int) |
| 182 |
|
| 183 |
If set to 1, then the module does not send a SIP reply internally in |
| 184 |
case there is an error detected when performing the sanity checks. |
| 185 |
There is the option to send the reply from config file with functions |
| 186 |
from sl or tm module as well as sanity_reply() from this module. |
| 187 |
|
| 188 |
Default value: 0. |
| 189 |
|
| 190 |
Example 1.5. Set noreply parameter |
| 191 |
... |
| 192 |
modparam("sanity", "noreply", 1) |
| 193 |
... |
| 194 |
|
| 195 |
4. Functions |
| 196 |
|
| 197 |
4.1. sanity_check([msg_checks [, uri_checks]]) |
| 198 |
4.2. sanity_reply() |
| 199 |
|
| 200 |
4.1. sanity_check([msg_checks [, uri_checks]]) |
| 201 |
|
| 202 |
This function makes a row of sanity checks over the given SIP request. |
| 203 |
The behavior of the function is also controlled by autodrop parameter. |
| 204 |
If autodrop=0, the function returns false (-1) if one of the checks |
| 205 |
failed. When autodrop=1, the function stops the execution of |
| 206 |
configuration file. In both cases, if one of the checks fails the |
| 207 |
module sends a precise error reply via SL send_reply(). Thus there is |
| 208 |
no need to reply with a generic error message. |
| 209 |
|
| 210 |
The parameters can be static integers or variables holding integer |
| 211 |
values. |
| 212 |
|
| 213 |
Example 1.6. sanity_check usage |
| 214 |
... |
| 215 |
if (!sanity_check()) { |
| 216 |
exit; |
| 217 |
} |
| 218 |
... |
| 219 |
|
| 220 |
Optionally the function takes an integer argument which overwrites the |
| 221 |
global module parameter default_checks. This makes it possible to run |
| 222 |
certain tests from script regions. The integer value is again the sum |
| 223 |
of the checks (like for the module parameter) which should be executed |
| 224 |
at this function call. |
| 225 |
|
| 226 |
Example 1.7. sanity_check usage with parameter |
| 227 |
... |
| 228 |
if (method=="REGISTER" && !sanity_check("256")) { |
| 229 |
/* the register contains an invalid expires value and is replied with a |
| 230 |
400 */ |
| 231 |
exit; |
| 232 |
} |
| 233 |
... |
| 234 |
|
| 235 |
Optionally the function takes a second integer argument which |
| 236 |
overwrites the global module parameter uri_checks and thus determines |
| 237 |
which URIs will be checked if the parse uri test will be executed. |
| 238 |
|
| 239 |
Example 1.8. sanity_check usage with two parameters |
| 240 |
... |
| 241 |
if (method=="INVITE" && !sanity_check("1024", "6")) { |
| 242 |
/* the INVITE contains an invalid From or To header and is replied with |
| 243 |
a 400 */ |
| 244 |
exit; |
| 245 |
} |
| 246 |
... |
| 247 |
|
| 248 |
4.2. sanity_reply() |
| 249 |
|
| 250 |
Send a SIP reply using the code and reason text set internally by the |
| 251 |
module when detecting errors while performing the sanity checks. It is |
| 252 |
done only when parameter noreply is set to 1. |
| 253 |
|
| 254 |
Example 1.9. sanity_reply usage |
| 255 |
... |
| 256 |
if(!sanity_check("1024", "6")) { |
| 257 |
xdbg("sanity checks failed\n"); |
| 258 |
sanity_reply(); |
| 259 |
exit; |
| 260 |
} |
| 261 |
... |