]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Make the Proxy Protocol tests compatible with Python 2
authorRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 25 Feb 2020 10:04:59 +0000 (11:04 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 17 Mar 2020 13:12:55 +0000 (14:12 +0100)
regression-tests.dnsdist/proxyprotocol.py

index cc34b9f16cf0e48d264b467596b4d6d1881eee0b..a7a74907a812b0515bd4b5017060df08af1bbe54 100644 (file)
@@ -19,18 +19,20 @@ class ProxyProtocol(object):
         if data[:len(self.MAGIC)] != self.MAGIC:
             return False
 
-        self.version = int(data[12]) >> 4
+        value = struct.unpack('!B', bytes(bytearray([data[12]])))[0]
+        self.version = value >> 4
         if self.version != 0x02:
             return False
 
-        self.command = int(data[12]) & ~0x20
+        self.command = value & ~0x20
         self.local = False
         self.offset = self.HEADER_SIZE
 
         if self.command == 0x00:
             self.local = True
         elif self.command == 0x01:
-            self.family = int(data[13]) >> 4
+            value = struct.unpack('!B', bytes(bytearray([data[13]])))[0]
+            self.family = value >> 4
             if self.family == 0x01:
                 self.addrSize = 4
             elif self.family == 0x02:
@@ -38,7 +40,7 @@ class ProxyProtocol(object):
             else:
                 return False
 
-            self.protocol = int(data[13]) & ~0xF0
+            self.protocol = value & ~0xF0
             if self.protocol == 0x01:
                 self.tcp = True
             elif self.protocol == 0x02:
@@ -103,7 +105,7 @@ class ProxyProtocol(object):
             return False
 
         while remaining >= 3:
-            valueType = data[self.offset]
+            valueType = struct.unpack("!B", bytes(bytearray([data[self.offset]])))[0]
             self.offset = self.offset + 1
             valueLen = struct.unpack("!H", data[self.offset:self.offset+2])[0]
             self.offset = self.offset + 2