1NOSIP Module 2 3Daniel-Constantin Mierla 4 5 <miconda@gmail.com> 6 7Edited by 8 9Daniel-Constantin Mierla 10 11 <miconda@gmail.com> 12 13 Copyright © 2014 asipto.com 14 __________________________________________________________________ 15 16 Table of Contents 17 18 1. Admin Guide 19 20 1. Overview 21 2. Dependencies 22 23 2.1. Kamailio Modules 24 2.2. External Libraries or Applications 25 26 3. Parameters 27 28 3.1. msg_match (str) 29 3.2. msg_skip (str) 30 31 4. Event Routes 32 33 4.1. event_route[nosip:msg] 34 35 5. Examples of Usage 36 37 List of Examples 38 39 1.1. Set msg_match parameter 40 1.2. Set msg_match parameter 41 1.3. event_route[nosip:msg] usage 42 1.4. event_route[nosip:msg] use case 43 44Chapter 1. Admin Guide 45 46 Table of Contents 47 48 1. Overview 49 2. Dependencies 50 51 2.1. Kamailio Modules 52 2.2. External Libraries or Applications 53 54 3. Parameters 55 56 3.1. msg_match (str) 57 3.2. msg_skip (str) 58 59 4. Event Routes 60 61 4.1. event_route[nosip:msg] 62 63 5. Examples of Usage 64 651. Overview 66 67 This module provides a way to get access to non-SIP packages received 68 by Kamailio via its SIP worker processes. The content of such packages 69 is available in the $mb variable inside the event_route[nosip:msg]. 70 71 Note that packets with size less than 32 bytes are discarded, this 72 threshold being set to avoid handling the NAT keepalive packets coming 73 from devices. The limit is planned to be made configurable. Also, by 74 default Kamailio writes a log messages in case of SIP parsing error, 75 that can be controlled via 'corelog' global parameter. 76 77 Besides the content of the packet, $si and $sp provide the source IP 78 and port, allowing to do filtering and authorization. 79 802. Dependencies 81 82 2.1. Kamailio Modules 83 2.2. External Libraries or Applications 84 852.1. Kamailio Modules 86 87 The following modules must be loaded before this module: 88 * none. 89 902.2. External Libraries or Applications 91 92 The following libraries or applications must be installed before 93 running Kamailio with this module loaded: 94 * none 95 963. Parameters 97 98 3.1. msg_match (str) 99 3.2. msg_skip (str) 100 1013.1. msg_match (str) 102 103 Regular expression to match against content of the packet in order to 104 execute the event_route[nosip:msg]. 105 106 Default value is empty. 107 108 Example 1.1. Set msg_match parameter 109... 110modparam("nosip", "msg_match", "^KREQUEST-") 111... 112 1133.2. msg_skip (str) 114 115 Regular expression to match against content of the packet in order to 116 skip execution the event_route[nosip:msg]. 117 118 Default value is empty. 119 120 Example 1.2. Set msg_match parameter 121... 122modparam("nosip", "msg_skip", "^GET ") 123... 124 1254. Event Routes 126 127 4.1. event_route[nosip:msg] 128 1294.1. event_route[nosip:msg] 130 131 Event route block to be executed when a non-sip message is received by 132 a SIP worker process. 133 134 The routename parameter can be a static string or a dynamic string 135 value with config variables. 136 137 The sleep parameter represent the number of seconds to suspend the 138 processing of a SIP request. Maximum value is 100. The parameter can be 139 a static integer or a variable holding an integer. 140 141 Since the SIP request handling is resumed in another process, the 142 config file execution state is practically lost. Therefore beware that 143 the execution of config after resume will end once the route[routename] 144 is finished. 145 146 This function can be used from REQUEST_ROUTE. 147 148 Example 1.3. event_route[nosip:msg] usage 149... 150loadmodule "nosip.so" 151... 152event_route[nosip:msg] { 153 xlog("non-sip packet received - content [[$mb]] from [$si:$sp]\n"); 154 exit; 155} 156... 157 1585. Examples of Usage 159 160 There can be many useful cases when one wants to get a SIP worker back 161 to handle a suspended SIP transaction. While this could be achieved via 162 XMLRPC or HTTP for TCP workers, UDP workers are the least loaded in 163 terms of network interaction layer (ie., there is no overhead for 164 connections management like for TCP). 165 166 Parsing of the non-sip message can be done using config file actions: 167 functions, expressions with variables and transformations. 168 169 Next is a basic example of parsing a message from the network and 170 resuming the transaction. 171 172 Example 1.4. event_route[nosip:msg] use case 173... 174# expect: :KREQUEST-RESUME-TRANSACTION:tindex:tlabel:routename: 175# example: :KREQUEST-RESUME-TRANSACTION:4242:8686:RESUME: 176loadmodule "nosip.so" 177... 178event_route[nosip:msg] { 179 xlog("non-sip packet received - content [[$mb]] from [$si:$sp]\n"); 180 181 # must be a trusted IP 182 if($si!="127.0.0.1") { 183 exit; 184 } 185 186 # validation of the format and resume transaction 187 if($mb=~":KREQUEST-RESUME-TRANSACTION:[0-9]+:[0-9]+:[a-zA-Z0-9]+:$") { 188 $var(tindex) = $(mb{s.select,1,:}); 189 $var(tlabel) = $(mb{s.select,2,:}); 190 $var(rname) = $(mb{s.select,3,:}); 191 t_continue("$var(tindex)", "$var(tlabel)", "$var(rname)"); 192 } 193 exit; 194} 195 196route[RESUME] { 197 ... 198} 199... 200