[SR-Users] websocket relay

jaflong jaflong jaflong at yandex.com
Tue Feb 4 15:36:18 CET 2014


Hi Everyone,

I want kamailio to do a single task, that is relay incoming (webrtc sip over websockets) connections to asterisk. All sip handling is to be done is asterisk.
I have configured asterisk with tls settings.

My sample conf file is below

At the moment I am getting these errors

ERROR: tm [ut.h:343]: uri2dst2(): no corresponding socket for af 2
ERROR: tm [t_fwd.c:520]: prepare_new_uac(): ERROR: can't fwd to af 2, proto 3  (no corresponding listening socket)

Please can anyone provide any advise to complete this configuration 



listen=tcp:10.2.3.4:5080
enable_tls=yes 
tcp_connection_lifetime=3605
tcp_accept_no_cl=yes 


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

# set paths to location of modules (to sources or installation folders)
mpath="/usr/local/lib64/kamailio/modules/"

loadmodule "mi_fifo.so"
loadmodule "kex.so"
loadmodule "corex.so"
loadmodule "tm.so"
loadmodule "tmx.so"
loadmodule "sl.so"
loadmodule "rr.so"
loadmodule "pv.so"
loadmodule "maxfwd.so"
loadmodule "usrloc.so"
loadmodule "registrar.so"
loadmodule "textops.so"
loadmodule "siputils.so"
loadmodule "xlog.so"
loadmodule "sanity.so"
loadmodule "ctl.so"
loadmodule "cfg_rpc.so"
loadmodule "mi_rpc.so"
loadmodule "acc.so"
loadmodule "sdpops.so"
loadmodule "nathelper.so"
loadmodule "xhttp.so"
loadmodule "websocket.so"
loadmodule "tls.so"




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

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


# ----- tm params -----
# auto-discard branches from previous serial forking leg
modparam("tm", "failure_reply_mode", 3)
# default retransmission timeout: 30sec
modparam("tm", "fr_timer", 30000)
# default invite retransmission timeout after 1xx: 120sec
modparam("tm", "fr_inv_timer", 120000)


# ----- 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)


# ----- registrar params -----
modparam("registrar", "method_filtering", 1)
/* uncomment the next line to disable parallel forking via location */
# modparam("registrar", "append_branches", 0)
/* uncomment the next line not to allow more than 10 contacts per AOR */
#modparam("registrar", "max_contacts", 10)
# max value for expires of registrations
modparam("registrar", "max_expires", 3600)
# set it to 1 to enable GRUU
modparam("registrar", "gruu_enabled", 0)




# ----- nathelper params -----
modparam("nathelper|registrar", "received_avp", "$avp(RECEIVED)")

# WITH_TLS
# ----- tls params -----
modparam("tls", "config", "/usr/local/etc/kamailio/tls.cfg")




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

event_route[xhttp:request] {
    set_reply_close();
    set_reply_no_connect();

    xlog("L_INFO", "HTTP Request Received\n");

    if ($hdr(Upgrade)=~"websocket" && $hdr(Connection)=~"Upgrade" && $rm =~"GET") {

        if (ws_handle_handshake()) {

            exit;
        }
    }

    xhttp_reply("404", "Not Found", "", "");
}


request_route {

        if ((($Rp == MY_WS_PORT || $Rp == MY_WSS_PORT) && !(proto == WS || proto == WSS))) {
                xlog("L_WARN", "SIP request received on $Rp\n");
                sl_send_reply("403", "Forbidden");
                exit;
        }

        route(REQINIT);

        route(NATDETECT);

        route(RELAY);
}




route[REQINIT] {

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

        if(!sanity_check("1511", "7")) {
            xlog("Malformed SIP message from $si:$sp\n");
            exit;
        }
}


route[NATDETECT] {
    if (nat_uac_test(64)) {
        # Do NAT traversal stuff for requests from a WebSocket
        # connection - even if it is not behind a NAT!
        # This won't be needed in the future if Kamailio and the
        # WebSocket client support Outbound and Path.
        force_rport();
        if (is_method("REGISTER"))
            fix_nated_register();
        else {
            if (!add_contact_alias()) {
                xlog("L_ERR", "Error aliasing contact <$ct>\n");
                sl_send_reply("400", "Bad Request");
                exit;
            }
        }
    }
}


route[RELAY] {

    xlog("L_INFO", "Forwarding Request\n");

	$ru = "sip:"+$rU+"10.2.3.5:5080;transport=tcp";

    if (!t_relay_to_tls()) {
        sl_reply_error(); 
        return; 
    }

    exit;
}
        



More information about the sr-users mailing list