### Description
Following this scenario:
Softphone <-> Kamailio <-> Asterisk
1- Softphone registers with kamailio (REGISTER) 2- Kamailio challenges... (401) 3- Softphone registers with kamailio (REGISTER + Auth info) 4- Kamailio accepts (200) 5- If Kamailio accepted, it sends a REGISTER to asterisk (REGISTER) 6- Asterisk challenges... (401) 7- Kamailio authenticates (REGISTER + Auth info) 8- Asterisk accepts (200)
(NOTE: I know you can avoid Asterisk re-requesting for authentication, but in this case it's mandatory.)
kamailio.cfg has this:
``` $var(rip) = $(avp(s:dsp_uri_list){uri.host}); $var(rip_port) = $(avp(s:dsp_uri_list){uri.port}); $uac_req(method)="REGISTER"; $uac_req(auser)=$avp(customer_user); $uac_req(apasswd)=$avp(customer_pass); $uac_req(ruri)="sip:" + $var(rip) + ":" + $var(rip_port); $uac_req(furi)="sip:" + $au + "@" + $var(rip); $uac_req(turi)="sip:" + $au + "@" + $var(rip); $uac_req(hdrs)="Contact: <sip:" + $au + "@X.X.X.X:5060>\r\n"; $uac_req(evroute)=1; if ($sel(contact.expires) != $null) { $uac_req(hdrs)= $uac_req(hdrs) + "Expires: " + $sel(contact.expires) + "\r\n"; } else { $uac_req(hdrs)= $uac_req(hdrs) + "Expires: " + $hdr(Expires) + "\r\n"; } uac_req_send(); ```
and this:
``` # Log replies from uac_req_send() event_route[uac:reply] { xlog("L_NOTICE", "[UAC] - $uac_req(method) request from user $uac_req(auser) to $uac_req(ruri) completed with code: $uac_req(evcode)\n"); } ```
The result:

``` Jul 20 16:49:42 sbc01 sbc[5236]: NOTICE: <script>: [UAC] - REGISTER request from user XXXXX to sip:A.B.C.D:5060 completed with code: 401 Jul 20 16:51:05 sbc01 sbc[5240]: NOTICE: <script>: [UAC] - REGISTER request from user XXXXX to sip:A.B.C.D:5060 completed with code: 401 Jul 20 16:51:49 sbc01 sbc[5241]: NOTICE: <script>: [UAC] - REGISTER request from user XXXXX to sip:A.B.C.D:5060 completed with code: 401 Jul 20 17:00:06 sbc01 sbc[5239]: NOTICE: <script>: [UAC] - REGISTER request from user XXXXX to sip:A.B.C.D:5060 completed with code: 401 Jul 20 17:09:06 sbc01 sbc[5240]: NOTICE: <script>: [UAC] - REGISTER request from user XXXXX to sip:A.B.C.D:5060 completed with code: 401 ```
I was expecting for `$uac_req(evcode)` to be 200, but it's 401.
#### Reproduction
Generate a REGISTER using uaq_send_req() with `auser` and `apasswd` set, and then print the `$uac_req(evcode)` from the corresponding `event_route[]`.
### Possible Solutions
Not sure if the 401 is expected because it was the *first* final response, period.
Or, (when using authentication), it should be updated to 200 or whatever the reply is after sending the REGISTER with auth info.
### Additional Information
* **Kamailio Version** - output of `kamailio -v`
``` # kamailio -v version: kamailio 5.1.4 (x86_64/linux) flags: STATS: Off, USE_TCP, USE_TLS, USE_SCTP, TLS_HOOKS, DISABLE_NAGLE, USE_MCAST, DNS_IP_HACK, SHM_MEM, SHM_MMAP, PKG_MALLOC, Q_MALLOC, F_MALLOC, TLSF_MALLOC, DBG_SR_MEMORY, USE_FUTEX, FAST_LOCK-ADAPTIVE_WAIT, USE_DNS_CACHE, USE_DNS_FAILOVER, USE_NAPTR, USE_DST_BLACKLIST, HAVE_RESOLV_RES ADAPTIVE_WAIT_LOOPS=1024, MAX_RECV_BUFFER_SIZE 262144, MAX_LISTEN 16, MAX_URI_SIZE 1024, BUF_SIZE 65535, DEFAULT PKG_SIZE 8MB poll method support: poll, epoll_lt, epoll_et, sigio_rt, select. id: unknown compiled with gcc 6.3.0 ```
* **Operating System**:
``` OS: Debian stretch 9.4
Kernel: Linux kamailio 4.9.0-6-amd64 #1 SMP Debian 4.9.88-1+deb9u1 (2018-05-07) x86_64 GNU/Linux ```
I looked at the code and the event route is executed only for first final response, in this case 401/407. When the 2nd reply comes (for the request with credentials), there is no event route executed. That's the reason you do not see the 200ok.
As a new feature, I can add execution for the follow up reply.
Hi Daniel, that would be awesome. Thank you.
Offtopic but related question, does this mean also that if the final reply would be a 5XX or a different 4XX a failure_route would no be called for uac_req_send()?
How do you failover to registrar_server2 if registrar_server1 is dead if you have no failure_route execution?
It is no failure_route executed here because the request is generated by kamailio. You can loop once through kamailio and then you can engage failure route.
However, if the first server is down, the event_route is executed and you can send to another one.
I also pushed a commit to execute the event_route for the second final reply, no matter what it is -- see it referenced above. Maybe you can test and report the result, I did it in my way to ClueCon and had no time for testing at all.
Absolutely! Building with this commit right now. I'll report back in a bit :)
It is no failure_route executed here because the request is generated by kamailio.
IIRC, a failure_route can be set in a tm:local-request event-route.
@miconda: tested, works:
``` Jul 23 13:10:22 sbc01 sbc[5374]: NOTICE: <script>: [UAC] - REGISTER request from user 1000105 to sip:138.99.136.3:5060 completed with code: 401 Jul 23 13:10:22 sbc01 sbc[5375]: NOTICE: <script>: [UAC] - REGISTER request from user 1000105 to sip:138.99.136.3:5060 completed with code: 200 ```
@gaaf: thanks for the hint, I'll give it a test!
Closed #1598.
Closing this one...