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.c111
1 files changed, 48 insertions, 63 deletions
diff --git a/networking/udhcp/serverpacket.c b/networking/udhcp/serverpacket.c
index b5cfcf405..8889fda86 100644
--- a/networking/udhcp/serverpacket.c
+++ b/networking/udhcp/serverpacket.c
@@ -20,17 +20,10 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <string.h>
-#include <time.h>
-
#include "common.h"
-#include "serverpacket.h"
#include "dhcpd.h"
#include "options.h"
-#include "static_leases.h"
+
/* send a packet to giaddr using the kernel ip stack */
static int send_packet_to_relay(struct dhcpMessage *payload)
@@ -122,65 +115,57 @@ int sendOffer(struct dhcpMessage *oldpacket)
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 */
- if ((lease = find_lease_by_chaddr(oldpacket->chaddr))) {
- 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 */
+ if (!static_lease_ip) {
+ /* the client is in our lease/offered table */
+ lease = find_lease_by_chaddr(oldpacket->chaddr);
+ if (lease) {
+ 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)))) {
- packet.yiaddr = req_align; /* FIXME: oh my, is there a host using this IP? */
-
+ && (!(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 */
- } else {
+ } 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);
- }
-
- if(!packet.yiaddr) {
- bb_error_msg("no IP addresses to give - OFFER abandoned");
- return -1;
- }
-
- if (!add_lease(packet.chaddr, packet.yiaddr, server_config.offer_time)) {
- bb_error_msg("lease pool is full - OFFER abandoned");
- return -1;
- }
-
- if ((lease_time = get_option(oldpacket, DHCP_LEASE_TIME))) {
- memcpy(&lease_time_align, lease_time, 4);
- lease_time_align = ntohl(lease_time_align);
- if (lease_time_align > server_config.lease)
+ packet.yiaddr = find_address(0);
+ /* try for an expired lease */
+ if (!packet.yiaddr) packet.yiaddr = find_address(1);
+ }
+
+ if (!packet.yiaddr) {
+ bb_error_msg("no IP addresses to give - OFFER abandoned");
+ return -1;
+ }
+ if (!add_lease(packet.chaddr, packet.yiaddr, server_config.offer_time)) {
+ bb_error_msg("lease pool is full - OFFER abandoned");
+ return -1;
+ }
+ 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)
+ lease_time_align = server_config.lease;
+ }
+
+ /* Make sure we aren't just using the lease time from the previous offer */
+ if (lease_time_align < server_config.min_lease)
lease_time_align = server_config.lease;
- }
-
- /* Make sure we aren't just using the lease time from the previous offer */
- if (lease_time_align < server_config.min_lease)
- lease_time_align = server_config.lease;
- }
- /* ADDME: end of short circuit */
- else
- {
+ /* ADDME: end of short circuit */
+ } else {
/* It is a static lease... use it */
packet.yiaddr = static_lease_ip;
}