]>
Commit | Line | Data |
---|---|---|
b44cd882 TG |
1 | /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ |
2 | ||
3 | /*** | |
4 | This file is part of systemd. | |
5 | ||
6 | Copyright (C) 2013 Intel Corporation. All rights reserved. | |
7 | Copyright (C) 2014 Tom Gundersen | |
8 | ||
9 | systemd is free software; you can redistribute it and/or modify it | |
10 | under the terms of the GNU Lesser General Public License as published by | |
11 | the Free Software Foundation; either version 2.1 of the License, or | |
12 | (at your option) any later version. | |
13 | ||
14 | systemd is distributed in the hope that it will be useful, but | |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
17 | Lesser General Public License for more details. | |
18 | ||
19 | You should have received a copy of the GNU Lesser General Public License | |
20 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
21 | ***/ | |
22 | ||
c9403dce ZJS |
23 | #pragma once |
24 | ||
b44cd882 TG |
25 | #include "sd-event.h" |
26 | #include "sd-dhcp-server.h" | |
27 | ||
87322b3a | 28 | #include "hashmap.h" |
b44cd882 TG |
29 | #include "util.h" |
30 | #include "log.h" | |
31 | ||
be077570 TG |
32 | #include "dhcp-internal.h" |
33 | ||
87322b3a TG |
34 | typedef struct DHCPClientId { |
35 | size_t length; | |
9a0f246f | 36 | void *data; |
87322b3a TG |
37 | } DHCPClientId; |
38 | ||
39 | typedef struct DHCPLease { | |
40 | DHCPClientId client_id; | |
41 | ||
42 | be32_t address; | |
52750344 TG |
43 | be32_t gateway; |
44 | uint8_t chaddr[16]; | |
87322b3a TG |
45 | usec_t expiration; |
46 | } DHCPLease; | |
47 | ||
b44cd882 | 48 | struct sd_dhcp_server { |
3733eec3 | 49 | unsigned n_ref; |
b44cd882 TG |
50 | |
51 | sd_event *event; | |
52 | int event_priority; | |
ff734080 TG |
53 | sd_event_source *receive_message; |
54 | int fd; | |
8de4a226 | 55 | int fd_raw; |
3a864fe4 | 56 | |
b3ec603c | 57 | int ifindex; |
20af7091 | 58 | be32_t address; |
59b8f6b6 | 59 | be32_t netmask; |
99634696 TG |
60 | be32_t subnet; |
61 | uint32_t pool_offset; | |
62 | uint32_t pool_size; | |
b44cd882 | 63 | |
8eb9058d LP |
64 | char *timezone; |
65 | ||
1a04db0f LP |
66 | struct in_addr *ntp, *dns; |
67 | unsigned n_ntp, n_dns; | |
68 | ||
87322b3a TG |
69 | Hashmap *leases_by_client_id; |
70 | DHCPLease **bound_leases; | |
99634696 | 71 | DHCPLease invalid_lease; |
586ac6f7 LP |
72 | |
73 | uint32_t max_lease_time, default_lease_time; | |
87322b3a | 74 | }; |
816e2e7a TG |
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; | |
2dead812 | 84 | be32_t requested_ip; |
586ac6f7 | 85 | uint32_t lifetime; |
816e2e7a TG |
86 | } DHCPRequest; |
87 | ||
b44cd882 TG |
88 | DEFINE_TRIVIAL_CLEANUP_FUNC(sd_dhcp_server*, sd_dhcp_server_unref); |
89 | #define _cleanup_dhcp_server_unref_ _cleanup_(sd_dhcp_server_unrefp) | |
90 | ||
79008bdd | 91 | #define log_dhcp_server(client, fmt, ...) log_internal(LOG_DEBUG, 0, __FILE__, __LINE__, __func__, "DHCP SERVER: " fmt, ##__VA_ARGS__) |
be077570 TG |
92 | |
93 | int dhcp_server_handle_message(sd_dhcp_server *server, DHCPMessage *message, | |
94 | size_t length); | |
969b009d TG |
95 | int dhcp_server_send_packet(sd_dhcp_server *server, |
96 | DHCPRequest *req, DHCPPacket *packet, | |
97 | int type, size_t optoffset); | |
87322b3a | 98 | |
b826ab58 | 99 | void client_id_hash_func(const void *p, struct siphash *state); |
87322b3a | 100 | int client_id_compare_func(const void *_a, const void *_b); |