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
This commit is contained in:
parent
f51c99da13
commit
de828cbdf9
23
external/bsd/dhcp/dist/client/dhclient.c
vendored
23
external/bsd/dhcp/dist/client/dhclient.c
vendored
@ -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_ta = 0;
|
||||
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 @@ main(int argc, char **argv) {
|
||||
char *s;
|
||||
char **ifaces;
|
||||
|
||||
libdhcp_callbacks_register(&dhclient_callbacks);
|
||||
|
||||
/* Initialize client globals. */
|
||||
memset(&default_duid, 0, sizeof(default_duid));
|
||||
|
||||
@ -942,7 +959,7 @@ int find_subnet (struct subnet **sp,
|
||||
*/
|
||||
|
||||
#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;
|
||||
|
6
external/bsd/dhcp/dist/common/bpf.c
vendored
6
external/bsd/dhcp/dist/common/bpf.c
vendored
@ -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 @@ void if_register_receive (info)
|
||||
/* 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");
|
||||
|
7
external/bsd/dhcp/dist/common/comapi.c
vendored
7
external/bsd/dhcp/dist/common/comapi.c
vendored
@ -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 @@ isc_result_t dhcp_control_set_value (omapi_object_t *h,
|
||||
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;
|
||||
|
6
external/bsd/dhcp/dist/common/discover.c
vendored
6
external/bsd/dhcp/dist/common/discover.c
vendored
@ -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 @@ __RCSID("$NetBSD: discover.c,v 1.5 2016/01/10 20:10:44 christos Exp $");
|
||||
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 *);
|
||||
|
17
external/bsd/dhcp/dist/common/dispatch.c
vendored
17
external/bsd/dhcp/dist/common/dispatch.c
vendored
@ -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 @@ __RCSID("$NetBSD: dispatch.c,v 1.4 2014/07/12 12:09:37 spz Exp $");
|
||||
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 @@ dispatch(void)
|
||||
* 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 @@ void relinquish_timeouts ()
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void libdhcp_callbacks_register(cb)
|
||||
libdhcp_callbacks_t *cb;
|
||||
{
|
||||
memcpy(&libdhcp_callbacks, cb, sizeof(libdhcp_callbacks));
|
||||
return;
|
||||
}
|
||||
|
6
external/bsd/dhcp/dist/common/dlpi.c
vendored
6
external/bsd/dhcp/dist/common/dlpi.c
vendored
@ -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 @@ void if_register_receive (info)
|
||||
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
|
||||
|
6
external/bsd/dhcp/dist/common/execute.c
vendored
6
external/bsd/dhcp/dist/common/execute.c
vendored
@ -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 @@ int execute_statements (result, packet, lease, client_state,
|
||||
? r->data.add->name
|
||||
: "<unnamed class>"));
|
||||
#endif
|
||||
classify (packet, r->data.add);
|
||||
libdhcp_callbacks.classify (packet, r->data.add);
|
||||
break;
|
||||
|
||||
case break_statement:
|
||||
|
8
external/bsd/dhcp/dist/common/lpf.c
vendored
8
external/bsd/dhcp/dist/common/lpf.c
vendored
@ -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 @@ static void lpf_gen_filter_setup (info)
|
||||
/* 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 @@ static void lpf_tr_filter_setup (info)
|
||||
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) {
|
||||
|
6
external/bsd/dhcp/dist/common/nit.c
vendored
6
external/bsd/dhcp/dist/common/nit.c
vendored
@ -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 @@ void if_register_receive (info)
|
||||
pf.Pf_Filter [pf.Pf_FilterLen++] = ENF_CAND;
|
||||
pf.Pf_Filter [pf.Pf_FilterLen++] = ENF_PUSHWORD + 18;
|
||||
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;
|
||||
|
||||
/* Install the filter... */
|
||||
sio.ic_cmd = NIOCSETF;
|
||||
|
10
external/bsd/dhcp/dist/common/options.c
vendored
10
external/bsd/dhcp/dist/common/options.c
vendored
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: options.c,v 1.1.1.4 2016/01/10 19:44:40 christos Exp $ */
|
||||
/* $NetBSD: options.c,v 1.2 2017/06/28 02:46:30 manu Exp $ */
|
||||
/* options.c
|
||||
|
||||
DHCP options parsing and reassembly. */
|
||||
@ -28,7 +28,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: options.c,v 1.1.1.4 2016/01/10 19:44:40 christos Exp $");
|
||||
__RCSID("$NetBSD: options.c,v 1.2 2017/06/28 02:46:30 manu Exp $");
|
||||
|
||||
#define DHCP_OPTION_DATA
|
||||
#include "dhcpd.h"
|
||||
@ -3910,9 +3910,9 @@ void do_packet (interface, packet, len, from_port, from, hfrom)
|
||||
|
||||
if (validate_packet(decoded_packet) != 0) {
|
||||
if (decoded_packet->packet_type)
|
||||
dhcp(decoded_packet);
|
||||
libdhcp_callbacks.dhcp(decoded_packet);
|
||||
else
|
||||
bootp(decoded_packet);
|
||||
libdhcp_callbacks.bootp(decoded_packet);
|
||||
}
|
||||
|
||||
/* If the caller kept the packet, they'll have upped the refcnt. */
|
||||
@ -4040,7 +4040,7 @@ do_packet6(struct interface_info *interface, const char *packet,
|
||||
}
|
||||
}
|
||||
|
||||
dhcpv6(decoded_packet);
|
||||
libdhcp_callbacks.dhcpv6(decoded_packet);
|
||||
|
||||
packet_dereference(&decoded_packet, MDL);
|
||||
|
||||
|
8
external/bsd/dhcp/dist/common/packet.c
vendored
8
external/bsd/dhcp/dist/common/packet.c
vendored
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: packet.c,v 1.3 2016/01/10 20:10:44 christos Exp $ */
|
||||
/* $NetBSD: packet.c,v 1.4 2017/06/28 02:46:30 manu Exp $ */
|
||||
/* packet.c
|
||||
|
||||
Packet assembly code, originally contributed by Archie Cobbs. */
|
||||
@ -34,7 +34,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: packet.c,v 1.3 2016/01/10 20:10:44 christos Exp $");
|
||||
__RCSID("$NetBSD: packet.c,v 1.4 2017/06/28 02:46:30 manu Exp $");
|
||||
|
||||
#include "dhcpd.h"
|
||||
|
||||
@ -170,7 +170,7 @@ void assemble_udp_ip_header (interface, buf, bufix,
|
||||
*bufix += sizeof ip;
|
||||
|
||||
/* Fill out the UDP header */
|
||||
udp.uh_sport = local_port; /* XXX */
|
||||
udp.uh_sport = *libdhcp_callbacks.local_port; /* XXX */
|
||||
udp.uh_dport = port; /* XXX */
|
||||
udp.uh_ulen = htons(sizeof(udp) + len);
|
||||
memset (&udp.uh_sum, 0, sizeof udp.uh_sum);
|
||||
@ -301,7 +301,7 @@ decode_udp_ip_header(struct interface_info *interface,
|
||||
return -1;
|
||||
|
||||
/* Is it to the port we're serving? */
|
||||
if (udp.uh_dport != local_port)
|
||||
if (udp.uh_dport != *libdhcp_callbacks.local_port)
|
||||
return -1;
|
||||
#endif /* USERLAND_FILTER */
|
||||
|
||||
|
8
external/bsd/dhcp/dist/common/parse.c
vendored
8
external/bsd/dhcp/dist/common/parse.c
vendored
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: parse.c,v 1.1.1.4 2016/01/10 19:44:39 christos Exp $ */
|
||||
/* $NetBSD: parse.c,v 1.2 2017/06/28 02:46:30 manu Exp $ */
|
||||
/* parse.c
|
||||
|
||||
Common parser code for dhcpd and dhclient. */
|
||||
@ -28,7 +28,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: parse.c,v 1.1.1.4 2016/01/10 19:44:39 christos Exp $");
|
||||
__RCSID("$NetBSD: parse.c,v 1.2 2017/06/28 02:46:30 manu Exp $");
|
||||
|
||||
#include "dhcpd.h"
|
||||
#include <syslog.h>
|
||||
@ -2155,7 +2155,7 @@ int parse_executable_statement (result, cfile, lose, case_context)
|
||||
return 0;
|
||||
}
|
||||
cta = (struct class *)0;
|
||||
status = find_class (&cta, val, MDL);
|
||||
status = libdhcp_callbacks.find_class (&cta, val, MDL);
|
||||
if (status != ISC_R_SUCCESS) {
|
||||
parse_warn (cfile, "class %s: %s",
|
||||
val, isc_result_totext (status));
|
||||
@ -2222,7 +2222,7 @@ int parse_executable_statement (result, cfile, lose, case_context)
|
||||
pad:
|
||||
skip_token(&val, (unsigned *)0, cfile);
|
||||
cache = (struct option_cache *)0;
|
||||
if (!parse_allow_deny (&cache, cfile, flag))
|
||||
if (!libdhcp_callbacks.parse_allow_deny (&cache, cfile, flag))
|
||||
return 0;
|
||||
if (!executable_statement_allocate (result, MDL))
|
||||
log_fatal ("no memory for new statement.");
|
||||
|
9
external/bsd/dhcp/dist/common/raw.c
vendored
9
external/bsd/dhcp/dist/common/raw.c
vendored
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: raw.c,v 1.1.1.2 2014/07/12 11:57:46 spz Exp $ */
|
||||
/* $NetBSD: raw.c,v 1.2 2017/06/28 02:46:30 manu Exp $ */
|
||||
/* raw.c
|
||||
|
||||
BSD raw socket interface code... */
|
||||
@ -41,7 +41,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: raw.c,v 1.1.1.2 2014/07/12 11:57:46 spz Exp $");
|
||||
__RCSID("$NetBSD: raw.c,v 1.2 2017/06/28 02:46:30 manu Exp $");
|
||||
|
||||
#include "dhcpd.h"
|
||||
|
||||
@ -59,14 +59,15 @@ void if_register_send (info)
|
||||
|
||||
/* Set up the address we're going to connect to. */
|
||||
name.sin_family = AF_INET;
|
||||
name.sin_port = local_port;
|
||||
name.sin_port = *libdhcp_callbacks.local_port;
|
||||
name.sin_addr.s_addr = htonl (INADDR_BROADCAST);
|
||||
memset (name.sin_zero, 0, sizeof (name.sin_zero));
|
||||
|
||||
/* List addresses on which we're listening. */
|
||||
if (!quiet_interface_discovery)
|
||||
log_info ("Sending on %s, port %d",
|
||||
piaddr (info -> address), htons (local_port));
|
||||
piaddr (info -> address),
|
||||
htons (*libdhcp_callbacks.local_port));
|
||||
if ((sock = socket (AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0)
|
||||
log_fatal ("Can't create dhcp socket: %m");
|
||||
|
||||
|
14
external/bsd/dhcp/dist/common/socket.c
vendored
14
external/bsd/dhcp/dist/common/socket.c
vendored
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: socket.c,v 1.1.1.4 2016/01/10 19:44:40 christos Exp $ */
|
||||
/* $NetBSD: socket.c,v 1.2 2017/06/28 02:46:30 manu Exp $ */
|
||||
/* socket.c
|
||||
|
||||
BSD socket interface code... */
|
||||
@ -28,7 +28,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: socket.c,v 1.1.1.4 2016/01/10 19:44:40 christos Exp $");
|
||||
__RCSID("$NetBSD: socket.c,v 1.2 2017/06/28 02:46:30 manu Exp $");
|
||||
|
||||
/* SO_BINDTODEVICE support added by Elliot Poger (poger@leland.stanford.edu).
|
||||
* This sockopt allows a socket to be bound to a particular interface,
|
||||
@ -159,7 +159,7 @@ if_register_socket(struct interface_info *info, int family,
|
||||
case AF_INET6:
|
||||
addr6 = (struct sockaddr_in6 *)&name;
|
||||
addr6->sin6_family = AF_INET6;
|
||||
addr6->sin6_port = local_port;
|
||||
addr6->sin6_port = *libdhcp_callbacks.local_port;
|
||||
if (linklocal6) {
|
||||
memcpy(&addr6->sin6_addr,
|
||||
linklocal6,
|
||||
@ -181,7 +181,7 @@ if_register_socket(struct interface_info *info, int family,
|
||||
default:
|
||||
addr = (struct sockaddr_in *)&name;
|
||||
addr->sin_family = AF_INET;
|
||||
addr->sin_port = local_port;
|
||||
addr->sin_port = *libdhcp_callbacks.local_port;
|
||||
memcpy(&addr->sin_addr,
|
||||
&local_address,
|
||||
sizeof(addr->sin_addr));
|
||||
@ -498,7 +498,8 @@ if_register6(struct interface_info *info, int do_multicast) {
|
||||
*/
|
||||
log_fatal("Impossible condition at %s:%d", MDL);
|
||||
} else {
|
||||
log_info("Bound to *:%d", ntohs(local_port));
|
||||
log_info("Bound to *:%d",
|
||||
ntohs(*libdhcp_callbacks.local_port));
|
||||
}
|
||||
}
|
||||
|
||||
@ -617,7 +618,8 @@ if_deregister6(struct interface_info *info) {
|
||||
close(global_v6_socket);
|
||||
global_v6_socket = -1;
|
||||
|
||||
log_info("Unbound from *:%d", ntohs(local_port));
|
||||
log_info("Unbound from *:%d",
|
||||
ntohs(*libdhcp_callbacks.local_port));
|
||||
}
|
||||
}
|
||||
#endif /* DHCPv6 */
|
||||
|
6
external/bsd/dhcp/dist/common/tr.c
vendored
6
external/bsd/dhcp/dist/common/tr.c
vendored
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: tr.c,v 1.1.1.3 2014/07/12 11:57:48 spz Exp $ */
|
||||
/* $NetBSD: tr.c,v 1.2 2017/06/28 02:46:30 manu Exp $ */
|
||||
/* tr.c
|
||||
|
||||
token ring interface support
|
||||
@ -29,7 +29,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: tr.c,v 1.1.1.3 2014/07/12 11:57:48 spz Exp $");
|
||||
__RCSID("$NetBSD: tr.c,v 1.2 2017/06/28 02:46:30 manu Exp $");
|
||||
|
||||
#include "dhcpd.h"
|
||||
|
||||
@ -179,7 +179,7 @@ ssize_t decode_tr_header (interface, buf, bufix, from)
|
||||
|| ntohs(llc->ethertype) != ETHERTYPE_IP
|
||||
|| ip->ip_p != IPPROTO_UDP
|
||||
|| (ntohs (ip->ip_off) & IP_OFFMASK) != 0
|
||||
|| udp->uh_dport != local_port)
|
||||
|| udp->uh_dport != *libdhcp_callbacks.local_port)
|
||||
return -1;
|
||||
|
||||
/* only save source routing information for packets from valued hosts */
|
||||
|
8
external/bsd/dhcp/dist/common/tree.c
vendored
8
external/bsd/dhcp/dist/common/tree.c
vendored
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: tree.c,v 1.1.1.4 2016/01/10 19:44:40 christos Exp $ */
|
||||
/* $NetBSD: tree.c,v 1.2 2017/06/28 02:46:30 manu Exp $ */
|
||||
/* tree.c
|
||||
|
||||
Routines for manipulating parse trees... */
|
||||
@ -29,7 +29,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: tree.c,v 1.1.1.4 2016/01/10 19:44:40 christos Exp $");
|
||||
__RCSID("$NetBSD: tree.c,v 1.2 2017/06/28 02:46:30 manu Exp $");
|
||||
|
||||
#include "dhcpd.h"
|
||||
#include <omapip/omapip_p.h>
|
||||
@ -719,8 +719,8 @@ int evaluate_boolean_expression (result, packet, lease, client_state,
|
||||
|
||||
switch (expr -> op) {
|
||||
case expr_check:
|
||||
*result = check_collection (packet, lease,
|
||||
expr -> data.check);
|
||||
*result = libdhcp_callbacks.check_collection (packet, lease,
|
||||
expr -> data.check);
|
||||
#if defined (DEBUG_EXPRESSIONS)
|
||||
log_debug ("bool: check (%s) returns %s",
|
||||
expr -> data.check -> name,
|
||||
|
6
external/bsd/dhcp/dist/common/upf.c
vendored
6
external/bsd/dhcp/dist/common/upf.c
vendored
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: upf.c,v 1.1.1.3 2016/01/10 19:44:40 christos Exp $ */
|
||||
/* $NetBSD: upf.c,v 1.2 2017/06/28 02:46:30 manu Exp $ */
|
||||
/* upf.c
|
||||
|
||||
Ultrix PacketFilter interface code. */
|
||||
@ -28,7 +28,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: upf.c,v 1.1.1.3 2016/01/10 19:44:40 christos Exp $");
|
||||
__RCSID("$NetBSD: upf.c,v 1.2 2017/06/28 02:46:30 manu Exp $");
|
||||
|
||||
#include "dhcpd.h"
|
||||
#if defined (USE_UPF_SEND) || defined (USE_UPF_RECEIVE)
|
||||
@ -205,7 +205,7 @@ void if_register_receive (info)
|
||||
pf.enf_Filter [pf.enf_FilterLen++] = ENF_CAND;
|
||||
pf.enf_Filter [pf.enf_FilterLen++] = ENF_PUSHWORD + 18;
|
||||
pf.enf_Filter [pf.enf_FilterLen++] = ENF_PUSHLIT + ENF_CAND;
|
||||
pf.enf_Filter [pf.enf_FilterLen++] = local_port;
|
||||
pf.enf_Filter [pf.enf_FilterLen++] = *libdhcp_callbacks.local_port;
|
||||
|
||||
if (ioctl (info -> rfdesc, EIOCSETF, &pf) < 0)
|
||||
log_fatal ("Can't install packet filter program: %m");
|
||||
|
23
external/bsd/dhcp/dist/dhcpctl/cltest.c
vendored
23
external/bsd/dhcp/dist/dhcpctl/cltest.c
vendored
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: cltest.c,v 1.1.1.3 2014/07/12 11:57:51 spz Exp $ */
|
||||
/* $NetBSD: cltest.c,v 1.2 2017/06/28 02:46:30 manu Exp $ */
|
||||
/* cltest.c
|
||||
|
||||
Example program that uses the dhcpctl library. */
|
||||
@ -30,7 +30,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: cltest.c,v 1.1.1.3 2014/07/12 11:57:51 spz Exp $");
|
||||
__RCSID("$NetBSD: cltest.c,v 1.2 2017/06/28 02:46:30 manu Exp $");
|
||||
|
||||
#include "config.h"
|
||||
|
||||
@ -43,6 +43,23 @@ __RCSID("$NetBSD: cltest.c,v 1.1.1.3 2014/07/12 11:57:51 spz Exp $");
|
||||
#include "omapip/result.h"
|
||||
#include "dhcpctl.h"
|
||||
|
||||
uint16_t local_port = 0;
|
||||
uint16_t remote_port = 0;
|
||||
libdhcp_callbacks_t cltest_callbacks = {
|
||||
&local_port,
|
||||
&remote_port,
|
||||
classify,
|
||||
check_collection,
|
||||
dhcp,
|
||||
#ifdef DHCPv6
|
||||
dhcpv6,
|
||||
#endif /* DHCPv6 */
|
||||
bootp,
|
||||
find_class,
|
||||
parse_allow_deny,
|
||||
dhcp_set_control_state,
|
||||
};
|
||||
|
||||
int main (int, char **);
|
||||
|
||||
enum modes { up, down, undefined };
|
||||
@ -67,6 +84,8 @@ int main (argc, argv)
|
||||
int mode = undefined;
|
||||
const char *interface = 0;
|
||||
const char *action;
|
||||
|
||||
libdhcp_callbacks_register(&cltest_callbacks);
|
||||
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (!strcmp (argv[i], "-u")) {
|
||||
|
23
external/bsd/dhcp/dist/dhcpctl/omshell.c
vendored
23
external/bsd/dhcp/dist/dhcpctl/omshell.c
vendored
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: omshell.c,v 1.1.1.3 2016/01/10 19:44:41 christos Exp $ */
|
||||
/* $NetBSD: omshell.c,v 1.2 2017/06/28 02:46:30 manu Exp $ */
|
||||
/* omshell.c
|
||||
|
||||
Examine and modify omapi objects. */
|
||||
@ -29,7 +29,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: omshell.c,v 1.1.1.3 2016/01/10 19:44:41 christos Exp $");
|
||||
__RCSID("$NetBSD: omshell.c,v 1.2 2017/06/28 02:46:30 manu Exp $");
|
||||
|
||||
#include "config.h"
|
||||
|
||||
@ -44,6 +44,23 @@ __RCSID("$NetBSD: omshell.c,v 1.1.1.3 2016/01/10 19:44:41 christos Exp $");
|
||||
#include "dhcpctl.h"
|
||||
#include "dhcpd.h"
|
||||
|
||||
uint16_t local_port = 0;
|
||||
uint16_t remote_port = 0;
|
||||
libdhcp_callbacks_t omshell_callbacks = {
|
||||
&local_port,
|
||||
&remote_port,
|
||||
classify,
|
||||
check_collection,
|
||||
dhcp,
|
||||
#ifdef DHCPv6
|
||||
dhcpv6,
|
||||
#endif /* DHCPv6 */
|
||||
bootp,
|
||||
find_class,
|
||||
parse_allow_deny,
|
||||
dhcp_set_control_state,
|
||||
};
|
||||
|
||||
/* Fixups */
|
||||
isc_result_t find_class (struct class **c, const char *n, const char *f, int l)
|
||||
{
|
||||
@ -99,6 +116,8 @@ main(int argc, char **argv) {
|
||||
int connected = 0;
|
||||
char hex_buf[1025];
|
||||
|
||||
libdhcp_callbacks_register(&omshell_callbacks);
|
||||
|
||||
for (i = 1; i < argc; i++) {
|
||||
usage(argv[0]);
|
||||
}
|
||||
|
24
external/bsd/dhcp/dist/includes/dhcpd.h
vendored
24
external/bsd/dhcp/dist/includes/dhcpd.h
vendored
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: dhcpd.h,v 1.8 2016/01/10 20:10:44 christos Exp $ */
|
||||
/* $NetBSD: dhcpd.h,v 1.9 2017/06/28 02:46:30 manu Exp $ */
|
||||
/* dhcpd.h
|
||||
|
||||
Definitions for dhcpd... */
|
||||
@ -3767,6 +3767,28 @@ void lc_delete_all(struct leasechain *lc);
|
||||
#define MAX_ADDRESS_STRING_LEN \
|
||||
(sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"))
|
||||
|
||||
typedef struct libdhcp_callbacks {
|
||||
uint16_t *local_port;
|
||||
uint16_t *remote_port;
|
||||
void (*classify) (struct packet *, struct class *);
|
||||
int (*check_collection) (struct packet *, struct lease *,
|
||||
struct collection *);
|
||||
void (*dhcp) (struct packet *);
|
||||
#ifdef DHCPv6
|
||||
void (*dhcpv6) (struct packet *);
|
||||
#endif /* DHCPv6 */
|
||||
void (*bootp) (struct packet *);
|
||||
isc_result_t (*find_class) (struct class **, const char *,
|
||||
const char *, int);
|
||||
int (*parse_allow_deny) (struct option_cache **, struct parse *, int);
|
||||
isc_result_t (*dhcp_set_control_state) (control_object_state_t,
|
||||
control_object_state_t);
|
||||
} libdhcp_callbacks_t;
|
||||
|
||||
extern libdhcp_callbacks_t libdhcp_callbacks;
|
||||
|
||||
void libdhcp_callbacks_register(libdhcp_callbacks_t *);
|
||||
|
||||
/* Find the percentage of count. We need to try two different
|
||||
* ways to avoid rounding mistakes.
|
||||
*/
|
||||
|
27
external/bsd/dhcp/dist/relay/dhcrelay.c
vendored
27
external/bsd/dhcp/dist/relay/dhcrelay.c
vendored
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: dhcrelay.c,v 1.7 2017/06/05 07:35:23 manu Exp $ */
|
||||
/* $NetBSD: dhcrelay.c,v 1.8 2017/06/28 02:46:30 manu Exp $ */
|
||||
/* dhcrelay.c
|
||||
|
||||
DHCP/BOOTP Relay Agent. */
|
||||
@ -28,7 +28,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: dhcrelay.c,v 1.7 2017/06/05 07:35:23 manu Exp $");
|
||||
__RCSID("$NetBSD: dhcrelay.c,v 1.8 2017/06/28 02:46:30 manu Exp $");
|
||||
|
||||
#include "dhcpd.h"
|
||||
#include <syslog.h>
|
||||
@ -94,8 +94,8 @@ enum { forward_and_append, /* Forward and append our own relay option. */
|
||||
forward_untouched, /* Forward without changes. */
|
||||
discard } agent_relay_mode = forward_and_replace;
|
||||
|
||||
u_int16_t local_port;
|
||||
u_int16_t remote_port;
|
||||
u_int16_t local_port = 0;
|
||||
u_int16_t remote_port = 0;
|
||||
|
||||
/* Relay agent server list. */
|
||||
struct server_list {
|
||||
@ -124,6 +124,21 @@ static void setup_streams(void);
|
||||
char *dhcrelay_sub_id = NULL;
|
||||
#endif
|
||||
|
||||
libdhcp_callbacks_t dhcrelay_callbacks = {
|
||||
&local_port,
|
||||
&remote_port,
|
||||
classify,
|
||||
check_collection,
|
||||
dhcp,
|
||||
#ifdef DHCPv6
|
||||
dhcpv6,
|
||||
#endif /* DHCPv6 */
|
||||
bootp,
|
||||
find_class,
|
||||
parse_allow_deny,
|
||||
dhcp_set_control_state,
|
||||
};
|
||||
|
||||
static void do_relay4(struct interface_info *, struct dhcp_packet *,
|
||||
unsigned int, unsigned int, struct iaddr,
|
||||
struct hardware *);
|
||||
@ -188,6 +203,8 @@ main(int argc, char **argv) {
|
||||
int local_family_set = 0;
|
||||
#endif
|
||||
|
||||
libdhcp_callbacks_register(&dhcrelay_callbacks);
|
||||
|
||||
/* Make sure that file descriptors 0(stdin), 1,(stdout), and
|
||||
2(stderr) are open. To do this, we assume that when we
|
||||
open a file the lowest available file descriptor is used. */
|
||||
@ -948,7 +965,7 @@ find_interface_by_agent_option(struct dhcp_packet *packet,
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: dhcrelay.c,v 1.7 2017/06/05 07:35:23 manu Exp $");
|
||||
__RCSID("$NetBSD: dhcrelay.c,v 1.8 2017/06/28 02:46:30 manu Exp $");
|
||||
static int
|
||||
add_relay_agent_options(struct interface_info *ip, struct dhcp_packet *packet,
|
||||
unsigned length, struct in_addr giaddr) {
|
||||
|
25
external/bsd/dhcp/dist/server/dhcpd.c
vendored
25
external/bsd/dhcp/dist/server/dhcpd.c
vendored
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: dhcpd.c,v 1.5 2016/01/10 20:10:45 christos Exp $ */
|
||||
/* $NetBSD: dhcpd.c,v 1.6 2017/06/28 02:46:31 manu Exp $ */
|
||||
/* dhcpd.c
|
||||
|
||||
DHCP Server Daemon. */
|
||||
@ -28,7 +28,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: dhcpd.c,v 1.5 2016/01/10 20:10:45 christos Exp $");
|
||||
__RCSID("$NetBSD: dhcpd.c,v 1.6 2017/06/28 02:46:31 manu Exp $");
|
||||
|
||||
static const char copyright[] =
|
||||
"Copyright 2004-2015 Internet Systems Consortium.";
|
||||
@ -98,6 +98,23 @@ int omapi_port;
|
||||
trace_type_t *trace_srandom;
|
||||
#endif
|
||||
|
||||
uint16_t local_port = 0;
|
||||
uint16_t remote_port = 0;
|
||||
libdhcp_callbacks_t dhcpd_callbacks = {
|
||||
&local_port,
|
||||
&remote_port,
|
||||
classify,
|
||||
check_collection,
|
||||
dhcp,
|
||||
#ifdef DHCPv6
|
||||
dhcpv6,
|
||||
#endif /* DHCPv6 */
|
||||
bootp,
|
||||
find_class,
|
||||
parse_allow_deny,
|
||||
dhcp_set_control_state,
|
||||
};
|
||||
|
||||
static isc_result_t verify_addr (omapi_object_t *l, omapi_addr_t *addr) {
|
||||
return ISC_R_SUCCESS;
|
||||
}
|
||||
@ -141,7 +158,7 @@ static void omapi_listener_start (void *foo)
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: dhcpd.c,v 1.5 2016/01/10 20:10:45 christos Exp $");
|
||||
__RCSID("$NetBSD: dhcpd.c,v 1.6 2017/06/28 02:46:31 manu Exp $");
|
||||
|
||||
#if defined (PARANOIA)
|
||||
/* to be used in one of two possible scenarios */
|
||||
@ -198,6 +215,8 @@ main(int argc, char **argv) {
|
||||
char *set_chroot = 0;
|
||||
#endif /* PARANOIA */
|
||||
|
||||
libdhcp_callbacks_register(&dhcpd_callbacks);
|
||||
|
||||
/* Make sure that file descriptors 0 (stdin), 1, (stdout), and
|
||||
2 (stderr) are open. To do this, we assume that when we
|
||||
open a file the lowest available file descriptor is used. */
|
||||
|
21
external/bsd/dhcp/dist/tests/t_api.c
vendored
21
external/bsd/dhcp/dist/tests/t_api.c
vendored
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: t_api.c,v 1.1.1.3 2014/07/12 11:58:01 spz Exp $ */
|
||||
/* $NetBSD: t_api.c,v 1.2 2017/06/28 02:46:31 manu Exp $ */
|
||||
/*
|
||||
* Copyright (C) 2004, 2005, 2007, 2009 Internet Systems Consortium, Inc. ("ISC")
|
||||
* Copyright (C) 1999-2003 Internet Software Consortium.
|
||||
@ -125,6 +125,23 @@ printusage(void);
|
||||
|
||||
static int T_int;
|
||||
|
||||
uint16_t local_port = 0;
|
||||
uint16_t remote_port = 0;
|
||||
libdhcp_callbacks_t t_api_callbacks = {
|
||||
&local_port,
|
||||
&remote_port,
|
||||
classify,
|
||||
check_collection,
|
||||
dhcp,
|
||||
#ifdef DHCPv6
|
||||
dhcpv6,
|
||||
#endif /* DHCPv6 */
|
||||
bootp,
|
||||
find_class,
|
||||
parse_allow_deny,
|
||||
dhcp_set_control_state,
|
||||
};
|
||||
|
||||
static void
|
||||
t_sighandler(int sig) {
|
||||
T_int = sig;
|
||||
@ -149,6 +166,8 @@ main(int argc, char **argv) {
|
||||
subprocs = 1;
|
||||
T_timeout = T_TCTOUT;
|
||||
|
||||
libdhcp_callbacks_register(&t_api_callbacks);
|
||||
|
||||
/*
|
||||
* -a option is now default.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user