Skip to content

Commit 1e3bf4d

Browse files
wsycqyzwangxin
authored andcommitted
Fix arp_responder.py failed to start in many tests
Summary: Fixes arp_responder.py failed to start due to receiving unknown ethernet type packets What is the motivation for this PR? When ARP responder received malformed packet, it cannot handle it and just crashed. This caused a lot of testcase failures. How did you do it? Add more logic to check the received packet. How did you verify/test it? Run test_acl.py::TestBasicACL and got 100% pass
1 parent d15c618 commit 1e3bf4d

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

tests/scripts/arp_responder.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,23 @@ def __init__(self, ip_sets):
9999

100100
def action(self, interface):
101101
data = interface.recv()
102-
103-
if len(data) <= self.ARP_PKT_LEN:
104-
return self.reply_to_arp(data, interface)
105-
elif len(data) <= self.NDP_PKT_LEN:
106-
return self.reply_to_ndp(data, interface)
102+
eth_type = struct.unpack('!H', data[12:14])[0]
103+
104+
if eth_type == 0x0806: # ARP
105+
if len(data) <= self.ARP_PKT_LEN:
106+
return self.reply_to_arp(data, interface)
107+
else:
108+
# Handle the case where data length is greater than ARP packet length
109+
pass
110+
elif eth_type == 0x86DD: # IPv6
111+
if len(data) <= self.NDP_PKT_LEN:
112+
return self.reply_to_ndp(data, interface)
113+
else:
114+
# Handle the case where data length is greater than NDP packet length
115+
pass
116+
else:
117+
# Handle other Ethernet types
118+
pass
107119

108120
def reply_to_arp(self, data, interface):
109121
remote_mac, remote_ip, request_ip, op_type, vlan_id = self.extract_arp_info(data)

0 commit comments

Comments
 (0)