blob: 4f7b520567cb892d61305ccc27ebb622f3a8f918 [file] [log] [blame]
"Robert P. J. Day"63fc1a92006-07-02 19:47:05 +00001/* vi: set sw=4 ts=4: */
Mike Frysinger7031f622006-05-08 03:20:50 +00002/*
3 * files.c -- DHCP server file manipulation *
4 * Rewrite by Russ Dill <Russ.Dill@asu.edu> July 2001
Denis Vlasenkodb12d1d2008-12-07 00:52:58 +00005 *
6 * Licensed under GPLv2, see file LICENSE in this tarball for details.
Mike Frysinger7031f622006-05-08 03:20:50 +00007 */
8
Mike Frysinger7031f622006-05-08 03:20:50 +00009#include <netinet/ether.h>
Mike Frysinger7031f622006-05-08 03:20:50 +000010
Denis Vlasenko5a3395b2006-11-18 19:51:32 +000011#include "common.h"
Mike Frysinger7031f622006-05-08 03:20:50 +000012#include "dhcpd.h"
13#include "options.h"
Denis Vlasenko5a3395b2006-11-18 19:51:32 +000014
Mike Frysinger7031f622006-05-08 03:20:50 +000015
Denis Vlasenkoc82b5102007-07-01 17:05:57 +000016/* on these functions, make sure your datatype matches */
Mike Frysinger7031f622006-05-08 03:20:50 +000017static int read_ip(const char *line, void *arg)
18{
Denis Vlasenkoe9913032007-02-04 02:41:57 +000019 len_and_sockaddr *lsa;
Mike Frysinger7031f622006-05-08 03:20:50 +000020
Denis Vlasenkoe9913032007-02-04 02:41:57 +000021 lsa = host_and_af2sockaddr(line, 0, AF_INET);
Denis Vlasenko42b3dea2007-07-03 15:47:50 +000022 if (!lsa)
23 return 0;
Bernhard Reutner-Fischer8c69afd2008-01-29 10:33:34 +000024 *(uint32_t*)arg = lsa->u.sin.sin_addr.s_addr;
Denis Vlasenko42b3dea2007-07-03 15:47:50 +000025 free(lsa);
26 return 1;
Mike Frysinger7031f622006-05-08 03:20:50 +000027}
28
29static int read_mac(const char *line, void *arg)
30{
Mike Frysinger7031f622006-05-08 03:20:50 +000031 struct ether_addr *temp_ether_addr;
Mike Frysinger7031f622006-05-08 03:20:50 +000032
Denis Vlasenkofcc63472008-04-10 02:09:40 +000033 temp_ether_addr = ether_aton_r(line, (struct ether_addr *)arg);
Denis Vlasenko5a3395b2006-11-18 19:51:32 +000034 if (temp_ether_addr == NULL)
Denis Vlasenkoc82b5102007-07-01 17:05:57 +000035 return 0;
Denis Vlasenkoc82b5102007-07-01 17:05:57 +000036 return 1;
Mike Frysinger7031f622006-05-08 03:20:50 +000037}
38
39
40static int read_str(const char *line, void *arg)
41{
42 char **dest = arg;
43
44 free(*dest);
Denis Vlasenko4ebaf102007-01-19 21:33:19 +000045 *dest = xstrdup(line);
Mike Frysinger7031f622006-05-08 03:20:50 +000046 return 1;
47}
48
49
50static int read_u32(const char *line, void *arg)
51{
Denis Vlasenkoc82b5102007-07-01 17:05:57 +000052 *(uint32_t*)arg = bb_strtou32(line, NULL, 10);
Denis Vlasenkod686a042006-11-27 14:43:21 +000053 return errno == 0;
Mike Frysinger7031f622006-05-08 03:20:50 +000054}
55
56
57static int read_yn(const char *line, void *arg)
58{
59 char *dest = arg;
Mike Frysinger7031f622006-05-08 03:20:50 +000060
Denis Vlasenkoc82b5102007-07-01 17:05:57 +000061 if (!strcasecmp("yes", line)) {
Mike Frysinger7031f622006-05-08 03:20:50 +000062 *dest = 1;
Denis Vlasenkoc82b5102007-07-01 17:05:57 +000063 return 1;
64 }
65 if (!strcasecmp("no", line)) {
Mike Frysinger7031f622006-05-08 03:20:50 +000066 *dest = 0;
Denis Vlasenkoc82b5102007-07-01 17:05:57 +000067 return 1;
68 }
69 return 0;
Mike Frysinger7031f622006-05-08 03:20:50 +000070}
71
72
73/* find option 'code' in opt_list */
Denis Vlasenkof1980f62008-09-26 09:34:59 +000074struct option_set* FAST_FUNC find_option(struct option_set *opt_list, uint8_t code)
Mike Frysinger7031f622006-05-08 03:20:50 +000075{
76 while (opt_list && opt_list->data[OPT_CODE] < code)
77 opt_list = opt_list->next;
78
Denis Vlasenkoc82b5102007-07-01 17:05:57 +000079 if (opt_list && opt_list->data[OPT_CODE] == code)
80 return opt_list;
81 return NULL;
Mike Frysinger7031f622006-05-08 03:20:50 +000082}
83
84
85/* add an option to the opt_list */
Denis Vlasenkoc90c3f32006-11-23 12:57:49 +000086static void attach_option(struct option_set **opt_list,
87 const struct dhcp_option *option, char *buffer, int length)
Mike Frysinger7031f622006-05-08 03:20:50 +000088{
89 struct option_set *existing, *new, **curr;
90
Denis Vlasenkod686a042006-11-27 14:43:21 +000091 existing = find_option(*opt_list, option->code);
Denis Vlasenkoc4d606e2007-02-02 01:16:08 +000092 if (!existing) {
Denis Vlasenko35ff7462007-11-28 19:23:12 +000093 DEBUG("Attaching option %02x to list", option->code);
Mike Frysinger7031f622006-05-08 03:20:50 +000094
Denis Vlasenko35a064b2008-11-06 00:49:59 +000095#if ENABLE_FEATURE_UDHCP_RFC3397
Denis Vlasenko50664732007-02-27 21:15:08 +000096 if ((option->flags & TYPE_MASK) == OPTION_STR1035)
97 /* reuse buffer and length for RFC1035-formatted string */
Denis Vlasenkoc4f12f52008-05-12 14:35:56 +000098 buffer = (char *)dname_enc(NULL, 0, buffer, &length);
Denis Vlasenko50664732007-02-27 21:15:08 +000099#endif
100
Mike Frysinger7031f622006-05-08 03:20:50 +0000101 /* make a new option */
Denis Vlasenkoc82b5102007-07-01 17:05:57 +0000102 new = xmalloc(sizeof(*new));
Mike Frysinger7031f622006-05-08 03:20:50 +0000103 new->data = xmalloc(length + 2);
104 new->data[OPT_CODE] = option->code;
105 new->data[OPT_LEN] = length;
106 memcpy(new->data + 2, buffer, length);
107
108 curr = opt_list;
109 while (*curr && (*curr)->data[OPT_CODE] < option->code)
110 curr = &(*curr)->next;
111
112 new->next = *curr;
113 *curr = new;
Denis Vlasenko35a064b2008-11-06 00:49:59 +0000114#if ENABLE_FEATURE_UDHCP_RFC3397
Denis Vlasenko50664732007-02-27 21:15:08 +0000115 if ((option->flags & TYPE_MASK) == OPTION_STR1035 && buffer != NULL)
116 free(buffer);
117#endif
Denis Vlasenkoc4d606e2007-02-02 01:16:08 +0000118 return;
Mike Frysinger7031f622006-05-08 03:20:50 +0000119 }
Denis Vlasenkoc4d606e2007-02-02 01:16:08 +0000120
121 /* add it to an existing option */
Denis Vlasenko35ff7462007-11-28 19:23:12 +0000122 DEBUG("Attaching option %02x to existing member of list", option->code);
Denis Vlasenkoc4d606e2007-02-02 01:16:08 +0000123 if (option->flags & OPTION_LIST) {
Denis Vlasenko35a064b2008-11-06 00:49:59 +0000124#if ENABLE_FEATURE_UDHCP_RFC3397
Denis Vlasenko50664732007-02-27 21:15:08 +0000125 if ((option->flags & TYPE_MASK) == OPTION_STR1035)
126 /* reuse buffer and length for RFC1035-formatted string */
Denis Vlasenkoc4f12f52008-05-12 14:35:56 +0000127 buffer = (char *)dname_enc(existing->data + 2,
Denis Vlasenko50664732007-02-27 21:15:08 +0000128 existing->data[OPT_LEN], buffer, &length);
129#endif
Denis Vlasenkoc4d606e2007-02-02 01:16:08 +0000130 if (existing->data[OPT_LEN] + length <= 255) {
131 existing->data = xrealloc(existing->data,
132 existing->data[OPT_LEN] + length + 3);
133 if ((option->flags & TYPE_MASK) == OPTION_STRING) {
Denis Vlasenkoe129f432007-02-02 01:57:24 +0000134 /* ' ' can bring us to 256 - bad */
Denis Vlasenkoc4d606e2007-02-02 01:16:08 +0000135 if (existing->data[OPT_LEN] + length >= 255)
136 return;
137 /* add space separator between STRING options in a list */
138 existing->data[existing->data[OPT_LEN] + 2] = ' ';
139 existing->data[OPT_LEN]++;
140 }
141 memcpy(existing->data + existing->data[OPT_LEN] + 2, buffer, length);
142 existing->data[OPT_LEN] += length;
143 } /* else, ignore the data, we could put this in a second option in the future */
Denis Vlasenko35a064b2008-11-06 00:49:59 +0000144#if ENABLE_FEATURE_UDHCP_RFC3397
Denis Vlasenko50664732007-02-27 21:15:08 +0000145 if ((option->flags & TYPE_MASK) == OPTION_STR1035 && buffer != NULL)
146 free(buffer);
147#endif
Denis Vlasenkoc4d606e2007-02-02 01:16:08 +0000148 } /* else, ignore the new data */
Mike Frysinger7031f622006-05-08 03:20:50 +0000149}
150
151
152/* read a dhcp option and add it to opt_list */
153static int read_opt(const char *const_line, void *arg)
154{
155 struct option_set **opt_list = arg;
156 char *opt, *val, *endptr;
Mike Frysinger7031f622006-05-08 03:20:50 +0000157 char *line;
Denis Vlasenkob539c842007-11-29 08:17:45 +0000158 const struct dhcp_option *option;
159 int retval, length, idx;
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +0000160 char buffer[8] ALIGNED(4);
Mike Frysinger7031f622006-05-08 03:20:50 +0000161 uint16_t *result_u16 = (uint16_t *) buffer;
162 uint32_t *result_u32 = (uint32_t *) buffer;
163
164 /* Cheat, the only const line we'll actually get is "" */
165 line = (char *) const_line;
Denis Vlasenkoc90c3f32006-11-23 12:57:49 +0000166 opt = strtok(line, " \t=");
Denis Vlasenkob539c842007-11-29 08:17:45 +0000167 if (!opt)
168 return 0;
Mike Frysinger7031f622006-05-08 03:20:50 +0000169
Denis Vlasenko027271e2008-03-20 12:47:01 +0000170 idx = index_in_strings(dhcp_option_strings, opt); /* NB: was strcasecmp! */
Denis Vlasenkob539c842007-11-29 08:17:45 +0000171 if (idx < 0)
172 return 0;
173 option = &dhcp_options[idx];
Mike Frysinger7031f622006-05-08 03:20:50 +0000174
Denis Vlasenkob539c842007-11-29 08:17:45 +0000175 retval = 0;
Mike Frysinger7031f622006-05-08 03:20:50 +0000176 do {
Denis Vlasenkoc90c3f32006-11-23 12:57:49 +0000177 val = strtok(NULL, ", \t");
178 if (!val) break;
Denis Vlasenkob539c842007-11-29 08:17:45 +0000179 length = dhcp_option_lengths[option->flags & TYPE_MASK];
Mike Frysinger7031f622006-05-08 03:20:50 +0000180 retval = 0;
181 opt = buffer; /* new meaning for variable opt */
182 switch (option->flags & TYPE_MASK) {
183 case OPTION_IP:
184 retval = read_ip(val, buffer);
185 break;
186 case OPTION_IP_PAIR:
187 retval = read_ip(val, buffer);
Denis Vlasenkoc82b5102007-07-01 17:05:57 +0000188 val = strtok(NULL, ", \t/-");
189 if (!val)
190 retval = 0;
191 if (retval)
192 retval = read_ip(val, buffer + 4);
Mike Frysinger7031f622006-05-08 03:20:50 +0000193 break;
194 case OPTION_STRING:
Denis Vlasenko35a064b2008-11-06 00:49:59 +0000195#if ENABLE_FEATURE_UDHCP_RFC3397
Denis Vlasenko50664732007-02-27 21:15:08 +0000196 case OPTION_STR1035:
197#endif
Mike Frysinger7031f622006-05-08 03:20:50 +0000198 length = strlen(val);
199 if (length > 0) {
200 if (length > 254) length = 254;
201 opt = val;
202 retval = 1;
203 }
204 break;
205 case OPTION_BOOLEAN:
206 retval = read_yn(val, buffer);
207 break;
208 case OPTION_U8:
209 buffer[0] = strtoul(val, &endptr, 0);
210 retval = (endptr[0] == '\0');
211 break;
Denis Vlasenkoc82b5102007-07-01 17:05:57 +0000212 /* htonX are macros in older libc's, using temp var
213 * in code below for safety */
214 /* TODO: use bb_strtoX? */
215 case OPTION_U16: {
216 unsigned long tmp = strtoul(val, &endptr, 0);
217 *result_u16 = htons(tmp);
218 retval = (endptr[0] == '\0' /*&& tmp < 0x10000*/);
219 break;
220 }
221 case OPTION_S16: {
222 long tmp = strtol(val, &endptr, 0);
223 *result_u16 = htons(tmp);
Mike Frysinger7031f622006-05-08 03:20:50 +0000224 retval = (endptr[0] == '\0');
225 break;
Denis Vlasenkoc82b5102007-07-01 17:05:57 +0000226 }
227 case OPTION_U32: {
228 unsigned long tmp = strtoul(val, &endptr, 0);
229 *result_u32 = htonl(tmp);
Mike Frysinger7031f622006-05-08 03:20:50 +0000230 retval = (endptr[0] == '\0');
231 break;
Denis Vlasenkoc82b5102007-07-01 17:05:57 +0000232 }
233 case OPTION_S32: {
234 long tmp = strtol(val, &endptr, 0);
235 *result_u32 = htonl(tmp);
Mike Frysinger7031f622006-05-08 03:20:50 +0000236 retval = (endptr[0] == '\0');
237 break;
Denis Vlasenkoc82b5102007-07-01 17:05:57 +0000238 }
Mike Frysinger7031f622006-05-08 03:20:50 +0000239 default:
240 break;
241 }
242 if (retval)
243 attach_option(opt_list, option, opt, length);
244 } while (retval && option->flags & OPTION_LIST);
245 return retval;
246}
247
248static int read_staticlease(const char *const_line, void *arg)
249{
Mike Frysinger7031f622006-05-08 03:20:50 +0000250 char *line;
251 char *mac_string;
252 char *ip_string;
253 uint8_t *mac_bytes;
254 uint32_t *ip;
255
Mike Frysinger7031f622006-05-08 03:20:50 +0000256 /* Allocate memory for addresses */
257 mac_bytes = xmalloc(sizeof(unsigned char) * 8);
258 ip = xmalloc(sizeof(uint32_t));
259
260 /* Read mac */
261 line = (char *) const_line;
262 mac_string = strtok(line, " \t");
263 read_mac(mac_string, mac_bytes);
264
265 /* Read ip */
266 ip_string = strtok(NULL, " \t");
267 read_ip(ip_string, ip);
268
269 addStaticLease(arg, mac_bytes, ip);
270
Denis Vlasenko35a064b2008-11-06 00:49:59 +0000271 if (ENABLE_UDHCP_DEBUG) printStaticLeases(arg);
Mike Frysinger7031f622006-05-08 03:20:50 +0000272
273 return 1;
Mike Frysinger7031f622006-05-08 03:20:50 +0000274}
275
276
Denis Vlasenkoc82b5102007-07-01 17:05:57 +0000277struct config_keyword {
278 const char *keyword;
279 int (*handler)(const char *line, void *var);
280 void *var;
281 const char *def;
Mike Frysinger7031f622006-05-08 03:20:50 +0000282};
283
Denis Vlasenkoc82b5102007-07-01 17:05:57 +0000284static const struct config_keyword keywords[] = {
285 /* keyword handler variable address default */
286 {"start", read_ip, &(server_config.start_ip), "192.168.0.20"},
287 {"end", read_ip, &(server_config.end_ip), "192.168.0.254"},
288 {"interface", read_str, &(server_config.interface), "eth0"},
Denis Vlasenkoc82b5102007-07-01 17:05:57 +0000289 /* Avoid "max_leases value not sane" warning by setting default
290 * to default_end_ip - default_start_ip + 1: */
291 {"max_leases", read_u32, &(server_config.max_leases), "235"},
292 {"remaining", read_yn, &(server_config.remaining), "yes"},
293 {"auto_time", read_u32, &(server_config.auto_time), "7200"},
294 {"decline_time", read_u32, &(server_config.decline_time), "3600"},
295 {"conflict_time",read_u32, &(server_config.conflict_time),"3600"},
296 {"offer_time", read_u32, &(server_config.offer_time), "60"},
297 {"min_lease", read_u32, &(server_config.min_lease), "60"},
298 {"lease_file", read_str, &(server_config.lease_file), LEASES_FILE},
299 {"pidfile", read_str, &(server_config.pidfile), "/var/run/udhcpd.pid"},
Denis Vlasenkoc82b5102007-07-01 17:05:57 +0000300 {"siaddr", read_ip, &(server_config.siaddr), "0.0.0.0"},
Denis Vlasenko027271e2008-03-20 12:47:01 +0000301 /* keywords with no defaults must be last! */
302 {"option", read_opt, &(server_config.options), ""},
303 {"opt", read_opt, &(server_config.options), ""},
304 {"notify_file", read_str, &(server_config.notify_file), ""},
Denis Vlasenkoc82b5102007-07-01 17:05:57 +0000305 {"sname", read_str, &(server_config.sname), ""},
306 {"boot_file", read_str, &(server_config.boot_file), ""},
307 {"static_lease", read_staticlease, &(server_config.static_leases), ""},
308 /* ADDME: static lease */
309};
Denis Vlasenko027271e2008-03-20 12:47:01 +0000310enum { KWS_WITH_DEFAULTS = ARRAY_SIZE(keywords) - 6 };
Denis Vlasenkoc82b5102007-07-01 17:05:57 +0000311
Denis Vlasenkof1980f62008-09-26 09:34:59 +0000312void FAST_FUNC read_config(const char *file)
Mike Frysinger7031f622006-05-08 03:20:50 +0000313{
Denis Vlasenkoeb751292008-07-20 17:58:12 +0000314 parser_t *parser;
315 const struct config_keyword *k;
316 unsigned i;
317 char *token[2];
Mike Frysinger7031f622006-05-08 03:20:50 +0000318
Denis Vlasenko027271e2008-03-20 12:47:01 +0000319 for (i = 0; i < KWS_WITH_DEFAULTS; i++)
320 keywords[i].handler(keywords[i].def, keywords[i].var);
Mike Frysinger7031f622006-05-08 03:20:50 +0000321
Denis Vlasenkoeb751292008-07-20 17:58:12 +0000322 parser = config_open(file);
Denis Vlasenko084266e2008-07-26 23:08:31 +0000323 while (config_read(parser, token, 2, 2, "# \t", PARSE_NORMAL)) {
Denis Vlasenkoeb751292008-07-20 17:58:12 +0000324 for (k = keywords, i = 0; i < ARRAY_SIZE(keywords); k++, i++) {
325 if (!strcasecmp(token[0], k->keyword)) {
326 if (!k->handler(token[1], k->var)) {
327 bb_error_msg("can't parse line %u in %s",
328 parser->lineno, file);
Mike Frysinger7031f622006-05-08 03:20:50 +0000329 /* reset back to the default value */
Denis Vlasenkoeb751292008-07-20 17:58:12 +0000330 k->handler(k->def, k->var);
Mike Frysinger7031f622006-05-08 03:20:50 +0000331 }
Denis Vlasenko027271e2008-03-20 12:47:01 +0000332 break;
333 }
334 }
Mike Frysinger7031f622006-05-08 03:20:50 +0000335 }
Denis Vlasenkoeb751292008-07-20 17:58:12 +0000336 config_close(parser);
Denis Vlasenkoc82b5102007-07-01 17:05:57 +0000337
338 server_config.start_ip = ntohl(server_config.start_ip);
339 server_config.end_ip = ntohl(server_config.end_ip);
Mike Frysinger7031f622006-05-08 03:20:50 +0000340}
341
342
Denis Vlasenkof1980f62008-09-26 09:34:59 +0000343void FAST_FUNC write_leases(void)
Mike Frysinger7031f622006-05-08 03:20:50 +0000344{
Denis Vlasenko61126ab2006-11-18 22:03:26 +0000345 int fp;
346 unsigned i;
Mike Frysinger7031f622006-05-08 03:20:50 +0000347 time_t curr = time(0);
348 unsigned long tmp_time;
349
Denis Vlasenko62a90cd2008-03-17 09:07:36 +0000350 fp = open_or_warn(server_config.lease_file, O_WRONLY|O_CREAT|O_TRUNC);
Denis Vlasenko61126ab2006-11-18 22:03:26 +0000351 if (fp < 0) {
Mike Frysinger7031f622006-05-08 03:20:50 +0000352 return;
353 }
354
355 for (i = 0; i < server_config.max_leases; i++) {
356 if (leases[i].yiaddr != 0) {
357
358 /* screw with the time in the struct, for easier writing */
359 tmp_time = leases[i].expires;
360
361 if (server_config.remaining) {
362 if (lease_expired(&(leases[i])))
363 leases[i].expires = 0;
364 else leases[i].expires -= curr;
365 } /* else stick with the time we got */
366 leases[i].expires = htonl(leases[i].expires);
Denis Vlasenko61126ab2006-11-18 22:03:26 +0000367 // FIXME: error check??
368 full_write(fp, &leases[i], sizeof(leases[i]));
Mike Frysinger7031f622006-05-08 03:20:50 +0000369
Denis Vlasenko61126ab2006-11-18 22:03:26 +0000370 /* then restore it when done */
Mike Frysinger7031f622006-05-08 03:20:50 +0000371 leases[i].expires = tmp_time;
372 }
373 }
Denis Vlasenko61126ab2006-11-18 22:03:26 +0000374 close(fp);
Mike Frysinger7031f622006-05-08 03:20:50 +0000375
376 if (server_config.notify_file) {
Denis Vlasenko2e4c3c42008-04-02 13:04:19 +0000377// TODO: vfork-based child creation
Denis Vlasenko61126ab2006-11-18 22:03:26 +0000378 char *cmd = xasprintf("%s %s", server_config.notify_file, server_config.lease_file);
379 system(cmd);
380 free(cmd);
Mike Frysinger7031f622006-05-08 03:20:50 +0000381 }
382}
383
384
Denis Vlasenkof1980f62008-09-26 09:34:59 +0000385void FAST_FUNC read_leases(const char *file)
Mike Frysinger7031f622006-05-08 03:20:50 +0000386{
Denis Vlasenko61126ab2006-11-18 22:03:26 +0000387 int fp;
Denis Vlasenko2e4c3c42008-04-02 13:04:19 +0000388 unsigned i;
Mike Frysinger7031f622006-05-08 03:20:50 +0000389 struct dhcpOfferedAddr lease;
390
Denis Vlasenko50f7f442007-04-11 23:20:53 +0000391 fp = open_or_warn(file, O_RDONLY);
Denis Vlasenko61126ab2006-11-18 22:03:26 +0000392 if (fp < 0) {
Mike Frysinger7031f622006-05-08 03:20:50 +0000393 return;
394 }
395
Denis Vlasenko2e4c3c42008-04-02 13:04:19 +0000396 i = 0;
Denis Vlasenko61126ab2006-11-18 22:03:26 +0000397 while (i < server_config.max_leases
398 && full_read(fp, &lease, sizeof(lease)) == sizeof(lease)
399 ) {
Mike Frysinger7031f622006-05-08 03:20:50 +0000400 /* ADDME: is it a static lease */
Denis Vlasenkoc82b5102007-07-01 17:05:57 +0000401 uint32_t y = ntohl(lease.yiaddr);
402 if (y >= server_config.start_ip && y <= server_config.end_ip) {
Mike Frysinger7031f622006-05-08 03:20:50 +0000403 lease.expires = ntohl(lease.expires);
Denis Vlasenkoc82b5102007-07-01 17:05:57 +0000404 if (!server_config.remaining)
Denis Vlasenko2e4c3c42008-04-02 13:04:19 +0000405 lease.expires -= time(NULL);
Mike Frysinger7031f622006-05-08 03:20:50 +0000406 if (!(add_lease(lease.chaddr, lease.yiaddr, lease.expires))) {
Denis Vlasenkoe1a0d482006-10-20 13:28:22 +0000407 bb_error_msg("too many leases while loading %s", file);
Mike Frysinger7031f622006-05-08 03:20:50 +0000408 break;
409 }
410 i++;
411 }
412 }
Denis Vlasenko3538b9a2006-09-06 18:36:50 +0000413 DEBUG("Read %d leases", i);
Denis Vlasenko61126ab2006-11-18 22:03:26 +0000414 close(fp);
Mike Frysinger7031f622006-05-08 03:20:50 +0000415}