![Susant Sahani](/assets/img/avatar_default.png)
Implementes https://tools.ietf.org/html/rfc2132 ``` [DHCPServer] SendRawOption=26:uint32:1400 SendRawOption=23:uint8:10 ``` Frame 448: 350 bytes on wire (2800 bits), 350 bytes captured (2800 bits) on interface 0 Linux cooked capture Internet Protocol Version 4, Src: 192.168.5.1, Dst: 192.168.5.11 User Datagram Protocol, Src Port: 67, Dst Port: 68 Dynamic Host Configuration Protocol (ACK) Message type: Boot Reply (2) Hardware type: Ethernet (0x01) Hardware address length: 6 Hops: 0 Transaction ID: 0x71f8de9d Seconds elapsed: 0 Bootp flags: 0x0000 (Unicast) Client IP address: 0.0.0.0 Your (client) IP address: 192.168.5.11 Next server IP address: 0.0.0.0 Relay agent IP address: 0.0.0.0 Client MAC address: 1e:04:f8:b8:2f:d4 (1e:04:f8:b8:2f:d4) Client hardware address padding: 00000000000000000000 Server host name not given Boot file name not given Magic cookie: DHCP Option: (53) DHCP Message Type (ACK) Length: 1 DHCP: ACK (5) Option: (51) IP Address Lease Time Length: 4 IP Address Lease Time: (3600s) 1 hour Option: (1) Subnet Mask (255.255.255.0) Length: 4 Subnet Mask: 255.255.255.0 Option: (3) Router Length: 4 Router: 192.168.5.1 Option: (6) Domain Name Server Length: 4 Domain Name Server: 192.168.5.1 Option: (42) Network Time Protocol Servers Length: 4 Network Time Protocol Server: 192.168.5.1 Option: (101) TCode Length: 13 TZ TCode: Europe/Berlin Option: (43) Vendor-Specific Information Length: 9 Value: 1701311a0431343030 Option: (54) DHCP Server Identifier (192.168.5.1) Length: 4 DHCP Server Identifier: 192.168.5.1 Option: (255) End Option End: 255 ```
104 lines
2.6 KiB
C
104 lines
2.6 KiB
C
/* SPDX-License-Identifier: LGPL-2.1+ */
|
|
#pragma once
|
|
|
|
/***
|
|
Copyright © 2013 Intel Corporation. All rights reserved.
|
|
***/
|
|
|
|
#include "sd-dhcp-server.h"
|
|
#include "sd-event.h"
|
|
|
|
#include "dhcp-internal.h"
|
|
#include "hashmap.h"
|
|
#include "log.h"
|
|
#include "time-util.h"
|
|
|
|
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,
|
|
_DHCP_RAW_OPTION_DATA_MAX,
|
|
_DHCP_RAW_OPTION_DATA_INVALID,
|
|
} DHCPRawOption;
|
|
|
|
typedef struct DHCPClientId {
|
|
size_t length;
|
|
void *data;
|
|
} DHCPClientId;
|
|
|
|
typedef struct DHCPLease {
|
|
DHCPClientId client_id;
|
|
|
|
be32_t address;
|
|
be32_t gateway;
|
|
uint8_t chaddr[16];
|
|
usec_t expiration;
|
|
} DHCPLease;
|
|
|
|
struct sd_dhcp_raw_option {
|
|
unsigned n_ref;
|
|
|
|
uint8_t type;
|
|
uint8_t length;
|
|
|
|
void *data;
|
|
};
|
|
|
|
struct sd_dhcp_server {
|
|
unsigned n_ref;
|
|
|
|
sd_event *event;
|
|
int event_priority;
|
|
sd_event_source *receive_message;
|
|
int fd;
|
|
int fd_raw;
|
|
|
|
int ifindex;
|
|
be32_t address;
|
|
be32_t netmask;
|
|
be32_t subnet;
|
|
uint32_t pool_offset;
|
|
uint32_t pool_size;
|
|
|
|
char *timezone;
|
|
|
|
struct in_addr *ntp, *dns, *sip;
|
|
unsigned n_ntp, n_dns, n_sip;
|
|
|
|
OrderedHashmap *raw_option;
|
|
|
|
bool emit_router;
|
|
|
|
Hashmap *leases_by_client_id;
|
|
DHCPLease **bound_leases;
|
|
DHCPLease invalid_lease;
|
|
|
|
uint32_t max_lease_time, default_lease_time;
|
|
};
|
|
|
|
typedef struct DHCPRequest {
|
|
/* received message */
|
|
DHCPMessage *message;
|
|
|
|
/* options */
|
|
DHCPClientId client_id;
|
|
size_t max_optlen;
|
|
be32_t server_id;
|
|
be32_t requested_ip;
|
|
uint32_t lifetime;
|
|
} DHCPRequest;
|
|
|
|
#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__)
|
|
|
|
int dhcp_server_handle_message(sd_dhcp_server *server, DHCPMessage *message,
|
|
size_t length);
|
|
int dhcp_server_send_packet(sd_dhcp_server *server,
|
|
DHCPRequest *req, DHCPPacket *packet,
|
|
int type, size_t optoffset);
|
|
|
|
void client_id_hash_func(const DHCPClientId *p, struct siphash *state);
|
|
int client_id_compare_func(const DHCPClientId *a, const DHCPClientId *b);
|