join 1.0
lightweight network framework library
Loading...
Searching...
No Matches
join::BasicDhcpServer< Protocol > Class Template Referenceabstract

DHCP server. More...

#include <dhcp.hpp>

Inheritance diagram for join::BasicDhcpServer< Protocol >:
Collaboration diagram for join::BasicDhcpServer< Protocol >:

Public Member Functions

 BasicDhcpServer ()=delete
 create the BasicDhcpServer instance.
 
 BasicDhcpServer (const std::string &interface, Reactor &reactor=ReactorThread::reactor())
 create the instance bound to the given interface.
 
virtual ~BasicDhcpServer ()=default
 destroy the instance.
 
int offer (const DhcpPacket &request, const IpAddress &address, const DhcpOption &options={})
 answer a DISCOVER message with an OFFER.
 
int ack (const DhcpPacket &request, const IpAddress &address, const DhcpOption &options={})
 answer a REQUEST message with an ACK.
 
int nak (const DhcpPacket &request, const std::string &message={})
 refuse a REQUEST message with a NAK.
 
- Public Member Functions inherited from join::BasicDhcp< Protocol >
 BasicDhcp ()=delete
 create the BasicDhcp instance.
 
 BasicDhcp (const std::string &interface, Reactor &reactor=ReactorThread::reactor())
 create the instance bound to the given interface.
 
 BasicDhcp (const BasicDhcp &other)=delete
 create instance by copy.
 
BasicDhcpoperator= (const BasicDhcp &other)=delete
 assign instance by copy.
 
 BasicDhcp (BasicDhcp &&other)=delete
 create instance by move.
 
BasicDhcpoperator= (BasicDhcp &&other)=delete
 assign instance by move.
 
virtual ~BasicDhcp ()
 destroy the instance.
 
const std::string & interface () const noexcept
 get the name of the interface the instance is bound to.
 
const MacAddresshardware () const noexcept
 get the hardware address of the interface the instance is bound to.
 
- Public Member Functions inherited from join::EventHandler
 EventHandler ()=default
 create instance.
 
 EventHandler (const EventHandler &other)=default
 copy constructor.
 
EventHandleroperator= (const EventHandler &other)=default
 copy assignment operator.
 
 EventHandler (EventHandler &&other)=default
 move constructor.
 
EventHandleroperator= (EventHandler &&other)=default
 move assignment operator.
 
virtual ~EventHandler ()=default
 destroy instance.
 

Protected Member Functions

virtual void onDiscover (const DhcpPacket &request)=0
 method called when a DISCOVER message is received.
 
virtual void onRequest (const DhcpPacket &request)=0
 method called when a REQUEST message is received.
 
virtual void onRelease (const DhcpPacket &request)=0
 method called when a RELEASE message is received.
 
virtual void onDecline (const DhcpPacket &request)=0
 method called when a DECLINE message is received.
 
virtual void onInform (const DhcpPacket &request)=0
 method called when an INFORM message is received.
 
void onMessage (DhcpPacket::Ptr packet) override final
 dispatch a received message to the handler for its type.
 
int reply (const DhcpPacket &request, uint8_t type, const IpAddress &address, const DhcpOption &options)
 answer a message received from a client.
 
- Protected Member Functions inherited from join::BasicDhcp< Protocol >
struct __attribute__ ((packed)) Frame
 link, internet and transport headers a DHCP message is framed with.
 
struct __attribute__ ((packed)) Pseudo
 header the UDP checksum is computed over, RFC 768.
 
void onReadable (int fd) override final
 method called when data are ready to be read.
 
int transmit (const DhcpPacket &packet, const IpAddress &source, const IpAddress &destination)
 frame a message and write it on the wire.
 
DhcpPacket::Ptr receive (const char *data, size_t size) const
 decode a frame received on the wire.
 
- Protected Member Functions inherited from join::EventHandler
virtual void onEvent (int fd, uint32_t revents)
 method called when events are reported on handle.
 
virtual void onWriteable (int fd)
 method called when data are ready to be written on handle.
 
virtual void onClose (int fd)
 method called when handle was closed by the peer.
 
virtual void onError (int fd)
 method called when an error occurred on handle.
 

Additional Inherited Members

- Public Types inherited from join::BasicDhcp< Protocol >
using Socket = typename Protocol::Socket
 
- Static Protected Member Functions inherited from join::BasicDhcp< Protocol >
static uint16_t udpChecksum (const Frame &frame, const char *payload, size_t size)
 compute the checksum of a UDP datagram, RFC 768.
 
- Protected Attributes inherited from join::BasicDhcp< Protocol >
Socket _socket
 underlying socket.
 
DhcpMessage _message
 DHCP message codec.
 
std::unique_ptr< char[]> _buffer
 receive buffer.
 
const std::string _interface
 interface name.
 
const MacAddress _hardware
 hardware address of the interface.
 
Reactor_reactor
 event loop reactor.
 

Detailed Description

template<class Protocol>
class join::BasicDhcpServer< Protocol >

DHCP server.

Constructor & Destructor Documentation

◆ BasicDhcpServer() [1/2]

template<class Protocol >
join::BasicDhcpServer< Protocol >::BasicDhcpServer ( )
delete

create the BasicDhcpServer instance.

◆ BasicDhcpServer() [2/2]

template<class Protocol >
join::BasicDhcpServer< Protocol >::BasicDhcpServer ( const std::string & interface,
Reactor & reactor = ReactorThread::reactor () )
inlineexplicit

create the instance bound to the given interface.

Parameters
interfaceinterface name.
reactorreactor instance.
Exceptions
std::system_errorif the interface is unknown or the socket could not be bound to it.

◆ ~BasicDhcpServer()

template<class Protocol >
virtual join::BasicDhcpServer< Protocol >::~BasicDhcpServer ( )
virtualdefault

destroy the instance.

Member Function Documentation

◆ ack()

template<class Protocol >
int join::BasicDhcpServer< Protocol >::ack ( const DhcpPacket & request,
const IpAddress & address,
const DhcpOption & options = {} )
inline

answer a REQUEST message with an ACK.

Parameters
requestmessage being answered.
addressaddress assigned to the client.
optionsoptions to advertise, the message type and the server identifier are added.
Returns
0 on success, -1 on failure.

◆ nak()

template<class Protocol >
int join::BasicDhcpServer< Protocol >::nak ( const DhcpPacket & request,
const std::string & message = {} )
inline

refuse a REQUEST message with a NAK.

Parameters
requestmessage being refused.
messagehuman readable reason, empty to give none.
Returns
0 on success, -1 on failure.

◆ offer()

template<class Protocol >
int join::BasicDhcpServer< Protocol >::offer ( const DhcpPacket & request,
const IpAddress & address,
const DhcpOption & options = {} )
inline

answer a DISCOVER message with an OFFER.

Parameters
requestmessage being answered.
addressaddress offered to the client.
optionsoptions to advertise, the message type and the server identifier are added.
Returns
0 on success, -1 on failure.

◆ onDecline()

template<class Protocol >
virtual void join::BasicDhcpServer< Protocol >::onDecline ( const DhcpPacket & request)
protectedpure virtual

method called when a DECLINE message is received.

Parameters
requestmessage received.

◆ onDiscover()

template<class Protocol >
virtual void join::BasicDhcpServer< Protocol >::onDiscover ( const DhcpPacket & request)
protectedpure virtual

method called when a DISCOVER message is received.

Parameters
requestmessage received.

◆ onInform()

template<class Protocol >
virtual void join::BasicDhcpServer< Protocol >::onInform ( const DhcpPacket & request)
protectedpure virtual

method called when an INFORM message is received.

Parameters
requestmessage received.

◆ onMessage()

template<class Protocol >
void join::BasicDhcpServer< Protocol >::onMessage ( DhcpPacket::Ptr packet)
inlinefinaloverrideprotectedvirtual

dispatch a received message to the handler for its type.

Parameters
packetmessage received.

Implements join::BasicDhcp< Protocol >.

◆ onRelease()

template<class Protocol >
virtual void join::BasicDhcpServer< Protocol >::onRelease ( const DhcpPacket & request)
protectedpure virtual

method called when a RELEASE message is received.

Parameters
requestmessage received.

◆ onRequest()

template<class Protocol >
virtual void join::BasicDhcpServer< Protocol >::onRequest ( const DhcpPacket & request)
protectedpure virtual

method called when a REQUEST message is received.

Parameters
requestmessage received.

◆ reply()

template<class Protocol >
int join::BasicDhcpServer< Protocol >::reply ( const DhcpPacket & request,
uint8_t type,
const IpAddress & address,
const DhcpOption & options )
inlineprotected

answer a message received from a client.

Parameters
requestmessage being answered.
typemessage type of the answer.
addressaddress assigned to the client.
optionsoptions to advertise.
Returns
0 on success, -1 on failure.

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