aboutsummaryrefslogtreecommitdiff
path: root/networking/udhcp/serverpacket.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2004-10-08 08:49:26 +0000
committerEric Andersen <andersen@codepoet.org>2004-10-08 08:49:26 +0000
commitabf58d6ba5df9bbe04c4c7008cbbc8c7dc626392 (patch)
treec64a5328d250449c9a4e3964d59a657543e06440 /networking/udhcp/serverpacket.c
parent751750e3ee0195eef802a1554e97712285bf8fd7 (diff)
downloadbusybox-w32-abf58d6ba5df9bbe04c4c7008cbbc8c7dc626392.tar.gz
busybox-w32-abf58d6ba5df9bbe04c4c7008cbbc8c7dc626392.tar.bz2
busybox-w32-abf58d6ba5df9bbe04c4c7008cbbc8c7dc626392.zip
Wade Berrier writes:
Hello, Here's a patch for a first attempt at static leases for udhcpd. Included in the tarball are 2 files (static_leases.c, static_leases.h) and a patch against the latest cvs. In the config file you can configure static leases with the following format: static_lease 00:60:08:11:CE:4E 192.168.0.54 static_lease 00:60:08:11:CE:3E 192.168.0.44 Comments/suggestions/improvements are welcome. Wade
Diffstat (limited to 'networking/udhcp/serverpacket.c')
-rw-r--r--networking/udhcp/serverpacket.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/networking/udhcp/serverpacket.c b/networking/udhcp/serverpacket.c
index bc9d822a9..75d55bd92 100644
--- a/networking/udhcp/serverpacket.c
+++ b/networking/udhcp/serverpacket.c
@@ -29,6 +29,7 @@
29#include "dhcpd.h" 29#include "dhcpd.h"
30#include "options.h" 30#include "options.h"
31#include "common.h" 31#include "common.h"
32#include "static_leases.h"
32 33
33/* send a packet to giaddr using the kernel ip stack */ 34/* send a packet to giaddr using the kernel ip stack */
34static int send_packet_to_relay(struct dhcpMessage *payload) 35static int send_packet_to_relay(struct dhcpMessage *payload)
@@ -113,9 +114,15 @@ int sendOffer(struct dhcpMessage *oldpacket)
113 struct option_set *curr; 114 struct option_set *curr;
114 struct in_addr addr; 115 struct in_addr addr;
115 116
117 uint32_t static_lease_ip;
118
116 init_packet(&packet, oldpacket, DHCPOFFER); 119 init_packet(&packet, oldpacket, DHCPOFFER);
117 120
121 static_lease_ip = getIpByMac(server_config.static_leases, oldpacket->chaddr);
122
118 /* ADDME: if static, short circuit */ 123 /* ADDME: if static, short circuit */
124 if(!static_lease_ip)
125 {
119 /* the client is in our lease/offered table */ 126 /* the client is in our lease/offered table */
120 if ((lease = find_lease_by_chaddr(oldpacket->chaddr))) { 127 if ((lease = find_lease_by_chaddr(oldpacket->chaddr))) {
121 if (!lease_expired(lease)) 128 if (!lease_expired(lease))
@@ -132,15 +139,17 @@ int sendOffer(struct dhcpMessage *oldpacket)
132 ntohl(req_align) >= ntohl(server_config.start) && 139 ntohl(req_align) >= ntohl(server_config.start) &&
133 ntohl(req_align) <= ntohl(server_config.end) && 140 ntohl(req_align) <= ntohl(server_config.end) &&
134 141
135 /* and its not already taken/offered */ /* ADDME: check that its not a static lease */ 142 !static_lease_ip && /* Check that its not a static lease */
143 /* and is not already taken/offered */
136 ((!(lease = find_lease_by_yiaddr(req_align)) || 144 ((!(lease = find_lease_by_yiaddr(req_align)) ||
137 145
138 /* or its taken, but expired */ /* ADDME: or maybe in here */ 146 /* or its taken, but expired */ /* ADDME: or maybe in here */
139 lease_expired(lease)))) { 147 lease_expired(lease)))) {
140 packet.yiaddr = req_align; /* FIXME: oh my, is there a host using this IP? */ 148 packet.yiaddr = req_align; /* FIXME: oh my, is there a host using this IP? */
141 149
142 /* otherwise, find a free IP */ /*ADDME: is it a static lease? */ 150 /* otherwise, find a free IP */
143 } else { 151 } else {
152 /* Is it a static lease? (No, because find_address skips static lease) */
144 packet.yiaddr = find_address(0); 153 packet.yiaddr = find_address(0);
145 154
146 /* try for an expired lease */ 155 /* try for an expired lease */
@@ -167,7 +176,14 @@ int sendOffer(struct dhcpMessage *oldpacket)
167 /* Make sure we aren't just using the lease time from the previous offer */ 176 /* Make sure we aren't just using the lease time from the previous offer */
168 if (lease_time_align < server_config.min_lease) 177 if (lease_time_align < server_config.min_lease)
169 lease_time_align = server_config.lease; 178 lease_time_align = server_config.lease;
179 }
170 /* ADDME: end of short circuit */ 180 /* ADDME: end of short circuit */
181 else
182 {
183 /* It is a static lease... use it */
184 packet.yiaddr = static_lease_ip;
185 }
186
171 add_simple_option(packet.options, DHCP_LEASE_TIME, htonl(lease_time_align)); 187 add_simple_option(packet.options, DHCP_LEASE_TIME, htonl(lease_time_align));
172 188
173 curr = server_config.options; 189 curr = server_config.options;