dhcp_server_misc.c File Reference

Helper functions for DHCP server. More...

#include "core/net.h"
#include "dhcp/dhcp_server.h"
#include "dhcp/dhcp_server_misc.h"
#include "dhcp/dhcp_common.h"
#include "dhcp/dhcp_debug.h"
#include "date_time.h"
#include "debug.h"

Go to the source code of this file.

Macros

#define TRACE_LEVEL   DHCP_TRACE_LEVEL
 

Functions

void dhcpServerTick (DhcpServerContext *context)
 DHCP server timer handler. More...
 
void dhcpServerProcessMessage (NetInterface *interface, const IpPseudoHeader *pseudoHeader, const UdpHeader *udpHeader, const NetBuffer *buffer, size_t offset, const NetRxAncillary *ancillary, void *param)
 Process incoming DHCP message. More...
 
void dhcpServerParseDiscover (DhcpServerContext *context, const DhcpMessage *message, size_t length)
 Parse DHCPDISCOVER message. More...
 
void dhcpServerParseRequest (DhcpServerContext *context, const DhcpMessage *message, size_t length)
 Parse DHCPREQUEST message. More...
 
void dhcpServerParseDecline (DhcpServerContext *context, const DhcpMessage *message, size_t length)
 Parse DHCPDECLINE message. More...
 
void dhcpServerParseRelease (DhcpServerContext *context, const DhcpMessage *message, size_t length)
 Parse DHCPRELEASE message. More...
 
void dhcpServerParseInform (DhcpServerContext *context, const DhcpMessage *message, size_t length)
 Parse DHCPINFORM message. More...
 
error_t dhcpServerSendReply (DhcpServerContext *context, uint8_t type, Ipv4Addr yourIpAddr, const DhcpMessage *request, size_t requestLen)
 Send DHCP reply message. More...
 
DhcpServerBindingdhcpServerCreateBinding (DhcpServerContext *context)
 Create a new binding. More...
 
DhcpServerBindingdhcpServerFindBindingByMacAddr (DhcpServerContext *context, const MacAddr *macAddr)
 Search the list of bindings for a given MAC address. More...
 
DhcpServerBindingdhcpServerFindBindingByIpAddr (DhcpServerContext *context, Ipv4Addr ipAddr)
 Search the list of bindings for a given IP address. More...
 
error_t dhcpServerGetNextIpAddr (DhcpServerContext *context, Ipv4Addr *ipAddr)
 Retrieve the next IP address to be used. More...
 

Variables

systime_t dhcpServerTickCounter
 

Detailed Description

Helper functions for DHCP server.

License

SPDX-License-Identifier: GPL-2.0-or-later

Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.

This file is part of CycloneTCP Open.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Author
Oryx Embedded SARL (www.oryx-embedded.com)
Version
2.4.4

Definition in file dhcp_server_misc.c.

Macro Definition Documentation

◆ TRACE_LEVEL

#define TRACE_LEVEL   DHCP_TRACE_LEVEL

Definition at line 32 of file dhcp_server_misc.c.

Function Documentation

◆ dhcpServerCreateBinding()

DhcpServerBinding* dhcpServerCreateBinding ( DhcpServerContext context)

Create a new binding.

Parameters
[in]contextPointer to the DHCP server context
Returns
Pointer to the newly created binding

Definition at line 798 of file dhcp_server_misc.c.

◆ dhcpServerFindBindingByIpAddr()

DhcpServerBinding* dhcpServerFindBindingByIpAddr ( DhcpServerContext context,
Ipv4Addr  ipAddr 
)

Search the list of bindings for a given IP address.

Parameters
[in]contextPointer to the DHCP server context
[in]ipAddrIP address
Returns
Pointer to the corresponding DHCP binding

Definition at line 898 of file dhcp_server_misc.c.

◆ dhcpServerFindBindingByMacAddr()

DhcpServerBinding* dhcpServerFindBindingByMacAddr ( DhcpServerContext context,
const MacAddr macAddr 
)

Search the list of bindings for a given MAC address.

Parameters
[in]contextPointer to the DHCP server context
[in]macAddrMAC address
Returns
Pointer to the corresponding DHCP binding

Definition at line 862 of file dhcp_server_misc.c.

◆ dhcpServerGetNextIpAddr()

error_t dhcpServerGetNextIpAddr ( DhcpServerContext context,
Ipv4Addr ipAddr 
)

Retrieve the next IP address to be used.

Parameters
[in]contextPointer to the DHCP server context
[out]ipAddrNext IP address to be used
Returns
Error code

Definition at line 934 of file dhcp_server_misc.c.

◆ dhcpServerParseDecline()

void dhcpServerParseDecline ( DhcpServerContext context,
const DhcpMessage message,
size_t  length 
)

Parse DHCPDECLINE message.

Parameters
[in]contextPointer to the DHCP server context
[in]messagePointer to the incoming DHCP message
[in]lengthLength of the incoming message to parse

Definition at line 488 of file dhcp_server_misc.c.

◆ dhcpServerParseDiscover()

void dhcpServerParseDiscover ( DhcpServerContext context,
const DhcpMessage message,
size_t  length 
)

Parse DHCPDISCOVER message.

Parameters
[in]contextPointer to the DHCP server context
[in]messagePointer to the incoming DHCP message
[in]lengthLength of the incoming message to parse

Definition at line 230 of file dhcp_server_misc.c.

◆ dhcpServerParseInform()

void dhcpServerParseInform ( DhcpServerContext context,
const DhcpMessage message,
size_t  length 
)

Parse DHCPINFORM message.

Parameters
[in]contextPointer to the DHCP server context
[in]messagePointer to the incoming DHCP message
[in]lengthLength of the incoming message to parse

Definition at line 556 of file dhcp_server_misc.c.

◆ dhcpServerParseRelease()

void dhcpServerParseRelease ( DhcpServerContext context,
const DhcpMessage message,
size_t  length 
)

Parse DHCPRELEASE message.

Parameters
[in]contextPointer to the DHCP server context
[in]messagePointer to the incoming DHCP message
[in]lengthLength of the incoming message to parse

Definition at line 528 of file dhcp_server_misc.c.

◆ dhcpServerParseRequest()

void dhcpServerParseRequest ( DhcpServerContext context,
const DhcpMessage message,
size_t  length 
)

Parse DHCPREQUEST message.

Parameters
[in]contextPointer to the DHCP server context
[in]messagePointer to the incoming DHCP message
[in]lengthLength of the incoming message to parse

Definition at line 364 of file dhcp_server_misc.c.

◆ dhcpServerProcessMessage()

void dhcpServerProcessMessage ( NetInterface interface,
const IpPseudoHeader pseudoHeader,
const UdpHeader udpHeader,
const NetBuffer buffer,
size_t  offset,
const NetRxAncillary ancillary,
void *  param 
)

Process incoming DHCP message.

Parameters
[in]interfaceUnderlying network interface
[in]pseudoHeaderUDP pseudo header
[in]udpHeaderUDP header
[in]bufferMulti-part buffer containing the incoming DHCP message
[in]offsetOffset to the first byte of the DHCP message
[in]ancillaryAdditional options passed to the stack along with the packet
[in]paramPointer to the DHCP server context

Definition at line 119 of file dhcp_server_misc.c.

◆ dhcpServerSendReply()

error_t dhcpServerSendReply ( DhcpServerContext context,
uint8_t  type,
Ipv4Addr  yourIpAddr,
const DhcpMessage request,
size_t  requestLen 
)

Send DHCP reply message.

Parameters
[in]contextPointer to the DHCP server context
[in]typeDHCP message type (DHCPOFFER, DHCPACK or DHCPNAK)
[in]yourIpAddrThe IP address to be placed in the 'yiaddr' field
[in]requestPointer to DHCP message received from the client
[in]requestLenLength of the DHCP message received from the client
Returns
Error code

Definition at line 580 of file dhcp_server_misc.c.

◆ dhcpServerTick()

void dhcpServerTick ( DhcpServerContext context)

DHCP server timer handler.

This routine must be periodically called by the TCP/IP stack to manage DHCP server operation

Parameters
[in]contextPointer to the DHCP server context

Definition at line 59 of file dhcp_server_misc.c.

Variable Documentation

◆ dhcpServerTickCounter

systime_t dhcpServerTickCounter

Definition at line 47 of file dhcp_server_misc.c.