Kea 2.5.9
isc::dhcp::PktFilter6 Class Referenceabstract

Abstract packet handling class for DHCPv6. More...

#include <pkt_filter6.h>

+ Inheritance diagram for isc::dhcp::PktFilter6:

Public Member Functions

virtual ~PktFilter6 ()
 Virtual Destructor.
virtual SocketInfo openSocket (const Iface &iface, const isc::asiolink::IOAddress &addr, const uint16_t port, const bool join_multicast)=0
 Opens a socket.
virtual Pkt6Ptr receive (const SocketInfo &socket_info)=0
 Receives DHCPv6 message on the interface.
virtual int send (const Iface &iface, uint16_t sockfd, const Pkt6Ptr &pkt)=0
 Sends DHCPv6 message through a specified interface and socket.

Static Public Member Functions

static bool joinMulticast (int sock, const std::string &ifname, const std::string &mcast)
 Joins IPv6 multicast group on a socket.

Detailed Description

Abstract packet handling class for DHCPv6.

This class defines methods for performing low level operations on IPv6 socket:

  • open socket,
  • send DHCPv6 message through the socket,
  • receive DHCPv6 through the socket.

Methods exposed by this class are called through the IfaceMgr only. They are not meant to be called directly, except unit testing.

The IfaceMgr is responsible for managing the pool of sockets. In particular, IfaceMgr detects interfaces suitable to send/receive DHCPv6 messages. When it intends to open a socket on a particular interface, it will call the PktFilter6::openSocket. If this call is successful, the structure describing a new socket is returned.

In order to send or receive a DHCPv6 message through this socket, the IfaceMgr must use PktFilter6::send or PktFilter6::receive functions of the same class that has been used to open a socket, i.e. all send/receive operations should be performed using this particular class.

The major motivation behind creating a separate class, to manage low level operations using sockets, is to make IfaceMgr unit testable. By providing a stub implementation of this class which mimics the behavior of the real socket handling class, it is possible to simulate and test various conditions. For example, the IfaceMgr::openSockets function will try to open sockets on all available interfaces. The test doesn't have any means to know which interfaces are present. In addition, even if the network interface detection was implemented on the test side, there is no guarantee that the particular system has sufficient number of suitable IPv6-enabled interfaces available for a particular test. Moreover, the test may need to tweak some of the interface configuration to cover certain test scenarios. The proposed solution is to not use the actual interfaces but simply create a pool of fake interfaces which configuration can be freely modified by a test. This however implies that operations on sockets must be simulated.

This class is named after PktFilter abstract class which exposes similar interface for DHCPv4. However, the PktFilter class is devoted to solve the problem of sending DHCPv4 messages to the hosts which don't have an IP address yet (a.k.a. direct DHCPv4 traffic). Where required, the custom implementations of PktFilter are provided to send and receive messages through raw sockets. In order to filter out the desired traffic Linux Packet Filtering or Berkeley Packet Filtering is used, hence the name of the class. In case of DHCPv6 regular IPv6/UDPv6 sockets are used and derived classes do not use Linux or Berkeley Packet Filtering.

Definition at line 70 of file pkt_filter6.h.

Constructor & Destructor Documentation

◆ ~PktFilter6()

virtual isc::dhcp::PktFilter6::~PktFilter6 ( )

Virtual Destructor.

Definition at line 74 of file pkt_filter6.h.

Member Function Documentation

◆ joinMulticast()

bool isc::dhcp::PktFilter6::joinMulticast ( int  sock,
const std::string &  ifname,
const std::string &  mcast 

Joins IPv6 multicast group on a socket.

This function joins the socket to the specified multicast group. The socket descriptor must point to a valid socket bound to the in6addr_any prior to calling this function.

sockA socket descriptor (socket must be bound).
ifnameAn interface name (for link-scoped multicast groups).
mcastA multicast address to join (e.g. "ff02::1:2").
true if multicast join was successful

Definition at line 15 of file

Referenced by isc::dhcp::PktFilterInet6::openSocket().

◆ openSocket()

virtual SocketInfo isc::dhcp::PktFilter6::openSocket ( const Iface iface,
const isc::asiolink::IOAddress addr,
const uint16_t  port,
const bool  join_multicast 
pure virtual

Opens a socket.

This function open an IPv6 socket on an interface and binds it to a specified UDP port and IPv6 address.

ifaceInterface descriptor.
addrAddress on the interface to be used to send packets.
portPort number.
join_multicastA boolean parameter which indicates whether socket should join All_DHCP_Relay_Agents_and_servers multicast group.
A structure describing a primary and fallback socket.

Implemented in isc::dhcp::PktFilterInet6.

◆ receive()

virtual Pkt6Ptr isc::dhcp::PktFilter6::receive ( const SocketInfo socket_info)
pure virtual

Receives DHCPv6 message on the interface.

This function receives a single DHCPv6 message through using a socket open on a specified interface.

socket_infoA structure holding socket information.
A pointer to received message.

Implemented in isc::dhcp::PktFilterInet6.

◆ send()

virtual int isc::dhcp::PktFilter6::send ( const Iface iface,
uint16_t  sockfd,
const Pkt6Ptr pkt 
pure virtual

Sends DHCPv6 message through a specified interface and socket.

This function sends a DHCPv6 message through a specified interface and socket. In general, there may be multiple sockets open on a single interface as a single interface may have multiple IPv6 addresses.

ifaceInterface to be used to send packet.
sockfdA socket descriptor
pktA packet to be sent.
A result of sending the message. It is 0 if successful.

Implemented in isc::dhcp::PktFilterInet6.

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