| 1 |
permissions Module |
| 2 |
|
| 3 |
Miklos Tirpak |
| 4 |
|
| 5 |
Edited by |
| 6 |
|
| 7 |
Miklos Tirpak |
| 8 |
|
| 9 |
Bogdan-Andrei Iancu |
| 10 |
|
| 11 |
Juha Heinanen |
| 12 |
|
| 13 |
Emmanuel Schmidbauer |
| 14 |
|
| 15 |
Donat Zenichev |
| 16 |
|
| 17 |
Tyler Moore |
| 18 |
|
| 19 |
Copyright © 2003 Miklos Tirpak |
| 20 |
|
| 21 |
Copyright © 2006-2008 Juha Heinanen |
| 22 |
|
| 23 |
Copyright © 2025 Tyler Moore, dOpenSource |
| 24 |
__________________________________________________________________ |
| 25 |
|
| 26 |
Table of Contents |
| 27 |
|
| 28 |
1. Admin Guide |
| 29 |
|
| 30 |
1. Overview |
| 31 |
|
| 32 |
1.1. Call Routing |
| 33 |
1.2. Registration Permissions |
| 34 |
1.3. URI Permissions |
| 35 |
1.4. Address Permissions |
| 36 |
1.5. Trusted Requests |
| 37 |
|
| 38 |
2. Dependencies |
| 39 |
|
| 40 |
2.1. Kamailio Modules |
| 41 |
2.2. External Libraries or Applications |
| 42 |
|
| 43 |
3. Parameters |
| 44 |
|
| 45 |
3.1. default_allow_file (string) |
| 46 |
3.2. default_deny_file (string) |
| 47 |
3.3. check_all_branches (integer) |
| 48 |
3.4. allow_suffix (string) |
| 49 |
3.5. deny_suffix (string) |
| 50 |
3.6. address_file (string) |
| 51 |
3.7. db_url (string) |
| 52 |
3.8. address_table (string) |
| 53 |
3.9. grp_col (string) |
| 54 |
3.10. ip_addr_col (string) |
| 55 |
3.11. mask_col (string) |
| 56 |
3.12. port_col (string) |
| 57 |
3.13. db_mode (integer) |
| 58 |
3.14. trusted_table (string) |
| 59 |
3.15. source_col (string) |
| 60 |
3.16. proto_col (string) |
| 61 |
3.17. from_col (string) |
| 62 |
3.18. ruri_col (string) |
| 63 |
3.19. tag_col (string) |
| 64 |
3.20. priority_col (string) |
| 65 |
3.21. peer_tag_avp (AVP string) |
| 66 |
3.22. peer_tag_mode (integer) |
| 67 |
3.23. max_subnets (int) |
| 68 |
3.24. subnet_match_mode (int) |
| 69 |
3.25. load_backends (int) |
| 70 |
3.26. reload_delta (int) |
| 71 |
3.27. trusted_cleanup_interval (int) |
| 72 |
|
| 73 |
4. Functions |
| 74 |
|
| 75 |
4.1. allow_routing() |
| 76 |
4.2. allow_routing(basename) |
| 77 |
4.3. allow_routing(allow_file, deny_file) |
| 78 |
4.4. allow_register(basename) |
| 79 |
4.5. allow_register(allow_file, deny_file) |
| 80 |
4.6. allow_register_include_port(basename) |
| 81 |
4.7. allow_register_include_port(allow_file, deny_file) |
| 82 |
4.8. allow_uri(basename, pvar) |
| 83 |
4.9. allow_address(group_id, ip_addr_pvar, port_pvar) |
| 84 |
4.10. allow_source_address([group_id]) |
| 85 |
4.11. allow_source_address_group() |
| 86 |
4.12. allow_address_group(addr, port) |
| 87 |
4.13. allow_trusted([src_ip_pvar, proto_pvar, furi_pvar]) |
| 88 |
|
| 89 |
5. RPC Commands |
| 90 |
|
| 91 |
5.1. permissions.addressReload |
| 92 |
5.2. permissions.addressDump |
| 93 |
5.3. permissions.subnetDump |
| 94 |
5.4. permissions.domainDump |
| 95 |
5.5. permissions.testUri |
| 96 |
5.6. permissions.allowUri |
| 97 |
5.7. permissions.trustedReload |
| 98 |
5.8. permissions.trustedDump |
| 99 |
|
| 100 |
6. Address File Format |
| 101 |
7. Register File Format |
| 102 |
|
| 103 |
List of Examples |
| 104 |
|
| 105 |
1.1. Set default_allow_file parameter |
| 106 |
1.2. Set default_deny_file parameter |
| 107 |
1.3. Set check_all_branches parameter |
| 108 |
1.4. Set allow_suffix parameter |
| 109 |
1.5. Set deny_suffix parameter |
| 110 |
1.6. Set address_file parameter |
| 111 |
1.7. Set db_url parameter |
| 112 |
1.8. Set address_table parameter |
| 113 |
1.9. Set grp_col parameter |
| 114 |
1.10. Set ip_addr_col parameter |
| 115 |
1.11. Set mask_col parameter |
| 116 |
1.12. Set port_col parameter |
| 117 |
1.13. Set db_mode parameter |
| 118 |
1.14. Set trusted_table parameter |
| 119 |
1.15. Set source_col parameter |
| 120 |
1.16. Set proto_col parameter |
| 121 |
1.17. Set from_col parameter |
| 122 |
1.18. Set ruri_col parameter |
| 123 |
1.19. Set tag_col parameter |
| 124 |
1.20. Set priority_col parameter |
| 125 |
1.21. Set peer_tag_avp parameter |
| 126 |
1.22. Set peer_tag_mode parameter |
| 127 |
1.23. Set max_subnets parameter |
| 128 |
1.24. Set subnet_match_mode parameter |
| 129 |
1.25. Set load_backends parameter |
| 130 |
1.26. Set reload_delta parameter |
| 131 |
1.27. Set trusted_cleanup_interval parameter |
| 132 |
1.28. allow_routing usage |
| 133 |
1.29. allow_routing(basename) usage |
| 134 |
1.30. allow_routing(allow_file, deny_file) usage |
| 135 |
1.31. allow_register(basename) usage |
| 136 |
1.32. allow_register(allow_file, deny_file) usage |
| 137 |
1.33. allow_register_include_port(basename) usage |
| 138 |
1.34. allow_register_include_port(allow_file, deny_file) usage |
| 139 |
1.35. allow_uri(basename, pvar) usage |
| 140 |
1.36. allow_address() usage |
| 141 |
1.37. allow_source_address(group_id) usage |
| 142 |
1.38. allow_source_address_group() usage |
| 143 |
1.39. allow_source_address_group() usage |
| 144 |
1.40. allow_trusted() usage |
| 145 |
1.41. Address File Sample |
| 146 |
1.42. Register File Sample |
| 147 |
|
| 148 |
Chapter 1. Admin Guide |
| 149 |
|
| 150 |
Table of Contents |
| 151 |
|
| 152 |
1. Overview |
| 153 |
|
| 154 |
1.1. Call Routing |
| 155 |
1.2. Registration Permissions |
| 156 |
1.3. URI Permissions |
| 157 |
1.4. Address Permissions |
| 158 |
1.5. Trusted Requests |
| 159 |
|
| 160 |
2. Dependencies |
| 161 |
|
| 162 |
2.1. Kamailio Modules |
| 163 |
2.2. External Libraries or Applications |
| 164 |
|
| 165 |
3. Parameters |
| 166 |
|
| 167 |
3.1. default_allow_file (string) |
| 168 |
3.2. default_deny_file (string) |
| 169 |
3.3. check_all_branches (integer) |
| 170 |
3.4. allow_suffix (string) |
| 171 |
3.5. deny_suffix (string) |
| 172 |
3.6. address_file (string) |
| 173 |
3.7. db_url (string) |
| 174 |
3.8. address_table (string) |
| 175 |
3.9. grp_col (string) |
| 176 |
3.10. ip_addr_col (string) |
| 177 |
3.11. mask_col (string) |
| 178 |
3.12. port_col (string) |
| 179 |
3.13. db_mode (integer) |
| 180 |
3.14. trusted_table (string) |
| 181 |
3.15. source_col (string) |
| 182 |
3.16. proto_col (string) |
| 183 |
3.17. from_col (string) |
| 184 |
3.18. ruri_col (string) |
| 185 |
3.19. tag_col (string) |
| 186 |
3.20. priority_col (string) |
| 187 |
3.21. peer_tag_avp (AVP string) |
| 188 |
3.22. peer_tag_mode (integer) |
| 189 |
3.23. max_subnets (int) |
| 190 |
3.24. subnet_match_mode (int) |
| 191 |
3.25. load_backends (int) |
| 192 |
3.26. reload_delta (int) |
| 193 |
3.27. trusted_cleanup_interval (int) |
| 194 |
|
| 195 |
4. Functions |
| 196 |
|
| 197 |
4.1. allow_routing() |
| 198 |
4.2. allow_routing(basename) |
| 199 |
4.3. allow_routing(allow_file, deny_file) |
| 200 |
4.4. allow_register(basename) |
| 201 |
4.5. allow_register(allow_file, deny_file) |
| 202 |
4.6. allow_register_include_port(basename) |
| 203 |
4.7. allow_register_include_port(allow_file, deny_file) |
| 204 |
4.8. allow_uri(basename, pvar) |
| 205 |
4.9. allow_address(group_id, ip_addr_pvar, port_pvar) |
| 206 |
4.10. allow_source_address([group_id]) |
| 207 |
4.11. allow_source_address_group() |
| 208 |
4.12. allow_address_group(addr, port) |
| 209 |
4.13. allow_trusted([src_ip_pvar, proto_pvar, furi_pvar]) |
| 210 |
|
| 211 |
5. RPC Commands |
| 212 |
|
| 213 |
5.1. permissions.addressReload |
| 214 |
5.2. permissions.addressDump |
| 215 |
5.3. permissions.subnetDump |
| 216 |
5.4. permissions.domainDump |
| 217 |
5.5. permissions.testUri |
| 218 |
5.6. permissions.allowUri |
| 219 |
5.7. permissions.trustedReload |
| 220 |
5.8. permissions.trustedDump |
| 221 |
|
| 222 |
6. Address File Format |
| 223 |
7. Register File Format |
| 224 |
|
| 225 |
1. Overview |
| 226 |
|
| 227 |
1.1. Call Routing |
| 228 |
1.2. Registration Permissions |
| 229 |
1.3. URI Permissions |
| 230 |
1.4. Address Permissions |
| 231 |
1.5. Trusted Requests |
| 232 |
|
| 233 |
The Permissions module provides functions for handling IP based access |
| 234 |
control lists (ACL) in a number of ways. |
| 235 |
* Call Routing |
| 236 |
* Registration permissions |
| 237 |
* URI permissions |
| 238 |
* Address permissions |
| 239 |
* Trusted Requests |
| 240 |
|
| 241 |
The Address permissions and Trusted request handling supports using a |
| 242 |
database to load ACLs into RAM for fast processing. |
| 243 |
|
| 244 |
1.1. Call Routing |
| 245 |
|
| 246 |
The module can be used to determine if a call has appropriate |
| 247 |
permission to be established. Permission rules are stored in plaintext |
| 248 |
configuration files similar to hosts.allow and hosts.deny files used by |
| 249 |
tcpd. |
| 250 |
|
| 251 |
When allow_routing function is called it tries to find a rule that |
| 252 |
matches selected fields of the message. |
| 253 |
|
| 254 |
Kamailio is a forking proxy and therefore a single message can be sent |
| 255 |
to different destinations simultaneously. When checking permissions all |
| 256 |
the destinations must be checked and if one of them fails, the |
| 257 |
forwarding will fail. |
| 258 |
|
| 259 |
The matching algorithm is as follows, first match wins: |
| 260 |
* Create a set of pairs of form (From, R-URI of branch 1), (From, |
| 261 |
R-URI of branch 2), etc. |
| 262 |
* Routing will be allowed when all pairs match an entry in the allow |
| 263 |
file. |
| 264 |
* Otherwise routing will be denied when one of pairs matches an entry |
| 265 |
in the deny file. |
| 266 |
* Otherwise, routing will be allowed. |
| 267 |
|
| 268 |
A non-existing permission control file is treated as if it were an |
| 269 |
empty file. Thus, permission control can be turned off by providing no |
| 270 |
permission control files. |
| 271 |
|
| 272 |
From header field and Request-URIs are always compared with regular |
| 273 |
expressions! For the syntax see the sample file: |
| 274 |
config/permissions.allow. |
| 275 |
|
| 276 |
1.2. Registration Permissions |
| 277 |
|
| 278 |
In addition to call routing it is also possible to check REGISTER |
| 279 |
messages and decide--based on the configuration files--whether the |
| 280 |
message should be allowed and the registration accepted or not. |
| 281 |
|
| 282 |
Main purpose of the function is to prevent registration of "prohibited" |
| 283 |
IP addresses. One example, when a malicious user registers a contact |
| 284 |
containing IP address of a PSTN gateway, he might be able to bypass |
| 285 |
authorization checks performed by the SIP proxy. That is undesirable |
| 286 |
and therefore attempts to register IP address of a PSTN gateway should |
| 287 |
be rejected. Files config/register.allow and config/register.deny |
| 288 |
contain an example configuration. |
| 289 |
|
| 290 |
The function for registration checking is called allow_register and the |
| 291 |
algorithm is very similar to the algorithm described in Section 1.1, |
| 292 |
“Call Routing”. The only difference is in the way how pairs are |
| 293 |
created. Additionally one can use allow_register_include_port function |
| 294 |
in order to include the port value of the Contact into the check. |
| 295 |
|
| 296 |
Instead of the From header field the function uses the To header field |
| 297 |
because the To header field in REGISTER messages contains the URI of |
| 298 |
the person being registered. Instead of the Request-URI of branches the |
| 299 |
function uses the Contact header field. |
| 300 |
|
| 301 |
Thus, the pairs used in matching will look like this: (To, Contact 1), |
| 302 |
(To, Contact 2), (To, Contact 3), and so on.. |
| 303 |
|
| 304 |
The algorithm of matching is the same as described in Section 1.1, |
| 305 |
“Call Routing”. |
| 306 |
|
| 307 |
1.3. URI Permissions |
| 308 |
|
| 309 |
The module can be used to determine if a request to a destination is |
| 310 |
allowed, based on an URI stored in a pvar. Permission rules are stored |
| 311 |
in plaintext configuration files similar to hosts.allow and hosts.deny |
| 312 |
used by tcpd. |
| 313 |
|
| 314 |
When the allow_uri function is called, it tries to find a rule that |
| 315 |
matches selected fields of the message. The matching algorithm is as |
| 316 |
follows, where the first match wins: |
| 317 |
* Create a pair <From URI, URI stored in pvar>. |
| 318 |
* Request will be allowed when the pair matches an entry in the allow |
| 319 |
file. |
| 320 |
* Request will be denied when the pair matches an entry in the deny |
| 321 |
file. |
| 322 |
* Otherwise, request will be allowed. |
| 323 |
|
| 324 |
A non-existing permission control file is treated as if it were an |
| 325 |
empty file. Thus, permission control can be turned off by providing no |
| 326 |
permission control files. |
| 327 |
|
| 328 |
The From URI and the URI stored in pvar are always compared with |
| 329 |
regular expressions! For the syntax see the sample file: |
| 330 |
config/permissions.allow. |
| 331 |
|
| 332 |
1.4. Address Permissions |
| 333 |
|
| 334 |
The module can be used to determine if an address (IP address and port |
| 335 |
or DNS domain name) matches any of the addresses stored in a cached |
| 336 |
Kamailio database table or file. IP addresses in the database table or |
| 337 |
file can be subnet addresses. Port 0 matches any port. The address and |
| 338 |
port to be matched can be either taken from the source of IP packet of |
| 339 |
the request (allow_source_address) or given as a variable argument |
| 340 |
(allow_address). |
| 341 |
|
| 342 |
Addresses stored in the database table or file can be grouped together |
| 343 |
into one or more groups specified by a group identifier (positive |
| 344 |
integer value, i.e., equal or greater than 1). The group identifier is |
| 345 |
given as an argument to the allow_address() and allow_source_address() |
| 346 |
functions. One group can contain all of the three types of addresses: |
| 347 |
exact IP address, subnet IP address or DNS domain name. |
| 348 |
|
| 349 |
When the argument is an IP address, it is tried to be matched with the |
| 350 |
records from that group that are of type exact IP or subnet. If the |
| 351 |
argument is not an IP it is tried to be matched with the records that |
| 352 |
are DNS domain names. No DNS lookup is performed, only strict matching. |
| 353 |
|
| 354 |
As a side effect of matching the address, non-NULL tag (see tag_col |
| 355 |
module parameter) is added as value to peer_tag AVP if peer_tag_avp |
| 356 |
module parameter has been defined. |
| 357 |
|
| 358 |
Note |
| 359 |
|
| 360 |
Starting with Kamailio version 6.1.x, the allow_address() its related |
| 361 |
functions can do First Prefix Match (FPM) or the Longest Prefix Match |
| 362 |
(LPM) methods to find the subnet matching record, which can set the tag |
| 363 |
variable. The matching method is controled by the parameter |
| 364 |
subnet_match_mode. |
| 365 |
|
| 366 |
Th LPM means the _group variants will now return the most specific |
| 367 |
(longest) subnet match, instead of the first match (which was |
| 368 |
previously the entry with the lowest group ID). The FPM/LPM behavior is |
| 369 |
now consistent across the following functions: |
| 370 |
* allow_address() |
| 371 |
* allow_source_address() |
| 372 |
* allow_source_address_group() |
| 373 |
* allow_address_group() |
| 374 |
|
| 375 |
1.5. Trusted Requests |
| 376 |
|
| 377 |
The module can be used to determine if an incoming request can be |
| 378 |
trusted without authentication. |
| 379 |
|
| 380 |
When the allow_trusted function is called, it tries to find a rule that |
| 381 |
matches the request. Rules contain the following fields: <source |
| 382 |
address, transport protocol, regular expression>. |
| 383 |
|
| 384 |
A request is accepted if there exists a rule, where |
| 385 |
* source address is equal to the source address of the request or the |
| 386 |
source address given in pvar, |
| 387 |
* transport protocol is either "ANY" or equal to the transport |
| 388 |
protocol of request or the transport protocol given in pvar, and |
| 389 |
* regular expression is either empty (NULL in database) or matches |
| 390 |
the request's From (or optionally provided) URI. |
| 391 |
|
| 392 |
Otherwise the request is rejected. |
| 393 |
|
| 394 |
As a side effect of accepting the request, the peer's non-NULL tag (see |
| 395 |
tag_col module parameter) is added as value to peer_tag AVP if the |
| 396 |
peer_tag_avp module parameter has been defined. |
| 397 |
|
| 398 |
Rules are stored in a database table specified by the module |
| 399 |
parameters. There is a module parameter called db_mode that determines |
| 400 |
if the rules are cached into memory for faster matching or if the |
| 401 |
database is consulted for each invocation of the allow_trusted() |
| 402 |
function call. |
| 403 |
|
| 404 |
2. Dependencies |
| 405 |
|
| 406 |
2.1. Kamailio Modules |
| 407 |
2.2. External Libraries or Applications |
| 408 |
|
| 409 |
2.1. Kamailio Modules |
| 410 |
|
| 411 |
The following modules must be loaded before this module: |
| 412 |
* No dependencies on other Kamailio modules. |
| 413 |
|
| 414 |
2.2. External Libraries or Applications |
| 415 |
|
| 416 |
The following libraries or applications must be installed before |
| 417 |
running Kamailio with this module loaded: |
| 418 |
* None. |
| 419 |
|
| 420 |
3. Parameters |
| 421 |
|
| 422 |
3.1. default_allow_file (string) |
| 423 |
3.2. default_deny_file (string) |
| 424 |
3.3. check_all_branches (integer) |
| 425 |
3.4. allow_suffix (string) |
| 426 |
3.5. deny_suffix (string) |
| 427 |
3.6. address_file (string) |
| 428 |
3.7. db_url (string) |
| 429 |
3.8. address_table (string) |
| 430 |
3.9. grp_col (string) |
| 431 |
3.10. ip_addr_col (string) |
| 432 |
3.11. mask_col (string) |
| 433 |
3.12. port_col (string) |
| 434 |
3.13. db_mode (integer) |
| 435 |
3.14. trusted_table (string) |
| 436 |
3.15. source_col (string) |
| 437 |
3.16. proto_col (string) |
| 438 |
3.17. from_col (string) |
| 439 |
3.18. ruri_col (string) |
| 440 |
3.19. tag_col (string) |
| 441 |
3.20. priority_col (string) |
| 442 |
3.21. peer_tag_avp (AVP string) |
| 443 |
3.22. peer_tag_mode (integer) |
| 444 |
3.23. max_subnets (int) |
| 445 |
3.24. subnet_match_mode (int) |
| 446 |
3.25. load_backends (int) |
| 447 |
3.26. reload_delta (int) |
| 448 |
3.27. trusted_cleanup_interval (int) |
| 449 |
|
| 450 |
3.1. default_allow_file (string) |
| 451 |
|
| 452 |
Default allow file used by the functions with no parameters. If you |
| 453 |
don't specify a full pathname then the directory in which the main |
| 454 |
config file is located will be used. |
| 455 |
|
| 456 |
Default value is “permissions.allow”. |
| 457 |
|
| 458 |
Example 1.1. Set default_allow_file parameter |
| 459 |
... |
| 460 |
modparam("permissions", "default_allow_file", "/etc/permissions.allow") |
| 461 |
... |
| 462 |
|
| 463 |
3.2. default_deny_file (string) |
| 464 |
|
| 465 |
Default file containing deny rules. The file is used by functions with |
| 466 |
no parameters. If you don't specify a full pathname then the directory |
| 467 |
in which the main config file is located will be used. |
| 468 |
|
| 469 |
Default value is “permissions.deny”. |
| 470 |
|
| 471 |
Example 1.2. Set default_deny_file parameter |
| 472 |
... |
| 473 |
modparam("permissions", "default_deny_file", "/etc/permissions.deny") |
| 474 |
... |
| 475 |
|
| 476 |
3.3. check_all_branches (integer) |
| 477 |
|
| 478 |
If set then allow_routing functions will check Request-URI of all |
| 479 |
branches (default). If disabled then only Request-URI of the first |
| 480 |
branch will be checked. |
| 481 |
|
| 482 |
Warning |
| 483 |
|
| 484 |
Do not disable this parameter unless you really know what you are |
| 485 |
doing. |
| 486 |
|
| 487 |
Default value is 1. |
| 488 |
|
| 489 |
Example 1.3. Set check_all_branches parameter |
| 490 |
... |
| 491 |
modparam("permissions", "check_all_branches", 0) |
| 492 |
... |
| 493 |
|
| 494 |
3.4. allow_suffix (string) |
| 495 |
|
| 496 |
Suffix to be appended to basename to create filename of the allow file |
| 497 |
when version with one parameter of either allow_routing or |
| 498 |
allow_register_include_port or allow_register is used. |
| 499 |
|
| 500 |
Note |
| 501 |
|
| 502 |
Including leading dot. |
| 503 |
|
| 504 |
Default value is “.allow”. |
| 505 |
|
| 506 |
Example 1.4. Set allow_suffix parameter |
| 507 |
... |
| 508 |
modparam("permissions", "allow_suffix", ".allow") |
| 509 |
... |
| 510 |
|
| 511 |
3.5. deny_suffix (string) |
| 512 |
|
| 513 |
Suffix to be appended to basename to create filename of the deny file |
| 514 |
when version with one parameter of either allow_routing or |
| 515 |
allow_register_include_port or allow_register is used. |
| 516 |
|
| 517 |
Note |
| 518 |
|
| 519 |
Including leading dot. |
| 520 |
|
| 521 |
Default value is “.deny”. |
| 522 |
|
| 523 |
Example 1.5. Set deny_suffix parameter |
| 524 |
... |
| 525 |
modparam("permissions", "deny_suffix", ".deny") |
| 526 |
... |
| 527 |
|
| 528 |
3.6. address_file (string) |
| 529 |
|
| 530 |
This is the name of full path to the file that store rules used by |
| 531 |
allow_address function (and its variants). If it is only the file name, |
| 532 |
it is expected to be in the same folder as kamailio.cfg file. |
| 533 |
|
| 534 |
If set, this parameter has priority over the database backend, so the |
| 535 |
address matching records are loaded from the file, not from database. |
| 536 |
|
| 537 |
To see the format of the file see the section "Address File Format". |
| 538 |
|
| 539 |
Default value is “NULL”. |
| 540 |
|
| 541 |
Example 1.6. Set address_file parameter |
| 542 |
... |
| 543 |
modparam("permissions", "address_file", "address.list") |
| 544 |
... |
| 545 |
|
| 546 |
3.7. db_url (string) |
| 547 |
|
| 548 |
This is URL of the database to be used to store rules used by |
| 549 |
allow_trusted or allow_address functions. |
| 550 |
|
| 551 |
Default value is “NULL”. |
| 552 |
|
| 553 |
Example 1.7. Set db_url parameter |
| 554 |
... |
| 555 |
modparam("permissions", "db_url", "dbdriver://username:password@dbhost/dbname") |
| 556 |
... |
| 557 |
|
| 558 |
3.8. address_table (string) |
| 559 |
|
| 560 |
The name of the database table containing IP subnets and DNS domain |
| 561 |
names used by allow_address and allow_source_address functions. |
| 562 |
|
| 563 |
Default value is “address”. |
| 564 |
|
| 565 |
Example 1.8. Set address_table parameter |
| 566 |
... |
| 567 |
modparam("permissions", "address_table", "addr") |
| 568 |
... |
| 569 |
|
| 570 |
3.9. grp_col (string) |
| 571 |
|
| 572 |
Name of address table column containing the group identifier of the |
| 573 |
address. |
| 574 |
|
| 575 |
Default value is “grp”. |
| 576 |
|
| 577 |
Example 1.9. Set grp_col parameter |
| 578 |
... |
| 579 |
modparam("permissions", "grp_col", "group_id") |
| 580 |
... |
| 581 |
|
| 582 |
3.10. ip_addr_col (string) |
| 583 |
|
| 584 |
Name of address table column containing the IP address part of the |
| 585 |
address. |
| 586 |
|
| 587 |
Default value is “ip_addr”. |
| 588 |
|
| 589 |
Example 1.10. Set ip_addr_col parameter |
| 590 |
... |
| 591 |
modparam("permissions", "ip_addr_col", "ip_address") |
| 592 |
... |
| 593 |
|
| 594 |
3.11. mask_col (string) |
| 595 |
|
| 596 |
Name of address table column containing the network mask of the |
| 597 |
address. Possible values are 0-32 for IPv4 and 0-128 for IPv6 |
| 598 |
addresses. If the value is 0, the network mask is set to 32 for IPv4 |
| 599 |
addresses and to 128 for IPv6 addresses. |
| 600 |
|
| 601 |
Default value is “mask”. |
| 602 |
|
| 603 |
Example 1.11. Set mask_col parameter |
| 604 |
... |
| 605 |
modparam("permissions", "mask_col", "subnet_length") |
| 606 |
... |
| 607 |
|
| 608 |
3.12. port_col (string) |
| 609 |
|
| 610 |
Name of address table column containing the port part of the address. |
| 611 |
|
| 612 |
Default value is “port”. |
| 613 |
|
| 614 |
Example 1.12. Set port_col parameter |
| 615 |
... |
| 616 |
modparam("permissions", "port_col", "port") |
| 617 |
... |
| 618 |
|
| 619 |
3.13. db_mode (integer) |
| 620 |
|
| 621 |
Database mode. 0 means non-caching, 1 means caching. Valid only for the |
| 622 |
allow_trusted function. |
| 623 |
|
| 624 |
Default value is 0 (non-caching). |
| 625 |
|
| 626 |
Example 1.13. Set db_mode parameter |
| 627 |
... |
| 628 |
modparam("permissions", "db_mode", 1) |
| 629 |
... |
| 630 |
|
| 631 |
3.14. trusted_table (string) |
| 632 |
|
| 633 |
Name of database table containing the matching rules used by the |
| 634 |
allow_trusted function. |
| 635 |
|
| 636 |
Default value is “trusted”. |
| 637 |
|
| 638 |
Example 1.14. Set trusted_table parameter |
| 639 |
... |
| 640 |
modparam("permissions", "trusted_table", "pbx") |
| 641 |
... |
| 642 |
|
| 643 |
3.15. source_col (string) |
| 644 |
|
| 645 |
Name of column in the “trusted” table containing the source IP address |
| 646 |
that is matched against source IP address of received request. |
| 647 |
|
| 648 |
Default value is “src_ip”. |
| 649 |
|
| 650 |
Example 1.15. Set source_col parameter |
| 651 |
... |
| 652 |
modparam("permissions", "source_col", "source_ip_address") |
| 653 |
... |
| 654 |
|
| 655 |
3.16. proto_col (string) |
| 656 |
|
| 657 |
Name of column in the “trusted” table containing the transport protocol |
| 658 |
that is matched against transport protocol of the received request. |
| 659 |
Possible values that can be stored in proto_col are “any”, “udp”, |
| 660 |
“tcp”, “tls”, “sctp”, “ws”, “wss”, and “none”. Value “any” matches |
| 661 |
always and value “none” never. |
| 662 |
|
| 663 |
Default value is “proto”. |
| 664 |
|
| 665 |
Example 1.16. Set proto_col parameter |
| 666 |
... |
| 667 |
modparam("permissions", "proto_col", "transport") |
| 668 |
... |
| 669 |
|
| 670 |
3.17. from_col (string) |
| 671 |
|
| 672 |
Name of the column trusted table containing a regular expression that |
| 673 |
is matched against the From URI. |
| 674 |
|
| 675 |
Default value is “from_pattern”. |
| 676 |
|
| 677 |
Example 1.17. Set from_col parameter |
| 678 |
... |
| 679 |
modparam("permissions", "from_col", "regexp") |
| 680 |
... |
| 681 |
|
| 682 |
3.18. ruri_col (string) |
| 683 |
|
| 684 |
Name of the column trusted table containing a regular expression that |
| 685 |
is matched against the Request URI. |
| 686 |
|
| 687 |
Default value is “ruri_pattern”. |
| 688 |
|
| 689 |
Example 1.18. Set ruri_col parameter |
| 690 |
... |
| 691 |
modparam("permissions", "ruri_col", "regexp") |
| 692 |
... |
| 693 |
|
| 694 |
3.19. tag_col (string) |
| 695 |
|
| 696 |
Name of the column in the “address” or “trusted” table containing a |
| 697 |
string that is added as value to peer_tag AVP if peer_tag AVP has been |
| 698 |
defined and if the address or peer matches. |
| 699 |
|
| 700 |
The tag_col field will be implicitly converted to a string when the |
| 701 |
database field is loaded into “peer_tag” AVP if the field type is |
| 702 |
supported. |
| 703 |
|
| 704 |
Default value is “tag”. |
| 705 |
|
| 706 |
Example 1.19. Set tag_col parameter |
| 707 |
... |
| 708 |
modparam("permissions", "tag_col", "peer_tag") |
| 709 |
... |
| 710 |
|
| 711 |
3.20. priority_col (string) |
| 712 |
|
| 713 |
The column name used to store the priority of the corresponding rule |
| 714 |
from the database row. Priority values should be integer. When db_mode |
| 715 |
is set to 1 (caching), priorities are ordered from highest to lowest. |
| 716 |
In non-caching mode, priority order (ASC vs DESC) is determined by |
| 717 |
database. |
| 718 |
|
| 719 |
Default value is “priority”. |
| 720 |
|
| 721 |
Example 1.20. Set priority_col parameter |
| 722 |
... |
| 723 |
modparam("permissions", "priority_col", "column_name") |
| 724 |
... |
| 725 |
|
| 726 |
3.21. peer_tag_avp (AVP string) |
| 727 |
|
| 728 |
If defined, the AVP will be set as a side effect of allow_trusted call |
| 729 |
to not NULL tag column value of the matching peer. |
| 730 |
|
| 731 |
Default value is “undefined”. |
| 732 |
|
| 733 |
Example 1.21. Set peer_tag_avp parameter |
| 734 |
... |
| 735 |
modparam("permissions", "peer_tag_avp", "$avp(i:707)") |
| 736 |
... |
| 737 |
|
| 738 |
3.22. peer_tag_mode (integer) |
| 739 |
|
| 740 |
Tag mode for allow_trusted. “0” sets only the tag of the first match. |
| 741 |
“1” adds the tags of all matches to the avp. In addition the return |
| 742 |
value of allow_trusted is the number of matches. This parameter is not |
| 743 |
used for address table matching functions. |
| 744 |
|
| 745 |
Default value is “0”. |
| 746 |
|
| 747 |
Example 1.22. Set peer_tag_mode parameter |
| 748 |
... |
| 749 |
modparam("permissions", "peer_tag_mode", 1) |
| 750 |
... |
| 751 |
|
| 752 |
3.23. max_subnets (int) |
| 753 |
|
| 754 |
The maximum number of subnet addresses to be loaded from address table. |
| 755 |
|
| 756 |
Default value is “512”. |
| 757 |
|
| 758 |
Example 1.23. Set max_subnets parameter |
| 759 |
... |
| 760 |
modparam("permissions", "max_subnets", 1024) |
| 761 |
... |
| 762 |
|
| 763 |
3.24. subnet_match_mode (int) |
| 764 |
|
| 765 |
Control how subnet addresses are matched: 0 - return on the first |
| 766 |
prefix match; 1 - return on the longest prefix match. It impacts |
| 767 |
functions like allow_source_address(), allow_address(), |
| 768 |
allow_source_address_group() or allow_address_group(). |
| 769 |
|
| 770 |
Default value is “0”. |
| 771 |
|
| 772 |
Example 1.24. Set subnet_match_mode parameter |
| 773 |
... |
| 774 |
modparam("permissions", "subnet_match_mode", 1) |
| 775 |
... |
| 776 |
|
| 777 |
3.25. load_backends (int) |
| 778 |
|
| 779 |
Control what backends should be loaded: 1 - address table; 2 - trusted |
| 780 |
table; 4 - allow file; 8 - deny file. |
| 781 |
|
| 782 |
It can be a combination (sum) of the options to load many backends |
| 783 |
(e.g., 3 - loads address and trusted tables). |
| 784 |
|
| 785 |
Default value is “0xffff” (load all backends). |
| 786 |
|
| 787 |
Example 1.25. Set load_backends parameter |
| 788 |
... |
| 789 |
modparam("permissions", "load_backends", 1) |
| 790 |
... |
| 791 |
|
| 792 |
3.26. reload_delta (int) |
| 793 |
|
| 794 |
The number of seconds that have to be waited before executing a new RPC |
| 795 |
reload. By default there is a rate limiting of maximum one reload in |
| 796 |
five seconds. |
| 797 |
|
| 798 |
If set to 0, no rate limit is configured. Note carefully: use this |
| 799 |
configuration only in tests environments because executing two RPC |
| 800 |
reloads of the same table at the same time can cause Kamailio to crash. |
| 801 |
|
| 802 |
Default value is “5”. |
| 803 |
|
| 804 |
Example 1.26. Set reload_delta parameter |
| 805 |
... |
| 806 |
modparam("permissions", "reload_delta", 1) |
| 807 |
... |
| 808 |
|
| 809 |
3.27. trusted_cleanup_interval (int) |
| 810 |
|
| 811 |
If module parameter db_mode is set to 1 a cleanup timer is set to the |
| 812 |
trusted_cleanup_interval value in seconds. This process will cleanup |
| 813 |
the previous values from memory after a RPC reload. |
| 814 |
|
| 815 |
Default value is “60”. |
| 816 |
|
| 817 |
Example 1.27. Set trusted_cleanup_interval parameter |
| 818 |
... |
| 819 |
modparam("permissions", "trusted_cleanup_interval", 120) |
| 820 |
... |
| 821 |
|
| 822 |
4. Functions |
| 823 |
|
| 824 |
4.1. allow_routing() |
| 825 |
4.2. allow_routing(basename) |
| 826 |
4.3. allow_routing(allow_file, deny_file) |
| 827 |
4.4. allow_register(basename) |
| 828 |
4.5. allow_register(allow_file, deny_file) |
| 829 |
4.6. allow_register_include_port(basename) |
| 830 |
4.7. allow_register_include_port(allow_file, deny_file) |
| 831 |
4.8. allow_uri(basename, pvar) |
| 832 |
4.9. allow_address(group_id, ip_addr_pvar, port_pvar) |
| 833 |
4.10. allow_source_address([group_id]) |
| 834 |
4.11. allow_source_address_group() |
| 835 |
4.12. allow_address_group(addr, port) |
| 836 |
4.13. allow_trusted([src_ip_pvar, proto_pvar, furi_pvar]) |
| 837 |
|
| 838 |
4.1. allow_routing() |
| 839 |
|
| 840 |
Returns true if all pairs constructed as described in Section 1.1, |
| 841 |
“Call Routing” have appropriate permissions according to the |
| 842 |
configuration files. This function uses default configuration files |
| 843 |
specified in default_allow_file and default_deny_file. |
| 844 |
|
| 845 |
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE. |
| 846 |
|
| 847 |
Example 1.28. allow_routing usage |
| 848 |
... |
| 849 |
if (allow_routing()) { |
| 850 |
t_relay(); |
| 851 |
}; |
| 852 |
... |
| 853 |
|
| 854 |
4.2. allow_routing(basename) |
| 855 |
|
| 856 |
Returns true if all pairs constructed as described in Section 1.1, |
| 857 |
“Call Routing” have appropriate permissions according to the |
| 858 |
configuration files given as parameters. |
| 859 |
|
| 860 |
Meaning of the parameters is as follows: |
| 861 |
* basename - Basename from which allow and deny filenames will be |
| 862 |
created by appending contents of allow_suffix and deny_suffix |
| 863 |
parameters. |
| 864 |
If the parameter doesn't contain full pathname then the function |
| 865 |
expects the file to be located in the same directory as the main |
| 866 |
configuration file of the server. |
| 867 |
|
| 868 |
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE. |
| 869 |
|
| 870 |
Example 1.29. allow_routing(basename) usage |
| 871 |
... |
| 872 |
if (allow_routing("basename")) { |
| 873 |
t_relay(); |
| 874 |
}; |
| 875 |
... |
| 876 |
|
| 877 |
4.3. allow_routing(allow_file, deny_file) |
| 878 |
|
| 879 |
Returns true if all pairs constructed as described in Section 1.1, |
| 880 |
“Call Routing” have appropriate permissions according to the |
| 881 |
configuration files given as parameters. |
| 882 |
|
| 883 |
Meaning of the parameters is as follows: |
| 884 |
* allow_file - File containing allow rules. |
| 885 |
If the parameter doesn't contain full pathname then the function |
| 886 |
expects the file to be located in the same directory as the main |
| 887 |
configuration file of the server. |
| 888 |
* deny_file - File containing deny rules. |
| 889 |
If the parameter doesn't contain full pathname then the function |
| 890 |
expects the file to be located in the same directory as the main |
| 891 |
configuration file of the server. |
| 892 |
|
| 893 |
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE. |
| 894 |
|
| 895 |
Example 1.30. allow_routing(allow_file, deny_file) usage |
| 896 |
... |
| 897 |
if (allow_routing("rules.allow", "rules.deny")) { |
| 898 |
t_relay(); |
| 899 |
}; |
| 900 |
... |
| 901 |
|
| 902 |
4.4. allow_register(basename) |
| 903 |
|
| 904 |
The function returns true if all pairs constructed as described in |
| 905 |
Section 1.2, “Registration Permissions” have appropriate permissions |
| 906 |
according to the configuration files given as parameters. |
| 907 |
|
| 908 |
Meaning of the parameters is as follows: |
| 909 |
* basename - Basename from which allow and deny filenames will be |
| 910 |
created by appending contents of allow_suffix and deny_suffix |
| 911 |
parameters. |
| 912 |
If the parameter doesn't contain full pathname then the function |
| 913 |
expects the file to be located in the same directory as the main |
| 914 |
configuration file of the server. |
| 915 |
|
| 916 |
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE. |
| 917 |
|
| 918 |
Example 1.31. allow_register(basename) usage |
| 919 |
... |
| 920 |
if (method=="REGISTER") { |
| 921 |
if (allow_register("register")) { |
| 922 |
save("location"); |
| 923 |
exit; |
| 924 |
} else { |
| 925 |
sl_send_reply("403", "Forbidden"); |
| 926 |
}; |
| 927 |
}; |
| 928 |
... |
| 929 |
|
| 930 |
4.5. allow_register(allow_file, deny_file) |
| 931 |
|
| 932 |
The function returns true if all pairs constructed as described in |
| 933 |
Section 1.2, “Registration Permissions” have appropriate permissions |
| 934 |
according to the configuration files given as parameters. |
| 935 |
|
| 936 |
Meaning of the parameters is as follows: |
| 937 |
* allow_file - File containing allow rules. |
| 938 |
If the parameter doesn't contain full pathname then the function |
| 939 |
expects the file to be located in the same directory as the main |
| 940 |
configuration file of the server. |
| 941 |
* deny_file - File containing deny rules. |
| 942 |
If the parameter doesn't contain full pathname then the function |
| 943 |
expects the file to be located in the same directory as the main |
| 944 |
configuration file of the server. |
| 945 |
|
| 946 |
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE. |
| 947 |
|
| 948 |
Example 1.32. allow_register(allow_file, deny_file) usage |
| 949 |
... |
| 950 |
if (method=="REGISTER") { |
| 951 |
if (allow_register("register.allow", "register.deny")) { |
| 952 |
save("location"); |
| 953 |
exit; |
| 954 |
} else { |
| 955 |
sl_send_reply("403", "Forbidden"); |
| 956 |
}; |
| 957 |
}; |
| 958 |
... |
| 959 |
|
| 960 |
4.6. allow_register_include_port(basename) |
| 961 |
|
| 962 |
The function does exacty the same thing as allow_register(basename) |
| 963 |
apart that it tells the module to include the port value of Contact |
| 964 |
into the check. No additional function parameters required. |
| 965 |
|
| 966 |
Meaning of the parameters is as follows: |
| 967 |
* basename - Basename from which allow and deny filenames will be |
| 968 |
created by appending contents of allow_suffix and deny_suffix |
| 969 |
parameters. |
| 970 |
If the parameter doesn't contain full pathname then the function |
| 971 |
expects the file to be located in the same directory as the main |
| 972 |
configuration file of the server. |
| 973 |
|
| 974 |
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE. |
| 975 |
|
| 976 |
Example 1.33. allow_register_include_port(basename) usage |
| 977 |
... |
| 978 |
if (method=="REGISTER") { |
| 979 |
if (allow_register_include_port("register")) { |
| 980 |
save("location"); |
| 981 |
exit; |
| 982 |
} else { |
| 983 |
sl_send_reply("403", "Forbidden"); |
| 984 |
}; |
| 985 |
}; |
| 986 |
... |
| 987 |
|
| 988 |
4.7. allow_register_include_port(allow_file, deny_file) |
| 989 |
|
| 990 |
The function does exacty the same thing as allow_register(allow_file, |
| 991 |
deny_file) apart that it tells the module to include the port value of |
| 992 |
Contact into the check. No additional function parameters required. |
| 993 |
|
| 994 |
Meaning of the parameters is as follows: |
| 995 |
* allow_file - File containing allow rules. |
| 996 |
If the parameter doesn't contain full pathname then the function |
| 997 |
expects the file to be located in the same directory as the main |
| 998 |
configuration file of the server. |
| 999 |
* deny_file - File containing deny rules. |
| 1000 |
If the parameter doesn't contain full pathname then the function |
| 1001 |
expects the file to be located in the same directory as the main |
| 1002 |
configuration file of the server. |
| 1003 |
|
| 1004 |
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE. |
| 1005 |
|
| 1006 |
Example 1.34. allow_register_include_port(allow_file, deny_file) usage |
| 1007 |
... |
| 1008 |
if (method=="REGISTER") { |
| 1009 |
if (allow_register_include_port("register.allow", "register.deny")) { |
| 1010 |
save("location"); |
| 1011 |
exit; |
| 1012 |
} else { |
| 1013 |
sl_send_reply("403", "Forbidden"); |
| 1014 |
}; |
| 1015 |
}; |
| 1016 |
... |
| 1017 |
|
| 1018 |
4.8. allow_uri(basename, pvar) |
| 1019 |
|
| 1020 |
Returns true if the pair constructed as described in Section 1.3, “URI |
| 1021 |
Permissions” have appropriate permissions according to the |
| 1022 |
configuration files specified by the parameter. |
| 1023 |
|
| 1024 |
Meaning of the parameter is as follows: |
| 1025 |
* basename - Basename from which allow and deny filenames will be |
| 1026 |
created by appending contents of allow_suffix and deny_suffix |
| 1027 |
parameters. |
| 1028 |
If the parameter doesn't contain full pathname then the function |
| 1029 |
expects the file to be located in the same directory as the main |
| 1030 |
configuration file of the server. |
| 1031 |
* pvar - Any pseudo-variable defined in Kamailio. |
| 1032 |
|
| 1033 |
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE. |
| 1034 |
|
| 1035 |
Example 1.35. allow_uri(basename, pvar) usage |
| 1036 |
... |
| 1037 |
if (allow_uri("basename", "$rt")) { // Check Refer-To URI |
| 1038 |
t_relay(); |
| 1039 |
}; |
| 1040 |
if (allow_uri("basename", "$avp(i:705)") { // Check URI stored in $avp(i:705) |
| 1041 |
t_relay(); |
| 1042 |
}; |
| 1043 |
... |
| 1044 |
|
| 1045 |
4.9. allow_address(group_id, ip_addr_pvar, port_pvar) |
| 1046 |
|
| 1047 |
Returns true if the address and port given as values of pvar arguments |
| 1048 |
belonging to a group given as group_id argument matches an IP subnet or |
| 1049 |
a DNS domain name found in cached address table. |
| 1050 |
|
| 1051 |
When matching is done if the argument is an IP address, it is matched |
| 1052 |
with the records from that group that are of type exact IP or subnet. |
| 1053 |
If the argument is not an IP it is tried to be matched with the records |
| 1054 |
that are DNS domain names. No DNS lookup is performed, only strict |
| 1055 |
matching. Cached address table entry containing port value “0” matches |
| 1056 |
any port. The “group_id” argument can be an integer string or a pseudo |
| 1057 |
variable. |
| 1058 |
|
| 1059 |
Note |
| 1060 |
|
| 1061 |
See Address permissions for more details. |
| 1062 |
|
| 1063 |
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE. |
| 1064 |
|
| 1065 |
Example 1.36. allow_address() usage |
| 1066 |
... |
| 1067 |
|
| 1068 |
// Check if source address/port is in group 1 |
| 1069 |
if (!allow_address("1", "$si", "$sp")) { |
| 1070 |
sl_send_reply("403", "Forbidden"); |
| 1071 |
}; |
| 1072 |
// Check address/port stored in AVPs src_adr/src_port is in group 2 |
| 1073 |
$avp(dst_adr) = "sipdomain.com"; |
| 1074 |
$avp(dst_port) = "0"; |
| 1075 |
if (!allow_address("2", "$avp(dst_adr)", "$avp(dst_port)") { |
| 1076 |
sl_send_reply("403", "Forbidden"); |
| 1077 |
}; |
| 1078 |
... |
| 1079 |
|
| 1080 |
4.10. allow_source_address([group_id]) |
| 1081 |
|
| 1082 |
Equal to “allow_address(group_id, "$si", "$sp")”. If 'group_id' is |
| 1083 |
missing, the function is equal to allow_address("1", "$si", "$sp"). |
| 1084 |
|
| 1085 |
Note |
| 1086 |
|
| 1087 |
See Address permissions for more details. |
| 1088 |
|
| 1089 |
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE. |
| 1090 |
|
| 1091 |
Example 1.37. allow_source_address(group_id) usage |
| 1092 |
... |
| 1093 |
|
| 1094 |
// Check source address/port of request |
| 1095 |
if (!allow_source_address("1")) { |
| 1096 |
sl_send_reply("403", "Forbidden"); |
| 1097 |
}; |
| 1098 |
... |
| 1099 |
|
| 1100 |
4.11. allow_source_address_group() |
| 1101 |
|
| 1102 |
Checks if source address/port is found in cached address or subnet |
| 1103 |
table in any group. If yes, returns that group. If not returns -1. Port |
| 1104 |
value 0 in cached address and group table matches any port. |
| 1105 |
|
| 1106 |
Note |
| 1107 |
|
| 1108 |
See Address permissions for more details on how searching is |
| 1109 |
implemented. |
| 1110 |
|
| 1111 |
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE. |
| 1112 |
|
| 1113 |
Example 1.38. allow_source_address_group() usage |
| 1114 |
... |
| 1115 |
|
| 1116 |
$var(group) = allow_source_address_group(); |
| 1117 |
if ($var(group) != -1) { |
| 1118 |
# do something with $var(group) |
| 1119 |
}; |
| 1120 |
... |
| 1121 |
|
| 1122 |
4.12. allow_address_group(addr, port) |
| 1123 |
|
| 1124 |
Checks if address/port is found in cached address or subnet table in |
| 1125 |
any group. If yes, returns that group. If not returns -1. Port value 0 |
| 1126 |
in cached address and group table matches any port. The parameters can |
| 1127 |
be pseudo-variables. |
| 1128 |
|
| 1129 |
Note |
| 1130 |
|
| 1131 |
See Address permissions for more details on how searching is |
| 1132 |
implemented. |
| 1133 |
|
| 1134 |
This function can be used from ANY_ROUTE. |
| 1135 |
|
| 1136 |
Example 1.39. allow_source_address_group() usage |
| 1137 |
... |
| 1138 |
|
| 1139 |
$var(group) = allow_address_group("1.2.3.4", "5060"); |
| 1140 |
if ($var(group) != -1) { |
| 1141 |
# do something with $var(group) |
| 1142 |
}; |
| 1143 |
... |
| 1144 |
|
| 1145 |
4.13. allow_trusted([src_ip_pvar, proto_pvar, furi_pvar]) |
| 1146 |
|
| 1147 |
Checks based either on request's source address and transport protocol |
| 1148 |
or source address and transport protocol given in pvar arguments, and |
| 1149 |
From URI of request (or furi_pvar if provided) if request can be |
| 1150 |
trusted without authentication. Returns “1” if a match is found as |
| 1151 |
described in Section 1.5, “Trusted Requests” and “-1” otherwise. If a |
| 1152 |
match is found and peer_tag_avp has been defined, adds a non-NULL tag |
| 1153 |
column value of the matching peer to AVP peer_tag_avp. |
| 1154 |
|
| 1155 |
NOTE: source IP is matched using string comparison. Be careful if the |
| 1156 |
IP can have different forms, for a safer alternative for matching IP |
| 1157 |
addresses, look at allow_source_address or allow_address(). |
| 1158 |
|
| 1159 |
Source address, transport protocol and uri given in the arguments must |
| 1160 |
be in string format and they can contain script variables. Valid |
| 1161 |
transport protocol values are (ignoring case) "any", "udp, "tcp", |
| 1162 |
"tls", "ws", "wss" and "sctp". |
| 1163 |
|
| 1164 |
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE. |
| 1165 |
|
| 1166 |
Example 1.40. allow_trusted() usage |
| 1167 |
... |
| 1168 |
if (allow_trusted()) { |
| 1169 |
t_relay(); |
| 1170 |
} |
| 1171 |
... |
| 1172 |
if (allow_trusted("$si", "$proto")) { |
| 1173 |
t_relay(); |
| 1174 |
} |
| 1175 |
... |
| 1176 |
if (allow_trusted("$si", "any", "$ai")) { |
| 1177 |
t_relay(); |
| 1178 |
} |
| 1179 |
... |
| 1180 |
|
| 1181 |
5. RPC Commands |
| 1182 |
|
| 1183 |
5.1. permissions.addressReload |
| 1184 |
5.2. permissions.addressDump |
| 1185 |
5.3. permissions.subnetDump |
| 1186 |
5.4. permissions.domainDump |
| 1187 |
5.5. permissions.testUri |
| 1188 |
5.6. permissions.allowUri |
| 1189 |
5.7. permissions.trustedReload |
| 1190 |
5.8. permissions.trustedDump |
| 1191 |
|
| 1192 |
5.1. permissions.addressReload |
| 1193 |
|
| 1194 |
Causes the permissions module to re-read the contents of address |
| 1195 |
database table into cache memory. In cache memory the entries are for |
| 1196 |
performance reasons stored in two different tables: address table and |
| 1197 |
subnet table depending on the value of the mask field (IPv6: 64 or |
| 1198 |
smaller, IPv4: 32 or smaller). Note that there is a rate limiting |
| 1199 |
defined by 'reload_delta' parameter. By default is allowed maximum one |
| 1200 |
reload in five seconds. |
| 1201 |
|
| 1202 |
Parameters: none |
| 1203 |
|
| 1204 |
This RPC command is exported with "RPC_EXEC_DELTA" flag, therefore its |
| 1205 |
execution rate can be restricted to specific time intervals by setting |
| 1206 |
the "rpc_exec_delta" core parameter. |
| 1207 |
|
| 1208 |
5.2. permissions.addressDump |
| 1209 |
|
| 1210 |
Causes the permissions module to dump the contents of cache memory |
| 1211 |
address table. (Not the subnet table). |
| 1212 |
|
| 1213 |
Parameters: none |
| 1214 |
|
| 1215 |
5.3. permissions.subnetDump |
| 1216 |
|
| 1217 |
Causes permissions module to dump contents of cache memory subnet |
| 1218 |
table. |
| 1219 |
|
| 1220 |
Parameters: none |
| 1221 |
|
| 1222 |
5.4. permissions.domainDump |
| 1223 |
|
| 1224 |
Causes permissions module to dump contents of cache memory domain |
| 1225 |
table. |
| 1226 |
|
| 1227 |
Parameters: none |
| 1228 |
|
| 1229 |
5.5. permissions.testUri |
| 1230 |
|
| 1231 |
Tests if the (URI, Contact) pair is allowed according to allow/deny |
| 1232 |
files. The files must already have been loaded by Kamailio. |
| 1233 |
|
| 1234 |
Parameters: |
| 1235 |
* basename - Basename from which allow and deny filenames will be |
| 1236 |
created by appending contents of the allow_suffix and deny_suffix |
| 1237 |
parameters. |
| 1238 |
* URI - URI to be tested |
| 1239 |
* Contact - Contact to be tested |
| 1240 |
|
| 1241 |
5.6. permissions.allowUri |
| 1242 |
|
| 1243 |
5.7. permissions.trustedReload |
| 1244 |
|
| 1245 |
Causes the permissions module to re-read the contents of the trusted |
| 1246 |
database table into cache memory. Note that there is a rate limiting |
| 1247 |
defined by 'reload_delta' parameter. By default is allowed maximum one |
| 1248 |
reload in five seconds. |
| 1249 |
|
| 1250 |
Parameters: none |
| 1251 |
|
| 1252 |
This RPC command is exported with "RPC_EXEC_DELTA" flag, therefore its |
| 1253 |
execution rate can be restricted to specific time intervals by setting |
| 1254 |
the "rpc_exec_delta" core parameter. |
| 1255 |
|
| 1256 |
5.8. permissions.trustedDump |
| 1257 |
|
| 1258 |
Causes the permissions module to dump contents of the trusted database |
| 1259 |
table from cache memory. |
| 1260 |
|
| 1261 |
Parameters: none |
| 1262 |
|
| 1263 |
6. Address File Format |
| 1264 |
|
| 1265 |
It is a text file with one record per line. Lines starting with '#' are |
| 1266 |
considered comments and ignored. Comments can be also at the end of |
| 1267 |
records, by using '#' to start the comment part of the line. |
| 1268 |
|
| 1269 |
Each record line has the format: |
| 1270 |
... |
| 1271 |
(groupid,int) (address,str) (netmask,int,o), (port,int,o) (tag,str,o) |
| 1272 |
... |
| 1273 |
|
| 1274 |
The groupid, address, netmask, port and tag are the names of the |
| 1275 |
attributes whose values are expected in the respective order. The 'int' |
| 1276 |
indicates that the value has to be an integer number. The 'str' |
| 1277 |
indicates that the value has to be a string. The 'o' indicates that the |
| 1278 |
attribute is optional. If netmask is not provided, it is set to 32 for |
| 1279 |
IPv4 addresses and 128 for IPv6 addresses. If port is not provided, it |
| 1280 |
is set to 0. The tag attribute is not set, if not provided. When |
| 1281 |
provided, the tag value has to be a single token, without whitespaces |
| 1282 |
(other punctuation signs can be in its value, like ',', '=', ';', ...). |
| 1283 |
|
| 1284 |
Example 1.41. Address File Sample |
| 1285 |
... |
| 1286 |
# address file - records to match with allow_address(...) and variants |
| 1287 |
# * file format details |
| 1288 |
# - comments start with # and go to end of line |
| 1289 |
# - each line corresponds to a record with following attributes: |
| 1290 |
# |
| 1291 |
# (groupid,int) (address,str) (netmask,int,o), (port,int,o) (tag,str,o) |
| 1292 |
# |
| 1293 |
# * description of the tokens used to describe line format |
| 1294 |
# - int: expected integer value |
| 1295 |
# - str: expected string value |
| 1296 |
# - o: optional field |
| 1297 |
|
| 1298 |
1 127.0.0.1 32 0 tag1 |
| 1299 |
1 10.0.0.10 |
| 1300 |
|
| 1301 |
2 192.168.1.0 24 0 tag2 |
| 1302 |
2 192.168.2.0 24 0 tag3 |
| 1303 |
|
| 1304 |
3 [1:5ee::900d:c0de] |
| 1305 |
... |
| 1306 |
|
| 1307 |
7. Register File Format |
| 1308 |
|
| 1309 |
It is a text file with one record per line. Lines starting with '#' are |
| 1310 |
considered comments and ignored. Comments can be also at the end of |
| 1311 |
records, by using '#' to start the comment part of the line. |
| 1312 |
|
| 1313 |
Each record line has the format: |
| 1314 |
... |
| 1315 |
(from_list,str) (req_uri_list,str) |
| 1316 |
... |
| 1317 |
|
| 1318 |
The 'str' indicates that the value has to be a string compatible with |
| 1319 |
POSIX Extended Regular Expressions. |
| 1320 |
|
| 1321 |
Example 1.42. Register File Sample |
| 1322 |
... |
| 1323 |
# Syntax: |
| 1324 |
# from_list [EXCEPT from_list] : req_uri_list [EXCEPT req_uri_list] |
| 1325 |
# |
| 1326 |
# from_list and req_uri_list are comma separated expressions |
| 1327 |
# Expressions are treated as case insensitive POSIX Extended Regular Expre |
| 1328 |
ssions. |
| 1329 |
# Keyword ALL matches any expression. |
| 1330 |
# |
| 1331 |
# Examples (requires a usage of allow_register() function): |
| 1332 |
# ALL : "^sip:361[0-9]*@abc\.com$" EXCEPT "^sip:361[0-9]*3@abc\.com$", "^s |
| 1333 |
ip:361[0-9]*4@abc\.com$" |
| 1334 |
# |
| 1335 |
# "^sip:3677[0-9]*@abc\.com$" : "^sip:361[0-9]*@abc\.com$" |
| 1336 |
# |
| 1337 |
# All : ALL |
| 1338 |
# |
| 1339 |
# Examples including port check (requires a usage of allow_register_include_port |
| 1340 |
() function): |
| 1341 |
# |
| 1342 |
# ALL : "^sip:.*@192.168.0.1:5062" |
| 1343 |
... |