1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
5 Copyright © 2013 Intel Corporation. All rights reserved.
8 #include "sd-dhcp-server.h"
11 #include "dhcp-internal.h"
12 #include "network-common.h"
13 #include "ordered-set.h"
14 #include "time-util.h"
16 typedef enum DHCPRawOption
{
17 DHCP_RAW_OPTION_DATA_UINT8
,
18 DHCP_RAW_OPTION_DATA_UINT16
,
19 DHCP_RAW_OPTION_DATA_UINT32
,
20 DHCP_RAW_OPTION_DATA_STRING
,
21 DHCP_RAW_OPTION_DATA_IPV4ADDRESS
,
22 DHCP_RAW_OPTION_DATA_IPV6ADDRESS
,
23 _DHCP_RAW_OPTION_DATA_MAX
,
24 _DHCP_RAW_OPTION_DATA_INVALID
,
27 typedef struct DHCPClientId
{
32 typedef struct DHCPLease
{
33 sd_dhcp_server
*server
;
35 DHCPClientId client_id
;
37 uint8_t htype
; /* e.g. ARPHRD_ETHER */
38 uint8_t hlen
; /* e.g. ETH_ALEN */
45 struct sd_dhcp_server
{
50 sd_event_source
*receive_message
;
51 sd_event_source
*receive_broadcast
;
58 bool bind_to_interface
;
67 DHCPServerData servers
[_SD_DHCP_LEASE_SERVER_TYPE_MAX
];
68 struct in_addr boot_server_address
;
69 char *boot_server_name
;
72 OrderedSet
*extra_options
;
73 OrderedSet
*vendor_options
;
76 struct in_addr router_address
;
78 Hashmap
*bound_leases_by_client_id
;
79 Hashmap
*bound_leases_by_address
;
80 Hashmap
*static_leases_by_client_id
;
81 Hashmap
*static_leases_by_address
;
83 uint32_t max_lease_time
, default_lease_time
;
85 sd_dhcp_server_callback_t callback
;
86 void *callback_userdata
;
88 struct in_addr relay_target
;
90 char *agent_circuit_id
;
91 char *agent_remote_id
;
94 typedef struct DHCPRequest
{
95 /* received message */
99 DHCPClientId client_id
;
104 const uint8_t *agent_info_option
;
107 extern const struct hash_ops dhcp_lease_hash_ops
;
109 int dhcp_server_handle_message(sd_dhcp_server
*server
, DHCPMessage
*message
,
111 int dhcp_server_send_packet(sd_dhcp_server
*server
,
112 DHCPRequest
*req
, DHCPPacket
*packet
,
113 int type
, size_t optoffset
);
115 void client_id_hash_func(const DHCPClientId
*p
, struct siphash
*state
);
116 int client_id_compare_func(const DHCPClientId
*a
, const DHCPClientId
*b
);
118 #define log_dhcp_server_errno(server, error, fmt, ...) \
119 log_interface_prefix_full_errno( \
121 sd_dhcp_server, server, \
122 error, fmt, ##__VA_ARGS__)
123 #define log_dhcp_server(server, fmt, ...) \
124 log_interface_prefix_full_errno_zerook( \
126 sd_dhcp_server, server, \
127 0, fmt, ##__VA_ARGS__)