]> git.proxmox.com Git - systemd.git/blame - src/libsystemd-network/dhcp-server-internal.h
Imported Upstream version 217
[systemd.git] / src / libsystemd-network / dhcp-server-internal.h
CommitLineData
e842803a
MB
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
26#include "hashmap.h"
27#include "refcnt.h"
28#include "util.h"
29#include "log.h"
30
31#include "dhcp-internal.h"
32
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;
5eef597e
MP
42 be32_t gateway;
43 uint8_t chaddr[16];
e842803a
MB
44 usec_t expiration;
45} DHCPLease;
46
47struct sd_dhcp_server {
48 RefCount n_ref;
49
50 sd_event *event;
51 int event_priority;
52 sd_event_source *receive_message;
53 int fd;
54 int fd_raw;
55
56 int index;
57 be32_t address;
5eef597e 58 be32_t netmask;
e842803a
MB
59 be32_t pool_start;
60 size_t pool_size;
61 size_t next_offer;
62
63 Hashmap *leases_by_client_id;
64 DHCPLease **bound_leases;
65};
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;
75 be32_t requested_ip;
76 int lifetime;
77} DHCPRequest;
78
79DEFINE_TRIVIAL_CLEANUP_FUNC(sd_dhcp_server*, sd_dhcp_server_unref);
80#define _cleanup_dhcp_server_unref_ _cleanup_(sd_dhcp_server_unrefp)
81
82#define log_dhcp_server(client, fmt, ...) log_meta(LOG_DEBUG, __FILE__, __LINE__, __func__, "DHCP SERVER: " fmt, ##__VA_ARGS__)
83
84int dhcp_server_handle_message(sd_dhcp_server *server, DHCPMessage *message,
85 size_t length);
86int dhcp_server_send_packet(sd_dhcp_server *server,
87 DHCPRequest *req, DHCPPacket *packet,
88 int type, size_t optoffset);
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);