]> git.proxmox.com Git - systemd.git/blame - src/libsystemd-network/dhcp-server-internal.h
Imported Upstream version 226
[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
e735f4d4
MP
23#pragma once
24
e842803a
MB
25#include "sd-event.h"
26#include "sd-dhcp-server.h"
27
28#include "hashmap.h"
e842803a
MB
29#include "util.h"
30#include "log.h"
31
32#include "dhcp-internal.h"
33
34typedef struct DHCPClientId {
35 size_t length;
d9dfd233 36 void *data;
e842803a
MB
37} DHCPClientId;
38
39typedef struct DHCPLease {
40 DHCPClientId client_id;
41
42 be32_t address;
5eef597e
MP
43 be32_t gateway;
44 uint8_t chaddr[16];
e842803a
MB
45 usec_t expiration;
46} DHCPLease;
47
48struct sd_dhcp_server {
d9dfd233 49 unsigned n_ref;
e842803a
MB
50
51 sd_event *event;
52 int event_priority;
53 sd_event_source *receive_message;
54 int fd;
55 int fd_raw;
56
d9dfd233 57 int ifindex;
e842803a 58 be32_t address;
5eef597e 59 be32_t netmask;
d9dfd233
MP
60 be32_t subnet;
61 uint32_t pool_offset;
62 uint32_t pool_size;
63
64 char *timezone;
65
66 struct in_addr *ntp, *dns;
67 unsigned n_ntp, n_dns;
e842803a
MB
68
69 Hashmap *leases_by_client_id;
70 DHCPLease **bound_leases;
d9dfd233
MP
71 DHCPLease invalid_lease;
72
73 uint32_t max_lease_time, default_lease_time;
e842803a
MB
74};
75
76typedef 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;
84 be32_t requested_ip;
d9dfd233 85 uint32_t lifetime;
e842803a
MB
86} DHCPRequest;
87
88DEFINE_TRIVIAL_CLEANUP_FUNC(sd_dhcp_server*, sd_dhcp_server_unref);
89#define _cleanup_dhcp_server_unref_ _cleanup_(sd_dhcp_server_unrefp)
90
f47781d8 91#define log_dhcp_server(client, fmt, ...) log_internal(LOG_DEBUG, 0, __FILE__, __LINE__, __func__, "DHCP SERVER: " fmt, ##__VA_ARGS__)
e842803a
MB
92
93int dhcp_server_handle_message(sd_dhcp_server *server, DHCPMessage *message,
94 size_t length);
95int dhcp_server_send_packet(sd_dhcp_server *server,
96 DHCPRequest *req, DHCPPacket *packet,
97 int type, size_t optoffset);
98
99unsigned long client_id_hash_func(const void *p, const uint8_t hash_key[HASH_KEY_SIZE]);
100int client_id_compare_func(const void *_a, const void *_b);