/*
* Copyright (c) 1992 Regents of the University of California.
* All rights reserved.
*
* This software was developed by the Computer Systems Engineering group
* at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
* contributed to Berkeley.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Lawrence Berkeley Laboratory and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#) Header: arp.c,v 1.5 93/07/15 05:52:26 leres Exp (LBL)
*/
/* Cache stuff */
#define ARP_NUM 8 /* need at most 3 arp entries */
struct arp_list {
struct in_addr addr;
u_char ea[ETHER_ADDR_LEN];
} arp_list[ARP_NUM] = {
/* XXX - net order `INADDR_BROADCAST' must be a constant */
{ {0xffffffff}, BA }
};
int arp_num = 1;
if (ah->arp_op == htons(ARPOP_REQUEST)) {
#ifdef ARP_DEBUG
if (debug)
printf("is request\n");
#endif
arp_reply(d, ah);
return -1;
}
if (ah->arp_op != htons(ARPOP_REPLY)) {
#ifdef ARP_DEBUG
if (debug)
printf("not ARP reply\n");
#endif
return -1;
}
/* Is the reply from the source we want? */
if (memcmp(&arp_list[arp_num].addr,
ah->arp_spa, sizeof(ah->arp_spa)))
{
#ifdef ARP_DEBUG
if (debug)
printf("unwanted address\n");
#endif
return -1;
}
/* We don't care who the reply was sent to. */
/* We have our answer. */
#ifdef ARP_DEBUG
if (debug)
printf("got it\n");
#endif
return n;
}
/*
* Convert an ARP request into a reply and send it.
* Notes: Re-uses buffer. Pad to length = 46.
*/
void
arp_reply(struct iodesc *d, void *pkt)
{
struct ether_arp *arp = pkt;
if (arp->arp_hrd != htons(ARPHRD_ETHER) ||
arp->arp_pro != htons(ETHERTYPE_IP) ||
arp->arp_hln != sizeof(arp->arp_sha) ||
arp->arp_pln != sizeof(arp->arp_spa) )
{
#ifdef ARP_DEBUG
if (debug)
printf("%s: bad hrd/pro/hln/pln\n", __func__);
#endif
return;
}
if (arp->arp_op != htons(ARPOP_REQUEST)) {
#ifdef ARP_DEBUG
if (debug)
printf("%s: not request!\n", __func__);
#endif
return;
}
/* If we are not the target, ignore the request. */
if (memcmp(arp->arp_tpa, &d->myip, sizeof(arp->arp_tpa)))
return;
#ifdef ARP_DEBUG
if (debug) {
printf("%s: to %s\n", __func__, ether_sprintf(arp->arp_sha));
}
#endif
/*
* No need to get fancy here. If the send fails, the
* requestor will just ask again.
*/
(void) sendether(d, pkt, sizeof(*arp) + 18,
arp->arp_tha, ETHERTYPE_ARP);
}