aboutsummaryrefslogtreecommitdiff
path: root/networking/udhcp/serverpacket.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-07-01 17:05:57 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-07-01 17:05:57 +0000
commitc82b5108e1a40f3b299043770e01d7d7db35de04 (patch)
tree35039a36868df644b8e5ffc766c1b0c921c88ab5 /networking/udhcp/serverpacket.c
parentdc7a5eae36d31f5cfc301de2499329b8a03ea660 (diff)
downloadbusybox-c82b5108e1a40f3b299043770e01d7d7db35de04.tar.gz
udhcp: new config option "Rewrite the lease file at every new acknowledge"
(Mats Erik Andersson <mats@blue2net.com> (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
Diffstat (limited to 'networking/udhcp/serverpacket.c')
-rw-r--r--networking/udhcp/serverpacket.c31
1 files changed, 18 insertions, 13 deletions
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;
}