From c82b5108e1a40f3b299043770e01d7d7db35de04 Mon Sep 17 00:00:00 2001 From: Denis Vlasenko Date: Sun, 1 Jul 2007 17:05:57 +0000 Subject: udhcp: new config option "Rewrite the lease file at every new acknowledge" (Mats Erik Andersson (Blue2Net AB)) udhcp: consistently treat server_config.start/end IPs as host-order fix IP parsing for 64bit machines fix unsafe hton macro usage in read_opt() do not chdir("/") when daemonizing fix help text --- networking/udhcp/serverpacket.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) (limited to 'networking/udhcp/serverpacket.c') diff --git a/networking/udhcp/serverpacket.c b/networking/udhcp/serverpacket.c index e1a88addd..ecbf50a14 100644 --- a/networking/udhcp/serverpacket.c +++ b/networking/udhcp/serverpacket.c @@ -122,19 +122,18 @@ int sendOffer(struct dhcpMessage *oldpacket) if (!lease_expired(lease)) lease_time_align = lease->expires - time(0); packet.yiaddr = lease->yiaddr; - /* Or the client has a requested ip */ } else if ((req = get_option(oldpacket, DHCP_REQUESTED_IP)) - /* Don't look here (ugly hackish thing to do) */ - && memcpy(&req_align, req, 4) - /* and the ip is in the lease range */ - && ntohl(req_align) >= ntohl(server_config.start) - && ntohl(req_align) <= ntohl(server_config.end) - && !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 */ - || lease_expired(lease)) + /* Don't look here (ugly hackish thing to do) */ + && memcpy(&req_align, req, 4) + /* 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 */ + || lease_expired(lease)) ) { packet.yiaddr = req_align; /* FIXME: oh my, is there a host using this IP? */ /* otherwise, find a free IP */ @@ -142,7 +141,8 @@ int sendOffer(struct dhcpMessage *oldpacket) /* 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); + if (!packet.yiaddr) + packet.yiaddr = find_address(1); } if (!packet.yiaddr) { @@ -209,7 +209,8 @@ int sendACK(struct dhcpMessage *oldpacket, uint32_t yiaddr) init_packet(&packet, oldpacket, DHCPACK); packet.yiaddr = yiaddr; - if ((lease_time = get_option(oldpacket, DHCP_LEASE_TIME))) { + lease_time = get_option(oldpacket, DHCP_LEASE_TIME); + if (lease_time) { memcpy(&lease_time_align, lease_time, 4); lease_time_align = ntohl(lease_time_align); if (lease_time_align > server_config.lease) @@ -236,6 +237,10 @@ int sendACK(struct dhcpMessage *oldpacket, uint32_t yiaddr) return -1; add_lease(packet.chaddr, packet.yiaddr, lease_time_align); + if (ENABLE_FEATURE_UDHCPD_WRITE_LEASES_EARLY) { + /* rewrite the file with leases at every new acceptance */ + write_leases(); + } return 0; } -- cgit v1.2.3