bootp.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 2005 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 <unistd.h>
#include <stdarg.h>
#include <errno.h>
#include <assert.h>
#include <string.h>
#include <syslog.h>
#include <netinet/if_ether.h>
#include <nss_dbdefs.h>
#include <netdb.h>
#include <dhcp_symbol.h>
#include "dhcpd.h"
#include "per_dnet.h"
#include "interfaces.h"
#include <locale.h>
/*
* This file contains the code which implements the BOOTP compatibility.
*/
/*
* We are guaranteed that the packet received is a BOOTP request packet,
* e.g., *NOT* a DHCP packet.
*/
void
{
int pkt_len;
char cidbuf[DHCP_MAX_OPT_SIZE];
char hbuf[NSS_BUFLEN_HOSTS];
#ifdef DEBUG
#endif /* DEBUG */
crecords = 1;
} else {
/*
* Try to find a CID entry for the client. We don't care about
* lease info here, since a BOOTP client always has a permanent
* lease. We also don't care about the entry owner either,
* unless we end up allocating a new entry for the client.
*/
/*
* If a client address (ciaddr) is given, we simply trust that
* the client knows what it's doing, and we use that IP address
* to locate the client's record. If we can't find the client's
* record, then we keep silent. If the client id of the record
* doesn't match this client, then either the client or our
* database is inconsistent, and we'll ignore it (notice
* message generated).
*/
}
crecords = 1;
goto leave_bootp;
}
}
if (crecords == 0 && !be_automatic) {
if (verbose) {
}
goto leave_bootp;
}
/*
* If the client thinks it knows who it is (ciaddr), and this doesn't
* match our registered IP address, then display an error message and
* give up.
*/
/*
* If the client specified an IP address, then let's check
* whether it is available, since we have no CID mapping
* registered for this client. If it is available and
* unassigned but owned by a different server, we ignore the
* client.
*/
/*
* We have no record of this client's IP address, thus
* we really can't respond to this client, because it
* doesn't have a configuration.
*/
if (verbose) {
"client: %1$s. IP address: %2$s not "
"administered by this server.\n",
}
goto leave_bootp;
} else
irecords = 1;
goto leave_bootp;
if (dn.dn_cid_len != 0) {
if (verbose) {
"thinks it owns %2$s, but that "
"address belongs to %3$s. Ignoring "
cidbuf);
}
goto leave_bootp;
}
} else {
if (verbose) {
"believes it owns %2$s. That "
"address is free, but is owned by "
"DHCP server %3$s. Ignoring "
sizeof (ntoab)));
}
goto leave_bootp;
}
}
}
if (crecords == 0) {
/*
* The dhcp-network table did not have any matching entries.
* Try to allocate a new one if possible.
*/
sizeof (cipbuf));
srecords = 1;
}
}
"(%1$s) No more BOOTP IP addresses for %2$s network.\n",
goto leave_bootp;
}
/* Check the address. But only if client doesn't know its address. */
if (!noping) {
/*
* If icmp echo check fails,
* let the plp fall by the wayside.
*/
if (errno != 0) {
"performed for: %s, ignoring\n", cipbuf);
goto leave_bootp;
}
if (result) {
"OFFER candidate: %s, disabling.\n",
cipbuf);
/* Keep the cached entry current. */
}
goto leave_bootp;
}
}
}
/*
* It is possible that the client could specify a REQUEST list,
* but then it would be a DHCP client, wouldn't it? Only copy the
* std option list, since that potentially could be changed by
* load_options().
*/
if (!no_dhcptab) {
open_macros();
/* If dhcptab configured to return hostname, do so. */
NULL) {
}
}
}
/* Produce a BOOTP reply. */
/*
* Set the client's "your" IP address if client doesn't know it,
* otherwise echo the client's ciaddr back to him.
*/
else
/*
* Omit lease time options implicitly, e.g.
* ~(DHCP_DHCP_CLNT | DHCP_SEND_LEASE)
*/
/* Now load in configured options. */
NULL);
if (!no_dhcptab)
close_macros();
/*
* Only perform a write if we have selected an entry not yet
* assigned to the client (a matching DN_FBOOTP_ONLY entry from
* ip address lookup, or an unassigned entry from select_offer()).
*/
/* Keep state of the cached entry current. */
} else {
if (verbose) {
"BOOTP client: %1$s, %2$s\n",
}
}
if (write_error == DSVC_SUCCESS) {
"Reply to BOOTP client %1$s with %2$s failed.\n",
} else {
/* Note that the conversation has completed. */
}
}
}