join 1.0
lightweight network framework library
Loading...
Searching...
No Matches
join::NdpMessage Class Reference

NDP message codec. More...

#include <ndp_message.hpp>

Public Types

enum  MessageType : uint8_t { RouterSolicit = ND_ROUTER_SOLICIT , RouterAdvert = ND_ROUTER_ADVERT , NeighborSolicit = ND_NEIGHBOR_SOLICIT , NeighborAdvert = ND_NEIGHBOR_ADVERT }
 NDP message types, RFC 4861 section 4. More...
 
enum  OptionType : uint8_t {
  SourceLinkAddress = ND_OPT_SOURCE_LINKADDR , TargetLinkAddress = ND_OPT_TARGET_LINKADDR , PrefixInformation = ND_OPT_PREFIX_INFORMATION , Mtu = ND_OPT_MTU ,
  RecursiveDnsServer = 25
}
 NDP option types. More...
 

Public Member Functions

ssize_t serialize (const RouterSolicitation &packet, char *data, size_t maxSize) const
 serialize a router solicitation into a buffer.
 
ssize_t serialize (const RouterAdvertisement &packet, char *data, size_t maxSize) const
 serialize a router advertisement into a buffer.
 
ssize_t serialize (const RouterAdvertisement &packet, char *data, size_t maxSize, const MacAddress &link) const
 serialize a router advertisement into a buffer with the given link layer address.
 
ssize_t serialize (const NeighborSolicitation &packet, char *data, size_t maxSize) const
 serialize a neighbor solicitation into a buffer.
 
ssize_t serialize (const NeighborAdvertisement &packet, char *data, size_t maxSize) const
 serialize a neighbor advertisement into a buffer.
 
ssize_t serialize (const NeighborAdvertisement &packet, char *data, size_t maxSize, const MacAddress &link) const
 serialize a neighbor advertisement into a buffer with the given link layer address.
 
int deserialize (RouterSolicitation &packet, const char *data, size_t size) const
 deserialize a router solicitation from a buffer.
 
int deserialize (RouterAdvertisement &packet, const char *data, size_t size) const
 deserialize a router advertisement from a buffer.
 
int deserialize (NeighborSolicitation &packet, const char *data, size_t size) const
 deserialize a neighbor solicitation from a buffer.
 
int deserialize (NeighborAdvertisement &packet, const char *data, size_t size) const
 deserialize a neighbor advertisement from a buffer.
 

Static Public Attributes

static constexpr size_t maxRouterSolicitationSize
 biggest router solicitation the codec writes, link layer address option included.
 
static constexpr size_t maxNeighborSolicitationSize
 biggest neighbor solicitation the codec writes, link layer address option included.
 
static constexpr size_t maxNeighborAdvertisementSize
 biggest neighbor advertisement the codec writes, link layer address option included.
 

Protected Member Functions

struct __attribute__ ((packed)) RdnssHeader
 recursive DNS server option header, RFC 8106 section 5.1.
 

Static Protected Member Functions

static bool writeLinkAddress (char *&cur, const char *end, const MacAddress &link, OptionType type=SourceLinkAddress)
 write a link layer address option into a buffer.
 
template<typename Handler >
static int readOptions (const char *cur, const char *end, Handler &&handler)
 walk through the options of a message, RFC 4861 section 4.6.
 

Static Protected Attributes

static constexpr size_t _optionHeaderSize = 2
 size of an option type and length fields.
 
static constexpr size_t _maxOptionSize = 255 << 3
 biggest option, its length field counts units of 8 octets.
 
static constexpr size_t _maxDnsServers = 127
 most recursive DNS servers a single option can carry.
 

Detailed Description

NDP message codec.

Member Enumeration Documentation

◆ MessageType

NDP message types, RFC 4861 section 4.

Enumerator
RouterSolicit 

a host looking for routers.

RouterAdvert 

a router advertising its presence.

NeighborSolicit 

a node resolving a neighbor or checking its reachability.

NeighborAdvert 

a node answering a solicitation or announcing a change.

◆ OptionType

NDP option types.

Enumerator
SourceLinkAddress 

link layer address of the sender.

TargetLinkAddress 

link layer address of the target.

PrefixInformation 

on-link and autoconfiguration prefix.

Mtu 

link MTU.

RecursiveDnsServer 

recursive DNS servers, RFC 8106.

Member Function Documentation

◆ __attribute__()

struct join::NdpMessage::__attribute__ ( (packed) )
inlineprotected

recursive DNS server option header, RFC 8106 section 5.1.

option type.

option length in units of 8 octets.

reserved.

time in seconds the servers may be used for.

◆ deserialize() [1/4]

int join::NdpMessage::deserialize ( NeighborAdvertisement & packet,
const char * data,
size_t size ) const
inline

deserialize a neighbor advertisement from a buffer.

Parameters
packetneighbor advertisement to deserialize into.
databuffer holding the message to deserialize.
sizemessage size.
Returns
0 on success, -1 on failure.

◆ deserialize() [2/4]

int join::NdpMessage::deserialize ( NeighborSolicitation & packet,
const char * data,
size_t size ) const
inline

deserialize a neighbor solicitation from a buffer.

Parameters
packetneighbor solicitation to deserialize into.
databuffer holding the message to deserialize.
sizemessage size.
Returns
0 on success, -1 on failure.

◆ deserialize() [3/4]

int join::NdpMessage::deserialize ( RouterAdvertisement & packet,
const char * data,
size_t size ) const
inline

deserialize a router advertisement from a buffer.

Parameters
packetrouter advertisement to deserialize into.
databuffer holding the message to deserialize.
sizemessage size.
Returns
0 on success, -1 on failure.

◆ deserialize() [4/4]

int join::NdpMessage::deserialize ( RouterSolicitation & packet,
const char * data,
size_t size ) const
inline

deserialize a router solicitation from a buffer.

Parameters
packetrouter solicitation to deserialize into.
databuffer holding the message to deserialize.
sizemessage size.
Returns
0 on success, -1 on failure.

◆ readOptions()

template<typename Handler >
static int join::NdpMessage::readOptions ( const char * cur,
const char * end,
Handler && handler )
inlinestaticprotected

walk through the options of a message, RFC 4861 section 4.6.

Parameters
curbeginning of the options.
endend of the options.
handlerfunction called with each option, header included, and its size.
Returns
0 on success, -1 if an option is malformed.

◆ serialize() [1/6]

ssize_t join::NdpMessage::serialize ( const NeighborAdvertisement & packet,
char * data,
size_t maxSize ) const
inline

serialize a neighbor advertisement into a buffer.

Parameters
packetneighbor advertisement to serialize.
databuffer to serialize the message into.
maxSizebuffer size.
Returns
the message size, -1 on failure.

◆ serialize() [2/6]

ssize_t join::NdpMessage::serialize ( const NeighborAdvertisement & packet,
char * data,
size_t maxSize,
const MacAddress & link ) const
inline

serialize a neighbor advertisement into a buffer with the given link layer address.

Parameters
packetneighbor advertisement to serialize.
databuffer to serialize the message into.
maxSizebuffer size.
linklink layer address to carry instead of the one of the advertisement.
Returns
the message size, -1 on failure.

◆ serialize() [3/6]

ssize_t join::NdpMessage::serialize ( const NeighborSolicitation & packet,
char * data,
size_t maxSize ) const
inline

serialize a neighbor solicitation into a buffer.

Parameters
packetneighbor solicitation to serialize.
databuffer to serialize the message into.
maxSizebuffer size.
Returns
the message size, -1 on failure.

◆ serialize() [4/6]

ssize_t join::NdpMessage::serialize ( const RouterAdvertisement & packet,
char * data,
size_t maxSize ) const
inline

serialize a router advertisement into a buffer.

Parameters
packetrouter advertisement to serialize.
databuffer to serialize the message into.
maxSizebuffer size.
Returns
the message size, -1 on failure.

◆ serialize() [5/6]

ssize_t join::NdpMessage::serialize ( const RouterAdvertisement & packet,
char * data,
size_t maxSize,
const MacAddress & link ) const
inline

serialize a router advertisement into a buffer with the given link layer address.

Parameters
packetrouter advertisement to serialize.
databuffer to serialize the message into.
maxSizebuffer size.
linklink layer address to carry instead of the one of the advertisement.
Returns
the message size, -1 on failure.

◆ serialize() [6/6]

ssize_t join::NdpMessage::serialize ( const RouterSolicitation & packet,
char * data,
size_t maxSize ) const
inline

serialize a router solicitation into a buffer.

Parameters
packetrouter solicitation to serialize.
databuffer to serialize the message into.
maxSizebuffer size.
Returns
the message size, -1 on failure.

◆ writeLinkAddress()

static bool join::NdpMessage::writeLinkAddress ( char *& cur,
const char * end,
const MacAddress & link,
OptionType type = SourceLinkAddress )
inlinestaticprotected

write a link layer address option into a buffer.

Parameters
curcurrent position in the buffer, advanced on success.
endend of the buffer.
linklink layer address, nothing is written if wildcard.
typeoption type, source or target link layer address.
Returns
true on success, false if the buffer is too small.

Member Data Documentation

◆ _maxDnsServers

size_t join::NdpMessage::_maxDnsServers = 127
staticconstexprprotected

most recursive DNS servers a single option can carry.

◆ _maxOptionSize

size_t join::NdpMessage::_maxOptionSize = 255 << 3
staticconstexprprotected

biggest option, its length field counts units of 8 octets.

◆ _optionHeaderSize

size_t join::NdpMessage::_optionHeaderSize = 2
staticconstexprprotected

size of an option type and length fields.

◆ maxNeighborAdvertisementSize

size_t join::NdpMessage::maxNeighborAdvertisementSize
staticconstexpr
Initial value:
=
sizeof (struct nd_neighbor_advert) + _optionHeaderSize + ETH_ALEN
static constexpr size_t _optionHeaderSize
size of an option type and length fields.
Definition ndp_message.hpp:684

biggest neighbor advertisement the codec writes, link layer address option included.

◆ maxNeighborSolicitationSize

size_t join::NdpMessage::maxNeighborSolicitationSize
staticconstexpr
Initial value:
=
sizeof (struct nd_neighbor_solicit) + _optionHeaderSize + ETH_ALEN

biggest neighbor solicitation the codec writes, link layer address option included.

◆ maxRouterSolicitationSize

size_t join::NdpMessage::maxRouterSolicitationSize
staticconstexpr
Initial value:
=
sizeof (struct nd_router_solicit) + _optionHeaderSize + ETH_ALEN

biggest router solicitation the codec writes, link layer address option included.


The documentation for this class was generated from the following file: