aboutsummaryrefslogtreecommitdiff
path: root/networking/udhcp/serverpacket.c
diff options
context:
space:
mode:
Diffstat (limited to 'networking/udhcp/serverpacket.c')
-rw-r--r--networking/udhcp/serverpacket.c37
1 files changed, 16 insertions, 21 deletions
diff --git a/networking/udhcp/serverpacket.c b/networking/udhcp/serverpacket.c
index fca685dd1..afc0fb40d 100644
--- a/networking/udhcp/serverpacket.c
+++ b/networking/udhcp/serverpacket.c
@@ -102,48 +102,44 @@ static void add_bootp_options(struct dhcpMessage *packet)
int FAST_FUNC send_offer(struct dhcpMessage *oldpacket)
{
struct dhcpMessage packet;
- struct dhcpOfferedAddr *lease = NULL;
uint32_t req_align;
uint32_t lease_time_aligned = server_config.lease;
+ uint32_t static_lease_ip;
uint8_t *req, *lease_time;
struct option_set *curr;
struct in_addr addr;
- uint32_t static_lease_ip;
-
init_packet(&packet, oldpacket, DHCPOFFER);
static_lease_ip = getIpByMac(server_config.static_leases, oldpacket->chaddr);
/* ADDME: if static, short circuit */
if (!static_lease_ip) {
- /* the client is in our lease/offered table */
+ struct dhcpOfferedAddr *lease;
+
lease = find_lease_by_chaddr(oldpacket->chaddr);
+ /* the client is in our lease/offered table */
if (lease) {
- if (!lease_expired(lease))
- lease_time_aligned = lease->expires - time(0);
+ signed_leasetime_t tmp = lease->expires - time(NULL);
+ if (tmp >= 0)
+ lease_time_aligned = tmp;
packet.yiaddr = lease->yiaddr;
- /* Or the client has a requested ip */
- } else if ((req = get_option(oldpacket, DHCP_REQUESTED_IP))
+ /* Or the client has requested an ip */
+ } else if ((req = get_option(oldpacket, DHCP_REQUESTED_IP)) != NULL
/* Don't look here (ugly hackish thing to do) */
- && memcpy(&req_align, req, 4)
+ && (move_from_unaligned32(req_align, req), 1)
/* and the ip is in the lease range */
&& ntohl(req_align) >= server_config.start_ip
&& ntohl(req_align) <= server_config.end_ip
- && !static_lease_ip /* Check that its not a static lease */
/* and is not already taken/offered */
&& (!(lease = find_lease_by_yiaddr(req_align))
- /* or its taken, but expired */ /* ADDME: or maybe in here */
+ /* or its taken, but expired */
|| lease_expired(lease))
) {
- packet.yiaddr = req_align; /* FIXME: oh my, is there a host using this IP? */
- /* otherwise, find a free IP */
+ packet.yiaddr = req_align;
+ /* otherwise, find a free IP */
} else {
- /* Is it a static lease? (No, because find_address skips static lease) */
- packet.yiaddr = find_address(0);
- /* try for an expired lease */
- if (!packet.yiaddr)
- packet.yiaddr = find_address(1);
+ packet.yiaddr = find_free_or_expired_address();
}
if (!packet.yiaddr) {
@@ -164,8 +160,7 @@ int FAST_FUNC send_offer(struct dhcpMessage *oldpacket)
/* Make sure we aren't just using the lease time from the previous offer */
if (lease_time_aligned < server_config.min_lease)
- lease_time_aligned = server_config.lease;
- /* ADDME: end of short circuit */
+ lease_time_aligned = server_config.min_lease;
} else {
/* It is a static lease... use it */
packet.yiaddr = static_lease_ip;
@@ -217,7 +212,7 @@ int FAST_FUNC send_ACK(struct dhcpMessage *oldpacket, uint32_t yiaddr)
if (lease_time_aligned > server_config.lease)
lease_time_aligned = server_config.lease;
else if (lease_time_aligned < server_config.min_lease)
- lease_time_aligned = server_config.lease;
+ lease_time_aligned = server_config.min_lease;
}
add_simple_option(packet.options, DHCP_LEASE_TIME, htonl(lease_time_aligned));