From: Ted Lemon Date: Wed, 8 Sep 1999 01:44:08 +0000 (+0000) Subject: Make interfaces OMAPI objects. X-Git-Tag: V3-BETA-1-PATCH-2~5^2~129 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=acc21512788665a7cf3e90bb06542373d13f9a83;p=thirdparty%2Fdhcp.git Make interfaces OMAPI objects. --- diff --git a/common/bpf.c b/common/bpf.c index 1ee652672..290e12be4 100644 --- a/common/bpf.c +++ b/common/bpf.c @@ -22,7 +22,7 @@ #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" @@ -419,12 +419,19 @@ int can_receive_unicast_unconfigured (ip) 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 diff --git a/common/discover.c b/common/discover.c index 21144db12..8afee1a22 100644 --- a/common/discover.c +++ b/common/discover.c @@ -22,7 +22,7 @@ #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" @@ -36,6 +36,8 @@ void (*bootp_packet_handler) PROTO ((struct interface_info *, 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 @@ -60,6 +62,22 @@ void discover_interfaces (state) #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) @@ -170,8 +188,10 @@ void discover_interfaces (state) 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 @@ -186,7 +206,7 @@ void discover_interfaces (state) #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; @@ -467,21 +487,40 @@ void discover_interfaces (state) } /* 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 = @@ -509,8 +548,8 @@ void reinitialize_interfaces () 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; @@ -522,15 +561,19 @@ void got_one (l) 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; @@ -539,5 +582,72 @@ void got_one (l) (*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; } diff --git a/common/dlpi.c b/common/dlpi.c index 41b134d21..981cd6e0c 100644 --- a/common/dlpi.c +++ b/common/dlpi.c @@ -70,7 +70,7 @@ #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" @@ -1246,12 +1246,19 @@ int can_receive_unicast_unconfigured (ip) 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 */ diff --git a/common/lpf.c b/common/lpf.c index da2c75832..f20f9b2dd 100644 --- a/common/lpf.c +++ b/common/lpf.c @@ -23,7 +23,7 @@ #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" @@ -314,12 +314,19 @@ int can_receive_unicast_unconfigured (ip) 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 diff --git a/common/nit.c b/common/nit.c index ce9b79a7b..ef4a2ce78 100644 --- a/common/nit.c +++ b/common/nit.c @@ -23,7 +23,7 @@ #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" @@ -350,12 +350,19 @@ int can_receive_unicast_unconfigured (ip) 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 diff --git a/common/socket.c b/common/socket.c index ccf1cd537..9e30160f7 100644 --- a/common/socket.c +++ b/common/socket.c @@ -30,7 +30,7 @@ #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" @@ -227,19 +227,26 @@ ssize_t receive_packet (interface, buf, len, from, hfrom) #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 */ @@ -263,12 +270,19 @@ int can_receive_unicast_unconfigured (ip) 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 } diff --git a/common/upf.c b/common/upf.c index a55099112..6eb48df66 100644 --- a/common/upf.c +++ b/common/upf.c @@ -22,7 +22,7 @@ #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" @@ -300,12 +300,19 @@ int can_receive_unicast_unconfigured (ip) 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