美文网首页
【opensips】xxx.invalid的host不能解析问题

【opensips】xxx.invalid的host不能解析问题

作者: 安安爸Chris | 来源:发表于2020-09-23 17:49 被阅读0次

背景

opensips作为服务端,SIP客户端向其注册,但是注册时带的contact是一个非法的地址


image.png

这种情况一般常见于web端使用jsSIP的客户端

opensips注册完后,你可以在location表里看到如下记录


image.png

注意这里received是空的。

现象

注册端无法发起INVITE呼叫,opensips报如下错误


image.png

字面上来看,就是这个xxx.invalid的host是找不到的。

问题根因

注册端发起INVITE呼叫时,opensips通过location表找到该条记录,然后根据contact里的信息来指定接下来的路由,由于xxx.invalid是非法地址,所以opensips也不知道该往哪里路由,所以产生了错误。

解决方案

在register消息的处理流程中添加fix_nated_register

if (is_method("REGISTER")) {
    if (!www_authorize("", "subscriber")) {
      www_challenge("", "0");
      exit;
    }
      
    if (isflagset(SRC_WS)) {
      setbflag(DST_WS);
    }

    # fixing nat for register message in order that 
    # 'received' field can be stored in location
    fix_nated_register();
    if (!save("location","f")){
      sl_reply_error();
      exit;
    }
    exit;
  }

该函数会处理register消息中的nat地址,在调用save同时,nat转换后的外网地址会写到received字段

相关文章

网友评论

      本文标题:【opensips】xxx.invalid的host不能解析问题

      本文链接:https://www.haomeiwen.com/subject/plqoyktx.html