[OpenSIPS-Users] Opensips NAT + RTPProxy bad "BYE" Command

Milos Mosovsky milos.mosovsky at gmail.com
Wed Aug 28 10:56:59 CEST 2013


Hi All,

Im trying to make Opensips + RTP Proxy works .

My Configuration works well , im sucesfully rewriting private IP ,
sucesfully have 2-way audio

But when i call from NOT NATED client to NATED client , and initiate
BYE request from NO NATED client request is getting private IP

85.13.245.142 is server
85.13.245.139 is not nated client

On this , i get hang up call on nated client , but client who is
behind nat did not get BYE command and dont hang up the call .

Im also attaching .cfg which is full of stupid and unneccessary
command which i have added as im desperate with this issue.

Also noticing that i have rtpproxy_offer/answer on bye command because
i was thinking that it helps but not.

Thanks

Here is debug log from opensips

Aug 27 16:18:43 [14289] DBG:core:parse_msg: SIP Request:
Aug 27 16:18:43 [14289] DBG:core:parse_msg:  method:  <BYE>
Aug 27 16:18:43 [14289] DBG:core:parse_msg:  uri:
<sip:2256 at 192.168.2.2:5060>
Aug 27 16:18:43 [14289] DBG:core:parse_msg:  version: <SIP/2.0>
Aug 27 16:18:43 [14289] DBG:core:parse_headers: flags=2
Aug 27 16:18:43 [14289] DBG:core:parse_via_param: found param type
235, <rport> = <n/a>; state=6
Aug 27 16:18:43 [14289] DBG:core:parse_via_param: found param type
232, <branch> = <z9hG4bK2225959006>; state=16
Aug 27 16:18:43 [14289] DBG:core:parse_via: end of header reached, state=5
Aug 27 16:18:43 [14289] DBG:core:parse_headers: via found, flags=2
Aug 27 16:18:43 [14289] DBG:core:parse_headers: this is the first via
Aug 27 16:18:43 [14289] DBG:core:receive_msg: After parse_msg...
Aug 27 16:18:43 [14289] DBG:core:receive_msg: preparing to run routing
scripts...
Aug 27 16:18:43 [14289] DBG:core:parse_headers: flags=100
Aug 27 16:18:43 [14289] DBG:core:parse_to_param: tag=3803688050
Aug 27 16:18:43 [14289] DBG:core:parse_to: end of header reached, state=29
Aug 27 16:18:43 [14289] DBG:core:parse_to: display={},
ruri={sip:2256 at 85.13.245.142}
Aug 27 16:18:43 [14289] DBG:core:get_hdr_field: <To> [41];
uri=[sip:2256 at 85.13.245.142]
Aug 27 16:18:43 [14289] DBG:core:get_hdr_field: to body
[<sip:2256 at 85.13.245.142>]
Aug 27 16:18:43 [14289] DBG:core:get_hdr_field: cseq <CSeq>: <21> <BYE>
Aug 27 16:18:43 [14289] DBG:maxfwd:is_maxfwd_present: value = 70
Aug 27 16:18:43 [14289] DBG:core:check_ip_address: params
85.13.245.139, 85.13.245.139, 0
Aug 27 16:18:43 [14289] DBG:core:parse_headers: flags=ffffffffffffffff
Aug 27 16:18:43 [14289] DBG:core:get_hdr_field: content_length=0
Aug 27 16:18:43 [14289] DBG:core:get_hdr_field: found end of header
Aug 27 16:18:43 [14289] DBG:core:parse_headers: flags=ffffffffffffffff
Aug 27 16:18:43 [14289] ERROR:rtpproxy:force_rtp_proxy: Unable to parse body
Aug 27 16:18:43 [14289] DBG:uri:has_totag: totag found
Aug 27 16:18:43 [14289] DBG:core:parse_headers: flags=200
Aug 27 16:18:43 [14289] DBG:rr:is_preloaded: is_preloaded: No
Aug 27 16:18:43 [14289] DBG:core:grep_sock_info: checking if host==us:
11==13 &&  [192.168.2.2] == [85.13.245.142]
Aug 27 16:18:43 [14289] DBG:core:grep_sock_info: checking if port 5060
matches port 5060
Aug 27 16:18:43 [14289] DBG:core:check_self: host != me
Aug 27 16:18:43 [14289] DBG:core:grep_sock_info: checking if host==us:
13==13 &&  [85.13.245.142] == [85.13.245.142]
Aug 27 16:18:43 [14289] DBG:core:grep_sock_info: checking if port 5060
matches port 5060
Aug 27 16:18:43 [14289] DBG:rr:after_loose: Topmost route URI:
'sip:85.13.245.142;lr' is me
Aug 27 16:18:43 [14289] DBG:core:parse_headers: flags=200
Aug 27 16:18:43 [14289] DBG:core:get_hdr_field: found end of header
Aug 27 16:18:43 [14289] DBG:rr:find_next_route: No next Route HF found
Aug 27 16:18:43 [14289] DBG:rr:after_loose: No next URI found!
Aug 27 16:18:43 [14289] DBG:core:parse_headers: flags=40
Aug 27 16:18:43 [14289] DBG:core:parse_to_param: tag=4043143610
Aug 27 16:18:43 [14289] DBG:core:parse_to: end of header reached, state=29
Aug 27 16:18:43 [14289] DBG:core:parse_to: display={mikinko},
ruri={sip:1255 at 85.13.245.142}
Aug 27 16:18:43 [14289] DBG:rtpproxy:unforce_rtp_proxy_f: sent unforce command
Aug 27 16:18:43 [14289] DBG:tm:t_newtran: transaction on
entrance=0xffffffffffffffff
Aug 27 16:18:43 [14289] DBG:core:parse_headers: flags=ffffffffffffffff
Aug 27 16:18:43 [14289] DBG:core:parse_headers: flags=78
Aug 27 16:18:43 [14289] DBG:tm:t_lookup_request: start searching:
hash=58322, isACK=0
Aug 27 16:18:43 [14289] DBG:tm:matching_3261: RFC3261 transaction
matched, tid=2225959006
Aug 27 16:18:43 [14289] DBG:tm:t_lookup_request:
REF_UNSAFE:[0x7f7f8ded0920] after is 1
Aug 27 16:18:43 [14289] DBG:tm:t_lookup_request: transaction found
(T=0x7f7f8ded0920)
Aug 27 16:18:43 [14289] DBG:tm:t_retransmit_reply: nothing to retransmit
Aug 27 16:18:43 [14289] DBG:tm:t_unref: UNREF_UNSAFE: [0x7f7f8ded0920]
after is 0
Aug 27 16:18:43 [14289] DBG:core:destroy_avp_list: destroying list (nil)
Aug 27 16:18:43 [14289] DBG:core:receive_msg: cleaning up
Aug 27 16:18:43 [14292] DBG:tm:utimer_routine: timer
routine:5,tl=0x7f7f8ded0b40 next=(nil), timeout=282200000
Aug 27 16:18:43 [14292] DBG:tm:retransmission_handler:
retransmission_handler : request resending (t=0x7f7f8ded0920, BYE
sip:2 ... )
Aug 27 16:18:43 [14292] DBG:tm:set_timer: relative timeout is 2000000
Aug 27 16:18:43 [14292] DBG:tm:insert_timer_unsafe: [6]:
0x7f7f8ded0b40 (284200000)



opensips.cfg

#
# $Id: opensips.cfg 9740 2013-02-05 10:20:39Z vladut-paiu $
#
# OpenSIPS residential configuration script
#     by OpenSIPS Solutions <team at opensips-solutions.com>
#
# This script was generated via "make menuconfig", from
#   the "Residential" scenario.
# You can enable / disable more features / functionalities by
#   re-generating the scenario with different options.#
#
# Please refer to the Core CookBook at:
#      http://www.opensips.org/Resources/DocsCookbooks
# for a explanation of possible statements, functions and parameters.
#


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

debug=3
log_stderror=no
log_facility=LOG_LOCAL0

fork=yes
children=4

/* uncomment the following lines to enable debugging */
debug=6
fork=no
log_stderror=yes

/* uncomment the next line to enable the auto temporary blacklisting of
   not available destinations (default disabled) */
#disable_dns_blacklist=no

/* uncomment the next line to enable IPv6 lookup after IPv4 dns
   lookup failures (default disabled) */
#dns_try_ipv6=yes

/* comment the next line to enable the auto discovery of local aliases
   based on revers DNS on IPs */
auto_aliases=no


listen=udp:85.13.245.142:5060   # CUSTOMIZE ME


disable_tcp=yes

#disable_tls=yes


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

#set module path
mpath="/usr/lib/opensips/modules/"



#proxy
loadmodule "rtpproxy.so"
modparam("rtpproxy", "rtpproxy_sock", "udp:localhost:22222")



loadmodule "nathelper.so"
loadmodule "nat_traversal.so"
modparam("nathelper", "force_socket", "127.0.0.1:22222")


modparam("nathelper", "ping_nated_only", 1)
modparam("nathelper", "sipping_bflag", 8)
modparam("nathelper", "received_avp", "$avp(i:801)")
modparam("rtpproxy", "rtpproxy_timeout", "0.5")



#loadmodule "stun.so"
#modparam("stun","primary_ip","85.13.245.142")
#modparam("stun","primary_port","5060")
#modparam("stun","alternate_ip","85.13.245.143")
#modparam("stun","alternate_port","5060")

#### SIGNALING module
loadmodule "signaling.so"

#### StateLess module
loadmodule "sl.so"

#### Transaction Module
loadmodule "tm.so"
modparam("tm", "fr_timer", 5)
modparam("tm", "fr_inv_timer", 30)
modparam("tm", "restart_fr_on_each_reply", 1)
modparam("tm", "onreply_avp_mode", 1)

#### Record Route Module
loadmodule "rr.so"
/* do not append from tag to the RR (no need for this script) */
modparam("rr", "append_fromtag", 0)

#### MAX ForWarD module
loadmodule "maxfwd.so"

#### SIP MSG OPerationS module
loadmodule "sipmsgops.so"

#### FIFO Management Interface
loadmodule "mi_fifo.so"
modparam("mi_fifo", "fifo_name", "/tmp/opensips_fifo")
modparam("mi_fifo", "fifo_mode", 0666)


#### URI module
loadmodule "uri.so"
modparam("uri", "use_uri_table", 0)

#### USeR LOCation module
loadmodule "usrloc.so"
modparam("usrloc", "nat_bflag", "NAT")
modparam("usrloc", "db_mode",   0)

#### REGISTRAR module
loadmodule "registrar.so"
modparam("registrar", "tcp_persistent_flag", "TCP_PERSISTENT")

/* uncomment the next line not to allow more than 10 contacts per AOR */
#modparam("registrar", "max_contacts", 10)

#### ACCounting module
loadmodule "acc.so"
/* what special events should be accounted ? */
modparam("acc", "early_media", 0)
modparam("acc", "report_cancels", 0)
/* by default we do not adjust the direct of the sequential requests.
   if you enable this parameter, be sure the enable "append_fromtag"
   in "rr" module */
modparam("acc", "detect_direction", 0)
modparam("acc", "failed_transaction_flag", "ACC_FAILED")
/* account triggers (flags) */
modparam("acc", "log_flag", "ACC_DO")
modparam("acc", "log_missed_flag", "ACC_MISSED")


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

# main request routing logic

route{
if (!mf_process_maxfwd_header("10")) {
sl_send_reply("483","Too Many Hops");
exit;
}
  if (nat_uac_test("3")) {

        if (is_method("REGISTER") && !is_present_hf("Record-Route")) {

            #Rewrite contact with source IP of signalling
            fix_nated_contact();
            fix_nated_register();
        };
    if ( is_method("INVITE") )
           {
                rtpproxy_offer();
                fix_nated_sdp("1"); # Add direction=active to SDP
           };
  setbflag(8);

    };
if(is_method("BYE"))
{
              if(rtpproxy_offer())
                        {
                                t_on_reply("1");
                        }
                        else
                        {
                                t_on_reply("2");
                        }

}
if(is_method("ACK") && has_body("application/sdp") )
{
rtpproxy_answer();
}
if (has_totag()) {
# sequential request withing a dialog should
# take the path determined by record-routing
if (loose_route()) {
if (is_method("BYE")) {
unforce_rtp_proxy();
setflag(ACC_DO); # do accounting ...
setflag(ACC_FAILED); # ... even if the transaction fails
} else if (is_method("INVITE")) {
# even if in most of the cases is useless, do RR for
# re-INVITEs alos, as some buggy clients do change route set
# during the dialog.
record_route();
}

# route it out to whatever destination was set by loose_route()
# in $du (destination URI).
route(relay);
} else {
if ( is_method("ACK") ) {
if ( t_check_trans() ) {
# non loose-route, but stateful ACK; must be an ACK after
# a 487 or e.g. 404 from upstream server
t_relay();
exit;
} else {
# ACK without matching transaction ->
# ignore and discard
exit;
}
}
sl_send_reply("404","Not here");
}
exit;
}

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

t_check_trans();

if ( !(is_method("REGISTER")  ) ) {
if (from_uri==myself)
{
} else {
# if caller is not local, then called number must be local
if (!uri==myself) {
send_reply("403","Rely forbidden");
exit;
}
}
}

# preloaded route checking
if (loose_route()) {
xlog("L_ERR",
"Attempt to route with preloaded Route's [$fu/$tu/$ru/$ci]");
if (!is_method("ACK"))
sl_send_reply("403","Preload Route denied");
exit;
}

# record routing
if (!is_method("REGISTER|MESSAGE"))
record_route();

# account only INVITEs
if (is_method("INVITE")) {
setflag(ACC_DO); # do accounting
}

if (!uri==myself) {
append_hf("P-hint: outbound\r\n");
route(relay);
}

# requests for my domain
if (is_method("PUBLISH|SUBSCRIBE"))
{
sl_send_reply("503", "Service Unavailable");
exit;
}

if (is_method("REGISTER"))
{
if (   0 ) setflag(TCP_PERSISTENT);
if (!save("location"))
sl_reply_error();

exit;
}

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

# do lookup with method filtering
if (!lookup("location","m")) {
t_newtran();
t_reply("404", "Not Found");
exit;
}

# when routing via usrloc, log the missed calls also
setflag(ACC_MISSED);
route(relay);
route(1);
}


route[relay] {
# for INVITEs enable some additional helper routes
if (is_method("INVITE")) {
t_on_branch("per_branch_ops");
t_on_reply("handle_nat");
t_on_failure("missed_call");
if(rtpproxy_offer())
{
t_on_reply("1");
}
else
{
t_on_reply("2");
}

}

if (!t_relay()) {
send_reply("500","Internal Error");
};
exit;
}




branch_route[per_branch_ops] {
xlog("new branch at $ru\n");
}


onreply_route[handle_nat] {
xlog("incoming reply\n");
}


failure_route[missed_call] {
if (t_was_cancelled()) {
exit;
}

# uncomment the following lines if you want to block client
# redirect based on 3xx replies.
##if (t_check_status("3[0-9][0-9]")) {
##t_reply("404","Not found");
## exit;
##}

}




 onreply_route[2] {
  xdbg("incoming reply\n");
  if (has_body("application/sdp")) rtpproxy_offer();
  exit;
}
route[1] {

    ################## NAT ######################
#    if (uri=~"[@:](192\.168\.10\.172\.(1[6-9]2[0-9]3[0-1])\.)" &&
!search("^Route:")) {
#        sl_send_reply("479", "We don't forward to private IP addresses");
#        exit;
#    };

    # if client or server know to be behind a NAT, enable relay
    if (isbflagset(6)) {
        if (has_body("application/sdp")) {
            rtpproxy_offer("o");
        };
    };

    t_on_reply("1");
    ################## NAT ######################


    # send it out now; use stateful forwarding as it works
    # reliably even for UDP2TCP
    if (!t_relay()) {
        sl_reply_error();
    };

    exit;
}

onreply_route[1] {
    xdbg("incoming reply\n");
        if (has_body("application/sdp")) rtpproxy_answer();
        exit;

    ################## NAT ######################
    if (isbflagset(6) && status =~ "(183)|2[0-9][0-9]") {
        fix_nated_contact();
        if (has_body("application/sdp")) {
            rtpproxy_answer("o");
        };

        # Is this a transaction behind a NAT and we did not
        # know at time of request processing?
    } else if (nat_uac_test("1")) {
        fix_nated_contact();
    };
    ################## NAT ######################

}

failure_route[1] {
    unforce_rtp_proxy();
}



More information about the Users mailing list