Kea 2.7.5
|
Abstract packet handling class for DHCPv6. More...
#include <pkt_filter6.h>
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. | |
Abstract packet handling class for DHCPv6.
This class defines methods for performing low level operations on IPv6 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.
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.
|
inlinevirtual |
Virtual Destructor.
Definition at line 74 of file pkt_filter6.h.
|
static |
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.
sock | A socket descriptor (socket must be bound). |
ifname | An interface name (for link-scoped multicast groups). |
mcast | A multicast address to join (e.g. "ff02::1:2"). |
Definition at line 15 of file pkt_filter6.cc.
Referenced by isc::dhcp::PktFilterInet6::openSocket().
|
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.
iface | Interface descriptor. |
addr | Address on the interface to be used to send packets. |
port | Port number. |
join_multicast | A boolean parameter which indicates whether socket should join All_DHCP_Relay_Agents_and_servers multicast group. |
Implemented in isc::dhcp::PktFilterInet6.
|
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_info | A structure holding socket information. |
Implemented in isc::dhcp::PktFilterInet6.
|
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.
iface | Interface to be used to send packet. |
sockfd | A socket descriptor |
pkt | A packet to be sent. |
Implemented in isc::dhcp::PktFilterInet6.