summaryrefslogtreecommitdiffstats
path: root/src/libsystemd-network/sd-dhcp-server.c
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2023-11-07 17:27:46 +0100
committerYu Watanabe <watanabe.yu+github@gmail.com>2023-11-07 18:39:59 +0100
commit538ff0a60af9c34e09deba9c5b9744b1064fcb22 (patch)
tree612910ff908d5eebdd0cd52c3f56bbc0e147b7c8 /src/libsystemd-network/sd-dhcp-server.c
parentsd-dhcp-client: unconditionally set sd_dhcp_client.request_sent when a packet... (diff)
downloadsystemd-538ff0a60af9c34e09deba9c5b9744b1064fcb22.tar.xz
systemd-538ff0a60af9c34e09deba9c5b9744b1064fcb22.zip
sd-dhcp-server: support rapid commit (RFC4039)
https://datatracker.ietf.org/doc/html/rfc4039
Diffstat (limited to 'src/libsystemd-network/sd-dhcp-server.c')
-rw-r--r--src/libsystemd-network/sd-dhcp-server.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/libsystemd-network/sd-dhcp-server.c b/src/libsystemd-network/sd-dhcp-server.c
index 54a659766d..437028800d 100644
--- a/src/libsystemd-network/sd-dhcp-server.c
+++ b/src/libsystemd-network/sd-dhcp-server.c
@@ -211,6 +211,7 @@ int sd_dhcp_server_new(sd_dhcp_server **ret, int ifindex) {
.bind_to_interface = true,
.default_lease_time = DHCP_DEFAULT_LEASE_TIME_USEC,
.max_lease_time = DHCP_MAX_LEASE_TIME_USEC,
+ .rapid_commit = true,
};
*ret = TAKE_PTR(server);
@@ -692,6 +693,15 @@ static int server_send_offer_or_ack(
return r;
}
+ if (server->rapid_commit && req->rapid_commit && type == DHCP_ACK) {
+ r = dhcp_option_append(
+ &packet->dhcp, req->max_optlen, &offset, 0,
+ SD_DHCP_OPTION_RAPID_COMMIT,
+ 0, NULL);
+ if (r < 0)
+ return r;
+ }
+
return dhcp_server_send_packet(server, req, packet, type, offset);
}
@@ -810,6 +820,10 @@ static int parse_request(uint8_t code, uint8_t len, const void *option, void *us
req->parameter_request_list = option;
req->parameter_request_list_len = len;
break;
+
+ case SD_DHCP_OPTION_RAPID_COMMIT:
+ req->rapid_commit = true;
+ break;
}
return 0;
@@ -1210,6 +1224,9 @@ int dhcp_server_handle_message(sd_dhcp_server *server, DHCPMessage *message, siz
/* no free addresses left */
return 0;
+ if (server->rapid_commit && req->rapid_commit)
+ return server_ack_request(server, req, existing_lease, address);
+
r = server_send_offer_or_ack(server, req, address, DHCP_OFFER);
if (r < 0)
/* this only fails on critical errors */
@@ -1274,6 +1291,9 @@ int dhcp_server_handle_message(sd_dhcp_server *server, DHCPMessage *message, siz
address = req->message->ciaddr;
}
+ /* Silently ignore Rapid Commit option in REQUEST message. */
+ req->rapid_commit = false;
+
/* disallow our own address */
if (address == server->address)
return 0;
@@ -1545,6 +1565,13 @@ int sd_dhcp_server_set_ipv6_only_preferred_usec(sd_dhcp_server *server, uint64_t
return 0;
}
+int sd_dhcp_server_set_rapid_commit(sd_dhcp_server *server, int enabled) {
+ assert_return(server, -EINVAL);
+
+ server->rapid_commit = enabled;
+ return 0;
+}
+
int sd_dhcp_server_set_servers(
sd_dhcp_server *server,
sd_dhcp_lease_server_type_t what,