DHCP6¶
DHCPv6 packet parser/serializer
[RFC 3315] DHCPv6 packet format:
The following diagram illustrates the format of DHCP messages sent between clients and servers:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| msg_type | transaction_id |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
. options .
. (variable) .
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
There are two relay agent messages, which share the following format:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| msg_type | hop_count | |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| |
| link_address |
| |
| +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-|
| | |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| |
| peer_address |
| |
| +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-|
| | |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
. .
. options (variable number and length) .... .
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-
class
ryu.lib.packet.dhcp6.
dhcp6
(msg_type, options, transaction_id=None, hop_count=0, link_address='::', peer_address='::')¶ DHCPv6 (RFC 3315) header encoder/decoder class.
The serialized packet would looks like the ones described in the following sections.
- RFC 3315 DHCP packet format
An instance has the following attributes at least. Most of them are same to the on-wire counterparts but in host byte order. __init__ takes the corresponding args in this order.
Attribute Description msg_type Identifies the DHCP message type transaction_id For unrelayed messages only: the transaction ID for this message exchange. hop_count For relayed messages only: number of relay agents that have relayed this message. link_address For relayed messages only: a global or site-local address that will be used by the server to identify the link on which the client is located. peer_address For relayed messages only: the address of the client or relay agent from which the message to be relayed was received. options Options carried in this message -
classmethod
parser
(buf)¶ Decode a protocol header.
This method is used only when decoding a packet.
Decode a protocol header at offset 0 in bytearray buf. Returns the following three objects.
- An object to describe the decoded header.
- A packet_base.PacketBase subclass appropriate for the rest of the packet. None when the rest of the packet should be considered as raw payload.
- The rest of packet.
-
serialize
(payload=None, prev=None)¶ Encode a protocol header.
This method is used only when encoding a packet.
Encode a protocol header. Returns a bytearray which contains the header.
payload is the rest of the packet which will immediately follow this header.
prev is a packet_base.PacketBase subclass for the outer protocol header. prev is None if the current header is the outer-most. For example, prev is ipv4 or ipv6 for tcp.serialize.
-
class
ryu.lib.packet.dhcp6.
option
(code, data, length=0)¶ DHCP (RFC 3315) options encoder/decoder class.
This is used with ryu.lib.packet.dhcp6.dhcp6.options.
An instance has the following attributes at least. Most of them are same to the on-wire counterparts but in host byte order. __init__ takes the corresponding args in this order.
The format of DHCP options is:
0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | option-code | option-len | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | option-data | | (option-len octets) | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Attribute Description option-code An unsigned integer identifying the specific option type carried in this option. option-len An unsigned integer giving the length of the option-data field in this option in octets. option-data The data for the option; the format of this data depends on the definition of the option.
-
class
ryu.lib.packet.dhcp6.
options
(option_list=None, options_len=0)¶ DHCP (RFC 3315) options encoder/decoder class.
This is used with ryu.lib.packet.dhcp6.dhcp6.