mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-02-08 05:57:26 +03:00
1. DHCP server trasmit 2. Client parses and saves in leases Implements http://www.rfc-editor.org/rfc/rfc3361.txt ``` Frame 134: 348 bytes on wire (2784 bits), 348 bytes captured (2784 bits) on interface 0 Ethernet II, Src: 42:65:85:d6:4e:32 (42:65:85:d6:4e:32), Dst: 1e:04:f8:b8:2f:d4 (1e:04:f8:b8:2f:d4) 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: 0x7cc87cb4 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.1.1 Option: (120) SIP Servers <=====here Length: 9 SIP Server Encoding: IPv4 Address (1) SIP Server Address: 192.168.1.1 SIP Server Address: 192.168.5.2 Option: (101) TCode Length: 13 TZ TCode: Europe/Berlin Option: (54) DHCP Server Identifier (192.168.5.1) Length: 4 DHCP Server Identifier: 192.168.5.1 Option: (255) End Option End: 255 ``` ``` cat /run/systemd/netif/state ✔ ⚡ 3148 16:40:51 OPER_STATE=routable CARRIER_STATE=carrier ADDRESS_STATE=routable DNS=192.168.94.2 192.168.5.1 NTP=192.168.5.1 SIP=192.168.1.1 192.168.5.2 ``` aa
97 lines
2.2 KiB
C
97 lines
2.2 KiB
C
/* SPDX-License-Identifier: LGPL-2.1+ */
|
|
#pragma once
|
|
|
|
/***
|
|
Copyright © 2013 Intel Corporation. All rights reserved.
|
|
***/
|
|
|
|
#include <stdint.h>
|
|
#include <linux/if_packet.h>
|
|
|
|
#include "sd-dhcp-client.h"
|
|
|
|
#include "dhcp-protocol.h"
|
|
#include "list.h"
|
|
#include "util.h"
|
|
|
|
struct sd_dhcp_route {
|
|
struct in_addr dst_addr;
|
|
struct in_addr gw_addr;
|
|
unsigned char dst_prefixlen;
|
|
|
|
uint8_t option;
|
|
};
|
|
|
|
struct sd_dhcp_raw_option {
|
|
LIST_FIELDS(struct sd_dhcp_raw_option, options);
|
|
|
|
uint8_t tag;
|
|
uint8_t length;
|
|
void *data;
|
|
};
|
|
|
|
struct sd_dhcp_lease {
|
|
unsigned n_ref;
|
|
|
|
/* each 0 if unset */
|
|
uint32_t t1;
|
|
uint32_t t2;
|
|
uint32_t lifetime;
|
|
|
|
/* each 0 if unset */
|
|
be32_t address;
|
|
be32_t server_address;
|
|
be32_t next_server;
|
|
|
|
bool have_subnet_mask;
|
|
be32_t subnet_mask;
|
|
|
|
bool have_broadcast;
|
|
be32_t broadcast;
|
|
|
|
struct in_addr *router;
|
|
size_t router_size;
|
|
|
|
struct in_addr *dns;
|
|
size_t dns_size;
|
|
|
|
struct in_addr *ntp;
|
|
size_t ntp_size;
|
|
|
|
struct in_addr *sip;
|
|
size_t sip_size;
|
|
|
|
struct sd_dhcp_route *static_route;
|
|
size_t static_route_size, static_route_allocated;
|
|
|
|
uint16_t mtu; /* 0 if unset */
|
|
|
|
char *domainname;
|
|
char **search_domains;
|
|
char *hostname;
|
|
char *root_path;
|
|
|
|
void *client_id;
|
|
size_t client_id_len;
|
|
|
|
void *vendor_specific;
|
|
size_t vendor_specific_len;
|
|
|
|
char *timezone;
|
|
|
|
LIST_HEAD(struct sd_dhcp_raw_option, private_options);
|
|
};
|
|
|
|
int dhcp_lease_new(sd_dhcp_lease **ret);
|
|
|
|
int dhcp_lease_parse_options(uint8_t code, uint8_t len, const void *option, void *userdata);
|
|
int dhcp_lease_parse_search_domains(const uint8_t *option, size_t len, char ***domains);
|
|
int dhcp_lease_insert_private_option(sd_dhcp_lease *lease, uint8_t tag, const void *data, uint8_t len);
|
|
|
|
int dhcp_lease_set_default_subnet_mask(sd_dhcp_lease *lease);
|
|
|
|
int dhcp_lease_set_client_id(sd_dhcp_lease *lease, const void *client_id, size_t client_id_len);
|
|
|
|
int dhcp_lease_save(sd_dhcp_lease *lease, const char *lease_file);
|
|
int dhcp_lease_load(sd_dhcp_lease **ret, const char *lease_file);
|