From eb99fbd8b22cc6197541cdcf5eec36248389e386 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Sat, 14 May 2022 18:35:15 -0400 Subject: [PATCH] Switch from clear buffer to sized memoryview Use the recvmsg hint to mask out the buffer rather than zeroing the entire buffer. This is more efficient and further improves efficiency of parsing of the packet. --- confluent_server/confluent/discovery/protocols/pxe.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/confluent_server/confluent/discovery/protocols/pxe.py b/confluent_server/confluent/discovery/protocols/pxe.py index ca06cfba..97efdad9 100644 --- a/confluent_server/confluent/discovery/protocols/pxe.py +++ b/confluent_server/confluent/discovery/protocols/pxe.py @@ -381,7 +381,6 @@ def snoop(handler, protocol=None, nodeguess=None): if not ready or not ready[0]: continue for netc in ready[0]: - rawbuffer[:] = b'\x00' * 2048 idx = None if netc == net4: i = recvmsg(netc.fileno(), ctypes.pointer(msg), 0) @@ -394,7 +393,7 @@ def snoop(handler, protocol=None, nodeguess=None): if level == socket.IPPROTO_IP and typ == IP_PKTINFO: idx, recv = struct.unpack('II', cmsgarr[16:24]) recv = ipfromint(recv) - rqv = memoryview(rawbuffer) + rqv = memoryview(rawbuffer)[:i] if rawbuffer[0] == 1: # Boot request process_dhcp4req(handler, nodeguess, cfg, net4, idx, recv, rqv) elif netc == net6: