summaryrefslogtreecommitdiff
path: root/src/libsystemd-network
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2014-05-25 21:47:38 +0200
committerTom Gundersen <teg@jklm.no>2014-06-13 17:07:19 +0200
commitc7d9ffe6d629cb5b34dd749e4a88b190b11a0f48 (patch)
tree9b6b4b66813dbc6a2815f86e2fe280ed5e1ac567 /src/libsystemd-network
parentbd57b45029ff25067704c9538e79f31e71c10045 (diff)
sd-dhcp-server: add support for clients requesting lease lifetime
Diffstat (limited to 'src/libsystemd-network')
-rw-r--r--src/libsystemd-network/dhcp-server-internal.h1
-rw-r--r--src/libsystemd-network/sd-dhcp-server.c14
2 files changed, 11 insertions, 4 deletions
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;
}