From c7d9ffe6d629cb5b34dd749e4a88b190b11a0f48 Mon Sep 17 00:00:00 2001 From: Tom Gundersen Date: Sun, 25 May 2014 21:47:38 +0200 Subject: sd-dhcp-server: add support for clients requesting lease lifetime --- src/libsystemd-network/dhcp-server-internal.h | 1 + src/libsystemd-network/sd-dhcp-server.c | 14 ++++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) (limited to 'src/libsystemd-network') diff --git a/src/libsystemd-network/dhcp-server-internal.h b/src/libsystemd-network/dhcp-server-internal.h index cd480e7bba..ce2e260945 100644 --- a/src/libsystemd-network/dhcp-server-internal.h +++ b/src/libsystemd-network/dhcp-server-internal.h @@ -58,6 +58,7 @@ typedef struct DHCPRequest { size_t max_optlen; be32_t server_id; be32_t requested_ip; + int lifetime; } DHCPRequest; DEFINE_TRIVIAL_CLEANUP_FUNC(sd_dhcp_server*, sd_dhcp_server_unref); diff --git a/src/libsystemd-network/sd-dhcp-server.c b/src/libsystemd-network/sd-dhcp-server.c index 75f4316550..4c43eeb3fb 100644 --- a/src/libsystemd-network/sd-dhcp-server.c +++ b/src/libsystemd-network/sd-dhcp-server.c @@ -337,8 +337,7 @@ static int server_send_offer(sd_dhcp_server *server, DHCPRequest *req, be32_t ad packet->dhcp.yiaddr = address; - /* for one minute */ - lease_time = htobe32(DHCP_DEFAULT_LEASE_TIME); + lease_time = htobe32(req->lifetime); r = dhcp_option_append(&packet->dhcp, req->max_optlen, &offset, 0, DHCP_OPTION_IP_ADDRESS_LEASE_TIME, 4, &lease_time); if (r < 0) @@ -363,8 +362,7 @@ static int server_send_ack(sd_dhcp_server *server, DHCPRequest *req, be32_t addr packet->dhcp.yiaddr = address; - /* for ten seconds */ - lease_time = htobe32(DHCP_DEFAULT_LEASE_TIME); + lease_time = htobe32(req->lifetime); r = dhcp_option_append(&packet->dhcp, req->max_optlen, &offset, 0, DHCP_OPTION_IP_ADDRESS_LEASE_TIME, 4, &lease_time); if (r < 0) @@ -400,6 +398,11 @@ static int parse_request(uint8_t code, uint8_t len, const uint8_t *option, assert(req); switch(code) { + case DHCP_OPTION_IP_ADDRESS_LEASE_TIME: + if (len == 4) + req->lifetime = be32toh(*(be32_t*)option); + + break; case DHCP_OPTION_REQUESTED_IP_ADDRESS: if (len == 4) req->requested_ip = *(be32_t*)option; @@ -469,6 +472,9 @@ static int ensure_sane_request(DHCPRequest *req, DHCPMessage *message) { if (req->max_optlen < DHCP_MIN_OPTIONS_SIZE) req->max_optlen = DHCP_MIN_OPTIONS_SIZE; + if (!req->lifetime) + req->lifetime = DHCP_DEFAULT_LEASE_TIME; + return 0; } -- cgit v1.2.3-54-g00ecf