]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/libsystemd-network/dhcp-server-internal.h
dhcp: Implemented BindToInterface= configuration option
[thirdparty/systemd.git] / src / libsystemd-network / dhcp-server-internal.h
CommitLineData
db9ecf05 1/* SPDX-License-Identifier: LGPL-2.1-or-later */
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"
ebffea2a 12#include "ordered-set.h"
35388783 13#include "log-link.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 46 sd_event_source *receive_message;
21b6b87e 47 sd_event_source *receive_broadcast;
ff734080 48 int fd;
8de4a226 49 int fd_raw;
21b6b87e 50 int fd_broadcast;
3a864fe4 51
b3ec603c 52 int ifindex;
61a9fa8f 53 char *ifname;
21b6b87e 54 bool bind_to_interface;
20af7091 55 be32_t address;
59b8f6b6 56 be32_t netmask;
99634696
TG
57 be32_t subnet;
58 uint32_t pool_offset;
59 uint32_t pool_size;
b44cd882 60
8eb9058d
LP
61 char *timezone;
62
ddb82ec2 63 DHCPServerData servers[_SD_DHCP_LEASE_SERVER_TYPE_MAX];
1a04db0f 64
ebffea2a
SS
65 OrderedSet *extra_options;
66 OrderedSet *vendor_options;
564ca984 67
77ff6022
CG
68 bool emit_router;
69
87322b3a
TG
70 Hashmap *leases_by_client_id;
71 DHCPLease **bound_leases;
99634696 72 DHCPLease invalid_lease;
586ac6f7
LP
73
74 uint32_t max_lease_time, default_lease_time;
5b03043a
MAL
75
76 sd_dhcp_server_callback_t callback;
77 void *callback_userdata;
87322b3a 78};
816e2e7a
TG
79
80typedef struct DHCPRequest {
81 /* received message */
82 DHCPMessage *message;
83
84 /* options */
85 DHCPClientId client_id;
86 size_t max_optlen;
87 be32_t server_id;
2dead812 88 be32_t requested_ip;
586ac6f7 89 uint32_t lifetime;
816e2e7a
TG
90} DHCPRequest;
91
be077570
TG
92int dhcp_server_handle_message(sd_dhcp_server *server, DHCPMessage *message,
93 size_t length);
969b009d
TG
94int dhcp_server_send_packet(sd_dhcp_server *server,
95 DHCPRequest *req, DHCPPacket *packet,
96 int type, size_t optoffset);
87322b3a 97
7a08d314
YW
98void client_id_hash_func(const DHCPClientId *p, struct siphash *state);
99int client_id_compare_func(const DHCPClientId *a, const DHCPClientId *b);
35388783
YW
100
101#define log_dhcp_server_errno(server, error, fmt, ...) \
102 ({ \
103 int _e = (error); \
104 if (DEBUG_LOGGING) \
105 log_interface_full_errno( \
106 sd_dhcp_server_get_ifname(server), \
107 LOG_DEBUG, _e, "DHCPv4 server: " fmt, \
108 ##__VA_ARGS__); \
109 -ERRNO_VALUE(_e); \
110 })
111#define log_dhcp_server(server, fmt, ...) \
112 log_dhcp_server_errno(server, 0, fmt, ##__VA_ARGS__)