]> git.ipfire.org Git - thirdparty/dhcp.git/commitdiff
Make interfaces OMAPI objects.
authorTed Lemon <source@isc.org>
Wed, 8 Sep 1999 01:44:08 +0000 (01:44 +0000)
committerTed Lemon <source@isc.org>
Wed, 8 Sep 1999 01:44:08 +0000 (01:44 +0000)
common/bpf.c
common/discover.c
common/dlpi.c
common/lpf.c
common/nit.c
common/socket.c
common/upf.c

index 1ee65267252a1cdc3a0d3115c2c58b0c3229723b..290e12be4ba857503d13de917cb6b1fc9d57a9c4 100644 (file)
@@ -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
index 21144db127b72bc38796b8bac56b824da62ac60c..8afee1a228de6264291310eb98f5bced3408bad6 100644 (file)
@@ -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;
 }
 
index 41b134d21cb4d701bb7479d2ddbee90ae7d4ce8e..981cd6e0c08b087349f64a60035be5e63521eedf 100644 (file)
@@ -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 */
index da2c75832cbab11f60b7961b112c3e4d2ed4e275..f20f9b2dd02b68731027912e9262456db0651bd8 100644 (file)
@@ -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
index ce9b79a7b805a32ac192794b74df0d6076b10756..ef4a2ce78d25ff3c70bda0b28daa6b6289c1abeb 100644 (file)
@@ -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
index ccf1cd5370cf45f85298390fa62ac9b721ba5909..9e30160f7e4df83ad38248ff3a1bae3b160299bc 100644 (file)
@@ -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
 }
index a550991125ec8d123e3aa87ad01ebc873bf529dd..6eb48df66db4f0e7eb9b9cbef84723987b124776 100644 (file)
@@ -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