diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2006-05-11 01:19:09 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2006-05-11 01:19:09 +0000 |
commit | d38d8fdc9dfad44e06115fb8a446df20dc031781 (patch) | |
tree | 8a8c8a76e7c1363a084d7134109d55eadb232efe /usr.sbin/dhcpd | |
parent | 5c63d182406271b85863839f3a5bb71c76a2b955 (diff) |
If a list of interfaces is supplied via the command line or
dhcpd.interfaces then
a) don't bother looking up information on interfaces that were not
requested;
b) don't exit if a requested interface is not found, just issue a
warning message;
c) exit if none of the interfaces were found.
The command line for dhcpd shown in ps will continue to show requested
but ignored interfaces.
As usual with dhc* code, whack a bunch of unused states, constants,
flags, etc. Since we only invoke discover_interfaces() with
DISCOVER_SERVER, there is no need to keep track of other
possibilities.
Diffstat (limited to 'usr.sbin/dhcpd')
-rw-r--r-- | usr.sbin/dhcpd/dhcpd.c | 5 | ||||
-rw-r--r-- | usr.sbin/dhcpd/dhcpd.h | 15 | ||||
-rw-r--r-- | usr.sbin/dhcpd/dispatch.c | 53 |
3 files changed, 27 insertions, 46 deletions
diff --git a/usr.sbin/dhcpd/dhcpd.c b/usr.sbin/dhcpd/dhcpd.c index 657867c0792..a2ba8fc4bc6 100644 --- a/usr.sbin/dhcpd/dhcpd.c +++ b/usr.sbin/dhcpd/dhcpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dhcpd.c,v 1.24 2005/05/23 22:54:55 henning Exp $ */ +/* $OpenBSD: dhcpd.c,v 1.25 2006/05/11 01:19:08 krw Exp $ */ /* * Copyright (c) 2004 Henning Brauer <henning@cvs.openbsd.org> @@ -101,7 +101,6 @@ main(int argc, char *argv[]) error("calloc"); strlcpy(tmp->name, argv[0], sizeof(tmp->name)); tmp->next = interfaces; - tmp->flags = INTERFACE_REQUESTED; interfaces = tmp; argc--; argv++; @@ -121,7 +120,7 @@ main(int argc, char *argv[]) exit(0); db_startup(); - discover_interfaces(DISCOVER_SERVER); + discover_interfaces(); icmp_startup(1, lease_pinged); if ((pw = getpwnam("_dhcp")) == NULL) diff --git a/usr.sbin/dhcpd/dhcpd.h b/usr.sbin/dhcpd/dhcpd.h index cbb904be9d3..24af5c36510 100644 --- a/usr.sbin/dhcpd/dhcpd.h +++ b/usr.sbin/dhcpd/dhcpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dhcpd.h,v 1.16 2004/10/31 10:43:38 canacar Exp $ */ +/* $OpenBSD: dhcpd.h,v 1.17 2006/05/11 01:19:08 krw Exp $ */ /* * Copyright (c) 1995, 1996, 1997, 1998, 1999 @@ -242,14 +242,6 @@ struct lease_state { #define CLASS_DECL 4 #define GROUP_DECL 5 -/* Possible modes in which discover_interfaces can run. */ - -#define DISCOVER_RUNNING 0 -#define DISCOVER_SERVER 1 -#define DISCOVER_UNCONFIGURED 2 -#define DISCOVER_RELAY 3 -#define DISCOVER_REQUESTED 4 - /* Group of declarations that share common parameters. */ struct group { struct group *next; @@ -436,9 +428,6 @@ struct interface_info { size_t rbuf_len; /* Length of data in buffer. */ struct ifreq *ifp; /* Pointer to ifreq struct. */ - u_int32_t flags; /* Control flags... */ -#define INTERFACE_REQUESTED 1 -#define INTERFACE_AUTOMATIC 2 /* Only used by DHCP client code. */ struct client_state *client; @@ -723,7 +712,7 @@ extern struct protocol *protocols; extern void (*bootp_packet_handler)(struct interface_info *, struct dhcp_packet *, int, unsigned int, struct iaddr, struct hardware *); extern struct timeout *timeouts; -void discover_interfaces(int); +void discover_interfaces(void); void dispatch(void); int locate_network(struct packet *); void got_one(struct protocol *); diff --git a/usr.sbin/dhcpd/dispatch.c b/usr.sbin/dhcpd/dispatch.c index 19f47995b99..10f240718f3 100644 --- a/usr.sbin/dhcpd/dispatch.c +++ b/usr.sbin/dhcpd/dispatch.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dispatch.c,v 1.17 2006/03/16 15:44:40 claudio Exp $ */ +/* $OpenBSD: dispatch.c,v 1.18 2006/05/11 01:19:08 krw Exp $ */ /* * Copyright (c) 1995, 1996, 1997, 1998, 1999 @@ -64,14 +64,14 @@ static int interface_status(struct interface_info *ifinfo); subnet it's on, and add it to the list of interfaces. */ void -discover_interfaces(int state) +discover_interfaces(void) { struct interface_info *tmp; struct interface_info *last, *next; struct subnet *subnet; struct shared_network *share; struct sockaddr_in foo; - int ir; + int ir = 0; struct ifreq *tif; struct ifaddrs *ifap, *ifa; #ifdef ALIAS_NAMES_PERMUTED @@ -81,15 +81,12 @@ discover_interfaces(int state) if (getifaddrs(&ifap) != 0) error("getifaddrs failed"); - /* If we already have a list of interfaces, and we're running as - a DHCP server, the interfaces were requested. */ - if (interfaces && (state == DISCOVER_SERVER || - state == DISCOVER_RELAY || state == DISCOVER_REQUESTED)) - ir = 0; - else if (state == DISCOVER_UNCONFIGURED) - ir = INTERFACE_REQUESTED | INTERFACE_AUTOMATIC; - else - ir = INTERFACE_REQUESTED; + /* + * If we already have a list of interfaces, the interfaces were + * requested. + */ + if (interfaces != NULL) + ir = 1; /* Cycle through the list of interfaces looking for IP addresses. */ for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) { @@ -101,8 +98,7 @@ discover_interfaces(int state) */ if ((ifa->ifa_flags & IFF_LOOPBACK) || (ifa->ifa_flags & IFF_POINTOPOINT) || - (!(ifa->ifa_flags & IFF_UP) && - state != DISCOVER_UNCONFIGURED)) + (!(ifa->ifa_flags & IFF_UP))) continue; /* See if we've seen an interface that matches this one. */ @@ -110,9 +106,13 @@ discover_interfaces(int state) if (!strcmp(tmp->name, ifa->ifa_name)) break; + /* If we are looking for specific interfaces, ignore others. */ + if (tmp == NULL && ir) + continue; + /* If there isn't already an interface by this name, allocate one. */ - if (!tmp) { + if (tmp == NULL) { tmp = ((struct interface_info *)dmalloc(sizeof *tmp, "discover_interfaces")); if (!tmp) @@ -120,7 +120,6 @@ discover_interfaces(int state) "record interface", ifa->ifa_name); strlcpy(tmp->name, ifa->ifa_name, sizeof(tmp->name)); tmp->next = interfaces; - tmp->flags = ir; tmp->noifmedia = tmp->dead = tmp->errors = 0; interfaces = tmp; } @@ -206,27 +205,18 @@ discover_interfaces(int state) /* Now cycle through all the interfaces we found, looking for hardware addresses. */ - /* If we're just trying to get a list of interfaces that we might - be able to configure, we can quit now. */ - if (state == DISCOVER_UNCONFIGURED) - return; - /* Weed out the interfaces that did not have IP addresses. */ last = NULL; for (tmp = interfaces; tmp; tmp = next) { next = tmp->next; - if ((tmp->flags & INTERFACE_AUTOMATIC) && - state == DISCOVER_REQUESTED) - tmp->flags &= - ~(INTERFACE_AUTOMATIC | INTERFACE_REQUESTED); - if (!tmp->ifp || !(tmp->flags & INTERFACE_REQUESTED)) { - if ((tmp->flags & INTERFACE_REQUESTED) != ir) - error("%s: not found", tmp->name); + if (!tmp->ifp) { + if (ir) + warning("%s: not found", tmp->name); + /* Remove tmp from the list of interfaces. */ if (!last) interfaces = interfaces->next; else last->next = tmp->next; - continue; } last = tmp; @@ -234,7 +224,7 @@ discover_interfaces(int state) memcpy(&foo, &tmp->ifp->ifr_addr, sizeof tmp->ifp->ifr_addr); /* We must have a subnet declaration for each interface. */ - if (!tmp->shared_network && (state == DISCOVER_SERVER)) { + if (!tmp->shared_network) { warning("No subnet declaration for %s (%s).", tmp->name, inet_ntoa(foo.sin_addr)); warning("Please write a subnet declaration in your %s", @@ -263,6 +253,9 @@ discover_interfaces(int state) if_register_send(tmp); } + if (interfaces == NULL) + error("No interfaces to listen on."); + /* Now register all the remaining interfaces as protocols. */ for (tmp = interfaces; tmp; tmp = tmp->next) add_protocol(tmp->name, tmp->rfdesc, got_one, tmp); |