-
Notifications
You must be signed in to change notification settings - Fork 41
/
registrar-role.cfg
588 lines (500 loc) · 22.8 KB
/
registrar-role.cfg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
#### NAT PINGING PARAMS ###
#!trydef REGISTRAR_NAT_PING_INTERVAL 30
## REGISTRAR_NAT_PING_TIMEOUT should be (REGISTRAR_NAT_PING_INTERVAL * 3 + 10) or 0 to disable
#!trydef REGISTRAR_NAT_PING_TIMEOUT 0
#!trydef REGISTRAR_NAT_PING_NAT_ONLY 1
#!trydef REGISTRAR_NAT_PING_WORKERS 5
#####
#!trydef REGISTRAR_MIN_EXPIRES 300
#!trydef REGISTRAR_MAX_EXPIRES 3600
#!trydef REGISTRAR_DEFAULT_EXPIRES 600
#!trydef REGISTRAR_ERROR_MIN_EXPIRES 1
#!trydef REGISTRAR_ERROR_MISSING_EXPIRES 1
#!trydef REGISTRAR_CONTACT_MAX_SIZE 2048
#!trydef REGISTRAR_QUERY_TIMEOUT_MS 2500
#!trydef REGISTRAR_HANDLE_LOST_TCP 1
#!trydef REGISTRAR_CLOSE_EXPIRED_TCP 1
#!trydef REGISTRAR_HANDLE_EXPIRED_TCP 1
#!trydef REGISTRAR_HANDLE_EXPIRED_UDP 0
#!trydef REGISTRAR_HANDLE_EXPIRED_TLS 1
#!trydef REGISTRAR_HANDLE_EXPIRED_WS 1
#!trydef REGISTRAR_FORCE_QUERY 0
#!trydef REGISTRAR_FORCE_FAILOVER 0
#!trydef REGISTRAR_CHECK_AMQP_AVAILABILITY 1
#!trydef KZ_REGISTRAR_KEEPALIVE_UDP_ONLY 1
#!trydef REGISTRAR_AMQP_EXCHANGE callmgr
#!trydef REGISTRAR_AMQP_FLAGS 0
#!trydef REGISTRAR_AMQP_RK_PREFIX authn.req.
#!trydef REGISTRAR_SEND_100 1
#!trydef REGISTRAR_DB_MODE 2
#!trydef REGISTRAR_DB_TIMER_CLEANUP 0
#!trydef REGISTRAR_DB_REMOVE_EXPIRED_DELAY 0
#!trydef REGISTRAR_SYNC_TIMER_INTERVAL 5
#!trydef REGISTRAR_SYNC_TIMER_PROCS 1
#!ifdef REGISTRAR_WARM_CACHE
#!substdef "!REGISTRAR_S_WARM_CACHE!dbtable=auth_cache;dbmode=1;!g"
#!else
#!substdef "!REGISTRAR_S_WARM_CACHE!!g"
#!endif
######## Generic Hash Table container in shared memory ########
modparam("htable", "htable", "auth_cache=>size=16;autoexpire=7200;REGISTRAR_S_WARM_CACHE")
####### Authentication Interface module ##########
loadmodule "auth.so"
####### User Location Implementation module ##########
loadmodule "usrloc.so"
modparam("usrloc", "db_update_as_insert", 0)
modparam("usrloc", "use_domain", 1)
modparam("usrloc", "nat_bflag", FLB_NATB)
modparam("usrloc", "db_url", "KAZOO_DB_URL")
modparam("usrloc", "db_mode", REGISTRAR_DB_MODE)
modparam("usrloc", "db_timer_clean", REGISTRAR_DB_TIMER_CLEANUP)
modparam("usrloc", "handle_lost_tcp", REGISTRAR_HANDLE_LOST_TCP)
modparam("usrloc", "rm_expired_delay", REGISTRAR_DB_REMOVE_EXPIRED_DELAY)
modparam("usrloc", "db_check_update", 1)
modparam("usrloc", "db_ops_ruid", 1)
modparam("usrloc", "xavp_contact", "ulattrs")
modparam("usrloc", "timer_interval", REGISTRAR_SYNC_TIMER_INTERVAL)
modparam("usrloc", "timer_procs", REGISTRAR_SYNC_TIMER_PROCS)
modparam("usrloc", "fetch_rows", 400)
modparam("usrloc", "handle_lost_tcp", REGISTRAR_HANDLE_LOST_TCP)
modparam("usrloc", "close_expired_tcp", REGISTRAR_CLOSE_EXPIRED_TCP)
####### SIP Registrar implementation module ##########
loadmodule "registrar.so"
modparam("registrar", "received_avp", "$avp(AVP_RECV_PARAM)")
modparam("registrar", "min_expires", REGISTRAR_MIN_EXPIRES)
modparam("registrar", "max_expires", REGISTRAR_MAX_EXPIRES)
modparam("registrar", "default_expires", REGISTRAR_DEFAULT_EXPIRES)
modparam("registrar", "xavp_cfg", "regcfg")
modparam("registrar", "gruu_enabled", 1)
modparam("registrar", "outbound_mode", 1)
modparam("registrar", "regid_mode", 1)
modparam("registrar", "path_mode", 1)
modparam("registrar", "use_path", 1)
modparam("registrar", "received_param", "")
modparam("registrar", "xavp_rcd", "ulrcd")
modparam("registrar", "contact_max_size", REGISTRAR_CONTACT_MAX_SIZE)
####### NAT ##########
#!ifdef NAT_TRAVERSAL_ROLE
#!ifndef NATHELPER_LOADED
loadmodule "nathelper.so"
#!trydef NATHELPER_LOADED
#!endif
#!ifdef KEEPALIVE_ROLE
modparam("nathelper", "natping_interval", 0)
modparam("nathelper", "natping_processes", 0)
#!else
modparam("nathelper", "natping_interval", REGISTRAR_NAT_PING_INTERVAL)
modparam("nathelper", "ping_nated_only", REGISTRAR_NAT_PING_NAT_ONLY)
modparam("nathelper", "natping_processes", REGISTRAR_NAT_PING_WORKERS)
modparam("nathelper", "sipping_bflag", FLB_NATSIPPING)
modparam("nathelper", "keepalive_timeout", REGISTRAR_NAT_PING_TIMEOUT)
#!endif
#!endif
## stats ##
modparam("statistics","variable", "registrar:force_failover")
modparam("statistics","variable", "registrar:cached")
modparam("statistics","variable", "registrar:ip_realm")
modparam("statistics","variable", "registrar:new_tran")
modparam("statistics","variable", "registrar:amqp_not_available")
modparam("statistics","variable", "registrar:challenge")
modparam("statistics","variable", "registrar:amqp_async_error")
modparam("statistics","variable", "registrar:amqp_returned")
modparam("statistics","variable", "registrar:amqp_timeout")
modparam("statistics","variable", "registrar:drops")
modparam("statistics","variable", "registrar:authn_perm_err")
modparam("statistics","variable", "registrar:authn_err")
modparam("statistics","variable", "registrar:authn_resp")
modparam("statistics","variable", "registrar:authn_unknown")
modparam("statistics","variable", "registrar:save_error")
modparam("statistics","variable", "registrar:missing_expires")
modparam("statistics","variable", "registrar:missing_expires_allowed")
modparam("statistics","variable", "registrar:min_expires")
modparam("statistics","variable", "registrar:min_expires_allowed")
##### registrar realtime params #####
kazoo.registrar_error_min_expires = REGISTRAR_ERROR_MIN_EXPIRES descr "send error when UAS sends expires < min-expires"
kazoo.registrar_error_missing_expires = REGISTRAR_ERROR_MISSING_EXPIRES descr "send error when UAS do not send expires header"
kazoo.registrar_handle_expired_tcp = REGISTRAR_HANDLE_EXPIRED_TCP descr "handles expired tcp registrations"
kazoo.registrar_handle_expired_udp = REGISTRAR_HANDLE_EXPIRED_UDP descr "handles expired udp registrations"
kazoo.registrar_handle_expired_tls = REGISTRAR_HANDLE_EXPIRED_TLS descr "handles expired tls registrations"
kazoo.registrar_handle_expired_ws = REGISTRAR_HANDLE_EXPIRED_WS descr "handles expired ws registrations"
kazoo.registrar_query_timeout_ms = REGISTRAR_QUERY_TIMEOUT_MS descr "timeout waiting for reply from registrar"
kazoo.registrar_failover = REGISTRAR_FORCE_FAILOVER descr "force failover if 1"
kazoo.registrar_force_query = REGISTRAR_FORCE_QUERY descr "force query if 1"
kazoo.registrar_check_amqp_availability = REGISTRAR_CHECK_AMQP_AVAILABILITY descr "checks if amqp connection is available before querying registrar"
kazoo.registrar_keepalive_udp_only = KZ_REGISTRAR_KEEPALIVE_UDP_ONLY descr "should we keepalive nat phones for udp only"
kazoo.registrar_send_100 = REGISTRAR_SEND_100 descr "should we send 100 reply while doing directory search"
####### Registrar Logic ########
route[REGISTRAR_NAT_FLAGS]
{
if (isflagset(FLT_NATS)) {
xlog("L_DEBUG", "$ci|log|fixing contact for nat request\n");
setbflag(FLB_NATB);
fix_nated_register();
## KAZOO-1846: Cisco SPA8000 freaks out on options pings
if (!($ua =~ "Linksys/SPA8000"
|| $ua =~ "SIPp"
|| (af==INET6)
|| ($sel(cfg_get.kazoo.registrar_keepalive_udp_only) == 1 && $proto != "udp")
|| ($proto =="ws" || $proto == "wss")
|| ($(xavp(ulattrs=>custom_channel_vars){kz.json,Keep-Alive}) == "false")
)) {
xlog("L_DEBUG", "$ci|log|set nat pinging\n");
setbflag(FLB_NATSIPPING);
}
} else {
$avp(AVP_RECV_PARAM) = $su;
}
}
route[HANDLE_REGISTER]
{
if (!is_method("REGISTER")) {
return;
}
#!ifdef PUSHER_ROLE
route(PUSHER_ATTEMPT_REGISTRATION);
#!endif
if($sel(cfg_get.kazoo.registrar_failover) == 1) {
xlog("L_INFO", "$ci|log|register|forcing failover\n");
update_stat("registrar:force_failover", "+1");
drop;
}
if($sel(cfg_get.kazoo.registrar_force_query) == 0) {
if($sht(auth_cache=>$Au) == "authn_perm_err") {
xlog("L_INFO", "$ci|end|issuing auth challenge to cached permanent failed registration attempt for $Au from IP $si:$sp\n");
update_stat("registrar:authn_perm_err", "+1");
#!ifdef ANTIFLOOD_ROLE
route(ANITFLOOD_FAILED_AUTH);
#!endif
update_stat("registrar:challenge", "+1");
auth_challenge("$fd", "4");
exit;
} else if($sht(auth_cache=>$Au) != $null) {
$xavp(regcfg=>match_received) = $su;
if(registered("location", "$rz:$Au", 2, 1) == 1) {
if($(xavp(ulattrs=>custom_channel_vars){s.len}) > 1) {
$var(password) = $sht(auth_cache=>$Au);
update_stat("registrar:cached", "+1");
route(SAVE_LOCATION);
exit;
}
}
}
}
if($td =~ "[0-9]{1,3}\.[0-9]{1,3}.[0-9]{1,3}\.[0-9]{1,3}" ||
$fd =~ "[0-9]{1,3}\.[0-9]{1,3}.[0-9]{1,3}\.[0-9]{1,3}") {
xlog("L_INFO", "$ci|log|register|invalid domain\n");
update_stat("registrar:ip_realm", "+1");
drop;
}
if($sel(cfg_get.kazoo.registrar_check_amqp_availability) == 1) {
if($xavp(amqpc=>default::MY_AMQP_ZONE) == 0) {
xlog("L_WARNING", "$ci|end|register|no amqp connection available for default worker in zone MY_AMQP_ZONE\n");
update_stat("registrar:amqp_not_available", "+1");
drop;
}
}
route(REGISTRAR_BOUNDS);
$var(auth) = pv_auth_check("$fd", "$uuid(g)", "0", "0");
if($var(auth) != -2) {
xlog("L_INFO", "$ci|end|challenging $Au $si:$sp\n");
$var(auth) = auth_challenge("$fd", "4");
update_stat("registrar:challenge", "+1");
if($var(auth) != 1) {
xlog("L_ERROR", "$ci|register|error creating or sending challenge to registration attempt for $fu from $si:$sp\n");
drop;
}
exit;
}
if (!t_newtran()) {
xlog("L_ERROR", "$ci|log|failed to create transaction to query for authentication credentials for $Au $si:$sp\n");
update_stat("registrar:new_tran", "+1");
drop;
}
if($sel(cfg_get.kazoo.registrar_send_100) == 1) {
sl_send_reply("100", "checking your credentials");
}
$var(amqp_payload_request) = $_s({"Event-Category" : "directory" , "Event-Name" : "authn_req", "Method" : "REGISTER", "Auth-Nonce" : "$adn", "Auth-Realm" : "$fd", "Auth-User" : "$fU", "From" : "$fu", "To" : "$tu", "Orig-IP" : "$si", "Orig-Port" : "$sp", "User-Agent" : "$(ua{s.escape.common}{s.replace,\','}{s.replace,$$,})", "Contact" : "$(ct{s.escape.common}{s.replace,\','}{s.replace,$$,})", "Call-ID" : "$ci" });
$var(amqp_routing_key) = $_s($def(REGISTRAR_AMQP_RK_PREFIX)$(fd{kz.encode}));
$avp(kz_timeout) = $sel(cfg_get.kazoo.registrar_query_timeout_ms);
$xavp(deltas=>query) = $(TV(Sn){s.replace,.,});
xlog("L_DEBUG", "$ci|amqp|publishing to $def(REGISTRAR_AMQP_EXCHANGE) => $var(amqp_routing_key) : $def(REGISTRAR_AMQP_FLAGS) : $var(amqp_payload_request)\n");
if(kazoo_async_query("$def(REGISTRAR_AMQP_EXCHANGE)", $var(amqp_routing_key), $var(amqp_payload_request), "KZ_AUTHORIZATION_REPLY", "KZ_AUTHORIZATION_TIMEOUT", "$def(REGISTRAR_AMQP_FLAGS)") != 1) {
xlog("L_INFO", "$ci|log|failed to send registrar query for authentication credentials for $Au $si:$sp\n");
update_stat("registrar:amqp_async_error", "+1");
t_drop();
}
}
failure_route[KZ_AUTHORIZATION_TIMEOUT]
{
if($(kzR{kz.json,Event-Name}) == "message_returned" ) {
xlog("L_WARNING", "$ci|amqp|message was returned by broker $(kzR{kz.json,Error-Code}) $(kzR{kz.json,Error-Reason})\n");
update_stat("registrar:amqp_returned", "+1");
} else {
xlog("L_WARNING", "$ci|end|failed $T_reply_code $T_reply_reason [$T(id_index):$T(id_label)] querying directory for authentication credentials for $Au $si:$sp\n");
update_stat("registrar:amqp_timeout", "+1");
}
update_stat("registrar:drops", "+1");
t_drop();
}
onreply_route[KZ_AUTHORIZATION_REPLY]
{
$var(StartRoute) = $(TV(Sn){s.replace,.,});
$var(delta_to_start) = $var(StartRoute) - $(kzR{kz.json,AMQP-Received});
$var(delta_from_query) = $(kzR{kz.json,AMQP-Received}) - $xavp(deltas=>query);
xlog("L_INFO", "$ci|log|received $(kzR{kz.json,Event-Category}) $(kzR{kz.json,Event-Name}) reply from $(kzR{kz.json,App-Name})-$(kzR{kz.json,App-Version}) (Δ1 $(kzR{kz.json,AMQP-Elapsed-Micro}) μs , Δ2 $var(delta_to_start) μs, Δ3 $var(delta_from_query) μs)\n");
$var(password) = $(kzR{kz.json,Auth-Password});
$var(nonce) = $adn;
if( $(kzR{kz.json,Event-Name}) == "authn_err" ) {
if($(kzR{kz.json,Permanent-Error}) == "true") {
$sht(auth_cache=>$Au) = "authn_perm_err";
}
update_stat("registrar:authn_err", "+1");
#!ifdef ANTIFLOOD_ROLE
route(ANITFLOOD_FAILED_AUTH);
#!endif
update_stat("registrar:challenge", "+1");
auth_challenge("$fd", "4");
xlog("L_INFO", "$ci|end|challenging $Au $si:$sp via $(kzR{kz.json,App-Name})-$(kzR{kz.json,App-Version}) response\n");
exit;
} else if( $(kzR{kz.json,Event-Name}) == "authn_resp" ) {
update_stat("registrar:authn_resp", "+1");
xlog("L_INFO", "$ci|log|authenticating $Au via $(kzR{kz.json,App-Name})-$(kzR{kz.json,App-Version}) response\n");
route(CHECK_AUTHORIZATION);
} else {
update_stat("registrar:authn_unknown", "+1");
update_stat("registrar:drops", "+1");
xlog("L_INFO", "$ci|log|unhandle response from directory $Au via $(kzR{kz.json,App-Name})-$(kzR{kz.json,App-Version})\n");
t_drop();
}
}
route[CHECK_AUTHORIZATION]
{
if (!pv_auth_check("$fd", "$var(password)", "0", "0")) {
#!ifdef ANTIFLOOD_ROLE
route(ANITFLOOD_FAILED_AUTH);
#!endif
xlog("L_WARNING", "$ci|end|issuing auth challenge to failed registration attempt for $Au from IP $si:$sp\n");
update_stat("registrar:challenge", "+1");
auth_challenge("$fd", "5");
exit;
}
#!ifdef ANTIFLOOD_ROLE
route(ANTIFLOOD_SUCCESSFUL_AUTH);
#!endif
# user authenticated - remove auth header
consume_credentials();
$xavp(ulattrs=>custom_channel_vars) = $(kzR{kz.json,Custom-Channel-Vars});
$xavp(ulattrs[0]=>token) = $_s($(kzR{kz.json,Custom-Channel-Vars.Authorizing-ID})@$(kzR{kz.json,Custom-Channel-Vars.Account-ID}));
route(SAVE_LOCATION);
}
route[SAVE_LOCATION]
{
if ($sht(auth_cache=>$Au) == $null && $var(password) != $null) {
xlog("L_INFO", "$ci|log|caching sip credentials for $Au\n");
};
$sht(auth_cache=>$Au) = $var(password);
route(REGISTRAR_NAT_FLAGS);
$var(save_result) = save("location", "0x04");
if($var(save_result) < 0) {
xlog("L_WARNING", "$ci|end|not expected result $var(save_result) when saving $Au registration from IP $si:$sp\n");
update_stat("registrar:save_error", "+1");
exit;
} else {
if($var(save_result) == 1) {
$var(new_reg) = "true";
} else {
$var(new_reg) = "false";
}
}
if($var(save_result) == 3) {
$var(expires) = 0;
} else {
$var(expires) = $xavp(ulrcd=>expires);
}
if($var(expires) == 0) {
xlog("L_INFO", "$ci|end|unregister request from $Au $si:$sp\n");
$var(Status) = "Unregistered";
} else {
$var(Status) = "Registered";
}
$var(ip) = $Ri;
if(af==INET6) {
$var(ip) = "[" + $Ri + "]";
}
# allow port redirection on registration
switch($proto)
{
#!ifdef KZ_WEBSOCKETS_REGISTRAR_PORT
case "ws":
case "wss":
$var(port) = KZ_WEBSOCKETS_REGISTRAR_PORT;
break;
#!endif
#!ifdef KZ_TLS_REGISTRAR_PORT
case "tls":
$var(port) = KZ_TLS_REGISTRAR_PORT;
break;
#!endif
#!ifdef KZ_UDP_REGISTRAR_PORT
case "udp":
$var(port) = KZ_UDP_REGISTRAR_PORT;
break;
#!endif
#!ifdef KZ_TCP_REGISTRAR_PORT
case "tcp":
$var(port) = KZ_TCP_REGISTRAR_PORT;
break;
#!endif
default:
$var(port) = $Rp;
}
$var(AdvIP) = $RAi;
if(af==INET6) {
$var(AdvIP) = "[" + $RAi + "]";
}
$var(amqp_payload_request) = $_s({"Event-Category" : "directory", "Event-Name" : "reg_success", "Status" : "$var(Status)", "Event-Timestamp" : $TS, "Expires" : $(var(expires){s.int}), "First-Registration" : $var(new_reg), "Contact" : "$(ct{s.escape.common}{s.replace,\','}{s.replace,$$,})", "Call-ID" : "$ci", "Realm" : "$fd", "Username" : "$fU", "From-User" : "$fU", "From-Host" : "$fd", "To-User" : "$tU", "To-Host" : "$td", "User-Agent" : "$(ua{s.escape.common}{s.replace,\','}{s.replace,$$,})" , "Custom-Channel-Vars" : $xavp(ulattrs=>custom_channel_vars), "Proxy-Path" : "sip:MY_IP_ADDRESS:$var(port)", "Proxy-Protocol" : "$proto", "Proxy-IP" : "$var(AdvIP)", "Proxy-Port" : "$RAp", "Source-IP": "$si", "Source-Port": "$sp" });
$var(amqp_routing_key) = "registration.success." + $(fd{kz.encode}) + "." + $(fU{kz.encode});
kazoo_publish("registrar", $var(amqp_routing_key), $var(amqp_payload_request));
xlog("L_INFO", "$ci|end|successful $(var(Status){s.tolower}) with contact : $ct : $var(expires)\n");
#!ifdef PUSHER_ROLE
route(PUSHER_ON_REGISTRATION);
#!endif
#!ifdef KEEPALIVE_ROLE
route(KEEPALIVE_ON_REGISTRATION);
#!endif
exit;
}
## kazoo event route , {"directory", "reg_flush") => reg-flush by kamailio limitations
## when a Event-Category or Event-Name has a underscore (_) we need to declare it with a dash (-)
event_route[kazoo:consumer-event-directory-reg-flush]
{
$var(user) = $(kzE{kz.json,Username}) + "@" + $(kzE{kz.json,Realm});
xlog("L_INFO", "$(kzE{kz.json,Msg-ID})|log|received directory flush for $var(user)\n");
if ($sht(auth_cache=>$var(user)) != $null) {
$sht(auth_cache=>$var(user)) = $null;
}
if( $(kzE{kz.json,Cache-Only}) == "true") {
return;
}
if(reg_fetch_contacts("location", "sip:$var(user)", "caller")) {
$var(i) = 0;
while($var(i) < $(ulc(caller=>count))) {
unregister("location", "sip:$(ulc(caller=>aor))", "$(ulc(caller=>ruid)[$var(i)])");
$var(i) = $var(i) + 1;
}
reg_free_contacts("caller");
}
#!ifdef ANTIFLOOD_ROLE
route(ANTIFLOOD_RESET_AUTH);
#!endif
}
route[REGISTRAR_BINDINGS]
{
#!import_file "registrar-custom-bindings.cfg"
#!ifndef REGISTRAR_CUSTOM_BINDINGS
$var(payload) = $_s({"name": "registrar-api", "exchange": "registrar", "type": "topic", "queue": "registrar-flush-MY_HOSTNAME", "routing": "registration.flush.*", "federate": 1 });
kazoo_subscribe("$var(payload)");
#!endif
#!ifdef REGISTRAR_SYNC_ROLE
route(REGISTRAR_SYNC_BINDINGS);
#!endif
}
route[REGISTRAR_BOUNDS]
{
if((int)@contact.expires) {
$var(expires) = @contact.expires;
} else if(is_present_hf("Expires")) {
$var(expires) = $hdr(Expires);
} else if($(sel(contact){tobody.params}{param.value,expires}) != "") {
$var(expires) = $(sel(contact){tobody.params}{param.value,expires}{s.int});
} else {
if($sel(cfg_get.kazoo.registrar_error_missing_expires) == 1) {
xlog("L_WARNING", "$ci|end|missing expires registering $Au from IP $si:$sp\n");
send_reply("400", "Missing Expires");
update_stat("registrar:missing_expires", "+1");
exit;
} else {
update_stat("registrar:missing_expires_allowed", "+1");
xlog("L_WARNING", "$ci|end|allowing missing expires registering $Au from IP $si:$sp\n");
}
}
if($var(expires) != 0) {
if($var(expires) < REGISTRAR_MIN_EXPIRES) {
if($sel(cfg_get.kazoo.registrar_error_min_expires) == 1) {
xlog("L_WARNING", "$ci|end|expires $var(expires) too brief (configured $def(REGISTRAR_MIN_EXPIRES)) registering $Au from IP $si:$sp\n");
append_to_reply("Min-Expires: $def(REGISTRAR_MIN_EXPIRES)\r\n");
send_reply("423", "Interval Too Brief");
update_stat("registrar:min_expires", "+1");
exit;
} else {
update_stat("registrar:min_expires_allowed", "+1");
xlog("L_WARNING", "$ci|end|allowing expires $var(expires) too brief (configured $def(REGISTRAR_MIN_EXPIRES)) registering $Au from IP $si:$sp\n");
}
}
}
}
##
## this needs handling logic in ecallmgr
## because we will fire the unregister from this server
## after device registers in another proxy
## causing ecallmgr to delete the registration
## from the other server
##
event_route[usrloc:contact-expired]
{
#!ifdef PRESENCE_ROLE
route(PRESENCE_EXPIRED_REGISTRATION);
#!endif
#!ifdef KEEPALIVE_ROLE
route(KEEPALIVE_ON_EXPIRED_REGISTRATION);
#!endif
## return until we handle this in ecallmr
xlog("L_INFO", "$ulc(exp=>callid)|expired|removed registration for $ulc(exp=>aor) with contact : $ulc(exp=>addr)\n");
return;
$var(transport) = $(ulc(exp=>received){uri.transport});
$var(proto) = $(ulc(exp=>socket){re.subst,/^([^:]*):(.*)/\1/});
if($var(proto) == "tls" && $var(transport) == "ws") {
$var(proto) = "wss";
}
$var(handle) = 0;
switch($var(proto))
{
case "ws":
case "wss":
if($sel(cfg_get.kazoo.registrar_handle_expired_ws) == 1) {
$var(handle) = 1;
}
break;
case "tls":
if($sel(cfg_get.kazoo.registrar_handle_expired_tls) == 1) {
$var(handle) = 1;
}
break;
case "tcp":
if($sel(cfg_get.kazoo.registrar_handle_expired_tcp) == 1) {
$var(handle) = 1;
}
break;
case "udp":
if($sel(cfg_get.kazoo.registrar_handle_expired_udp) == 1) {
$var(handle) = 1;
}
break;
default:
break;
}
if($var(handle) == 1) {
$var(aor) = $_s(sip:$ulc(exp=>aor));
$var(username) = $(var(aor){uri.user});
$var(domain) = $(var(aor){uri.host});
$var(amqp_payload_request) = $_s({"Event-Category" : "directory", "Event-Name" : "reg_success", "Status" : "Unregistered", "Event-Timestamp" : $TS, "Expires" : 0, "First-Registration" : false, "Contact" : "$(ulc(exp=>addr){s.escape.common}{s.replace,\','}{s.replace,$$,})", "Call-ID" : "$ulc(exp=>callid)", "Realm" : "$var(domain)", "Username" : "$var(username)", "From-User" : "$var(username)", "From-Host" : "$var(domain)", "To-User" : "$var(username)", "To-Host" : "$var(domain)", "Proxy-Path" : "$ulc(exp=>socket)", "User-Agent" : "$(ulc(exp=>user_agent){s.escape.common}{s.replace,\','}{s.replace,$$,})"});
$var(amqp_routing_key) = "registration.success." + $(var(domain){kz.encode}) + "." + $(var(username){kz.encode});
kazoo_publish("registrar", $var(amqp_routing_key), $var(amqp_payload_request));
xlog("L_INFO", "$ulc(exp=>callid)|expired|notified registration removal with contact : $ulc(exp=>addr)\n");
}
xlog("L_INFO", "$ulc(exp=>callid)|expired|removed registration for $ulc(exp=>aor) with contact : $ulc(exp=>addr)\n");
}
#!ifdef REGISTRAR_SYNC_ROLE
#!include_file "registrar-sync-role.cfg"
#!endif
# vim: tabstop=4 softtabstop=4 shiftwidth=4 expandtab