Skip to content

Commit

Permalink
Add RPL Hop-by-Hop option (RFC 6553)
Browse files Browse the repository at this point in the history
  • Loading branch information
thvdveld committed Apr 26, 2023
1 parent 0f294fd commit 6a8a25e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
24 changes: 23 additions & 1 deletion scapy/layers/inet6.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
DestIP6Field, FieldLenField, FlagsField, IntField, IP6Field, \
LongField, MACField, PacketLenField, PacketListField, ShortEnumField, \
ShortField, SourceIP6Field, StrField, StrFixedLenField, StrLenField, \
X3BytesField, XBitField, XIntField, XShortField
X3BytesField, XBitField, XIntField, XShortField, XByteField
from scapy.layers.inet import IP, IPTools, TCP, TCPerror, TracerouteResult, \
UDP, UDPerror
from scapy.layers.l2 import CookedLinux, Ether, GRE, Loopback, SNAP
Expand Down Expand Up @@ -756,6 +756,27 @@ def extract_padding(self, p):
return b"", p


class RplOption(Packet): # RFC 6553 - RPL Option
name = "RPL Option"
fields_desc = [_OTypeField("otype", 0x63, _hbhopts),
ByteField("optlen", 4),
BitField("Down", 0, 1),
BitField("RankError", 0, 1),
BitField("ForwardError", 0, 1),
BitField("unused", 0, 5),
XByteField("RplInstanceId", 0),
XShortField("SenderRank", 0)]

def alignment_delta(self, curpos): # alignment requirement : 2n+0
x = 2
y = 0
delta = x * ((curpos - y + x - 1) // x) + y - curpos
return delta

def extract_padding(self, p):
return b"", p


class Jumbo(Packet): # IPv6 Hop-By-Hop Option
name = "Jumbo Payload"
fields_desc = [_OTypeField("otype", 0xC2, _hbhopts),
Expand Down Expand Up @@ -791,6 +812,7 @@ def extract_padding(self, p):
_hbhoptcls = {0x00: Pad1,
0x01: PadN,
0x05: RouterAlert,
0x63: RplOption,
0xC2: Jumbo,
0xC9: HAO}

Expand Down
22 changes: 22 additions & 0 deletions test/scapy/layers/inet6.uts
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,25 @@ raw(RouterAlert(optlen=3, value=0xffff)) == b'\x05\x03\xff\xff'
a=RouterAlert(b'\x05\x03\xff\xff')
a.otype == 0x05 and a.optlen == 3 and a.value == 0xffff

############
############
+ Test RPL Option (RFC 6553)

= RplOption - Basic Instantiation
raw(RplOption()) == b'c\x04\x00\x00\x00\x00'

= RplOption - Basic Dissection
a=RplOption(b'c\x04\x00\x00\x00\x00')
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

= RplOption - Instantiation with specific values
a=RplOption(RplInstanceId=0x1e, SenderRank=0x800)
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

= RplOption - Instantiation with specific values
a=RplOption(Down=True, RplInstanceId=0x1e, SenderRank=0x800)
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
raw(a) == b'c\x04\x80\x1e\x08\x00'

############
############
Expand Down Expand Up @@ -625,6 +644,9 @@ raw(IPv6ExtHdrHopByHop(options=[HAO()])) == b';\x02\x01\x02\x00\x00\xc9\x10\x00\

= IPv6ExtHdrHopByHop - Instantiation with RouterAlert option
raw(IPv6ExtHdrHopByHop(options=[RouterAlert()])) == b';\x00\x05\x02\x00\x00\x01\x00'

= IPv6ExtHdrHopByHop - Instantiation with RPL option
raw(IPv6ExtHdrHopByHop(options=[RplOption()])) == b';\x00c\x04\x00\x00\x00\x00'

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

0 comments on commit 6a8a25e

Please sign in to comment.