Browse code

b/f:core:dlg: reevaluate nat_handling flag after onSipRequest/onInvite

Stefan Sayer authored on 29/11/2013 13:07:31
Showing 1 changed files
... ...
@@ -313,25 +313,31 @@ void AmBasicSipDialog::onRxRequest(const AmSipRequest& req)
313 313
     return;
314 314
     
315 315
   uas_trans[req.cseq] = req;
316
-    
316
+
317
+  string nh = req.remote_ip + ":"
318
+    + int2str(req.remote_port)
319
+    + "/" + req.trsp;
320
+
321
+  bool target_refresh_req =
322
+    req.from_uri.length() && 
323
+    (remote_uri.empty() ||
324
+     (req.method == SIP_METH_INVITE || 
325
+      req.method == SIP_METH_UPDATE ||
326
+      req.method == SIP_METH_SUBSCRIBE ||
327
+      req.method == SIP_METH_NOTIFY));
328
+
317 329
   // target refresh requests
318
-  if (req.from_uri.length() && 
319
-      (remote_uri.empty() ||
320
-       (req.method == SIP_METH_INVITE || 
321
-	req.method == SIP_METH_UPDATE ||
322
-	req.method == SIP_METH_SUBSCRIBE ||
323
-	req.method == SIP_METH_NOTIFY))) {
330
+  if (target_refresh_req) {
324 331
     
325 332
     // refresh the target
326 333
     if (remote_uri != req.from_uri) {
327 334
       setRemoteUri(req.from_uri);
328
-      if(nat_handling && req.first_hop) {
329
-	string nh = req.remote_ip + ":"
330
-	  + int2str(req.remote_port)
331
-	  + "/" + req.trsp;
332
-	setNextHop(nh);
333
-	setNextHop1stReq(false);
334
-      }
335
+    }
336
+
337
+    if(nat_handling && req.first_hop) {
338
+      DBG("nat_handling: setting next_hop to received '%s'\n", nh.c_str());
339
+      setNextHop(nh);
340
+      setNextHop1stReq(false);
335 341
     }
336 342
 
337 343
     string ua = getHeader(req.hdrs,"User-Agent");
... ...
@@ -356,6 +362,14 @@ void AmBasicSipDialog::onRxRequest(const AmSipRequest& req)
356 362
 
357 363
   if(onRxReqStatus(req) && hdl)
358 364
     hdl->onSipRequest(req);
365
+
366
+  // reevaluate nat_handling next hop - may have changed in onSipRequest
367
+  if(target_refresh_req && nat_handling && req.first_hop) {
368
+    DBG("nat_handling: setting next_hop to received '%s'\n", nh.c_str());
369
+    setNextHop(nh);
370
+    setNextHop1stReq(false);
371
+  }
372
+
359 373
 }
360 374
 
361 375
 bool AmBasicSipDialog::onRxReplyStatus(const AmSipReply& reply,