mirror of
https://github.com/systemd/systemd.git
synced 2025-01-26 14:04:03 +03:00
Merge pull request #22615 from yuwata/network-dhcp-server-support-pxe-boot-systems
network: dhcp server: support pxe boot systems
This commit is contained in:
commit
224f21e64f
@ -2626,6 +2626,23 @@ Token=prefixstable:2002:da8:1::</programlisting></para>
|
||||
<filename>/etc/localtime</filename> symlink.</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><varname>NextServer=</varname></term>
|
||||
|
||||
<listitem>
|
||||
<para>Takes an IPv4 address. Configures the next server used by e.g. PXE boot systems.
|
||||
Defaults to unset.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><varname>Filename=</varname></term>
|
||||
|
||||
<listitem>
|
||||
<para>Takes a path or url to a file loaded by e.g. a PXE boot loader. Defaults to unset.</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><varname>SendOption=</varname></term>
|
||||
<listitem>
|
||||
|
@ -65,6 +65,8 @@ struct sd_dhcp_server {
|
||||
char *timezone;
|
||||
|
||||
DHCPServerData servers[_SD_DHCP_LEASE_SERVER_TYPE_MAX];
|
||||
struct in_addr next_server;
|
||||
char *filename;
|
||||
|
||||
OrderedSet *extra_options;
|
||||
OrderedSet *vendor_options;
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "siphash24.h"
|
||||
#include "string-util.h"
|
||||
#include "unaligned.h"
|
||||
#include "utf8.h"
|
||||
|
||||
#define DHCP_DEFAULT_LEASE_TIME_USEC USEC_PER_HOUR
|
||||
#define DHCP_MAX_LEASE_TIME_USEC (USEC_PER_HOUR*12)
|
||||
@ -162,6 +163,7 @@ static sd_dhcp_server *dhcp_server_free(sd_dhcp_server *server) {
|
||||
|
||||
sd_event_unref(server->event);
|
||||
|
||||
free(server->filename);
|
||||
free(server->timezone);
|
||||
|
||||
for (sd_dhcp_lease_server_type_t i = 0; i < _SD_DHCP_LEASE_SERVER_TYPE_MAX; i++)
|
||||
@ -270,6 +272,26 @@ sd_event *sd_dhcp_server_get_event(sd_dhcp_server *server) {
|
||||
return server->event;
|
||||
}
|
||||
|
||||
int sd_dhcp_server_set_next_server(sd_dhcp_server *server, const struct in_addr *next_server) {
|
||||
assert_return(server, -EINVAL);
|
||||
|
||||
if (next_server)
|
||||
server->next_server = *next_server;
|
||||
else
|
||||
server->next_server = (struct in_addr) {};
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sd_dhcp_server_set_filename(sd_dhcp_server *server, const char *filename) {
|
||||
assert_return(server, -EINVAL);
|
||||
|
||||
if (filename && !ascii_is_valid(filename))
|
||||
return -EINVAL;
|
||||
|
||||
return free_and_strdup(&server->filename, filename);
|
||||
}
|
||||
|
||||
int sd_dhcp_server_stop(sd_dhcp_server *server) {
|
||||
bool running;
|
||||
|
||||
@ -539,6 +561,7 @@ static int server_send_offer_or_ack(
|
||||
return r;
|
||||
|
||||
packet->dhcp.yiaddr = address;
|
||||
packet->dhcp.siaddr = server->next_server.s_addr;
|
||||
|
||||
lease_time = htobe32(req->lifetime);
|
||||
r = dhcp_option_append(&packet->dhcp, req->max_optlen, &offset, 0,
|
||||
@ -562,6 +585,22 @@ static int server_send_offer_or_ack(
|
||||
return r;
|
||||
}
|
||||
|
||||
if (server->filename) {
|
||||
/* The pxelinux magic option is marked as deprecated, but let's append it for older
|
||||
* implementations. */
|
||||
r = dhcp_option_append(&packet->dhcp, req->max_optlen, &offset, 0,
|
||||
SD_DHCP_OPTION_PXELINUX_MAGIC, 4,
|
||||
(const uint8_t[]) { 0xf1, 0x00, 0x74, 0x7e });
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = dhcp_option_append(&packet->dhcp, req->max_optlen, &offset, 0,
|
||||
SD_DHCP_OPTION_CONFIGURATION_FILE,
|
||||
strlen(server->filename), server->filename);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
if (type == DHCP_ACK) {
|
||||
static const uint8_t option_map[_SD_DHCP_LEASE_SERVER_TYPE_MAX] = {
|
||||
[SD_DHCP_LEASE_DNS] = SD_DHCP_OPTION_DOMAIN_NAME_SERVER,
|
||||
|
@ -416,6 +416,14 @@ static int dhcp4_server_configure(Link *link) {
|
||||
return log_link_error_errno(link, r, "Failed to set default lease time for DHCPv4 server instance: %m");
|
||||
}
|
||||
|
||||
r = sd_dhcp_server_set_next_server(link->dhcp_server, &link->network->dhcp_server_next_server);
|
||||
if (r < 0)
|
||||
return log_link_warning_errno(link, r, "Failed to set next server for DHCPv4 server instance: %m");
|
||||
|
||||
r = sd_dhcp_server_set_filename(link->dhcp_server, link->network->dhcp_server_filename);
|
||||
if (r < 0)
|
||||
return log_link_warning_errno(link, r, "Failed to set filename for DHCPv4 server instance: %m");
|
||||
|
||||
for (sd_dhcp_lease_server_type_t type = 0; type < _SD_DHCP_LEASE_SERVER_TYPE_MAX; type ++) {
|
||||
|
||||
if (!link->network->dhcp_server_emit[type].emit)
|
||||
|
@ -305,6 +305,8 @@ DHCPServer.PoolSize, config_parse_uint32,
|
||||
DHCPServer.SendVendorOption, config_parse_dhcp_send_option, 0, offsetof(Network, dhcp_server_send_vendor_options)
|
||||
DHCPServer.SendOption, config_parse_dhcp_send_option, 0, offsetof(Network, dhcp_server_send_options)
|
||||
DHCPServer.BindToInterface, config_parse_bool, 0, offsetof(Network, dhcp_server_bind_to_interface)
|
||||
DHCPServer.NextServer, config_parse_in_addr_non_null, AF_INET, offsetof(Network, dhcp_server_next_server)
|
||||
DHCPServer.Filename, config_parse_string, 0, offsetof(Network, dhcp_server_filename)
|
||||
DHCPServerStaticLease.Address, config_parse_dhcp_static_lease_address, 0, 0
|
||||
DHCPServerStaticLease.MACAddress, config_parse_dhcp_static_lease_hwaddr, 0, 0
|
||||
Bridge.Cost, config_parse_uint32, 0, offsetof(Network, cost)
|
||||
|
@ -700,6 +700,7 @@ static Network *network_free(Network *network) {
|
||||
|
||||
free(network->dhcp_server_relay_agent_circuit_id);
|
||||
free(network->dhcp_server_relay_agent_remote_id);
|
||||
free(network->dhcp_server_filename);
|
||||
|
||||
free(network->description);
|
||||
free(network->dhcp_vendor_class_identifier);
|
||||
|
@ -200,6 +200,8 @@ struct Network {
|
||||
uint32_t dhcp_server_pool_size;
|
||||
OrderedHashmap *dhcp_server_send_options;
|
||||
OrderedHashmap *dhcp_server_send_vendor_options;
|
||||
struct in_addr dhcp_server_next_server;
|
||||
char *dhcp_server_filename;
|
||||
|
||||
/* link local addressing support */
|
||||
AddressFamily link_local;
|
||||
|
@ -97,6 +97,10 @@ enum {
|
||||
SD_DHCP_OPTION_SIP_SERVER = 120,
|
||||
SD_DHCP_OPTION_CLASSLESS_STATIC_ROUTE = 121,
|
||||
SD_DHCP_OPTION_MUD_URL = 161,
|
||||
SD_DHCP_OPTION_PXELINUX_MAGIC = 208, /* deprecated */
|
||||
SD_DHCP_OPTION_CONFIGURATION_FILE = 209,
|
||||
SD_DHCP_OPTION_PATH_PREFIX = 210,
|
||||
SD_DHCP_OPTION_REBOOT_TIME = 211,
|
||||
SD_DHCP_OPTION_6RD = 212,
|
||||
SD_DHCP_OPTION_PRIVATE_BASE = 224,
|
||||
/* Windows 10 option to send when Anonymize=true */
|
||||
|
@ -58,6 +58,8 @@ int sd_dhcp_server_stop(sd_dhcp_server *server);
|
||||
|
||||
int sd_dhcp_server_configure_pool(sd_dhcp_server *server, const struct in_addr *address, unsigned char prefixlen, uint32_t offset, uint32_t size);
|
||||
|
||||
int sd_dhcp_server_set_next_server(sd_dhcp_server *server, const struct in_addr *next_server);
|
||||
int sd_dhcp_server_set_filename(sd_dhcp_server *server, const char *filename);
|
||||
int sd_dhcp_server_set_bind_to_interface(sd_dhcp_server *server, int enabled);
|
||||
int sd_dhcp_server_set_timezone(sd_dhcp_server *server, const char *timezone);
|
||||
int sd_dhcp_server_set_router(sd_dhcp_server *server, const struct in_addr *address);
|
||||
|
@ -409,6 +409,8 @@ RelayAgentCircuitId=
|
||||
RelayAgentRemoteId=
|
||||
ServerAddress=
|
||||
UplinkInterface=
|
||||
NextServer=
|
||||
Filename=
|
||||
[DHCPServerStaticLease]
|
||||
MACAddress=
|
||||
Address=
|
||||
|
Loading…
x
Reference in New Issue
Block a user