29#define DHCP_SERV_MAX_INTF (4)
30#define DHCP_OFFER_DURATION (2 * TICKS_PER_SECOND)
31#define DHCP_SERV_MAX_HOSTNAME_LEN (32)
33#define LEASE_POOL_SIZE 150
34#define DHCPD_STARTING_ADDRESS 0xC0A80184
104 virtual uint32_t GetLeaseTime() = 0;
109 virtual bool GetDhcpInfo(
DhcpInfo &infoBlock,
MACADR &client_mac,
int intfNum) = 0;
110 virtual bool AddInterface(
int intfNum) = 0;
111 virtual void RemoveInterface(
int intfNum) = 0;
125 uint32_t m_leaseDuration;
132 inline void ChangeAllocAddr(
IPADDR4 ip) { m_theIP = ip; }
138 if ((m_intfNum > 0) && (m_intfNum != intfNum))
140 pLease->
ip = m_theIP;
148 if ((m_intfNum > 0) && (m_intfNum != intfNum))
150 if (pLease->
ip != m_theIP)
152 pLease->
ip = 0x00000000;
155 pLease->
ip = m_theIP;
163 if ((m_intfNum > 0) && (m_intfNum != intfNum))
165 return pLease->
ip == m_theIP;
171 if ((m_intfNum > 0) && (m_intfNum != intfNum))
174 return pLease->
ip == m_theIP;
177 virtual uint32_t GetLeaseTime() {
return m_leaseDuration; }
179 void SetLeaseTime(uint32_t hours, uint32_t minutes = 0, uint32_t seconds = 0);
180 virtual bool GetDhcpInfo(
DhcpInfo &infoBlock,
MACADR &client_mac,
int intfNum);
181 virtual void UpdateDhcpInfo(
const DhcpInfo *infoBlock) {
return; }
182 virtual bool AddInterface(
int intfNum) { m_intfNum = intfNum;
return true; }
183 virtual void RemoveInterface(
int intfNum) {
if (m_intfNum == intfNum) m_intfNum = 0;
return; }
184 virtual bool IsRegisteredInterface(
int intfNum) {
return true; }
185 virtual bool GetLeaseData(
DhcpLeaseData *data) {
return false; }
192 const int m_leaseCount;
194 bool m_staticLeaseExist;
195 uint32_t m_lastIndex;
198 bool IsValidIntf(
int intfNum);
199 uint32_t m_leaseDuration;
205 void SetLeaseTime(uint32_t hours, uint32_t minutes = 0, uint32_t seconds = 0);
207 virtual uint32_t GetLeaseTime() {
return m_leaseDuration; }
213 virtual bool GetDhcpInfo(
DhcpInfo &infoBlock,
MACADR &client_mac,
int intfNum);
214 virtual void UpdateDhcpInfo(
const DhcpInfo *infoBlock);
215 virtual bool AddInterface(
int intfNum);
216 virtual void RemoveInterface(
int intfNum);
217 inline virtual bool IsRegisteredInterface(
int intfNum)
221 if (m_validIntf[i] == intfNum) {
return true; }
228 inline void SetStartIP(
const IPADDR4 newStartIP)
230 m_startIP = newStartIP;
243 const bool m_whitelist;
248 const bool whitelist,
250 const int leaseCount,
263 static Server *theInstance;
267 void ProcessDiscover(
PoolPtr pp);
268 void ProcessRequest(
PoolPtr pp);
269 void ProcessDecline(
PoolPtr pp);
270 void ProcessRelease(
PoolPtr pp);
271 void ProcessInform(
PoolPtr pp);
273 void ProcessParamReq(uint8_t *&optBuf, uint8_t *ReqList, uint8_t reqLen,
const DhcpInfo &info,
IPADDR4 intfIP);
279 bool ProcessServerMessage(
PoolPtr pp);
283 bool AddInterface(
int intfNum);
284 void RemoveInterface(
int intfNum);
286 static inline bool AddServerInterface(
int intfNum)
288 if (theInstance) {
return theInstance->AddInterface(intfNum); }
291 static inline void RemoveServerInterface(
int intfNum)
293 if (theInstance) { theInstance->RemoveInterface(intfNum); }
295 static inline void ProcessMessage(
PoolPtr pp)
297 if (theInstance) { theInstance->ProcessServerMessage(pp); }
299 static inline Server *GetInstance() {
return theInstance; }
Basic allocator that handles multiple leases in a contiguous IP block.
Definition dhcpd.h:190
Base class/interface for lease allocators for the DHCP server.
Definition dhcpd.h:90
Derived from BlockAllocator Has the ability to whitelist/blacklist certain mac address ranges based o...
Definition dhcpd.h:240
DHCP Server class Requires a lease allocator to be added in order to function.
Definition dhcpd.h:262
Stripped down allocator Fails to conform to many standard behaviors, but shows the basics of what nee...
Definition dhcpd.h:120
Used to store and manipulate IPv4 addresses in dual stack mode.
Definition nettypes.h:225
static IPADDR4 NullIP()
C++ static function for a null IP address.
Definition nettypes.h:363
Used to store and manipulate MAC addresses.
Definition nettypes.h:69
bool AddStandardDHCPServer(int intf=0, IPADDR4 startAddr=IPADDR4::NullIP())
Starts a standard allocator DHCP server.
#define DHCP_SERV_MAX_HOSTNAME_LEN
Definition dhcpd.h:31
#define DHCP_SERV_MAX_INTF
Definition dhcpd.h:29
DHCP Namespace.
Definition dhcpd.h:39
enum DHCP::LeaseState LeaseState_t
Lease State.
LeaseState
Lease State.
Definition dhcpd.h:43
@ LEASE_OPEN
Definition dhcpd.h:44
@ LEASE_TAKEN
Definition dhcpd.h:46
@ LEASE_STATIC
Definition dhcpd.h:47
@ LEASE_OFFERED
Definition dhcpd.h:45
@ ARP_CONFLICT
Definition dhcpd.h:48
DHCP Info.
Definition dhcpd.h:72
IPADDR4 dns_1
primary DNS Server
Definition dhcpd.h:75
IPADDR4 dns_2
secondary DNS Server
Definition dhcpd.h:76
uint8_t * bonusOpts
additional options, pre written
Definition dhcpd.h:85
IPADDR4 logServ
Syslog Server.
Definition dhcpd.h:77
IPADDR4 ntpServ
NTP Server.
Definition dhcpd.h:79
char * bootfile
tftp boot file, null terminated
Definition dhcpd.h:83
uint16_t bonusLength
Length of any additional options, pre written.
Definition dhcpd.h:84
IPADDR4 netmask
Netmask for the lease offered.
Definition dhcpd.h:73
IPADDR4 gateway
gateway to be offered
Definition dhcpd.h:74
char * hostname
Hostname.
Definition dhcpd.h:81
char * tftp_name
tftp server name/dotted ip, null terminated
Definition dhcpd.h:82
IPADDR4 smtpServ
SMTP Server.
Definition dhcpd.h:78
const char * domain_name
Domain name for hosts.
Definition dhcpd.h:80
Lease Data.
Definition dhcpd.h:63
char hostname[DHCP_SERV_MAX_HOSTNAME_LEN+1]
buffer for client hostname
Definition dhcpd.h:67
uint32_t expiration
The tick that the lease expires on.
Definition dhcpd.h:66
MACADR mac
source mac address of the request
Definition dhcpd.h:65
IPADDR4 ip
the IP Address to be offered
Definition dhcpd.h:64
Lease Request.
Definition dhcpd.h:53
uint32_t xid
transaction id of the DHCP message
Definition dhcpd.h:57
uint32_t duration
The duration of the lease, in seconds.
Definition dhcpd.h:56
MACADR mac
source mac address of the request
Definition dhcpd.h:55
IPADDR4 ip
the IP Address to be offered
Definition dhcpd.h:54
char hostname[DHCP_SERV_MAX_HOSTNAME_LEN+1]
buffer for client hostname
Definition dhcpd.h:58
Main buffer structure for network and serial communication.
Definition buffers.h:90