diff options
author | Eric Andersen <andersen@codepoet.org> | 2004-10-08 08:49:26 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2004-10-08 08:49:26 +0000 |
commit | abf58d6ba5df9bbe04c4c7008cbbc8c7dc626392 (patch) | |
tree | c64a5328d250449c9a4e3964d59a657543e06440 /networking/udhcp/dhcpd.c | |
parent | 751750e3ee0195eef802a1554e97712285bf8fd7 (diff) | |
download | busybox-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/dhcpd.c')
-rw-r--r-- | networking/udhcp/dhcpd.c | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/networking/udhcp/dhcpd.c b/networking/udhcp/dhcpd.c index 6f38f07f7..ab3ddfe4f 100644 --- a/networking/udhcp/dhcpd.c +++ b/networking/udhcp/dhcpd.c | |||
@@ -44,6 +44,7 @@ | |||
44 | #include "serverpacket.h" | 44 | #include "serverpacket.h" |
45 | #include "common.h" | 45 | #include "common.h" |
46 | #include "signalpipe.h" | 46 | #include "signalpipe.h" |
47 | #include "static_leases.h" | ||
47 | 48 | ||
48 | 49 | ||
49 | /* globals */ | 50 | /* globals */ |
@@ -68,9 +69,12 @@ int main(int argc, char *argv[]) | |||
68 | unsigned long timeout_end; | 69 | unsigned long timeout_end; |
69 | struct option_set *option; | 70 | struct option_set *option; |
70 | struct dhcpOfferedAddr *lease; | 71 | struct dhcpOfferedAddr *lease; |
72 | struct dhcpOfferedAddr static_lease; | ||
71 | int max_sock; | 73 | int max_sock; |
72 | unsigned long num_ips; | 74 | unsigned long num_ips; |
73 | 75 | ||
76 | uint32_t static_lease_ip; | ||
77 | |||
74 | memset(&server_config, 0, sizeof(struct server_config_t)); | 78 | memset(&server_config, 0, sizeof(struct server_config_t)); |
75 | read_config(argc < 2 ? DHCPD_CONF_FILE : argv[1]); | 79 | read_config(argc < 2 ? DHCPD_CONF_FILE : argv[1]); |
76 | 80 | ||
@@ -162,8 +166,25 @@ int main(int argc, char *argv[]) | |||
162 | continue; | 166 | continue; |
163 | } | 167 | } |
164 | 168 | ||
165 | /* ADDME: look for a static lease */ | 169 | /* Look for a static lease */ |
170 | static_lease_ip = getIpByMac(server_config.static_leases, &packet.chaddr); | ||
171 | |||
172 | if(static_lease_ip) | ||
173 | { | ||
174 | printf("Found static lease: %x\n", static_lease_ip); | ||
175 | |||
176 | memcpy(&static_lease.chaddr, &packet.chaddr, 16); | ||
177 | static_lease.yiaddr = static_lease_ip; | ||
178 | static_lease.expires = 0; | ||
179 | |||
180 | lease = &static_lease; | ||
181 | |||
182 | } | ||
183 | else | ||
184 | { | ||
166 | lease = find_lease_by_chaddr(packet.chaddr); | 185 | lease = find_lease_by_chaddr(packet.chaddr); |
186 | } | ||
187 | |||
167 | switch (state[0]) { | 188 | switch (state[0]) { |
168 | case DHCPDISCOVER: | 189 | case DHCPDISCOVER: |
169 | DEBUG(LOG_INFO,"received DISCOVER"); | 190 | DEBUG(LOG_INFO,"received DISCOVER"); |
@@ -181,7 +202,7 @@ int main(int argc, char *argv[]) | |||
181 | if (requested) memcpy(&requested_align, requested, 4); | 202 | if (requested) memcpy(&requested_align, requested, 4); |
182 | if (server_id) memcpy(&server_id_align, server_id, 4); | 203 | if (server_id) memcpy(&server_id_align, server_id, 4); |
183 | 204 | ||
184 | if (lease) { /*ADDME: or static lease */ | 205 | if (lease) { |
185 | if (server_id) { | 206 | if (server_id) { |
186 | /* SELECTING State */ | 207 | /* SELECTING State */ |
187 | DEBUG(LOG_INFO, "server_id = %08x", ntohl(server_id_align)); | 208 | DEBUG(LOG_INFO, "server_id = %08x", ntohl(server_id_align)); |