Hello all,

I am trying to use Kamailio 5.0 with Asterisk (separate IP addresses, both port 5060),
but Asterisk doesn't register the SIP clients which comes through Kamailio.
If I register the same user directly to the Asterisk then it works! 1st REGISTER
is also without Authorization (Digest name) but in the 2nd REGISTER it exists
and registration goes OK.

How to use Kamailio with Asterisk in the way the SIP client is registered on both of them?
Thank you
Marko


SIP-CLIENT DIRECTLY TO ASTERISK:
-----------------------------------------------------------
1    2017-04-01 15:20:48.331806    192.168.0.12    192.168.0.2    SIP    544    Request: REGISTER sip:192.168.0.2  (1 binding) |
2    2017-04-01 15:20:48.332998    192.168.0.2    192.168.0.12    SIP    626    Status: 401 Unauthorized |
3    2017-04-01 15:20:48.333814    192.168.0.12    192.168.0.2    SIP    700    Request: REGISTER sip:192.168.0.2  (1 binding) |
4    2017-04-01 15:20:48.335975    192.168.0.2    192.168.0.12    SIP    647    Status: 200 OK  (1 binding) |

Frame 3: 700 bytes on wire (5600 bits), 700 bytes captured (5600 bits) on interface 0
Ethernet II, Src: AsrockIn_0a:0b:46 (70:85:c2:0a:0b:46), Dst: Raspberr_a1:fd:f7 (b8:27:eb:a1:fd:f7)
Internet Protocol Version 4, Src: 192.168.0.12, Dst: 192.168.0.2
User Datagram Protocol, Src Port: 64369, Dst Port: 5060
Session Initiation Protocol (REGISTER)
    Request-Line: REGISTER sip:192.168.0.2 SIP/2.0
    Message Header
        Via: SIP/2.0/UDP 192.168.0.12:64369;rport;branch=z9hG4bKPj9f8759c0537b4834bb411358d0b0a2ff
        Max-Forwards: 70
        From: "33" <sip:33@192.168.0.2>;tag=4c586be1fcf842359e7d429abcb0b213
        To: "33" <sip:33@192.168.0.2>
        Contact: <sip:74081936@192.168.0.12:64369>;+sip.instance="<urn:uuid:b408367e-d06b-4780-a9a0-291eb99ec83c>"
        Call-ID: d3c240808c934b77a9bbcb8bd4c1bd8c
        CSeq: 2 REGISTER
        Expires: 600
        Supported: gruu
        User-Agent: Blink 3.0.0 (Windows)
        Authorization: Digest username="33", realm="asterisk", nonce="76ca37d8", uri="sip:192.168.0.2", response="19fc1a634abc72c41dcb516470c34fc2", algorithm=MD5
            Authentication Scheme: Digest
            Username: "33"
            Realm: "asterisk"
            Nonce Value: "76ca37d8"
            Authentication URI: "sip:192.168.0.2"
            Digest Authentication Response: "19fc1a634abc72c41dcb516470c34fc2"
            Algorithm: MD5
        Content-Length:  0


SIP-CLIENT TO KAMAILIO WITH FORWARD TO ASTERISK:
----------------------------------------------------------------------------------------------
11    2017-04-01 15:21:06.806347    192.168.0.13    192.168.0.2    SIP    459    Request: REGISTER sip:192.168.0.2:5060  (1 binding) |
12    2017-04-01 15:21:06.807514    192.168.0.2    192.168.0.13    SIP    608    Status: 401 Unauthorized |
13    2017-04-01 15:21:06.814819    192.168.0.13    192.168.0.2    SIP    456    Request: REGISTER sip:192.168.0.2:5060  (remove 1 binding) |
14    2017-04-01 15:21:06.815712    192.168.0.2    192.168.0.13    SIP    608    Status: 401 Unauthorized |
15    2017-04-01 15:21:06.821125    192.168.0.13    192.168.0.2    SIP    459    Request: REGISTER sip:192.168.0.2:5060  (1 binding) |
16    2017-04-01 15:21:06.821910    192.168.0.2    192.168.0.13    SIP    608    Status: 401 Unauthorized |

Frame 15: 459 bytes on wire (3672 bits), 459 bytes captured (3672 bits) on interface 0
Ethernet II, Src: Micro-St_de:b2:3a (00:24:21:de:b2:3a), Dst: Raspberr_a1:fd:f7 (b8:27:eb:a1:fd:f7)
Internet Protocol Version 4, Src: 192.168.0.13, Dst: 192.168.0.2
User Datagram Protocol, Src Port: 5060, Dst Port: 5060
Session Initiation Protocol (REGISTER)
    Request-Line: REGISTER sip:192.168.0.2:5060 SIP/2.0
    Message Header
        Via: SIP/2.0/UDP 192.168.0.13;branch=z9hG4bKd101.0ad599b6000000000000000000000000.0
        To: <sip:32@192.168.0.2>
            SIP to address: sip:32@192.168.0.2
        From: <sip:32@192.168.0.2>;tag=533cb9e91f4b999cf76861cbb9ed54ed-85c4
            SIP from address: sip:32@192.168.0.2
            SIP from tag: 533cb9e91f4b999cf76861cbb9ed54ed-85c4
        CSeq: 10 REGISTER
        Call-ID: 41df282f10fdc7b6-2773@127.0.0.1
        Max-Forwards: 70
        Content-Length: 0
        User-Agent: kamailio (5.0.0 (x86_64/linux))
        Contact: <sip:32@192.168.0.13:5060>
            Contact URI: sip:32@192.168.0.13:5060
        Expires: 3600



kamailio.cfg:
--------------------

#!define WITH_DEBUG
#!define WITH_MYSQL
#!define WITH_AUTH
#!define WITH_USRLOCDB
#!define WITH_ASTERISK
...

#!ifdef WITH_ASTERISK
asterisk.bindip = "192.168.0.2" desc "Asterisk IP Address"
asterisk.bindport = "5060" desc "Asterisk Port"
kamailio.bindip = "192.168.0.13" desc "Kamailio IP Address"
kamailio.bindport = "5060" desc "Kamailio Port"
#!endif
...

# Forward REGISTER to Asterisk
route[REGFWD] {
    if(!is_method("REGISTER"))
    {
        return;
    }
    $var(rip) = $sel(cfg_get.asterisk.bindip);
    $uac_req(method)="REGISTER";
    $uac_req(ruri)="sip:" + $var(rip) + ":" + $sel(cfg_get.asterisk.bindport);
    #$uac_req(ruri)="sip:" + $au + "@" + $var(rip) + ":" + $sel(cfg_get.asterisk.bindport);
    $uac_req(furi)="sip:" + $au + "@" + $var(rip);
    $uac_req(turi)="sip:" + $au + "@" + $var(rip);
    $uac_req(hdrs)="Contact: <sip:" + $au + "@"
                + $sel(cfg_get.kamailio.bindip)
                + ":" + $sel(cfg_get.kamailio.bindport) + ">\r\n";
    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();
}