| 1 |
The Ctl Module |
| 2 |
|
| 3 |
Andrei Pelinescu-Onciul |
| 4 |
|
| 5 |
iptelorg GmbH |
| 6 |
|
| 7 |
Copyright © 2009 iptelorg GmbH |
| 8 |
__________________________________________________________________ |
| 9 |
|
| 10 |
Table of Contents |
| 11 |
|
| 12 |
1. Admin Guide |
| 13 |
|
| 14 |
1. Overview |
| 15 |
2. BINRPC |
| 16 |
3. Parameters |
| 17 |
|
| 18 |
3.1. binrpc (string) |
| 19 |
3.2. binrpc_buffer_size (integer) |
| 20 |
3.3. mode (integer) |
| 21 |
3.4. user (integer or string) |
| 22 |
3.5. group (integer or string) |
| 23 |
3.6. fifo (integer) |
| 24 |
3.7. autoconversion (integer) |
| 25 |
3.8. binrpc_max_body_size (integer) |
| 26 |
3.9. binrpc_struct_max_body_size (integer) |
| 27 |
|
| 28 |
4. RPC Functions |
| 29 |
|
| 30 |
4.1. ctl.listen |
| 31 |
4.2. ctl.connections |
| 32 |
4.3. ctl.who |
| 33 |
|
| 34 |
List of Examples |
| 35 |
|
| 36 |
1.1. kamcmd example usage |
| 37 |
1.2. Set binrpc parameter |
| 38 |
1.3. Set binrpc_buffer_size parameter |
| 39 |
1.4. Set mode parameter |
| 40 |
1.5. Set user parameter |
| 41 |
1.6. Set group parameter |
| 42 |
1.7. Set fifo parameter |
| 43 |
1.8. Set the autoconversion parameter |
| 44 |
1.9. Set the binrpc_max_body_size parameter |
| 45 |
1.10. Set the binrpc_struct_max_body_size parameter |
| 46 |
1.11. print usage |
| 47 |
1.12. ctl.connections usage |
| 48 |
1.13. ctl.who usage |
| 49 |
|
| 50 |
Chapter 1. Admin Guide |
| 51 |
|
| 52 |
Table of Contents |
| 53 |
|
| 54 |
1. Overview |
| 55 |
2. BINRPC |
| 56 |
3. Parameters |
| 57 |
|
| 58 |
3.1. binrpc (string) |
| 59 |
3.2. binrpc_buffer_size (integer) |
| 60 |
3.3. mode (integer) |
| 61 |
3.4. user (integer or string) |
| 62 |
3.5. group (integer or string) |
| 63 |
3.6. fifo (integer) |
| 64 |
3.7. autoconversion (integer) |
| 65 |
3.8. binrpc_max_body_size (integer) |
| 66 |
3.9. binrpc_struct_max_body_size (integer) |
| 67 |
|
| 68 |
4. RPC Functions |
| 69 |
|
| 70 |
4.1. ctl.listen |
| 71 |
4.2. ctl.connections |
| 72 |
4.3. ctl.who |
| 73 |
|
| 74 |
1. Overview |
| 75 |
|
| 76 |
This module implements the binrpc transport interface for Kamailio |
| 77 |
RPCs. It supports various transports over which it speaks binrpc: Unix |
| 78 |
datagram sockets, Unix stream sockets, UDP and TCP. It also supports a |
| 79 |
backward compatible FIFO interface (using the old Kamailio FIFO |
| 80 |
protocol). |
| 81 |
|
| 82 |
By default (if no parameters are changed in the config file) it uses a |
| 83 |
Unix stream socket under /run/kamailio: /run/kamailio/kamailio_ctl. |
| 84 |
This socket is also the default for kamcmd. |
| 85 |
|
| 86 |
In general it's used in conjunction with kamcmd. kamcmd is a Unix tool |
| 87 |
for invoking Kamailio RPC functions. It can be used both in interactive |
| 88 |
mode (supports tab-completion and history) or command line mode. |
| 89 |
|
| 90 |
Example 1.1. kamcmd example usage |
| 91 |
$ kamcmd ps |
| 92 |
11262 attendant |
| 93 |
11268 udp receiver child=0 sock=127.0.0.1:5060 |
| 94 |
11269 udp receiver child=1 sock=127.0.0.1:5060 |
| 95 |
11270 udp receiver child=0 sock=192.168.1.101:5060 |
| 96 |
11271 udp receiver child=1 sock=192.168.1.101:5060 |
| 97 |
11272 slow timer |
| 98 |
11273 timer |
| 99 |
11274 ctl handler |
| 100 |
11275 tcp receiver child=0 |
| 101 |
11276 tcp receiver child=1 |
| 102 |
11277 tcp main process |
| 103 |
|
| 104 |
See utils/kamcmd/EXAMPLES for more examples. |
| 105 |
|
| 106 |
2. BINRPC |
| 107 |
|
| 108 |
binrpc is a Kamailio proprietary binary protocol for invoking rpcs. It |
| 109 |
was designed such that it would minimize the packet sizes and it would |
| 110 |
be very fast to parse (as opposed to XML-rpc). |
| 111 |
|
| 112 |
The binrpc encoding format is fully documented inside |
| 113 |
modules/ctl/binrpc.h. |
| 114 |
|
| 115 |
3. Parameters |
| 116 |
|
| 117 |
3.1. binrpc (string) |
| 118 |
3.2. binrpc_buffer_size (integer) |
| 119 |
3.3. mode (integer) |
| 120 |
3.4. user (integer or string) |
| 121 |
3.5. group (integer or string) |
| 122 |
3.6. fifo (integer) |
| 123 |
3.7. autoconversion (integer) |
| 124 |
3.8. binrpc_max_body_size (integer) |
| 125 |
3.9. binrpc_struct_max_body_size (integer) |
| 126 |
|
| 127 |
3.1. binrpc (string) |
| 128 |
|
| 129 |
Specifies the transport used for the binrpc protocol. The following |
| 130 |
transport protocol are supported: Unix datagram sockets, Unix stream |
| 131 |
sockets, UDP and TCP. |
| 132 |
|
| 133 |
The format is: [ protocol:] address_port|path . |
| 134 |
|
| 135 |
* For Unix sockets: [unixd|unixs|unix]:path where "unixd" means Unix |
| 136 |
datagram sockets and "unix" "unixs" mean Unix stream sockets. |
| 137 |
Examples: "unixd:/tmp/unix_dgram", "unixs:/tmp/unix_stream", |
| 138 |
"unix:/tmp/unix_stream". |
| 139 |
* For UDP or TCP sockets: [udp|tcp]:address:port. If the address is |
| 140 |
"*" or missing, it will bind to all the local addresses (0.0.0.0). |
| 141 |
Examples: "udp:localhost:2046", "tcp:localhost:2046", "tcp:3012", |
| 142 |
"udp:*:3012". |
| 143 |
|
| 144 |
If the protocol part is missing and the address/path part looks like a |
| 145 |
file system path it will default to a Unix stream socket and if not to |
| 146 |
a Unix UDP socket. Examples: |
| 147 |
* "/tmp/unix_test" - equivalent to "unixs:/tmp/unix_test". |
| 148 |
* "localhost:3000" - equivalent to "udp:localhost:3000". |
| 149 |
|
| 150 |
Multiple transports / listen addresses can be specified, just by |
| 151 |
setting the parameter multiple times. |
| 152 |
|
| 153 |
Default: "unix:/run/kamailio/kamailio_ctl" (Unix stream socket). The |
| 154 |
default value is used only if no binrpc parameter is found in the |
| 155 |
config file. |
| 156 |
|
| 157 |
Example 1.2. Set binrpc parameter |
| 158 |
loadmodule "ctl" |
| 159 |
# optional listen addresses, if no one is specified, |
| 160 |
# ctl will listen on unixs:/tmp/kamailio_ctl |
| 161 |
|
| 162 |
modparam("ctl", "binrpc", "unix:/run/kamailio/kamailio_ctl") # default |
| 163 |
modparam("ctl", "binrpc", "udp:localhost:2046") |
| 164 |
modparam("ctl", "binrpc", "tcp:localhost:2046") |
| 165 |
modparam("ctl", "binrpc", "unixd:/tmp/unix_dgram") # unix datagram |
| 166 |
modparam("ctl", "binrpc", "unixs:/tmp/unix_stream") # unix stream |
| 167 |
modparam("ctl", "binrpc", "unix:/tmp/unix_default") # unix stream |
| 168 |
modparam("ctl", "binrpc", "/tmp/unix_test") # unix stream |
| 169 |
modparam("ctl", "binrpc", "localhost:3000") # udp |
| 170 |
modparam("ctl", "binrpc", "tcp:3012") # tcp any , port 3012 |
| 171 |
modparam("ctl", "binrpc", "udp:*:3012") # udp any , port 3012 |
| 172 |
|
| 173 |
3.2. binrpc_buffer_size (integer) |
| 174 |
|
| 175 |
The size of the internal buffer used for printing elements of the RPC |
| 176 |
response (e.g., internal RPC printf()). The value is given in bytes. |
| 177 |
|
| 178 |
Default: 1024. |
| 179 |
|
| 180 |
Example 1.3. Set binrpc_buffer_size parameter |
| 181 |
... |
| 182 |
modparam("ctl", "binrpc_buffer_size", 4096) |
| 183 |
... |
| 184 |
|
| 185 |
3.3. mode (integer) |
| 186 |
|
| 187 |
Permissions used for the created Unix sockets or for the fifo. |
| 188 |
|
| 189 |
Default: 0600. |
| 190 |
|
| 191 |
Example 1.4. Set mode parameter |
| 192 |
modparam("ctl", "mode", 0600) # permissions |
| 193 |
|
| 194 |
3.4. user (integer or string) |
| 195 |
|
| 196 |
Username or uid used for the created Unix sockets or for the fifo. |
| 197 |
|
| 198 |
Default: not set (the user under which SER runs). |
| 199 |
|
| 200 |
Example 1.5. Set user parameter |
| 201 |
... |
| 202 |
modparam("ctl", "user", "andrei") |
| 203 |
... |
| 204 |
|
| 205 |
3.5. group (integer or string) |
| 206 |
|
| 207 |
Group name or gid used for the created Unix sockets or for the fifo. |
| 208 |
|
| 209 |
Default: not set (the group under which SER runs). |
| 210 |
|
| 211 |
Example 1.6. Set group parameter |
| 212 |
... |
| 213 |
modparam("ctl", "group", 100) |
| 214 |
... |
| 215 |
|
| 216 |
3.6. fifo (integer) |
| 217 |
|
| 218 |
fifo used for the obsolete fifo protocol. The fifo protocol can be run |
| 219 |
over a real fifo, over UDP or over TCP. Format: |
| 220 |
[protocol:]path|address. If no protocol is specified the default is |
| 221 |
"fifo". Examples: "fifo:/tmp/kamailio_fifo", "/tmp/kamailio_fifo2", |
| 222 |
"udp:*:2050", "tcp:localhost:2050". For more details on the UDP and TCP |
| 223 |
formats see binrpc. Multiple fifos or fifo transports can be used in |
| 224 |
the same time (just by setting the fifo parameter multiple times in the |
| 225 |
config). |
| 226 |
|
| 227 |
Default: not set (no fifo will be used). |
| 228 |
|
| 229 |
Example 1.7. Set fifo parameter |
| 230 |
... |
| 231 |
# old fifo support |
| 232 |
modparam("ctl", "fifo", "fifo:/tmp/kamailio_fifo") # classic fifo |
| 233 |
modparam("ctl", "fifo", "/tmp/kamailio_fifo2") |
| 234 |
modparam("ctl", "fifo", "udp:*:2050") # fifo protocol over udp |
| 235 |
modparam("ctl", "fifo", "tcp:*:2050") # fifo over tcp |
| 236 |
... |
| 237 |
|
| 238 |
3.7. autoconversion (integer) |
| 239 |
|
| 240 |
Enable or disable automatic type conversion globally, for all the |
| 241 |
methods parameters. If on, a type mismatch in a method parameter will |
| 242 |
not cause a fault if it is possible to automatically convert it to the |
| 243 |
expected type. |
| 244 |
|
| 245 |
Default: off |
| 246 |
|
| 247 |
It is recommended to leave this parameter to its default off value and |
| 248 |
fix instead the client application (which should use the proper types) |
| 249 |
or to modify the target rpc to accept any type (see the rpc scan '.' |
| 250 |
modifier). |
| 251 |
|
| 252 |
Example 1.8. Set the autoconversion parameter |
| 253 |
... |
| 254 |
modparam("ctl", "autoconversion", 1) |
| 255 |
... |
| 256 |
|
| 257 |
3.8. binrpc_max_body_size (integer) |
| 258 |
|
| 259 |
Set the size of binrpc buffer for RPC reply. Value represents |
| 260 |
kilobytes. |
| 261 |
|
| 262 |
Default: 32 (meaning 32KB); |
| 263 |
|
| 264 |
Example 1.9. Set the binrpc_max_body_size parameter |
| 265 |
... |
| 266 |
modparam("ctl", "binrpc_max_body_size", 16) |
| 267 |
... |
| 268 |
|
| 269 |
3.9. binrpc_struct_max_body_size (integer) |
| 270 |
|
| 271 |
Set the size of binrpc structure buffer for RPC reply. Value represents |
| 272 |
kilobytes. |
| 273 |
|
| 274 |
Default: 8 (meaning 8KB); |
| 275 |
|
| 276 |
Example 1.10. Set the binrpc_struct_max_body_size parameter |
| 277 |
... |
| 278 |
modparam("ctl", "binrpc_struct_max_body_size", 4) |
| 279 |
... |
| 280 |
|
| 281 |
4. RPC Functions |
| 282 |
|
| 283 |
4.1. ctl.listen |
| 284 |
4.2. ctl.connections |
| 285 |
4.3. ctl.who |
| 286 |
|
| 287 |
4.1. ctl.listen |
| 288 |
|
| 289 |
List all the sockets on which the ctl module listens. |
| 290 |
|
| 291 |
Example 1.11. print usage |
| 292 |
$ kamcmd -f"[%v] %v:%v %v\n" ctl.listen |
| 293 |
[binrpc] unix_stream:/run/kamailio/kamailio_ctl |
| 294 |
|
| 295 |
# note: the above command is equivalent with kamcmd listen |
| 296 |
|
| 297 |
4.2. ctl.connections |
| 298 |
|
| 299 |
Returns the number of open binrpc connections (to the ctl module). |
| 300 |
|
| 301 |
Example 1.12. ctl.connections usage |
| 302 |
$ kamcmd ctl.connections |
| 303 |
1 |
| 304 |
|
| 305 |
4.3. ctl.who |
| 306 |
|
| 307 |
List open binrpc connections (to the ctl module). |
| 308 |
|
| 309 |
Example 1.13. ctl.who usage |
| 310 |
$ kamcmd -f"[%v] %v: %v %v -> %v %v\n" ctl.who |
| 311 |
[binrpc] unix_stream: <anonymous unix socket> -> /run/kamailio/kamailio_ctl |
| 312 |
|
| 313 |
# note the above command is equivalent to kamcmd who |