]>
Commit | Line | Data |
---|---|---|
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" |
5977b71f | 12 | #include "network-common.h" |
ebffea2a | 13 | #include "ordered-set.h" |
ca78ad1d | 14 | #include "time-util.h" |
be077570 | 15 | |
564ca984 SS |
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, | |
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 |
27 | typedef struct DHCPClientId { |
28 | size_t length; | |
2cb66bbd | 29 | uint8_t *data; |
87322b3a TG |
30 | } DHCPClientId; |
31 | ||
32 | typedef struct DHCPLease { | |
b713a99b YW |
33 | sd_dhcp_server *server; |
34 | ||
87322b3a TG |
35 | DHCPClientId client_id; |
36 | ||
54d95d02 YW |
37 | uint8_t htype; /* e.g. ARPHRD_ETHER */ |
38 | uint8_t hlen; /* e.g. ETH_ALEN */ | |
87322b3a | 39 | be32_t address; |
52750344 TG |
40 | be32_t gateway; |
41 | uint8_t chaddr[16]; | |
87322b3a | 42 | usec_t expiration; |
930133d5 | 43 | char *hostname; |
87322b3a TG |
44 | } DHCPLease; |
45 | ||
b44cd882 | 46 | struct sd_dhcp_server { |
3733eec3 | 47 | unsigned n_ref; |
b44cd882 TG |
48 | |
49 | sd_event *event; | |
50 | int event_priority; | |
ff734080 | 51 | sd_event_source *receive_message; |
21b6b87e | 52 | sd_event_source *receive_broadcast; |
ff734080 | 53 | int fd; |
8de4a226 | 54 | int fd_raw; |
21b6b87e | 55 | int fd_broadcast; |
3a864fe4 | 56 | |
b3ec603c | 57 | int ifindex; |
61a9fa8f | 58 | char *ifname; |
21b6b87e | 59 | bool bind_to_interface; |
20af7091 | 60 | be32_t address; |
59b8f6b6 | 61 | be32_t netmask; |
99634696 TG |
62 | be32_t subnet; |
63 | uint32_t pool_offset; | |
64 | uint32_t pool_size; | |
b44cd882 | 65 | |
8eb9058d LP |
66 | char *timezone; |
67 | ||
ddb82ec2 | 68 | DHCPServerData servers[_SD_DHCP_LEASE_SERVER_TYPE_MAX]; |
6278e428 YW |
69 | struct in_addr boot_server_address; |
70 | char *boot_server_name; | |
71 | char *boot_filename; | |
1a04db0f | 72 | |
ebffea2a SS |
73 | OrderedSet *extra_options; |
74 | OrderedSet *vendor_options; | |
564ca984 | 75 | |
77ff6022 | 76 | bool emit_router; |
59aa6220 | 77 | struct in_addr router_address; |
77ff6022 | 78 | |
b713a99b YW |
79 | Hashmap *bound_leases_by_client_id; |
80 | Hashmap *bound_leases_by_address; | |
65a0ef23 | 81 | Hashmap *static_leases_by_client_id; |
b713a99b | 82 | Hashmap *static_leases_by_address; |
586ac6f7 | 83 | |
a0007611 YW |
84 | usec_t max_lease_time; |
85 | usec_t default_lease_time; | |
14bd102e | 86 | usec_t ipv6_only_preferred_usec; |
5b03043a MAL |
87 | |
88 | sd_dhcp_server_callback_t callback; | |
89 | void *callback_userdata; | |
11c38d3e YA |
90 | |
91 | struct in_addr relay_target; | |
92 | ||
93 | char *agent_circuit_id; | |
94 | char *agent_remote_id; | |
87322b3a | 95 | }; |
816e2e7a TG |
96 | |
97 | typedef struct DHCPRequest { | |
98 | /* received message */ | |
99 | DHCPMessage *message; | |
100 | ||
101 | /* options */ | |
102 | DHCPClientId client_id; | |
103 | size_t max_optlen; | |
104 | be32_t server_id; | |
2dead812 | 105 | be32_t requested_ip; |
a0007611 | 106 | usec_t lifetime; |
11c38d3e | 107 | const uint8_t *agent_info_option; |
930133d5 | 108 | char *hostname; |
14bd102e SS |
109 | const uint8_t *parameter_request_list; |
110 | size_t parameter_request_list_len; | |
816e2e7a TG |
111 | } DHCPRequest; |
112 | ||
cedf6a8d YW |
113 | extern const struct hash_ops dhcp_lease_hash_ops; |
114 | ||
be077570 TG |
115 | int dhcp_server_handle_message(sd_dhcp_server *server, DHCPMessage *message, |
116 | size_t length); | |
969b009d TG |
117 | int dhcp_server_send_packet(sd_dhcp_server *server, |
118 | DHCPRequest *req, DHCPPacket *packet, | |
119 | int type, size_t optoffset); | |
87322b3a | 120 | |
7a08d314 YW |
121 | void client_id_hash_func(const DHCPClientId *p, struct siphash *state); |
122 | int client_id_compare_func(const DHCPClientId *a, const DHCPClientId *b); | |
35388783 | 123 | |
aca607d1 FS |
124 | DHCPLease *dhcp_lease_free(DHCPLease *lease); |
125 | DEFINE_TRIVIAL_CLEANUP_FUNC(DHCPLease*, dhcp_lease_free); | |
126 | ||
a0c2541b | 127 | #define log_dhcp_server_errno(server, error, fmt, ...) \ |
00dd6d77 | 128 | log_interface_prefix_full_errno( \ |
a0c2541b | 129 | "DHCPv4 server: ", \ |
5977b71f | 130 | sd_dhcp_server, server, \ |
a0c2541b | 131 | error, fmt, ##__VA_ARGS__) |
35388783 | 132 | #define log_dhcp_server(server, fmt, ...) \ |
00dd6d77 ZJS |
133 | log_interface_prefix_full_errno_zerook( \ |
134 | "DHCPv4 server: ", \ | |
5977b71f | 135 | sd_dhcp_server, server, \ |
00dd6d77 | 136 | 0, fmt, ##__VA_ARGS__) |