version 1.1.1.3, 2021/05/26 22:48:50 |
version 1.1.1.4, 2022/04/03 01:08:42 |
|
|
DHCP/BOOTP Relay Agent. */ |
DHCP/BOOTP Relay Agent. */ |
|
|
/* |
/* |
* Copyright(c) 2004-2021 by Internet Systems Consortium, Inc.("ISC") |
* Copyright(c) 2004-2022 by Internet Systems Consortium, Inc.("ISC") |
* Copyright(c) 1997-2003 by Internet Software Consortium |
* Copyright(c) 1997-2003 by Internet Software Consortium |
* |
* |
* This Source Code Form is subject to the terms of the Mozilla Public |
* This Source Code Form is subject to the terms of the Mozilla Public |
|
|
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
* |
* |
* Internet Systems Consortium, Inc. |
* Internet Systems Consortium, Inc. |
* 950 Charter Street |
* PO Box 360 |
* Redwood City, CA 94063 |
* Newmarket, NH 03857 USA |
* <info@isc.org> |
* <info@isc.org> |
* https://www.isc.org/ |
* https://www.isc.org/ |
* |
* |
Line 100 enum { forward_and_append, /* Forward an |
|
Line 100 enum { forward_and_append, /* Forward an |
|
forward_untouched, /* Forward without changes. */ |
forward_untouched, /* Forward without changes. */ |
discard } agent_relay_mode = forward_and_replace; |
discard } agent_relay_mode = forward_and_replace; |
|
|
u_int16_t local_port; |
extern u_int16_t local_port; |
u_int16_t remote_port; |
extern u_int16_t remote_port; |
|
|
/* Relay agent server list. */ |
/* Relay agent server list. */ |
struct server_list { |
struct server_list { |
Line 110 struct server_list { |
|
Line 110 struct server_list { |
|
} *servers; |
} *servers; |
|
|
struct interface_info *uplink = NULL; |
struct interface_info *uplink = NULL; |
|
isc_boolean_t use_fake_gw = ISC_FALSE; |
|
struct in_addr gw = {0}; |
|
|
#ifdef DHCPv6 |
#ifdef DHCPv6 |
struct stream_list { |
struct stream_list { |
Line 154 extern int strip_relay_agent_options(str |
|
Line 156 extern int strip_relay_agent_options(str |
|
static void request_v4_interface(const char* name, int flags); |
static void request_v4_interface(const char* name, int flags); |
|
|
static const char copyright[] = |
static const char copyright[] = |
"Copyright 2004-2021 Internet Systems Consortium."; |
"Copyright 2004-2022 Internet Systems Consortium."; |
static const char arr[] = "All rights reserved."; |
static const char arr[] = "All rights reserved."; |
static const char message[] = |
static const char message[] = |
"Internet Systems Consortium DHCP Relay Agent"; |
"Internet Systems Consortium DHCP Relay Agent"; |
|
|
" [-i interface0 [ ... -i interfaceN]\n" \ |
" [-i interface0 [ ... -i interfaceN]\n" \ |
" [-iu interface0 [ ... -iu interfaceN]\n" \ |
" [-iu interface0 [ ... -iu interfaceN]\n" \ |
" [-id interface0 [ ... -id interfaceN]\n" \ |
" [-id interface0 [ ... -id interfaceN]\n" \ |
" [-U interface]\n" \ |
" [-U interface] [-g <ip-address>]\n" \ |
" server0 [ ... serverN]\n\n" \ |
" server0 [ ... serverN]\n\n" \ |
" %s -6 [-d] [-q] [-I] [-c <hops>]\n" \ |
" %s -6 [-d] [-q] [-I] [-c <hops>]\n" \ |
" [-p <port> | -rp <relay-port>]\n" \ |
" [-p <port> | -rp <relay-port>]\n" \ |
|
|
" [-i interface0 [ ... -i interfaceN]\n" \ |
" [-i interface0 [ ... -i interfaceN]\n" \ |
" [-iu interface0 [ ... -iu interfaceN]\n" \ |
" [-iu interface0 [ ... -iu interfaceN]\n" \ |
" [-id interface0 [ ... -id interfaceN]\n" \ |
" [-id interface0 [ ... -id interfaceN]\n" \ |
" [-U interface]\n" \ |
" [-U interface] [-g <ip-address>]\n" \ |
" server0 [ ... serverN]\n\n" \ |
" server0 [ ... serverN]\n\n" \ |
" %s -6 [-d] [-q] [-I] [-c <hops>] [-p <port>]\n" \ |
" %s -6 [-d] [-q] [-I] [-c <hops>] [-p <port>]\n" \ |
" [-pf <pid-file>] [--no-pid]\n" \ |
" [-pf <pid-file>] [--no-pid]\n" \ |
|
|
" [-i interface0 [ ... -i interfaceN]\n" \ |
" [-i interface0 [ ... -i interfaceN]\n" \ |
" [-iu interface0 [ ... -iu interfaceN]\n" \ |
" [-iu interface0 [ ... -iu interfaceN]\n" \ |
" [-id interface0 [ ... -id interfaceN]\n" \ |
" [-id interface0 [ ... -id interfaceN]\n" \ |
" [-U interface]\n" \ |
" [-U interface] [-g <ip-address>]\n" \ |
" server0 [ ... serverN]\n\n" \ |
" server0 [ ... serverN]\n\n" \ |
" %s {--version|--help|-h}" |
" %s {--version|--help|-h}" |
#else |
#else |
|
|
" [-i interface0 [ ... -i interfaceN]\n" \ |
" [-i interface0 [ ... -i interfaceN]\n" \ |
" [-iu interface0 [ ... -iu interfaceN]\n" \ |
" [-iu interface0 [ ... -iu interfaceN]\n" \ |
" [-id interface0 [ ... -id interfaceN]\n" \ |
" [-id interface0 [ ... -id interfaceN]\n" \ |
" [-U interface]\n" \ |
" [-U interface] [-g <ip-address>]\n" \ |
" server0 [ ... serverN]\n\n" \ |
" server0 [ ... serverN]\n\n" \ |
" %s {--version|--help|-h}" |
" %s {--version|--help|-h}" |
#endif |
#endif |
|
|
* the description of the command line. The arguments provide |
* the description of the command line. The arguments provide |
* a way for the caller to request more specific information about |
* a way for the caller to request more specific information about |
* the error be printed as well. Mostly this will be that some |
* the error be printed as well. Mostly this will be that some |
* comamnd doesn't include its argument. |
* command doesn't include its argument. |
* |
* |
* \param sfmt - The basic string and format for the specific error |
* \param sfmt - The basic string and format for the specific error |
* \param sarg - Generally the offending argument from the comamnd line. |
* \param sarg - Generally the offending argument from the command line. |
* |
* |
* \return Nothing |
* \return Nothing |
*/ |
*/ |
Line 555 main(int argc, char **argv) { |
|
Line 557 main(int argc, char **argv) { |
|
/* Turn on -a, in case they don't do so explicitly */ |
/* Turn on -a, in case they don't do so explicitly */ |
add_agent_options = 1; |
add_agent_options = 1; |
add_rfc3527_suboption = 1; |
add_rfc3527_suboption = 1; |
|
} else if (!strcmp(argv[i], "-g")) { |
|
if (++i == argc) |
|
usage(use_noarg, argv[i-1]); |
|
#ifdef DHCPv6 |
|
if (local_family_set && (local_family == AF_INET6)) { |
|
usage(use_v4command, argv[i]); |
|
} |
|
local_family_set = 1; |
|
local_family = AF_INET; |
|
#endif |
|
if (inet_pton(AF_INET, argv[i], &gw) <= 0) { |
|
usage("Invalid gateway address '%s'", argv[i]); |
|
} else { |
|
use_fake_gw = ISC_TRUE; |
|
} |
} else if (!strcmp(argv[i], "-D")) { |
} else if (!strcmp(argv[i], "-D")) { |
#ifdef DHCPv6 |
#ifdef DHCPv6 |
if (local_family_set && (local_family == AF_INET6)) { |
if (local_family_set && (local_family == AF_INET6)) { |
Line 886 do_relay4(struct interface_info *ip, str |
|
Line 903 do_relay4(struct interface_info *ip, str |
|
return; |
return; |
} |
} |
|
|
|
log_debug("BOOTREPLY giaddr: %s\n", inet_ntoa(packet->giaddr)); |
if (!(packet->flags & htons(BOOTP_BROADCAST)) && |
if (!(packet->flags & htons(BOOTP_BROADCAST)) && |
can_unicast_without_arp(out)) { |
can_unicast_without_arp(out)) { |
to.sin_addr = packet->yiaddr; |
to.sin_addr = packet->yiaddr; |
Line 924 do_relay4(struct interface_info *ip, str |
|
Line 942 do_relay4(struct interface_info *ip, str |
|
return; |
return; |
} |
} |
|
|
|
if (use_fake_gw) { |
|
packet->giaddr = gw; |
|
} |
|
|
if (send_packet(out, NULL, packet, length, out->addresses[0], |
if (send_packet(out, NULL, packet, length, out->addresses[0], |
&to, htop) < 0) { |
&to, htop) < 0) { |
++server_packet_errors; |
++server_packet_errors; |
Line 1441 add_relay_agent_options(struct interface |
|
Line 1463 add_relay_agent_options(struct interface |
|
return (length); |
return (length); |
} |
} |
|
|
#ifndef UNIT_TEST |
|
|
|
#ifdef DHCPv6 |
#ifdef DHCPv6 |
|
#ifndef UNIT_TEST |
/* |
/* |
* Parse a downstream argument: [address%]interface[#index]. |
* Parse a downstream argument: [address%]interface[#index]. |
*/ |
*/ |
Line 2028 process_down6(struct packet *packet) { |
|
Line 2049 process_down6(struct packet *packet) { |
|
if (if_id.data != NULL) |
if (if_id.data != NULL) |
data_string_forget(&if_id, MDL); |
data_string_forget(&if_id, MDL); |
} |
} |
|
#endif /* UNIT_TEST */ |
|
|
/* |
/* |
* Called by the dispatch packet handler with a decoded packet. |
* Called by the dispatch packet handler with a decoded packet. |
*/ |
*/ |
void |
void |
dhcpv6(struct packet *packet) { |
dhcpv6(struct packet *packet) { |
|
#ifndef UNIT_TEST |
struct stream_list *dp; |
struct stream_list *dp; |
|
|
/* Try all relay-replies downwards. */ |
/* Try all relay-replies downwards. */ |
Line 2056 dhcpv6(struct packet *packet) { |
|
Line 2079 dhcpv6(struct packet *packet) { |
|
|
|
log_info("Can't process packet from interface '%s'.", |
log_info("Can't process packet from interface '%s'.", |
packet->interface->name); |
packet->interface->name); |
|
#endif /* UNIT_TEST */ |
} |
} |
#endif |
#endif /* DHCPv6 */ |
|
|
/* Stub routines needed for linking with DHCP libraries. */ |
/* Stub routines needed for linking with DHCP libraries. */ |
void |
void |
Line 2155 void request_v4_interface(const char* na |
|
Line 2179 void request_v4_interface(const char* na |
|
interface_snorf(tmp, (INTERFACE_REQUESTED | flags)); |
interface_snorf(tmp, (INTERFACE_REQUESTED | flags)); |
interface_dereference(&tmp, MDL); |
interface_dereference(&tmp, MDL); |
} |
} |
#endif /* UNIT_TEST */ |
|