Kea
1.9.9-git
|
Abstract packet handling class. More...
#include <pkt_filter.h>
Public Member Functions | |
virtual | ~PktFilter () |
Virtual Destructor. More... | |
virtual bool | isDirectResponseSupported () const =0 |
Check if packet can be sent to the host without address directly. More... | |
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. More... | |
virtual Pkt4Ptr | receive (Iface &iface, const SocketInfo &socket_info)=0 |
Receive packet over specified socket. More... | |
virtual int | send (const Iface &iface, uint16_t sockfd, const Pkt4Ptr &pkt)=0 |
Send packet over specified socket. More... | |
Protected Member Functions | |
virtual int | openFallbackSocket (const isc::asiolink::IOAddress &addr, const uint16_t port) |
Default implementation to open a fallback socket. More... | |
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.
|
inlinevirtual |
Virtual Destructor.
Definition at line 48 of file pkt_filter.h.
|
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.
Implemented in isc::dhcp::PktFilterBPF, isc::dhcp::PktFilterLPF, and isc::dhcp::PktFilterInet.
|
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.
addr | An IPv4 address to bind the socket to. |
port | A port number to bind socket to. |
fallbackfd_
field of the isc::dhcp::SocketInfo
structure. isc::dhcp::SocketConfigError | if socket opening, binding or configuration fails. |
Definition at line 18 of file pkt_filter.cc.
References isc_throw, and isc::asiolink::IOAddress::toUint32().
|
pure virtual |
Open primary and fallback socket.
A method implementation in the derived class may open one or two sockets:
isc::dhcp::SocketInfo
.iface | Interface descriptor. |
addr | Address on the interface to be used to send packets. |
port | Port number. |
receive_bcast | Configure socket to receive broadcast messages |
send_bcast | configure socket to send broadcast messages. |
Implemented in isc::dhcp::PktFilterBPF, isc::dhcp::PktFilterInet, and isc::dhcp::PktFilterLPF.
|
pure virtual |
Receive packet over specified socket.
iface | interface |
socket_info | structure holding socket information |
Implemented in isc::dhcp::PktFilterBPF, isc::dhcp::PktFilterInet, and isc::dhcp::PktFilterLPF.
|
pure virtual |
Send packet over specified socket.
iface | interface to be used to send packet |
sockfd | socket descriptor |
pkt | packet to be sent |
Implemented in isc::dhcp::PktFilterBPF, isc::dhcp::PktFilterInet, and isc::dhcp::PktFilterLPF.