mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-08 21:17:47 +03:00
dhcp-server: also append specified additional options and vendor specific option on DHCP_OFFER
Fixes #15780.
This commit is contained in:
parent
329998b365
commit
986c0edfcb
@ -425,14 +425,23 @@ static int server_message_init(sd_dhcp_server *server, DHCPPacket **ret,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int server_send_offer(sd_dhcp_server *server, DHCPRequest *req,
|
||||
be32_t address) {
|
||||
static int server_send_offer_or_ack(
|
||||
sd_dhcp_server *server,
|
||||
DHCPRequest *req,
|
||||
be32_t address,
|
||||
uint8_t type) {
|
||||
|
||||
_cleanup_free_ DHCPPacket *packet = NULL;
|
||||
size_t offset;
|
||||
sd_dhcp_option *j;
|
||||
be32_t lease_time;
|
||||
size_t offset;
|
||||
int r;
|
||||
|
||||
r = server_message_init(server, &packet, DHCP_OFFER, &offset, req);
|
||||
assert(server);
|
||||
assert(req);
|
||||
assert(IN_SET(type, DHCP_OFFER, DHCP_ACK));
|
||||
|
||||
r = server_message_init(server, &packet, type, &offset, req);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@ -457,18 +466,7 @@ static int server_send_offer(sd_dhcp_server *server, DHCPRequest *req,
|
||||
return r;
|
||||
}
|
||||
|
||||
r = dhcp_server_send_packet(server, req, packet, DHCP_OFFER, offset);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int server_send_ack(
|
||||
sd_dhcp_server *server,
|
||||
DHCPRequest *req,
|
||||
be32_t address) {
|
||||
|
||||
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,
|
||||
[SD_DHCP_LEASE_NTP] = SD_DHCP_OPTION_NTP_SERVER,
|
||||
@ -478,46 +476,15 @@ static int server_send_ack(
|
||||
[SD_DHCP_LEASE_LPR] = SD_DHCP_OPTION_LPR_SERVER,
|
||||
};
|
||||
|
||||
_cleanup_free_ DHCPPacket *packet = NULL;
|
||||
be32_t lease_time;
|
||||
sd_dhcp_option *j;
|
||||
size_t offset;
|
||||
int r;
|
||||
|
||||
r = server_message_init(server, &packet, DHCP_ACK, &offset, req);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
packet->dhcp.yiaddr = address;
|
||||
|
||||
lease_time = htobe32(req->lifetime);
|
||||
r = dhcp_option_append(&packet->dhcp, req->max_optlen, &offset, 0,
|
||||
SD_DHCP_OPTION_IP_ADDRESS_LEASE_TIME, 4,
|
||||
&lease_time);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = dhcp_option_append(&packet->dhcp, req->max_optlen, &offset, 0,
|
||||
SD_DHCP_OPTION_SUBNET_MASK, 4, &server->netmask);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (server->emit_router) {
|
||||
r = dhcp_option_append(&packet->dhcp, req->max_optlen, &offset, 0,
|
||||
SD_DHCP_OPTION_ROUTER, 4, &server->address);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
for (sd_dhcp_lease_server_type_t k = 0; k < _SD_DHCP_LEASE_SERVER_TYPE_MAX; k++) {
|
||||
|
||||
if (server->servers[k].size <= 0)
|
||||
continue;
|
||||
|
||||
r = dhcp_option_append(
|
||||
&packet->dhcp, req->max_optlen, &offset, 0,
|
||||
option_map[k],
|
||||
sizeof(struct in_addr) * server->servers[k].size, server->servers[k].addr);
|
||||
sizeof(struct in_addr) * server->servers[k].size,
|
||||
server->servers[k].addr);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
@ -531,6 +498,7 @@ static int server_send_ack(
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
ORDERED_SET_FOREACH(j, server->extra_options) {
|
||||
r = dhcp_option_append(&packet->dhcp, req->max_optlen, &offset, 0,
|
||||
@ -548,7 +516,7 @@ static int server_send_ack(
|
||||
return r;
|
||||
}
|
||||
|
||||
r = dhcp_server_send_packet(server, req, packet, DHCP_ACK, offset);
|
||||
r = dhcp_server_send_packet(server, req, packet, type, offset);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@ -783,7 +751,7 @@ int dhcp_server_handle_message(sd_dhcp_server *server, DHCPMessage *message,
|
||||
/* no free addresses left */
|
||||
return 0;
|
||||
|
||||
r = server_send_offer(server, req, address);
|
||||
r = server_send_offer_or_ack(server, req, address, DHCP_OFFER);
|
||||
if (r < 0)
|
||||
/* this only fails on critical errors */
|
||||
return log_dhcp_server_errno(server, r, "Could not send offer: %m");
|
||||
@ -886,7 +854,7 @@ int dhcp_server_handle_message(sd_dhcp_server *server, DHCPMessage *message,
|
||||
|
||||
lease->expiration = req->lifetime * USEC_PER_SEC + time_now;
|
||||
|
||||
r = server_send_ack(server, req, address);
|
||||
r = server_send_offer_or_ack(server, req, address, DHCP_ACK);
|
||||
if (r < 0) {
|
||||
/* this only fails on critical errors */
|
||||
log_dhcp_server_errno(server, r, "Could not send ack: %m");
|
||||
|
Loading…
Reference in New Issue
Block a user