dhcpkit.ipv6.messages module

Classes and constants for the message types defined in RFC 3315

class dhcpkit.ipv6.messages.AdvertiseMessage(transaction_id: bytes = b'x00x00x00', options: Iterable = None)[source]

Bases: dhcpkit.ipv6.messages.ClientServerMessage

A server sends an Advertise message to indicate that it is available for DHCP service, in response to a Solicit message received from a client.

from_server_to_client = True
message_type = 2
class dhcpkit.ipv6.messages.ClientServerMessage(transaction_id: bytes = b'x00x00x00', options: Iterable = None)[source]

Bases: dhcpkit.ipv6.messages.Message

RFC 3315#section-6

All DHCP messages sent between clients and servers share an identical fixed format header and a variable format area for options.

All values in the message header and in options are in network byte order.

Options are stored serially in the options field, with no padding between the options. Options are byte-aligned but are not aligned in any other way such as on 2 or 4 byte boundaries.

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)                          .
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
msg-type
Identifies the DHCP message type; the available message types are listed in section 5.3.
transaction-id
The transaction ID for this message exchange.
options
Options carried in this message; options are described in section 22.
get_option_of_type(*args) → Union[source]

Get the first option that is a subclass of the given class.

Parameters:args – The classes to look for
Returns:The option or None
get_options_of_type(*args) → List[source]

Get all options that are subclasses of the given class.

Parameters:args – The classes to look for
Returns:The list of options
load_from(buffer: bytes, offset: int = 0, length: int = None) → int[source]

Load the internal state of this object from the given buffer. The buffer may contain more data after the structured element is parsed. This data is ignored.

Parameters:
  • buffer – The buffer to read data from
  • offset – The offset in the buffer where to start reading
  • length – The amount of data we are allowed to read from the buffer
Returns:

The number of bytes used from the buffer

save() → Union[source]

Save the internal state of this object as a buffer.

Returns:The buffer with the data from this element
validate()[source]

Validate that the contents of this object conform to protocol specs.

class dhcpkit.ipv6.messages.ConfirmMessage(transaction_id: bytes = b'x00x00x00', options: Iterable = None)[source]

Bases: dhcpkit.ipv6.messages.ClientServerMessage

A client sends a Confirm message to any available server to determine whether the addresses it was assigned are still appropriate to the link to which the client is connected.

from_client_to_server = True
message_type = 4
class dhcpkit.ipv6.messages.DeclineMessage(transaction_id: bytes = b'x00x00x00', options: Iterable = None)[source]

Bases: dhcpkit.ipv6.messages.ClientServerMessage

A client sends a Decline message to a server to indicate that the client has determined that one or more addresses assigned by the server are already in use on the link to which the client is connected.

from_client_to_server = True
message_type = 9
class dhcpkit.ipv6.messages.InformationRequestMessage(transaction_id: bytes = b'x00x00x00', options: Iterable = None)[source]

Bases: dhcpkit.ipv6.messages.ClientServerMessage

A client sends an Information-request message to a server to request configuration parameters without the assignment of any IP addresses to the client.

from_client_to_server = True
message_type = 11
class dhcpkit.ipv6.messages.Message[source]

Bases: dhcpkit.protocol_element.ProtocolElement

The base class for DHCP messages.

classmethod determine_class(buffer: bytes, offset: int = 0) → type[source]

Return the appropriate subclass from the registry, or UnknownClientServerMessage if no subclass is registered.

Parameters:
  • buffer – The buffer to read data from
  • offset – The offset in the buffer where to start reading
Returns:

The best known class for this message data

from_client_to_server = False
from_server_to_client = False
message_type = 0
class dhcpkit.ipv6.messages.RebindMessage(transaction_id: bytes = b'x00x00x00', options: Iterable = None)[source]

Bases: dhcpkit.ipv6.messages.ClientServerMessage

A client sends a Rebind message to any available server to extend the lifetimes on the addresses assigned to the client and to update other configuration parameters; this message is sent after a client receives no response to a Renew message.

from_client_to_server = True
message_type = 6
class dhcpkit.ipv6.messages.ReconfigureMessage(transaction_id: bytes = b'x00x00x00', options: Iterable = None)[source]

Bases: dhcpkit.ipv6.messages.ClientServerMessage

A server sends a Reconfigure message to a client to inform the client that the server has new or updated configuration parameters, and that the client is to initiate a Renew/Reply or Information-request/Reply transaction with the server in order to receive the updated information.

from_server_to_client = True
message_type = 10
class dhcpkit.ipv6.messages.RelayForwardMessage(hop_count: int = 0, link_address: ipaddress.IPv6Address = None, peer_address: ipaddress.IPv6Address = None, options: Iterable = None)[source]

Bases: dhcpkit.ipv6.messages.RelayServerMessage

A relay agent sends a Relay-forward message to relay messages to servers, either directly or through another relay agent. The received message, either a client message or a Relay-forward message from another relay agent, is encapsulated in an option in the Relay-forward message.

from_client_to_server = True
message_type = 12
wrap_response(response: dhcpkit.ipv6.messages.ClientServerMessage) → dhcpkit.ipv6.messages.RelayReplyMessage[source]

The incoming message was wrapped in this RelayForwardMessage. Let this RelayForwardMessage then create a RelayReplyMessage with the correct options and wrap the reply .

Parameters:response – The response that is going to be sent to the client
Returns:The RelayReplyMessage wrapping the response
Return type:RelayReplyMessage
class dhcpkit.ipv6.messages.RelayReplyMessage(hop_count: int = 0, link_address: ipaddress.IPv6Address = None, peer_address: ipaddress.IPv6Address = None, options: Iterable = None)[source]

Bases: dhcpkit.ipv6.messages.RelayServerMessage

A server sends a Relay-reply message to a relay agent containing a message that the relay agent delivers to a client. The Relay-reply message may be relayed by other relay agents for delivery to the destination relay agent.

The server encapsulates the client message as an option in the Relay-reply message, which the relay agent extracts and relays to the client.

from_server_to_client = True
message_type = 13
class dhcpkit.ipv6.messages.RelayServerMessage(hop_count: int = 0, link_address: ipaddress.IPv6Address = None, peer_address: ipaddress.IPv6Address = None, options: Iterable = None)[source]

Bases: dhcpkit.ipv6.messages.Message

RFC 3315#section-7

Relay agents exchange messages with servers to relay messages between clients and servers that are not connected to the same link.

All values in the message header and in options are in network byte order.

Options are stored serially in the options field, with no padding between the options. Options are byte-aligned but are not aligned in any other way such as on 2 or 4 byte boundaries.

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)   ....        .
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
get_option_of_type(*args) → Union[source]

Get the first option that is a subclass of the given class.

Parameters:args – The classes to look for
Returns:The option or None
get_options_of_type(*args) → List[source]

Get all options that are subclasses of the given class.

Parameters:args – The classes to look for
Returns:The list of options
inner_message

Utility method to easily get the innermost message from the RelayMessageOption inside this RelayServerMessage.

Returns:The message, if found
inner_relay_message

Utility method to easily get the innermost relay message from the RelayMessageOption inside this RelayServerMessage.

Returns:The message, if found
Return type:RelayServerMessage or None
load_from(buffer: bytes, offset: int = 0, length: int = None) → int[source]

Load the internal state of this object from the given buffer. The buffer may contain more data after the structured element is parsed. This data is ignored.

Parameters:
  • buffer – The buffer to read data from
  • offset – The offset in the buffer where to start reading
  • length – The amount of data we are allowed to read from the buffer
Returns:

The number of bytes used from the buffer

relayed_message

Utility method to easily get the relayed message from the RelayMessageOption inside this RelayServerMessage.

Returns:The message, if found
save() → Union[source]

Save the internal state of this object as a buffer.

Returns:The buffer with the data from this element
validate()[source]

Validate that the contents of this object conform to protocol specs.

class dhcpkit.ipv6.messages.ReleaseMessage(transaction_id: bytes = b'x00x00x00', options: Iterable = None)[source]

Bases: dhcpkit.ipv6.messages.ClientServerMessage

A client sends a Release message to the server that assigned addresses to the client to indicate that the client will no longer use one or more of the assigned addresses.

from_client_to_server = True
message_type = 8
class dhcpkit.ipv6.messages.RenewMessage(transaction_id: bytes = b'x00x00x00', options: Iterable = None)[source]

Bases: dhcpkit.ipv6.messages.ClientServerMessage

A client sends a Renew message to the server that originally provided the client’s addresses and configuration parameters to extend the lifetimes on the addresses assigned to the client and to update other configuration parameters.

from_client_to_server = True
message_type = 5
class dhcpkit.ipv6.messages.ReplyMessage(transaction_id: bytes = b'x00x00x00', options: Iterable = None)[source]

Bases: dhcpkit.ipv6.messages.ClientServerMessage

A server sends a Reply message containing assigned addresses and configuration parameters in response to a Solicit, Request, Renew, Rebind message received from a client. A server sends a Reply message containing configuration parameters in response to an Information-request message. A server sends a Reply message in response to a Confirm message confirming or denying that the addresses assigned to the client are appropriate to the link to which the client is connected. A server sends a Reply message to acknowledge receipt of a Release or Decline message.

from_server_to_client = True
message_type = 7
class dhcpkit.ipv6.messages.RequestMessage(transaction_id: bytes = b'x00x00x00', options: Iterable = None)[source]

Bases: dhcpkit.ipv6.messages.ClientServerMessage

A client sends a Request message to request configuration parameters, including IP addresses, from a specific server.

from_client_to_server = True
message_type = 3
class dhcpkit.ipv6.messages.SolicitMessage(transaction_id: bytes = b'x00x00x00', options: Iterable = None)[source]

Bases: dhcpkit.ipv6.messages.ClientServerMessage

SOLICIT (1)
A client sends a Solicit message to locate servers.
from_client_to_server = True
message_type = 1
class dhcpkit.ipv6.messages.UnknownMessage(message_type: int = 0, message_data: bytes = b'')[source]

Bases: dhcpkit.ipv6.messages.Message

Container for raw message content for cases where we don’t know how to decode the message.

load_from(buffer: bytes, offset: int = 0, length: int = None) → int[source]

Load the internal state of this object from the given buffer. The buffer may contain more data after the structured element is parsed. This data is ignored.

Parameters:
  • buffer – The buffer to read data from
  • offset – The offset in the buffer where to start reading
  • length – The amount of data we are allowed to read from the buffer
Returns:

The number of bytes used from the buffer

save() → Union[source]

Save the internal state of this object as a buffer.

Returns:The buffer with the data from this element
validate()[source]

Validate that the contents of this object conform to protocol specs.