aboutsummaryrefslogtreecommitdiffstats
path: root/GPL
diff options
context:
space:
mode:
authorJan Gelety <jgelety@cisco.com>2020-09-03 20:39:03 +0200
committerJan Gelety <jgelety@cisco.com>2020-09-03 23:29:28 +0200
commitfc536db7de1d765e51d20f402d429cff5ecd170c (patch)
tree5deffb8d50993ad505e07fbb0e6cb5557ea1c14a /GPL
parent04df3394c9b69c22fcbdb993566e548cec58a492 (diff)
FIX: use correct minimal packet length in scapy scripts
Change-Id: Icd1b4a3edb203cb0963203bb2e3e765b35c81600 Signed-off-by: Jan Gelety <jgelety@cisco.com>
Diffstat (limited to 'GPL')
-rw-r--r--GPL/traffic_scripts/PacketVerifier.py14
1 files changed, 9 insertions, 5 deletions
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