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;
124 uint32_t m_leaseDuration;
131 inline void ChangeAllocAddr(
IPADDR4 ip) { m_theIP = ip; }
135 pLease->
ip = m_theIP;
141 if (pLease->
ip != m_theIP)
143 pLease->
ip = 0x00000000;
146 pLease->
ip = m_theIP;
150 inline virtual bool ReleaseLease(
DhcpLeaseRequest *pLease,
int intfNum) {
return pLease->
ip == m_theIP; }
154 return pLease->
ip == m_theIP;
157 virtual uint32_t GetLeaseTime() {
return m_leaseDuration; }
159 void SetLeaseTime(uint32_t hours, uint32_t minutes = 0, uint32_t seconds = 0);
160 virtual bool GetDhcpInfo(
DhcpInfo &infoBlock,
MACADR &client_mac,
int intfNum);
161 virtual void UpdateDhcpInfo(
const DhcpInfo *infoBlock) {
return; }
162 virtual bool AddInterface(
int intfNum) {
return true; }
163 virtual void RemoveInterface(
int intfNum) {
return; }
164 virtual bool IsRegisteredInterface(
int intfNum) {
return true; }
165 virtual bool GetLeaseData(
DhcpLeaseData *data) {
return false; }
172 const int m_leaseCount;
174 bool m_staticLeaseExist;
175 uint32_t m_lastIndex;
176 int m_validIntf[DHCP_SERV_MAX_INTF];
178 bool IsValidIntf(
int intfNum);
179 uint32_t m_leaseDuration;
185 void SetLeaseTime(uint32_t hours, uint32_t minutes = 0, uint32_t seconds = 0);
187 virtual uint32_t GetLeaseTime() {
return m_leaseDuration; }
193 virtual bool GetDhcpInfo(
DhcpInfo &infoBlock,
MACADR &client_mac,
int intfNum);
194 virtual void UpdateDhcpInfo(
const DhcpInfo *infoBlock);
195 virtual bool AddInterface(
int intfNum);
196 virtual void RemoveInterface(
int intfNum);
197 inline virtual bool IsRegisteredInterface(
int intfNum)
199 for (
int i = 0; i < DHCP_SERV_MAX_INTF; i++)
201 if (m_validIntf[i] == intfNum) {
return true; }
208 inline void SetStartIP(
const IPADDR4 newStartIP)
210 m_startIP = newStartIP;
223 const bool m_whitelist;
228 const bool whitelist,
230 const int leaseCount,
243 static Server *theInstance;
247 void ProcessDiscover(PoolPtr pp);
248 void ProcessRequest(PoolPtr pp);
249 void ProcessDecline(PoolPtr pp);
250 void ProcessRelease(PoolPtr pp);
251 void ProcessInform(PoolPtr pp);
253 void ProcessParamReq(uint8_t *&optBuf, uint8_t *ReqList, uint8_t reqLen,
const DhcpInfo &info,
IPADDR4 intfIP);
259 bool ProcessServerMessage(PoolPtr pp);
263 bool AddInterface(
int intfNum);
264 void RemoveInterface(
int intfNum);
266 static inline bool AddServerInterface(
int intfNum)
268 if (theInstance) {
return theInstance->AddInterface(intfNum); }
271 static inline void RemoveServerInterface(
int intfNum)
273 if (theInstance) { theInstance->RemoveInterface(intfNum); }
275 static inline void ProcessMessage(PoolPtr pp)
277 if (theInstance) { theInstance->ProcessServerMessage(pp); }
279 static inline Server *GetInstance() {
return theInstance; }
Basic allocator that handles multiple leases in a contiguous IP block.
Definition dhcpd.h:170
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:220
DHCP Server class Requires a lease allocator to be added in order to function.
Definition dhcpd.h:242
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:208
static IPADDR4 NullIP()
C++ static function for a null IP address.
Definition nettypes.h:346
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.
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
NetBurner System Constants.
NetBurner IPADDR4 Class. See the IPADDR4 Class page for complete documentation.
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