Skip to content

Commit

Permalink
Fix Geneve dissection (#3917)
Browse files Browse the repository at this point in the history
* fix Geneve dissection

* Removed accidentally added local files and added unit test.

* Little enhancement of Geneve multiple options test

* Removed redundant line from gitignore
  • Loading branch information
inthefog committed Feb 6, 2024
1 parent 18d4c30 commit 703cd5a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ coverage.xml
.ipynb_checkpoints
.mypy_cache
.vscode
.DS_Store
[.]venv/
__pycache__/
doc/scapy/_build
Expand Down
3 changes: 3 additions & 0 deletions scapy/contrib/geneve.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ class GeneveOptions(Packet):
BitField("length", None, 5),
StrLenField('data', '', length_from=lambda x: x.length * 4)]

def extract_padding(self, s):
return "", s

def post_build(self, p, pay):
if self.length is None:
tmp_len = len(self.data) // 4
Expand Down
10 changes: 10 additions & 0 deletions test/contrib/geneve.uts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ assert (s == b'\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x81\x00\x00\x01\
p = Ether(s)
assert GENEVE in p and Ether in p[GENEVE].payload and p[GENEVE].proto == 0x6558 and p[GeneveOptions].length == 1 and p[GeneveOptions].classid == 0x102 and p[GeneveOptions].type == 0x80

= Build & dissect - GENEVE with multiple options

s = raw(GENEVE(proto=0x0800,options=[GeneveOptions(classid=0x0102,type=0x1,data=b'\x00\x01\x00\x02'), GeneveOptions(classid=0x0102,type=0x2,data=b'\x00\x01\x00\x02')]))
p = GENEVE(s)
assert p.optionlen == 4
assert len(p.options) == 2
assert p.options[0].classid == 0x102 and p.options[0].type == 0x1
assert p.options[1].classid == 0x102 and p.options[1].type == 0x2


= Build & dissect - GENEVE encapsulates IPv4

s = raw(IP()/UDP(sport=10000)/GENEVE()/IP())
Expand Down

0 comments on commit 703cd5a

Please sign in to comment.