diff options
| author | mycroft <mycroft@NetBSD.org> | 1995-02-20 11:04:00 +0000 |
|---|---|---|
| committer | mycroft <mycroft@NetBSD.org> | 1995-02-20 11:04:00 +0000 |
| commit | 258efc53df6fdb025eb2d3be09beaf77a3f556a6 (patch) | |
| tree | c15353fdb7a950c811f4e6f57ae114ff5de55886 /sys/lib | |
| parent | 41af5cf1314704e144184477f0d0f80b16770df6 (diff) | |
Various:
* Fix some misused types.
* Encapsulate the protocols better.
* Rearrange the RPC stuff to work more like the kernel. (Needs more work.)
* Remove a bunch of extra hair when reading a file over NFS.
* Use RPCAUTH_UNIX when talking to the NFS server.
Diffstat (limited to 'sys/lib')
| -rw-r--r-- | sys/lib/libsa/arp.c | 74 | ||||
| -rw-r--r-- | sys/lib/libsa/bootp.c | 88 | ||||
| -rw-r--r-- | sys/lib/libsa/ether.c | 48 | ||||
| -rw-r--r-- | sys/lib/libsa/net.c | 155 | ||||
| -rw-r--r-- | sys/lib/libsa/net.h | 15 | ||||
| -rw-r--r-- | sys/lib/libsa/nfs.c | 377 | ||||
| -rw-r--r-- | sys/lib/libsa/rarp.c | 82 | ||||
| -rw-r--r-- | sys/lib/libsa/rpc.c | 120 | ||||
| -rw-r--r-- | sys/lib/libsa/rpc.h | 31 |
9 files changed, 410 insertions, 580 deletions
diff --git a/sys/lib/libsa/arp.c b/sys/lib/libsa/arp.c index 474215a6709..7d1db887761 100644 --- a/sys/lib/libsa/arp.c +++ b/sys/lib/libsa/arp.c @@ -1,4 +1,4 @@ -/* $NetBSD: arp.c,v 1.3 1994/10/26 05:44:36 cgd Exp $ */ +/* $NetBSD: arp.c,v 1.4 1995/02/20 11:04:00 mycroft Exp $ */ /* * Copyright (c) 1992 Regents of the University of California. @@ -64,8 +64,8 @@ static struct arp_list { static int arp_num = 1; /* Local forwards */ -static int arpsend __P((struct iodesc *, void *, int)); -static int arprecv __P((struct iodesc *, void *, int)); +static size_t arpsend __P((struct iodesc *, void *, size_t)); +static size_t arprecv __P((struct iodesc *, void *, size_t, time_t)); /* Broadcast an ARP packet, asking who has addr on interface d */ u_char * @@ -80,12 +80,9 @@ arpwhohas(d, addr) u_char header[ETHER_SIZE]; struct ether_arp warp; } wbuf; - union { - u_char buffer[RECV_SIZE]; - struct { - u_char header[ETHER_SIZE]; - struct ether_arp rarp; - } ru; + struct { + u_char header[ETHER_SIZE]; + struct ether_arp rarp; } rbuf; #ifdef ARP_DEBUG @@ -103,8 +100,9 @@ arpwhohas(d, addr) #ifdef ARP_DEBUG if (debug) - printf("arpwhohas: not cached\n"); + printf("arpwhohas: not cached\n"); #endif + ah = &wbuf.warp; bzero(ah, sizeof(*ah)); @@ -120,55 +118,58 @@ arpwhohas(d, addr) /* Store ip address in cache */ al->addr = addr; - (void)sendrecv(d, arpsend, ah, sizeof(*ah), arprecv, - ((u_char *)&rbuf.ru.rarp) - ETHER_SIZE, - ETHER_SIZE + sizeof(rbuf.ru.rarp)); + (void)sendrecv(d, + arpsend, ah, sizeof(*ah), + arprecv, &rbuf.rarp, sizeof(rbuf.rarp)); /* Store ethernet address in cache */ - MACPY(rbuf.ru.rarp.arp_sha, al->ea); + MACPY(rbuf.rarp.arp_sha, al->ea); ++arp_num; + #ifdef ARP_DEBUG if (debug) - printf("arpwhohas: cacheing %s --> %s\n", intoa(addr), ether_sprintf(al->ea)); + printf("arpwhohas: cacheing %s --> %s\n", intoa(addr), ether_sprintf(al->ea)); #endif return (al->ea); } -static int +static size_t arpsend(d, pkt, len) register struct iodesc *d; register void *pkt; - register int len; + register size_t len; { + #ifdef ARP_DEBUG if (debug) - printf("arpsend: called\n"); + printf("arpsend: called\n"); #endif + return (sendether(d, pkt, len, bcea, ETHERTYPE_ARP)); } /* Returns 0 if this is the packet we're waiting for else -1 (and errno == 0) */ -static int -arprecv(d, pkt, len) +static size_t +arprecv(d, pkt, len, tleft) register struct iodesc *d; register void *pkt; - register int len; + register size_t len; + time_t tleft; { register struct ether_header *eh; register struct ether_arp *ah; #ifdef ARP_DEBUG if (debug) - printf("arprecv: called\n"); + printf("arprecv: called\n"); #endif - if (len < sizeof(*eh) + sizeof(*ah)) { - errno = 0; - return (-1); - } - eh = (struct ether_header *)pkt; + len = readether(d, pkt, len, tleft); + if (len == -1 || len < sizeof(struct ether_arp)) + goto bad; + eh = (struct ether_header *)pkt - 1; /* Must be to us */ if (bcmp(d->myea, eh->ether_dhost, 6) != 0 && bcmp(bcea, eh->ether_dhost, 6) != 0) { @@ -176,20 +177,17 @@ arprecv(d, pkt, len) if (debug) printf("arprecv: not ours %s\n", ether_sprintf(eh->ether_dhost)); #endif - errno = 0; - return (-1); + goto bad; } - if (ntohs(eh->ether_type) != ETHERTYPE_ARP) { #ifdef ARP_DEBUG if (debug) printf("arprecv: not arp %d\n", ntohs(eh->ether_type)); #endif - errno = 0; - return (-1); + goto bad; } - ah = (struct ether_arp *)(eh + 1); + ah = (struct ether_arp *)pkt; HTONS(ah->arp_hrd); HTONS(ah->arp_pro); HTONS(ah->arp_op); @@ -200,8 +198,7 @@ arprecv(d, pkt, len) if (debug) printf("arprecv: not valid reply\n"); #endif - errno = 0; - return (-1); + goto bad; } if (bcmp(&arp_list[arp_num].addr, ah->arp_spa, sizeof(long)) != 0 || bcmp(&d->myip, ah->arp_tpa, sizeof(d->myip)) != 0) { @@ -209,9 +206,12 @@ arprecv(d, pkt, len) if (debug) printf("arprecv: already cached??\n"); #endif - errno = 0; - return (-1); + goto bad; } return (0); + +bad: + errno = 0; + return (-1); } diff --git a/sys/lib/libsa/bootp.c b/sys/lib/libsa/bootp.c index 88ece8497fa..eb02c1142ce 100644 --- a/sys/lib/libsa/bootp.c +++ b/sys/lib/libsa/bootp.c @@ -1,4 +1,4 @@ -/* $NetBSD: bootp.c,v 1.2 1994/10/26 05:44:38 cgd Exp $ */ +/* $NetBSD: bootp.c,v 1.3 1995/02/20 11:04:04 mycroft Exp $ */ /* * Copyright (c) 1992 Regents of the University of California. @@ -58,8 +58,8 @@ static char vm_rfc1048[4] = VM_RFC1048; static char vm_cmu[4] = VM_CMU; /* Local forwards */ -static int bootpsend __P((struct iodesc *, void *, int)); -static int bootprecv __P((struct iodesc*, void *, int)); +static size_t bootpsend __P((struct iodesc *, void *, size_t)); +static size_t bootprecv __P((struct iodesc *, void *, size_t, time_t)); static void vend_cmu __P((u_char *)); static void vend_rfc1048 __P((u_char *, u_int)); @@ -70,18 +70,13 @@ bootp(sock) { struct iodesc *d; register struct bootp *bp; - register void *pkt; struct { u_char header[HEADER_SIZE]; struct bootp wbootp; } wbuf; - union { - u_char buffer[RECV_SIZE]; - struct { - u_char header[HEADER_SIZE]; - struct bootp xrbootp; - }xrbuf; -#define rbootp xrbuf.xrbootp + struct { + u_char header[HEADER_SIZE]; + struct bootp rbootp; } rbuf; #ifdef BOOTP_DEBUG @@ -100,9 +95,6 @@ bootp(sock) printf("bootp: d=%x\n", (u_int)d); #endif bp = &wbuf.wbootp; - pkt = &rbuf.rbootp; - pkt -= HEADER_SIZE; - bzero(bp, sizeof(*bp)); bp->bp_op = BOOTREQUEST; @@ -117,16 +109,16 @@ bootp(sock) d->destport = IPPORT_BOOTPS; (void)sendrecv(d, - bootpsend, bp, sizeof(*bp), - bootprecv, pkt, RECV_SIZE); + bootpsend, bp, sizeof(*bp), + bootprecv, &rbuf.rbootp, sizeof(rbuf.rbootp)); } /* Transmit a bootp request */ -static int +static size_t bootpsend(d, pkt, len) register struct iodesc *d; register void *pkt; - register int len; + register size_t len; { register struct bootp *bp; @@ -134,63 +126,65 @@ bootpsend(d, pkt, len) if (debug) printf("bootpsend: d=%x called.\n", (u_int)d); #endif + bp = pkt; bzero(bp->bp_file, sizeof(bp->bp_file)); + bcopy(vm_rfc1048, bp->bp_vend, sizeof(long)); bp->bp_xid = d->xid; bp->bp_secs = (u_long)(getsecs() - bot); + #ifdef BOOTP_DEBUG if (debug) - printf("bootpsend: calling sendudp\n"); + printf("bootpsend: calling sendudp\n"); #endif + return (sendudp(d, pkt, len)); } /* Returns 0 if this is the packet we're waiting for else -1 (and errno == 0) */ -static int -bootprecv(d, pkt, len) +static size_t +bootprecv(d, pkt, len, tleft) register struct iodesc *d; register void *pkt; - int len; + register size_t len; + time_t tleft; { register struct bootp *bp; #ifdef BOOTP_DEBUG if (debug) - printf("bootprecv: called\n"); + printf("bootprecv: called\n"); #endif - bp = (struct bootp *)checkudp(d, pkt, &len); + + len = readudp(d, pkt, len, tleft); + if (len == -1 || len < sizeof(struct bootp)) + goto bad; + + bp = (struct bootp *)pkt; + NTOHL(bp->bp_xid); + #ifdef BOOTP_DEBUG if (debug) printf("bootprecv: checked. bp = 0x%x, len = %d\n", (unsigned)bp, len); #endif - if (bp == NULL || len < sizeof(*bp) || bp->bp_xid != d->xid) { + if (bp->bp_xid != d->xid) { #ifdef BOOTP_DEBUG if (debug) { - printf("bootprecv: not for us.\n"); - if (bp == NULL) - printf("bootprecv: bp null\n"); - else { - if (len < sizeof(*bp)) - printf("bootprecv: expected %d bytes, got %d\n", - sizeof(*bp), len); - if (bp->bp_xid != d->xid) - printf("bootprecv: expected xid 0x%x, got 0x%x\n", - d->xid, bp->bp_xid); - } + printf("bootprecv: expected xid 0x%x, got 0x%x\n", + d->xid, bp->bp_xid); } #endif - errno = 0; - return (-1); + goto bad; } - /* Bump xid so next request will be unique */ + /* Bump xid so next request will be unique. */ ++d->xid; #ifdef BOOTP_DEBUG if (debug) - printf("bootprecv: got one!\n"); + printf("bootprecv: got one!\n"); #endif /* Pick up our ip address (and natural netmask) */ @@ -210,13 +204,11 @@ bootprecv(d, pkt, len) printf("'native netmask' is %s\n", intoa(nmask)); #endif - /* Pick up root or swap server address and file spec */ - if (bp->bp_siaddr.s_addr != 0) { + /* Pick up root or swap server address and file spec. */ + if (bp->bp_siaddr.s_addr != 0) rootip = ntohl(bp->bp_siaddr.s_addr); - } if (bp->bp_file[0] != '\0') { - strncpy(bootfile, (char *)bp->bp_file, - sizeof(bootfile)); + strncpy(bootfile, (char *)bp->bp_file, sizeof(bootfile)); bootfile[sizeof(bootfile) - 1] = '\0'; } @@ -253,6 +245,7 @@ bootprecv(d, pkt, len) printf("need gateway for root ip\n"); #endif } + if (!SAMENET(d->myip, swapip, mask)) { #ifdef BOOTP_DEBUG if (debug) @@ -268,7 +261,12 @@ bootprecv(d, pkt, len) #endif gateip = 0; } + return (0); + +bad: + errno = 0; + return (-1); } static void diff --git a/sys/lib/libsa/ether.c b/sys/lib/libsa/ether.c index 6291d3652ab..57e363c15e3 100644 --- a/sys/lib/libsa/ether.c +++ b/sys/lib/libsa/ether.c @@ -1,4 +1,4 @@ -/* $NetBSD: ether.c,v 1.3 1995/02/19 17:04:46 mycroft Exp $ */ +/* $NetBSD: ether.c,v 1.4 1995/02/20 11:04:06 mycroft Exp $ */ /* * Copyright (c) 1992 Regents of the University of California. @@ -55,11 +55,11 @@ #include "netif.h" /* Caller must leave room for ethernet header in front!! */ -int -sendether(d, buf, len, dea, etype) +size_t +sendether(d, pkt, len, dea, etype) struct iodesc *d; - void *buf; - int len; + void *pkt; + size_t len; u_char *dea; int etype; { @@ -69,13 +69,45 @@ sendether(d, buf, len, dea, etype) if (debug) printf("sendether: called\n"); #endif - eh = ((struct ether_header *)buf) - 1; - len += ETHER_SIZE; + + eh = (struct ether_header *)pkt - 1; + len += sizeof(*eh); MACPY(d->myea, eh->ether_shost); /* by byte */ MACPY(dea, eh->ether_dhost); /* by byte */ eh->ether_type = htons(etype); - return (netif_put(d, eh, len) - ETHER_SIZE); + + len = netif_put(d, eh, len); + if (len == -1 || len < sizeof(*eh)) + return (-1); + + len -= sizeof(*eh); + return (len); +} + +size_t +readether(d, pkt, len, tleft) + register struct iodesc *d; + register void *pkt; + register size_t len; + time_t tleft; +{ + register struct ether_header *eh; + +#ifdef ETHER_DEBUG + if (debug) + printf("readether: called\n"); +#endif + + eh = (struct ether_header *)pkt - 1; + len += sizeof(*eh); + + len = netif_get(d, eh, len, tleft); + if (len == -1 || len < sizeof(*eh)) + return (-1); + + len -= sizeof(*eh); + return (len); } /* diff --git a/sys/lib/libsa/net.c b/sys/lib/libsa/net.c index a869aa82b81..e40e5a2052e 100644 --- a/sys/lib/libsa/net.c +++ b/sys/lib/libsa/net.c @@ -1,4 +1,4 @@ -/* $NetBSD: net.c,v 1.3 1994/10/26 05:44:52 cgd Exp $ */ +/* $NetBSD: net.c,v 1.4 1995/02/20 11:04:08 mycroft Exp $ */ /* * Copyright (c) 1992 Regents of the University of California. @@ -61,13 +61,13 @@ n_long myip; /* Caller must leave room for ethernet, ip and udp headers in front!! */ -int -sendudp(d, buf, len) +size_t +sendudp(d, pkt, len) register struct iodesc *d; - register void *buf; - register int len; + register void *pkt; + register size_t len; { - register int cc; + register size_t cc; register struct ip *ip; register struct udpiphdr *ui; register struct udphdr *uh; @@ -85,8 +85,9 @@ sendudp(d, buf, len) } } #endif - uh = ((struct udphdr *)buf) - 1; - ip = ((struct ip *)uh) - 1; + + uh = (struct udphdr *)pkt - 1; + ip = (struct ip *)uh - 1; len += sizeof(*ip) + sizeof(*uh); bzero(ip, sizeof(*ip) + sizeof(*uh)); @@ -121,21 +122,22 @@ sendudp(d, buf, len) ea = arpwhohas(d, htonl(gateip)); cc = sendether(d, ip, len, ea, ETHERTYPE_IP); - if (cc < 0) - return (cc); + if (cc == -1) + return (-1); if (cc != len) panic("sendudp: bad write (%d != %d)", cc, len); return (cc - (sizeof(*ip) + sizeof(*uh))); } /* Check that packet is a valid udp packet for us */ -void * -checkudp(d, pkt, lenp) +size_t +readudp(d, pkt, len, tleft) register struct iodesc *d; register void *pkt; - register int *lenp; + register size_t len; + time_t tleft; { - register int hlen, len; + register size_t hlen; register struct ether_header *eh; register struct ip *ip; register struct udphdr *uh; @@ -144,91 +146,93 @@ checkudp(d, pkt, lenp) #ifdef NET_DEBUG if (debug) - printf("checkudp: called\n"); + printf("readudp: called\n"); #endif - eh = pkt; - ip = (struct ip *)(eh + 1); - uh = (struct udphdr *)(ip + 1); + uh = (struct udphdr *)pkt - 1; + ip = (struct ip *)uh - 1; + + len = readether(d, ip, len + sizeof(*ip) + sizeof(*uh), tleft); + if (len == -1 || len < sizeof(*ip) + sizeof(*uh)) + goto bad; + + eh = (struct ether_header *)ip - 1; /* Must be to us */ - if (bcmp(d->myea, eh->ether_dhost, 6) != 0 && /* by byte */ - bcmp(bcea, eh->ether_dhost, 6) != 0) { /* by byte */ + if (bcmp(d->myea, eh->ether_dhost, 6) != 0 && + bcmp(bcea, eh->ether_dhost, 6) != 0) { #ifdef NET_DEBUG if (debug) - printf("checkudp: not ours. myea=%s bcea=%s\n", + printf("readudp: not ours. myea=%s bcea=%s\n", ether_sprintf(d->myea), ether_sprintf(bcea)); #endif - return (NULL); - } - - /* And ip */ + goto bad; + } if (ntohs(eh->ether_type) != ETHERTYPE_IP) { #ifdef NET_DEBUG if (debug) - printf("checkudp: not IP. ether_type=%x\n", eh->ether_type); + printf("readudp: not IP. ether_type=%x\n", eh->ether_type); #endif - return (NULL); + goto bad; } /* Check ip header */ - if (ip->ip_v != IPVERSION || ip->ip_p != IPPROTO_UDP) { /* half char */ + if (ip->ip_v != IPVERSION || + ip->ip_p != IPPROTO_UDP) { /* half char */ #ifdef NET_DEBUG if (debug) - printf("checkudp: IP version or not UDP. ip_v=%d ip_p=%d\n", ip->ip_v, ip->ip_p); + printf("readudp: IP version or not UDP. ip_v=%d ip_p=%d\n", ip->ip_v, ip->ip_p); #endif - return (NULL); + goto bad; } hlen = ip->ip_hl << 2; - if (hlen < sizeof(*ip) || in_cksum(ip, hlen) != 0) { + if (hlen < sizeof(*ip) || + in_cksum(ip, hlen) != 0) { #ifdef NET_DEBUG if (debug) - printf("checkudp: short hdr or bad cksum.\n"); + printf("readudp: short hdr or bad cksum.\n"); #endif - return (NULL); + goto bad; } NTOHS(ip->ip_len); - if (*lenp - sizeof(*eh) < ip->ip_len) { + if (len < ip->ip_len) { #ifdef NET_DEBUG if (debug) - printf("checkudp: bad length %d < %d.\n", - *lenp - sizeof(*eh), ip->ip_len); + printf("readudp: bad length %d < %d.\n", + len, ip->ip_len); #endif - return (NULL); + goto bad; } if (d->myip && ntohl(ip->ip_dst.s_addr) != d->myip) { #ifdef NET_DEBUG if (debug) { - printf("checkudp: bad saddr %s != ", - intoa(d->myip)); - printf("%s\n", - intoa(ntohl(ip->ip_dst.s_addr))); + printf("readudp: bad saddr %s != ", intoa(d->myip)); + printf("%s\n", intoa(ntohl(ip->ip_dst.s_addr))); } #endif - return (NULL); + goto bad; } /* If there were ip options, make them go away */ if (hlen != sizeof(*ip)) { - bcopy(((u_char *)ip) + hlen, uh, - *lenp - (sizeof(*eh) + hlen)); + bcopy(((u_char *)ip) + hlen, uh, len - hlen); ip->ip_len = sizeof(*ip); - *lenp -= hlen - sizeof(*ip); + len -= hlen - sizeof(*ip); } if (ntohs(uh->uh_dport) != d->myport) { #ifdef NET_DEBUG if (debug) - printf("checkudp: bad dport %d != %d\n", + printf("readudp: bad dport %d != %d\n", d->myport, ntohs(uh->uh_dport)); #endif - return (NULL); + goto bad; } if (uh->uh_sum) { - len = ntohs(uh->uh_ulen); - if (len > RECV_SIZE - (sizeof(*eh) + sizeof(*ip))) { - printf("checkudp: huge packet, udp len %d\n", len); - return (NULL); + len = ntohs(uh->uh_ulen) + sizeof(*ip); + if (len > RECV_SIZE - sizeof(*eh)) { + printf("readudp: huge packet, udp len %d\n", len); + goto bad; } /* Check checksum (must save and restore ip header) */ @@ -238,13 +242,13 @@ checkudp(d, pkt, lenp) ui->ui_prev = 0; ui->ui_x1 = 0; ui->ui_len = uh->uh_ulen; - if (in_cksum(ui, len + sizeof(*ip)) != 0) { + if (in_cksum(ui, len) != 0) { #ifdef NET_DEBUG if (debug) - printf("checkudp: bad cksum\n"); + printf("readudp: bad cksum\n"); #endif *ip = tip; - return (NULL); + goto bad; } *ip = tip; } @@ -254,13 +258,17 @@ checkudp(d, pkt, lenp) if (uh->uh_ulen < sizeof(*uh)) { #ifdef NET_DEBUG if (debug) - printf("checkudp: bad udp len %d < %d\n", + printf("readudp: bad udp len %d < %d\n", uh->uh_ulen, sizeof(*uh)); #endif - return (NULL); + goto bad; } - *lenp -= sizeof(*eh) + sizeof(*ip) + sizeof(*uh); - return (uh + 1); + + len -= sizeof(*ip) + sizeof(*uh); + return (len); + +bad: + return (-1); } /* @@ -273,30 +281,31 @@ checkudp(d, pkt, lenp) * non-zero errno to indicate failure; finally, it can return -1 with a * zero errno to indicate it isn't done yet. */ -int +size_t sendrecv(d, sproc, sbuf, ssize, rproc, rbuf, rsize) register struct iodesc *d; - register int (*sproc)(struct iodesc *, void *, int); + register size_t (*sproc)(struct iodesc *, void *, size_t); register void *sbuf; - register int ssize; - register int (*rproc)(struct iodesc *, void *, int); + register size_t ssize; + register size_t (*rproc)(struct iodesc *, void *, size_t, time_t); register void *rbuf; - register int rsize; + register size_t rsize; { - register int cc; + register size_t cc; register time_t t, tmo, tlast, tleft; #ifdef NET_DEBUG if (debug) - printf("sendrecv: called\n"); + printf("sendrecv: called\n"); #endif + tmo = MINTMO; tlast = tleft = 0; t = getsecs(); for (;;) { if (tleft <= 0) { cc = (*sproc)(d, sbuf, ssize); - if (cc < ssize) + if (cc == -1 || cc < ssize) panic("sendrecv: short write! (%d < %d)", cc, ssize); @@ -307,14 +316,12 @@ sendrecv(d, sproc, sbuf, ssize, rproc, rbuf, rsize) tlast = t; } - cc = netif_get(d, rbuf, rsize, tleft); - if (cc >= 0) { - /* Got a packet, process it */ - cc = (*rproc)(d, rbuf, cc); - /* Return on data, EOF or real error */ - if (cc >= 0 || errno != 0) - return (cc); - } + /* Try to get a packet and process it. */ + cc = (*rproc)(d, rbuf, rsize, tleft); + /* Return on data, EOF or real error. */ + if (cc != -1 || errno != 0) + return (cc); + /* Timed out or didn't get the packet we're waiting for */ t = getsecs(); tleft -= t - tlast; diff --git a/sys/lib/libsa/net.h b/sys/lib/libsa/net.h index ee354d7e43b..b694f0c8098 100644 --- a/sys/lib/libsa/net.h +++ b/sys/lib/libsa/net.h @@ -1,4 +1,4 @@ -/* $NetBSD: net.h,v 1.2 1994/10/26 05:44:52 cgd Exp $ */ +/* $NetBSD: net.h,v 1.3 1995/02/20 11:04:10 mycroft Exp $ */ /* * Copyright (c) 1993 Adam Glass @@ -80,12 +80,13 @@ extern struct iodesc sockets[SOPEN_MAX]; u_char *arpwhohas __P((struct iodesc *, n_long)); -int sendether __P((struct iodesc *, void *, int, u_char *, int)); -int sendudp __P((struct iodesc *, void *, int)); -int recvudp __P((struct iodesc *, void *, int, time_t)); -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 *)); +size_t sendether __P((struct iodesc *, void *, size_t, u_char *, int)); +size_t readether __P((struct iodesc *, void *, size_t, time_t)); +size_t sendudp __P((struct iodesc *, void *, size_t)); +size_t readudp __P((struct iodesc *, void *, size_t, time_t)); +size_t sendrecv __P((struct iodesc *, size_t (*)(struct iodesc *, void *, size_t), + void *, size_t, size_t (*)(struct iodesc *, void *, size_t, time_t), + void *, size_t)); /* utilties: */ diff --git a/sys/lib/libsa/nfs.c b/sys/lib/libsa/nfs.c index 6fbaef0f7ed..06df94a4619 100644 --- a/sys/lib/libsa/nfs.c +++ b/sys/lib/libsa/nfs.c @@ -1,4 +1,4 @@ -/* $NetBSD: nfs.c,v 1.5 1995/02/19 23:51:39 mycroft Exp $ */ +/* $NetBSD: nfs.c,v 1.6 1995/02/20 11:04:12 mycroft Exp $ */ /*- * Copyright (c) 1993 John Brezak @@ -39,6 +39,7 @@ #include <nfs/rpcv2.h> #include <nfs/nfsv2.h> +#include <nfs/xdr_subs.h> #include "stand.h" #include "net.h" @@ -62,19 +63,6 @@ struct nfs_reply_data { }; #define NFSREAD_SIZE sizeof(((struct nfs_reply_data *)0)->data) -/* max number of nfs reads pending */ -#define NFS_COUNT 10 - -static struct nfsstate { - u_long off; - u_long len; - int done; - void *addr; - u_long xid; -} nfsstate[NFS_COUNT]; - -static u_long nfscc; - struct nfs_iodesc { off_t off; size_t size; @@ -93,36 +81,37 @@ getmountfh(d, path, fhp) struct { u_long len; char path[FNAME_SIZE]; - } sdata; + } wbuf; struct { u_long errno; u_char fh[NFS_FHSIZE]; - } rdata; - int cc; + } rbuf; + size_t cc; #ifdef NFS_DEBUG if (debug) - printf("getmountfh: called\n"); + printf("getmountfh: called\n"); #endif - bzero(&sdata, sizeof(sdata)); + + bzero(&wbuf, sizeof(wbuf)); len = strlen(path); - if (len > sizeof(sdata.path)) - len = sizeof(sdata.path); - bcopy(path, sdata.path, len); - sdata.len = htonl(len); - len = sizeof(sdata) - sizeof(sdata.path) + roundup(len, sizeof(long)); + if (len > sizeof(wbuf.path)) + len = sizeof(wbuf.path); + bcopy(path, wbuf.path, len); + wbuf.len = htonl(len); + len = sizeof(wbuf) - sizeof(wbuf.path) + roundup(len, sizeof(long)); if ((cc = callrpc(d, RPCPROG_MNT, RPCMNT_VER1, RPCMNT_MOUNT, - &sdata, len, &rdata, sizeof(rdata))) < 0) - return(-1); - if (cc < sizeof(rdata.errno)) + &wbuf, len, &rbuf, sizeof(rbuf))) == -1) + return (-1); + if (cc < sizeof(rbuf.errno)) panic("getmountfh: callrpc small read"); - if (rdata.errno) { - errno = ntohl(rdata.errno); - return(-1); + if (rbuf.errno) { + errno = ntohl(rbuf.errno); + return (-1); } - bcopy(rdata.fh, fhp, sizeof(rdata.fh)); - return(0); + bcopy(rbuf.fh, fhp, sizeof(rbuf.fh)); + return (0); } /* Fetch file timestamp and size */ @@ -140,45 +129,43 @@ getnfsinfo(d, tp, sp, fp, mp, up, gp) struct { u_long errno; struct nfsv2_fattr fa; - } rdata; - int cc; + } rbuf; + size_t cc; #ifdef NFS_DEBUG if (debug) printf("getnfsinfo: called\n"); #endif - rlen = sizeof(rdata); -#ifdef NFSX_FATTR + rlen = sizeof(rbuf); #if NFSX_FATTR(1) > NFSX_FATTR(0) /* nqnfs makes this more painful than it needs to be */ rlen -= NFSX_FATTR(1) - NFSX_FATTR(0); #endif -#endif if ((cc = callrpc(d->iodesc, NFS_PROG, NFS_VER2, NFSPROC_GETATTR, - d->fh, NFS_FHSIZE, &rdata, rlen)) < 0) - return(-1); - if (cc < sizeof(rdata.errno)) + d->fh, NFS_FHSIZE, &rbuf, rlen)) == -1) + return (-1); + if (cc < sizeof(rbuf.errno)) panic("getnfsinfo: callrpc small read"); - if (rdata.errno) { - errno = ntohl(rdata.errno); - return(-1); + if (rbuf.errno) { + errno = ntohl(rbuf.errno); + return (-1); } if (tp) { - *tp = ntohl(rdata.fa.fa_nfsmtime.nfs_sec); - t = ntohl(rdata.fa.fa_nfsatime.nfs_sec); + *tp = ntohl(rbuf.fa.fa_nfsmtime.nfs_sec); + t = ntohl(rbuf.fa.fa_nfsatime.nfs_sec); if (*tp < t) *tp = t; } if (sp) - *sp = ntohl(rdata.fa.fa_nfssize); + *sp = ntohl(rbuf.fa.fa_nfssize); if (fp) - *fp = ntohl(rdata.fa.fa_type); + *fp = ntohl(rbuf.fa.fa_type); if (mp) - *mp = ntohl(rdata.fa.fa_mode); + *mp = ntohl(rbuf.fa.fa_mode); if (up) - *up = ntohl(rdata.fa.fa_uid); + *up = ntohl(rbuf.fa.fa_uid); if (gp) - *gp = ntohl(rdata.fa.fa_gid); + *gp = ntohl(rbuf.fa.fa_gid); return(0); } @@ -196,266 +183,82 @@ lookupfh(d, name, fhp, tp, sp, fp) u_char fh[NFS_FHSIZE]; u_long len; char name[FNAME_SIZE]; - } sdata; + } wbuf; struct { u_long errno; u_char fh[NFS_FHSIZE]; struct nfsv2_fattr fa; - } rdata; - int cc; + } rbuf; + size_t cc; #ifdef NFS_DEBUG if (debug) - printf("lookupfh: called\n"); + printf("lookupfh: called\n"); #endif - bzero(&sdata, sizeof(sdata)); - bcopy(d->fh, sdata.fh, sizeof(sdata.fh)); + bzero(&wbuf, sizeof(wbuf)); + bcopy(d->fh, wbuf.fh, sizeof(wbuf.fh)); len = strlen(name); - if (len > sizeof(sdata.name)) - len = sizeof(sdata.name); - bcopy(name, sdata.name, len); - sdata.len = htonl(len); - len = sizeof(sdata) - sizeof(sdata.name) + roundup(len, sizeof(long)); - - rlen = sizeof(rdata); -#if 0 + if (len > sizeof(wbuf.name)) + len = sizeof(wbuf.name); + bcopy(name, wbuf.name, len); + wbuf.len = htonl(len); + len = sizeof(wbuf) - sizeof(wbuf.name) + roundup(len, sizeof(long)); + + rlen = sizeof(rbuf); #ifdef NFSX_FATTR #if NFSX_FATTR(1) > NFSX_FATTR(0) /* nqnfs makes this more painful than it needs to be */ rlen -= NFSX_FATTR(1) - NFSX_FATTR(0); #endif #endif -#endif + if ((cc = callrpc(d->iodesc, NFS_PROG, NFS_VER2, NFSPROC_LOOKUP, - &sdata, len, &rdata, rlen)) < 0) + &wbuf, len, &rbuf, rlen)) == -1) return (-1); - if (cc < sizeof(rdata.errno)) + if (cc < sizeof(rbuf.errno)) panic("lookupfh: callrpc small read"); - if (rdata.errno) { - errno = ntohl(rdata.errno); - return(-1); + if (rbuf.errno) { + errno = ntohl(rbuf.errno); + return (-1); } - bcopy(rdata.fh, fhp, sizeof(rdata.fh)); + bcopy(rbuf.fh, fhp, sizeof(rbuf.fh)); if (tp) - *tp = ntohl(rdata.fa.fa_nfsctime.nfs_sec); + *tp = ntohl(rbuf.fa.fa_nfsctime.nfs_sec); if (sp) - *sp = ntohl(rdata.fa.fa_nfssize); + *sp = ntohl(rbuf.fa.fa_nfssize); if (fp) - *fp = ntohl(rdata.fa.fa_type); + *fp = ntohl(rbuf.fa.fa_type); return (0); } -static int -sendreaddata(d, pkt, len) - register struct nfs_iodesc *d; - register void *pkt; - register int len; -{ - register int i; - register u_long cc; - register struct rpc_call *rpc; - register struct nfs_call_data *nfs; - register struct nfsstate *ns; - -#ifdef NFS_DEBUG - if (debug) - printf("sendreaddata: called\n"); -#endif - - if (len != sizeof(*rpc) + sizeof(*nfs)) - panic("sendreaddata: bad buffer (%d != %d)", - len, sizeof(*rpc) + sizeof(*nfs)); - rpc = pkt; - nfs = (struct nfs_call_data *)(rpc + 1); - for (i = 0, ns = nfsstate; i < NFS_COUNT; ++i, ++ns) { - if (ns->done) - continue; - - rpc->rp_xid = ns->xid; - nfs->off = htonl(ns->off); - nfs->len = htonl(ns->len); - cc = sendudp(d->iodesc, rpc, len); - - if (cc != len) - panic("sendreaddata: short write (%d != %d)", cc, len); - } - /* XXX we may have actually sent a lot more bytes... */ - - return (len); -} - -/* Returns char count if done else -1 (and errno == 0) */ -static int -recvreaddata(d, pkt, len) - register struct nfs_iodesc *d; - register void *pkt; - int len; -{ - register int i; - register struct rpc_reply *rpc; - register struct nfs_reply_data *nfs; - register struct nfsstate *ns; - -#ifdef NFS_DEBUG - if (debug) - printf("recvreaddata: called\n"); -#endif - rpc = (struct rpc_reply *)checkudp(d->iodesc, pkt, &len); - if (rpc == NULL || len < sizeof(*rpc)) { - errno = 0; - return (-1); - } - len -= sizeof(*rpc); - - NTOHL(rpc->rp_direction); - NTOHL(rpc->rp_stat); - - if (rpc->rp_direction != REPLY || rpc->rp_stat != MSG_ACCEPTED) { - errno = 0; - return (-1); - } - - for (i = 0, ns = nfsstate; i < NFS_COUNT; ++i, ++ns) - if (rpc->rp_xid == ns->xid) - break; - if (i >= NFS_COUNT) { - errno = 0; - return (-1); - } - - if (ns->done) { - errno = 0; - return (-1); - } -#ifdef NFS_DEBUG - if (debug) - printf("recvreaddata: ns=%x\n", (u_int)ns); -#endif - nfs = (struct nfs_reply_data *)(rpc + 1); - if (len < sizeof(nfs->errno)) - panic("recvreaddata: bad read %d", len); - if (nfs->errno) { - errno = ntohl(nfs->errno); - return (-1); - } - if (len < sizeof(*nfs) - sizeof(nfs->data)) - panic("recvreaddata: less than nfs sized %d", len); - len -= sizeof(*nfs) - sizeof(nfs->data); - - if (len < nfs->count) - panic("recvreaddata: short read (%d < %d)", len, nfs->count); - len = nfs->count; - if (len > ns->len) - panic("recvreaddata: huge read (%d > %d)", len, ns->len); - - -#ifdef NFS_DEBUG - if (debug) - printf("recvreaddata: read %d bytes.\n", len); -#endif - bcopy(nfs->data, ns->addr, len); - ns->done = 1; - nfscc += len; - - if (len < ns->len) { - /* If first packet assume no more data to read */ - if (i == 0) - return (0); - - /* Short read, assume we are at EOF */ - ++i; - ++ns; - while (i < NFS_COUNT) { - ns->done = 1; - ++i; - ++ns; - } - } - - for (i = 0, ns = nfsstate; i < NFS_COUNT; ++i, ++ns) - if (!ns->done) { - errno = 0; - return (-1); - } - - /* Return data count (thus indicating success) */ - return (nfscc); -} - /* Read data from a file */ -static int +static size_t readdata(d, off, addr, len) register struct nfs_iodesc *d; register off_t off; register void *addr; - register u_long len; + register size_t len; { - register int i, cc; - register struct rpc_call *rpc; - register struct nfsstate *ns; - struct { - u_char header[HEADER_SIZE]; - struct rpc_call rpc; - struct nfs_call_data nfs; - } sdata; - struct { - u_char header[HEADER_SIZE]; - struct rpc_call rpc; - struct nfs_reply_data nfs; - } rdata; - -#ifdef NFS_DEBUG - if (debug) - printf("readdata: addr=%x, off=%d len=%d\n", (u_int)addr, (u_int)off, len); -#endif - if (len == 0) - return (0); - d->iodesc->destport = getport(d->iodesc, NFS_PROG, NFS_VER2); - - bzero(&sdata, sizeof(sdata)); - - for (i = 0, ns = nfsstate; i < NFS_COUNT; ++i, ++ns) { - if (len <= 0) { - ns->done = 1; - continue; - } - ns->done = 0; - - ns->xid = d->iodesc->xid; - ++d->iodesc->xid; - - ns->off = (u_int)off; - ns->len = len; - if (ns->len > NFSREAD_SIZE) - ns->len = NFSREAD_SIZE; -#ifdef notdef -/* XXX to align or not align? It doesn't seem to speed things up... */ - if ((ns->off % NFSREAD_SIZE) != 0) - ns->len -= off % NFSREAD_SIZE; -#endif - - off += ns->len; - len -= ns->len; - - ns->addr = addr; - addr += NFSREAD_SIZE; - } + size_t cc; + struct nfs_call_data wbuf; + struct nfs_reply_data rbuf; + + bcopy(d->fh, wbuf.fh, NFS_FHSIZE); + wbuf.off = txdr_unsigned(off); + if (len > NFSREAD_SIZE) + len = NFSREAD_SIZE; + wbuf.len = txdr_unsigned(len); + wbuf.xxx = txdr_unsigned(0); + + cc = callrpc(d->iodesc, NFS_PROG, NFS_VER2, NFSPROC_READ, + &wbuf, sizeof(wbuf), + &rbuf, sizeof(rbuf) - NFSREAD_SIZE + len); + if (cc == -1 || cc < sizeof(rbuf) - NFSREAD_SIZE) + return (-1); - rpc = &sdata.rpc; - rpc->rp_rpcvers = htonl(RPC_MSG_VERSION); - rpc->rp_prog = htonl(NFS_PROG); - rpc->rp_vers = htonl(NFS_VER2); - rpc->rp_proc = htonl(NFSPROC_READ); - bcopy(d->fh, sdata.nfs.fh, sizeof(sdata.nfs.fh)); - - nfscc = 0; - cc = sendrecv(d->iodesc, - sendreaddata, &sdata.rpc, - sizeof(struct rpc_call) + sizeof(struct nfs_call_data), - recvreaddata, - ((u_char *)&rdata.rpc) - HEADER_SIZE, HEADER_SIZE + - sizeof(struct rpc_call) + sizeof(struct nfs_reply_data)); + cc -= sizeof(rbuf) - NFSREAD_SIZE; + bcopy(rbuf.data, addr, cc); return (cc); } @@ -598,7 +401,7 @@ nfs_read(f, addr, size, resid) u_int *resid; /* out */ { register struct nfs_iodesc *fp = (struct nfs_iodesc *)f->f_fsdata; - register int cc; + register size_t cc; #ifdef NFS_DEBUG if (debug) @@ -606,16 +409,15 @@ nfs_read(f, addr, size, resid) #endif while (size > 0) { cc = readdata(fp->iodesc, fp->off, (void *)addr, size); - if (cc <= 0) { - /* XXX maybe should retry on certain errors */ - if (cc < 0) { + /* XXX maybe should retry on certain errors */ + if (cc == -1) { #ifdef NFS_DEBUG - if (debug) - printf("nfs_read: read: %s", - strerror(errno)); + if (debug) + printf("nfs_read: read: %s", strerror(errno)); #endif - return (-1); - } + return (-1); + } + if (cc == 0) { if (debug) printf("nfs_read: hit EOF unexpectantly"); goto ret; @@ -681,8 +483,9 @@ nfs_stat(f, sb) #ifdef NFS_DEBUG if (debug) - printf("nfs_stat: called\n"); + printf("nfs_stat: called\n"); #endif + if (getnfsinfo(fp, &mounttime, &sb->st_size, &ftype, &mode, &sb->st_uid, &sb->st_gid) < 0) return(-1); diff --git a/sys/lib/libsa/rarp.c b/sys/lib/libsa/rarp.c index 5414f99aa6c..1d64157d490 100644 --- a/sys/lib/libsa/rarp.c +++ b/sys/lib/libsa/rarp.c @@ -1,4 +1,4 @@ -/* $NetBSD: rarp.c,v 1.4 1994/10/26 05:44:59 cgd Exp $ */ +/* $NetBSD: rarp.c,v 1.5 1995/02/20 11:04:16 mycroft Exp $ */ /* * Copyright (c) 1992 Regents of the University of California. @@ -52,8 +52,8 @@ #include "net.h" #include "netif.h" -static int rarpsend(struct iodesc *, void *, int); -static int rarprecv(struct iodesc *, void *, int); +static size_t rarpsend __P((struct iodesc *, void *, size_t)); +static size_t rarprecv __P((struct iodesc *, void *, size_t, time_t)); /* * Ethernet (Reverse) Address Resolution Protocol (see RFC 903, and 826). @@ -64,18 +64,13 @@ rarp_getipaddress(sock) { struct iodesc *d; register struct ether_arp *ap; - register void *pkt; struct { u_char header[HEADER_SIZE]; struct ether_arp wrarp; } wbuf; - union { - u_char buffer[RECV_SIZE]; - struct { - u_char header[HEADER_SIZE]; - struct ether_arp xrrarp; - }xrbuf; -#define rrarp xrbuf.xrrarp + struct { + u_char header[HEADER_SIZE]; + struct ether_arp rrarp; } rbuf; #ifdef RARP_DEBUG @@ -90,10 +85,8 @@ rarp_getipaddress(sock) if (debug) printf("rarp: d=%x\n", (u_int)d); #endif - ap = &wbuf.wrarp; - pkt = &rbuf.rrarp; - pkt -= HEADER_SIZE; + ap = &wbuf.wrarp; bzero(ap, sizeof(*ap)); ap->arp_hrd = htons(ARPHRD_ETHER); @@ -105,72 +98,73 @@ rarp_getipaddress(sock) bcopy(d->myea, ap->arp_tha, 6); if (sendrecv(d, - rarpsend, ap, sizeof(*ap), - rarprecv, pkt, RECV_SIZE) < 0) { + rarpsend, ap, sizeof(*ap), + rarprecv, &rbuf.rrarp, sizeof(rbuf.rrarp)) < 0) { printf("No response for RARP request\n"); return(INADDR_ANY); } - return(myip); + return (myip); } /* * Broadcast a RARP request (i.e. who knows who I am) */ -static int +static size_t rarpsend(d, pkt, len) register struct iodesc *d; register void *pkt; - register int len; + register size_t len; { + #ifdef RARP_DEBUG if (debug) - printf("rarpsend: called\n"); + printf("rarpsend: called\n"); #endif + return (sendether(d, pkt, len, bcea, ETHERTYPE_REVARP)); } /* * Called when packet containing RARP is received */ -static int -rarprecv(d, pkt, len) +static size_t +rarprecv(d, pkt, len, tleft) register struct iodesc *d; register void *pkt; - register int len; + register size_t len; + time_t tleft; { - register struct ether_header *ep; + register struct ether_header *eh; register struct ether_arp *ap; #ifdef RARP_DEBUG if (debug) - printf("rarprecv: called\n"); + printf("rarprecv: called\n"); #endif - if (len < sizeof(struct ether_header) + sizeof(struct ether_arp)) { - errno = 0; - return (-1); - } - ep = (struct ether_header *)pkt; - if (ntohs(ep->ether_type) != ETHERTYPE_REVARP) { - errno = 0; - return (-1); - } + len = readether(d, pkt, len, tleft); + if (len == -1 || len < sizeof(struct ether_arp)) + goto bad; + + eh = (struct ether_header *)pkt - 1; + if (ntohs(eh->ether_type) != ETHERTYPE_REVARP) + goto bad; - ap = (struct ether_arp *)(ep + 1); + ap = (struct ether_arp *)pkt; if (ntohs(ap->arp_op) != ARPOP_REPLY || - ntohs(ap->arp_pro) != ETHERTYPE_IP) { - errno = 0; - return (-1); - } + ntohs(ap->arp_pro) != ETHERTYPE_IP) + goto bad; - if (bcmp(ap->arp_tha, d->myea, 6)) { - errno = 0; - return (-1); - } + if (bcmp(ap->arp_tha, d->myea, 6)) + goto bad; bcopy(ap->arp_tpa, (char *)&myip, sizeof(myip)); bcopy(ap->arp_spa, (char *)&rootip, sizeof(rootip)); - return(0); + return (0); + +bad: + errno = 0; + return (-1); } diff --git a/sys/lib/libsa/rpc.c b/sys/lib/libsa/rpc.c index e27b9ba6f11..63c284cbb00 100644 --- a/sys/lib/libsa/rpc.c +++ b/sys/lib/libsa/rpc.c @@ -1,4 +1,4 @@ -/* $NetBSD: rpc.c,v 1.3 1995/02/19 23:52:18 mycroft Exp $ */ +/* $NetBSD: rpc.c,v 1.4 1995/02/20 11:04:18 mycroft Exp $ */ /* * Copyright (c) 1992 Regents of the University of California. @@ -47,7 +47,8 @@ #include <nfs/rpcv2.h> #include <nfs/nfsv2.h> -#undef NFSX_FATTR +#include <nfs/xdr_subs.h> + #include <string.h> #include "stand.h" @@ -58,11 +59,7 @@ /* XXX Data part of nfs rpc reply (also the largest thing we receive) */ struct nfs_reply_data { u_long errno; -#ifndef NFSX_FATTR - struct nfsv2_fattr fa; -#else u_char fa[NFSX_FATTR(0)]; -#endif u_long count; u_char data[1200]; }; @@ -82,27 +79,26 @@ static struct pmap_list { static int pmap_num = 1; /* Local forwards */ -static int recvrpc __P((struct iodesc *, void *, int)); +static size_t recvrpc __P((struct iodesc *, void *, size_t, time_t)); /* Make a rpc call; return length of answer */ -int +size_t callrpc(d, prog, vers, proc, sdata, slen, rdata, rlen) register struct iodesc *d; register u_long prog, vers, proc; register void *sdata; - register int slen; + register size_t slen; register void *rdata; - register int rlen; + register size_t rlen; { - register int cc; - register struct rpc_call *rpc; + register size_t cc; + register u_long *tl; struct { u_char header[HEADER_SIZE]; - struct rpc_call wrpc; - u_char data[sizeof(struct nfs_reply_data)]; /* XXX */ + u_long data[96]; /* XXX */ } wbuf; struct { - u_char header[HEADER_SIZE]; + u_char header[HEADER_SIZE]; struct rpc_reply rrpc; union { u_long errno; @@ -120,28 +116,52 @@ callrpc(d, prog, vers, proc, sdata, slen, rdata, rlen) d->destport = getport(d, prog, vers); - rpc = &wbuf.wrpc; + tl = wbuf.data; - bzero(rpc, sizeof(*rpc)); + /* Fill in RPC call structure. */ + *tl++ = txdr_unsigned(d->xid); + *tl++ = txdr_unsigned(RPC_CALL); + *tl++ = txdr_unsigned(RPC_VER2); + *tl++ = txdr_unsigned(prog); + *tl++ = txdr_unsigned(vers); + *tl++ = txdr_unsigned(proc); + + /* Fill in authorization info. */ + if (prog != NFS_PROG) { + *tl++ = txdr_unsigned(RPCAUTH_NULL); + *tl++ = txdr_unsigned(0); + } else { + *tl++ = txdr_unsigned(RPCAUTH_UNIX); + *tl++ = txdr_unsigned(3*NFSX_UNSIGNED); + *tl++ = txdr_unsigned(0); /* time */ + *tl++ = txdr_unsigned(0); /* host name length */ + *tl++ = txdr_unsigned(0); /* uid */ + *tl++ = txdr_unsigned(0); /* gid */ + *tl++ = txdr_unsigned(0); /* gid list length */ + } + *tl++ = txdr_unsigned(RPCAUTH_NULL); + *tl++ = txdr_unsigned(0); - rpc->rp_xid = d->xid; - rpc->rp_rpcvers = htonl(RPC_MSG_VERSION); - rpc->rp_prog = htonl(prog); - rpc->rp_vers = htonl(vers); - rpc->rp_proc = htonl(proc); - bcopy(sdata, wbuf.data, slen); + /* Fill in RPC call arguments. */ + bcopy(sdata, tl, slen); + + cc = sendrecv(d, + sendudp, wbuf.data, + (tl - wbuf.data) * NFSX_UNSIGNED + slen, + recvrpc, &rbuf.rrpc, + sizeof(struct rpc_reply) + sizeof(struct nfs_reply_data)); - cc = sendrecv(d, sendudp, rpc, sizeof(*rpc) + slen, recvrpc, - ((u_char *)&rbuf.rrpc) - HEADER_SIZE, sizeof(rbuf) - HEADER_SIZE); #ifdef RPC_DEBUG if (debug) printf("callrpc: cc=%d rlen=%d, rp_stat=%d\n", cc, rlen, rbuf.rrpc.rp_stat); #endif - /* Bump xid so next request will be unique */ + /* Bump xid so next request will be unique. */ ++d->xid; + if (cc == -1) + return (-1); if (cc < rlen) { /* Check for an error return */ if (cc >= sizeof(rbuf.ru.errno) && rbuf.ru.errno != 0) { @@ -158,11 +178,12 @@ callrpc(d, prog, vers, proc, sdata, slen, rdata, rlen) } /* Returns true if packet is the one we're waiting for */ -static int -recvrpc(d, pkt, len) +static size_t +recvrpc(d, pkt, len, tleft) register struct iodesc *d; register void *pkt; - int len; + register size_t len; + time_t tleft; { register struct rpc_reply *rpc; @@ -171,41 +192,40 @@ recvrpc(d, pkt, len) if (debug) printf("recvrpc: called len=%d\n", len); #endif - rpc = (struct rpc_reply *)checkudp(d, pkt, &len); - if (rpc == NULL || len < sizeof(*rpc)) { -#ifdef RPC_DEBUG - if (debug) - printf("recvrpc: bad response rpc=%x len=%d\n", - (u_int)rpc, len); -#endif - return (-1); - } -#ifdef RPC_DEBUG - if (debug) - printf("recvrpc: got response len=%d\n", len); -#endif + len = readudp(d, pkt, len, tleft); + if (len == -1 || len < sizeof(struct rpc_reply)) + goto bad; + + rpc = (struct rpc_reply *)pkt; + NTOHL(rpc->rp_xid); NTOHL(rpc->rp_direction); NTOHL(rpc->rp_stat); - if (rpc->rp_xid != d->xid || rpc->rp_direction != REPLY || - rpc->rp_stat != MSG_ACCEPTED) { + if (rpc->rp_xid != d->xid || + rpc->rp_direction != RPC_REPLY || + rpc->rp_stat != RPC_MSGACCEPTED) { #ifdef RPC_DEBUG if (debug) { if (rpc->rp_xid != d->xid) printf("recvrpc: rp_xid %d != xid %d\n", - rpc->rp_xid, d->xid); - if (rpc->rp_direction != REPLY) - printf("recvrpc: %d != REPLY\n", rpc->rp_direction); - if (rpc->rp_stat != MSG_ACCEPTED) - printf("recvrpc: %d != MSG_ACCEPTED\n", rpc->rp_stat); + rpc->rp_xid, d->xid); + if (rpc->rp_direction != RPC_REPLY) + printf("recvrpc: rp_direction %d != RPC_REPLY\n", + rpc->rp_direction); + if (rpc->rp_stat != RPC_MSGACCEPTED) + printf("recvrpc: rp_stat %d != RPC_MSGACCEPTED\n", + rpc->rp_stat); } #endif - return (-1); + goto bad; } /* Return data count (thus indicating success) */ return (len - sizeof(*rpc)); + +bad: + return (-1); } /* Request a port number from the port mapper */ diff --git a/sys/lib/libsa/rpc.h b/sys/lib/libsa/rpc.h index adf631be031..2998a90d0a3 100644 --- a/sys/lib/libsa/rpc.h +++ b/sys/lib/libsa/rpc.h @@ -1,4 +1,4 @@ -/* $NetBSD: rpc.h,v 1.2 1994/10/26 05:45:03 cgd Exp $ */ +/* $NetBSD: rpc.h,v 1.3 1995/02/20 11:04:19 mycroft Exp $ */ /* * Copyright (c) 1992 Regents of the University of California. @@ -43,30 +43,6 @@ #define PMAPVERS 2 #define PMAPPROC_GETPORT 3 -#define RPC_MSG_VERSION 2 -#define MSG_ACCEPTED 0 -#define CALL 0 -#define REPLY 1 - - -/* Null rpc auth info */ -struct auth_info { - int rp_atype; /* zero (really AUTH_NULL) */ - u_long rp_alen; /* zero (size of auth struct) */ -}; - -/* Generic rpc call header */ -struct rpc_call { - u_long rp_xid; /* request transaction id */ - int rp_direction; /* call direction */ - u_long rp_rpcvers; /* rpc version (2) */ - u_long rp_prog; /* program */ - u_long rp_vers; /* version */ - u_long rp_proc; /* procedure */ - struct auth_info rp_auth; /* AUTH_NULL */ - struct auth_info rp_verf; /* AUTH_NULL */ -}; - /* Generic rpc reply header */ struct rpc_reply { u_long rp_xid; /* request transaction id */ @@ -78,7 +54,6 @@ struct rpc_reply { }; /* RPC functions: */ -int callrpc __P((struct iodesc *d, u_long prog, u_long ver, u_long op, - void *sdata, int slen, void *rdata, int rlen)); +size_t callrpc __P((struct iodesc *d, u_long prog, u_long ver, u_long op, + void *sdata, size_t slen, void *rdata, size_t rlen)); u_short getport __P((struct iodesc *d, u_long prog, u_long vers)); - |
