Skip to content

Commit 254ab6d

Browse files
authored
Merge pull request #1196 from guedou/ipv6_jumbo
Decode IPv6 Jumbograms
2 parents cf3e908 + 44b5b63 commit 254ab6d

2 files changed

Lines changed: 40 additions & 3 deletions

File tree

scapy/layers/inet6.py

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -438,9 +438,37 @@ def post_build(self, p, pay):
438438
p = p[:4]+struct.pack("!H", l)+p[6:]
439439
return p
440440

441-
def extract_padding(self, s):
442-
l = self.plen
443-
return s[:l], s[l:]
441+
def extract_padding(self, data):
442+
"""Extract the IPv6 payload"""
443+
444+
if self.plen == 0 and self.nh == 0 and len(data) >= 8:
445+
# Extract Hop-by-Hop extension length
446+
hbh_len = orb(data[1])
447+
hbh_len = 8 + hbh_len * 8
448+
449+
# Extract length from the Jumbogram option
450+
# Note: the following algorithm take advantage of the Jumbo option
451+
# mandatory alignment (4n + 2, RFC2675 Section 2)
452+
jumbo_len = None
453+
idx = 0
454+
offset = 4*idx+2
455+
while offset <= len(data):
456+
opt_type = orb(data[offset])
457+
if opt_type == 0xc2: # Jumbo option
458+
jumbo_len = struct.unpack("I", data[offset+2:offset+2+4])[0]
459+
break
460+
offset = 4*idx+2
461+
idx += 1
462+
463+
if jumbo_len is None:
464+
warning("Scapy did not find a Jumbo option")
465+
jumbo_len = 0
466+
467+
l = hbh_len + jumbo_len
468+
else:
469+
l = self.plen
470+
471+
return data[:l], data[l:]
444472

445473
def hashret(self):
446474
if self.nh == 58 and isinstance(self.payload, _ICMPv6):

test/regression.uts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2332,6 +2332,15 @@ raw(IPv6ExtHdrHopByHop(options=[RouterAlert()])) == b';\x00\x05\x02\x00\x00\x01\
23322332
= IPv6ExtHdrHopByHop - Instantiation with Jumbo option
23332333
raw(IPv6ExtHdrHopByHop(options=[Jumbo()])) == b';\x00\xc2\x04\x00\x00\x00\x00'
23342334

2335+
= IPv6ExtHdrHopByHop - Complete dissection with Jumbo option
2336+
s = b'`\x00\x00\x00\x00\x00\x00@\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01:\x00\xc2\x04\x00\x00\x00\x10\x80\x00\x7f\xbb\x00\x00\x00\x00'
2337+
p = IPv6(s)
2338+
assert IPv6ExtHdrHopByHop in p and Jumbo in p and ICMPv6EchoRequest in p
2339+
2340+
s = b'`\x00\x00\x00\x00\x00\x00@\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01:\x01\x01\x06\x00\x00\x00\x00\x00\x00\xc2\x04\x00\x00\x00\x18\x80\x00\x7f\xbb\x00\x00\x00\x00'
2341+
p = IPv6(s)
2342+
assert IPv6ExtHdrHopByHop in p and PadN in p and Jumbo in p and ICMPv6EchoRequest in p
2343+
23352344
= IPv6ExtHdrHopByHop - Instantiation with Pad1 option
23362345
raw(IPv6ExtHdrHopByHop(options=[Pad1()])) == b';\x00\x00\x01\x03\x00\x00\x00'
23372346

0 commit comments

Comments
 (0)