[Kamailio-Users] add_path_received and OBP problems

Florian Meister Florian.Meister at teleport.vol.at
Fri Sep 25 10:40:49 CEST 2009


Hi,

I'm trying to set up a HA-OBP for both natted and non-natted users.

Atm my setup looks like that:


[UAC] <---> (NAT) <---> [LB] <---> [REG + Proxy] <---> [PSTN GW]

At the loadbalancer I use add_path and add_path_received to add a path-header to the request sent to the Registrar. (Of course only for register requests). I use a few parameters for telling the registrar module to use the path header. When looking in the mysql-db I can see the correct value in the path-field in the location-table.

When getting an invite from the PSTN gateway for one of the UAC's the Proxy is adding a route-header according to the path-value in the mysql. That seems also correct. Now to my problem:

The loadbalancer is sending out the INVITE to the private-ip, not to the public-nat-ip of the UAC. It seems that the received-parameter in the Route-header is somehow ignored. I am using the use_received parameter in the loadbalancer, but it does not work.

In the following you can find the SIP trace (made on the loadbalancer) and the loadbalancer config, since I think there is the problem.

Thanks,

Florian


Here is the SIP-trace of the INVITE:

09:49:07.785294 IP [Proxy+Registrar].5060 > [Loadbalancer].5060: SIP, length: 1101
E..i.. at .?.Yb..,F..,+.....U.BINVITE sip:435572949012@[PRIVATE IP of UAC];user=phone SIP/2.0
Record-Route: <sip:[Proxy+Registrar];lr;ftag=as33339e2e>
Via: SIP/2.0/UDP [Proxy+Registrar];branch=z9hG4bK3d51.bf3830b5.0
Via: SIP/2.0/UDP [PSTN Gateway]:5060;branch=z9hG4bK521a62f5;rport=5060
Route: <sip:[Loadbalancer];lr;received="sip:[PUBLIC NAT IP of UAC]:64224">
Max-Forwards: 69
From: "4366480588134" <sip:4366480588134@[PSTN Gateway]>;tag=as33339e2e
To: <sip:+435572949012@[Proxy+Registrar]>
Contact: <sip:4366480588134@[PSTN Gateway]>
Call-ID: 067ebe30188025880d0c9f6e78c1b86d@[PSTN Gateway]
CSeq: 102 INVITE
User-Agent: Asterisk PBX 1.6.1.5
Date: Fri, 25 Sep 2009 07:40:26 GMT
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO
Supported: replaces, timer
Content-Type: application/sdp
Content-Length: 312

v=0
o=root 1940822246 1940822246 IN IP4 [PSTN Gateway]
s=Asterisk PBX 1.6.1.5
c=IN IP4 [PSTN Gateway]
t=0 0
m=audio 19178 RTP/AVP 8 3 0 101
a=rtpmap:8 PCMA/8000
a=rtpmap:3 GSM/8000
a=rtpmap:0 PCMU/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=silenceSupp:off - - - -
a=ptime:20
a=sendrecv

09:49:07.786459 IP [Loadbalancer].5060 > [Proxy+Registrar].5060: SIP, length: 445
E..... at .@.Z...,+..,F........SIP/2.0 100 Giving a try
Via: SIP/2.0/UDP [Proxy+Registrar];branch=z9hG4bK3d51.bf3830b5.0;rport=5060;received=[Proxy+Registrar]
Via: SIP/2.0/UDP [PSTN Gateway]:5060;branch=z9hG4bK521a62f5;rport=5060
From: "4366480588134" <sip:4366480588134@[PSTN Gateway]>;tag=as33339e2e
To: <sip:+435572949012@[Proxy+Registrar]>
Call-ID: 067ebe30188025880d0c9f6e78c1b86d@[PSTN Gateway]
CSeq: 102 INVITE
Server: Kamailio (1.5.1-notls (i386/linux))
Content-Length: 0


09:49:07.786608 IP [Loadbalancer].5060 > [PRIVATE IP of UAC].5060: SIP, length: 1307
E..7.. at .@.. at ..,+.........#>.INVITE sip:435572949012@[PRIVATE IP of UAC];user=phone SIP/2.0
Record-Route: <sip:[Loadbalancer];lr;ftag=as33339e2e;nat=yes>
Record-Route: <sip:[Proxy+Registrar];lr;ftag=as33339e2e>
Via: SIP/2.0/UDP [Loadbalancer];branch=z9hG4bK3d51.207ba0a5.0
Via: SIP/2.0/UDP [Proxy+Registrar];rport=5060;received=[Proxy+Registrar];branch=z9hG4bK3d51.bf3830b5.0
Via: SIP/2.0/UDP [PSTN Gateway]:5060;branch=z9hG4bK521a62f5;rport=5060
Route: <sip:[Loadbalancer];lr;received="sip:[PUBLIC NAT IP of UAC]:64224">
Max-Forwards: 68
From: "4366480588134" <sip:4366480588134@[PSTN Gateway]>;tag=as33339e2e
To: <sip:+435572949012@[Proxy+Registrar]>
Contact: <sip:4366480588134@[PSTN Gateway]>
Call-ID: 067ebe30188025880d0c9f6e78c1b86d@[PSTN Gateway]
CSeq: 102 INVITE
User-Agent: Asterisk PBX 1.6.1.5
Date: Fri, 25 Sep 2009 07:40:26 GMT
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO
Supported: replaces, timer
Content-Type: application/sdp
Content-Length: 330
Path: <sip:[Loadbalancer];lr>

v=0
o=root 1940822246 1940822246 IN IP4 [PSTN Gateway]
s=Asterisk PBX 1.6.1.5
c=IN IP4 [Loadbalancer]
t=0 0
m=audio 35480 RTP/AVP 8 3 0 101
a=rtpmap:8 PCMA/8000
a=rtpmap:3 GSM/8000
a=rtpmap:0 PCMU/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=silenceSupp:off - - - -
a=ptime:20
a=sendrecv
a=nortpproxy:yes

09:49:08.258116 IP [Loadbalancer].5060 > [PRIVATE IP of UAC].5060: SIP, length: 1307
E..7.. at .@.. at ..,+.........#>.INVITE sip:435572949012@[PRIVATE IP of UAC];user=phone SIP/2.0
Record-Route: <sip:[Loadbalancer];lr;ftag=as33339e2e;nat=yes>
Record-Route: <sip:[Proxy+Registrar];lr;ftag=as33339e2e>
Via: SIP/2.0/UDP [Loadbalancer];branch=z9hG4bK3d51.207ba0a5.0
Via: SIP/2.0/UDP [Proxy+Registrar];rport=5060;received=[Proxy+Registrar];branch=z9hG4bK3d51.bf3830b5.0
Via: SIP/2.0/UDP [PSTN Gateway]:5060;branch=z9hG4bK521a62f5;rport=5060
Route: <sip:[Loadbalancer];lr;received="sip:[PUBLIC NAT IP of UAC]:64224">
Max-Forwards: 68
From: "4366480588134" <sip:4366480588134@[PSTN Gateway]>;tag=as33339e2e
To: <sip:+435572949012@[Proxy+Registrar]>
Contact: <sip:4366480588134@[PSTN Gateway]>
Call-ID: 067ebe30188025880d0c9f6e78c1b86d@[PSTN Gateway]
CSeq: 102 INVITE
User-Agent: Asterisk PBX 1.6.1.5
Date: Fri, 25 Sep 2009 07:40:26 GMT
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO
Supported: replaces, timer
Content-Type: application/sdp
Content-Length: 330
Path: <sip:[Loadbalancer];lr>

v=0
o=root 1940822246 1940822246 IN IP4 [PSTN Gateway]
s=Asterisk PBX 1.6.1.5
c=IN IP4 [Loadbalancer]
t=0 0
m=audio 35480 RTP/AVP 8 3 0 101
a=rtpmap:8 PCMA/8000
a=rtpmap:3 GSM/8000
a=rtpmap:0 PCMU/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=silenceSupp:off - - - -
a=ptime:20
a=sendrecv
a=nortpproxy:yes

09:49:09.258109 IP [Loadbalancer].5060 > [PRIVATE IP of UAC].5060: SIP, length: 1307
E..7.. at .@.. at ..,+.........#>.INVITE sip:435572949012@[PRIVATE IP of UAC];user=phone SIP/2.0
Record-Route: <sip:[Loadbalancer];lr;ftag=as33339e2e;nat=yes>
Record-Route: <sip:[Proxy+Registrar];lr;ftag=as33339e2e>
Via: SIP/2.0/UDP [Loadbalancer];branch=z9hG4bK3d51.207ba0a5.0
Via: SIP/2.0/UDP [Proxy+Registrar];rport=5060;received=[Proxy+Registrar];branch=z9hG4bK3d51.bf3830b5.0
Via: SIP/2.0/UDP [PSTN Gateway]:5060;branch=z9hG4bK521a62f5;rport=5060
Route: <sip:[Loadbalancer];lr;received="sip:[PUBLIC NAT IP of UAC]:64224">
Max-Forwards: 68
From: "4366480588134" <sip:4366480588134@[PSTN Gateway]>;tag=as33339e2e
To: <sip:+435572949012@[Proxy+Registrar]>
Contact: <sip:4366480588134@[PSTN Gateway]>
Call-ID: 067ebe30188025880d0c9f6e78c1b86d@[PSTN Gateway]
CSeq: 102 INVITE
User-Agent: Asterisk PBX 1.6.1.5
Date: Fri, 25 Sep 2009 07:40:26 GMT
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO
Supported: replaces, timer
Content-Type: application/sdp
Content-Length: 330
Path: <sip:[Loadbalancer];lr>

v=0
o=root 1940822246 1940822246 IN IP4 [PSTN Gateway]
s=Asterisk PBX 1.6.1.5
c=IN IP4 [Loadbalancer]
t=0 0
m=audio 35480 RTP/AVP 8 3 0 101
a=rtpmap:8 PCMA/8000
a=rtpmap:3 GSM/8000
a=rtpmap:0 PCMU/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=silenceSupp:off - - - -
a=ptime:20
a=sendrecv
a=nortpproxy:yes

09:49:11.258107 IP [Loadbalancer].5060 > [PRIVATE IP of UAC].5060: SIP, length: 1307
E..7.. at .@.. at ..,+.........#>.INVITE sip:435572949012@[PRIVATE IP of UAC];user=phone SIP/2.0
Record-Route: <sip:[Loadbalancer];lr;ftag=as33339e2e;nat=yes>
Record-Route: <sip:[Proxy+Registrar];lr;ftag=as33339e2e>
Via: SIP/2.0/UDP [Loadbalancer];branch=z9hG4bK3d51.207ba0a5.0
Via: SIP/2.0/UDP [Proxy+Registrar];rport=5060;received=[Proxy+Registrar];branch=z9hG4bK3d51.bf3830b5.0
Via: SIP/2.0/UDP [PSTN Gateway]:5060;branch=z9hG4bK521a62f5;rport=5060
Route: <sip:[Loadbalancer];lr;received="sip:[PUBLIC NAT IP of UAC]:64224">
Max-Forwards: 68
From: "4366480588134" <sip:4366480588134@[PSTN Gateway]>;tag=as33339e2e
To: <sip:+435572949012@[Proxy+Registrar]>
Contact: <sip:4366480588134@[PSTN Gateway]>
Call-ID: 067ebe30188025880d0c9f6e78c1b86d@[PSTN Gateway]
CSeq: 102 INVITE
User-Agent: Asterisk PBX 1.6.1.5
Date: Fri, 25 Sep 2009 07:40:26 GMT
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO
Supported: replaces, timer
Content-Type: application/sdp
Content-Length: 330
Path: <sip:[Loadbalancer];lr>

v=0
o=root 1940822246 1940822246 IN IP4 [PSTN Gateway]
s=Asterisk PBX 1.6.1.5
c=IN IP4 [Loadbalancer]
t=0 0
m=audio 35480 RTP/AVP 8 3 0 101
a=rtpmap:8 PCMA/8000
a=rtpmap:3 GSM/8000
a=rtpmap:0 PCMU/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=silenceSupp:off - - - -
a=ptime:20
a=sendrecv
a=nortpproxy:yes

09:49:15.023388 IP [Proxy+Registrar].5060 > [Loadbalancer].5060: SIP, length: 397
E..... at .?.\"..,F..,+......a.CANCEL sip:435572949012@[PRIVATE IP of UAC];user=phone SIP/2.0
Via: SIP/2.0/UDP [Proxy+Registrar];branch=z9hG4bK3d51.bf3830b5.0
From: "4366480588134" <sip:4366480588134@[PSTN Gateway]>;tag=as33339e2e
Call-ID: 067ebe30188025880d0c9f6e78c1b86d@[PSTN Gateway]
To: <sip:+435572949012@[Proxy+Registrar]>
CSeq: 102 CANCEL
Max-Forwards: 70
User-Agent: OpenSER (1.3.2-notls (x86_64/linux))
Content-Length: 0


09:49:15.024138 IP [Loadbalancer].5060 > [Proxy+Registrar].5060: SIP, length: 413
E..... at .@.[...,+..,F........SIP/2.0 200 canceling
Via: SIP/2.0/UDP [Proxy+Registrar];branch=z9hG4bK3d51.bf3830b5.0;rport=5060;received=[Proxy+Registrar]
From: "4366480588134" <sip:4366480588134@[PSTN Gateway]>;tag=as33339e2e
Call-ID: 067ebe30188025880d0c9f6e78c1b86d@[PSTN Gateway]
To: <sip:+435572949012@[Proxy+Registrar]>;tag=77b8b5897dbef36847302656cec9825e-db87
CSeq: 102 CANCEL
Server: Kamailio (1.5.1-notls (i386/linux))
Content-Length: 0


09:49:15.024576 IP [Loadbalancer].5060 > [Proxy+Registrar].5060: SIP, length: 493
E..     .. at .@.Z...,+..,F........SIP/2.0 487 Request Terminated
Via: SIP/2.0/UDP [Proxy+Registrar];branch=z9hG4bK3d51.bf3830b5.0;rport=5060;received=[Proxy+Registrar]
Via: SIP/2.0/UDP [PSTN Gateway]:5060;branch=z9hG4bK521a62f5;rport=5060
From: "4366480588134" <sip:4366480588134@[PSTN Gateway]>;tag=as33339e2e
To: <sip:+435572949012@[Proxy+Registrar]>;tag=77b8b5897dbef36847302656cec9825e-db87
Call-ID: 067ebe30188025880d0c9f6e78c1b86d@[PSTN Gateway]
CSeq: 102 INVITE
Server: Kamailio (1.5.1-notls (i386/linux))
Content-Length: 0


09:49:15.025180 IP [Proxy+Registrar].5060 > [Loadbalancer].5060: SIP, length: 433
E..... at .?.[...,F..,+.......MACK sip:435572949012@[PRIVATE IP of UAC];user=phone SIP/2.0
Via: SIP/2.0/UDP [Proxy+Registrar];branch=z9hG4bK3d51.bf3830b5.0
From: "4366480588134" <sip:4366480588134@[PSTN Gateway]>;tag=as33339e2e
Call-ID: 067ebe30188025880d0c9f6e78c1b86d@[PSTN Gateway]
To: <sip:+435572949012@[Proxy+Registrar]>;tag=77b8b5897dbef36847302656cec9825e-db87
CSeq: 102 ACK
Max-Forwards: 70
User-Agent: OpenSER (1.3.2-notls (x86_64/linux))
Content-Length: 0


----------------This is the config of my loadbalancer--------------------:

####### Global Parameters #########

debug=100
log_stderror=yes
log_facility=LOG_LOCAL0

fork=no
children=4

disable_tcp=yes

port=5060

listen=[Loadbalancer]

####### Modules Section ########

mpath="/usr/lib/kamailio/modules/"

loadmodule "mi_fifo.so"
loadmodule "sl.so"
loadmodule "tm.so"
loadmodule "rr.so"
loadmodule "pv.so"
loadmodule "maxfwd.so"
loadmodule "textops.so"
loadmodule "siputils.so"
loadmodule "xlog.so"
loadmodule "nathelper.so"
loadmodule "dispatcher.so"
loadmodule "path.so"

# ----------------- setting module-specific parameters ---------------


# ----- mi_fifo params -----
modparam("mi_fifo", "fifo_name", "/tmp/kamailio_fifo")


# ----- rr params -----
# add value to ;lr param to cope with most of the UAs
#modparam("rr", "enable_full_lr", 1)
# do not append from tag to the RR (no need for this script)
#modparam("rr", "append_fromtag", 0)


# -- nathelper
modparam("nathelper", "rtpproxy_sock", "/var/run/rtpproxy/rtpproxy.sock")
modparam("nathelper", "received_avp", "$avp(i:80)")

# -- dispatcher params --
modparam("dispatcher", "list_file", "/etc/kamailio/dispatcher.list")

# -- path params --
modparam("path", "use_received", 1)

####### Routing Logic ########


# main request routing logic

route{
        xlog("L_ALERT", "[$rm] from [$fu] to [$tu]\n");
        if (!mf_process_maxfwd_header("10")) {
                sl_send_reply("483","Too Many Hops");
                exit;
        }

        # NAT detection
        route(4);

        if (has_totag()) {
                xlog("L_ALERT", "_____HASTOTAG [$rm] from [$fu] to [$tu]\n");
                # sequential request withing a dialog should
                # take the path determined by record-routing
                if (loose_route()) {
                        xlog("L_ALERT", "_____LOOSE_ROUTE [$rm] from [$fu] to [$tu]\n");
                        t_relay();
                        exit;
                } else {
                        if ( is_method("ACK") ) {
                                if ( t_check_trans() ) {
                                        xlog("L_ALERT", "_____NON-LOOSE, STATEFUL-ACK [$rm] from [$fu] to [$tu]\n");
                                        # non loose-route, but stateful ACK; must be an ACK after a 487 or e.g. 404 from upstream server
                                        t_relay();
                                        exit;
                                } else {
                                        xlog("L_ALERT", "_____ACK_WITHOUT_TRANSACTION [$rm] from [$fu] to [$tu]\n");
                                        # ACK without matching transaction ... ignore and discard.\n");
                                        exit;
                                }
                        }
                        sl_send_reply("404","Not here");
                }
                exit;
        }

        #initial requests

        # CANCEL processing
        if (is_method("CANCEL"))
        {
                if (t_check_trans())
                        t_relay();
                exit;
        }

        t_check_trans();

        # record routing
        if (!is_method("REGISTER|MESSAGE"))
                xlog("L_ALERT", "_____RECORD_ROUTING [$rm] from [$fu] to [$tu]\n");
                record_route();

        #if ($rU==NULL) {
        #       # request with no Username in RURI
        #       sl_send_reply("484","Address Incomplete");
        #       exit;
        #}

        if (check_route_param("nat=yes")) {
                setbflag(6);
        }
        #if (isflagset(5) || isbflagset(6)) {
                route(5);
        #}

        /* example how to enable some additional event routes */
        if (is_method("INVITE")) {
                t_on_reply("1");
                t_on_failure("1");
        }

        if(!ds_is_from_list()) {
                ds_select_domain("0", "0");
        }
        if (!t_relay()) {
                sl_reply_error();
        }
}


# Caller NAT detection route
route[4]{
        force_rport();
        if (nat_uac_test("19")) {
                if (method=="REGISTER") {
                        add_path_received();
                        fix_nated_register();
                } else {
                        fix_nated_contact();
                }
                setflag(5);
        }
        else {
                add_path();
        }
        return;
}

# RTPProxy control
route[5] {
        if (is_method("BYE")) {
                unforce_rtp_proxy();
        } else if (is_method("INVITE")){
                force_rtp_proxy();
        }
        if (!has_totag()) add_rr_param(";nat=yes");
        return;
}

onreply_route[1] {
        xdbg("incoming reply\n");

        #if ((isflagset(5) || isbflagset(6)) && status=~"(183)|(2[0-9][0-9])") {
        if (status=~"(183)|(2[0-9][0-9])") {
                force_rtp_proxy();
        }
        if (isbflagset(6)) {
                fix_nated_contact();
        }
}

failure_route[1] {
        #if (is_method("INVITE") && (isbflagset(6) || isflagset(5))) {
        if (is_method("INVITE")) {
                unforce_rtp_proxy();
        }

        if (t_was_cancelled()) {
                exit;
        }
}







More information about the sr-users mailing list