From fc536db7de1d765e51d20f402d429cff5ecd170c Mon Sep 17 00:00:00 2001 From: Jan Gelety Date: Thu, 3 Sep 2020 20:39:03 +0200 Subject: FIX: use correct minimal packet length in scapy scripts Change-Id: Icd1b4a3edb203cb0963203bb2e3e765b35c81600 Signed-off-by: Jan Gelety --- GPL/traffic_scripts/PacketVerifier.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'GPL') diff --git a/GPL/traffic_scripts/PacketVerifier.py b/GPL/traffic_scripts/PacketVerifier.py index 20e9af603b..9b21fea4d9 100644 --- a/GPL/traffic_scripts/PacketVerifier.py +++ b/GPL/traffic_scripts/PacketVerifier.py @@ -71,7 +71,7 @@ from scapy.all import ETH_P_IP, ETH_P_IPV6, ETH_P_ALL, ETH_P_ARP from scapy.config import conf from scapy.layers.inet6 import IPv6 from scapy.layers.l2 import Ether, ARP -from scapy.packet import Raw +from scapy.packet import Raw, Padding # Enable libpcap's L2listen conf.use_pcap = True @@ -314,10 +314,14 @@ def create_gratuitous_arp_request(src_mac, src_ip): def auto_pad(packet): - """Pads zeroes at the end of the packet if the total len < 60 bytes.""" - # padded = str(packet) - if len(packet) < 60: - packet[Raw].load += (b"\0" * (60 - len(packet))) + """Pads zeroes at the end of the packet if the total packet length is less + then 64 bytes in case of IPv4 or 78 bytes in case of IPv6. + """ + min_len = 78 if packet.haslayer(IPv6) else 64 + pad_layer = Raw if packet.haslayer(Raw) \ + else Padding if packet.haslayer(Padding) else None + if pad_layer: + packet[pad_layer].load += (b"\0" * (min_len - len(packet))) return packet -- cgit 1.2.3-korg