2017-11-18 17:09:20 +01:00
|
|
|
/* SPDX-License-Identifier: LGPL-2.1+ */
|
2016-02-16 20:05:15 +01:00
|
|
|
#pragma once
|
|
|
|
|
2014-05-24 18:48:41 +02:00
|
|
|
/***
|
2018-06-12 17:15:23 +02:00
|
|
|
Copyright © 2013 Intel Corporation. All rights reserved.
|
2014-05-24 18:48:41 +02:00
|
|
|
***/
|
|
|
|
|
|
|
|
#include "sd-dhcp-server.h"
|
2015-11-18 22:46:33 +01:00
|
|
|
#include "sd-event.h"
|
2014-05-24 18:48:41 +02:00
|
|
|
|
2015-11-18 22:46:33 +01:00
|
|
|
#include "dhcp-internal.h"
|
2014-05-25 22:07:53 +02:00
|
|
|
#include "hashmap.h"
|
2014-05-24 18:48:41 +02:00
|
|
|
#include "log.h"
|
2019-03-27 11:32:41 +01:00
|
|
|
#include "time-util.h"
|
2014-05-24 21:04:27 +02:00
|
|
|
|
2019-09-20 04:22:17 +02:00
|
|
|
typedef enum DHCPRawOption {
|
|
|
|
DHCP_RAW_OPTION_DATA_UINT8,
|
|
|
|
DHCP_RAW_OPTION_DATA_UINT16,
|
|
|
|
DHCP_RAW_OPTION_DATA_UINT32,
|
|
|
|
DHCP_RAW_OPTION_DATA_STRING,
|
|
|
|
DHCP_RAW_OPTION_DATA_IPV4ADDRESS,
|
2020-05-01 16:30:31 +02:00
|
|
|
DHCP_RAW_OPTION_DATA_IPV6ADDRESS,
|
2019-09-20 04:22:17 +02:00
|
|
|
_DHCP_RAW_OPTION_DATA_MAX,
|
|
|
|
_DHCP_RAW_OPTION_DATA_INVALID,
|
|
|
|
} DHCPRawOption;
|
|
|
|
|
2014-05-25 22:07:53 +02:00
|
|
|
typedef struct DHCPClientId {
|
|
|
|
size_t length;
|
2015-08-26 23:30:27 +02:00
|
|
|
void *data;
|
2014-05-25 22:07:53 +02:00
|
|
|
} DHCPClientId;
|
|
|
|
|
|
|
|
typedef struct DHCPLease {
|
|
|
|
DHCPClientId client_id;
|
|
|
|
|
|
|
|
be32_t address;
|
2014-07-26 19:12:24 +02:00
|
|
|
be32_t gateway;
|
|
|
|
uint8_t chaddr[16];
|
2014-05-25 22:07:53 +02:00
|
|
|
usec_t expiration;
|
|
|
|
} DHCPLease;
|
|
|
|
|
2014-05-24 18:48:41 +02:00
|
|
|
struct sd_dhcp_server {
|
2015-08-26 21:05:53 +02:00
|
|
|
unsigned n_ref;
|
2014-05-24 18:48:41 +02:00
|
|
|
|
|
|
|
sd_event *event;
|
|
|
|
int event_priority;
|
2014-05-24 19:27:20 +02:00
|
|
|
sd_event_source *receive_message;
|
|
|
|
int fd;
|
2014-05-24 23:03:49 +02:00
|
|
|
int fd_raw;
|
2014-05-24 19:38:17 +02:00
|
|
|
|
2015-08-26 23:31:47 +02:00
|
|
|
int ifindex;
|
2014-05-25 00:29:13 +02:00
|
|
|
be32_t address;
|
2014-08-04 20:57:02 +02:00
|
|
|
be32_t netmask;
|
2015-08-28 20:29:10 +02:00
|
|
|
be32_t subnet;
|
|
|
|
uint32_t pool_offset;
|
|
|
|
uint32_t pool_size;
|
2014-05-24 18:48:41 +02:00
|
|
|
|
2015-08-26 19:19:32 +02:00
|
|
|
char *timezone;
|
|
|
|
|
2020-05-29 11:26:24 +02:00
|
|
|
DHCPServerData servers[_SD_DHCP_LEASE_SERVER_TYPE_MAX];
|
2015-08-27 14:48:37 +02:00
|
|
|
|
2020-02-28 19:28:49 +01:00
|
|
|
OrderedHashmap *extra_options;
|
|
|
|
OrderedHashmap *vendor_options;
|
2019-09-20 04:22:17 +02:00
|
|
|
|
2016-05-18 01:34:25 +02:00
|
|
|
bool emit_router;
|
|
|
|
|
2014-05-25 22:07:53 +02:00
|
|
|
Hashmap *leases_by_client_id;
|
|
|
|
DHCPLease **bound_leases;
|
2015-08-28 20:29:10 +02:00
|
|
|
DHCPLease invalid_lease;
|
2015-08-27 01:47:42 +02:00
|
|
|
|
|
|
|
uint32_t max_lease_time, default_lease_time;
|
2020-05-22 11:33:36 +02:00
|
|
|
|
|
|
|
sd_dhcp_server_callback_t callback;
|
|
|
|
void *callback_userdata;
|
2014-05-25 22:07:53 +02:00
|
|
|
};
|
2014-05-24 22:14:32 +02:00
|
|
|
|
|
|
|
typedef struct DHCPRequest {
|
|
|
|
/* received message */
|
|
|
|
DHCPMessage *message;
|
|
|
|
|
|
|
|
/* options */
|
|
|
|
DHCPClientId client_id;
|
|
|
|
size_t max_optlen;
|
|
|
|
be32_t server_id;
|
2014-05-25 18:28:03 +02:00
|
|
|
be32_t requested_ip;
|
2015-08-27 01:47:42 +02:00
|
|
|
uint32_t lifetime;
|
2014-05-24 22:14:32 +02:00
|
|
|
} DHCPRequest;
|
|
|
|
|
2019-06-07 15:00:47 +02:00
|
|
|
#define log_dhcp_server(client, fmt, ...) log_internal(LOG_DEBUG, 0, PROJECT_FILE, __LINE__, __func__, "DHCP SERVER: " fmt, ##__VA_ARGS__)
|
|
|
|
#define log_dhcp_server_errno(client, error, fmt, ...) log_internal(LOG_DEBUG, error, PROJECT_FILE, __LINE__, __func__, "DHCP SERVER: " fmt, ##__VA_ARGS__)
|
2014-05-24 21:04:27 +02:00
|
|
|
|
|
|
|
int dhcp_server_handle_message(sd_dhcp_server *server, DHCPMessage *message,
|
|
|
|
size_t length);
|
2014-05-25 17:20:57 +02:00
|
|
|
int dhcp_server_send_packet(sd_dhcp_server *server,
|
|
|
|
DHCPRequest *req, DHCPPacket *packet,
|
|
|
|
int type, size_t optoffset);
|
2014-05-25 22:07:53 +02:00
|
|
|
|
2018-11-27 14:25:20 +01:00
|
|
|
void client_id_hash_func(const DHCPClientId *p, struct siphash *state);
|
|
|
|
int client_id_compare_func(const DHCPClientId *a, const DHCPClientId *b);
|