relay.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 1996-2003 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <assert.h>
#include <errno.h>
#include <netdb.h>
#include <string.h>
#include "dhcpd.h"
#include "per_dnet.h"
#include "interfaces.h"
#include <locale.h>
/*
* This file contains the code which implements the BOOTP relay agent.
*/
/*
* Parse arguments. If an agument begins with a digit, then it's
* an IP address, otherwise it's a hostname which needs to be
* resolved into an IP address.
*
* Use the arguments to fill in relay_ip array.
*
* Only callable by main thread. MT UNSAFE
*/
int
relay_agent_init(char *args)
{
int i;
char ntoab[INET_ADDRSTRLEN];
for (i = 0; i <= MAX_RELAY_IP; i++) {
break; /* done */
/*
* If there's more than MAX_RELAY_IP addresses
* specified that's an error. If we can't
* resolve the host name, that's an error.
*/
if (i == MAX_RELAY_IP) {
gettext("Too many relay agent destinations.\n"));
return (E2BIG);
}
"Invalid relay agent destination name: %s\n"),
args);
return (EINVAL);
}
/* LINTED [will be lw aligned] */
/*
* Note: no way to guess at destination subnet mask,
* and verify that it's not a new broadcast addr.
*/
cannot be 0, loopback, or broadcast address.\n"));
return (EINVAL);
}
if (verbose) {
gettext("Relay destination: %s (%s)"),
}
}
if (i == 0) {
/*
* Gotta specify at least one IP addr.
*/
gettext("Specify at least one relay agent destination.\n"));
return (ENOENT);
}
if (i < MAX_RELAY_IP)
return (0);
}
/*
* Note: if_head_mtx must be held by caller, as the interface list is
* walked in relay_reply.
*
* MT SAFE
*/
int
{
}
/*
* MT SAFE
*/
static int
{
struct sockaddr_in to;
int i;
char ntoab[INET_ADDRSTRLEN];
/*
* Send it on to the next relay(s)/servers
*/
for (i = 0; i < MAX_RELAY_IP; i++) {
break; /* we're done */
if (verbose) {
%1$s is the same as client %2$s network, ignored.\n",
buf);
}
continue; /* skip this target */
}
msg = "Relaying request %1$s to %2$s, server port.\n";
else
msg = "Relaying request %1$s to %2$s, client port.\n";
if (debug) {
}
} else {
plp);
}
}
return (0);
}
/*
* Note: if_head_mtx must be held by caller, as the interface list is
* walked here.
*/
static int
{
int err;
char buf[DHCP_MAX_OPT_SIZE];
/*
* Somehow we picked up a reply packet from a DHCP server
* on this net intended for a client on this net. Drop it.
*/
if (verbose) {
"Reply packet without giaddr set ignored.\n");
}
return (0);
}
/*
* server to us, and we are to address it directly to the client.
*/
/*
* It is possible that this is a multihomed host. We'll
* check to see if this is the case, and handle it
* appropriately.
*/
break;
}
if (verbose) {
not intended for this interface: %1$s giaddr: %2$s\n",
}
return (0);
} else
}
if (debug)
address or network IP address; cannot send reply to client: %s.\n", buf);
return (0);
}
} else
}
return (err);
}