欣赏一段Kamailio路由脚本


#!KAMAILIO

#!define MULTIDOMAIN 0

log_stderror=no
debug=3

log_facility=LOG_LOCAL0
log_prefix="{$mt $hdr(CSeq) $ci} "
log_name="kamailio"

# number of SIP routing processes
children=8

# Interface definition
listen=udp:192.168.100.2:5060 name "udp"
listen=tcp:192.168.100.2:5060 name "tcp"
listen=tls:192.168.100.2:8088 name "wss"
listen=tls:192.168.100.2:5061 name "tls"
enable_tls=yes

# life time of TCP connection when there is no traffic
# a bit higher than registration expires to cope with UA behind NAT
tcp_connection_lifetime=3605
tcp_accept_no_cl=yes


####### Modules Section ########
loadmodule "kex.so"
loadmodule "corex.so"
loadmodule "tm.so"
loadmodule "tmx.so"
loadmodule "sl.so"
loadmodule "rr.so"
loadmodule "pv.so"
loadmodule "textops.so"
loadmodule "siputils.so"
loadmodule "xlog.so"
loadmodule "counters.so"
loadmodule "tls.so"
loadmodule "dialog.so"
loadmodule "sipdump.so"
loadmodule "debugger.so"


modparam("tls", "private_key", "/etc/kamailio/ssl/cakey.pem");
modparam("tls", "certificate", "/etc/kamailio/ssl/cacert.pem");
modparam("tls", "tls_method", "TLSv1.2");

modparam("debugger", "log_level_name", "cfgtrace")

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

request_route {
    xdbg("==> $rm (initial request) from $si to $Ri ($RAi)\n");

    if (!is_method("ACK")) {
        if (t_precheck_trans()) {
            t_check_trans();
            exit;
        }
        t_check_trans();
    }

    # - remove preloaded route headers
    remove_hf("Route");
    if (is_method("INVITE|SUBSCRIBE|OPTIONS|NOTIFY|MESSAGE")) {
        record_route();
    }

    route(PSTN);

    exit;
}
# Wrapper for relaying requests
route[RELAY] {
    if (!t_relay()) {
        sl_reply_error();
    }

    exit;
}


# PSTN GW routing
route[PSTN] {
    $rd = "192.168.100.123";
    $rp = "5061";
    set_send_socket("tls");
    $du = $ru + ";transport=tls";

    route(RELAY);
}

onreply_route {
    xerr("$Rp $Rn $Rut");
    dbg_sip_msg();

    if ($Rp == 8088 && proto != WS && proto != WSS) {
        xwarn("SIP response received on $Rp\n");
        drop;
    }
}

好几个想不到:

  • 没想到有这样的函数dbg_sip_msg()
  • listen里面可以增加name参数,set_send_socket|set_send_socket_name|$fs去对应,这个也是没想到的
  • $RAi,$Rut,没想到还有这样的伪变量

还得加油。

你可能感兴趣的:(Kamailio,Kamailio脚本)