]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/libsystemd-network/dhcp-server-internal.h
Merge pull request #16057 from keszybz/resolvectl-sorted-no-nta
[thirdparty/systemd.git] / src / libsystemd-network / dhcp-server-internal.h
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
0ef6f454
LP
2#pragma once
3
b44cd882 4/***
810adae9 5 Copyright © 2013 Intel Corporation. All rights reserved.
b44cd882
TG
6***/
7
b44cd882 8#include "sd-dhcp-server.h"
71d35b6b 9#include "sd-event.h"
b44cd882 10
71d35b6b 11#include "dhcp-internal.h"
87322b3a 12#include "hashmap.h"
b44cd882 13#include "log.h"
ca78ad1d 14#include "time-util.h"
be077570 15
564ca984
SS
16typedef 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,
e7d5fe17 22 DHCP_RAW_OPTION_DATA_IPV6ADDRESS,
564ca984
SS
23 _DHCP_RAW_OPTION_DATA_MAX,
24 _DHCP_RAW_OPTION_DATA_INVALID,
25} DHCPRawOption;
26
87322b3a
TG
27typedef struct DHCPClientId {
28 size_t length;
9a0f246f 29 void *data;
87322b3a
TG
30} DHCPClientId;
31
32typedef struct DHCPLease {
33 DHCPClientId client_id;
34
35 be32_t address;
52750344
TG
36 be32_t gateway;
37 uint8_t chaddr[16];
87322b3a
TG
38 usec_t expiration;
39} DHCPLease;
40
b44cd882 41struct sd_dhcp_server {
3733eec3 42 unsigned n_ref;
b44cd882
TG
43
44 sd_event *event;
45 int event_priority;
ff734080
TG
46 sd_event_source *receive_message;
47 int fd;
8de4a226 48 int fd_raw;
3a864fe4 49
b3ec603c 50 int ifindex;
20af7091 51 be32_t address;
59b8f6b6 52 be32_t netmask;
99634696
TG
53 be32_t subnet;
54 uint32_t pool_offset;
55 uint32_t pool_size;
b44cd882 56
8eb9058d
LP
57 char *timezone;
58
ddb82ec2 59 DHCPServerData servers[_SD_DHCP_LEASE_SERVER_TYPE_MAX];
1a04db0f 60
7354900d
DW
61 OrderedHashmap *extra_options;
62 OrderedHashmap *vendor_options;
564ca984 63
77ff6022
CG
64 bool emit_router;
65
87322b3a
TG
66 Hashmap *leases_by_client_id;
67 DHCPLease **bound_leases;
99634696 68 DHCPLease invalid_lease;
586ac6f7
LP
69
70 uint32_t max_lease_time, default_lease_time;
87322b3a 71};
816e2e7a
TG
72
73typedef struct DHCPRequest {
74 /* received message */
75 DHCPMessage *message;
76
77 /* options */
78 DHCPClientId client_id;
79 size_t max_optlen;
80 be32_t server_id;
2dead812 81 be32_t requested_ip;
586ac6f7 82 uint32_t lifetime;
816e2e7a
TG
83} DHCPRequest;
84
62c6bbbc
ZJS
85#define log_dhcp_server(client, fmt, ...) log_internal(LOG_DEBUG, 0, PROJECT_FILE, __LINE__, __func__, "DHCP SERVER: " fmt, ##__VA_ARGS__)
86#define log_dhcp_server_errno(client, error, fmt, ...) log_internal(LOG_DEBUG, error, PROJECT_FILE, __LINE__, __func__, "DHCP SERVER: " fmt, ##__VA_ARGS__)
be077570
TG
87
88int dhcp_server_handle_message(sd_dhcp_server *server, DHCPMessage *message,
89 size_t length);
969b009d
TG
90int dhcp_server_send_packet(sd_dhcp_server *server,
91 DHCPRequest *req, DHCPPacket *packet,
92 int type, size_t optoffset);
87322b3a 93
7a08d314
YW
94void client_id_hash_func(const DHCPClientId *p, struct siphash *state);
95int client_id_compare_func(const DHCPClientId *a, const DHCPClientId *b);