Zephyr Project API 4.3.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
dhcpv4_server.h
Go to the documentation of this file.
1
4
5/*
6 * Copyright (c) 2024 Nordic Semiconductor ASA
7 *
8 * SPDX-License-Identifier: Apache-2.0
9 */
10
11#ifndef ZEPHYR_INCLUDE_NET_DHCPV4_SERVER_H_
12#define ZEPHYR_INCLUDE_NET_DHCPV4_SERVER_H_
13
14#include <zephyr/net/net_ip.h>
15#include <zephyr/sys_clock.h>
16
17#ifdef __cplusplus
18extern "C" {
19#endif
20
29
31
32struct net_if;
33
34#define DHCPV4_CLIENT_ID_MAX_SIZE 20
35
40#define DHCPV4_HARDWARE_ADDRESS_MAX_SIZE 16
41
42enum dhcpv4_server_addr_state {
43 DHCPV4_SERVER_ADDR_FREE,
44 DHCPV4_SERVER_ADDR_RESERVED,
45 DHCPV4_SERVER_ADDR_ALLOCATED,
46 DHCPV4_SERVER_ADDR_DECLINED,
47};
48
49struct dhcpv4_client_id {
50 uint8_t hw_addr_type;
51 uint8_t hw_addr_buf[DHCPV4_HARDWARE_ADDRESS_MAX_SIZE];
52 uint8_t hw_addr_len;
53
54 uint8_t buf[DHCPV4_CLIENT_ID_MAX_SIZE];
55 uint8_t len;
56};
57
58struct dhcpv4_addr_slot {
59 enum dhcpv4_server_addr_state state;
60 struct dhcpv4_client_id client_id;
61 struct net_in_addr addr;
62 uint32_t lease_time;
63 k_timepoint_t expiry;
64};
65
67
82int net_dhcpv4_server_start(struct net_if *iface, struct net_in_addr *base_addr);
83
94int net_dhcpv4_server_stop(struct net_if *iface);
95
104typedef void (*net_dhcpv4_lease_cb_t)(struct net_if *iface,
105 struct dhcpv4_addr_slot *lease,
106 void *user_data);
107
120 void *user_data);
121
137typedef int (*net_dhcpv4_server_provider_cb_t)(struct net_if *iface,
138 const struct dhcpv4_client_id *client_id,
139 struct net_in_addr *addr,
140 void *user_data);
148 void *user_data);
149
153
154#ifdef __cplusplus
155}
156#endif
157
158#endif /* ZEPHYR_INCLUDE_NET_DHCPV4_SERVER_H_ */
int net_dhcpv4_server_start(struct net_if *iface, struct net_in_addr *base_addr)
Start DHCPv4 server instance on an iface.
void net_dhcpv4_server_set_provider_cb(net_dhcpv4_server_provider_cb_t cb, void *user_data)
Set the callback used to provide addresses to the DHCP server.
int(* net_dhcpv4_server_provider_cb_t)(struct net_if *iface, const struct dhcpv4_client_id *client_id, struct net_in_addr *addr, void *user_data)
Callback used to let application provide an address for a given client ID.
Definition dhcpv4_server.h:137
int net_dhcpv4_server_foreach_lease(struct net_if *iface, net_dhcpv4_lease_cb_t cb, void *user_data)
Iterate over all DHCPv4 address leases on a given network interface and call callback for each lease.
int net_dhcpv4_server_stop(struct net_if *iface)
Stop DHCPv4 server instance on an iface.
void(* net_dhcpv4_lease_cb_t)(struct net_if *iface, struct dhcpv4_addr_slot *lease, void *user_data)
Callback used while iterating over active DHCPv4 address leases.
Definition dhcpv4_server.h:104
IPv6 and IPv4 definitions.
state
Definition parser_state.h:29
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
Network Interface structure.
Definition net_if.h:726
IPv4 address struct.
Definition net_ip.h:155