dhcpkit.ipv6.extensions.leasequery module

Implementation of the Leasequery protocol extension as specified in RFC 5007.

class dhcpkit.ipv6.extensions.leasequery.CLTTimeOption(clt_time: int = 0)[source]

Bases: dhcpkit.ipv6.options.Option

RFC 5007#section-4.1.2.3

The Client Last Transaction Time option is encapsulated in an OPTION_CLIENT_DATA and identifies how long ago the server last communicated with the client, in seconds.

The format of the Client Last Transaction Time option is shown below:

 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_CLT_TIME        |         option-len            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                 client-last-transaction-time                  |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
option-code
OPTION_CLT_TIME (46)
option-len
4
client-last-transaction-time
The number of seconds since the server last communicated with the client (on that link).

The client-last-transaction-time is a positive value and reflects the number of seconds since the server last communicated with the client (on that link).

clt_time = None

The number of seconds since the server last communicated with the client

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

option_type = 46
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.extensions.leasequery.ClientDataOption(options: Iterable = None)[source]

Bases: dhcpkit.ipv6.options.Option

RFC 5007#section-4.1.2.2

The Client Data option is used to encapsulate the data for a single client on a single link in a LEASEQUERY-REPLY message.

The format of the Client Data option is shown below:

 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_CLIENT_DATA      |         option-len            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
.                                                               .
.                        client-options                         .
.                                                               .
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
option-code
OPTION_CLIENT_DATA (45)
option-len
Length, in octets, of the encapsulated client-options field.
client-options
The options associated with this client.

The encapsulated client-options include the OPTION_CLIENTID, OPTION_IAADDR, OPTION_IAPREFIX, and OPTION_CLT_TIME options and other options specific to the client and requested by the requestor in the OPTION_ORO in the OPTION_LQ_QUERY’s query-options. The server MUST return all of the client’s statefully assigned addresses and delegated prefixes, with a non-zero valid lifetime, on the link.

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

option_type = 45
options = None

The options associated with this client

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.

Bases: dhcpkit.ipv6.options.Option

RFC 5007#section-4.1.2.5

The Client Link option is used only in a LEASEQUERY-REPLY message and identifies the links on which the client has one or more bindings. It is used in reply to a query when no link-address was specified and the client is found to be on more than one link.

The format of the Client Link option is shown below:

 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_LQ_CLIENT_LINK     |         option-len            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
|                  link-address (IPv6 address)                  |
|                                                               |
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
|                  link-address (IPv6 address)                  |
|                                                               |
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                              ...                              |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
option-code
OPTION_LQ_CLIENT_LINK (48)
option-len
Length of the list of links in octets; must be a multiple of 16.
link-address
A global address used by the server to identify the link on which the client is located.

A server may respond to a query by client-id, where the 0::0 link- address was specified, with this option if the client is found to be on multiple links. The requestor may then repeat the query once for each link-address returned in the list, specifying the returned link- address. If the client is on a single link, the server SHOULD return the client’s data in an OPTION_CLIENT_DATA option.

Global addresses used by the server to identify the link on which the client is located

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

option_type = 48
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.extensions.leasequery.LQQueryOption(query_type: int = 0, link_address: ipaddress.IPv6Address = None, options: Iterable = None)[source]

Bases: dhcpkit.ipv6.options.Option

RFC 5007#section-4.1.2.1

The Query option is used only in a LEASEQUERY message and identifies the query being performed. The option includes the query type, link- address (or 0::0), and option(s) to provide data needed for the query.

The format of the Query option is shown below:

 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_LQ_QUERY        |         option-len            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|   query-type  |                                               |
+-+-+-+-+-+-+-+-+                                               |
|                                                               |
|                         link-address                          |
|                                                               |
|               +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|               |                                               .
+-+-+-+-+-+-+-+-+                                               .
.                         query-options                         .
.                                                               .
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
option-code
OPTION_LQ_QUERY (44)
option-len
17 + length of query-options field.
link-address
A global address that will be used by the server to identify the link to which the query applies, or 0::0 if unspecified.
query-type
The query requested (see below).
query-options
The options related to the query.

The query-type and required query-options are:

QUERY_BY_ADDRESS (1)
The query-options MUST contain an OPTION_IAADDR option [2]. The link-address field, if not 0::0, specifies an address for the link on which the client is located if the address in the OPTION_IAADDR option is of insufficient scope. Only the information for the client that has a lease for the specified address or was delegated a prefix that contains the specified address is returned (if available).
QUERY_BY_CLIENTID (2)
The query-options MUST contain an OPTION_CLIENTID option [2]. The link-address field, if not 0::0, specifies an address for the link on which the client is located. If the link-address field is 0::0, the server SHOULD search all of its links for the client.

The query-options MAY also include an OPTION_ORO option [2] to indicate the options for each client that the requestor would like the server to return. Note that this OPTION_ORO is distinct and separate from an OPTION_ORO that may be in the requestor’s LEASEQUERY message.

If a server receives an OPTION_LQ_QUERY with a query-type it does not support, the server SHOULD return an UnknownQueryType status-code. If a server receives a supported query-type but the query-options is missing a required option, the server SHOULD return a MalformedQuery status-code.

This checking of mandatory options is done in the server code, not in validate().

display_query_type() → dhcpkit.protocol_element.ElementDataRepresentation[source]

Nicer representation of query types :return: Representation of query type

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

A global address that will be used by the server to identify the link to which the query applies

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

option_type = 44
options = None

The options related to the query

query_type = None

The query requested

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.extensions.leasequery.LQRelayDataOption(peer_address: ipaddress.IPv6Address = None, relay_message: dhcpkit.ipv6.messages.RelayForwardMessage = None)[source]

Bases: dhcpkit.ipv6.options.Option

RFC 5007#section-4.1.2.4

The Relay Data option is used only in a LEASEQUERY-REPLY message and provides the relay agent information used when the client last communicated with the server.

The format of the Relay Data option is shown below:

 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_LQ_RELAY_DATA      |         option-len            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
|                  peer-address (IPv6 address)                  |
|                                                               |
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               |
|                       DHCP-relay-message                      |
.                                                               .
.                                                               .
.                                                               .
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
option-code
OPTION_LQ_RELAY_DATA (47)
option-len
16 + length of DHCP-relay-message.
peer-address
The address of the relay agent from which the relayed message was received by the server.
DHCP-relay-message
The last complete relayed message, excluding the client’s message OPTION_RELAY_MSG, received by the server.

This option is used by the server to return full relay agent information for a client. It MUST NOT be returned if the server does not have such information, either because the client communicated directly (without relay agent) with the server or if the server did not retain such information.

If returned, the DHCP-relay-message MUST contain a valid (perhaps multi-hop) RELAY-FORW message as the most recently received by the server for the client. However, the (innermost) OPTION_RELAY_MSG option containing the client’s message MUST have been removed.

This option SHOULD only be returned if requested by the OPTION_ORO of the OPTION_LQ_QUERY.

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

option_type = 47
peer_address = None

The address of the relay agent from which the relayed message was received by the server.

relay_message = None

The options related to the query

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.extensions.leasequery.LeasequeryMessage(transaction_id: bytes = b'x00x00x00', options: Iterable = None)[source]

Bases: dhcpkit.ipv6.messages.ClientServerMessage

The LEASEQUERY and LEASEQUERY-REPLY messages use the Client/Server message formats. A requestor sends a LEASEQUERY message to any available server to obtain information on a client’s leases. The options in an OPTION_LQ_QUERY determine the query.

from_client_to_server = True
message_type = 14
class dhcpkit.ipv6.extensions.leasequery.LeasequeryReplyMessage(transaction_id: bytes = b'x00x00x00', options: Iterable = None)[source]

Bases: dhcpkit.ipv6.messages.ClientServerMessage

The LEASEQUERY and LEASEQUERY-REPLY messages use the Client/Server message formats. A server sends a LEASEQUERY-REPLY message containing client data in response to a LEASEQUERY message.

from_server_to_client = True
message_type = 15