169 |
ifaces = dev; |
ifaces = dev; |
170 |
} |
} |
171 |
|
|
172 |
|
/* |
173 |
|
* Returns: |
174 |
|
* 0 = Not handled, the packet is still in the queue |
175 |
|
* 1 = Handled |
176 |
|
*/ |
177 |
static int process_receive_event(struct state *s, time_t now) |
static int process_receive_event(struct state *s, time_t now) |
178 |
{ |
{ |
179 |
int handled = 1; |
int handled = 1; |
187 |
break; |
break; |
188 |
case 1: |
case 1: |
189 |
s->state = DEVST_COMPLETE; |
s->state = DEVST_COMPLETE; |
190 |
DEBUG(("\n bootp reply\n")); |
dprintf("\n bootp reply\n"); |
191 |
break; |
break; |
192 |
} |
} |
193 |
break; |
break; |
219 |
break; |
break; |
220 |
} |
} |
221 |
break; |
break; |
222 |
|
|
223 |
|
default: |
224 |
|
dprintf("\n"); |
225 |
|
handled = 0; |
226 |
|
break; |
227 |
} |
} |
228 |
|
|
229 |
switch (s->state) { |
switch (s->state) { |
234 |
case DEVST_ERROR: |
case DEVST_ERROR: |
235 |
/* error occurred, try again in 10 seconds */ |
/* error occurred, try again in 10 seconds */ |
236 |
s->expire = now + 10; |
s->expire = now + 10; |
|
default: |
|
|
DEBUG(("\n")); |
|
|
handled = 0; |
|
237 |
break; |
break; |
238 |
} |
} |
239 |
|
|
295 |
static struct state *slist; |
static struct state *slist; |
296 |
struct netdev *ifaces; |
struct netdev *ifaces; |
297 |
|
|
298 |
|
/* |
299 |
|
* Returns: |
300 |
|
* 0 = Error, packet not received or discarded |
301 |
|
* 1 = A packet was received and handled |
302 |
|
*/ |
303 |
static int do_pkt_recv(int pkt_fd, time_t now) |
static int do_pkt_recv(int pkt_fd, time_t now) |
304 |
{ |
{ |
305 |
int ifindex, ret; |
int ifindex, ret; |
306 |
struct state *s; |
struct state *s; |
307 |
|
|
308 |
ret = packet_peek(&ifindex); |
ret = packet_peek(&ifindex); |
309 |
if (ret < 0) |
if (ret == 0) |
310 |
goto bail; |
return ret; |
311 |
|
|
312 |
for (s = slist; s; s = s->next) { |
for (s = slist; s; s = s->next) { |
313 |
if (s->dev->ifindex == ifindex) { |
if (s->dev->ifindex == ifindex) { |
314 |
ret |= process_receive_event(s, now); |
ret = process_receive_event(s, now); |
315 |
break; |
break; |
316 |
} |
} |
317 |
} |
} |
318 |
|
|
319 |
bail: |
if (ret == 0) |
320 |
|
packet_discard(); |
321 |
|
|
322 |
return ret; |
return ret; |
323 |
} |
} |
324 |
|
|
351 |
int x; |
int x; |
352 |
|
|
353 |
for (s = slist; s; s = s->next) { |
for (s = slist; s; s = s->next) { |
354 |
DEBUG(("%s: state = %d\n", s->dev->name, s->state)); |
dprintf("%s: state = %d\n", s->dev->name, s->state); |
355 |
|
|
356 |
if (s->state == DEVST_COMPLETE) { |
if (s->state == DEVST_COMPLETE) { |
357 |
done++; |
done++; |
361 |
pending++; |
pending++; |
362 |
|
|
363 |
if (s->expire - now.tv_sec <= 0) { |
if (s->expire - now.tv_sec <= 0) { |
364 |
DEBUG(("timeout\n")); |
dprintf("timeout\n"); |
365 |
process_timeout_event(s, now.tv_sec); |
process_timeout_event(s, now.tv_sec); |
366 |
} |
} |
367 |
|
|
385 |
gettimeofday(&now, NULL); |
gettimeofday(&now, NULL); |
386 |
|
|
387 |
if ((fds[0].revents & POLLRDNORM)) { |
if ((fds[0].revents & POLLRDNORM)) { |
388 |
nr = do_pkt_recv(pkt_fd, now.tv_sec); |
if (do_pkt_recv(pkt_fd, now.tv_sec) == 1) |
|
if (nr == 1) |
|
389 |
break; |
break; |
|
else if (nr == 0) |
|
|
packet_discard(); |
|
390 |
} |
} |
391 |
|
|
392 |
if (loop_timeout >= 0 && |
if (loop_timeout >= 0 && |
399 |
delta_ms = (now.tv_sec - prev.tv_sec) * 1000; |
delta_ms = (now.tv_sec - prev.tv_sec) * 1000; |
400 |
delta_ms += (now.tv_usec - prev.tv_usec) / 1000; |
delta_ms += (now.tv_usec - prev.tv_usec) / 1000; |
401 |
|
|
402 |
DEBUG(("Delta: %d ms\n", delta_ms)); |
dprintf("Delta: %d ms\n", delta_ms); |
403 |
|
|
404 |
timeout_ms -= delta_ms; |
timeout_ms -= delta_ms; |
405 |
} |
} |
483 |
int i, opt; |
int i, opt; |
484 |
int is_ip = 0; |
int is_ip = 0; |
485 |
|
|
486 |
DEBUG(("IP-Config: parse_device: \"%s\"\n", ip)); |
dprintf("IP-Config: parse_device: \"%s\"\n", ip); |
487 |
|
|
488 |
if (strncmp(ip, "ip=", 3) == 0) { |
if (strncmp(ip, "ip=", 3) == 0) { |
489 |
ip += 3; |
ip += 3; |
515 |
|
|
516 |
if (*ip == '\0') |
if (*ip == '\0') |
517 |
continue; |
continue; |
518 |
DEBUG(("IP-Config: opt #%d: '%s'\n", opt, ip)); |
dprintf("IP-Config: opt #%d: '%s'\n", opt, ip); |
519 |
switch (opt) { |
switch (opt) { |
520 |
case 0: |
case 0: |
521 |
parse_addr(&dev->ip_addr, ip); |
parse_addr(&dev->ip_addr, ip); |
533 |
case 4: |
case 4: |
534 |
strncpy(dev->hostname, ip, SYS_NMLN - 1); |
strncpy(dev->hostname, ip, SYS_NMLN - 1); |
535 |
dev->hostname[SYS_NMLN - 1] = '\0'; |
dev->hostname[SYS_NMLN - 1] = '\0'; |
536 |
|
memcpy(dev->reqhostname, dev->hostname, |
537 |
|
SYS_NMLN); |
538 |
break; |
break; |
539 |
case 5: |
case 5: |
540 |
dev->name = ip; |
dev->name = ip; |
582 |
dev->ip_nameserver[1] = template->ip_nameserver[1]; |
dev->ip_nameserver[1] = template->ip_nameserver[1]; |
583 |
if (template->hostname[0] != '\0') |
if (template->hostname[0] != '\0') |
584 |
strcpy(dev->hostname, template->hostname); |
strcpy(dev->hostname, template->hostname); |
585 |
|
if (template->reqhostname[0] != '\0') |
586 |
|
strcpy(dev->reqhostname, template->reqhostname); |
587 |
dev->caps &= template->caps; |
dev->caps &= template->caps; |
588 |
|
|
589 |
bringup_device(dev); |
bringup_device(dev); |
666 |
logic the in-kernel ipconfig uses... */ |
logic the in-kernel ipconfig uses... */ |
667 |
if (!(flags & IFF_LOOPBACK) && |
if (!(flags & IFF_LOOPBACK) && |
668 |
(flags & (IFF_BROADCAST | IFF_POINTOPOINT))) { |
(flags & (IFF_BROADCAST | IFF_POINTOPOINT))) { |
669 |
DEBUG(("Trying to bring up %s\n", de->d_name)); |
dprintf("Trying to bring up %s\n", de->d_name); |
670 |
|
|
671 |
if (!(dev = add_device(de->d_name))) |
if (!(dev = add_device(de->d_name))) |
672 |
continue; |
continue; |