比较Kamailio和OpenSIPS的重写contact函数
Kamailio:调用set_contact_alias()之后,在原有的contact的后面增加参数,具体地说,就是网络地址,网络端口和transport,好处是收到后续请求之时可以恢复原有contact的内容(当然也有坏处,就是增加参数之后导致包大,可能超过MTU)
OpenSIPS:调用fix_nated_contact()之后,用网络地址和网络端口直接覆盖了在原有的contact,那么当收到后续请求时不太可能恢复原有contact的内容。窃以为,一定要慎重
比如,下图所示,OpenSIPS就不要修改uac的contact,显然如此
UAC--->第三方Proxy--->OpenSIPS--->FreeSWITCH
参考链接:
https://kb.smartvox.co.uk/opensips/nat-contact-and-via-fixing-in-sip-part-3/
当然,我们可以模仿set_contact_alias函数
route[set_contact_alias] {if (is_present_hf("contact")) {$var(sut) = $si + "~" + $sp + "~" + $socket_in(proto); # 远端网络地址$var(ct) = $(ct{re.subst,/^(.*)<(.*)>/\2/}); # 取contact <> 里面的内容# 更换成新的contact$var(new_ct) = "<" + $var(ct) + ";my_alias=" + $var(sut) + ">";remove_hf("contact");insert_hf("Contact: $var(new_ct)\r\n", "Call-ID");}
}route[restore_contact_by_alias] {if (!has_totag()) { # 对话内请求才能调用这个路由return;}# xlog("***ru = $ru, du = $du\n");if ($du != NULL) { # 如果已经设置了$du,那么不能再调用这个路由return;}$var(my_alias) = $(ru{nameaddr.param,my_alias});# xlog("***my_alias = $var(my_alias)\n");if ($var(my_alias) != NULL) {$var(ip) = $(var(my_alias){s.select,0,~});$var(port) = $(var(my_alias){s.select,1,~});$var(transport) = $(var(my_alias){s.select,2,~});$var(url) = "sip:" + $var(ip) + ":" + $var(port) + ";transport=" + $var(transport);# xlog("url = $var(url)\n");setdsturi($var(url));$ru = $(ru{re.subst,/^(sip:.*);my_alias=.*/\1/}); # 删除ru里面的my_alias以及内容 }
}
完整的路由脚本如下:
####### Global Parameters #########/* uncomment the following lines to enable debugging */
#debug_mode=yeslog_level=3
xlog_level=3
stderror_enabled=no
syslog_enabled=yes
syslog_facility=LOG_LOCAL0udp_workers=4/* uncomment the next line to enable the auto temporary blacklisting ofnot available destinations (default disabled) */
#disable_dns_blacklist=no/* uncomment the next line to enable IPv6 lookup after IPv4 dnslookup failures (default disabled) */
#dns_try_ipv6=yessocket=udp:172.20.10.6:5060 # CUSTOMIZE ME
socket=tcp:172.20.10.6:5060 # CUSTOMIZE ME####### Modules Section #########set module path
mpath="/usr/lib/x86_64-linux-gnu/opensips/modules/"#### SIGNALING module
loadmodule "signaling.so"#### StateLess module
loadmodule "sl.so"#### Transaction Module
loadmodule "tm.so"
modparam("tm", "fr_timeout", 5)
modparam("tm", "fr_inv_timeout", 30)
modparam("tm", "restart_fr_on_each_reply", 0)
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)#### MYSQL module
loadmodule "db_mysql.so"#### HTTPD module
loadmodule "httpd.so"
modparam("httpd", "port", 8888)#### USeR LOCation module
loadmodule "usrloc.so"
modparam("usrloc", "nat_bflag", "NAT")
modparam("usrloc", "working_mode_preset", "single-instance-sql-write-back")
modparam("usrloc", "db_url","mysql://opensips:opensipsrw@localhost/opensips") # CUSTOMIZE ME#### REGISTRAR module
loadmodule "registrar.so"
modparam("registrar", "tcp_persistent_flag", "TCP_PERSISTENT")
modparam("registrar", "received_avp", "$avp(received_nh)")/* 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 to enable "append_fromtag"in "rr" module */
modparam("acc", "detect_direction", 0)#### NAT modules
loadmodule "nathelper.so"
modparam("nathelper", "natping_interval", 10)
modparam("nathelper", "ping_nated_only", 1)
modparam("nathelper", "sipping_bflag", "SIP_PING_FLAG")
modparam("nathelper", "sipping_from", "sip:pinger@127.0.0.1") #CUSTOMIZE ME
modparam("nathelper", "received_avp", "$avp(received_nh)")# loadmodule "rtpproxy.so"
# modparam("rtpproxy", "rtpproxy_sock", "udp:localhost:12221") # CUSTOMIZE ME#### MI_HTTP module
loadmodule "mi_http.so"loadmodule "proto_udp.so"
loadmodule "proto_tcp.so"
####### Routing Logic ######### main request routing logicroute{xlog("$rm|$fU|$tU|$ci from $si:$sp\n");# initial NAT handling; detect if the request comes from behind a NAT# and apply contact fixingforce_rport();#if (nat_uac_test(23)) {if (true) {if (is_method("REGISTER")) {fix_nated_register();setbflag("NAT");} else {# fix_nated_contact();route(set_contact_alias);setflag("NAT");}}if (!mf_process_maxfwd_header(10)) {send_reply(483,"Too Many Hops");exit;}if (has_totag()) {# handle hop-by-hop ACK (no routing required)if ( is_method("ACK") && t_check_trans() ) {t_relay();exit;}# sequential request within a dialog should# take the path determined by record-routingif ( !loose_route() ) {# we do record-routing for all our traffic, so we should not# receive any sequential requests without Route hdr.send_reply(404,"Not here");exit;}route(restore_contact_by_alias);if (is_method("BYE")) {# do accounting even if the transaction failsdo_accounting("log","failed");}if (check_route_param("nat=yes"))setflag("NAT");# route it out to whatever destination was set by loose_route()# in $du (destination URI).route(relay);exit;}# CANCEL processingif (is_method("CANCEL")) {if (t_check_trans())t_relay();exit;}# absorb retransmissions, but do not create transactiont_check_trans();if ( !(is_method("REGISTER") ) ) {if (is_myself("$fd")) {} else {# if caller is not local, then called number must be localif (!is_myself("$rd")) {send_reply(403,"Relay Forbidden");exit;}}}# preloaded route checkingif (loose_route()) {xlog("L_ERR","Attempt to route with preloaded Route's [$fu/$tu/$ru/$ci]");if (!is_method("ACK"))send_reply(403,"Preload Route denied");exit;}# record routingif (!is_method("REGISTER|MESSAGE"))record_route();# account only INVITEsif (is_method("INVITE")) {do_accounting("log");}if (!is_myself("$rd")) {append_hf("P-hint: outbound\r\n");route(relay);}# requests for my domainif (is_method("PUBLISH|SUBSCRIBE")) {send_reply(503, "Service Unavailable");exit;}if (is_method("REGISTER")) {if ($socket_in(proto) == "tcp")setflag("TCP_PERSISTENT");if (isflagset("NAT")) {setbflag("SIP_PING_FLAG");}# store the registration and generate a SIP replyif (!save("location"))xlog("failed to register AoR $tu\n");exit;}if ($rU==NULL) {# request with no Username in RURIsend_reply(484,"Address Incomplete");exit;}# do lookup with method filteringif (!lookup("location", "method-filtering")) {t_reply(404, "Not Found");exit;}if (isbflagset("NAT")) setflag("NAT");# when routing via usrloc, log the missed calls alsodo_accounting("log","missed");route(relay);
}route[relay] {# for INVITEs enable some additional helper routesif (is_method("INVITE")) {# if (isflagset("NAT") && has_body("application/sdp")) {# rtpproxy_offer("ro");# }t_on_branch("per_branch_ops");t_on_reply("handle_nat");t_on_failure("missed_call");}if (isflagset("NAT")) {add_rr_param(";nat=yes");}if (!t_relay()) {send_reply(500,"Internal Error");}exit;
}branch_route[per_branch_ops] {xlog("new branch at $ru\n");
}onreply_route[handle_nat] {#if (nat_uac_test(1))# fix_nated_contact();route(set_contact_alias);# if ( isflagset("NAT") && has_body("application/sdp") )# rtpproxy_answer("ro");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;##}
}route[set_contact_alias] {if (is_present_hf("contact")) {$var(sut) = $si + "~" + $sp + "~" + $socket_in(proto); # 远端网络地址$var(ct) = $(ct{re.subst,/^(.*)<(.*)>/\2/}); # 取contact <> 里面的内容# 更换成新的contact$var(new_ct) = "<" + $var(ct) + ";my_alias=" + $var(sut) + ">";remove_hf("contact");insert_hf("Contact: $var(new_ct)\r\n", "Call-ID");}
}route[restore_contact_by_alias] {if (!has_totag()) { # 对话内请求才能调用这个路由return;}# xlog("***ru = $ru, du = $du\n");if ($du != NULL) { # 如果已经设置了$du,那么不能再调用这个路由return;}$var(my_alias) = $(ru{nameaddr.param,my_alias});# xlog("***my_alias = $var(my_alias)\n");if ($var(my_alias) != NULL) {$var(ip) = $(var(my_alias){s.select,0,~});$var(port) = $(var(my_alias){s.select,1,~});$var(transport) = $(var(my_alias){s.select,2,~});$var(url) = "sip:" + $var(ip) + ":" + $var(port) + ";transport=" + $var(transport);# xlog("url = $var(url)\n");setdsturi($var(url));$ru = $(ru{re.subst,/^(sip:.*);my_alias=.*/\1/}); # 删除ru里面的my_alias以及内容 }
}
以上脚本在OpenSIPS3.4.3上调试通过,但没测试其他版本
于2024年2月8日(次日即除夕)
全文完
相关文章:
比较Kamailio和OpenSIPS的重写contact函数
Kamailio:调用set_contact_alias()之后,在原有的contact的后面增加参数,具体地说,就是网络地址,网络端口和transport,好处是收到后续请求之时可以恢复原有contact的内容(当然也有坏处࿰…...
【ETOJ P1046】斐波那契数列 题解(数学+动态规划)
题目描述 给定一个整数 T T T,表示样例数。 对于每个样例,给定一个整数 n n n,求斐波那契数列的第 n n n 项。 斐波那契数列定义为 f ( 1 ) f ( 2 ) 1 f(1) f(2) 1 f(1)f(2)1, f ( n ) f ( n − 1 ) f ( n − 2 ) f(…...
编码技巧——基于RedisTemplate的RedisClient实现、操作Lua脚本
1. 背景 在新公司的脚手架中开发,需要用到redis,发现没有封装好一套能集成各种常用命令、包括Lua脚本的方便使用的RedisTemplateClient,于是自己来实现下; springboot整合redis之后,提供了操作redis的简便方式&#…...

Asp .Net Core 系列:Asp .Net Core 集成 Panda.DynamicWebApi
文章目录 简介Asp .Net Core 集成 Panda.DynamicWebApi配置原理什么是POCO Controller?POCO控制器原理ControllerFeatureProvider实现自定义判断规则IApplicationModelConventionPanda.DynamicWebApi中的实现ConfigureApiExplorer()ConfigureSelector()ConfigurePar…...

【PTA浙大版《C语言程序设计(第4版)》|编程题】习题7-3 判断上三角矩阵(附测试点)
目录 输入格式: 输出格式: 输入样例: 输出样例: 代码呈现 测试点 上三角矩阵指主对角线以下的元素都为0的矩阵;主对角线为从矩阵的左上角至右下角的连线。 本题要求编写程序,判断一个给定的方阵是否…...

JVM 性能调优 - 参数调优(3)
查看 JVM 内存的占用情况 编写代码 package com.test;public class PrintMemoryDemo {public static void main(String[] args) {// 堆内存总量long totalMemory Runtime.getRuntime().totalMemory();// jvm 试图使用的最大堆内存long maxMemory Runtime.getRuntime().maxM…...

Django(十)
1. Ajax请求 浏览器向网站发送请求时:URL 和 表单的形式提交。 GETPOST 特点:页面刷新。 除此之外,也可以基于Ajax向后台发送请求(偷偷的发送请求)。 依赖jQuery编写ajax代码 $.ajax({url:"发送的地址"…...
OpenHarmony开源鸿蒙开发之旅
文章目录 一、op系统架构二、op系统构建1. op源代码目录2. op系统构建3. op开发环境搭建 三、op系统的子系统四、op系统芯片移植五、op系统启动流程六、op系统组件七、驱动框架 一、op系统架构 二、op系统构建 1. op源代码目录 2. op系统构建 3. op开发环境搭建 三、op系统…...
SpringBoot之整合PageHelper分页插件
SpringBoot之整合PageHelper分页插件 文章目录 SpringBoot之整合PageHelper分页插件1. 引入坐标2. application.yml配置3. 基本使用4. 对多个查询执行分页1. 默认第一个Select语句会执行分页2. 让Pagehelper也能执行多个分页的方法3. 完整案例 详细配置请查看官网或MyBatis分页…...
Android java基础_类的封装
一.面向对象编程的引入 写一个简单的程序输出张三,李四的名字 class Person {String name;String getName() {return "guangdong "name;} };public class Oop {public static void main(String args[]) {Person p1 new Person();p1.name "zhangs…...
Vue-57、Vue技术路由的参数如何传递
query参数传递 1、传递参数 <!-- 跳转路由并携带query参数,to的字符串写法--> <router-link :to"/home/message/detail?id${p.id}&title${p.title}"> {{p.title}} </router-link><!-- 跳转路由…...

《MySQL 简易速速上手小册》第1章:MySQL 基础和安装(2024 最新版)
文章目录 1.1 MySQL 概览:版本、特性和生态系统1.1.1 基础知识1.1.2 重点案例:使用 Python 实现 MySQL 数据的 CRUD 操作1.1.3 拓展案例 1:使用 Python 实现 MySQL 数据备份**1.1.4 拓展案例 2:使用 Python 分析 MySQL 数据 1.2 安…...

Linux 软件管理(YUM RPM)
1 YUM yum(全称为 Yellow dog Updater, Modified)是一个在Fedora和RedHat以及CentOS中的Shell前端软件包管理器。基于RPM包管理,能够从指定的服务器自动处理依赖性关系,并且一次安装所有依赖的软件包,无须繁琐地一次次…...
【Makefile语法 05】动静态库编译链接
目录 一、多文件项目源代码 二、静态库编译链接 三、动态库编译链接 一、多文件项目源代码 // include/add.hpp#pragma once int add(int a, int b); // include/sub.hpp#pragma once int sub(int a, int b); // src/add.cpp#include "add.hpp"int add(int a, …...
JS - 处理元素滚动
业务功能中时常有元素滚动的功能,现在就总结一下一些常用的事件。 一、定位滚动元素 做一切滚动操作之前都应该先定位到滚动元素,再做其他操作,如滚动顶部,获取滚动距离、禁止滚动等。 把以下代码复制粘贴到浏览器 Console 面板…...

JavaScript滚动事件
🧑🎓 个人主页:《爱蹦跶的大A阿》 🔥当前正在更新专栏:《VUE》 、《JavaScript保姆级教程》、《krpano》、《krpano中文文档》 ✨ 前言 滚动是网页交互不可或缺的一部分。监听页面和元素的滚动事件,可以帮助…...

4.0 Zookeeper Java 客户端搭建
本教程使用的 IDE 为 IntelliJ IDEA,创建一个 maven 工程,命名为 zookeeper-demo,并且引入如下依赖,可以自行在maven中央仓库选择合适的版本,介绍原生 API 和 Curator 两种方式。 IntelliJ IDEA 相关介绍:…...
C#既然数组长度不可改变,那么如何动态调整集合类型数组大小,以便添加或删除元素?
目录 1.使用动态数组(ArrayList): 2.使用 jagged array(不规则数组): 3.使用 List : 4.使用数组复制: 在C#中,数组的长度是固定的,一旦声明和初始化&…...

3.1 Verilog 连续赋值
关键词:assign, 全加器 连续赋值语句是 Verilog 数据流建模的基本语句,用于对 wire 型变量进行赋值。: 格式如下 assign LHS_target RHS_expression ; LHS(left hand side) 指赋值操作…...

【http】2、http request header Origin 属性、跨域 CORS、同源、nginx 反向代理、预检请求
文章目录 一、Origin 含义二、跨源资源共享:**Cross-Origin Resource Sharing** CORS2.1 跨域的定义2.2 功能概述2.3 场景示例2.3.1 简单请求2.3.2 Preflighted requests:预检请求 2.4 header2.4.1 http request header2.4.1.1 Origin2.4.1.2 Access-Con…...

全球首个30米分辨率湿地数据集(2000—2022)
数据简介 今天我们分享的数据是全球30米分辨率湿地数据集,包含8种湿地亚类,该数据以0.5X0.5的瓦片存储,我们整理了所有属于中国的瓦片名称与其对应省份,方便大家研究使用。 该数据集作为全球首个30米分辨率、覆盖2000–2022年时间…...
基于数字孪生的水厂可视化平台建设:架构与实践
分享大纲: 1、数字孪生水厂可视化平台建设背景 2、数字孪生水厂可视化平台建设架构 3、数字孪生水厂可视化平台建设成效 近几年,数字孪生水厂的建设开展的如火如荼。作为提升水厂管理效率、优化资源的调度手段,基于数字孪生的水厂可视化平台的…...

P3 QT项目----记事本(3.8)
3.8 记事本项目总结 项目源码 1.main.cpp #include "widget.h" #include <QApplication> int main(int argc, char *argv[]) {QApplication a(argc, argv);Widget w;w.show();return a.exec(); } 2.widget.cpp #include "widget.h" #include &q…...
浅谈不同二分算法的查找情况
二分算法原理比较简单,但是实际的算法模板却有很多,这一切都源于二分查找问题中的复杂情况和二分算法的边界处理,以下是博主对一些二分算法查找的情况分析。 需要说明的是,以下二分算法都是基于有序序列为升序有序的情况…...
稳定币的深度剖析与展望
一、引言 在当今数字化浪潮席卷全球的时代,加密货币作为一种新兴的金融现象,正以前所未有的速度改变着我们对传统货币和金融体系的认知。然而,加密货币市场的高度波动性却成为了其广泛应用和普及的一大障碍。在这样的背景下,稳定…...
Angular微前端架构:Module Federation + ngx-build-plus (Webpack)
以下是一个完整的 Angular 微前端示例,其中使用的是 Module Federation 和 npx-build-plus 实现了主应用(Shell)与子应用(Remote)的集成。 🛠️ 项目结构 angular-mf/ ├── shell-app/ # 主应用&…...
Java + Spring Boot + Mybatis 实现批量插入
在 Java 中使用 Spring Boot 和 MyBatis 实现批量插入可以通过以下步骤完成。这里提供两种常用方法:使用 MyBatis 的 <foreach> 标签和批处理模式(ExecutorType.BATCH)。 方法一:使用 XML 的 <foreach> 标签ÿ…...

阿里云Ubuntu 22.04 64位搭建Flask流程(亲测)
cd /home 进入home盘 安装虚拟环境: 1、安装virtualenv pip install virtualenv 2.创建新的虚拟环境: virtualenv myenv 3、激活虚拟环境(激活环境可以在当前环境下安装包) source myenv/bin/activate 此时,终端…...

Python训练营-Day26-函数专题1:函数定义与参数
题目1:计算圆的面积 任务: 编写一个名为 calculate_circle_area 的函数,该函数接收圆的半径 radius 作为参数,并返回圆的面积。圆的面积 π * radius (可以使用 math.pi 作为 π 的值)要求:函数接收一个位置参数 radi…...

leetcode_69.x的平方根
题目如下 : 看到题 ,我们最原始的想法就是暴力解决: for(long long i 0;i<INT_MAX;i){if(i*ix){return i;}else if((i*i>x)&&((i-1)*(i-1)<x)){return i-1;}}我们直接开始遍历,我们是整数的平方根,所以我们分两…...