kamailio:如何在 VIA header 中发送带有端口号的回复

kamailio: how to send replies with port number in VIA header

使用 kamailio 5.4v 版

请帮我发送 replies/forwards 以包含 VIA header 端口,因为我可以看到它只是发送 IP 而不是 VIA header 中的端口。

我的路由和路由中继的 kamailio cfg 文件如下所示。

route[RELAY] {

        # enable additional event routes for forwarded requests
        # - serial forking, RTP relaying handling, a.s.o.
        if (is_method("INVITE|BYE|SUBSCRIBE|UPDATE")) {
                if(!t_is_set("branch_route")) t_on_branch("MANAGE_BRANCH");
        }
        if (is_method("INVITE|SUBSCRIBE|UPDATE")) {
                if(!t_is_set("onreply_route")) t_on_reply("MANAGE_REPLY");
        }
        if (is_method("INVITE")) {
                if(!t_is_set("failure_route")) t_on_failure("MANAGE_FAILURE");
        }
        if (is_method("ACK|BYE")) {
                $duri= $ruri;
                t_relay();
                exit;
        }

        if (!t_relay()) {
                sl_reply_error();
        }
        exit;
}

# Per SIP request initial checks
route[REQINIT] {
#!ifdef WITH_ANTIFLOOD
        # flood detection from same IP and traffic ban for a while
        # be sure you exclude checking trusted peers, such as pstn gateways
        # - local host excluded (e.g., loop to self)
        if(src_ip!=myself) {
                if($sht(ipban=>$si)!=$null) {
                        # ip is already blocked
                        xdbg("request from blocked IP - $rm from $fu (IP:$si:$sp)\n");
                        exit;
                }
                if (!pike_check_req()) {
                        xlog("L_ALERT","ALERT: pike blocking $rm from $fu (IP:$si:$sp)\n");
                        $sht(ipban=>$si) = 1;
                        exit;
                }
        }
#!endif
        if($ua =~ "friendly-scanner|sipcli|VaxSIPUserAgent") {
                # silent drop for scanners - uncomment next line if want to reply
                # sl_send_reply("200", "OK");
                exit;
        }

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

        if(is_method("OPTIONS") && uri==myself && $rU==$null) {
                sl_send_reply("200","Keepalive");
                exit;
        }

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


# Handle requests within SIP dialogs
route[WITHINDLG] {
        if (!has_totag()) return;

        # sequential request withing a dialog should
        # take the path determined by record-routing
        if (loose_route()) {
                route(DLGURI);
                if (is_method("BYE")) {
                        setflag(FLT_ACC); # do accounting ...
                        setflag(FLT_ACCFAILED); # ... even if the transaction fails
                } else if ( is_method("ACK") ) {
                        # ACK is forwarded statelessly
                        route(NATMANAGE);
                } else if ( is_method("NOTIFY") ) {
                        # Add Record-Route for in-dialog NOTIFY as per RFC 6665.
                        record_route();
                }
                route(RELAY);
                exit;
        }

        if (is_method("SUBSCRIBE") && uri == myself) {
                # in-dialog subscribe requests
                route(PRESENCE);
                exit;
        }
        if ( is_method("ACK|BYE") ) {
                #xlog("started ACK if else condition line 622 \n");
                if ( t_check_trans() ) {
                        # no loose-route, but stateful ACK;
                        # must be an ACK after a 487
                        # or e.g. 404 from upstream server
                        route(RELAY);
                        exit;
                } else {
                        route(RELAY);
                        # Added after observing ACK not being sent by CSCF
                        exit;
                }
        }
        sl_send_reply("404","Not here");
        exit;
}

# Caller NAT detection
route[NATDETECT] {
#!ifdef WITH_NAT
        force_rport();
        if (nat_uac_test("19")) {
                if (is_method("REGISTER")) {
                        fix_nated_register();
                } else {
                        if(is_first_hop()) {
                                set_contact_alias();
                        }
                }
                setflag(FLT_NATS);
        }
#!endif
        return;
}

# RTPProxy control and signaling updates for NAT traversal
route[NATMANAGE] {
#!ifdef WITH_NAT
        if (is_request()) {
                if(has_totag()) {
                        if(check_route_param("nat=yes")) {
                                setbflag(FLB_NATB);
                        }
                }
        }
        if (!(isflagset(FLT_NATS) || isbflagset(FLB_NATB))) return;

        if(nat_uac_test("8")) {
                rtpproxy_manage("co");
        } else {
                rtpproxy_manage("cor");
        }

        if (is_request()) {
                if (!has_totag()) {
                        if(t_is_branch_route()) {
                                add_rr_param(";nat=yes");
                        }
                }
        }
        if (is_reply()) {
                if(isbflagset(FLB_NATB)) {
                        if(is_first_hop())
                                set_contact_alias();
                }
        }
#!endif
        return;
}

# URI update for dialog requests
route[DLGURI] {
#!ifdef WITH_NAT
        if(!isdsturiset()) {
                handle_ruri_alias();
        }
#!endif
        return;
}

# Routing to foreign domains
route[SIPOUT] {
        if (uri==myself) return;

        append_hf("P-hint: outbound\r\n");
        route(RELAY);
        exit;
}

# PSTN GW routing
route[PSTN] {
#!ifdef WITH_PSTN
        $var(uri) = $sel(ruri);
        xavp_params_explode("$(var(uri){s.unbracket})", "uri"); $var(cic) = $xavp(uri=>cic[0]);

        if (($rU=~"^(\+)[0-9]{1,20}$")) {
           if(mt_match("ace", "$rU","0")) {
                insert_hf("Route: <sip:"+"$var(mtval)"+ ";lr\r\n");
                route(SYLKSERVERPOST);
                }
        }

        route(RELAY);
        exit;
#!endif
        return;
}

# Sylkserver routing
route[SYLKSERVERPOST] {
     if(mt_match("ace", "$rU","0")) {
         t_relay_to("udp:10.0.0.4", "0x01");
         exit;
   }
}

正在转发示例 INVITE

Session Initiation Protocol (SIP as raw text)
    INVITE sip:+440000000@spe01.vodafone.com SIP/2.0\r\n
    Record-Route: <sip:10.1.1.3;lr>\r\n
    Route: <sip:10.1.1.4:5060;lr>\r\n
    Via: SIP/2.0/UDP 10.1.1.3;branch=z9hG4bK4b7b.693512744570a1e2ea323648d7423180.0\r\n
    From: <sip:+4400000000@10.1.1.2:5060>;tag=1\r\n
    To: <sip:+4416300000001@spe01.vodafone.com:5060;user=phone>\r\n
    Call-ID: 1-9256@10.1.1.4\r\n
    Date: TUE, 13 DEC 2016 09:34:57 GMT\r\n
    Supported: timer,resource-priority,replaces\r\n
    Min-SE: 900\r\n
    User-Agent: Cisco-CUCM10.5\r\n
    Allow: INVITE, OPTIONS, INFO, BYE, CANCEL, ACK, PRACK, UPDATE, REFER, SUBSCRIBE, NOTIFY\r\n
    CSeq: 101 INVITE\r\n

请通过header

帮助下面如何更改
Via: SIP/2.0/UDP 10.1.1.3;branch=z9hG4bK4b7b.693512744570a1e2ea323648d7423180.0

Via: SIP/2.0/UDP 10.1.1.3:5060;branch=z9hG4bK4b7b.693512744570a1e2ea323648d7423180.0

我的 kamailio 服务器已经列出到 UDP 上的 IP:5060 端口。

请提前帮忙谢谢。

您可能advertised_port感兴趣

https://www.kamailio.org/wiki/cookbooks/5.4.x/core

请注意,如果端口是 5060 udp,SIP RFC 允许不发送端口。