Hi List
# ----- registrar params ----- modparam("registrar", "method_filtering", 1) # modparam("registrar", "append_branches", 0) modparam("registrar", "max_contacts", 10) modparam("registrar", "max_expires", 3600) modparam("registrar", "gruu_enabled", 0) modparam("registrar", "retry_after", 30) modparam("registrar", "xavp_cfg", "reg")
== snipp == # Handle SIP registrations route[REGISTRAR] {
# We are authenticated.
# Create an AOR based on the auth_username for the location service. $var(saveuri) = "sip:" + $aU + "@" + $rd;
# Set max_contacts limit via registration module reg xavp.
if ($avp(debug) > 0) { xlog("L_INFO", "$cfg(route): Setting max_contacts to $avp(max_contacts) for $var(saveuri)\n"); } $xavp(reg=>max_contacts) = $avp(max_contacts);
# Save Location!
$var(result) = save("location","0x00","$var(saveuri)"); if ($var(result) == -2) { xlog("L_ERR", "$cfg(route): Too many contacts for $var(saveuri)\n"); sl_reply_error(); } if ($var(result) == -1) { xlog("L_ERR", "$cfg(route): Error saving location $var(saveuri)\n"); sl_reply_error(); } if ($var(result) == 1) { xlog("L_INFO", "$cfg(route): Contact $var(saveuri) inserted\n"); } if ($var(result) == 2) { xlog("L_INFO", "$cfg(route): Contact $var(saveuri) updated\n"); } if ($var(result) == 3) { xlog("L_INFO", "$cfg(route): Contact $var(saveuri) deleted\n"); } if ($var(result) == 4) { xlog("L_INFO", "$cfg(route): Contact $var(saveuri) returend\n"); } exit; } == snapp ==
$avp(max_contacts) is set to 1 Still, multiple registrations are possible for the $aU in question.
What am I doing wrong?
Mit freundlichen Grüssen
-Benoît Panizzon-
Hi List
After some more google research and finding this thread
https://www.mail-archive.com/sr-dev@lists.kamailio.org/msg18728.html
and some more testing, I think I can conclude that setting
$xavp(reg=>max_contacts) = $anyvalue
is just not working as described in the documentation:
https://kamailio.org/docs/modules/5.1.x/modules/registrar.html#idp47250596
So I went ahead and pulled:
reg_fetch_contacts("location", "$var(saveuri)", "caller") to get $(ulc(caller=>count))
But now I face a new problem: When I get a registration, I don't know if this a legitimate update for a existing registration or the insertion of a new registration which would exceed the numbers of registration I want to allow for that specific AOR.
Any hint how to solve that challenge or how $xavp(reg=>max_contacts) could be made to work as documented?
Mit freundlichen Grüssen
-Benoît Panizzon-
On 16 Aug 2022, at 16:09, Benoit Panizzon benoit.panizzon@imp.ch wrote:
Hi List
After some more google research and finding this thread
https://www.mail-archive.com/sr-dev@lists.kamailio.org/msg18728.html
and some more testing, I think I can conclude that setting
$xavp(reg=>max_contacts) = $anyvalue
is just not working as described in the documentation:
https://kamailio.org/docs/modules/5.1.x/modules/registrar.html#idp47250596
So I went ahead and pulled:
reg_fetch_contacts("location", "$var(saveuri)", "caller") to get $(ulc(caller=>count))
But now I face a new problem: When I get a registration, I don't know if this a legitimate update for a existing registration or the insertion of a new registration which would exceed the numbers of registration I want to allow for that specific AOR.
That’s something that is only handled by SIP outbound with reg-id’s. Otherwise it’s a SIP-philosophy issue that’s been discussed since RFC 3261 was published…
Any hint how to solve that challenge or how $xavp(reg=>max_contacts) could be made to work as documented?
Limiting the number of contacts and throwing away existing but valid (not expired) entries only work if you are sure there’s one account per device. If that’s the case, then save() has an option for you.
If there are multiple devices, then it really doesn’t work. Especially if there are multiple devices behind the same NAT.
Cheers, /O
Hello,
Not answering your (new) question - but using the flag "4" for save(..) does not work for you? Do you need to have a dynamic limit?
Cheers,
Henning
Hi Henning
Not answering your (new) question - but using the flag "4" for save(..) does not work for you? Do you need to have a dynamic limit?
Flag 0x04 on save for 'replace' existing contact address does work, if I want to allow exactly 1 contact.
But what if I want to allow max 3 contacts for a specific customer and max 5 contacts for another one?
Mit freundlichen Grüssen
-Benoît Panizzon-
Hello,
On 16.08.22 16:09, Benoit Panizzon wrote:
Hi List
After some more google research and finding this thread
https://www.mail-archive.com/sr-dev@lists.kamailio.org/msg18728.html
and some more testing, I think I can conclude that setting
$xavp(reg=>max_contacts) = $anyvalue
is just not working as described in the documentation:
https://kamailio.org/docs/modules/5.1.x/modules/registrar.html#idp47250596
what actually happens? New registrations are accepted with different contact headers? Have you run with debug=3 to see if you can spot any hint in the logs?
So I went ahead and pulled:
reg_fetch_contacts("location", "$var(saveuri)", "caller") to get $(ulc(caller=>count))
But now I face a new problem: When I get a registration, I don't know if this a legitimate update for a existing registration or the insertion of a new registration which would exceed the numbers of registration I want to allow for that specific AOR.
It's up to you to do the match, the simplest is to compare the contact address, but that can fail with devices behind the nat having the same private address in different networks. Then source address, callid, path ... can be added to the matching expression. You can look at usrloc module readme, there is a parameter to specify how to match and inspire from there.
Cheers, Daniel
Any hint how to solve that challenge or how $xavp(reg=>max_contacts) could be made to work as documented?
Mit freundlichen Grüssen
-Benoît Panizzon-
I m p r o W a r e A G - Leiter Commerce Kunden ______________________________________________________
Zurlindenstrasse 29 Tel +41 61 826 93 00 CH-4133 Pratteln Fax +41 61 826 93 01 Schweiz Web http://www.imp.ch ______________________________________________________
Kamailio - Users Mailing List - Non Commercial Discussions
- sr-users@lists.kamailio.org
Important: keep the mailing list in the recipients, do not reply only to the sender! Edit mailing list options or unsubscribe:
Hi Daniel
what actually happens? New registrations are accepted with different contact headers? Have you run with debug=3 to see if you can spot any hint in the logs?
Well I did a different test, which I think hints where the problem is:
== Test 1 ==
modparam("registrar", "max_contacts", 10) modparam("registrar", "xavp_cfg", "reg")
[...]
$xavp(reg=>max_contacts) = 2; $var(result) = save("location","0x00","$var(saveuri)");
Result with 3 clients: AOR contains 3 Addresses.
$var(result) is positive.
== Test 2 ==
modparam("registrar", "max_contacts", 2) modparam("registrar", "xavp_cfg", "reg")
[...]
$xavp(reg=>max_contacts) = 3; $var(result) = save("location","0x00","$var(saveuri)");
Result with 3 clients: 3rd client is being rejected by save operation with:
[save.c:631]: test_max_contacts(): too many contacts for AOR
$var(result) is -2 as per documentation.
== Conclusion ==
Setting $xavp(reg=>max_contacts) on the fly in the config seems not work in Version 5.5.4
I will also increase the debug level to 3 and re-test to see if setting $xavp(reg=>max_contacts) generates any debug output hinting to the cause of the problem.
Mit freundlichen Grüssen
-Benoît Panizzon-
Hi Daniel
debug=3
Two CEP already registered. Registering a 3rd one (snom).
Some IP and Hostnames replaced by 'HIDDEN'.
Aug 18 07:52:55 dev-cpereg02 kamailio[1187007]: INFO: [1 315995001 zygwpey7@snom 1899942452 REGISTER]<script>: REGISTRAR: Setting max_contacts to 2 for sip:315995001@dev-cpereg02.HIDDEN Aug 18 07:52:55 dev-cpereg02 kamailio[1187007]: DEBUG: [1 315995001 zygwpey7@snom 1899942452 REGISTER]registrar [regpv.c:552]: pv_fetch_contacts_helper(): memory block between 0x7fd0c5bc7230 - 0x7fd0c5bc73a8 Aug 18 07:52:55 dev-cpereg02 kamailio[1187007]: DEBUG: [1 315995001 zygwpey7@snom 1899942452 REGISTER]registrar [regpv.c:552]: pv_fetch_contacts_helper(): memory block between 0x7fd0c5bc7410 - 0x7fd0c5bc75ea Aug 18 07:52:55 dev-cpereg02 kamailio[1187007]: DEBUG: [1 315995001 zygwpey7@snom 1899942452 REGISTER]registrar [regpv.c:574]: pv_fetch_contacts_helper(): fetched <2> contacts for <315995001> in [caller] Aug 18 07:52:55 dev-cpereg02 kamailio[1187007]: INFO: [1 315995001 zygwpey7@snom 1899942452 REGISTER]<script>: REGISTRAR: Existing registration contacts count: 2 Aug 18 07:52:55 dev-cpereg02 kamailio[1187007]: INFO: [1 315995001 zygwpey7@snom 1899942452 REGISTER]<script>: REGISTRAR: 0: Contact-Address: sip:315995001@HIDDEN:5060 Agent: Cisco/SPA112-1.4.1_SR5 Expires: 1660811132 Aug 18 07:52:55 dev-cpereg02 kamailio[1187007]: INFO: [1 315995001 zygwpey7@snom 1899942452 REGISTER]<script>: REGISTRAR: 1: Contact-Address: sip:315995001@HIDDEN;transport=udp Agent: Linphone Desktop/ (Debian GNU/Linux 11 (bullseye), Qt 5.15.2) LinphoneCore/4.4.21 Expires: 1660810748 Aug 18 07:52:55 dev-cpereg02 kamailio[1187007]: INFO: [1 315995001 zygwpey7@snom 1899942452 REGISTER]<script>: REGISTRAR: XAVP: <null> before setting Aug 18 07:52:55 dev-cpereg02 kamailio[1187007]: INFO: [1 315995001 zygwpey7@snom 1899942452 REGISTER]<script>: REGISTRAR: XAVP: 2 after setting Aug 18 07:52:55 dev-cpereg02 kamailio[1187007]: DEBUG: [1 315995001 zygwpey7@snom 1899942452 REGISTER]registrar [save.c:324]: pack_ci(): set instance[urn:uuid:1844976b-42aa-4810-b846-13783b5a8c8f] Aug 18 07:52:55 dev-cpereg02 kamailio[1187007]: DEBUG: [1 315995001 zygwpey7@snom 1899942452 REGISTER]<core> [core/utils/sruid.c:209]: sruid_nextx(): new sruid is [uloc-62fdee99-121cbf-1] (1 / 22) Aug 18 07:52:55 dev-cpereg02 kamailio[1187007]: DEBUG: [1 315995001 zygwpey7@snom 1899942452 REGISTER]registrar [save.c:420]: pack_ci(): generated ruid is: uloc-62fdee99-121cbf-1 Aug 18 07:52:55 dev-cpereg02 kamailio[1187007]: DEBUG: [1 315995001 zygwpey7@snom 1899942452 REGISTER]registrar [save.c:607]: test_max_contacts(): 2 valid contacts Aug 18 07:52:55 dev-cpereg02 kamailio[1187007]: DEBUG: [1 315995001 zygwpey7@snom 1899942452 REGISTER]registrar [save.c:629]: test_max_contacts(): 3 contacts after commit
Produced by:
$avp(max_contacts) is 2 for this $aU.
$var(saveuri) = "sip:" + $aU + "@" + $rd;
if ($avp(debug) > 0) { xlog("L_INFO", "$cfg(route): Setting max_contacts to $avp(max_contacts) for $var(saveuri)\n"); if(reg_fetch_contacts("location", "$var(saveuri)", "caller")) { xlog("L_INFO","$cfg(route): Existing registration contacts count: $(ulc(caller=>count))\n"); $var(i) = 0; while($var(i) < $(ulc(caller=>count))) { xlog("L_INFO","$cfg(route): $var(i): Contact-Address: $(ulc(caller=>addr)[$var(i)]) Agent: $(ulc(caller=>user_agent)[$var(i)]) Expires: $(ulc(caller=>expires)[$var(i)])\n"); $var(i) = $var(i) + 1; } } else { xlog("L_INFO","$cfg(route): No existing contacts for AOR $var(saveuri)\n"); } } xlog("L_INFO","$cfg(route): XAVP: $xavp(reg=>max_contacts) before setting\n"); $xavp(reg=>max_contacts) = $avp(max_contacts); xlog("L_INFO","$cfg(route): XAVP: $xavp(reg=>max_contacts) after setting\n");
$var(result) = save("location","0x00","$var(saveuri)");
== snipp ==
# kamctl ul show 315995001@dev-cpereg01.[HIDDEN] | grep Address "Address": "sip:315995001@[HIDDEN].229:5060", "Address": "sip:315995001@[HIDDEN]:9afa:9bff:fe4a:aa55];transport=udp", "Address": "sip:315995001@[HIDDEN]:204:13ff:fe30:2a80]:3038;transport=udp;line=8usewy",
Mit freundlichen Grüssen
-Benoît Panizzon-
Hello,
I looked at code and I couldn't spot quickly anything wrong with using the xavp. I added more debug message in the git master branch.
Can you add:
pv_xavp_print();
just before save() in your config and test with git master branch and debug=3? Then send the log messages printed for the registration that should exceed the limit set in the xavp.
Cheers, Daniel
On 18.08.22 10:04, Benoit Panizzon wrote:
Hi Daniel
debug=3
Two CEP already registered. Registering a 3rd one (snom).
Some IP and Hostnames replaced by 'HIDDEN'.
Aug 18 07:52:55 dev-cpereg02 kamailio[1187007]: INFO: [1 315995001 zygwpey7@snom 1899942452 REGISTER]<script>: REGISTRAR: Setting max_contacts to 2 for sip:315995001@dev-cpereg02.HIDDEN Aug 18 07:52:55 dev-cpereg02 kamailio[1187007]: DEBUG: [1 315995001 zygwpey7@snom 1899942452 REGISTER]registrar [regpv.c:552]: pv_fetch_contacts_helper(): memory block between 0x7fd0c5bc7230 - 0x7fd0c5bc73a8 Aug 18 07:52:55 dev-cpereg02 kamailio[1187007]: DEBUG: [1 315995001 zygwpey7@snom 1899942452 REGISTER]registrar [regpv.c:552]: pv_fetch_contacts_helper(): memory block between 0x7fd0c5bc7410 - 0x7fd0c5bc75ea Aug 18 07:52:55 dev-cpereg02 kamailio[1187007]: DEBUG: [1 315995001 zygwpey7@snom 1899942452 REGISTER]registrar [regpv.c:574]: pv_fetch_contacts_helper(): fetched <2> contacts for <315995001> in [caller] Aug 18 07:52:55 dev-cpereg02 kamailio[1187007]: INFO: [1 315995001 zygwpey7@snom 1899942452 REGISTER]<script>: REGISTRAR: Existing registration contacts count: 2 Aug 18 07:52:55 dev-cpereg02 kamailio[1187007]: INFO: [1 315995001 zygwpey7@snom 1899942452 REGISTER]<script>: REGISTRAR: 0: Contact-Address: sip:315995001@HIDDEN:5060 Agent: Cisco/SPA112-1.4.1_SR5 Expires: 1660811132 Aug 18 07:52:55 dev-cpereg02 kamailio[1187007]: INFO: [1 315995001 zygwpey7@snom 1899942452 REGISTER]<script>: REGISTRAR: 1: Contact-Address: sip:315995001@HIDDEN;transport=udp Agent: Linphone Desktop/ (Debian GNU/Linux 11 (bullseye), Qt 5.15.2) LinphoneCore/4.4.21 Expires: 1660810748 Aug 18 07:52:55 dev-cpereg02 kamailio[1187007]: INFO: [1 315995001 zygwpey7@snom 1899942452 REGISTER]<script>: REGISTRAR: XAVP: <null> before setting Aug 18 07:52:55 dev-cpereg02 kamailio[1187007]: INFO: [1 315995001 zygwpey7@snom 1899942452 REGISTER]<script>: REGISTRAR: XAVP: 2 after setting Aug 18 07:52:55 dev-cpereg02 kamailio[1187007]: DEBUG: [1 315995001 zygwpey7@snom 1899942452 REGISTER]registrar [save.c:324]: pack_ci(): set instance[urn:uuid:1844976b-42aa-4810-b846-13783b5a8c8f] Aug 18 07:52:55 dev-cpereg02 kamailio[1187007]: DEBUG: [1 315995001 zygwpey7@snom 1899942452 REGISTER]<core> [core/utils/sruid.c:209]: sruid_nextx(): new sruid is [uloc-62fdee99-121cbf-1] (1 / 22) Aug 18 07:52:55 dev-cpereg02 kamailio[1187007]: DEBUG: [1 315995001 zygwpey7@snom 1899942452 REGISTER]registrar [save.c:420]: pack_ci(): generated ruid is: uloc-62fdee99-121cbf-1 Aug 18 07:52:55 dev-cpereg02 kamailio[1187007]: DEBUG: [1 315995001 zygwpey7@snom 1899942452 REGISTER]registrar [save.c:607]: test_max_contacts(): 2 valid contacts Aug 18 07:52:55 dev-cpereg02 kamailio[1187007]: DEBUG: [1 315995001 zygwpey7@snom 1899942452 REGISTER]registrar [save.c:629]: test_max_contacts(): 3 contacts after commit
Produced by:
$avp(max_contacts) is 2 for this $aU.
$var(saveuri) = "sip:" + $aU + "@" + $rd;
if ($avp(debug) > 0) { xlog("L_INFO", "$cfg(route): Setting max_contacts to $avp(max_contacts) for $var(saveuri)\n"); if(reg_fetch_contacts("location", "$var(saveuri)", "caller")) { xlog("L_INFO","$cfg(route): Existing registration contacts count: $(ulc(caller=>count))\n"); $var(i) = 0; while($var(i) < $(ulc(caller=>count))) { xlog("L_INFO","$cfg(route): $var(i): Contact-Address: $(ulc(caller=>addr)[$var(i)]) Agent: $(ulc(caller=>user_agent)[$var(i)]) Expires: $(ulc(caller=>expires)[$var(i)])\n"); $var(i) = $var(i) + 1; } } else { xlog("L_INFO","$cfg(route): No existing contacts for AOR $var(saveuri)\n"); } } xlog("L_INFO","$cfg(route): XAVP: $xavp(reg=>max_contacts) before setting\n"); $xavp(reg=>max_contacts) = $avp(max_contacts); xlog("L_INFO","$cfg(route): XAVP: $xavp(reg=>max_contacts) after setting\n");
$var(result) = save("location","0x00","$var(saveuri)");
== snipp ==
# kamctl ul show 315995001@dev-cpereg01.[HIDDEN] | grep Address "Address": "sip:315995001@[HIDDEN].229:5060", "Address": "sip:315995001@[HIDDEN]:9afa:9bff:fe4a:aa55];transport=udp", "Address": "sip:315995001@[HIDDEN]:204:13ff:fe30:2a80]:3038;transport=udp;line=8usewy",
Mit freundlichen Grüssen
-Benoît Panizzon-
I m p r o W a r e A G - Leiter Commerce Kunden ______________________________________________________
Zurlindenstrasse 29 Tel +41 61 826 93 00 CH-4133 Pratteln Fax +41 61 826 93 01 Schweiz Web http://www.imp.ch ______________________________________________________