Kea 3.0.0
isc::ping_check::ICMPMsg Class Reference

Embodies an ICMP message. More...

#include <icmp_msg.h>

Public Types

enum  ICMPMsgType { ECHO_REPLY = 0 , TARGET_UNREACHABLE = 3 , ECHO_REQUEST = 8 }
 ICMP message types. More...

Public Member Functions

 ICMPMsg ()
 Constructor.
virtual ~ICMPMsg ()=default
 Destructor.
uint16_t getChecksum () const
 Fetches the checksum.
uint8_t getCode () const
 Fetches the ICMP message code.
const isc::asiolink::IOAddressgetDestination () const
 Fetches the destination IP address.
uint16_t getId () const
 Fetches the message id.
const std::vector< uint8_t > & getPayload () const
 Fetches the message payload.
uint16_t getSequence () const
 Fetches the message sequence number.
const isc::asiolink::IOAddressgetSource () const
 Fetches the source IP address.
uint8_t getType () const
 Fetches the ICMP message type (e.g.
ICMPPtr pack () const
 Packs the message into an ICMP structure.
void setChecksum (uint16_t check_sum)
 Sets the check sum.
void setCode (uint8_t code)
 Sets the ICMP code.
void setDestination (const isc::asiolink::IOAddress &destination)
 Sets the destination IP address.
void setId (const uint16_t id)
 Sets the message id.
void setPayload (const uint8_t *data, size_t length)
 Sets the message payload to the given data.
void setSequence (uint16_t sequence)
 Sets the message sequence number.
void setSource (const isc::asiolink::IOAddress &source)
 Sets the source IP address.
void setType (uint8_t msg_type)
 Sets the ICMP message type.

Static Public Member Functions

static uint32_t calcChecksum (const uint8_t *data, size_t length)
 Calculates the checksum of the given data buffer.
static ICMPMsgPtr unpack (const uint8_t *wire_data, size_t length)
 Unpacks an ICMP message from the given wire_data.

Static Public Attributes

static constexpr size_t ICMP_HEADER_SIZE = 8
 Size in octets of ICMP message header.

Detailed Description

Embodies an ICMP message.

Provides functions for marshalling of ICMP protocol messages to and from wire form

Definition at line 35 of file icmp_msg.h.

Member Enumeration Documentation

◆ ICMPMsgType

ICMP message types.

We only define the ones we care about.

Enumerator
ECHO_REPLY 
TARGET_UNREACHABLE 
ECHO_REQUEST 

Definition at line 39 of file icmp_msg.h.

Constructor & Destructor Documentation

◆ ICMPMsg()

isc::ping_check::ICMPMsg::ICMPMsg ( )

Constructor.

Definition at line 22 of file icmp_msg.cc.

Referenced by unpack().

◆ ~ICMPMsg()

virtual isc::ping_check::ICMPMsg::~ICMPMsg ( )
virtualdefault

Destructor.

Member Function Documentation

◆ calcChecksum()

uint32_t isc::ping_check::ICMPMsg::calcChecksum ( const uint8_t * data,
size_t length )
static

Calculates the checksum of the given data buffer.

Parameters
datapointer to data buffer from which to copy
lengthnumber of bytes in data buffer
Returns
uint32_t containing the calculated checksum

Definition at line 85 of file icmp_msg.cc.

References isc::util::readUint16().

Referenced by pack().

Here is the call graph for this function:

◆ getChecksum()

uint16_t isc::ping_check::ICMPMsg::getChecksum ( ) const
inline

Fetches the checksum.

Returns
uint16_t containing the message checksum

Definition at line 105 of file icmp_msg.h.

◆ getCode()

uint8_t isc::ping_check::ICMPMsg::getCode ( ) const
inline

Fetches the ICMP message code.

Returns
uint8_t containing the message code

Definition at line 91 of file icmp_msg.h.

◆ getDestination()

const isc::asiolink::IOAddress & isc::ping_check::ICMPMsg::getDestination ( ) const
inline

Fetches the destination IP address.

Returns
IOAddress containing the IP address of the message destination

Definition at line 161 of file icmp_msg.h.

◆ getId()

uint16_t isc::ping_check::ICMPMsg::getId ( ) const
inline

Fetches the message id.

Returns
uint16_t containing the id

Definition at line 119 of file icmp_msg.h.

◆ getPayload()

const std::vector< uint8_t > & isc::ping_check::ICMPMsg::getPayload ( ) const
inline

Fetches the message payload.

Returns
vector containing the message payload

Definition at line 175 of file icmp_msg.h.

◆ getSequence()

uint16_t isc::ping_check::ICMPMsg::getSequence ( ) const
inline

Fetches the message sequence number.

Returns
uint16_t containing the sequence number

Definition at line 133 of file icmp_msg.h.

◆ getSource()

const isc::asiolink::IOAddress & isc::ping_check::ICMPMsg::getSource ( ) const
inline

Fetches the source IP address.

Returns
IOAddress containing the IP address of the message source

Definition at line 147 of file icmp_msg.h.

◆ getType()

uint8_t isc::ping_check::ICMPMsg::getType ( ) const
inline

Fetches the ICMP message type (e.g.

ECHO_REQUEST, ECHO_REPLY)

Returns
message type as a uint8_t

Definition at line 77 of file icmp_msg.h.

◆ pack()

ICMPPtr isc::ping_check::ICMPMsg::pack ( ) const

Packs the message into an ICMP structure.

Returns
Pointer to the newly constructed ICMP structure.
Todo
copy in payload - not needed for ECHO REQUEST

Definition at line 68 of file icmp_msg.cc.

References calcChecksum().

Here is the call graph for this function:

◆ setChecksum()

void isc::ping_check::ICMPMsg::setChecksum ( uint16_t check_sum)
inline

Sets the check sum.

Parameters
check_sumnew value for the check sum

Definition at line 112 of file icmp_msg.h.

◆ setCode()

void isc::ping_check::ICMPMsg::setCode ( uint8_t code)
inline

Sets the ICMP code.

Parameters
codenew value for the message type

Definition at line 98 of file icmp_msg.h.

◆ setDestination()

void isc::ping_check::ICMPMsg::setDestination ( const isc::asiolink::IOAddress & destination)
inline

Sets the destination IP address.

Parameters
destinationnew value for the destination IP address

Definition at line 168 of file icmp_msg.h.

◆ setId()

void isc::ping_check::ICMPMsg::setId ( const uint16_t id)
inline

Sets the message id.

Parameters
idnew value for the message id

Definition at line 126 of file icmp_msg.h.

◆ setPayload()

void isc::ping_check::ICMPMsg::setPayload ( const uint8_t * data,
size_t length )

Sets the message payload to the given data.

Parameters
datapointer to data buffer from which to copy
lengthnumber of bytes in data buffer

Definition at line 80 of file icmp_msg.cc.

◆ setSequence()

void isc::ping_check::ICMPMsg::setSequence ( uint16_t sequence)
inline

Sets the message sequence number.

Parameters
sequencenew value for the message sequence number

Definition at line 140 of file icmp_msg.h.

◆ setSource()

void isc::ping_check::ICMPMsg::setSource ( const isc::asiolink::IOAddress & source)
inline

Sets the source IP address.

Parameters
sourcenew value for the source IP address

Definition at line 154 of file icmp_msg.h.

◆ setType()

void isc::ping_check::ICMPMsg::setType ( uint8_t msg_type)
inline

Sets the ICMP message type.

Parameters
msg_typenew value for the message type

Definition at line 84 of file icmp_msg.h.

◆ unpack()

ICMPMsgPtr isc::ping_check::ICMPMsg::unpack ( const uint8_t * wire_data,
size_t length )
static

Unpacks an ICMP message from the given wire_data.

The wire data is expected to include the IP header followed by an ICMP message.

Parameters
wire_dataraw data received from the socket
lengthnumber of bytes in the wire_data contents
Returns
Pointer to the newly constructed message
Exceptions
BadValueif the wire data is invalid

Definition at line 30 of file icmp_msg.cc.

References ICMPMsg(), ICMP_HEADER_SIZE, and isc_throw.

Referenced by isc::ping_check::PingCheckMgr::handleTargetUnreachable(), and isc::ping_check::PingChannel::socketReadCallback().

Here is the call graph for this function:

Member Data Documentation

◆ ICMP_HEADER_SIZE

size_t isc::ping_check::ICMPMsg::ICMP_HEADER_SIZE = 8
staticconstexpr

Size in octets of ICMP message header.

1 (msg type) + 1 (code) + 2 (checksum) + 4 (either unused or used differently basing on the ICMP type and code e.g Identifier and Sequence Number for Echo or Echo Reply Message)

Definition at line 49 of file icmp_msg.h.

Referenced by unpack().


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