This patch sets the BOOTP secs field in a RFC 951- and 2131-compliant
manner for DHCPv4 DISCOVER and REQUEST/SELECT packets.
Certain DHCP servers, such as that implemented in Mac OS X (< 10.7)
for its "Internet Sharing" feature, refuse to issue a DHCP lease to
clients that have not set a non-zero value in their DISCOVER or
REQUEST packets. In fact, based on http://hints.macworld.com/article.php?
story=
20071223001432304, it's not non-zero but a value greater than four (4)
seconds to allow another "authoritative" DHCP server on the subnet to reply
first.
Side-by-side packet analysis of Mac OS X, iOS, Android, ISC and
Windows clients show that these clients set the BOOTP 'secs' field and
are successfully issued a DHCP lease by Mac OS X. By contrast, a
connman-based client will issue 10 back-to-back DISCOVER packets and
will not be returned a DHCP OFFER from the server.
uint32_t server_ip;
uint32_t requested_ip;
char *assigned_ip;
uint32_t server_ip;
uint32_t requested_ip;
char *assigned_ip;
uint32_t lease_seconds;
ListenMode listen_mode;
int listener_sockfd;
uint32_t lease_seconds;
ListenMode listen_mode;
int listener_sockfd;
add_binary_option, packet);
}
add_binary_option, packet);
}
+/*
+ * Return an RFC 951- and 2131-complaint BOOTP 'secs' value that
+ * represents the number of seconds elapsed from the start of
+ * attempting DHCP to satisfy some DHCP servers that allow for an
+ * "authoritative" reply before responding.
+ */
+static uint16_t dhcp_attempt_secs(GDHCPClient *dhcp_client)
+{
+ return htons(MIN(time(NULL) - dhcp_client->start, UINT16_MAX));
+}
+
static int send_discover(GDHCPClient *dhcp_client, uint32_t requested)
{
struct dhcp_packet packet;
static int send_discover(GDHCPClient *dhcp_client, uint32_t requested)
{
struct dhcp_packet packet;
init_packet(dhcp_client, &packet, DHCPDISCOVER);
packet.xid = dhcp_client->xid;
init_packet(dhcp_client, &packet, DHCPDISCOVER);
packet.xid = dhcp_client->xid;
+ packet.secs = dhcp_attempt_secs(dhcp_client);
if (requested)
dhcp_add_simple_option(&packet, DHCP_REQUESTED_IP, requested);
if (requested)
dhcp_add_simple_option(&packet, DHCP_REQUESTED_IP, requested);
init_packet(dhcp_client, &packet, DHCPREQUEST);
packet.xid = dhcp_client->xid;
init_packet(dhcp_client, &packet, DHCPREQUEST);
packet.xid = dhcp_client->xid;
+ packet.secs = dhcp_attempt_secs(dhcp_client);
dhcp_add_simple_option(&packet, DHCP_REQUESTED_IP,
dhcp_client->requested_ip);
dhcp_add_simple_option(&packet, DHCP_REQUESTED_IP,
dhcp_client->requested_ip);
return re;
dhcp_client->xid = rand();
return re;
dhcp_client->xid = rand();
+ dhcp_client->start = time(NULL);
}
if (last_address == NULL) {
}
if (last_address == NULL) {