Author Topic: SIP outbound proxy not working  (Read 6348 times)

Gerry

  • Newbie
  • *
  • Posts: 3
    • View Profile
SIP outbound proxy not working
« on: July 09, 2020, 03:20:29 AM »
Hi,

How can I define a SIP outbound proxy for all calls routed by the register module?

I tried several things with no luck. The outbound parameter seems to be only used in ysipchan and I see some example uses
with regexroute and accfile but not with the register module.

I am able to set the outbound parameter in regexroute before routing hits the register module. The outbound parameter shows up in the message sniffer when doing routing with the register module. The INVITE is however sent to the R-URI address and not the outbound address. It seems that the outbound proxy functionality is not implemented for all SIP channels, just for LINE functions from accfile.

I am using yate 4.1.1

How can I fix this? If that is not implemented, where in the code should I patch that?

Thanks for you help.

Gerry

Gerry

  • Newbie
  • *
  • Posts: 3
    • View Profile
SIP outbound proxy patch
« Reply #1 on: July 11, 2020, 10:54:28 AM »
Hi,

Please find below a patch for Yate version 4.1.1. to get outbound proxying working. The patch introduces a new outboundproxy parameter which can be used for example from regexroute, like

; set proxy gateway
.*=;outboundproxy=112.203.17.24:5069

When this parameter is set it connects the outgoing YateSIPConnection to a proxy and sends all SIP messages there instead of the r-uri destination.

Comments re this patch would be highly welcome.

Cheers Gerry

@@ -4869,45 +4873,71 @@
     m_rtpForward = msg.getBoolValue(YSTRING("rtp_forward"));
     m_user = msg.getValue(YSTRING("user"));
     m_line = msg.getValue(YSTRING("line"));
+
     String tmp;
     YateSIPLine* line = 0;
     if (m_line) {
-   line = plugin.findLine(m_line);
-   if (line) {
-       if (uri.find('@') < 0 && !uri.startsWith("tel:")) {
-      if (!uri.startsWith("sip:"))
-          tmp = "sip:";
-      tmp << uri << "@" << line->domain();
-       }
-       m_externalAddr = line->getLocalAddr();
-   }
-    }
+       line = plugin.findLine(m_line);
+       if (line) {
+           if (uri.find('@') < 0 && !uri.startsWith("tel:")) {
+                if (!uri.startsWith("sip:"))
+                    tmp = "sip:";
+                tmp << uri << "@" << line->domain();
+           }
+           m_externalAddr = line->getLocalAddr();
+       }
+    }
+
     if (tmp.null()) {
-   if (!(uri.startsWith("tel:") || uri.startsWith("sip:"))) {
-       int sep = uri.find(':');
-       if ((sep < 0) || ((sep > 0) && (uri.substr(sep+1).toInteger(-1) > 0)))
-      tmp = "sip:";
-   }
-   tmp << uri;
+        if (!(uri.startsWith("tel:") || uri.startsWith("sip:"))) {
+            int sep = uri.find(':');
+            if ((sep < 0) || ((sep > 0) && (uri.substr(sep+1).toInteger(-1) > 0)))
+              tmp = "sip:";
+        }
+        tmp << uri;
     }
     m_uri = tmp;
     m_uri.parse();
-    if (!setParty(msg,false,"o",m_uri.getHost(),m_uri.getPort()) && line) {
-   SIPParty* party = line->party();
-   setParty(party);
-   TelEngine::destruct(party);
-    }
+
+    tmp.clear();
+    String rproxyaddr;
+    int rproxyport = 0;
+    tmp = msg.getValue(YSTRING("outboundproxy"));
+    if (tmp) {
+        int sep = tmp.find(':');
+        if (sep > 0) {
+            rproxyport = tmp.substr(sep + 1).toInteger(0);
+            rproxyaddr = tmp.substr(0,sep);
+        }
+        else
+            rproxyaddr = tmp;
+    }
+
+    if (rproxyaddr) {
+        setParty(msg,false,"o",rproxyaddr,rproxyport);
+    } else if (!setParty(msg,false,"o",m_uri.getHost(),m_uri.getPort()) && line) {
+       SIPParty* party = line->party();
+       setParty(party);
+       TelEngine::destruct(party);
+    }
+
     SIPMessage* m = new SIPMessage("INVITE",m_uri);
-    setSipParty(m,line,true,msg.getValue("host"),msg.getIntValue("port"));
+
+    if (rproxyaddr)
+        setSipParty(m,line,true,rproxyaddr,rproxyport);
+    else
+        setSipParty(m,line,true,msg.getValue("host"),msg.getIntValue("port"));
+
     if (!m->getParty()) {