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.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)
122 if (!lease_expired(lease)) 122 if (!lease_expired(lease))
123 lease_time_align = lease->expires - time(0); 123 lease_time_align = lease->expires - time(0);
124 packet.yiaddr = lease->yiaddr; 124 packet.yiaddr = lease->yiaddr;
125
126 /* Or the client has a requested ip */ 125 /* Or the client has a requested ip */
127 } else if ((req = get_option(oldpacket, DHCP_REQUESTED_IP)) 126 } else if ((req = get_option(oldpacket, DHCP_REQUESTED_IP))
128 /* Don't look here (ugly hackish thing to do) */ 127 /* Don't look here (ugly hackish thing to do) */
129 && memcpy(&req_align, req, 4) 128 && memcpy(&req_align, req, 4)
130 /* and the ip is in the lease range */ 129 /* and the ip is in the lease range */
131 && ntohl(req_align) >= ntohl(server_config.start) 130 && ntohl(req_align) >= server_config.start_ip
132 && ntohl(req_align) <= ntohl(server_config.end) 131 && ntohl(req_align) <= server_config.end_ip
133 && !static_lease_ip /* Check that its not a static lease */ 132 && !static_lease_ip /* Check that its not a static lease */
134 /* and is not already taken/offered */ 133 /* and is not already taken/offered */
135 && (!(lease = find_lease_by_yiaddr(req_align)) 134 && (!(lease = find_lease_by_yiaddr(req_align))
136 /* or its taken, but expired */ /* ADDME: or maybe in here */ 135 /* or its taken, but expired */ /* ADDME: or maybe in here */
137 || lease_expired(lease)) 136 || lease_expired(lease))
138 ) { 137 ) {
139 packet.yiaddr = req_align; /* FIXME: oh my, is there a host using this IP? */ 138 packet.yiaddr = req_align; /* FIXME: oh my, is there a host using this IP? */
140 /* otherwise, find a free IP */ 139 /* otherwise, find a free IP */
@@ -142,7 +141,8 @@ int sendOffer(struct dhcpMessage *oldpacket)
142 /* Is it a static lease? (No, because find_address skips static lease) */ 141 /* Is it a static lease? (No, because find_address skips static lease) */
143 packet.yiaddr = find_address(0); 142 packet.yiaddr = find_address(0);
144 /* try for an expired lease */ 143 /* try for an expired lease */
145 if (!packet.yiaddr) packet.yiaddr = find_address(1); 144 if (!packet.yiaddr)
145 packet.yiaddr = find_address(1);
146 } 146 }
147 147
148 if (!packet.yiaddr) { 148 if (!packet.yiaddr) {
@@ -209,7 +209,8 @@ int sendACK(struct dhcpMessage *oldpacket, uint32_t yiaddr)
209 init_packet(&packet, oldpacket, DHCPACK); 209 init_packet(&packet, oldpacket, DHCPACK);
210 packet.yiaddr = yiaddr; 210 packet.yiaddr = yiaddr;
211 211
212 if ((lease_time = get_option(oldpacket, DHCP_LEASE_TIME))) { 212 lease_time = get_option(oldpacket, DHCP_LEASE_TIME);
213 if (lease_time) {
213 memcpy(&lease_time_align, lease_time, 4); 214 memcpy(&lease_time_align, lease_time, 4);
214 lease_time_align = ntohl(lease_time_align); 215 lease_time_align = ntohl(lease_time_align);
215 if (lease_time_align > server_config.lease) 216 if (lease_time_align > server_config.lease)
@@ -236,6 +237,10 @@ int sendACK(struct dhcpMessage *oldpacket, uint32_t yiaddr)
236 return -1; 237 return -1;
237 238
238 add_lease(packet.chaddr, packet.yiaddr, lease_time_align); 239 add_lease(packet.chaddr, packet.yiaddr, lease_time_align);
240 if (ENABLE_FEATURE_UDHCPD_WRITE_LEASES_EARLY) {
241 /* rewrite the file with leases at every new acceptance */
242 write_leases();
243 }
239 244
240 return 0; 245 return 0;
241} 246}