Fix Geneve dissection (#3917)

* fix Geneve dissection

* Removed accidentally added local files and added unit test.

* Little enhancement of Geneve multiple options test

* Removed redundant line from gitignore
This commit is contained in:
Pavel 2024-02-06 02:13:06 +02:00 committed by GitHub
parent 18d4c30fa4
commit 703cd5a7f5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 14 additions and 0 deletions

1
.gitignore vendored
View File

@ -11,6 +11,7 @@ coverage.xml
.ipynb_checkpoints
.mypy_cache
.vscode
.DS_Store
[.]venv/
__pycache__/
doc/scapy/_build

View File

@ -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

View File

@ -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())