summaryrefslogtreecommitdiff
path: root/relay
diff options
context:
space:
mode:
authorDavid Hankins <dhankins@isc.org>2006-08-09 14:57:48 +0000
committerDavid Hankins <dhankins@isc.org>2006-08-09 14:57:48 +0000
commit78c553c4a00feae01947eaae167af79460e7c406 (patch)
tree0ec2ad6c34180f9af6d048050b513dd150804699 /relay
parent51c4d3f56fcd33f7d4a4e3d5c06bc028cf5846b4 (diff)
downloadisc-dhcp-78c553c4a00feae01947eaae167af79460e7c406.tar.gz
Removing the new I/O changes from HEAD. [ISC-Bugs #16328]
Diffstat (limited to 'relay')
-rw-r--r--relay/dhcrelay.812
-rw-r--r--relay/dhcrelay.c142
2 files changed, 49 insertions, 105 deletions
diff --git a/relay/dhcrelay.8 b/relay/dhcrelay.8
index 1e0a9a9c..238b16da 100644
--- a/relay/dhcrelay.8
+++ b/relay/dhcrelay.8
@@ -27,7 +27,7 @@
.\" see ``http://www.isc.org/isc''. To learn more about Vixie
.\" Enterprises, see ``http://www.vix.com''.
.\"
-.\" $Id: dhcrelay.8,v 1.11 2006/02/27 23:56:13 dhankins Exp $
+.\" $Id: dhcrelay.8,v 1.12 2006/08/09 14:57:48 dhankins Exp $
.\"
.TH dhcrelay 8
.SH NAME
@@ -48,11 +48,6 @@ dhcrelay - Dynamic Host Configuration Protocol Relay Agent
.B -i
.I if0
[
-.B -is
-.I server
-...
-]
-[
.B ...
.B -i
.I ifN
@@ -119,11 +114,6 @@ server) is attached. However, in some cases it may be necessary to
exclude some networks; in this case, you must list all those network
interfaces that should \fInot\fR be excluded using the \fB-i\fR flag.
.PP
-The
-.B -is
-flag can be used to indicate that for the previous interface specified with
--i, packets should be forwarded to the specified server.
-.PP
In some cases it
.I is
helpful for the relay agent to forward requests from networks on which
diff --git a/relay/dhcrelay.c b/relay/dhcrelay.c
index 859fcf0f..8465b03b 100644
--- a/relay/dhcrelay.c
+++ b/relay/dhcrelay.c
@@ -34,7 +34,7 @@
#ifndef lint
static char ocopyright[] =
-"$Id: dhcrelay.c,v 1.58 2006/05/11 14:48:59 shane Exp $ Copyright (c) 2004-2006 Internet Systems Consortium. All rights reserved.\n";
+"$Id: dhcrelay.c,v 1.59 2006/08/09 14:57:48 dhankins Exp $ Copyright (c) 2004-2006 Internet Systems Consortium. All rights reserved.\n";
#endif /* not lint */
#include "dhcpd.h"
@@ -92,6 +92,12 @@ enum { forward_and_append, /* Forward and append our own relay option. */
u_int16_t local_port;
u_int16_t remote_port;
+/* Relay agent server list. */
+struct server_list {
+ struct server_list *next;
+ struct sockaddr_in to;
+} *servers;
+
static char copyright [] = "Copyright 2004-2006 Internet Systems Consortium.";
static char arr [] = "All rights reserved.";
static char message [] = "Internet Systems Consortium DHCP Relay Agent";
@@ -104,12 +110,11 @@ int main (argc, argv, envp)
int fd;
int i;
struct servent *ent;
- struct server_list *sp = (struct server_list *)0;
+ struct server_list *sp = NULL;
int no_daemon = 0;
int quiet = 0;
isc_result_t status;
char *s;
- struct interface_info *tmp = (struct interface_info *)0;
/* Make sure that file descriptors 0 (stdin), 1, (stdout), and
2 (stderr) are open. To do this, we assume that when we
@@ -154,8 +159,8 @@ int main (argc, argv, envp)
} else if (!strcmp (argv [i], "-d")) {
no_daemon = 1;
} else if (!strcmp (argv [i], "-i")) {
- if (tmp)
- interface_dereference (&tmp, MDL);
+ struct interface_info *tmp =
+ (struct interface_info *)0;
status = interface_allocate (&tmp, MDL);
if (status != ISC_R_SUCCESS)
log_fatal ("%s: interface_allocate: %s",
@@ -166,14 +171,7 @@ int main (argc, argv, envp)
}
strcpy (tmp -> name, argv [i]);
interface_snorf (tmp, INTERFACE_REQUESTED);
- } else if (!strcmp (argv [i], "-is")) {
- if (++i == argc)
- usage ();
- if (!tmp) {
- log_error ("-is must follow -i.");
- usage ();
- }
- new_relay_server (argv [i], &tmp -> servers);
+ interface_dereference (&tmp, MDL);
} else if (!strcmp (argv [i], "-q")) {
quiet = 1;
quiet_interface_discovery = 1;
@@ -213,15 +211,33 @@ int main (argc, argv, envp)
log_info ("isc-dhcrelay-%s", DHCP_VERSION);
exit (0);
} else {
- new_relay_server (argv [i], &servers);
+ struct hostent *he;
+ struct in_addr ia, *iap = (struct in_addr *)0;
+ if (inet_aton (argv [i], &ia)) {
+ iap = &ia;
+ } else {
+ he = gethostbyname (argv [i]);
+ if (!he) {
+ log_error ("%s: host unknown",
+ argv [i]);
+ } else {
+ iap = ((struct in_addr *)
+ he -> h_addr_list [0]);
+ }
+ }
+ if (iap) {
+ sp = ((struct server_list *)
+ dmalloc (sizeof *sp, MDL));
+ if (!sp)
+ log_fatal ("no memory for server.\n");
+ sp -> next = servers;
+ servers = sp;
+ memcpy (&sp -> to.sin_addr,
+ iap, sizeof *iap);
+ }
}
}
- limited_broadcast.s_addr = INADDR_BROADCAST;
-
- if (tmp)
- interface_dereference (&tmp, MDL);
-
if ((s = getenv ("PATH_DHCRELAY_PID"))) {
path_dhcrelay_pid = s;
}
@@ -248,7 +264,7 @@ int main (argc, argv, envp)
remote_port = htons (ntohs (local_port) + 1);
/* We need at least one server. */
- if (!servers) {
+ if (!sp) {
usage ();
}
@@ -261,29 +277,6 @@ int main (argc, argv, envp)
#endif
}
- if (interfaces) {
- interface_reference (&tmp, interfaces, MDL);
- do {
- struct interface_info *next = NULL;
- if (tmp -> next)
- interface_reference (&next, tmp -> next, MDL);
-
- for (sp = tmp -> servers; sp; sp = sp -> next) {
- sp -> to.sin_port = local_port;
- sp -> to.sin_family = AF_INET;
-#ifdef HAVE_SA_LEN
- sp -> to.sin_len = sizeof sp -> to;
-#endif
- }
-
- interface_dereference (&tmp, MDL);
- if (next) {
- interface_reference (&tmp, next, MDL);
- interface_dereference (&next, MDL);
- }
- } while (tmp);
- }
-
/* Get the current time... */
GET_TIME (&cur_time);
@@ -335,36 +328,6 @@ int main (argc, argv, envp)
return 0;
}
-void new_relay_server (char *arg, struct server_list **servers)
-{
- struct hostent *he;
- struct in_addr ia, *iap = (struct in_addr *)0;
- struct server_list *sp;
-
- if (inet_aton (arg, &ia)) {
- iap = &ia;
- } else {
- he = gethostbyname (arg);
- if (!he) {
- log_error ("%s: host unknown", arg);
- } else {
- iap = ((struct in_addr *)
- he -> h_addr_list [0]);
- }
- }
- if (iap) {
- sp = ((struct server_list *)
- dmalloc (sizeof *sp, MDL));
- if (!sp)
- log_fatal ("no memory for server.\n");
- memset(sp, 0, sizeof *sp);
- sp -> next = *servers;
- *servers = sp;
- memcpy (&sp -> to.sin_addr,
- iap, sizeof *iap);
- }
-}
-
void relay (ip, packet, length, from_port, from, hfrom)
struct interface_info *ip;
struct dhcp_packet *packet;
@@ -377,7 +340,6 @@ void relay (ip, packet, length, from_port, from, hfrom)
struct sockaddr_in to;
struct interface_info *out;
struct hardware hto, *htop;
- int i;
if (packet -> hlen > sizeof packet -> chaddr) {
log_info ("Discarding packet with invalid hlen.");
@@ -388,16 +350,14 @@ void relay (ip, packet, length, from_port, from, hfrom)
in the packet. */
if (packet -> giaddr.s_addr) {
for (out = interfaces; out; out = out -> next) {
- for (i = 0; i < out -> address_count; i++) {
- if (out -> addresses [i].s_addr ==
- packet -> giaddr.s_addr)
- goto matched;
- }
+ if (!memcmp (&out -> primary_address,
+ &packet -> giaddr,
+ sizeof packet -> giaddr))
+ break;
}
} else {
out = (struct interface_info *)0;
}
- matched:
/* If it's a bootreply, forward it to the client. */
if (packet -> op == BOOTREPLY) {
@@ -433,18 +393,15 @@ void relay (ip, packet, length, from_port, from, hfrom)
return;
if (!out) {
- log_error ("packet to bogus giaddr %s.",
+ log_error ("packet to bogus giaddr %s.\n",
inet_ntoa (packet -> giaddr));
++bogus_giaddr_drops;
return;
}
- if (out -> address_count < 1)
- log_fatal ("no IP address on interface %s!",
- out -> name);
if (send_packet (out,
(struct packet *)0,
- packet, length, out -> addresses [0],
+ packet, length, out -> primary_address,
&to, htop) < 0) {
++server_packet_errors;
} else {
@@ -463,13 +420,10 @@ void relay (ip, packet, length, from_port, from, hfrom)
if (out)
return;
- if (ip -> address_count < 1)
- log_fatal ("no IP address on interface %s", ip -> name);
-
/* Add relay agent options if indicated. If something goes wrong,
drop the packet. */
if (!(length = add_relay_agent_options (ip, packet, length,
- ip -> addresses [0])))
+ ip -> primary_address)))
return;
/* If giaddr is not already set, Set it so the server can
@@ -478,7 +432,7 @@ void relay (ip, packet, length, from_port, from, hfrom)
set, the response will be sent directly to the relay agent
that set giaddr, so we won't see it. */
if (!packet -> giaddr.s_addr)
- packet -> giaddr = ip -> addresses [0];
+ packet -> giaddr = ip -> primary_address;
if (packet -> hops < max_hop_count)
packet -> hops = packet -> hops + 1;
else
@@ -486,12 +440,11 @@ void relay (ip, packet, length, from_port, from, hfrom)
/* Otherwise, it's a BOOTREQUEST, so forward it to all the
servers. */
- for (sp = (ip -> servers
- ? ip -> servers : servers); sp; sp = sp -> next) {
+ for (sp = servers; sp; sp = sp -> next) {
if (send_packet ((fallback_interface
? fallback_interface : interfaces),
(struct packet *)0,
- packet, length, ip -> addresses [0],
+ packet, length, ip -> primary_address,
&sp -> to, (struct hardware *)0) < 0) {
++client_packet_errors;
} else {
@@ -502,12 +455,13 @@ void relay (ip, packet, length, from_port, from, hfrom)
++client_packets_relayed;
}
}
+
}
static void usage ()
{
log_fatal ("Usage: dhcrelay [-p <port>] [-d] [-D] [-i %s%s%s%s",
- "interface [-is server ... ]]\n ",
+ "interface] [-q] [-a]\n ",
"[-c count] [-A length] ",
"[-m append|replace|forward|discard]\n",
" [server1 [... serverN]]");