From b7eb2efaf0d363b8afa26c6db56c6c651bc0de09 Mon Sep 17 00:00:00 2001 From: Pietro Bertera Date: Wed, 27 May 2015 17:06:27 +0200 Subject: [PATCH 1/2] FIX: #100 and #97 from PyPXE Imported 2 fix from PyPXE: Only Increment Wrap after Going Half-way Through #97 Always Seek to Correct Block #100 --- pypxe/tftp.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pypxe/tftp.py b/pypxe/tftp.py index 1851f74..7f14438 100644 --- a/pypxe/tftp.py +++ b/pypxe/tftp.py @@ -35,7 +35,8 @@ def __init__(self, mainsock, parent): self.fh = None self.netboot_directory = parent.netboot_directory self.filename = '' - self.wrap = -1 + self.wrap = 0 + self.arm_wrap = False # message from the main socket self.handle() @@ -53,6 +54,7 @@ def send_block(self): Sends the next block of data, setting the timeout and retry variables accordingly. ''' + self.fh.seek(self.blksize * (self.block - 1)) data = self.fh.read(self.blksize) # opcode 3 == DATA, wraparound block number response = struct.pack('!HH', 3, self.block % 65536) @@ -202,7 +204,7 @@ def handle(self): elif opcode == 4: [block] = struct.unpack('!H', self.message[2:4]) a = block + self.wrap * 65536 - if block == 0: + if block == 0 and self.arm_wrap: self.wrap += 1 if block < self.block % 65536: self.logger.warning('Ignoring duplicated ACK received for block {0}'.format(self.block)) @@ -285,7 +287,6 @@ def listen(self): for client in self.ongoing: if client.no_ack(): self.logger.warning("Retransmission of block {0}".format(client.block)) - client.fh.seek(-client.blksize, 1) client.send_block() # if we have run out of retries, kill the client for client in self.ongoing: From 8d4a1a8155be8cd14bc2f68b602281e1ce8656c2 Mon Sep 17 00:00:00 2001 From: Pietro Bertera Date: Fri, 29 May 2015 01:10:15 +0200 Subject: [PATCH 2/2] removeHeader refactored RemoveHeader now can receive a list where search the header to remove --- proxy.py | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/proxy.py b/proxy.py index 488abaf..d857093 100644 --- a/proxy.py +++ b/proxy.py @@ -161,36 +161,45 @@ def changeRequestUri(self): else: self.server.main_logger.debug("SIP: URI not found in Registrar: %s leaving the URI unchanged" % uri) - def removeHeader(self, regex): + def removeHeader(self, regex, data=None): + """ + remove a SIP header. + - `regex`contains the regex to extract the header + - if `data` is defined the `regex`is searched into data, otherwise in self.data + """ + if data == None: + read_data = self.data + else: + read_data = data self.server.main_logger.debug("SIP: Removing header with regex %s" % regex.pattern) data = [] - for line in self.data: + for line in read_data: if not regex.search(line): data.append(line) else: self.server.main_logger.debug("SIP: Removed %s" % line) return data - def removeMaxForward(self): - return self.removeHeader(rx_maxforward) + def removeMaxForward(self, data=None): + return self.removeHeader(rx_maxforward, data) - def removeRouteHeader(self): - return self.removeHeader(rx_route) + def removeRouteHeader(self, data=None): + return self.removeHeader(rx_route, data) - def removeContact(self): - return self.removeHeader(rx_contact) + def removeContact(self, data=None): + return self.removeHeader(rx_contact, data) - def removeContentType(self): - return self.removeHeader(rx_contenttype) + def removeContentType(self, data=None): + return self.removeHeader(rx_contenttype, data) - def removeUserAgent(self): - return self.removeHeader(rx_useragent) + def removeUserAgent(self, data=None): + return self.removeHeader(rx_useragent, data) - def removeSessionExpires(self): - return self.removeHeader(rx_sessionexpires) + def removeSessionExpires(self, data=None): + return self.removeHeader(rx_sessionexpires, data) - def removeSupported(self): - return self.removeHeader(rx_supported) + def removeSupported(self, data=None): + return self.removeHeader(rx_supported, data) def removeContentDisposition(self): return self.removeHeader(rx_contentdisposition) @@ -473,7 +482,9 @@ def processInvite(self): self.changeRequestUri() self.data = self.addTopVia() data = self.removeRouteHeader() + #data = self.removeSupported(data) data.insert(1, self.server.recordroute) + #data.insert(2, "Route: " % destination) text = string.join(data,"\r\n") self.sendTo(text , claddr, socket) self.server.main_logger.debug("SIP: Forwarding INVITE to %s:%d" % (claddr[0], claddr[1]))