#ifndef lint
static char copyright[] =
-"$Id: bpf.c,v 1.27 1999/05/27 17:43:27 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium. All rights reserved.\n";
+"$Id: bpf.c,v 1.28 1999/09/08 01:43:38 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium. All rights reserved.\n";
#endif /* not lint */
#include "dhcpd.h"
void maybe_setup_fallback ()
{
+ isc_result_t status;
struct interface_info *fbi;
fbi = setup_fallback ();
if (fbi) {
if_register_fallback (fbi);
- add_protocol ("fallback", fallback_interface -> wfdesc,
- fallback_discard, fallback_interface);
+ fbi -> refcnt = 1;
+ fbi -> type = dhcp_type_interface;
+ status = omapi_register_io_object ((omapi_object_t)fbi,
+ if_readsocket, 0,
+ fallback_discard, 0, 0);
+ if (status != ISC_R_SUCCESS)
+ log_fatal ("Can't register I/O handle for %s: %s",
+ fbi -> name, isc_result_totext (status));
}
}
#endif
#ifndef lint
static char copyright[] =
-"$Id: discover.c,v 1.10 1999/07/13 12:58:03 mellon Exp $ Copyright (c) 1995, 1996, 1998, 1999 The Internet Software Consortium. All rights reserved.\n";
+"$Id: discover.c,v 1.11 1999/09/08 01:44:08 mellon Exp $ Copyright (c) 1995, 1996, 1998, 1999 The Internet Software Consortium. All rights reserved.\n";
#endif /* not lint */
#include "dhcpd.h"
struct dhcp_packet *, int, unsigned int,
struct iaddr, struct hardware *));
+omapi_object_type_t *dhcp_type_interface;
+
/* Use the SIOCGIFCONF ioctl to get a list of all the attached interfaces.
For each interface that's of type INET and not the loopback interface,
register that interface with the network I/O software, figure out what
#ifdef ALIAS_NAMES_PERMUTED
char *s;
#endif
+ isc_result_t status;
+
+ if (!dhcp_type_interface) {
+ status = omapi_init ();
+ if (status != ISC_R_SUCCESS)
+ log_fatal ("Can't initialize OMAPI: %s",
+ isc_result_totext (status));
+ status = omapi_object_type_register
+ (&dhcp_type_interface, "interface",
+ interface_set_value, interface_get_value,
+ interface_destroy, interface_signal_handler,
+ interface_stuff_values, 0, 0);
+ if (status != ISC_R_SUCCESS)
+ log_fatal ("Can't create interface object type: %s",
+ isc_result_totext (status));
+ }
/* Create an unbound datagram socket to do the SIOCGIFADDR ioctl on. */
if ((sock = socket (AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)
sizeof ifp -> ifr_addr);
/* We don't want the loopback interface. */
- if (foo.sin_addr.s_addr == htonl (INADDR_LOOPBACK))
- continue;
+ if (foo.sin_addr.s_addr == htonl (INADDR_LOOPBACK) &&
+ ((tmp -> flags & INTERFACE_AUTOMATIC) &&
+ state == DISCOVER_SERVER))
+ continue;
/* If this is the first real IP address we've
#endif
tif = (struct ifreq *)malloc (len);
if (!tif)
- log_fatal ("no space to remember ifp.");
+ log_fatal ("no space for ifp.");
memcpy (tif, ifp, len);
tmp -> ifp = tif;
tmp -> primary_address = foo.sin_addr;
}
/* Now register all the remaining interfaces as protocols. */
- for (tmp = interfaces; tmp; tmp = tmp -> next)
- add_protocol (tmp -> name, tmp -> rfdesc, got_one, tmp);
+ for (tmp = interfaces; tmp; tmp = tmp -> next) {
+ tmp -> refcnt = 1;
+ tmp -> type = dhcp_type_interface;
+ status = omapi_register_io_object ((omapi_object_t *)tmp,
+ if_readsocket, 0,
+ got_one, 0, 0);
+ if (status != ISC_R_SUCCESS)
+ log_fatal ("Can't register I/O handle for %s: %s",
+ tmp -> name, isc_result_totext (status));
+ }
close (sock);
maybe_setup_fallback ();
}
+int if_readsocket (h)
+ omapi_object_t *h;
+{
+ struct interface_info *ip;
+
+ if (h -> type != dhcp_type_interface)
+ return ISC_R_INVALIDARG;
+ ip = (struct interface_info *)h;
+ return ip -> rfdesc;
+}
+
struct interface_info *setup_fallback ()
{
fallback_interface =
((struct interface_info *)
dmalloc (sizeof *fallback_interface, "discover_interfaces"));
if (!fallback_interface)
- log_fatal ("Insufficient memory to record fallback interface.");
+ log_fatal ("No memory to record fallback interface.");
memset (fallback_interface, 0, sizeof *fallback_interface);
strcpy (fallback_interface -> name, "fallback");
fallback_interface -> shared_network =
interfaces_invalidated = 1;
}
-void got_one (l)
- struct protocol *l;
+isc_result_t got_one (h)
+ omapi_object_t *h;
{
struct sockaddr_in from;
struct hardware hfrom;
possible MTU. */
struct dhcp_packet packet;
} u;
- struct interface_info *ip = l -> local;
+ struct interface_info *ip;
+
+ if (h -> type != dhcp_type_interface)
+ return ISC_R_INVALIDARG;
+ ip = (struct interface_info *)h;
if ((result =
receive_packet (ip, u.packbuf, sizeof u, &from, &hfrom)) < 0) {
log_error ("receive_packet failed on %s: %m", ip -> name);
- return;
+ return ISC_R_UNEXPECTED;
}
if (result == 0)
- return;
+ return ISC_R_UNEXPECTED;
if (bootp_packet_handler) {
ifrom.len = 4;
(*bootp_packet_handler) (ip, &u.packet, result,
from.sin_port, ifrom, &hfrom);
}
+ return ISC_R_SUCCESS;
+}
+
+isc_result_t interface_set_value (omapi_object_t *h,
+ omapi_object_t *id,
+ omapi_data_string_t *name,
+ omapi_typed_data_t *value)
+{
+ if (h -> type != dhcp_type_interface)
+ return ISC_R_INVALIDARG;
+
+ if (h -> inner && h -> inner -> type -> set_value)
+ return (*(h -> inner -> type -> set_value))
+ (h -> inner, id, name, value);
+ return ISC_R_NOTFOUND;
+}
+
+isc_result_t interface_get_value (omapi_object_t *h,
+ omapi_object_t *id,
+ omapi_data_string_t *name,
+ omapi_value_t **value)
+{
+ if (h -> type != dhcp_type_interface)
+ return ISC_R_INVALIDARG;
+
+ if (h -> inner && h -> inner -> type -> get_value)
+ return (*(h -> inner -> type -> get_value))
+ (h -> inner, id, name, value);
+ return ISC_R_NOTFOUND;
+}
+
+isc_result_t interface_stuff_values (omapi_object_t *c,
+ omapi_object_t *id,
+ omapi_object_t *m)
+{
+ if (m -> type != dhcp_type_interface)
+ return ISC_R_INVALIDARG;
+
+ if (m -> inner && m -> inner -> type -> stuff_values)
+ return (*(m -> inner -> type -> stuff_values)) (c, id,
+ m -> inner);
+ return ISC_R_NOTFOUND;
+}
+
+isc_result_t interface_destroy (omapi_object_t *h, char *name)
+{
+ int i;
+
+ struct interface_info *p;
+ if (h -> type != dhcp_type_interface)
+ return ISC_R_INVALIDARG;
+ /* Nothing to do yet, AFAIK - interfaces should never be
+ destroyed. Revisit this later when we handle interface
+ detection/deletion on the fly. */
+ return ISC_R_SUCCESS;
+}
+
+isc_result_t interface_signal_handler (omapi_object_t *h,
+ char *name, va_list ap)
+{
+ if (h -> type != dhcp_type_interface)
+ return ISC_R_INVALIDARG;
+
+ if (h -> inner && h -> inner -> type -> signal_handler)
+ return (*(h -> inner -> type -> signal_handler)) (h -> inner,
+ name, ap);
+ return ISC_R_NOTFOUND;
}
#ifndef lint
static char copyright[] =
-"$Id: dlpi.c,v 1.12 1999/05/27 14:10:22 mellon Exp $ Copyright (c) 1998, 1999 The Internet Software Consortium. All rights reserved.\n";
+"$Id: dlpi.c,v 1.13 1999/09/08 01:43:39 mellon Exp $ Copyright (c) 1998, 1999 The Internet Software Consortium. All rights reserved.\n";
#endif /* not lint */
#include "dhcpd.h"
void maybe_setup_fallback ()
{
+ isc_result_t status;
struct interface_info *fbi;
fbi = setup_fallback ();
if (fbi) {
if_register_fallback (fbi);
- add_protocol ("fallback", fallback_interface -> wfdesc,
- fallback_discard, fallback_interface);
+ fbi -> refcnt = 1;
+ fbi -> type = dhcp_type_interface;
+ status = omapi_register_io_object ((omapi_object_t)fbi,
+ if_readsocket, 0,
+ fallback_discard, 0, 0);
+ if (status != ISC_R_SUCCESS)
+ log_fatal ("Can't register I/O handle for %s: %s",
+ fbi -> name, isc_result_totext (status));
}
}
#endif /* USE_DLPI */
#ifndef lint
static char copyright[] =
-"$Id: lpf.c,v 1.14 1999/07/31 17:56:53 mellon Exp $ Copyright (c) 1995, 1996, 1998, 1999 The Internet Software Consortium. All rights reserved.\n";
+"$Id: lpf.c,v 1.15 1999/09/08 01:43:39 mellon Exp $ Copyright (c) 1995, 1996, 1998, 1999 The Internet Software Consortium. All rights reserved.\n";
#endif /* not lint */
#include "dhcpd.h"
void maybe_setup_fallback ()
{
+ isc_result_t status;
struct interface_info *fbi;
fbi = setup_fallback ();
if (fbi) {
if_register_fallback (fbi);
- add_protocol ("fallback", fallback_interface -> wfdesc,
- fallback_discard, fallback_interface);
+ fbi -> refcnt = 1;
+ fbi -> type = dhcp_type_interface;
+ status = omapi_register_io_object ((omapi_object_t)fbi,
+ if_readsocket, 0,
+ fallback_discard, 0, 0);
+ if (status != ISC_R_SUCCESS)
+ log_fatal ("Can't register I/O handle for %s: %s",
+ fbi -> name, isc_result_totext (status));
}
}
#endif
#ifndef lint
static char copyright[] =
-"$Id: nit.c,v 1.22 1999/03/16 06:37:49 mellon Exp $ Copyright (c) 1996, 1998, 1999 The Internet Software Consortium. All rights reserved.\n";
+"$Id: nit.c,v 1.23 1999/09/08 01:43:39 mellon Exp $ Copyright (c) 1996, 1998, 1999 The Internet Software Consortium. All rights reserved.\n";
#endif /* not lint */
#include "dhcpd.h"
void maybe_setup_fallback ()
{
+ isc_result_t status;
struct interface_info *fbi;
fbi = setup_fallback ();
if (fbi) {
if_register_fallback (fbi);
- add_protocol ("fallback", fallback_interface -> wfdesc,
- fallback_discard, fallback_interface);
+ fbi -> refcnt = 1;
+ fbi -> type = dhcp_type_interface;
+ status = omapi_register_io_object ((omapi_object_t)fbi,
+ if_readsocket, 0,
+ fallback_discard, 0, 0);
+ if (status != ISC_R_SUCCESS)
+ log_fatal ("Can't register I/O handle for %s: %s",
+ fbi -> name, isc_result_totext (status));
}
}
#endif
#ifndef lint
static char copyright[] =
-"$Id: socket.c,v 1.37 1999/05/27 14:18:27 mellon Exp $ Copyright (c) 1995, 1996, 1997, 1998, 1999 The Internet Software Consortium. All rights reserved.\n";
+"$Id: socket.c,v 1.38 1999/09/08 01:43:52 mellon Exp $ Copyright (c) 1995, 1996, 1997, 1998, 1999 The Internet Software Consortium. All rights reserved.\n";
#endif /* not lint */
#include "dhcpd.h"
#if defined (USE_SOCKET_FALLBACK)
/* This just reads in a packet and silently discards it. */
-void fallback_discard (protocol)
- struct protocol *protocol;
+isc_result_t fallback_discard (object)
+ omapi_object_t object;
{
char buf [1540];
struct sockaddr_in from;
int flen = sizeof from;
int status;
- struct interface_info *interface = protocol -> local;
+ struct interface_info *interface;
+
+ if (object -> type != dhcp_type_interface)
+ return ISC_R_INVALIDARG;
+ interface = (struct interface_info *)object;
status = recvfrom (interface -> wfdesc, buf, sizeof buf, 0,
(struct sockaddr *)&from, &flen);
- if (status < 0)
+ if (status < 0) {
log_error ("fallback_discard: %m");
+ return ISC_R_UNEXPECTED;
+ }
+ return ISC_R_SUCCESS;
}
#endif /* USE_SOCKET_SEND */
void maybe_setup_fallback ()
{
#if defined (SO_BINDTODEVICE)
+ isc_result_t status;
struct interface_info *fbi;
fbi = setup_fallback ();
if (fbi) {
fbi -> wfdesc = if_register_socket (fbi);
- add_protocol ("fallback",
- fbi -> wfdesc, fallback_discard, fbi);
+ fbi -> refcnt = 1;
+ fbi -> type = dhcp_type_interface;
+ status = omapi_register_io_object ((omapi_object_t)fbi,
+ if_readsocket, 0,
+ fallback_discard, 0, 0);
+ if (status != ISC_R_SUCCESS)
+ log_fatal ("Can't register I/O handle for %s: %s",
+ fbi -> name, isc_result_totext (status));
}
#endif
}
#ifndef lint
static char copyright[] =
-"$Id: upf.c,v 1.11 1999/03/26 19:19:44 mellon Exp $ Copyright (c) 1995, 1996, 1997, 1998, 1999 The Internet Software Consortium. All rights reserved.\n";
+"$Id: upf.c,v 1.12 1999/09/08 01:43:39 mellon Exp $ Copyright (c) 1995, 1996, 1997, 1998, 1999 The Internet Software Consortium. All rights reserved.\n";
#endif /* not lint */
#include "dhcpd.h"
void maybe_setup_fallback ()
{
+ isc_result_t status;
struct interface_info *fbi;
fbi = setup_fallback ();
if (fbi) {
if_register_fallback (fbi);
- add_protocol ("fallback", fallback_interface -> wfdesc,
- fallback_discard, fallback_interface);
+ fbi -> refcnt = 1;
+ fbi -> type = dhcp_type_interface;
+ status = omapi_register_io_object ((omapi_object_t)fbi,
+ if_readsocket, 0,
+ fallback_discard, 0, 0);
+ if (status != ISC_R_SUCCESS)
+ log_fatal ("Can't register I/O handle for %s: %s",
+ fbi -> name, isc_result_totext (status));
}
}
#endif