[rtems-tools commit] misc/tftprpoxy: Correctly scale the protocol timeout

Chris Johns chrisj at rtems.org
Thu Sep 9 08:32:25 UTC 2021


Module:    rtems-tools
Branch:    master
Commit:    cb969f359f4eb0bfcc58b6eeaf2df36b11b9b7a0
Changeset: http://git.rtems.org/rtems-tools/commit/?id=cb969f359f4eb0bfcc58b6eeaf2df36b11b9b7a0

Author:    Chris Johns <chrisj at rtems.org>
Date:      Tue Sep  7 14:04:12 2021 +1000

misc/tftprpoxy: Correctly scale the protocol timeout

- Fix data decoding

- Fix get MAC call

---

 misc/tools/tftpproxy.py | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/misc/tools/tftpproxy.py b/misc/tools/tftpproxy.py
index c0aebb0..a388912 100644
--- a/misc/tools/tftpproxy.py
+++ b/misc/tools/tftpproxy.py
@@ -113,10 +113,11 @@ class tftp_session(object):
                     block = (data[2] << 8) | data[3]
                     s += '  ' + self.opcodes[opcode] + ', '
                     s += '#' + str(block) + ', '
-                    if dlen > 4:
+                    if dlen > 8:
                         s += '%02x%02x..%02x%02x' % (data[4], data[5], data[-2], data[-1])
                     else:
-                        s += '%02x%02x%02x%02x' % (data[4], data[5], data[6], data[6])
+                        for i in range(4, dlen):
+                            s += '%02x' % (data[i])
                     s += ',' + str(dlen - 4)
                 elif opcode == 4:
                     block = (data[2] << 8) | data[3]
@@ -162,8 +163,8 @@ class tftp_session(object):
         return None
 
     def get_timeout(self, default_timeout, timeout_guard):
-        if self.timeout == 0:
-            return self.timeout + timeout_guard
+        if self.timeout != 0:
+            return self.timeout * timeout_guard
         return default_timeout
 
     def get_block_size(self):
@@ -178,7 +179,7 @@ class udp_handler(socketserver.BaseRequestHandler):
         session = tftp_session()
         finished = session.data(client_ip, client_port, self.request[0])
         if not finished:
-            timeout = session.get_timeout(self.server.proxy.session_timeout, 1)
+            timeout = session.get_timeout(self.server.proxy.session_timeout, 4)
             host = self.server.proxy.get_host(client_ip)
             if host is not None:
                 session_count = self.server.proxy.get_session_count()
@@ -325,7 +326,7 @@ class proxy_server(object):
             if client in self.clients:
                 host = self.clients[client]
             else:
-                mac = getmac.get_mac_address(ip = client)
+                mac = misc.tools.getmac.get_mac_address(ip = client)
                 if mac in self.clients:
                     host = self.clients[mac]
         finally:



More information about the vc mailing list