Check return value from sendrecv so that ARP timeout does not cause

garbage to be entered into the ARP table.  Also fix ARP_DEBUG code.
This commit is contained in:
gwr 1995-12-08 04:12:53 +00:00
parent 63e145ebd7
commit 63a836a44a

View File

@ -1,4 +1,4 @@
/* $NetBSD: arp.c,v 1.12 1995/09/27 23:14:57 pk Exp $ */ /* $NetBSD: arp.c,v 1.13 1995/12/08 04:12:53 gwr Exp $ */
/* /*
* Copyright (c) 1992 Regents of the University of California. * Copyright (c) 1992 Regents of the University of California.
@ -55,14 +55,14 @@
/* Cache stuff */ /* Cache stuff */
#define ARP_NUM 8 /* need at most 3 arp entries */ #define ARP_NUM 8 /* need at most 3 arp entries */
static struct arp_list { struct arp_list {
struct in_addr addr; struct in_addr addr;
u_char ea[6]; u_char ea[6];
} arp_list[ARP_NUM] = { } arp_list[ARP_NUM] = {
/* XXX - net order `INADDR_BROADCAST' must be a constant */ /* XXX - net order `INADDR_BROADCAST' must be a constant */
{ {0xffffffff}, BA } { {0xffffffff}, BA }
}; };
static int arp_num = 1; int arp_num = 1;
/* Local forwards */ /* Local forwards */
static ssize_t arpsend __P((struct iodesc *, void *, size_t)); static ssize_t arpsend __P((struct iodesc *, void *, size_t));
@ -78,36 +78,34 @@ arpwhohas(d, addr)
register struct ether_arp *ah; register struct ether_arp *ah;
register struct arp_list *al; register struct arp_list *al;
struct { struct {
u_char header[ETHER_SIZE]; struct ether_header eh;
struct { struct {
struct ether_arp arp; struct ether_arp arp;
u_char pad[18]; /* 60 - sizeof(arp) */ u_char pad[18]; /* 60 - sizeof(...) */
} data; } data;
} wbuf; } wbuf;
struct { struct {
u_char header[ETHER_SIZE]; struct ether_header eh;
struct { struct {
struct ether_arp arp; struct ether_arp arp;
u_char pad[24]; /* extra space */ u_char pad[24]; /* extra space */
} data; } data;
} rbuf; } rbuf;
#ifdef ARP_DEBUG
if (debug)
printf("arpwhohas: called for %s\n", inet_ntoa(addr));
#endif
/* Try for cached answer first */ /* Try for cached answer first */
for (i = 0, al = arp_list; i < arp_num; ++i, ++al) for (i = 0, al = arp_list; i < arp_num; ++i, ++al)
if (addr.s_addr == al->addr.s_addr) if (addr.s_addr == al->addr.s_addr)
return (al->ea); return (al->ea);
/* Don't overflow cache */ /* Don't overflow cache */
if (arp_num > ARP_NUM - 1) if (arp_num > ARP_NUM - 1) {
panic("arpwhohas: overflowed arp_list!"); arp_num = 1; /* recycle */
printf("arpwhohas: overflowed arp_list!\n");
}
#ifdef ARP_DEBUG #ifdef ARP_DEBUG
if (debug) if (debug)
printf("arpwhohas: not cached\n"); printf("arpwhohas: send request for %s\n", inet_ntoa(addr));
#endif #endif
bzero((char*)&wbuf.data, sizeof(wbuf.data)); bzero((char*)&wbuf.data, sizeof(wbuf.data));
@ -119,22 +117,30 @@ arpwhohas(d, addr)
ah->arp_op = htons(ARPOP_REQUEST); ah->arp_op = htons(ARPOP_REQUEST);
MACPY(d->myea, ah->arp_sha); MACPY(d->myea, ah->arp_sha);
bcopy(&d->myip, ah->arp_spa, sizeof(ah->arp_spa)); bcopy(&d->myip, ah->arp_spa, sizeof(ah->arp_spa));
/* Leave zeros in arp_tha */
bcopy(&addr, ah->arp_tpa, sizeof(ah->arp_tpa)); bcopy(&addr, ah->arp_tpa, sizeof(ah->arp_tpa));
/* Store ip address in cache */ /* Store ip address in cache (incomplete entry). */
al->addr = addr; al->addr = addr;
(void)sendrecv(d, i = sendrecv(d,
arpsend, &wbuf.data, sizeof(wbuf.data), arpsend, &wbuf.data, sizeof(wbuf.data),
arprecv, &rbuf.data, sizeof(rbuf.data)); arprecv, &rbuf.data, sizeof(rbuf.data));
if (i == -1) {
panic("arp: no response for %s\n",
inet_ntoa(addr));
}
/* Store ethernet address in cache */ /* Store ethernet address in cache */
ah = &rbuf.data.arp; ah = &rbuf.data.arp;
#ifdef ARP_DEBUG #ifdef ARP_DEBUG
if (debug) if (debug) {
printf("arp: response from %s\n",
ether_sprintf(rbuf.eh.ether_shost));
printf("arp: cacheing %s --> %s\n", printf("arp: cacheing %s --> %s\n",
intoa(ah->arp_spa), inet_ntoa(addr),
ether_sprintf(ah->arp_sha)); ether_sprintf(ah->arp_sha));
}
#endif #endif
MACPY(ah->arp_sha, al->ea); MACPY(ah->arp_sha, al->ea);
++arp_num; ++arp_num;
@ -205,7 +211,7 @@ arprecv(d, pkt, len, tleft)
{ {
#ifdef ARP_DEBUG #ifdef ARP_DEBUG
if (debug) if (debug)
printf("bad hrd/pro/hln/pln\n") printf("bad hrd/pro/hln/pln\n");
#endif #endif
return (-1); return (-1);
} }
@ -213,7 +219,7 @@ arprecv(d, pkt, len, tleft)
if (ah->arp_op == htons(ARPOP_REQUEST)) { if (ah->arp_op == htons(ARPOP_REQUEST)) {
#ifdef ARP_DEBUG #ifdef ARP_DEBUG
if (debug) if (debug)
printf("is request\n") printf("is request\n");
#endif #endif
arp_reply(d, ah); arp_reply(d, ah);
return (-1); return (-1);
@ -265,7 +271,7 @@ arp_reply(d, pkt)
{ {
#ifdef ARP_DEBUG #ifdef ARP_DEBUG
if (debug) if (debug)
printf("arp_reply: bad hrd/pro/hln/pln\n") printf("arp_reply: bad hrd/pro/hln/pln\n");
#endif #endif
return; return;
} }