Skip to content

Commit 90ec725

Browse files
thvdveldgpotter2
authored andcommitted
Add RPL Hop-by-Hop option (RFC 6553)
1 parent 5fa6428 commit 90ec725

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

scapy/layers/inet6.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
StrLenField,
5858
X3BytesField,
5959
XBitField,
60+
XByteField,
6061
XIntField,
6162
XShortField,
6263
)
@@ -783,6 +784,27 @@ def extract_padding(self, p):
783784
return b"", p
784785

785786

787+
class RplOption(Packet): # RFC 6553 - RPL Option
788+
name = "RPL Option"
789+
fields_desc = [_OTypeField("otype", 0x63, _hbhopts),
790+
ByteField("optlen", 4),
791+
BitField("Down", 0, 1),
792+
BitField("RankError", 0, 1),
793+
BitField("ForwardError", 0, 1),
794+
BitField("unused", 0, 5),
795+
XByteField("RplInstanceId", 0),
796+
XShortField("SenderRank", 0)]
797+
798+
def alignment_delta(self, curpos): # alignment requirement : 2n+0
799+
x = 2
800+
y = 0
801+
delta = x * ((curpos - y + x - 1) // x) + y - curpos
802+
return delta
803+
804+
def extract_padding(self, p):
805+
return b"", p
806+
807+
786808
class Jumbo(Packet): # IPv6 Hop-By-Hop Option
787809
name = "Jumbo Payload"
788810
fields_desc = [_OTypeField("otype", 0xC2, _hbhopts),
@@ -818,6 +840,7 @@ def extract_padding(self, p):
818840
_hbhoptcls = {0x00: Pad1,
819841
0x01: PadN,
820842
0x05: RouterAlert,
843+
0x63: RplOption,
821844
0xC2: Jumbo,
822845
0xC9: HAO}
823846

test/scapy/layers/inet6.uts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,25 @@ raw(RouterAlert(optlen=3, value=0xffff)) == b'\x05\x03\xff\xff'
572572
a=RouterAlert(b'\x05\x03\xff\xff')
573573
a.otype == 0x05 and a.optlen == 3 and a.value == 0xffff
574574

575+
############
576+
############
577+
+ Test RPL Option (RFC 6553)
578+
579+
= RplOption - Basic Instantiation
580+
raw(RplOption()) == b'c\x04\x00\x00\x00\x00'
581+
582+
= RplOption - Basic Dissection
583+
a=RplOption(b'c\x04\x00\x00\x00\x00')
584+
a.otype == 0x63 and a.optlen == 4 and a.Down == False and a.RankError == 0 and a.ForwardError == 0 and a.RplInstanceId == 0 and a.SenderRank == 0
585+
586+
= RplOption - Instantiation with specific values
587+
a=RplOption(RplInstanceId=0x1e, SenderRank=0x800)
588+
a.otype == 0x63 and a.optlen == 4 and a.Down == False and a.RankError == 0 and a.ForwardError == 0 and a.RplInstanceId == 0x1e and a.SenderRank == 0x800
589+
590+
= RplOption - Instantiation with specific values
591+
a=RplOption(Down=True, RplInstanceId=0x1e, SenderRank=0x800)
592+
a.otype == 0x63 and a.optlen == 4 and a.Down == True and a.RankError == 0 and a.ForwardError == 0 and a.RplInstanceId == 0x1e and a.SenderRank == 0x800
593+
raw(a) == b'c\x04\x80\x1e\x08\x00'
575594

576595
############
577596
############
@@ -628,6 +647,9 @@ raw(IPv6ExtHdrHopByHop(options=[HAO()])) == b';\x02\x01\x02\x00\x00\xc9\x10\x00\
628647

629648
= IPv6ExtHdrHopByHop - Instantiation with RouterAlert option
630649
raw(IPv6ExtHdrHopByHop(options=[RouterAlert()])) == b';\x00\x05\x02\x00\x00\x01\x00'
650+
651+
= IPv6ExtHdrHopByHop - Instantiation with RPL option
652+
raw(IPv6ExtHdrHopByHop(options=[RplOption()])) == b';\x00c\x04\x00\x00\x00\x00'
631653

632654
= IPv6ExtHdrHopByHop - Instantiation with Jumbo option
633655
raw(IPv6ExtHdrHopByHop(options=[Jumbo()])) == b';\x00\xc2\x04\x00\x00\x00\x00'

0 commit comments

Comments
 (0)