1996-09-05 23:55:39 +00:00
|
|
|
/* dispatch.c
|
1996-04-11 06:44:12 +00:00
|
|
|
|
1996-09-05 23:55:39 +00:00
|
|
|
Network input dispatcher... */
|
1996-04-11 06:44:12 +00:00
|
|
|
|
|
|
|
/*
|
1999-03-16 05:50:46 +00:00
|
|
|
* Copyright (c) 1996-1999 Internet Software Consortium.
|
|
|
|
* Use is subject to license terms which appear in the file named
|
|
|
|
* ISC-LICENSE that should have accompanied this file when you
|
|
|
|
* received it. If a file named ISC-LICENSE did not accompany this
|
|
|
|
* file, or you are not sure the one you have is correct, you may
|
|
|
|
* obtain an applicable copy of the license at:
|
1996-04-11 06:44:12 +00:00
|
|
|
*
|
1999-03-16 05:50:46 +00:00
|
|
|
* http://www.isc.org/isc-license-1.0.html.
|
1996-04-11 06:44:12 +00:00
|
|
|
*
|
1999-03-16 05:50:46 +00:00
|
|
|
* This file is part of the ISC DHCP distribution. The documentation
|
|
|
|
* associated with this file is listed in the file DOCUMENTATION,
|
|
|
|
* included in the top-level directory of this release.
|
1996-04-11 06:44:12 +00:00
|
|
|
*
|
1999-03-16 05:50:46 +00:00
|
|
|
* Support and other services are available for ISC products - see
|
|
|
|
* http://www.isc.org for more information.
|
1996-04-11 06:44:12 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef lint
|
|
|
|
static char copyright[] =
|
1999-10-04 23:46:30 +00:00
|
|
|
"$Id: dispatch.c,v 1.58 1999/10/04 23:46:30 mellon Exp $ Copyright (c) 1995, 1996, 1997, 1998, 1999 The Internet Software Consortium. All rights reserved.\n";
|
1996-04-11 06:44:12 +00:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#include "dhcpd.h"
|
|
|
|
|
1997-02-18 14:33:43 +00:00
|
|
|
struct timeout *timeouts;
|
|
|
|
static struct timeout *free_timeouts;
|
1996-04-11 06:44:12 +00:00
|
|
|
|
1998-10-17 13:35:24 +00:00
|
|
|
int interfaces_invalidated;
|
1996-04-11 06:44:12 +00:00
|
|
|
|
|
|
|
/* Wait for packets to come in using select(). When one does, call
|
|
|
|
receive_packet to receive the packet and possibly strip hardware
|
1999-02-14 18:46:20 +00:00
|
|
|
addressing information from it, and then call through the
|
|
|
|
bootp_packet_handler hook to try to do something with it. */
|
1996-04-11 06:44:12 +00:00
|
|
|
|
1997-03-06 06:52:30 +00:00
|
|
|
void dispatch ()
|
1996-04-11 06:44:12 +00:00
|
|
|
{
|
|
|
|
fd_set r, w, x;
|
1997-03-06 06:52:30 +00:00
|
|
|
struct protocol *l;
|
1996-04-11 06:44:12 +00:00
|
|
|
int max = 0;
|
|
|
|
int count;
|
1997-02-18 14:33:43 +00:00
|
|
|
struct timeval tv, *tvp;
|
1999-09-08 01:44:21 +00:00
|
|
|
isc_result_t status;
|
1996-04-11 06:44:12 +00:00
|
|
|
|
|
|
|
do {
|
1997-02-18 14:33:43 +00:00
|
|
|
/* Call any expired timeouts, and then if there's
|
|
|
|
still a timeout registered, time out the select
|
|
|
|
call then. */
|
|
|
|
another:
|
|
|
|
if (timeouts) {
|
|
|
|
struct timeout *t;
|
|
|
|
if (timeouts -> when <= cur_time) {
|
|
|
|
t = timeouts;
|
|
|
|
timeouts = timeouts -> next;
|
1997-03-06 06:52:30 +00:00
|
|
|
(*(t -> func)) (t -> what);
|
1997-02-18 14:33:43 +00:00
|
|
|
t -> next = free_timeouts;
|
|
|
|
free_timeouts = t;
|
|
|
|
goto another;
|
|
|
|
}
|
1999-09-08 01:44:21 +00:00
|
|
|
tv.tv_sec = timeouts -> when;
|
1997-02-18 14:33:43 +00:00
|
|
|
tv.tv_usec = 0;
|
|
|
|
tvp = &tv;
|
|
|
|
} else
|
|
|
|
tvp = (struct timeval *)0;
|
|
|
|
|
1996-04-11 06:44:12 +00:00
|
|
|
/* Wait for a packet or a timeout... XXX */
|
1999-09-08 01:44:21 +00:00
|
|
|
status = omapi_one_dispatch (0, tvp);
|
|
|
|
} while (status == ISC_R_TIMEDOUT || status == ISC_R_SUCCESS);
|
1999-10-04 23:46:30 +00:00
|
|
|
log_fatal ("omapi_one_dispatch failed: %s -- exiting.",
|
1999-10-04 23:14:00 +00:00
|
|
|
isc_result_totext (status));
|
1996-04-11 06:44:12 +00:00
|
|
|
}
|
|
|
|
|
1997-02-18 14:33:43 +00:00
|
|
|
void add_timeout (when, where, what)
|
|
|
|
TIME when;
|
1997-03-06 06:52:30 +00:00
|
|
|
void (*where) PROTO ((void *));
|
|
|
|
void *what;
|
1997-02-18 14:33:43 +00:00
|
|
|
{
|
|
|
|
struct timeout *t, *q;
|
|
|
|
|
|
|
|
/* See if this timeout supersedes an existing timeout. */
|
|
|
|
t = (struct timeout *)0;
|
|
|
|
for (q = timeouts; q; q = q -> next) {
|
1997-03-06 06:52:30 +00:00
|
|
|
if (q -> func == where && q -> what == what) {
|
1997-02-18 14:33:43 +00:00
|
|
|
if (t)
|
|
|
|
t -> next = q -> next;
|
|
|
|
else
|
|
|
|
timeouts = q -> next;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
t = q;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we didn't supersede a timeout, allocate a timeout
|
|
|
|
structure now. */
|
|
|
|
if (!q) {
|
|
|
|
if (free_timeouts) {
|
|
|
|
q = free_timeouts;
|
|
|
|
free_timeouts = q -> next;
|
|
|
|
q -> func = where;
|
1997-03-06 06:52:30 +00:00
|
|
|
q -> what = what;
|
1997-02-18 14:33:43 +00:00
|
|
|
} else {
|
|
|
|
q = (struct timeout *)malloc (sizeof (struct timeout));
|
|
|
|
if (!q)
|
1999-09-08 01:44:21 +00:00
|
|
|
log_fatal ("add_timeout: no memory!");
|
1997-02-18 14:33:43 +00:00
|
|
|
q -> func = where;
|
1997-03-06 06:52:30 +00:00
|
|
|
q -> what = what;
|
1997-02-18 14:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
q -> when = when;
|
|
|
|
|
|
|
|
/* Now sort this timeout into the timeout list. */
|
|
|
|
|
|
|
|
/* Beginning of list? */
|
|
|
|
if (!timeouts || timeouts -> when > q -> when) {
|
|
|
|
q -> next = timeouts;
|
|
|
|
timeouts = q;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Middle of list? */
|
|
|
|
for (t = timeouts; t -> next; t = t -> next) {
|
|
|
|
if (t -> next -> when > q -> when) {
|
|
|
|
q -> next = t -> next;
|
|
|
|
t -> next = q;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* End of list. */
|
|
|
|
t -> next = q;
|
|
|
|
q -> next = (struct timeout *)0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cancel_timeout (where, what)
|
1997-03-06 06:52:30 +00:00
|
|
|
void (*where) PROTO ((void *));
|
|
|
|
void *what;
|
1997-02-18 14:33:43 +00:00
|
|
|
{
|
|
|
|
struct timeout *t, *q;
|
|
|
|
|
|
|
|
/* Look for this timeout on the list, and unlink it if we find it. */
|
|
|
|
t = (struct timeout *)0;
|
|
|
|
for (q = timeouts; q; q = q -> next) {
|
1997-03-06 06:52:30 +00:00
|
|
|
if (q -> func == where && q -> what == what) {
|
1997-02-18 14:33:43 +00:00
|
|
|
if (t)
|
|
|
|
t -> next = q -> next;
|
|
|
|
else
|
|
|
|
timeouts = q -> next;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
t = q;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we found the timeout, put it on the free list. */
|
|
|
|
if (q) {
|
|
|
|
q -> next = free_timeouts;
|
|
|
|
free_timeouts = q;
|
|
|
|
}
|
|
|
|
}
|