|
|
cab8d5 |
From aa63a21ce0b20dfe988e0bcdf14b8b930de20311 Mon Sep 17 00:00:00 2001
|
|
|
cab8d5 |
From: Simon Kelley <simon@thekelleys.org.uk>
|
|
|
cab8d5 |
Date: Mon, 22 Apr 2013 15:01:52 +0100
|
|
|
cab8d5 |
Subject: [PATCH] Fix regression in dhcp_lease_time utility.
|
|
|
cab8d5 |
|
|
|
cab8d5 |
---
|
|
|
cab8d5 |
CHANGELOG | 9 +++++++++
|
|
|
cab8d5 |
contrib/wrt/dhcp_lease_time.c | 9 ++++++++-
|
|
|
cab8d5 |
src/rfc2131.c | 17 ++++++++++++++++-
|
|
|
cab8d5 |
3 files changed, 33 insertions(+), 2 deletions(-)
|
|
|
cab8d5 |
|
|
|
cab8d5 |
diff --git a/CHANGELOG b/CHANGELOG
|
|
|
cab8d5 |
index 6cb1b51..268b64d 100644
|
|
|
cab8d5 |
--- a/CHANGELOG
|
|
|
cab8d5 |
+++ b/CHANGELOG
|
|
|
cab8d5 |
@@ -2,6 +2,15 @@ version 2.67
|
|
|
cab8d5 |
Fix crash if upstream server returns SERVFAIL when
|
|
|
cab8d5 |
--conntrack in use. Thanks to Giacomo Tazzari for finding
|
|
|
cab8d5 |
this and supplying the patch.
|
|
|
cab8d5 |
+
|
|
|
cab8d5 |
+ Repair regression in 2.64. That release stopped sending
|
|
|
cab8d5 |
+ lease-time information in the reply to DHCPINFORM
|
|
|
cab8d5 |
+ requests, on the correct grounds that it was a standards
|
|
|
cab8d5 |
+ violation. However, this broke the dnsmasq-specific
|
|
|
cab8d5 |
+ dhcp_lease_time utility. Now, DHCPINFORM returns
|
|
|
cab8d5 |
+ lease-time only if it's specifically requested
|
|
|
cab8d5 |
+ (maintaining standards) and the dhcp_lease_time utility
|
|
|
cab8d5 |
+ has been taught to ask for it (restoring functionality).
|
|
|
cab8d5 |
|
|
|
cab8d5 |
|
|
|
cab8d5 |
version 2.66
|
|
|
cab8d5 |
diff --git a/contrib/wrt/dhcp_lease_time.c b/contrib/wrt/dhcp_lease_time.c
|
|
|
cab8d5 |
index 2866bb5..b438ef7 100644
|
|
|
cab8d5 |
--- a/contrib/wrt/dhcp_lease_time.c
|
|
|
cab8d5 |
+++ b/contrib/wrt/dhcp_lease_time.c
|
|
|
cab8d5 |
@@ -20,7 +20,7 @@
|
|
|
cab8d5 |
nothing is sent to stdout a message is sent to stderr and a
|
|
|
cab8d5 |
non-zero error code is returned.
|
|
|
cab8d5 |
|
|
|
cab8d5 |
- Requires dnsmasq 2.40 or later.
|
|
|
cab8d5 |
+ This version requires dnsmasq 2.66 or later.
|
|
|
cab8d5 |
*/
|
|
|
cab8d5 |
|
|
|
cab8d5 |
#include <sys/types.h>
|
|
|
cab8d5 |
@@ -46,6 +46,7 @@
|
|
|
cab8d5 |
#define OPTION_LEASE_TIME 51
|
|
|
cab8d5 |
#define OPTION_OVERLOAD 52
|
|
|
cab8d5 |
#define OPTION_MESSAGE_TYPE 53
|
|
|
cab8d5 |
+#define OPTION_REQUESTED_OPTIONS 55
|
|
|
cab8d5 |
#define OPTION_END 255
|
|
|
cab8d5 |
#define DHCPINFORM 8
|
|
|
cab8d5 |
#define DHCP_SERVER_PORT 67
|
|
|
cab8d5 |
@@ -167,6 +168,12 @@ int main(int argc, char **argv)
|
|
|
cab8d5 |
*(p++) = 1;
|
|
|
cab8d5 |
*(p++) = DHCPINFORM;
|
|
|
cab8d5 |
|
|
|
cab8d5 |
+ /* Explicity request the lease time, it won't be sent otherwise:
|
|
|
cab8d5 |
+ this is a dnsmasq extension, not standard. */
|
|
|
cab8d5 |
+ *(p++) = OPTION_REQUESTED_OPTIONS;
|
|
|
cab8d5 |
+ *(p++) = 1;
|
|
|
cab8d5 |
+ *(p++) = OPTION_LEASE_TIME;
|
|
|
cab8d5 |
+
|
|
|
cab8d5 |
*(p++) = OPTION_END;
|
|
|
cab8d5 |
|
|
|
cab8d5 |
dest.sin_family = AF_INET;
|
|
|
cab8d5 |
diff --git a/src/rfc2131.c b/src/rfc2131.c
|
|
|
cab8d5 |
index 92974c0..013a446 100644
|
|
|
cab8d5 |
--- a/src/rfc2131.c
|
|
|
cab8d5 |
+++ b/src/rfc2131.c
|
|
|
cab8d5 |
@@ -39,6 +39,7 @@ static unsigned char *option_find(struct dhcp_packet *mess, size_t size, int opt
|
|
|
cab8d5 |
static unsigned char *option_find1(unsigned char *p, unsigned char *end, int opt, int minsize);
|
|
|
cab8d5 |
static size_t dhcp_packet_size(struct dhcp_packet *mess, unsigned char *agent_id, unsigned char *real_end);
|
|
|
cab8d5 |
static void clear_packet(struct dhcp_packet *mess, unsigned char *end);
|
|
|
cab8d5 |
+static int in_list(unsigned char *list, int opt);
|
|
|
cab8d5 |
static void do_options(struct dhcp_context *context,
|
|
|
cab8d5 |
struct dhcp_packet *mess,
|
|
|
cab8d5 |
unsigned char *real_end,
|
|
|
cab8d5 |
@@ -1410,7 +1411,21 @@ size_t dhcp_reply(struct dhcp_context *context, char *iface_name, int int_index,
|
|
|
cab8d5 |
clear_packet(mess, end);
|
|
|
cab8d5 |
option_put(mess, end, OPTION_MESSAGE_TYPE, 1, DHCPACK);
|
|
|
cab8d5 |
option_put(mess, end, OPTION_SERVER_IDENTIFIER, INADDRSZ, ntohl(server_id(context, override, fallback).s_addr));
|
|
|
cab8d5 |
-
|
|
|
cab8d5 |
+
|
|
|
cab8d5 |
+ /* RFC 2131 says that DHCPINFORM shouldn't include lease-time parameters, but
|
|
|
cab8d5 |
+ we supply a utility which makes DHCPINFORM requests to get this information.
|
|
|
cab8d5 |
+ Only include lease time if OPTION_LEASE_TIME is in the parameter request list,
|
|
|
cab8d5 |
+ which won't be true for ordinary clients, but will be true for the
|
|
|
cab8d5 |
+ dhcp_lease_time utility. */
|
|
|
cab8d5 |
+ if (lease && in_list(req_options, OPTION_LEASE_TIME))
|
|
|
cab8d5 |
+ {
|
|
|
cab8d5 |
+ if (lease->expires == 0)
|
|
|
cab8d5 |
+ time = 0xffffffff;
|
|
|
cab8d5 |
+ else
|
|
|
cab8d5 |
+ time = (unsigned int)difftime(lease->expires, now);
|
|
|
cab8d5 |
+ option_put(mess, end, OPTION_LEASE_TIME, 4, time);
|
|
|
cab8d5 |
+ }
|
|
|
cab8d5 |
+
|
|
|
cab8d5 |
do_options(context, mess, end, req_options, hostname, get_domain(mess->ciaddr),
|
|
|
cab8d5 |
netid, subnet_addr, fqdn_flags, borken_opt, pxearch, uuid, vendor_class_len, now);
|
|
|
cab8d5 |
|
|
|
cab8d5 |
--
|
|
|
cab8d5 |
1.8.1.4
|
|
|
cab8d5 |
|