Skip to content
Snippets Groups Projects
Commit 1c98e2ab authored by Guillaume Valadon's avatar Guillaume Valadon Committed by Guillaume Valadon
Browse files

Fix DHCPv6 Relay message behavior

parent b03957f9
No related branches found
No related tags found
No related merge requests found
......@@ -23,7 +23,8 @@ from scapy.error import warning
from scapy.fields import BitField, ByteEnumField, ByteField, FieldLenField, \
FlagsField, IntEnumField, IntField, MACField, PacketField, \
PacketListField, ShortEnumField, ShortField, StrField, StrFixedLenField, \
StrLenField, UTCTimeField, X3BytesField, XIntField, XShortEnumField
StrLenField, UTCTimeField, X3BytesField, XIntField, XShortEnumField, \
PacketLenField
from scapy.layers.inet import UDP
from scapy.layers.inet6 import DomainNameListField, IP6Field, IP6ListField, IPv6
from scapy.packet import Packet, bind_bottom_up
......@@ -443,20 +444,6 @@ class DHCP6OptElapsedTime(_DHCP6OptGuessPayload):# RFC sect 22.9
_ElapsedTimeField("elapsedtime", 0) ]
#### DHCPv6 Relay Message Option ####################################
# Relayed message is seen as a payload.
class DHCP6OptRelayMsg(_DHCP6OptGuessPayload):# RFC sect 22.10
name = "DHCP6 Relay Message Option"
fields_desc = [ ShortEnumField("optcode", 9, dhcp6opts),
ShortField("optlen", None ) ]
def post_build(self, p, pay):
if self.optlen is None:
l = len(pay)
p = p[:2]+struct.pack("!H", l)
return p + pay
#### DHCPv6 Authentication Option ###################################
# The following fields are set in an Authentication option for the
......@@ -912,6 +899,17 @@ class DHCP6(_DHCP6OptGuessPayload):
def hashret(self):
return struct.pack("!I", self.trid)[1:4]
#### DHCPv6 Relay Message Option ####################################
# Relayed message is seen as a payload.
class DHCP6OptRelayMsg(_DHCP6OptGuessPayload): # RFC sect 22.10
name = "DHCP6 Relay Message Option"
fields_desc = [ ShortEnumField("optcode", 9, dhcp6opts),
FieldLenField("optlen", None, fmt="!H",
length_of="message"),
PacketLenField("message", DHCP6(), DHCP6,
length_from=lambda p: p.optlen) ]
#####################################################################
# Solicit Message : sect 17.1.1 RFC3315
# - sent by client
......
......@@ -4338,7 +4338,7 @@ a.msgtype == 12 and a.hopcount == 0 and a.linkaddr == "::" and a.peeraddr == "::
= DHCP6_RelayForward - Dissection with options
a = DHCP6_RelayForward(b'\x0c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\t\x00\x04\x00\x01\x00\x00')
a.msgtype == 12 and DHCP6OptRelayMsg in a and DHCP6OptClientId in a
a.msgtype == 12 and DHCP6OptRelayMsg in a and isinstance(a.message, DHCP6)
############
......@@ -4346,12 +4346,16 @@ a.msgtype == 12 and DHCP6OptRelayMsg in a and DHCP6OptClientId in a
+ Test DHCP6 Messages - DHCP6OptRelayMsg
= DHCP6OptRelayMsg - Basic Instantiation
str(DHCP6OptRelayMsg(optcode=37)) == b'\x00%\x00\x00'
str(DHCP6OptRelayMsg(optcode=37)) == b'\x00%\x00\x04\x00\x00\x00\x00'
= DHCP6OptRelayMsg - Basic Dissection
a=DHCP6OptRelayMsg(b'\x00\r\x00\x00')
assert a.optcode == 13
= DHCP6OptRelayMsg - Embedded DHCP6 packet
p = DHCP6OptRelayMsg(b'\x00\t\x00\x04\x00\x00\x00\x00')
isinstance(p.message, DHCP6)
############
############
+ Test DHCP6 Messages - DHCP6_RelayReply
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment