Skip to content

Commit

Permalink
Fix OpenFlow3 padding bug (#4440)
Browse files Browse the repository at this point in the history
  • Loading branch information
gpotter2 committed Jun 27, 2024
1 parent 2091f69 commit 460c989
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
12 changes: 5 additions & 7 deletions scapy/contrib/openflow3.py
Original file line number Diff line number Diff line change
Expand Up @@ -979,10 +979,8 @@ def post_build(self, p, pay):
zero_bytes = (8 - tmp_len % 8) % 8
tmp_len = tmp_len + zero_bytes # add padding length
p = p[:2] + struct.pack("!H", tmp_len) + p[4:]
else:
zero_bytes = (8 - tmp_len % 8) % 8
# every message will be padded correctly
p += b"\x00" * zero_bytes
p += b"\x00" * zero_bytes
# message with user-defined length will not be automatically padded
return p + pay

def extract_padding(self, s):
Expand Down Expand Up @@ -2697,9 +2695,9 @@ def post_build(self, p, pay):
if tmp_len is None:
tmp_len = len(p) + len(pay)
p = p[:2] + struct.pack("!H", tmp_len) + p[4:]
# every message will be padded correctly
zero_bytes = (8 - tmp_len % 8) % 8
p += b"\x00" * zero_bytes
zero_bytes = (8 - tmp_len % 8) % 8
p += b"\x00" * zero_bytes
# message with user-defined length will not be automatically padded
return p + pay

def extract_padding(self, s):
Expand Down
3 changes: 3 additions & 0 deletions test/contrib/openflow3.uts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ assert len(fpti) == 16
assert fpti.instruction_ids[0].type == 1
assert fpti.instruction_ids[1].type == 5

fpti.instruction_ids[0] = OFPITGotoTableID()
assert bytes(fpti) == b'\x00\x00\x00\x0c\x00\x01\x00\x04\x00\x05\x00\x04\x00\x00\x00\x00'

= OFPTPacketIn() containing an Ethernet frame
ofm = OFPTPacketIn(data=Ether()/IP()/ICMP())
p = OFPTPacketIn(raw(ofm))
Expand Down

0 comments on commit 460c989

Please sign in to comment.