]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/libsystemd-network/dhcp-server-internal.h
log: be a bit less wasteful when allocating buffers
[thirdparty/systemd.git] / src / libsystemd-network / dhcp-server-internal.h
CommitLineData
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
23#include "sd-event.h"
24#include "sd-dhcp-server.h"
25
87322b3a 26#include "hashmap.h"
b44cd882
TG
27#include "refcnt.h"
28#include "util.h"
29#include "log.h"
30
be077570
TG
31#include "dhcp-internal.h"
32
87322b3a
TG
33typedef struct DHCPClientId {
34 size_t length;
35 uint8_t *data;
36} DHCPClientId;
37
38typedef struct DHCPLease {
39 DHCPClientId client_id;
40
41 be32_t address;
52750344
TG
42 be32_t gateway;
43 uint8_t chaddr[16];
87322b3a
TG
44 usec_t expiration;
45} DHCPLease;
46
b44cd882
TG
47struct sd_dhcp_server {
48 RefCount n_ref;
49
50 sd_event *event;
51 int event_priority;
ff734080
TG
52 sd_event_source *receive_message;
53 int fd;
8de4a226 54 int fd_raw;
3a864fe4
TG
55
56 int index;
20af7091 57 be32_t address;
59b8f6b6 58 be32_t netmask;
2dead812
TG
59 be32_t pool_start;
60 size_t pool_size;
87322b3a 61 size_t next_offer;
b44cd882 62
87322b3a
TG
63 Hashmap *leases_by_client_id;
64 DHCPLease **bound_leases;
65};
816e2e7a
TG
66
67typedef struct DHCPRequest {
68 /* received message */
69 DHCPMessage *message;
70
71 /* options */
72 DHCPClientId client_id;
73 size_t max_optlen;
74 be32_t server_id;
2dead812 75 be32_t requested_ip;
c7d9ffe6 76 int lifetime;
816e2e7a
TG
77} DHCPRequest;
78
b44cd882
TG
79DEFINE_TRIVIAL_CLEANUP_FUNC(sd_dhcp_server*, sd_dhcp_server_unref);
80#define _cleanup_dhcp_server_unref_ _cleanup_(sd_dhcp_server_unrefp)
81
086891e5 82#define log_dhcp_server(client, fmt, ...) log_meta(LOG_DEBUG, 0, __FILE__, __LINE__, __func__, "DHCP SERVER: " fmt, ##__VA_ARGS__)
be077570
TG
83
84int dhcp_server_handle_message(sd_dhcp_server *server, DHCPMessage *message,
85 size_t length);
969b009d
TG
86int dhcp_server_send_packet(sd_dhcp_server *server,
87 DHCPRequest *req, DHCPPacket *packet,
88 int type, size_t optoffset);
87322b3a
TG
89
90unsigned long client_id_hash_func(const void *p, const uint8_t hash_key[HASH_KEY_SIZE]);
91int client_id_compare_func(const void *_a, const void *_b);