]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/libsystemd-network/dhcp-server-internal.h
Add SPDX license identifiers to source files under the LGPL
[thirdparty/systemd.git] / src / libsystemd-network / dhcp-server-internal.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
4 /***
5 This file is part of systemd.
6
7 Copyright (C) 2013 Intel Corporation. All rights reserved.
8 Copyright (C) 2014 Tom Gundersen
9
10 systemd is free software; you can redistribute it and/or modify it
11 under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14
15 systemd is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
19
20 You should have received a copy of the GNU Lesser General Public License
21 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 ***/
23
24 #include "sd-dhcp-server.h"
25 #include "sd-event.h"
26
27 #include "dhcp-internal.h"
28 #include "hashmap.h"
29 #include "log.h"
30 #include "util.h"
31
32 typedef struct DHCPClientId {
33 size_t length;
34 void *data;
35 } DHCPClientId;
36
37 typedef struct DHCPLease {
38 DHCPClientId client_id;
39
40 be32_t address;
41 be32_t gateway;
42 uint8_t chaddr[16];
43 usec_t expiration;
44 } DHCPLease;
45
46 struct sd_dhcp_server {
47 unsigned n_ref;
48
49 sd_event *event;
50 int event_priority;
51 sd_event_source *receive_message;
52 int fd;
53 int fd_raw;
54
55 int ifindex;
56 be32_t address;
57 be32_t netmask;
58 be32_t subnet;
59 uint32_t pool_offset;
60 uint32_t pool_size;
61
62 char *timezone;
63
64 struct in_addr *ntp, *dns;
65 unsigned n_ntp, n_dns;
66
67 bool emit_router;
68
69 Hashmap *leases_by_client_id;
70 DHCPLease **bound_leases;
71 DHCPLease invalid_lease;
72
73 uint32_t max_lease_time, default_lease_time;
74 };
75
76 typedef struct DHCPRequest {
77 /* received message */
78 DHCPMessage *message;
79
80 /* options */
81 DHCPClientId client_id;
82 size_t max_optlen;
83 be32_t server_id;
84 be32_t requested_ip;
85 uint32_t lifetime;
86 } DHCPRequest;
87
88 #define log_dhcp_server(client, fmt, ...) log_internal(LOG_DEBUG, 0, __FILE__, __LINE__, __func__, "DHCP SERVER: " fmt, ##__VA_ARGS__)
89
90 int dhcp_server_handle_message(sd_dhcp_server *server, DHCPMessage *message,
91 size_t length);
92 int dhcp_server_send_packet(sd_dhcp_server *server,
93 DHCPRequest *req, DHCPPacket *packet,
94 int type, size_t optoffset);
95
96 void client_id_hash_func(const void *p, struct siphash *state);
97 int client_id_compare_func(const void *_a, const void *_b);