total overhaul. still needs a lot of cleanup though...

This commit is contained in:
cgd 1993-10-16 07:57:36 +00:00
parent 7e8063835d
commit bf4b776381
13 changed files with 454 additions and 133 deletions

View File

@ -1,4 +1,4 @@
# $Id: Makefile,v 1.6 1993/10/15 13:52:26 cgd Exp $
# $Id: Makefile,v 1.7 1993/10/16 07:57:36 cgd Exp $
LIB= netboot
SRCS+= arp.c bootinfo.c bootp.c exec.c globals.c in_cksum.c \
@ -6,6 +6,11 @@ SRCS+= arp.c bootinfo.c bootp.c exec.c globals.c in_cksum.c \
SRCS+= boot_nfs.c boot_tftp.c
CFLAGS+= -DDEBUG
CFLAGS+= -DPARANOID -Wall
CFLAGS+= -I${.CURDIR}/../libc_sa
NOPROFILE=
NOPIC=

View File

@ -35,21 +35,22 @@
* SUCH DAMAGE.
*
* from @(#) Header: arp.c,v 1.5 93/07/15 05:52:26 leres Exp (LBL)
* $Id: arp.c,v 1.3 1993/10/14 04:53:35 glass Exp $
* $Id: arp.c,v 1.4 1993/10/16 07:57:38 cgd Exp $
*/
#include <sys/types.h>
#include <sys/socket.h>
#include <net/if.h>
#include <netinet/in.h>
#include <netinet/if_ether.h>
#include <netinet/in_systm.h>
#include <errno.h>
#include <string.h>
#include "salibc.h"
#include "netboot.h"
#include "bootbootp.h"
@ -89,8 +90,10 @@ arpwhohas(d, addr)
} ru;
} rbuf;
#ifdef DEBUG
if (debug)
printf("arpwhohas: called\n");
#endif
/* Try for cached answer first */
for (i = 0, al = arp_list; i < arp_num; ++i, ++al)
if (addr == al->addr)
@ -100,8 +103,10 @@ arpwhohas(d, addr)
if (arp_num > ARP_NUM - 1)
panic("arpwhohas: overflowed arp_list!");
#ifdef DEBUG
if (debug)
printf("arpwhohas: not cached\n");
#endif
ah = &wbuf.warp;
bzero(ah, sizeof(*ah));
@ -134,8 +139,10 @@ arpsend(d, pkt, len)
register void *pkt;
register int len;
{
#ifdef DEBUG
if (debug)
printf("arpsend: called\n");
#endif
return (sendether(d, pkt, len, bcea, ETHERTYPE_ARP));
}
@ -149,8 +156,10 @@ arprecv(d, pkt, len)
register struct ether_header *eh;
register struct ether_arp *ah;
#ifdef DEBUG
if (debug)
printf("arprecv: called\n");
#endif
if (len < sizeof(*eh) + sizeof(*ah)) {
errno = 0;
return (-1);

View File

@ -31,7 +31,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Header: /cvsroot/src/sys/lib/libnetboot/Attic/boot_nfs.c,v 1.4 1993/10/15 13:43:16 cgd Exp $
* $Header: /cvsroot/src/sys/lib/libnetboot/Attic/boot_nfs.c,v 1.5 1993/10/16 07:57:39 cgd Exp $
*/
/*
* Copyright (c) 1992 Regents of the University of California.
@ -69,7 +69,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#) $Header: /cvsroot/src/sys/lib/libnetboot/Attic/boot_nfs.c,v 1.4 1993/10/15 13:43:16 cgd Exp $ (LBL)
* @(#) $Header: /cvsroot/src/sys/lib/libnetboot/Attic/boot_nfs.c,v 1.5 1993/10/16 07:57:39 cgd Exp $ (LBL)
*/
#include <sys/param.h>
@ -84,6 +84,8 @@
#include <nfs/rpcv2.h>
#include <nfs/nfsv2.h>
#include "salibc.h"
#include "netboot.h"
#include "bootbootp.h"
#include "bootp.h"
@ -117,8 +119,10 @@ void nfs_setup(desc)
getnfsinfo(desc, &roottime, NULL, &ftype);
if (ftype != NFDIR)
panic("bad root ftype %d", ftype);
#ifdef DEBUG
if (debug)
printf("nfs_setup: got root fh\n");
#endif
desc->destip = swapip;
getnfsfh(desc, swappath, swapfh);
@ -129,15 +133,17 @@ void nfs_setup(desc)
if (ftype != NFREG)
panic("bad swap ftype %d\n", ftype);
swapblks = bytes / 512;
#ifdef DEBUG
if (debug)
printf("nfs_setup: got swap fh\n");
#endif
printf("swap: %d (%d blocks)\n", bytes, swapblks);
desc->destip = rootip;
desc->fh = rootfh;
}
unsigned int nfs_boot(kernel_override, machdep_hint)
unsigned int boot_nfs(kernel_override, machdep_hint)
char *kernel_override;
void *machdep_hint;
{
@ -164,7 +170,7 @@ unsigned int nfs_boot(kernel_override, machdep_hint)
panic("netboot: no interfaces left untried");
if (netif_probe(nif, machdep_hint)) {
printf("netboot: couldn't probe %s%d\n",
nif->netif_bname, nif->netif_unit);
nif->nif_driver->netif_bname, nif->nif_unit);
continue;
}
netif_attach(nif, &desc, machdep_hint);

View File

@ -27,11 +27,14 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: boot_tftp.c,v 1.1 1993/10/15 13:52:28 cgd Exp $
* $Id: boot_tftp.c,v 1.2 1993/10/16 07:57:40 cgd Exp $
*/
#include <sys/types.h>
#include <netinet/in_systm.h>
#include "salibc.h"
#include "netboot.h"
#include "netif.h"
@ -65,7 +68,7 @@ boot_tftp(kernel_override, machdep_hint)
if (netif_probe(nif, machdep_hint)) {
printf("netboot: couldn't probe %s%d\n",
nif->netif_bname, nif->netif_unit);
nif->nif_driver->netif_bname, nif->nif_unit);
continue;
}
netif_attach(nif, &desc, machdep_hint);
@ -73,7 +76,9 @@ boot_tftp(kernel_override, machdep_hint)
get_bootinfo(&desc);
/* loaded = tftp_load(&desc, kernel_override, &startaddr);*/
netif_detach(nif);
#ifdef notdef
if (loaded)
machdep_exec(startaddr);
call((u_long) startaddr);
#endif
}
}

View File

@ -35,17 +35,18 @@
* SUCH DAMAGE.
*
* from @(#) Header: bootp.c,v 1.4 93/09/11 03:13:51 leres Exp (LBL)
* $Id: bootp.c,v 1.2 1993/10/14 04:53:36 glass Exp $
* $Id: bootp.c,v 1.3 1993/10/16 07:57:40 cgd Exp $
*/
#include <sys/types.h>
#include <netinet/in.h>
#include <netinet/in_systm.h>
#include <errno.h>
#include <string.h>
#include "salibc.h"
#include "netboot.h"
#include "bootbootp.h"
#include "bootp.h"
@ -98,8 +99,10 @@ bootp(d)
#define rbootp xrbuf.xrbootp
} rbuf;
#ifdef DEBUG
if (debug)
printf("bootp: called\n");
#endif
bp = &wbuf.wbootp;
pkt = &rbuf.rbootp;
pkt -= HEADER_SIZE;
@ -116,8 +119,10 @@ bootp(d)
d->destip = INADDR_BROADCAST;
while ((have & need) != need) {
#ifdef DEBUG
if (debug)
printf("bootp: sendrecv\n");
#endif
(void)sendrecv(d, bootpsend, bp, sizeof(*bp),
bootprecv, pkt, RECV_SIZE);
}
@ -132,8 +137,10 @@ bootpsend(d, pkt, len)
{
register struct bootp *bp;
#ifdef DEBUG
if (debug)
printf("bootpsend: called\n");
#endif
bp = pkt;
bzero(bp->bp_file, sizeof(bp->bp_file));
if ((have & BOOT_ROOT) == 0)
@ -146,8 +153,10 @@ bootpsend(d, pkt, len)
nvend = (nvend + 1) % (sizeof(vend) / sizeof(vend[0]));
bp->bp_xid = d->xid;
bp->bp_secs = (u_long)(getsecs() - bot);
#ifdef DEBUG
if (debug)
printf("bootpsend: calling sendudp\n");
#endif
return (sendudp(d, pkt, len));
}
@ -161,8 +170,10 @@ bootprecv(d, pkt, len)
register struct bootp *bp;
u_long ul;
#ifdef DEBUG
if (debug)
printf("bootprecv: called\n");
#endif
bp = (struct bootp *)checkudp(d, pkt, &len);
if (bp == NULL || len < sizeof(*bp) || bp->bp_xid != d->xid) {
errno = 0;

View File

@ -28,7 +28,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Header: /cvsroot/src/sys/lib/libnetboot/Attic/exec.c,v 1.1 1993/10/13 05:41:30 cgd Exp $
* $Header: /cvsroot/src/sys/lib/libnetboot/Attic/exec.c,v 1.2 1993/10/16 07:57:41 cgd Exp $
*/
#include <sys/param.h>
@ -47,9 +47,10 @@
#include <a.out.h>
#include "salibc.h"
#include "netboot.h"
#include "netif.h"
#include "exec_var.h"
char *kern_names[] = {
"netbsd", "onetbsd", "netbsd.old",

View File

@ -0,0 +1,55 @@
/*
* Copyright (c) 1993 Adam Glass
* 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.
*
* $Id: iodesc.h,v 1.1 1993/10/16 07:57:42 cgd Exp $
*/
#ifndef __SYS_LIBNETBOOT_IODESC_H
#define __SYS_LIBNETBOOT_IODESC_H
struct iodesc {
n_long destip; /* destination ip address */
n_long myip; /* my ip address */
u_short destport; /* destination port */
u_short myport; /* destination port */
u_long xid; /* transaction identification */
u_char myea[6]; /* my ethernet address */
u_char *fh; /* pointer to file handle */
struct netif *io_netif;
};
#endif /* __SYS_LIBNETBOOT_IODESC_H */

View File

@ -52,6 +52,8 @@
#include <errno.h>
#include "salibc.h"
#include "netboot.h"
#include "netif.h"
@ -69,8 +71,10 @@ sendudp(d, buf, len)
register u_char *ea;
struct ip tip;
#ifdef DEBUG
if (debug)
printf("sendudp: called\n");
#endif
uh = ((struct udphdr *)buf) - 1;
ip = ((struct ip *)uh) - 1;
len += sizeof(*ip) + sizeof(*uh);
@ -125,8 +129,10 @@ sendether(d, buf, len, dea, etype)
{
register struct ether_header *eh;
#ifdef DEBUG
if (debug)
printf("sendether: called\n");
#endif
eh = ((struct ether_header *)buf) - 1;
len += ETHER_SIZE;
@ -150,8 +156,10 @@ checkudp(d, pkt, lenp)
register struct udpiphdr *ui;
struct ip tip;
#ifdef DEBUG
if (debug)
printf("checkudp: called\n");
#endif
eh = pkt;
ip = (struct ip *)(eh + 1);
uh = (struct udphdr *)(ip + 1);
@ -240,8 +248,10 @@ sendrecv(d, sproc, sbuf, ssize, rproc, rbuf, rsize)
register int cc;
register time_t t, tmo, tlast, tleft;
#ifdef DEBUG
if (debug)
printf("sendrecv: called\n");
#endif
tmo = MINTMO;
tlast = tleft = 0;
t = getsecs();
@ -281,9 +291,11 @@ int ethernet_get(desc, pkt, len, timeout)
time_t timeout;
{
int val;
val = desc->io_netif->netif_get(desc, pkt, len, timeout);
val = netif_get(desc, pkt, len, timeout);
#ifdef DEBUG
if (debug)
printf("ethernet_get: received %d\n", val);
#endif
return val;
}
int ethernet_put(desc, pkt, len)
@ -293,6 +305,7 @@ int ethernet_put(desc, pkt, len)
{
int count, val;
#ifdef DEBUG
if (debug) {
struct ether_header *eh;
@ -304,8 +317,7 @@ int ethernet_put(desc, pkt, len)
ether_sprintf(eh->ether_shost));
printf("ethernet_put: ether_type %x\n", eh->ether_type);
}
if (!desc->io_netif)
panic("ethernet_put: no netif_put support");
val = desc->io_netif->netif_put(desc, pkt, len);
#endif
val = netif_put(desc, pkt, len);
return val;
}

View File

@ -35,9 +35,12 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#) $Header: /cvsroot/src/sys/lib/libnetboot/Attic/netboot.h,v 1.1 1993/10/13 05:41:34 cgd Exp $ (LBL)
* $Id: netboot.h,v 1.2 1993/10/16 07:57:44 cgd Exp $
*/
#include "exec_var.h"
#include "iodesc.h"
#define BA { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }
/* Returns true if n_long's on the same net */
@ -56,17 +59,6 @@
#define ETHER_SIZE 14
#define HEADER_SIZE (ETHER_SIZE + 20 + 8)
struct iodesc {
n_long destip; /* destination ip address */
n_long myip; /* my ip address */
u_short destport; /* destination port */
u_short myport; /* destination port */
u_long xid; /* transaction identification */
u_char myea[6]; /* my ethernet address */
u_char *fh; /* pointer to file handle */
struct netif *io_netif;
};
extern u_char bcea[6];
extern char rootpath[FNAME_SIZE];
extern char swappath[FNAME_SIZE];
@ -78,10 +70,16 @@ extern n_long smask;
extern n_long nmask;
extern n_long mask;
extern time_t bot;
extern int debug;
#ifdef DEBUG
extern int debug; /* defined in the machdep sources */
#endif
/* ARP functions: */
u_char *arpwhohas __P((struct iodesc *, n_long));
/* ARP functions: */
void getnfsfh __P((struct iodesc *, char *, u_char *));
void getnfsinfo __P((struct iodesc *, time_t *, u_long *, u_long *));
int lookupfh __P((struct iodesc *, char *, u_char *, time_t *,
@ -90,13 +88,13 @@ int readdata __P((struct iodesc *, u_long, void *, u_long));
void readseg __P((struct iodesc *, u_long, u_long, u_long));
/* Ethernet functions: */
void ethernet_init __P((struct iodesc *));
int ethernet_put __P((struct iodesc *, void *, int));
int ethernet_poll __P((struct iodesc *, void *, int));
int ethernet_get __P((struct iodesc *, void *, int, time_t));
void ethernet_macaddr __P((struct iodesc *, int, u_char *));
time_t getsecs __P((void));
u_long gettenths __P((void));
int sendether __P((struct iodesc *, void *, int, u_char *, int));
int sendudp __P((struct iodesc *, void *, int));
@ -105,7 +103,27 @@ int sendrecv __P((struct iodesc *, int (*)(struct iodesc *, void *, int),
void *, int, int (*)(struct iodesc *, void *, int), void *, int));
void *checkudp __P((struct iodesc *, void *, int *));
void panic __P((const char *, ...));
/* utilties: */
void panic __P((const char *, ...));
char *ether_sprintf __P((u_char *));
int in_cksum __P((void *, int));
void call __P((u_long));
char *intoa __P((n_long)); /* similar to inet_ntoa */
void call __P((u_long)); /* ??? */
/* Machine-dependent functions: */
time_t getsecs __P((void));
u_long gettenths __P((void));
void delay __P((u_long));
int putchar __P((int));
#ifdef notyet /* XXX */
int getchar __P((void));
/* something to check for a char... */
#endif
void machdep_common_ether __P((unsigned char *));
void machdep_exec_setup __P((struct exec_var *));
int machdep_exec_override __P((int, int)); /* ??? */
int machdep_exec __P((int, int)); /* ??? */
void machdep_stop __P((void));

View File

@ -28,7 +28,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Header: /cvsroot/src/sys/lib/libnetboot/Attic/netif.c,v 1.1 1993/10/13 05:41:35 cgd Exp $
* $Id: netif.c,v 1.2 1993/10/16 07:57:45 cgd Exp $
*/
#include <sys/param.h>
@ -40,87 +40,235 @@
#include <netinet/in.h>
#include <netinet/in_systm.h>
#include "salibc.h"
#include "netboot.h"
#include "netif.h"
static int netif_newp = 0; /* an optimization to skip over exhausted netifs */
/*
* netif_init:
*
* initialize the generic network interface layer
*/
void netif_init()
void
netif_init()
{
int i;
struct netif_driver *drv;
int d, i;
if (debug)
printf("netif_init: called\n");
for (i =0; i < n_netif; i++) {
netiftab[i]->netif_unit;
netiftab[i]->netif_exhausted = 0;
}
}
int netif_match(nif, machdep_hint, unitp)
struct netif *nif;
void *machdep_hint;
int *unitp;
{
if (debug)
printf("netif_match: called\n");
return nif->netif_match(machdep_hint, unitp);
}
struct netif *netif_select(machdep_hint)
void *machdep_hint;
{
int i;
struct netif *best_if = NULL;
int best_unit;
int best_val;
int val, unit;
best_val = 0;
if (debug)
printf("network interfaces: %d\n", n_netif);
for (i = netif_newp; i < n_netif; i++) {
val = netif_match(netiftab[i], machdep_hint, &unit);
if (val == 0) {
netiftab[i]->netif_exhausted = 1;
continue;
#ifdef DEBUG
if (netif_debug)
printf("netif_init: called\n");
#endif
for (d = 0; d < n_netif_drivers; d++) {
drv = netif_drivers[d];
for (i = 0; i < drv->netif_nifs; i++)
drv->netif_ifs[i].dif_used = 0;
}
if (debug)
printf("netif_select: %s%d = %d\n", netiftab[i]->netif_bname,
netiftab[i]->netif_unit, val);
if (val > best_val) {
best_if = netiftab[i];
best_unit = unit;
}
int
netif_match(nif, machdep_hint)
struct netif *nif;
void *machdep_hint;
{
struct netif_driver *drv = nif->nif_driver;
#ifdef DEBUG
#ifdef notdef
if (netif_debug)
printf("%s%d: netif_match (%d)\n", drv->netif_bname,
nif->nif_unit, nif->nif_sel);
#endif
#endif
return drv->netif_match(nif, machdep_hint);
}
struct netif *
netif_select(machdep_hint)
void *machdep_hint;
{
int d, u, unit_done, s;
struct netif_driver *drv;
struct netif cur_if;
static struct netif best_if;
int best_val;
int val;
best_val = 0;
best_if.nif_driver = NULL;
#ifdef DEBUG
if (netif_debug)
printf("netif_select: %d interfaces\n", n_netif_drivers);
#endif
for (d = 0; d < n_netif_drivers; d++) {
cur_if.nif_driver = netif_drivers[d];
drv = cur_if.nif_driver;
for (u = 0; u < drv->netif_nifs; u++) {
cur_if.nif_unit = u;
unit_done = 0;
#ifdef DEBUG
if (netif_debug)
printf("\t%s%d:", drv->netif_bname,
cur_if.nif_unit);
#endif
for (s = 0; s < drv->netif_ifs[u].dif_nsel; s++) {
cur_if.nif_sel = s;
if (drv->netif_ifs[u].dif_used & (1 << s)) {
#ifdef DEBUG
if (netif_debug)
printf(" [%d used]", s);
#endif
continue;
}
val = netif_match(&cur_if, machdep_hint);
#ifdef DEBUG
if (netif_debug)
printf(" [%d -> %d]", s, val);
#endif
if (val > best_val) {
best_val = val;
best_if = cur_if;
}
}
#ifdef DEBUG
if (netif_debug)
printf("\n");
#endif
}
}
}
if (!best_if) return NULL;
best_if->netif_unit = best_unit;
return best_if;
if (best_if.nif_driver == NULL)
return NULL;
best_if.nif_driver->
netif_ifs[best_if.nif_unit].dif_used |= (1 << best_if.nif_sel);
#ifdef DEBUG
if (netif_debug)
printf("netif_select: %s%d(%d) wins\n",
best_if.nif_driver->netif_bname,
best_if.nif_unit, best_if.nif_sel);
#endif
return &best_if;
}
int netif_probe(nif, machdep_hint)
struct netif *nif;
void *machdep_hint;
int
netif_probe(nif, machdep_hint)
struct netif *nif;
void *machdep_hint;
{
if (debug)
printf("netif_probe: called\n");
return nif->netif_probe(machdep_hint);
struct netif_driver *drv = nif->nif_driver;
#ifdef DEBUG
if (netif_debug)
printf("%s%d: netif_probe\n", drv->netif_bname, nif->nif_unit);
#endif
return drv->netif_probe(nif, machdep_hint);
}
void netif_attach(nif, desc, machdep_hint)
struct netif *nif;
struct iodesc *desc;
void *machdep_hint;
void
netif_attach(nif, desc, machdep_hint)
struct netif *nif;
struct iodesc *desc;
void *machdep_hint;
{
if (debug)
printf("netif_attach: called\n");
nif->netif_init(desc, machdep_hint);
desc->io_netif = nif;
bzero(desc->io_netif->netif_stats, *desc->io_netif->netif_stats);
struct netif_driver *drv = nif->nif_driver;
#ifdef DEBUG
if (netif_debug)
printf("%s%d: netif_attach\n", drv->netif_bname, nif->nif_unit);
#endif
desc->io_netif = nif;
#ifdef PARANOID
if (drv->netif_init == NULL)
panic("%s%d: no netif_init support\n", drv->netif_bname,
nif->nif_unit);
#endif
drv->netif_init(desc, machdep_hint);
bzero(drv->netif_ifs[nif->nif_unit].dif_stats,
sizeof(struct netif_stats));
}
void netif_detach(nif)
struct netif *nif;
void
netif_detach(nif)
struct netif *nif;
{
if (debug)
printf("netif_detach: called\n");
nif->netif_end();
struct netif_driver *drv = nif->nif_driver;
#ifdef DEBUG
if (netif_debug)
printf("%s%d: netif_detach\n", drv->netif_bname, nif->nif_unit);
#endif
#ifdef PARANOID
if (drv->netif_end == NULL)
panic("%s%d: no netif_end support\n", drv->netif_bname,
nif->nif_unit);
#endif
drv->netif_end(nif);
}
int
netif_get(desc, pkt, len, timo)
struct iodesc *desc;
void *pkt;
int len;
time_t timo;
{
struct netif *nif = desc->io_netif;
struct netif_driver *drv = desc->io_netif->nif_driver;
int rv;
#ifdef DEBUG
if (netif_debug)
printf("%s%d: netif_get\n", drv->netif_bname, nif->nif_unit);
#endif
#ifdef PARANOID
if (drv->netif_get == NULL)
panic("%s%d: no netif_get support\n", drv->netif_bname,
nif->nif_unit);
#endif
rv = drv->netif_get(desc, pkt, len, timo);
#ifdef DEBUG
if (netif_debug)
printf("%s%d: netif_get returning %d\n", drv->netif_bname,
nif->nif_unit, rv);
#endif
return rv;
}
int
netif_put(desc, pkt, len)
struct iodesc *desc;
void *pkt;
int len;
{
struct netif *nif = desc->io_netif;
struct netif_driver *drv = desc->io_netif->nif_driver;
int rv;
#ifdef DEBUG
if (netif_debug)
printf("%s%d: netif_put\n", drv->netif_bname, nif->nif_unit);
#endif
#ifdef PARANOID
if (drv->netif_put == NULL)
panic("%s%d: no netif_put support\n", drv->netif_bname,
nif->nif_unit);
#endif
rv = drv->netif_put(desc, pkt, len);
#ifdef DEBUG
if (netif_debug)
printf("%s%d: netif_put returning %d\n", drv->netif_bname,
nif->nif_unit, rv);
#endif
return rv;
}

View File

@ -1,32 +1,59 @@
struct netif {
char *netif_bname;
int netif_unit;
int netif_exhausted;
int (*netif_match) __P((void *, int *));
int (*netif_probe) __P((void *));
void (*netif_init) __P((struct iodesc *, void *));
int (*netif_get) __P((struct iodesc *, void *, int, time_t));
int (*netif_put) __P((struct iodesc *, void *, int));
void (*netif_end) __P((void));
struct netif_stats *netif_stats;
#ifndef __SYS_LIBNETBOOT_NETIF_H
#define __SYS_LIBNETBOOT_NETIF_H
#include "iodesc.h"
#define NENTS(x) sizeof(x)/sizeof(x[0])
struct netif_driver {
char *netif_bname;
int (*netif_match) __P((struct netif *, void *));
int (*netif_probe) __P((struct netif *, void *));
void (*netif_init) __P((struct iodesc *, void *));
int (*netif_get) __P((struct iodesc *, void *, int, time_t));
int (*netif_put) __P((struct iodesc *, void *, int));
void (*netif_end) __P((struct netif *));
struct netif_dif *netif_ifs;
int netif_nifs;
};
struct netif_dif {
int dif_unit;
int dif_nsel;
struct netif_stats *dif_stats;
void *dif_private;
/* the following fields are used internally by the netif layer */
u_long dif_used;
};
struct netif_stats {
int collisions;
int collision_error;
int missed;
int sent;
int received;
int deferred;
int overflow;
int collisions;
int collision_error;
int missed;
int sent;
int received;
int deferred;
int overflow;
};
extern struct netif *netiftab[];
extern int n_netif;
struct netif {
struct netif_driver *nif_driver;
int nif_unit;
int nif_sel;
};
void netif_init __P((void));
struct netif *netif_select __P((void *));
int netif_probe __P((struct netif *, void *));
void netif_attach __P((struct netif *, struct iodesc *, void *));
void netif_detach __P((struct netif *));
extern struct netif_driver *netif_drivers[]; /* machdep */
extern int n_netif_drivers;
#ifdef DEBUG
extern int netif_debug;
#endif
void netif_init __P((void));
struct netif *netif_select __P((void *));
int netif_probe __P((struct netif *, void *));
void netif_attach __P((struct netif *, struct iodesc *, void *));
void netif_detach __P((struct netif *));
int netif_get __P((struct iodesc *, void *, int, time_t));
int netif_put __P((struct iodesc *, void *, int));
#endif /* __SYS_LIBNETBOOT_NETIF_H */

View File

@ -35,7 +35,7 @@
* SUCH DAMAGE.
*
* from @(#) Header: rpc.c,v 1.12 93/09/28 08:31:56 leres Exp (LBL)
* $Id: rpc.c,v 1.2 1993/10/14 04:53:39 glass Exp $
* $Id: rpc.c,v 1.3 1993/10/16 07:57:47 cgd Exp $
*/
#include <sys/param.h>
@ -49,6 +49,8 @@
#undef NFSX_FATTR
#include <errno.h>
#include "salibc.h"
#include "netboot.h"
#include "netif.h"
#include "bootbootp.h"
@ -157,8 +159,10 @@ callrpc(d, prog, vers, proc, sdata, slen, rdata, rlen)
} ru;
} rbuf;
#ifdef DEBUG
if (debug)
printf("callrpc: called\n");
#endif
if (rlen > sizeof(rbuf.ru.data))
panic("callrpc: huge read (%d > %d)",
rlen, sizeof(rbuf.ru.data));
@ -203,8 +207,10 @@ recvrpc(d, pkt, len)
{
register struct rpc_reply *rpc;
#ifdef DEBUG
if (debug)
printf("recvrpc: called\n");
#endif
rpc = (struct rpc_reply *)checkudp(d, pkt, &len);
if (rpc == NULL || len < sizeof(*rpc)) {
errno = 0;
@ -244,8 +250,10 @@ getport(d, prog, vers)
u_long port; /* call port (unused) */
} sdata;
#ifdef DEBUG
if (debug)
printf("getport: called\n");
#endif
/* Try for cached answer first */
for (i = 0, pl = pmap_list; i < pmap_num; ++i, ++pl)
if ((pl->addr == d->destip || pl->addr == 0) &&
@ -292,8 +300,10 @@ getnfsfh(d, path, fhp)
u_char fh[NFS_FHSIZE];
} rdata;
#ifdef DEBUG
if (debug)
printf("getnfsfh: called\n");
#endif
bzero(&sdata, sizeof(sdata));
len = strlen(path);
if (len > sizeof(sdata.path))
@ -323,8 +333,10 @@ getnfsinfo(d, tp, sp, fp)
struct nfsv2_fattr fa;
} rdata;
#ifdef DEBUG
if (debug)
printf("getnfsinfo: called\n");
#endif
rlen = sizeof(rdata);
#if 0
#ifdef NFSX_FATTR
@ -371,8 +383,10 @@ lookupfh(d, name, fhp, tp, sp, fp)
struct nfsv2_fattr fa;
} rdata;
#ifdef DEBUG
if (debug)
printf("lookupfh: called\n");
#endif
bzero(&sdata, sizeof(sdata));
bcopy(d->fh, sdata.fh, sizeof(sdata.fh));
@ -434,8 +448,10 @@ sendreaddata(d, pkt, len)
register struct nfs_call_data *nfs;
register struct nfsstate *ns;
#ifdef DEBUG
if (debug)
printf("sendreaddata: called\n");
#endif
if (len != sizeof(*rpc) + sizeof(*nfs))
panic("sendreaddata: bad buffer (%d != %d)",
@ -471,8 +487,10 @@ recvreaddata(d, pkt, len)
register struct nfs_reply_data *nfs;
register struct nfsstate *ns;
#ifdef DEBUG
if (debug)
printf("recvreaddata: called\n");
#endif
rpc = (struct rpc_reply *)checkudp(d, pkt, &len);
if (rpc == NULL || len < sizeof(*rpc)) {
errno = 0;
@ -568,8 +586,10 @@ readdata(d, off, addr, len)
struct nfs_reply_data nfs;
} rdata;
#ifdef DEBUG
if (debug)
printf("readdata: called\n");
#endif
if (len == 0)
return (0);
d->destport = getport(d, NFS_PROG, NFS_VER2);

View File

@ -5,7 +5,11 @@
#include <netinet/in.h>
#include <netinet/in_systm.h>
#include "../include/stdarg.h"
#include <stdarg.h>
#include "salibc.h"
#include "netboot.h"
void
#ifdef __STDC__
@ -33,7 +37,7 @@ intoa(addr)
register char *cp;
register u_int byte;
register int n;
static char buf[sizeof(".xxx.xxx.xxx.xxx")];
static char buf[17]; /* strlen(".255.255.255.255") + 1 */
cp = &buf[sizeof buf];
*--cp = '\0';
@ -53,7 +57,7 @@ intoa(addr)
addr >>= 8;
} while (--n > 0);
return (cp + 1);
return (cp+1);
}
/*