Openser中文网

专注于VoIP,Opensips,Kamailio等技术,QQ群:QQ群:293697898

OpenSIPS最新版本中nat_uac_test发生了变化


tags:OpenSIPS 脚本语法 nat uac 创建时间:2024-06-06 14:18:12

在OpenSER系统中nat_uac_test一直都是一个不错的函数,用于检查uac是不是在nat后边

在OpenSIPS3.3版本及以前,大部分上是类似:

nat_uac_test(flags) Determines whether the received SIP message originated behind a NAT, using a bitmask of pre-defined checks.

Meaning of the flags (int) parameter is as follows:
`
1 - Contact header field is searched for occurrence of RFC1918 / RFC6598 addresses.

2 - the "received" test is used: address in Via is compared against source IP address of signaling

4 - Top Most VIA is searched for occurrence of RFC1918 / RFC6598 addresses

8 - SDP is searched for occurrence of RFC1918 / RFC6598 addresses

16 - test if the source port is different from the port in Via

32 - address in Contact is compared against source IP address of signaling

64 - Port in Contact is compared against source port of signaling

All flags can be bitwise combined, the test returns true if any of the tests identified a NAT.`

This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE, FAILURE_ROUTE, BRANCH_ROUTE.

也就是从2的0次幂方开始,一直持续下去,当然不可能无穷大,够用即可。为什么要用这种方式,还是以前的老式程序员为了内存、运算等尽可能使用int、甚至于short int、char等类型来进行快带运算。

但是从OpenSIPS3.4开始,换成字符串类型了,到现在的3.6也是如此,如下:

nat_uac_test(flags) Determines whether the received SIP message originated behind a NAT, using one or more pre-defined checks.

The flags (string) parameter denotes a comma-separated list of checks to be performed, as follows:

private-contact - (old 1 flag) Contact header field is searched for occurrence of RFC1918 / RFC6598 addresses

diff-ip-src-via - (old 2 flag) the "received" test is used: address in Via is compared against source IP address of signaling

private-via - (old 4 flag) Top Most VIA is searched for occurrence of RFC1918 / RFC6598 addresses

private-sdp - (old 8 flag) SDP is searched for occurrence of RFC1918 / RFC6598 addresses

diff-port-src-via - (old 16 flag) test if the source port is different from the port in Via

diff-ip-src-contact - (old 32 flag) address in Contact is compared against source IP address of signaling

diff-port-src-contact - (old 64 flag) Port in Contact is compared against source port of signaling

carrier-grade-nat - (old 128 flag) also include RFC 6333 addresses in the checks for Contact, Via and SDP

Returns true if any of the tests passed.

This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE, FAILURE_ROUTE, BRANCH_ROUTE.

Example 1.24. nat_uac_test usage

...

check for private Contact or SDP media IP addresses

if (nat_uac_test("private-contact,private-sdp")) xlog("SIP message is NAT'ed (Call-ID: $ci)\n"); ... 从以上脚本来看,除了配置时更明显点外,没有别的优点,但缺点也是麻烦了,本来靠手指头+脚趾头就算出来个数字即可,结果输入的时候要打好多的文字,字符串标识通过,分隔。



如果在有疑问或需要沟通的地方,可以QQ:1354608370 或 加FreeSWITCH+Kamailio+Opensips QQ群: 293697898 沟通交流!