Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/external/bsd/dhcp/dist Make DHCP programs compatible with cr...



details:   https://anonhg.NetBSD.org/src/rev/8d70c32511c1
branches:  trunk
changeset: 825053:8d70c32511c1
user:      manu <manu%NetBSD.org@localhost>
date:      Wed Jun 28 02:46:30 2017 +0000

description:
Make DHCP programs compatible with crunchgen(1)

DHCP programs are incompatible with crunchgen(1) so far, because
libdhcp uses callbacks with the same function names for dhclient,
dhcrelay, dhcpd, and omshell. As a result, it is impossible to
link correctly in a single binary.

The offending symbols are classify, check_collection, dhcp, dhcpv6,
bootp, find_class, parse_allow_deny, and dhcp_set_control_state, and
the local_port and remote_port variables.

This change make each program register an array of callbacks at
main() start. libdhcp then uses callbacks through registered
function and variable pointers, and DHCP programs can now go
trough crunchgen(1).

Submitted upstream as ISC-Bugs #45330 with a patch against latest ISC git.
The soon to be released 4.3.6 will not include the change, but it is
likely to be included in 4.3.7

diffstat:

 external/bsd/dhcp/dist/client/dhclient.c |  23 ++++++++++++++++++++---
 external/bsd/dhcp/dist/common/bpf.c      |   6 +++---
 external/bsd/dhcp/dist/common/comapi.c   |   7 ++++---
 external/bsd/dhcp/dist/common/discover.c |   6 ++----
 external/bsd/dhcp/dist/common/dispatch.c |  17 +++++++++++++----
 external/bsd/dhcp/dist/common/dlpi.c     |   6 +++---
 external/bsd/dhcp/dist/common/execute.c  |   6 +++---
 external/bsd/dhcp/dist/common/lpf.c      |   8 ++++----
 external/bsd/dhcp/dist/common/nit.c      |   6 +++---
 external/bsd/dhcp/dist/common/options.c  |  10 +++++-----
 external/bsd/dhcp/dist/common/packet.c   |   8 ++++----
 external/bsd/dhcp/dist/common/parse.c    |   8 ++++----
 external/bsd/dhcp/dist/common/raw.c      |   9 +++++----
 external/bsd/dhcp/dist/common/socket.c   |  14 ++++++++------
 external/bsd/dhcp/dist/common/tr.c       |   6 +++---
 external/bsd/dhcp/dist/common/tree.c     |   8 ++++----
 external/bsd/dhcp/dist/common/upf.c      |   6 +++---
 external/bsd/dhcp/dist/dhcpctl/cltest.c  |  23 +++++++++++++++++++++--
 external/bsd/dhcp/dist/dhcpctl/omshell.c |  23 +++++++++++++++++++++--
 external/bsd/dhcp/dist/includes/dhcpd.h  |  24 +++++++++++++++++++++++-
 external/bsd/dhcp/dist/relay/dhcrelay.c  |  27 ++++++++++++++++++++++-----
 external/bsd/dhcp/dist/server/dhcpd.c    |  25 ++++++++++++++++++++++---
 external/bsd/dhcp/dist/tests/t_api.c     |  21 ++++++++++++++++++++-
 23 files changed, 220 insertions(+), 77 deletions(-)

diffs (truncated from 903 to 300 lines):

diff -r 5e6ba9f8922d -r 8d70c32511c1 external/bsd/dhcp/dist/client/dhclient.c
--- a/external/bsd/dhcp/dist/client/dhclient.c  Tue Jun 27 23:29:12 2017 +0000
+++ b/external/bsd/dhcp/dist/client/dhclient.c  Wed Jun 28 02:46:30 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dhclient.c,v 1.10 2016/01/10 20:10:44 christos Exp $   */
+/*     $NetBSD: dhclient.c,v 1.11 2017/06/28 02:46:30 manu Exp $       */
 /* dhclient.c
 
    DHCP Client. */
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: dhclient.c,v 1.10 2016/01/10 20:10:44 christos Exp $");
+__RCSID("$NetBSD: dhclient.c,v 1.11 2017/06/28 02:46:30 manu Exp $");
 
 #include "dhcpd.h"
 #include <syslog.h>
@@ -95,6 +95,21 @@
 int wanted_ia_pd = 0;
 char *mockup_relay = NULL;
 
+libdhcp_callbacks_t dhclient_callbacks = {
+       &local_port,
+       &remote_port,
+       classify,
+       check_collection,
+       dhcp,
+#ifdef DHCPv6
+       dhcpv6,
+#endif /* DHCPv6 */
+       bootp,
+       find_class,
+       parse_allow_deny,
+       dhcp_set_control_state,
+};
+
 void run_stateless(int exit_mode);
 
 static void usage(void);
@@ -183,6 +198,8 @@
        char *s;
        char **ifaces;
 
+       libdhcp_callbacks_register(&dhclient_callbacks);
+
        /* Initialize client globals. */
        memset(&default_duid, 0, sizeof(default_duid));
 
@@ -942,7 +959,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: dhclient.c,v 1.10 2016/01/10 20:10:44 christos Exp $");
+__RCSID("$NetBSD: dhclient.c,v 1.11 2017/06/28 02:46:30 manu Exp $");
 
 void state_reboot (cpp)
        void *cpp;
diff -r 5e6ba9f8922d -r 8d70c32511c1 external/bsd/dhcp/dist/common/bpf.c
--- a/external/bsd/dhcp/dist/common/bpf.c       Tue Jun 27 23:29:12 2017 +0000
+++ b/external/bsd/dhcp/dist/common/bpf.c       Wed Jun 28 02:46:30 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bpf.c,v 1.4 2016/01/10 20:10:44 christos Exp $ */
+/*     $NetBSD: bpf.c,v 1.5 2017/06/28 02:46:30 manu Exp $     */
 /* bpf.c
 
    BPF socket interface code, originally contributed by Archie Cobbs. */
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: bpf.c,v 1.4 2016/01/10 20:10:44 christos Exp $");
+__RCSID("$NetBSD: bpf.c,v 1.5 2017/06/28 02:46:30 manu Exp $");
 
 #include "dhcpd.h"
 #if defined (USE_BPF_SEND) || defined (USE_BPF_RECEIVE)        \
@@ -315,7 +315,7 @@
         /* Patch the server port into the BPF  program...
           XXX changes to filter program may require changes
           to the insn number(s) used below! XXX */
-       dhcp_bpf_filter [8].k = ntohs (local_port);
+       dhcp_bpf_filter [8].k = ntohs (*libdhcp_callbacks.local_port);
 
        if (ioctl (info -> rfdesc, BIOCSETF, &p) < 0)
                log_fatal ("Can't install packet filter program: %m");
diff -r 5e6ba9f8922d -r 8d70c32511c1 external/bsd/dhcp/dist/common/comapi.c
--- a/external/bsd/dhcp/dist/common/comapi.c    Tue Jun 27 23:29:12 2017 +0000
+++ b/external/bsd/dhcp/dist/common/comapi.c    Wed Jun 28 02:46:30 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: comapi.c,v 1.1.1.3 2014/07/12 11:57:39 spz Exp $       */
+/*     $NetBSD: comapi.c,v 1.2 2017/06/28 02:46:30 manu Exp $  */
 /* omapi.c
 
    OMAPI object interfaces for the DHCP server. */
@@ -29,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: comapi.c,v 1.1.1.3 2014/07/12 11:57:39 spz Exp $");
+__RCSID("$NetBSD: comapi.c,v 1.2 2017/06/28 02:46:30 manu Exp $");
 
 /* Many, many thanks to Brian Murrell and BCtel for this code - BCtel
    provided the funding that resulted in this code and the entire
@@ -454,7 +454,8 @@
                status = omapi_get_int_value (&newstate, value);
                if (status != ISC_R_SUCCESS)
                        return status;
-               status = dhcp_set_control_state (control -> state, newstate);
+               status = libdhcp_callbacks.dhcp_set_control_state 
+                               (control -> state, newstate);
                if (status == ISC_R_SUCCESS)
                        control -> state = value -> u.integer;
                return status;
diff -r 5e6ba9f8922d -r 8d70c32511c1 external/bsd/dhcp/dist/common/discover.c
--- a/external/bsd/dhcp/dist/common/discover.c  Tue Jun 27 23:29:12 2017 +0000
+++ b/external/bsd/dhcp/dist/common/discover.c  Wed Jun 28 02:46:30 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: discover.c,v 1.5 2016/01/10 20:10:44 christos Exp $    */
+/*     $NetBSD: discover.c,v 1.6 2017/06/28 02:46:30 manu Exp $        */
 /* discover.c
 
    Find and identify the network interfaces. */
@@ -29,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: discover.c,v 1.5 2016/01/10 20:10:44 christos Exp $");
+__RCSID("$NetBSD: discover.c,v 1.6 2017/06/28 02:46:30 manu Exp $");
 
 #include "dhcpd.h"
 
@@ -47,8 +47,6 @@
 struct interface_info *interfaces, *dummy_interfaces, *fallback_interface;
 int interfaces_invalidated;
 int quiet_interface_discovery;
-u_int16_t local_port;
-u_int16_t remote_port;
 int (*dhcp_interface_setup_hook) (struct interface_info *, struct iaddr *);
 int (*dhcp_interface_discovery_hook) (struct interface_info *);
 isc_result_t (*dhcp_interface_startup_hook) (struct interface_info *);
diff -r 5e6ba9f8922d -r 8d70c32511c1 external/bsd/dhcp/dist/common/dispatch.c
--- a/external/bsd/dhcp/dist/common/dispatch.c  Tue Jun 27 23:29:12 2017 +0000
+++ b/external/bsd/dhcp/dist/common/dispatch.c  Wed Jun 28 02:46:30 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dispatch.c,v 1.4 2014/07/12 12:09:37 spz Exp $ */
+/*     $NetBSD: dispatch.c,v 1.5 2017/06/28 02:46:30 manu Exp $        */
 /* dispatch.c
 
    Network input dispatcher... */
@@ -28,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: dispatch.c,v 1.4 2014/07/12 12:09:37 spz Exp $");
+__RCSID("$NetBSD: dispatch.c,v 1.5 2017/06/28 02:46:30 manu Exp $");
 
 #include "dhcpd.h"
 
@@ -37,6 +37,8 @@
 struct timeout *timeouts;
 static struct timeout *free_timeouts;
 
+libdhcp_callbacks_t libdhcp_callbacks;
+
 void set_time(TIME t)
 {
        /* Do any outstanding timeouts. */
@@ -128,8 +130,8 @@
                         * dhcp_set_control_state() will do the job.
                         * Note its first argument is ignored.
                         */
-                       status = dhcp_set_control_state(server_shutdown,
-                                                       server_shutdown);
+                       status = libdhcp_callbacks.dhcp_set_control_state
+                                       (server_shutdown, server_shutdown);
                        if (status == ISC_R_SUCCESS)
                                status = ISC_R_RELOAD;
                }
@@ -437,3 +439,10 @@
        }
 }
 #endif
+
+void libdhcp_callbacks_register(cb)
+       libdhcp_callbacks_t *cb;
+{
+       memcpy(&libdhcp_callbacks, cb, sizeof(libdhcp_callbacks));
+       return;
+}
diff -r 5e6ba9f8922d -r 8d70c32511c1 external/bsd/dhcp/dist/common/dlpi.c
--- a/external/bsd/dhcp/dist/common/dlpi.c      Tue Jun 27 23:29:12 2017 +0000
+++ b/external/bsd/dhcp/dist/common/dlpi.c      Wed Jun 28 02:46:30 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dlpi.c,v 1.1.1.4 2016/01/10 19:44:39 christos Exp $    */
+/*     $NetBSD: dlpi.c,v 1.2 2017/06/28 02:46:30 manu Exp $    */
 /* dlpi.c
  
    Data Link Provider Interface (DLPI) network interface code. */
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: dlpi.c,v 1.1.1.4 2016/01/10 19:44:39 christos Exp $");
+__RCSID("$NetBSD: dlpi.c,v 1.2 2017/06/28 02:46:30 manu Exp $");
 
 /*
  * Based largely in part to the existing NIT code in nit.c.
@@ -456,7 +456,7 @@
         offset = ETHER_H_PREFIX + sizeof (iphdr) + sizeof (u_int16_t);
         pf.Pf_Filter [pf.Pf_FilterLen++] = ENF_PUSHWORD + (offset / 2);
         pf.Pf_Filter [pf.Pf_FilterLen++] = ENF_PUSHLIT | ENF_CAND;
-        pf.Pf_Filter [pf.Pf_FilterLen++] = local_port;
+        pf.Pf_Filter [pf.Pf_FilterLen++] = *libdhcp_callbacks.local_port;
 
         /*
          * protocol should be udp. this is a byte compare, test for
diff -r 5e6ba9f8922d -r 8d70c32511c1 external/bsd/dhcp/dist/common/execute.c
--- a/external/bsd/dhcp/dist/common/execute.c   Tue Jun 27 23:29:12 2017 +0000
+++ b/external/bsd/dhcp/dist/common/execute.c   Wed Jun 28 02:46:30 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: execute.c,v 1.1.1.4 2016/01/10 19:44:39 christos Exp $ */
+/*     $NetBSD: execute.c,v 1.2 2017/06/28 02:46:30 manu Exp $ */
 /* execute.c
 
    Support for executable statements. */
@@ -29,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: execute.c,v 1.1.1.4 2016/01/10 19:44:39 christos Exp $");
+__RCSID("$NetBSD: execute.c,v 1.2 2017/06/28 02:46:30 manu Exp $");
 
 #include "dhcpd.h"
 #include <omapip/omapip_p.h>
@@ -295,7 +295,7 @@
                                               ? r->data.add->name
                                               : "<unnamed class>"));
 #endif
-                       classify (packet, r->data.add);
+                       libdhcp_callbacks.classify (packet, r->data.add);
                        break;
 
                      case break_statement:
diff -r 5e6ba9f8922d -r 8d70c32511c1 external/bsd/dhcp/dist/common/lpf.c
--- a/external/bsd/dhcp/dist/common/lpf.c       Tue Jun 27 23:29:12 2017 +0000
+++ b/external/bsd/dhcp/dist/common/lpf.c       Wed Jun 28 02:46:30 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lpf.c,v 1.1.1.5 2016/01/10 19:44:39 christos Exp $     */
+/*     $NetBSD: lpf.c,v 1.2 2017/06/28 02:46:30 manu Exp $     */
 /* lpf.c
 
    Linux packet filter code, contributed by Brian Murrel at Interlinx
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: lpf.c,v 1.1.1.5 2016/01/10 19:44:39 christos Exp $");
+__RCSID("$NetBSD: lpf.c,v 1.2 2017/06/28 02:46:30 manu Exp $");
 
 #include "dhcpd.h"
 #if defined (USE_LPF_SEND) || defined (USE_LPF_RECEIVE)
@@ -262,7 +262,7 @@
         /* Patch the server port into the LPF  program...
           XXX changes to filter program may require changes
           to the insn number(s) used below! XXX */
-       dhcp_bpf_filter [8].k = ntohs ((short)local_port);
+       dhcp_bpf_filter [8].k = ntohs ((short)*libdhcp_callbacks.local_port);
 
        if (setsockopt (info -> rfdesc, SOL_SOCKET, SO_ATTACH_FILTER, &p,
                        sizeof p) < 0) {
@@ -298,7 +298,7 @@
           XXX to the insn number(s) used below!
           XXX Token ring filter is null - when/if we have a filter 
           XXX that's not, we'll need this code.
-          XXX dhcp_bpf_filter [?].k = ntohs (local_port); */
+          XXX dhcp_bpf_filter [?].k = ntohs (*libdhcp_callbacks.local_port); */
 
        if (setsockopt (info -> rfdesc, SOL_SOCKET, SO_ATTACH_FILTER, &p,
                        sizeof p) < 0) {
diff -r 5e6ba9f8922d -r 8d70c32511c1 external/bsd/dhcp/dist/common/nit.c
--- a/external/bsd/dhcp/dist/common/nit.c       Tue Jun 27 23:29:12 2017 +0000
+++ b/external/bsd/dhcp/dist/common/nit.c       Wed Jun 28 02:46:30 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nit.c,v 1.1.1.3 2016/01/10 19:44:39 christos Exp $     */
+/*     $NetBSD: nit.c,v 1.2 2017/06/28 02:46:30 manu Exp $     */
 /* nit.c
 
    Network Interface Tap (NIT) network interface code, by Ted Lemon
@@ -29,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: nit.c,v 1.1.1.3 2016/01/10 19:44:39 christos Exp $");
+__RCSID("$NetBSD: nit.c,v 1.2 2017/06/28 02:46:30 manu Exp $");
 
 #include "dhcpd.h"
 #if defined (USE_NIT_SEND) || defined (USE_NIT_RECEIVE)
@@ -234,7 +234,7 @@
        pf.Pf_Filter [pf.Pf_FilterLen++] = ENF_CAND;
        pf.Pf_Filter [pf.Pf_FilterLen++] = ENF_PUSHWORD + 18;



Home | Main Index | Thread Index | Old Index