Kea 2.5.8
isc::dhcp::PktFilter Class Referenceabstract

Abstract packet handling class. More...

#include <pkt_filter.h>

+ Inheritance diagram for isc::dhcp::PktFilter:

Public Member Functions

virtual ~PktFilter ()
 Virtual Destructor.
 
virtual bool isDirectResponseSupported () const =0
 Check if packet can be sent to the host without address directly.
 
virtual bool isSocketReceivedTimeSupported () const =0
 Check if the socket received time is supported.
 
virtual SocketInfo openSocket (Iface &iface, const isc::asiolink::IOAddress &addr, const uint16_t port, const bool receive_bcast, const bool send_bcast)=0
 Open primary and fallback socket.
 
virtual Pkt4Ptr receive (Iface &iface, const SocketInfo &socket_info)=0
 Receive packet over specified socket.
 
virtual int send (const Iface &iface, uint16_t sockfd, const Pkt4Ptr &pkt)=0
 Send packet over specified socket.
 

Protected Member Functions

virtual int openFallbackSocket (const isc::asiolink::IOAddress &addr, const uint16_t port)
 Default implementation to open a fallback socket.
 

Detailed Description

Abstract packet handling class.

This class represents low level method to send and receive DHCP packet. Different methods, represented by classes derived from this class, use different socket families and socket types. Also, various packet filtering methods can be implemented by derived classes, e.g. Linux Packet Filtering (LPF) or Berkeley Packet Filtering (BPF).

Low-level code operating on sockets may require special privileges to execute. For example: opening raw socket or opening socket on low port number requires root privileges. This makes it impossible or very hard to unit test the IfaceMgr. In order to overcome this problem, it is recommended to create mock object derived from this class that mimics the behavior of the real packet handling class making IfaceMgr testable.

Definition at line 44 of file pkt_filter.h.

Constructor & Destructor Documentation

◆ ~PktFilter()

virtual isc::dhcp::PktFilter::~PktFilter ( )
inlinevirtual

Virtual Destructor.

Definition at line 48 of file pkt_filter.h.

Member Function Documentation

◆ isDirectResponseSupported()

virtual bool isc::dhcp::PktFilter::isDirectResponseSupported ( ) const
pure virtual

Check if packet can be sent to the host without address directly.

Checks if the Packet Filter class has capability to send a packet directly to the client having no address assigned. This capability is used by DHCPv4 servers which respond to the clients they assign addresses to. Not all classes derived from PktFilter support this because it requires injection of the destination host HW address to the link layer header of the packet.

Returns
true of the direct response is supported.

Implemented in isc::dhcp::PktFilterBPF, isc::dhcp::PktFilterInet, and isc::dhcp::PktFilterLPF.

◆ isSocketReceivedTimeSupported()

virtual bool isc::dhcp::PktFilter::isSocketReceivedTimeSupported ( ) const
pure virtual

Check if the socket received time is supported.

If true, then packets received through this filter will include a SOCKET_RECEIVED event in its event stack. Other than direct clients using BPF for which this is always true, this function is true provided SO_TIMESTAMP is defined.

Returns
True if it is supported.

Implemented in isc::dhcp::PktFilterBPF, isc::dhcp::PktFilterInet, and isc::dhcp::PktFilterLPF.

◆ openFallbackSocket()

int isc::dhcp::PktFilter::openFallbackSocket ( const isc::asiolink::IOAddress addr,
const uint16_t  port 
)
protectedvirtual

Default implementation to open a fallback socket.

This method provides a means to open a fallback socket and bind it to a given IPv4 address and UDP port. This function may be used by the derived classes to create a fallback socket. It can be overridden in the derived classes if it happens to be insufficient on some environments.

The fallback socket is meant to be opened together with the other socket (a.k.a. primary socket) used to receive and handle DHCPv4 traffic. The traffic received through the fallback should be dropped. The reasoning behind opening the fallback socket is explained in the documentation of isc::dhcp::SocketInfo structure.

Parameters
addrAn IPv4 address to bind the socket to.
portA port number to bind socket to.
Returns
A fallback socket descriptor. This descriptor should be assigned to the fallbackfd_ field of the isc::dhcp::SocketInfo structure.
Exceptions
isc::dhcp::SocketConfigErrorif socket opening, binding or configuration fails.

Definition at line 18 of file pkt_filter.cc.

References isc_throw, and isc::asiolink::IOAddress::toUint32().

Referenced by isc::dhcp::PktFilterBPF::openSocket(), and isc::dhcp::PktFilterLPF::openSocket().

+ Here is the call graph for this function:

◆ openSocket()

virtual SocketInfo isc::dhcp::PktFilter::openSocket ( Iface iface,
const isc::asiolink::IOAddress addr,
const uint16_t  port,
const bool  receive_bcast,
const bool  send_bcast 
)
pure virtual

Open primary and fallback socket.

A method implementation in the derived class may open one or two sockets:

  • a primary socket - used for communication with clients. DHCP messages received using this socket are processed and the same socket is used to send a response to the client.
  • a fallback socket which is optionally opened if there is a need for the presence of the socket which can be bound to a specific IP address and UDP port (e.g. raw primary socket can't be). For the details, see the documentation of isc::dhcp::SocketInfo.
Parameters
ifaceInterface descriptor.
addrAddress on the interface to be used to send packets.
portPort number.
receive_bcastConfigure socket to receive broadcast messages
send_bcastconfigure socket to send broadcast messages.
Returns
A structure describing a primary and fallback socket.

Implemented in isc::dhcp::PktFilterBPF, isc::dhcp::PktFilterInet, and isc::dhcp::PktFilterLPF.

◆ receive()

virtual Pkt4Ptr isc::dhcp::PktFilter::receive ( Iface iface,
const SocketInfo socket_info 
)
pure virtual

Receive packet over specified socket.

Parameters
ifaceinterface
socket_infostructure holding socket information
Returns
Received packet

Implemented in isc::dhcp::PktFilterBPF, isc::dhcp::PktFilterInet, and isc::dhcp::PktFilterLPF.

◆ send()

virtual int isc::dhcp::PktFilter::send ( const Iface iface,
uint16_t  sockfd,
const Pkt4Ptr pkt 
)
pure virtual

Send packet over specified socket.

Parameters
ifaceinterface to be used to send packet
sockfdsocket descriptor
pktpacket to be sent
Returns
result of sending the packet. It is 0 if successful.

Implemented in isc::dhcp::PktFilterBPF, isc::dhcp::PktFilterInet, and isc::dhcp::PktFilterLPF.


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