Skip to content

Commit

Permalink
Handle wan_address correctly in case some remote L argument is
Browse files Browse the repository at this point in the history
present in the original request.
  • Loading branch information
sobomax committed Mar 27, 2024
1 parent 4fd0c74 commit 28b90ba
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions Rtp_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

from errno import EADDRINUSE
from random import random
from functools import partial

try:
from urllib import quote, unquote
Expand All @@ -38,7 +40,6 @@
from sippy.Time.Timeout import TimeoutInact
from sippy.Core.EventDispatcher import ED2

from random import random

def is_dst_local(destination_ip):
#if destination_ip == '192.168.22.11':
Expand Down Expand Up @@ -160,15 +161,15 @@ def up_command_udp(self, data, address, server, rtime):
return self.up_command(clim, cmd)

def up_command(self, clim, orig_cmd):
#print('up_command', orig_cmd)
#print(f'up_command({orig_cmd=})')
cmd = Rtp_proxy_cmd(orig_cmd)
response_handler = self.down_command
#print cmd
if len(self.active) == 0:
self.down_command('E999', clim, cmd, None)
return
if cmd.type in ('U', 'L', 'D', 'P', 'S', 'R', 'C', 'Q'):
#print 'up', cmd.call_id, str(cmd)
#print(f'up_command: {cmd.call_id=}, {orig_cmd=}, {str(cmd)=}')
for rtpp in self.active:
if rtpp.isYours(cmd.call_id):
break
Expand Down Expand Up @@ -273,34 +274,35 @@ def up_command(self, clim, orig_cmd):
out_cmd = str(out_cmd)
else:
out_cmd = orig_cmd
rtpp.send_command(out_cmd, response_handler, clim, cmd, rtpp)
rtpp.send_command(out_cmd, partial(response_handler, clim, cmd, out_cmd, rtpp))

def ignore_response(self, result, clim, cmd, rtpp):
def ignore_response(self, clim, cmd, out_cmd, rtpp, result):
if result is None:
return
self.global_config['_sip_logger'].write('Got delayed response ' \
'from node "%s" to already completed request, ignoring: "%s"' \
% (rtpp.name, result))

def down_command(self, result, clim, cmd, rtpp):
def down_command(self, clim, cmd, out_cmd, rtpp, result):
if isinstance(clim, UdpCLIM) and clim.cookie in self.commands_inflight:
self.commands_inflight.remove(clim.cookie)
#print 'down', result
#if cmd.type in ('U', 'L'): print(f'down_command({result=})')
if result == None:
result = 'E997'
elif cmd.type in ('U', 'L') and not result[0].upper() == 'E' and \
rtpp.wan_address != None:
#print 'down', cmd.ul_opts.destination_ip, rtpp.wan_address
#print(f'down_command: {cmd.ul_opts.destination_ip=}, {cmd.ul_opts.local_ip=}, {rtpp.wan_address=}')
req_dip = cmd.ul_opts.destination_ip
req_lip = cmd.ul_opts.local_ip
req_lip_out = cmd_out.ul_opts.local_ip_out
result_parts = result.strip().split()
if result_parts[0] != '0' and req_dip != None and not is_dst_local(req_dip) and \
req_lip != rtpp.lan_address:
result = '%s %s' % (result_parts[0], rtpp.wan_address)
elif result_parts[0] != '0' and req_lip == None:
elif result_parts[0] != '0' and (req_lip is None or req_lip_out == rtpp.lan_address):
result = '%s %s' % (result_parts[0], rtpp.wan_address)
# result = '%s %s' % (result_parts[0], '192.168.1.22')
#print 'down clim.send', result
#if cmd.type in ('U', 'L'): print(f'down_command: clim.send({result=})')
response = result + '\n'
clim.send(response)
if isinstance(clim, UdpCLIM):
Expand Down

0 comments on commit 28b90ba

Please sign in to comment.