]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/libsystemd-network/dhcp-server-internal.h
libsystemd-network: introduce sd_xxx_{set,get}_ifname()
[thirdparty/systemd.git] / src / libsystemd-network / dhcp-server-internal.h
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3
4 /***
5 Copyright © 2013 Intel Corporation. All rights reserved.
6 ***/
7
8 #include "sd-dhcp-server.h"
9 #include "sd-event.h"
10
11 #include "dhcp-internal.h"
12 #include "ordered-set.h"
13 #include "log.h"
14 #include "time-util.h"
15
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,
25 } DHCPRawOption;
26
27 typedef struct DHCPClientId {
28 size_t length;
29 void *data;
30 } DHCPClientId;
31
32 typedef struct DHCPLease {
33 DHCPClientId client_id;
34
35 be32_t address;
36 be32_t gateway;
37 uint8_t chaddr[16];
38 usec_t expiration;
39 } DHCPLease;
40
41 struct sd_dhcp_server {
42 unsigned n_ref;
43
44 sd_event *event;
45 int event_priority;
46 sd_event_source *receive_message;
47 int fd;
48 int fd_raw;
49
50 int ifindex;
51 char *ifname;
52 be32_t address;
53 be32_t netmask;
54 be32_t subnet;
55 uint32_t pool_offset;
56 uint32_t pool_size;
57
58 char *timezone;
59
60 DHCPServerData servers[_SD_DHCP_LEASE_SERVER_TYPE_MAX];
61
62 OrderedSet *extra_options;
63 OrderedSet *vendor_options;
64
65 bool emit_router;
66
67 Hashmap *leases_by_client_id;
68 DHCPLease **bound_leases;
69 DHCPLease invalid_lease;
70
71 uint32_t max_lease_time, default_lease_time;
72
73 sd_dhcp_server_callback_t callback;
74 void *callback_userdata;
75 };
76
77 typedef struct DHCPRequest {
78 /* received message */
79 DHCPMessage *message;
80
81 /* options */
82 DHCPClientId client_id;
83 size_t max_optlen;
84 be32_t server_id;
85 be32_t requested_ip;
86 uint32_t lifetime;
87 } DHCPRequest;
88
89 #define log_dhcp_server(client, fmt, ...) log_internal(LOG_DEBUG, 0, PROJECT_FILE, __LINE__, __func__, "DHCP SERVER: " fmt, ##__VA_ARGS__)
90 #define log_dhcp_server_errno(client, error, fmt, ...) log_internal(LOG_DEBUG, error, PROJECT_FILE, __LINE__, __func__, "DHCP SERVER: " fmt, ##__VA_ARGS__)
91
92 int dhcp_server_handle_message(sd_dhcp_server *server, DHCPMessage *message,
93 size_t length);
94 int dhcp_server_send_packet(sd_dhcp_server *server,
95 DHCPRequest *req, DHCPPacket *packet,
96 int type, size_t optoffset);
97
98 void client_id_hash_func(const DHCPClientId *p, struct siphash *state);
99 int client_id_compare_func(const DHCPClientId *a, const DHCPClientId *b);