Getting more of the IP stack to compile
authorRonald G. Minnich <rminnich@google.com>
Fri, 17 Jan 2014 00:51:14 +0000 (16:51 -0800)
committerRonald G. Minnich <rminnich@google.com>
Fri, 17 Jan 2014 04:56:15 +0000 (20:56 -0800)
There are remaining errors and issues.
How do we sleep and timeout?

We'll skip compress.c for now, it's not likely we want it.

Signed-off-by: Ronald G. Minnich <rminnich@google.com>
15 files changed:
kern/arch/x86/frontend.c
kern/include/ip.h
kern/include/ns.h
kern/include/string.h
kern/src/Kbuild
kern/src/net/Kbuild
kern/src/net/arp.c
kern/src/net/compress.c
kern/src/net/devip.c
kern/src/net/ethermedium.c
kern/src/net/ipifc.c
kern/src/net/ptclbsum.c
kern/src/ns/chan.c
scripts/spatch/plan9.cocci
scripts/spatch/typedef.cocci

index 99b88f2..bdae12d 100644 (file)
@@ -7,6 +7,6 @@
 
 int handle_appserver_packet(const char* p, size_t size)
 {
 
 int handle_appserver_packet(const char* p, size_t size)
 {
-#warning "need to rewrite this for the new ip stack"
+
        panic("bad appserver packet!");
 }
        panic("bad appserver packet!");
 }
index 6d179a0..a3c4e52 100644 (file)
@@ -85,7 +85,7 @@ struct conv
        qlock_t listenq;
        struct rendez   listenr;
 
        qlock_t listenq;
        struct rendez   listenr;
 
-       struct ipmulti  *multi;                 /* multicast bindings for this interface */
+       struct Ipmulti  *multi;                 /* multicast bindings for this interface */
 
        void*   ptcl;                   /* Protocol specific stuff */
 
 
        void*   ptcl;                   /* Protocol specific stuff */
 
@@ -150,19 +150,19 @@ struct Iplifc
        long    preflt;         /* v6 preferred lifetime */
        long    origint;        /* time when addr was added */
        struct Iplink   *link;          /* addresses linked to this lifc */
        long    preflt;         /* v6 preferred lifetime */
        long    origint;        /* time when addr was added */
        struct Iplink   *link;          /* addresses linked to this lifc */
-       struct iplifc   *next;
+       struct Iplifc   *next;
 };
 
 /* binding twixt Ipself and Iplifc */
 struct Iplink
 {
        struct Ipself   *self;
 };
 
 /* binding twixt Ipself and Iplifc */
 struct Iplink
 {
        struct Ipself   *self;
-       struct iplifc   *lifc;
+       struct Iplifc   *lifc;
        struct Iplink   *selflink;      /* next link for this local address */
        struct Iplink   *lifclink;      /* next link for this ifc */
        uint32_t        expire;
        struct Iplink   *next;          /* free list */
        struct Iplink   *selflink;      /* next link for this local address */
        struct Iplink   *lifclink;      /* next link for this ifc */
        uint32_t        expire;
        struct Iplink   *next;          /* free list */
-       int     ref;
+       struct kref     ref;
 };
 
 /* rfc 2461, pp.40--43. */
 };
 
 /* rfc 2461, pp.40--43. */
@@ -464,7 +464,7 @@ struct route
        struct RouteTree rt;
 
        union {
        struct RouteTree rt;
 
        union {
-               struct V6route  v6;
+               struct V6route v6;
                struct V4route v4;
        };
 };
                struct V4route v4;
        };
 };
@@ -558,8 +558,6 @@ extern uint8_t IPnoaddr[IPaddrlen];
 extern uint8_t v4prefix[IPaddrlen];
 extern uint8_t IPallbits[IPaddrlen];
 
 extern uint8_t v4prefix[IPaddrlen];
 extern uint8_t IPallbits[IPaddrlen];
 
-#define        NOW     TK2MS(MACHP(0)->ticks)
-
 /*
  *  media
  */
 /*
  *  media
  */
@@ -583,7 +581,7 @@ extern void findlocalip(struct Fs*, uint8_t *local, uint8_t *remote);
 extern int     ipv4local(struct Ipifc *ifc, uint8_t *addr);
 extern int     ipv6local(struct Ipifc *ifc, uint8_t *addr);
 extern int     ipv6anylocal(struct Ipifc *ifc, uint8_t *addr);
 extern int     ipv4local(struct Ipifc *ifc, uint8_t *addr);
 extern int     ipv6local(struct Ipifc *ifc, uint8_t *addr);
 extern int     ipv6anylocal(struct Ipifc *ifc, uint8_t *addr);
-extern struct iplifc*  iplocalonifc(struct Ipifc *ifc, uint8_t *ip);
+extern struct Iplifc*  iplocalonifc(struct Ipifc *ifc, uint8_t *ip);
 extern int     ipproxyifc(struct Fs *f, struct Ipifc *ifc, uint8_t *ip);
 extern int     ipismulticast(uint8_t *ip);
 extern int     ipisbooting(void);
 extern int     ipproxyifc(struct Fs *f, struct Ipifc *ifc, uint8_t *ip);
 extern int     ipismulticast(uint8_t *ip);
 extern int     ipisbooting(void);
@@ -596,7 +594,7 @@ extern void ipifcremmulti(struct conv *c, uint8_t *ma, uint8_t *ia);
 extern void    ipifcaddmulti(struct conv *c, uint8_t *ma, uint8_t *ia);
 extern char*   ipifcrem(struct Ipifc *ifc, char **argv, int argc);
 extern char*   ipifcadd(struct Ipifc *ifc, char **argv, int argc, int tentative,
 extern void    ipifcaddmulti(struct conv *c, uint8_t *ma, uint8_t *ia);
 extern char*   ipifcrem(struct Ipifc *ifc, char **argv, int argc);
 extern char*   ipifcadd(struct Ipifc *ifc, char **argv, int argc, int tentative,
-                            struct iplifc *lifcp);
+                            struct Iplifc *lifcp);
 extern long    ipselftabread(struct Fs*, char *a, uint32_t offset, int n);
 extern char*   ipifcaddpref6(struct Ipifc *ifc, char**argv, int argc);
 extern void    ipsendra6(struct Fs *f, int on);
 extern long    ipselftabread(struct Fs*, char *a, uint32_t offset, int n);
 extern char*   ipifcaddpref6(struct Ipifc *ifc, char**argv, int argc);
 extern void    ipsendra6(struct Fs *f, int on);
@@ -842,3 +840,5 @@ extern int v6aNpreflen;
 extern int v6aLpreflen;
 
 extern int ReTransTimer;
 extern int v6aLpreflen;
 
 extern int ReTransTimer;
+
+int kdial(char *dest, char *local, char *dir, int *cfdp);
index 7355553..3a9f534 100644 (file)
@@ -960,3 +960,10 @@ char *index(char *s, int c);
 
 /* hack for now. */
 #define eve "eve"
 
 /* hack for now. */
 #define eve "eve"
+#define        NOW     tsc2msec(read_tsc())
+#define        seconds() tsc2sec(read_tsc())
+
+/* system calls */
+int sysclose(int fd);
+int sysopen(char *name, int omode);
+long sysread(int fd, void *p, size_t n, off_t off);
index fa43162..ee2807c 100644 (file)
@@ -8,6 +8,8 @@
 
 int    strlen(const STRING s);
 int    strnlen(const STRBUF(size) s, size_t size);
 
 int    strlen(const STRING s);
 int    strnlen(const STRBUF(size) s, size_t size);
+STRING  strstr(char *s1, char *s2);
+
 /* zra : These aren't being used, and they are dangerous, so I'm rm'ing them
 STRING strcpy(STRING dst, const STRING src);
 STRING strcat(STRING dst, const STRING src);
 /* zra : These aren't being used, and they are dangerous, so I'm rm'ing them
 STRING strcpy(STRING dst, const STRING src);
 STRING strcat(STRING dst, const STRING src);
index 6a6be0a..097a75d 100644 (file)
@@ -39,6 +39,7 @@ obj-y                                         += schedule.o
 obj-y                                          += slab.o
 obj-y                                          += smp.o
 obj-y                                          += string.o
 obj-y                                          += slab.o
 obj-y                                          += smp.o
 obj-y                                          += string.o
+obj-y                                          += strstr.o
 obj-y                                          += syscall.o
 obj-y                                          += sysevent.o
 obj-y                                          += testing.o
 obj-y                                          += syscall.o
 obj-y                                          += sysevent.o
 obj-y                                          += testing.o
index 1d14390..7d8cdac 100644 (file)
@@ -1,7 +1,11 @@
 obj-y                                          += arp.o
 obj-y                                          += arp.o
-obj-y                                          += nullmedium.o
+#obj-y                                         += compress.o
+obj-y                                          += devip.o
+obj-y                                          += ethermedium.o
+obj-y                                          += ipifc.o
 obj-y                                          += loopbackmedium.o
 obj-y                                          += netdevmedium.o
 obj-y                                          += loopbackmedium.o
 obj-y                                          += netdevmedium.o
+obj-y                                          += nullmedium.o
 obj-y                                          += ptclbsum.o
 obj-y                                          += pktmedium.o
 
 obj-y                                          += ptclbsum.o
 obj-y                                          += pktmedium.o
 
index a42f947..a21029b 100644 (file)
@@ -129,11 +129,11 @@ newarp6(struct arp *arp, uint8_t *ip, struct Ipifc *ifc, int addrxt)
        *l = a;
 
        memmove(a->ip, ip, sizeof(a->ip));
        *l = a;
 
        memmove(a->ip, ip, sizeof(a->ip));
-       //a->utime = NOW;
+       a->utime = NOW;
        a->ctime = 0;
        a->type = m;
 
        a->ctime = 0;
        a->type = m;
 
-       //a->rtime = NOW + ReTransTimer;
+       a->rtime = NOW + ReTransTimer;
        a->rxtsrem = MAX_MULTICAST_SOLICIT;
        a->ifc = ifc;
        a->ifcid = ifc->ifcid;
        a->rxtsrem = MAX_MULTICAST_SOLICIT;
        a->ifc = ifc;
        a->ifcid = ifc->ifcid;
@@ -233,8 +233,7 @@ arpget(struct arp *arp, struct block *bp, int version, struct Ipifc *ifc, uint8_
                a = newarp6(arp, ip, ifc, (version != V4));
                a->state = AWAIT;
        }
                a = newarp6(arp, ip, ifc, (version != V4));
                a->state = AWAIT;
        }
-#warning "utime, NOW, rtime, etc."
-       //a->utime = NOW;
+       a->utime = NOW;
        if(a->state == AWAIT){
                if(bp != NULL){
                        if(a->hold)
        if(a->state == AWAIT){
                if(bp != NULL){
                        if(a->hold)
@@ -250,8 +249,8 @@ arpget(struct arp *arp, struct block *bp, int version, struct Ipifc *ifc, uint8_
        memmove(mac, a->mac, a->type->maclen);
 
        /* remove old entries */
        memmove(mac, a->mac, a->type->maclen);
 
        /* remove old entries */
-       //if(NOW - a->ctime > 15*60*1000)
-       //      cleanarpent(arp, a);
+       if(NOW - a->ctime > 15*60*1000)
+               cleanarpent(arp, a);
 
        qunlock(&arp->qlock);
        return NULL;
 
        qunlock(&arp->qlock);
        return NULL;
@@ -292,7 +291,7 @@ arpresolve(struct arp *arp, struct arpent *a, struct medium *type, uint8_t *mac)
        memmove(a->mac, mac, type->maclen);
        a->type = type;
        a->state = AOK;
        memmove(a->mac, mac, type->maclen);
        a->type = type;
        a->state = AOK;
-       //a->utime = NOW;
+       a->utime = NOW;
        bp = a->hold;
        a->hold = NULL;
        qunlock(&arp->qlock);
        bp = a->hold;
        a->hold = NULL;
        qunlock(&arp->qlock);
@@ -368,7 +367,7 @@ arpenter(struct Fs *fs, int version, uint8_t *ip, uint8_t *mac, int n, int refre
                        a->hold = NULL;
                        if(version == V4)
                                ip += IPv4off;
                        a->hold = NULL;
                        if(version == V4)
                                ip += IPv4off;
-                       //a->utime = NOW;
+                       a->utime = NOW;
                        a->ctime = a->utime;
                        qunlock(&arp->qlock);
 
                        a->ctime = a->utime;
                        qunlock(&arp->qlock);
 
@@ -398,7 +397,7 @@ arpenter(struct Fs *fs, int version, uint8_t *ip, uint8_t *mac, int n, int refre
                a = newarp6(arp, ip, ifc, 0);
                a->state = AOK;
                a->type = type;
                a = newarp6(arp, ip, ifc, 0);
                a->state = AOK;
                a->type = type;
-               //a->ctime = NOW;
+               a->ctime = NOW;
                memmove(a->mac, mac, type->maclen);
        }
 
                memmove(a->mac, mac, type->maclen);
        }
 
@@ -592,9 +591,7 @@ rxmitsols(struct arp *arp)
                nrxt = 0;
                goto dodrops;           //return nrxt;
        }
                nrxt = 0;
                goto dodrops;           //return nrxt;
        }
-       //nrxt = a->rtime - NOW;
-#warning "NOW"
-       nrxt = 0;
+       nrxt = a->rtime - NOW;
        if(nrxt > 3*ReTransTimer/4) 
                goto dodrops;           //return nrxt;
 
        if(nrxt > 3*ReTransTimer/4) 
                goto dodrops;           //return nrxt;
 
@@ -643,13 +640,13 @@ rxmitsols(struct arp *arp)
        *l = a;
        a->rxtsrem--;
        a->nextrxt = NULL;
        *l = a;
        a->rxtsrem--;
        a->nextrxt = NULL;
-       //a->rtime = NOW + ReTransTimer;
+       a->rtime = NOW + ReTransTimer;
 
        a = arp->rxmt;
        if(a==NULL)
                nrxt = 0;
        else 
 
        a = arp->rxmt;
        if(a==NULL)
                nrxt = 0;
        else 
-               nrxt = 1; //a->rtime - NOW;
+               nrxt = a->rtime - NOW;
 
 dodrops:
        xp = arp->dropf;
 
 dodrops:
        xp = arp->dropf;
@@ -688,7 +685,7 @@ rxmitproc(void *v)
        //print("arp rxmitproc started\n");
        if(waserror()){
                arp->rxmitp = 0;
        //print("arp rxmitproc started\n");
        if(waserror()){
                arp->rxmitp = 0;
-#warning "pexti"
+#warning "pexit"
                //pexit("hangup", 1);
        }
        for(;;){
                //pexit("hangup", 1);
        }
        for(;;){
index 0a7bd7a..b0040dc 100644 (file)
@@ -1,12 +1,17 @@
-#include       "u.h"
-#include       "../port/lib.h"
-#include       "mem.h"
-#include       "dat.h"
-#include       "fns.h"
-#include       "../port/error.h"
-
-#include       "ip.h"
-#include       "ppp.h"
+// INFERNO
+#include <vfs.h>
+#include <kfs.h>
+#include <slab.h>
+#include <kmalloc.h>
+#include <kref.h>
+#include <string.h>
+#include <stdio.h>
+#include <assert.h>
+#include <error.h>
+#include <cpio.h>
+#include <pmap.h>
+#include <smp.h>
+#include <ip.h>
 
 typedef struct Iphdr   Iphdr;
 typedef struct Tcphdr  Tcphdr;
 
 typedef struct Iphdr   Iphdr;
 typedef struct Tcphdr  Tcphdr;
@@ -16,39 +21,39 @@ typedef struct Tcpc Tcpc;
 
 struct Iphdr
 {
 
 struct Iphdr
 {
-       uchar   vihl;           /* Version and header length */
-       uchar   tos;            /* Type of service */
-       uchar   length[2];      /* packet length */
-       uchar   id[2];          /* Identification */
-       uchar   frag[2];        /* Fragment information */
-       uchar   ttl;            /* Time to live */
-       uchar   proto;          /* Protocol */
-       uchar   cksum[2];       /* Header checksum */
-       ulong   src;            /* Ip source (byte ordering unimportant) */
-       ulong   dst;            /* Ip destination (byte ordering unimportant) */
+       uint8_t vihl;           /* Version and header length */
+       uint8_t tos;            /* Type of service */
+       uint8_t length[2];      /* packet length */
+       uint8_t id[2];          /* Identification */
+       uint8_t frag[2];        /* Fragment information */
+       uint8_t ttl;            /* Time to live */
+       uint8_t proto;          /* Protocol */
+       uint8_t cksum[2];       /* Header checksum */
+       uint32_t        src;            /* Ip source (byte ordering unimportant) */
+       uint32_t        dst;            /* Ip destination (byte ordering unimportant) */
 };
 
 struct Tcphdr
 {
 };
 
 struct Tcphdr
 {
-       ulong   ports;          /* defined as a ulong to make comparisons easier */
-       uchar   seq[4];
-       uchar   ack[4];
-       uchar   flag[2];
-       uchar   win[2];
-       uchar   cksum[2];
-       uchar   urg[2];
+       uint32_t        ports;          /* defined as a uint32_t to make comparisons easier */
+       uint8_t seq[4];
+       uint8_t ack[4];
+       uint8_t flag[2];
+       uint8_t win[2];
+       uint8_t cksum[2];
+       uint8_t urg[2];
 };
 
 struct Ilhdr
 {
 };
 
 struct Ilhdr
 {
-       uchar   sum[2]; /* Checksum including header */
-       uchar   len[2]; /* Packet length */
-       uchar   type;           /* Packet type */
-       uchar   spec;           /* Special */
-       uchar   src[2]; /* Src port */
-       uchar   dst[2]; /* Dst port */
-       uchar   id[4];  /* Sequence id */
-       uchar   ack[4]; /* Acked sequence */
+       uint8_t sum[2]; /* Checksum including header */
+       uint8_t len[2]; /* Packet length */
+       uint8_t type;           /* Packet type */
+       uint8_t spec;           /* Special */
+       uint8_t src[2]; /* Src port */
+       uint8_t dst[2]; /* Dst port */
+       uint8_t id[4];  /* Sequence id */
+       uint8_t ack[4]; /* Acked sequence */
 };
 
 enum
 };
 
 enum
@@ -69,7 +74,7 @@ enum
 
 struct Hdr
 {
 
 struct Hdr
 {
-       uchar   buf[128];
+       uint8_t buf[128];
        Iphdr   *ip;
        Tcphdr  *tcp;
        int     len;
        Iphdr   *ip;
        Tcphdr  *tcp;
        int     len;
@@ -77,11 +82,11 @@ struct Hdr
 
 struct Tcpc
 {
 
 struct Tcpc
 {
-       uchar   lastrecv;
-       uchar   lastxmit;
-       uchar   basexmit;
-       uchar   err;
-       uchar   compressid;
+       uint8_t lastrecv;
+       uint8_t lastxmit;
+       uint8_t basexmit;
+       uint8_t err;
+       uint8_t compressid;
        Hdr     t[MAX_STATES];
        Hdr     r[MAX_STATES];
 };
        Hdr     t[MAX_STATES];
        Hdr     r[MAX_STATES];
 };
@@ -105,9 +110,9 @@ enum
 #define SPECIALS_MASK (NEW_S|NEW_A|NEW_W|NEW_U)
 
 int
 #define SPECIALS_MASK (NEW_S|NEW_A|NEW_W|NEW_U)
 
 int
-encode(void *p, ulong n)
+encode(void *p, uint32_t n)
 {
 {
-       uchar   *cp;
+       uint8_t *cp;
 
        cp = p;
        if(n >= 256 || n == 0) {
 
        cp = p;
        if(n >= 256 || n == 0) {
@@ -125,7 +130,7 @@ encode(void *p, ulong n)
                hnputl(f, nhgetl(f) + ((cp[1] << 8) | cp[2])); \
                cp += 3; \
        } else { \
                hnputl(f, nhgetl(f) + ((cp[1] << 8) | cp[2])); \
                cp += 3; \
        } else { \
-               hnputl(f, nhgetl(f) + (ulong)*cp++); \
+               hnputl(f, nhgetl(f) + (uint32_t)*cp++); \
        } \
 }
 #define DECODES(f) { \
        } \
 }
 #define DECODES(f) { \
@@ -133,20 +138,20 @@ encode(void *p, ulong n)
                hnputs(f, nhgets(f) + ((cp[1] << 8) | cp[2])); \
                cp += 3; \
        } else { \
                hnputs(f, nhgets(f) + ((cp[1] << 8) | cp[2])); \
                cp += 3; \
        } else { \
-               hnputs(f, nhgets(f) + (ulong)*cp++); \
+               hnputs(f, nhgets(f) + (uint32_t)*cp++); \
        } \
 }
 
        } \
 }
 
-ushort
-tcpcompress(Tcpc *comp, Block *b, Fs *)
+uint16_t
+tcpcompress(Tcpc *comp, struct block *b, struct Fs *)
 {
        Iphdr   *ip;            /* current packet */
        Tcphdr  *tcp;           /* current pkt */
 {
        Iphdr   *ip;            /* current packet */
        Tcphdr  *tcp;           /* current pkt */
-       ulong   iplen, tcplen, hlen;    /* header length in bytes */
-       ulong   deltaS, deltaA; /* general purpose temporaries */
-       ulong   changes;        /* change mask */
-       uchar   new_seq[16];    /* changes from last to current */
-       uchar   *cp;
+       uint32_t        iplen, tcplen, hlen;    /* header length in bytes */
+       uint32_t        deltaS, deltaA; /* general purpose temporaries */
+       uint32_t        changes;        /* change mask */
+       uint8_t new_seq[16];    /* changes from last to current */
+       uint8_t *cp;
        Hdr     *h;             /* last packet */
        int     i, j;
 
        Hdr     *h;             /* last packet */
        int     i, j;
 
@@ -318,10 +323,10 @@ raise:
        return Pvjutcp;
 }
 
        return Pvjutcp;
 }
 
-Block*
-tcpuncompress(Tcpc *comp, Block *b, ushort type, Fs *f)
+struct block*
+tcpuncompress(Tcpc *comp, struct block *b, uint16_t type, struct Fs *f)
 {
 {
-       uchar   *cp, changes;
+       uint8_t *cp, changes;
        int     i;
        int     iplen, len;
        Iphdr   *ip;
        int     i;
        int     iplen, len;
        Iphdr   *ip;
@@ -378,7 +383,7 @@ netlog(f, Logcompress, "newc %d\n", comp->lastrecv);
                 */
                if(comp->err != 0){
                        freeblist(b);
                 */
                if(comp->err != 0){
                        freeblist(b);
-                       return nil;
+                       return NULL;
                }
 netlog(f, Logcompress, "oldc %d\n", comp->lastrecv);
        }
                }
 netlog(f, Logcompress, "oldc %d\n", comp->lastrecv);
        }
@@ -437,7 +442,7 @@ netlog(f, Logcompress, "oldc %d\n", comp->lastrecv);
                hnputs(ip->id, nhgets(ip->id) + 1);
 
        /*
                hnputs(ip->id, nhgets(ip->id) + 1);
 
        /*
-        *  At this point, cp points to the first byte of data in the packet.
+        *  At this po int unused_int, cp points to the first byte of data in the packet.
         *  Back up cp by the TCP/IP header length to make room for the
         *  reconstructed header.
         *  We assume the packet we were handed has enough space to prepend
         *  Back up cp by the TCP/IP header length to make room for the
         *  reconstructed header.
         *  We assume the packet we were handed has enough space to prepend
@@ -461,7 +466,7 @@ raise:
        netlog(f, Logcompress, "Bad Packet!\n");
        comp->err = 1;
        freeblist(b);
        netlog(f, Logcompress, "Bad Packet!\n");
        comp->err = 1;
        freeblist(b);
-       return nil;
+       return NULL;
 }
 
 Tcpc*
 }
 
 Tcpc*
@@ -470,10 +475,10 @@ compress_init(Tcpc *c)
        int i;
        Hdr *h;
 
        int i;
        Hdr *h;
 
-       if(c == nil){
-               c = malloc(sizeof(Tcpc));
-               if(c == nil)
-                       return nil;
+       if(c == NULL){
+               c = kzmalloc(sizeof(Tcpc), 0);
+               if(c == NULL)
+                       return NULL;
        }
        memset(c, 0, sizeof(*c));
        for(i = 0; i < MAX_STATES; i++){
        }
        memset(c, 0, sizeof(*c));
        for(i = 0; i < MAX_STATES; i++){
@@ -490,8 +495,8 @@ compress_init(Tcpc *c)
        return c;
 }
 
        return c;
 }
 
-ushort
-compress(Tcpc *tcp, Block *b, Fs *f)
+uint16_t
+compress(Tcpc *tcp, struct block *b, struct Fs *f)
 {
        Iphdr           *ip;
 
 {
        Iphdr           *ip;
 
@@ -511,7 +516,7 @@ compress(Tcpc *tcp, Block *b, Fs *f)
 }
 
 int
 }
 
 int
-compress_negotiate(Tcpc *tcp, uchar *data)
+compress_negotiate(Tcpc *tcp, uint8_t *data)
 {
        if(data[0] != MAX_STATES - 1)
                return -1;
 {
        if(data[0] != MAX_STATES - 1)
                return -1;
index bb37d34..570194c 100644 (file)
@@ -1,10 +1,17 @@
-#include       "u.h"
-#include       "../port/lib.h"
-#include       "mem.h"
-#include       "dat.h"
-#include       "fns.h"
-#include       "../port/error.h"
-#include       "../ip/ip.h"
+// INFERNO
+#include <vfs.h>
+#include <kfs.h>
+#include <slab.h>
+#include <kmalloc.h>
+#include <kref.h>
+#include <string.h>
+#include <stdio.h>
+#include <assert.h>
+#include <error.h>
+#include <cpio.h>
+#include <pmap.h>
+#include <smp.h>
+#include <ip.h>
 
 enum
 {
 
 enum
 {
@@ -45,31 +52,30 @@ enum
 
        Nfs=            32,
 };
 
        Nfs=            32,
 };
-#define TYPE(x)        ( ((ulong)(x).path) & Masktype )
-#define CONV(x)        ( (((ulong)(x).path) >> Shiftconv) & Maskconv )
-#define PROTO(x)       ( (((ulong)(x).path) >> Shiftproto) & Maskproto )
-#define QID(p, c, y)   ( ((p)<<(Shiftproto)) | ((c)<<Shiftconv) | (y) )
-
+#define TYPE(x)        ( ((uint32_t)(x).path) & Masktype )
+#define CONV(x)        ( (((uint32_t)(x).path) >> Shiftconv) & Maskconv )
+#define PROTO(x)       ( (((uint32_t)(x).path) >> Shiftproto) & Maskproto )
+#define QID(p, c, y)   ( ((p)<<(Shiftproto)) | ((c)<<Shiftconv) | (y))
 static char network[] = "network";
 
 static char network[] = "network";
 
-QLock  fslock;
-Fs     *ipfs[Nfs];     /* attached fs's */
-Queue  *qlog;
+qlock_t        fslock;
+struct Fs      *ipfs[Nfs];     /* attached fs's */
+struct queue   *qlog;
 
 extern void nullmediumlink(void);
 extern void pktmediumlink(void);
 
 extern void nullmediumlink(void);
 extern void pktmediumlink(void);
-static long ndbwrite(Fs*, char*, ulong, int);
-static void    closeconv(Conv*);
+static long ndbwrite(struct Fs*, char *unused_char_p_t, uint32_t, int);
+static void    closeconv(struct conv*);
 
 static int
 
 static int
-ip3gen(Chan *c, int i, Dir *dp)
+ip3gen(struct chan *c, int i, struct dir *dp)
 {
 {
-       Qid q;
-       Conv *cv;
+       struct qid q;
+       struct conv *cv;
        char *p;
 
        cv = ipfs[c->dev]->p[PROTO(c->qid)]->conv[CONV(c->qid)];
        char *p;
 
        cv = ipfs[c->dev]->p[PROTO(c->qid)]->conv[CONV(c->qid)];
-       if(cv->owner == nil)
+       if(cv->owner == NULL)
                kstrdup(&cv->owner, eve);
        mkqid(&q, QID(PROTO(c->qid), CONV(c->qid), i), 0, QTFILE);
 
                kstrdup(&cv->owner, eve);
        mkqid(&q, QID(PROTO(c->qid), CONV(c->qid), i), 0, QTFILE);
 
@@ -108,9 +114,9 @@ ip3gen(Chan *c, int i, Dir *dp)
 }
 
 static int
 }
 
 static int
-ip2gen(Chan *c, int i, Dir *dp)
+ip2gen(struct chan *c, int i, struct dir *dp)
 {
 {
-       Qid q;
+       struct qid q;
 
        switch(i) {
        case Qclone:
 
        switch(i) {
        case Qclone:
@@ -126,14 +132,14 @@ ip2gen(Chan *c, int i, Dir *dp)
 }
 
 static int
 }
 
 static int
-ip1gen(Chan *c, int i, Dir *dp)
+ip1gen(struct chan *c, int i, struct dir *dp)
 {
 {
-       Qid q;
+       struct qid q;
        char *p;
        int prot;
        int len = 0;
        char *p;
        int prot;
        int len = 0;
-       Fs *f;
-       extern ulong    kerndate;
+       struct Fs *f;
+       extern uint32_t kerndate;
 
        f = ipfs[c->dev];
 
 
        f = ipfs[c->dev];
 
@@ -147,7 +153,7 @@ ip1gen(Chan *c, int i, Dir *dp)
                break;
        case Qbootp:
                p = "bootp";
                break;
        case Qbootp:
                p = "bootp";
-               if(bootp == nil)
+               if(bootp == NULL)
                        return 0;
                break;
        case Qndb:
                        return 0;
                break;
        case Qndb:
@@ -176,11 +182,11 @@ ip1gen(Chan *c, int i, Dir *dp)
 }
 
 static int
 }
 
 static int
-ipgen(Chan *c, char*, Dirtab*, int, int s, Dir *dp)
+ipgen(struct chan *c, char *unused_char_p_t, struct dirtab*d, int unused_int, int s, struct dir *dp)
 {
 {
-       Qid q;
-       Conv *cv;
-       Fs *f;
+       struct qid q;
+       struct conv *cv;
+       struct Fs *f;
 
        f = ipfs[c->dev];
 
 
        f = ipfs[c->dev];
 
@@ -188,12 +194,12 @@ ipgen(Chan *c, char*, Dirtab*, int, int s, Dir *dp)
        case Qtopdir:
                if(s == DEVDOTDOT){
                        mkqid(&q, QID(0, 0, Qtopdir), 0, QTDIR);
        case Qtopdir:
                if(s == DEVDOTDOT){
                        mkqid(&q, QID(0, 0, Qtopdir), 0, QTDIR);
-                       sprint(up->genbuf, "#I%lud", c->dev);
-                       devdir(c, q, up->genbuf, 0, network, 0555, dp);
+                       snprintf(get_cur_genbuf(), GENBUF_SZ, "#I%lud", c->dev);
+                       devdir(c, q, get_cur_genbuf(), 0, network, 0555, dp);
                        return 1;
                }
                if(s < f->np) {
                        return 1;
                }
                if(s < f->np) {
-                       if(f->p[s]->connect == nil)
+                       if(f->p[s]->connect == NULL)
                                return 0;       /* protocol with no user interface */
                        mkqid(&q, QID(s, 0, Qprotodir), 0, QTDIR);
                        devdir(c, q, f->p[s]->name, 0, network, 0555, dp);
                                return 0;       /* protocol with no user interface */
                        mkqid(&q, QID(s, 0, Qprotodir), 0, QTDIR);
                        devdir(c, q, f->p[s]->name, 0, network, 0555, dp);
@@ -212,15 +218,15 @@ ipgen(Chan *c, char*, Dirtab*, int, int s, Dir *dp)
        case Qprotodir:
                if(s == DEVDOTDOT){
                        mkqid(&q, QID(0, 0, Qtopdir), 0, QTDIR);
        case Qprotodir:
                if(s == DEVDOTDOT){
                        mkqid(&q, QID(0, 0, Qtopdir), 0, QTDIR);
-                       sprint(up->genbuf, "#I%lud", c->dev);
-                       devdir(c, q, up->genbuf, 0, network, 0555, dp);
+                       snprintf(get_cur_genbuf(), GENBUF_SZ, "#I%lud", c->dev);
+                       devdir(c, q, get_cur_genbuf(), 0, network, 0555, dp);
                        return 1;
                }
                if(s < f->p[PROTO(c->qid)]->ac) {
                        cv = f->p[PROTO(c->qid)]->conv[s];
                        return 1;
                }
                if(s < f->p[PROTO(c->qid)]->ac) {
                        cv = f->p[PROTO(c->qid)]->conv[s];
-                       sprint(up->genbuf, "%d", s);
+                       snprintf(get_cur_genbuf(), GENBUF_SZ, "%d", s);
                        mkqid(&q, QID(PROTO(c->qid), s, Qconvdir), 0, QTDIR);
                        mkqid(&q, QID(PROTO(c->qid), s, Qconvdir), 0, QTDIR);
-                       devdir(c, q, up->genbuf, 0, cv->owner, 0555, dp);
+                       devdir(c, q, get_cur_genbuf(), 0, cv->owner, 0555, dp);
                        return 1;
                }
                s -= f->p[PROTO(c->qid)]->ac;
                        return 1;
                }
                s -= f->p[PROTO(c->qid)]->ac;
@@ -254,27 +260,28 @@ ipreset(void)
 {
        nullmediumlink();
        pktmediumlink();
 {
        nullmediumlink();
        pktmediumlink();
-
+/* if only
        fmtinstall('i', eipfmt);
        fmtinstall('I', eipfmt);
        fmtinstall('E', eipfmt);
        fmtinstall('V', eipfmt);
        fmtinstall('M', eipfmt);
        fmtinstall('i', eipfmt);
        fmtinstall('I', eipfmt);
        fmtinstall('E', eipfmt);
        fmtinstall('V', eipfmt);
        fmtinstall('M', eipfmt);
+*/
 }
 
 }
 
-static Fs*
+static struct Fs*
 ipgetfs(int dev)
 {
 ipgetfs(int dev)
 {
-       extern void (*ipprotoinit[])(Fs*);
-       Fs *f;
+       extern void (*ipprotoinit[])(struct Fs*);
+       struct Fs *f;
        int i;
 
        if(dev >= Nfs)
        int i;
 
        if(dev >= Nfs)
-               return nil;
+               return NULL;
 
        qlock(&fslock);
 
        qlock(&fslock);
-       if(ipfs[dev] == nil){
-               f = smalloc(sizeof(Fs));
+       if(ipfs[dev] == NULL){
+               f = kzmalloc(sizeof(struct Fs), 0);
                ip_init(f);
                arpinit(f);
                netloginit(f);
                ip_init(f);
                arpinit(f);
                netloginit(f);
@@ -288,13 +295,13 @@ ipgetfs(int dev)
        return ipfs[dev];
 }
 
        return ipfs[dev];
 }
 
-IPaux*
+struct IPaux*
 newipaux(char *owner, char *tag)
 {
 newipaux(char *owner, char *tag)
 {
-       IPaux *a;
+       struct IPaux *a;
        int n;
 
        int n;
 
-       a = smalloc(sizeof(*a));
+       a = kzmalloc(sizeof(*a), 0);
        kstrdup(&a->owner, owner);
        memset(a->tag, ' ', sizeof(a->tag));
        n = strlen(tag);
        kstrdup(&a->owner, owner);
        memset(a->tag, ' ', sizeof(a->tag));
        n = strlen(tag);
@@ -304,12 +311,12 @@ newipaux(char *owner, char *tag)
        return a;
 }
 
        return a;
 }
 
-#define ATTACHER(c) (((IPaux*)((c)->aux))->owner)
+#define ATTACHER(c) (((struct IPaux*)((c)->aux))->owner)
 
 
-static Chan*
+static struct chan*
 ipattach(char* spec)
 {
 ipattach(char* spec)
 {
-       Chan *c;
+       struct chan *c;
        int dev;
 
        dev = atoi(spec);
        int dev;
 
        dev = atoi(spec);
@@ -326,31 +333,31 @@ ipattach(char* spec)
        return c;
 }
 
        return c;
 }
 
-static Walkqid*
-ipwalk(Chan* c, Chan *nc, char **name, int nname)
+static struct walkqid*
+ipwalk(struct chan* c, struct chan *nc, char **name, int nname)
 {
 {
-       IPaux *a = c->aux;
-       Walkqid* w;
+       struct IPaux *a = c->aux;
+       struct walkqid* w;
 
 
-       w = devwalk(c, nc, name, nname, nil, 0, ipgen);
-       if(w != nil && w->clone != nil)
+       w = devwalk(c, nc, name, nname, NULL, 0, ipgen);
+       if(w != NULL && w->clone != NULL)
                w->clone->aux = newipaux(a->owner, a->tag);
        return w;
 }
 
 static int
                w->clone->aux = newipaux(a->owner, a->tag);
        return w;
 }
 
 static int
-ipstat(Chan* c, uchar* db, int n)
+ipstat(struct chan* c, uint8_t* db, int n)
 {
 {
-       return devstat(c, db, n, nil, 0, ipgen);
+       return devstat(c, db, n, NULL, 0, ipgen);
 }
 
 static int
 incoming(void* arg)
 {
 }
 
 static int
 incoming(void* arg)
 {
-       Conv *conv;
+       struct conv *conv;
 
        conv = arg;
 
        conv = arg;
-       return conv->incall != nil;
+       return conv->incall != NULL;
 }
 
 static int m2p[] = {
 }
 
 static int m2p[] = {
@@ -359,13 +366,14 @@ static int m2p[] = {
        [ORDWR]         6
 };
 
        [ORDWR]         6
 };
 
-static Chan*
-ipopen(Chan* c, int omode)
+static struct chan*
+ipopen(struct chan* c, int omode)
 {
 {
-       Conv *cv, *nc;
-       Proto *p;
+       ERRSTACK(2);
+       struct conv *cv, *nc;
+       struct Proto *p;
        int perm;
        int perm;
-       Fs *f;
+       struct Fs *f;
 
        perm = m2p[omode&3];
 
 
        perm = m2p[omode&3];
 
@@ -407,19 +415,19 @@ ipopen(Chan* c, int omode)
                cv = p->conv[CONV(c->qid)];
                if(strcmp(ATTACHER(c), cv->owner) != 0 && !iseve())
                        error(Eperm);
                cv = p->conv[CONV(c->qid)];
                if(strcmp(ATTACHER(c), cv->owner) != 0 && !iseve())
                        error(Eperm);
-               incref(&cv->snoopers);
+               kref_get(&cv->snoopers, 1);
                break;
        case Qclone:
                p = f->p[PROTO(c->qid)];
                break;
        case Qclone:
                p = f->p[PROTO(c->qid)];
-               qlock(p);
+               qlock(&p->qlock);
                if(waserror()){
                if(waserror()){
-                       qunlock(p);
+                       qunlock(&p->qlock);
                        nexterror();
                }
                cv = Fsprotoclone(p, ATTACHER(c));
                        nexterror();
                }
                cv = Fsprotoclone(p, ATTACHER(c));
-               qunlock(p);
+               qunlock(&p->qlock);
                poperror();
                poperror();
-               if(cv == nil) {
+               if(cv == NULL) {
                        error(Enodev);
                        break;
                }
                        error(Enodev);
                        break;
                }
@@ -429,12 +437,12 @@ ipopen(Chan* c, int omode)
        case Qctl:
        case Qerr:
                p = f->p[PROTO(c->qid)];
        case Qctl:
        case Qerr:
                p = f->p[PROTO(c->qid)];
-               qlock(p);
+               qlock(&p->qlock);
                cv = p->conv[CONV(c->qid)];
                cv = p->conv[CONV(c->qid)];
-               qlock(cv);
+               qlock(&cv->qlock);
                if(waserror()) {
                if(waserror()) {
-                       qunlock(cv);
-                       qunlock(p);
+                       qunlock(&cv->qlock);
+                       qunlock(&p->qlock);
                        nexterror();
                }
                if((perm & (cv->perm>>6)) != perm) {
                        nexterror();
                }
                if((perm & (cv->perm>>6)) != perm) {
@@ -449,8 +457,8 @@ ipopen(Chan* c, int omode)
                        kstrdup(&cv->owner, ATTACHER(c));
                        cv->perm = 0660;
                }
                        kstrdup(&cv->owner, ATTACHER(c));
                        cv->perm = 0660;
                }
-               qunlock(cv);
-               qunlock(p);
+               qunlock(&cv->qlock);
+               qunlock(&p->qlock);
                poperror();
                break;
        case Qlisten:
                poperror();
                break;
        case Qlisten:
@@ -470,12 +478,12 @@ ipopen(Chan* c, int omode)
                        closeconv(cv);
                        nexterror();
                }
                        closeconv(cv);
                        nexterror();
                }
-               qlock(cv);
+               qlock(&cv->qlock);
                cv->inuse++;
                cv->inuse++;
-               qunlock(cv);
+               qunlock(&cv->qlock);
 
 
-               nc = nil;
-               while(nc == nil) {
+               nc = NULL;
+               while(nc == NULL) {
                        /* give up if we got a hangup */
                        if(qisclosed(cv->rq))
                                error("listen hungup");
                        /* give up if we got a hangup */
                        if(qisclosed(cv->rq))
                                error("listen hungup");
@@ -489,14 +497,14 @@ ipopen(Chan* c, int omode)
                        /* wait for a connect */
                        sleep(&cv->listenr, incoming, cv);
 
                        /* wait for a connect */
                        sleep(&cv->listenr, incoming, cv);
 
-                       qlock(cv);
+                       qlock(&cv->qlock);
                        nc = cv->incall;
                        nc = cv->incall;
-                       if(nc != nil){
+                       if(nc != NULL){
                                cv->incall = nc->next;
                                mkqid(&c->qid, QID(PROTO(c->qid), nc->x, Qctl), 0, QTFILE);
                                kstrdup(&cv->owner, ATTACHER(c));
                        }
                                cv->incall = nc->next;
                                mkqid(&c->qid, QID(PROTO(c->qid), nc->x, Qctl), 0, QTFILE);
                                kstrdup(&cv->owner, ATTACHER(c));
                        }
-                       qunlock(cv);
+                       qunlock(&cv->qlock);
 
                        qunlock(&cv->listenq);
                        poperror();
 
                        qunlock(&cv->listenq);
                        poperror();
@@ -512,12 +520,13 @@ ipopen(Chan* c, int omode)
 }
 
 static int
 }
 
 static int
-ipwstat(Chan *c, uchar *dp, int n)
+ipwstat(struct chan *c, uint8_t *dp, int n)
 {
 {
-       Dir *d;
-       Conv *cv;
-       Fs *f;
-       Proto *p;
+       ERRSTACK(2);
+       struct dir *d;
+       struct conv *cv;
+       struct Fs *f;
+       struct Proto *p;
 
        f = ipfs[c->dev];
        switch(TYPE(c->qid)) {
 
        f = ipfs[c->dev];
        switch(TYPE(c->qid)) {
@@ -529,12 +538,12 @@ ipwstat(Chan *c, uchar *dp, int n)
                break;
        }
 
                break;
        }
 
-       d = smalloc(sizeof(*d)+n);
+       d = kzmalloc(sizeof(*d) + n, 0);
        if(waserror()){
        if(waserror()){
-               free(d);
+               kfree(d);
                nexterror();
        }
                nexterror();
        }
-       n = convM2D(dp, n, d, (char*)&d[1]);
+       n = convM2D(dp, n, d, ( char *)&d[1]);
        if(n == 0)
                error(Eshortstat);
        p = f->p[PROTO(c->qid)];
        if(n == 0)
                error(Eshortstat);
        p = f->p[PROTO(c->qid)];
@@ -546,20 +555,20 @@ ipwstat(Chan *c, uchar *dp, int n)
        if(d->mode != ~0UL)
                cv->perm = d->mode & 0777;
        poperror();
        if(d->mode != ~0UL)
                cv->perm = d->mode & 0777;
        poperror();
-       free(d);
+       kfree(d);
        return n;
 }
 
 static void
        return n;
 }
 
 static void
-closeconv(Conv *cv)
+closeconv(struct conv *cv)
 {
 {
-       Conv *nc;
-       Ipmulti *mp;
+       struct conv *nc;
+       struct Ipmulti *mp;
 
 
-       qlock(cv);
+       qlock(&cv->qlock);
 
        if(--cv->inuse > 0) {
 
        if(--cv->inuse > 0) {
-               qunlock(cv);
+               qunlock(&cv->qlock);
                return;
        }
 
                return;
        }
 
@@ -568,25 +577,25 @@ closeconv(Conv *cv)
                cv->incall = nc->next;
                closeconv(nc);
        }
                cv->incall = nc->next;
                closeconv(nc);
        }
-       cv->incall = nil;
+       cv->incall = NULL;
 
        kstrdup(&cv->owner, network);
        cv->perm = 0660;
 
 
        kstrdup(&cv->owner, network);
        cv->perm = 0660;
 
-       while((mp = cv->multi) != nil)
+       while((mp = cv->multi) != NULL)
                ipifcremmulti(cv, mp->ma, mp->ia);
 
                ipifcremmulti(cv, mp->ma, mp->ia);
 
-       cv->r = nil;
+       cv->r = NULL;
        cv->rgen = 0;
        cv->p->close(cv);
        cv->state = Idle;
        cv->rgen = 0;
        cv->p->close(cv);
        cv->state = Idle;
-       qunlock(cv);
+       qunlock(&cv->qlock);
 }
 
 static void
 }
 
 static void
-ipclose(Chan* c)
+ipclose(struct chan* c)
 {
 {
-       Fs *f;
+       struct Fs *f;
 
        f = ipfs[c->dev];
        switch(TYPE(c->qid)) {
 
        f = ipfs[c->dev];
        switch(TYPE(c->qid)) {
@@ -608,11 +617,11 @@ ipclose(Chan* c)
                break;
        case Qsnoop:
                if(c->flag & COPEN)
                break;
        case Qsnoop:
                if(c->flag & COPEN)
-                       decref(&f->p[PROTO(c->qid)]->conv[CONV(c->qid)]->snoopers);
+                       kref_put(&f->p[PROTO(c->qid)]->conv[CONV(c->qid)]->snoopers);
                break;
        }
                break;
        }
-       free(((IPaux*)c->aux)->owner);
-       free(c->aux);
+       kfree(((struct IPaux*)c->aux)->owner);
+       kfree(c->aux);
 }
 
 enum
 }
 
 enum
@@ -621,14 +630,14 @@ enum
 };
 
 static long
 };
 
 static long
-ipread(Chan *ch, void *a, long n, vlong off)
+ipread(struct chan *ch, void *a, long n, int64_t off)
 {
 {
-       Conv *c;
-       Proto *x;
+       struct conv *c;
+       struct Proto *x;
        char *buf, *p;
        long rv;
        char *buf, *p;
        long rv;
-       Fs *f;
-       ulong offset = off;
+       struct Fs *f;
+       uint32_t offset = off;
 
        f = ipfs[ch->dev];
 
 
        f = ipfs[ch->dev];
 
@@ -655,39 +664,39 @@ ipread(Chan *ch, void *a, long n, vlong off)
        case Qlog:
                return netlogread(f, a, offset, n);
        case Qctl:
        case Qlog:
                return netlogread(f, a, offset, n);
        case Qctl:
-               sprint(up->genbuf, "%lud", CONV(ch->qid));
-               return readstr(offset, p, n, up->genbuf);
+               snprintf(get_cur_genbuf(), GENBUF_SZ, "%lud", CONV(ch->qid));
+               return readstr(offset, p, n, get_cur_genbuf());
        case Qremote:
        case Qremote:
-               buf = smalloc(Statelen);
+               buf = kzmalloc(Statelen, 0);
                x = f->p[PROTO(ch->qid)];
                c = x->conv[CONV(ch->qid)];
                x = f->p[PROTO(ch->qid)];
                c = x->conv[CONV(ch->qid)];
-               if(x->remote == nil) {
-                       sprint(buf, "%I!%d\n", c->raddr, c->rport);
+               if(x->remote == NULL) {
+                       snprintf(buf, Statelen, "%I!%d\n", c->raddr, c->rport);
                } else {
                        (*x->remote)(c, buf, Statelen-2);
                }
                rv = readstr(offset, p, n, buf);
                } else {
                        (*x->remote)(c, buf, Statelen-2);
                }
                rv = readstr(offset, p, n, buf);
-               free(buf);
+               kfree(buf);
                return rv;
        case Qlocal:
                return rv;
        case Qlocal:
-               buf = smalloc(Statelen);
+               buf = kzmalloc(Statelen, 0);
                x = f->p[PROTO(ch->qid)];
                c = x->conv[CONV(ch->qid)];
                x = f->p[PROTO(ch->qid)];
                c = x->conv[CONV(ch->qid)];
-               if(x->local == nil) {
-                       sprint(buf, "%I!%d\n", c->laddr, c->lport);
+               if(x->local == NULL) {
+                       snprintf(buf, Statelen, "%I!%d\n", c->laddr, c->lport);
                } else {
                        (*x->local)(c, buf, Statelen-2);
                }
                rv = readstr(offset, p, n, buf);
                } else {
                        (*x->local)(c, buf, Statelen-2);
                }
                rv = readstr(offset, p, n, buf);
-               free(buf);
+               kfree(buf);
                return rv;
        case Qstatus:
                return rv;
        case Qstatus:
-               buf = smalloc(Statelen);
+               buf = kzmalloc(Statelen, 0);
                x = f->p[PROTO(ch->qid)];
                c = x->conv[CONV(ch->qid)];
                (*x->state)(c, buf, Statelen-2);
                rv = readstr(offset, p, n, buf);
                x = f->p[PROTO(ch->qid)];
                c = x->conv[CONV(ch->qid)];
                (*x->state)(c, buf, Statelen-2);
                rv = readstr(offset, p, n, buf);
-               free(buf);
+               kfree(buf);
                return rv;
        case Qdata:
                c = f->p[PROTO(ch->qid)]->conv[CONV(ch->qid)];
                return rv;
        case Qdata:
                c = f->p[PROTO(ch->qid)]->conv[CONV(ch->qid)];
@@ -700,22 +709,22 @@ ipread(Chan *ch, void *a, long n, vlong off)
                return qread(c->sq, a, n);
        case Qstats:
                x = f->p[PROTO(ch->qid)];
                return qread(c->sq, a, n);
        case Qstats:
                x = f->p[PROTO(ch->qid)];
-               if(x->stats == nil)
+               if(x->stats == NULL)
                        error("stats not implemented");
                        error("stats not implemented");
-               buf = smalloc(Statelen);
+               buf = kzmalloc(Statelen, 0);
                (*x->stats)(x, buf, Statelen);
                rv = readstr(offset, p, n, buf);
                (*x->stats)(x, buf, Statelen);
                rv = readstr(offset, p, n, buf);
-               free(buf);
+               kfree(buf);
                return rv;
        }
 }
 
                return rv;
        }
 }
 
-static Block*
-ipbread(Chan* ch, long n, ulong offset)
+static struct block*
+ipbread(struct chan* ch, long n, uint32_t offset)
 {
 {
-       Conv *c;
-       Proto *x;
-       Fs *f;
+       struct conv *c;
+       struct Proto *x;
+       struct Fs *f;
 
        switch(TYPE(ch->qid)){
        case Qdata:
 
        switch(TYPE(ch->qid)){
        case Qdata:
@@ -732,7 +741,7 @@ ipbread(Chan* ch, long n, ulong offset)
  *  set local address to be that of the ifc closest to remote address
  */
 static void
  *  set local address to be that of the ifc closest to remote address
  */
 static void
-setladdr(Conv* c)
+setladdr(struct conv* c)
 {
        findlocalip(c->p->f, c->laddr, c->raddr);
 }
 {
        findlocalip(c->p->f, c->laddr, c->raddr);
 }
@@ -741,18 +750,18 @@ setladdr(Conv* c)
  *  set a local port making sure the quad of raddr,rport,laddr,lport is unique
  */
 static char*
  *  set a local port making sure the quad of raddr,rport,laddr,lport is unique
  */
 static char*
-setluniqueport(Conv* c, int lport)
+setluniqueport(struct conv* c, int lport)
 {
 {
-       Proto *p;
-       Conv *xp;
+       struct Proto *p;
+       struct conv *xp;
        int x;
 
        p = c->p;
 
        int x;
 
        p = c->p;
 
-       qlock(p);
+       qlock(&p->qlock);
        for(x = 0; x < p->nc; x++){
                xp = p->conv[x];
        for(x = 0; x < p->nc; x++){
                xp = p->conv[x];
-               if(xp == nil)
+               if(xp == NULL)
                        break;
                if(xp == c)
                        continue;
                        break;
                if(xp == c)
                        continue;
@@ -761,23 +770,23 @@ setluniqueport(Conv* c, int lport)
                && xp->rport == c->rport
                && ipcmp(xp->raddr, c->raddr) == 0
                && ipcmp(xp->laddr, c->laddr) == 0){
                && xp->rport == c->rport
                && ipcmp(xp->raddr, c->raddr) == 0
                && ipcmp(xp->laddr, c->laddr) == 0){
-                       qunlock(p);
+                       qunlock(&p->qlock);
                        return "address in use";
                }
        }
        c->lport = lport;
                        return "address in use";
                }
        }
        c->lport = lport;
-       qunlock(p);
-       return nil;
+       qunlock(&p->qlock);
+       return NULL;
 }
 
 /*
  *  pick a local port and set it
  */
 static void
 }
 
 /*
  *  pick a local port and set it
  */
 static void
-setlport(Conv* c)
+setlport(struct conv* c)
 {
 {
-       Proto *p;
-       ushort *pp;
+       struct Proto *p;
+       uint16_t *pp;
        int x, found;
 
        p = c->p;
        int x, found;
 
        p = c->p;
@@ -785,7 +794,7 @@ setlport(Conv* c)
                pp = &p->nextrport;
        else
                pp = &p->nextport;
                pp = &p->nextrport;
        else
                pp = &p->nextport;
-       qlock(p);
+       qlock(&p->qlock);
        for(;;(*pp)++){
                /*
                 * Fsproto initialises p->nextport to 0 and the restricted
        for(;;(*pp)++){
                /*
                 * Fsproto initialises p->nextport to 0 and the restricted
@@ -804,7 +813,7 @@ setlport(Conv* c)
 
                found = 0;
                for(x = 0; x < p->nc; x++){
 
                found = 0;
                for(x = 0; x < p->nc; x++){
-                       if(p->conv[x] == nil)
+                       if(p->conv[x] == NULL)
                                break;
                        if(p->conv[x]->lport == *pp){
                                found = 1;
                                break;
                        if(p->conv[x]->lport == *pp){
                                found = 1;
@@ -815,7 +824,7 @@ setlport(Conv* c)
                        break;
        }
        c->lport = (*pp)++;
                        break;
        }
        c->lport = (*pp)++;
-       qunlock(p);
+       qunlock(&p->qlock);
 }
 
 /*
 }
 
 /*
@@ -823,28 +832,28 @@ setlport(Conv* c)
  *     [address!]port[!r]
  */
 static char*
  *     [address!]port[!r]
  */
 static char*
-setladdrport(Conv* c, char* str, int announcing)
+setladdrport(struct conv* c, char* str, int announcing)
 {
        char *p;
        char *rv;
 {
        char *p;
        char *rv;
-       ushort lport;
-       uchar addr[IPaddrlen];
+       uint16_t lport;
+       uint8_t addr[IPaddrlen];
 
 
-       rv = nil;
+       rv = NULL;
 
        /*
         *  ignore restricted part if it exists.  it's
         *  meaningless on local ports.
         */
        p = strchr(str, '!');
 
        /*
         *  ignore restricted part if it exists.  it's
         *  meaningless on local ports.
         */
        p = strchr(str, '!');
-       if(p != nil){
+       if(p != NULL){
                *p++ = 0;
                if(strcmp(p, "r") == 0)
                *p++ = 0;
                if(strcmp(p, "r") == 0)
-                       p = nil;
+                       p = NULL;
        }
 
        c->lport = 0;
        }
 
        c->lport = 0;
-       if(p == nil){
+       if(p == NULL){
                if(announcing)
                        ipmove(c->laddr, IPnoaddr);
                else
                if(announcing)
                        ipmove(c->laddr, IPnoaddr);
                else
@@ -878,29 +887,29 @@ setladdrport(Conv* c, char* str, int announcing)
 }
 
 static char*
 }
 
 static char*
-setraddrport(Conv* c, char* str)
+setraddrport(struct conv* c, char* str)
 {
        char *p;
 
        p = strchr(str, '!');
 {
        char *p;
 
        p = strchr(str, '!');
-       if(p == nil)
+       if(p == NULL)
                return "malformed address";
        *p++ = 0;
        parseip(c->raddr, str);
        c->rport = atoi(p);
        p = strchr(p, '!');
        if(p){
                return "malformed address";
        *p++ = 0;
        parseip(c->raddr, str);
        c->rport = atoi(p);
        p = strchr(p, '!');
        if(p){
-               if(strstr(p, "!r") != nil)
+               if(strstr(p, "!r") != NULL)
                        c->restricted = 1;
        }
                        c->restricted = 1;
        }
-       return nil;
+       return NULL;
 }
 
 /*
  *  called by protocol connect routine to set addresses
  */
 char*
 }
 
 /*
  *  called by protocol connect routine to set addresses
  */
 char*
-Fsstdconnect(Conv *c, char *argv[], int argc)
+Fsstdconnect(struct conv *c, char *argv[], int argc)
 {
        char *p;
 
 {
        char *p;
 
@@ -909,17 +918,17 @@ Fsstdconnect(Conv *c, char *argv[], int argc)
                return "bad args to connect";
        case 2:
                p = setraddrport(c, argv[1]);
                return "bad args to connect";
        case 2:
                p = setraddrport(c, argv[1]);
-               if(p != nil)
+               if(p != NULL)
                        return p;
                setladdr(c);
                setlport(c);
                break;
        case 3:
                p = setraddrport(c, argv[1]);
                        return p;
                setladdr(c);
                setlport(c);
                break;
        case 3:
                p = setraddrport(c, argv[1]);
-               if(p != nil)
+               if(p != NULL)
                        return p;
                p = setladdrport(c, argv[2], 0);
                        return p;
                p = setladdrport(c, argv[2], 0);
-               if(p != nil)
+               if(p != NULL)
                        return p;
        }
 
                        return p;
        }
 
@@ -930,7 +939,7 @@ Fsstdconnect(Conv *c, char *argv[], int argc)
        else
                c->ipversion = V6;
 
        else
                c->ipversion = V6;
 
-       return nil;
+       return NULL;
 }
 /*
  *  initiate connection and sleep till its set up
 }
 /*
  *  initiate connection and sleep till its set up
@@ -938,30 +947,31 @@ Fsstdconnect(Conv *c, char *argv[], int argc)
 static int
 connected(void* a)
 {
 static int
 connected(void* a)
 {
-       return ((Conv*)a)->state == Connected;
+       return ((struct conv*)a)->state == Connected;
 }
 static void
 }
 static void
-connectctlmsg(Proto *x, Conv *c, Cmdbuf *cb)
+connectctlmsg(struct Proto *x, struct conv *c, struct cmdbuf *cb)
 {
 {
+       ERRSTACK(2);
        char *p;
 
        if(c->state != 0)
                error(Econinuse);
        c->state = Connecting;
        c->cerr[0] = '\0';
        char *p;
 
        if(c->state != 0)
                error(Econinuse);
        c->state = Connecting;
        c->cerr[0] = '\0';
-       if(x->connect == nil)
+       if(x->connect == NULL)
                error("connect not supported");
        p = x->connect(c, cb->f, cb->nf);
                error("connect not supported");
        p = x->connect(c, cb->f, cb->nf);
-       if(p != nil)
+       if(p != NULL)
                error(p);
 
                error(p);
 
-       qunlock(c);
+       qunlock(&c->qlock);
        if(waserror()){
        if(waserror()){
-               qlock(c);
+               qlock(&c->qlock);
                nexterror();
        }
        sleep(&c->cr, connected, c);
                nexterror();
        }
        sleep(&c->cr, connected, c);
-       qlock(c);
+       qlock(&c->qlock);
        poperror();
 
        if(c->cerr[0] != '\0')
        poperror();
 
        if(c->cerr[0] != '\0')
@@ -972,7 +982,7 @@ connectctlmsg(Proto *x, Conv *c, Cmdbuf *cb)
  *  called by protocol announce routine to set addresses
  */
 char*
  *  called by protocol announce routine to set addresses
  */
 char*
-Fsstdannounce(Conv* c, char* argv[], int argc)
+Fsstdannounce(struct conv* c, char* argv[], int argc)
 {
        memset(c->raddr, 0, sizeof(c->raddr));
        c->rport = 0;
 {
        memset(c->raddr, 0, sizeof(c->raddr));
        c->rport = 0;
@@ -990,30 +1000,31 @@ Fsstdannounce(Conv* c, char* argv[], int argc)
 static int
 announced(void* a)
 {
 static int
 announced(void* a)
 {
-       return ((Conv*)a)->state == Announced;
+       return ((struct conv*)a)->state == Announced;
 }
 static void
 }
 static void
-announcectlmsg(Proto *x, Conv *c, Cmdbuf *cb)
+announcectlmsg(struct Proto *x, struct conv *c, struct cmdbuf *cb)
 {
 {
+       ERRSTACK(2);
        char *p;
 
        if(c->state != 0)
                error(Econinuse);
        c->state = Announcing;
        c->cerr[0] = '\0';
        char *p;
 
        if(c->state != 0)
                error(Econinuse);
        c->state = Announcing;
        c->cerr[0] = '\0';
-       if(x->announce == nil)
+       if(x->announce == NULL)
                error("announce not supported");
        p = x->announce(c, cb->f, cb->nf);
                error("announce not supported");
        p = x->announce(c, cb->f, cb->nf);
-       if(p != nil)
+       if(p != NULL)
                error(p);
 
                error(p);
 
-       qunlock(c);
+       qunlock(&c->qlock);
        if(waserror()){
        if(waserror()){
-               qlock(c);
+               qlock(&c->qlock);
                nexterror();
        }
        sleep(&c->cr, announced, c);
                nexterror();
        }
        sleep(&c->cr, announced, c);
-       qlock(c);
+       qlock(&c->qlock);
        poperror();
 
        if(c->cerr[0] != '\0')
        poperror();
 
        if(c->cerr[0] != '\0')
@@ -1024,7 +1035,7 @@ announcectlmsg(Proto *x, Conv *c, Cmdbuf *cb)
  *  called by protocol bind routine to set addresses
  */
 char*
  *  called by protocol bind routine to set addresses
  */
 char*
-Fsstdbind(Conv* c, char* argv[], int argc)
+Fsstdbind(struct conv* c, char* argv[], int argc)
 {
        switch(argc){
        default:
 {
        switch(argc){
        default:
@@ -1035,20 +1046,20 @@ Fsstdbind(Conv* c, char* argv[], int argc)
 }
 
 static void
 }
 
 static void
-bindctlmsg(Proto *x, Conv *c, Cmdbuf *cb)
+bindctlmsg(struct Proto *x, struct conv *c, struct cmdbuf *cb)
 {
        char *p;
 
 {
        char *p;
 
-       if(x->bind == nil)
+       if(x->bind == NULL)
                p = Fsstdbind(c, cb->f, cb->nf);
        else
                p = x->bind(c, cb->f, cb->nf);
                p = Fsstdbind(c, cb->f, cb->nf);
        else
                p = x->bind(c, cb->f, cb->nf);
-       if(p != nil)
+       if(p != NULL)
                error(p);
 }
 
 static void
                error(p);
 }
 
 static void
-tosctlmsg(Conv *c, Cmdbuf *cb)
+tosctlmsg(struct conv *c, struct cmdbuf *cb)
 {
        if(cb->nf < 2)
                c->tos = 0;
 {
        if(cb->nf < 2)
                c->tos = 0;
@@ -1057,7 +1068,7 @@ tosctlmsg(Conv *c, Cmdbuf *cb)
 }
 
 static void
 }
 
 static void
-ttlctlmsg(Conv *c, Cmdbuf *cb)
+ttlctlmsg(struct conv *c, struct cmdbuf *cb)
 {
        if(cb->nf < 2)
                c->ttl = MAXTTL;
 {
        if(cb->nf < 2)
                c->ttl = MAXTTL;
@@ -1066,14 +1077,15 @@ ttlctlmsg(Conv *c, Cmdbuf *cb)
 }
 
 static long
 }
 
 static long
-ipwrite(Chan* ch, void *v, long n, vlong off)
+ipwrite(struct chan* ch, void *v, long n, int64_t off)
 {
 {
-       Conv *c;
-       Proto *x;
+       ERRSTACK(2);
+       struct conv *c;
+       struct Proto *x;
        char *p;
        char *p;
-       Cmdbuf *cb;
-       uchar ia[IPaddrlen], ma[IPaddrlen];
-       Fs *f;
+       struct cmdbuf *cb;
+       uint8_t ia[IPaddrlen], ma[IPaddrlen];
+       struct Fs *f;
        char *a;
 
        a = v;
        char *a;
 
        a = v;
@@ -1086,7 +1098,7 @@ ipwrite(Chan* ch, void *v, long n, vlong off)
                x = f->p[PROTO(ch->qid)];
                c = x->conv[CONV(ch->qid)];
 
                x = f->p[PROTO(ch->qid)];
                c = x->conv[CONV(ch->qid)];
 
-               if(c->wq == nil)
+               if(c->wq == NULL)
                        error(Eperm);
 
                qwrite(c->wq, a, n);
                        error(Eperm);
 
                qwrite(c->wq, a, n);
@@ -1105,10 +1117,10 @@ ipwrite(Chan* ch, void *v, long n, vlong off)
                c = x->conv[CONV(ch->qid)];
                cb = parsecmd(a, n);
 
                c = x->conv[CONV(ch->qid)];
                cb = parsecmd(a, n);
 
-               qlock(c);
+               qlock(&c->qlock);
                if(waserror()) {
                if(waserror()) {
-                       qunlock(c);
-                       free(cb);
+                       qunlock(&c->qlock);
+                       kfree(cb);
                        nexterror();
                }
                if(cb->nf < 1)
                        nexterror();
                }
                if(cb->nf < 1)
@@ -1147,25 +1159,25 @@ ipwrite(Chan* ch, void *v, long n, vlong off)
                                error("remmulti for a non multicast address");
                        parseip(ia, cb->f[1]);
                        ipifcremmulti(c, c->raddr, ia);
                                error("remmulti for a non multicast address");
                        parseip(ia, cb->f[1]);
                        ipifcremmulti(c, c->raddr, ia);
-               } else if(x->ctl != nil) {
+               } else if(x->ctl != NULL) {
                        p = x->ctl(c, cb->f, cb->nf);
                        p = x->ctl(c, cb->f, cb->nf);
-                       if(p != nil)
+                       if(p != NULL)
                                error(p);
                } else
                        error("unknown control request");
                                error(p);
                } else
                        error("unknown control request");
-               qunlock(c);
-               free(cb);
+               qunlock(&c->qlock);
+               kfree(cb);
                poperror();
        }
        return n;
 }
 
 static long
                poperror();
        }
        return n;
 }
 
 static long
-ipbwrite(Chan* ch, Block* bp, ulong offset)
+ipbwrite(struct chan* ch, struct block* bp, uint32_t offset)
 {
 {
-       Conv *c;
-       Proto *x;
-       Fs *f;
+       struct conv *c;
+       struct Proto *x;
+       struct Fs *f;
        int n;
 
        switch(TYPE(ch->qid)){
        int n;
 
        switch(TYPE(ch->qid)){
@@ -1174,7 +1186,7 @@ ipbwrite(Chan* ch, Block* bp, ulong offset)
                x = f->p[PROTO(ch->qid)];
                c = x->conv[CONV(ch->qid)];
 
                x = f->p[PROTO(ch->qid)];
                c = x->conv[CONV(ch->qid)];
 
-               if(c->wq == nil)
+               if(c->wq == NULL)
                        error(Eperm);
 
                if(bp->next)
                        error(Eperm);
 
                if(bp->next)
@@ -1187,7 +1199,7 @@ ipbwrite(Chan* ch, Block* bp, ulong offset)
        }
 }
 
        }
 }
 
-Dev ipdevtab = {
+struct dev ipdevtab = {
        'I',
        "ip",
 
        'I',
        "ip",
 
@@ -1209,7 +1221,7 @@ Dev ipdevtab = {
 };
 
 int
 };
 
 int
-Fsproto(Fs *f, Proto *p)
+Fsproto(struct Fs *f, struct Proto *p)
 {
        if(f->np >= Maxproto)
                return -1;
 {
        if(f->np >= Maxproto)
                return -1;
@@ -1217,15 +1229,15 @@ Fsproto(Fs *f, Proto *p)
        p->f = f;
 
        if(p->ipproto > 0){
        p->f = f;
 
        if(p->ipproto > 0){
-               if(f->t2p[p->ipproto] != nil)
+               if(f->t2p[p->ipproto] != NULL)
                        return -1;
                f->t2p[p->ipproto] = p;
        }
 
        p->qid.type = QTDIR;
        p->qid.path = QID(f->np, 0, Qprotodir);
                        return -1;
                f->t2p[p->ipproto] = p;
        }
 
        p->qid.type = QTDIR;
        p->qid.path = QID(f->np, 0, Qprotodir);
-       p->conv = malloc(sizeof(Conv*)*(p->nc+1));
-       if(p->conv == nil)
+       p->conv = kzmalloc(sizeof(struct conv *) * (p->nc + 1), 0);
+       if(p->conv == NULL)
                panic("Fsproto");
 
        p->x = f->np;
                panic("Fsproto");
 
        p->x = f->np;
@@ -1241,35 +1253,35 @@ Fsproto(Fs *f, Proto *p)
  *  built in
  */
 int
  *  built in
  */
 int
-Fsbuiltinproto(Fs* f, uchar proto)
+Fsbuiltinproto(struct Fs* f, uint8_t proto)
 {
 {
-       return f->t2p[proto] != nil;
+       return f->t2p[proto] != NULL;
 }
 
 /*
  *  called with protocol locked
  */
 }
 
 /*
  *  called with protocol locked
  */
-Conv*
-Fsprotoclone(Proto *p, char *user)
+struct conv*
+Fsprotoclone(struct Proto *p, char *user)
 {
 {
-       Conv *c, **pp, **ep;
+       struct conv *c, **pp, **ep;
 
 retry:
 
 retry:
-       c = nil;
+       c = NULL;
        ep = &p->conv[p->nc];
        for(pp = p->conv; pp < ep; pp++) {
                c = *pp;
        ep = &p->conv[p->nc];
        for(pp = p->conv; pp < ep; pp++) {
                c = *pp;
-               if(c == nil){
-                       c = malloc(sizeof(Conv));
-                       if(c == nil)
+               if(c == NULL){
+                       c = kzmalloc(sizeof(struct conv), 0);
+                       if(c == NULL)
                                error(Enomem);
                                error(Enomem);
-                       qlock(c);
+                       qlock(&c->qlock);
                        c->p = p;
                        c->x = pp - p->conv;
                        if(p->ptclsize != 0){
                        c->p = p;
                        c->x = pp - p->conv;
                        if(p->ptclsize != 0){
-                               c->ptcl = malloc(p->ptclsize);
-                               if(c->ptcl == nil) {
-                                       free(c);
+                               c->ptcl = kzmalloc(p->ptclsize, 0);
+                               if(c->ptcl == NULL) {
+                                       kfree(c);
                                        error(Enomem);
                                }
                        }
                                        error(Enomem);
                                }
                        }
@@ -1279,21 +1291,21 @@ retry:
                        (*p->create)(c);
                        break;
                }
                        (*p->create)(c);
                        break;
                }
-               if(canqlock(c)){
+               if(canqlock(&c->qlock)){
                        /*
                         *  make sure both processes and protocol
                         *  are done with this Conv
                         */
                        /*
                         *  make sure both processes and protocol
                         *  are done with this Conv
                         */
-                       if(c->inuse == 0 && (p->inuse == nil || (*p->inuse)(c) == 0))
+                       if(c->inuse == 0 && (p->inuse == NULL || (*p->inuse)(c) == 0))
                                break;
 
                                break;
 
-                       qunlock(c);
+                       qunlock(&c->qlock);
                }
        }
        if(pp >= ep) {
                }
        }
        if(pp >= ep) {
-               if(p->gc != nil && (*p->gc)(p))
+               if(p->gc != NULL && (*p->gc)(p))
                        goto retry;
                        goto retry;
-               return nil;
+               return NULL;
        }
 
        c->inuse = 1;
        }
 
        c->inuse = 1;
@@ -1302,7 +1314,7 @@ retry:
        c->state = Idle;
        ipmove(c->laddr, IPnoaddr);
        ipmove(c->raddr, IPnoaddr);
        c->state = Idle;
        ipmove(c->laddr, IPnoaddr);
        ipmove(c->raddr, IPnoaddr);
-       c->r = nil;
+       c->r = NULL;
        c->rgen = 0;
        c->lport = 0;
        c->rport = 0;
        c->rgen = 0;
        c->lport = 0;
        c->rport = 0;
@@ -1313,15 +1325,15 @@ retry:
        qreopen(c->wq);
        qreopen(c->eq);
 
        qreopen(c->wq);
        qreopen(c->eq);
 
-       qunlock(c);
+       qunlock(&c->qlock);
        return c;
 }
 
 int
        return c;
 }
 
 int
-Fsconnected(Conv* c, char* msg)
+Fsconnected(struct conv* c, char* msg)
 {
 {
-       if(msg != nil && *msg != '\0')
-               kstrcpy(c->cerr, msg, sizeof(c->cerr));
+       if(msg != NULL && *msg != '\0')
+               strncpy(c->cerr, msg, sizeof(c->cerr));
 
        switch(c->state){
 
 
        switch(c->state){
 
@@ -1338,8 +1350,8 @@ Fsconnected(Conv* c, char* msg)
        return 0;
 }
 
        return 0;
 }
 
-Proto*
-Fsrcvpcol(Fs* f, uchar proto)
+struct Proto*
+Fsrcvpcol(struct Fs* f, uint8_t proto)
 {
        if(f->ipmux)
                return f->ipmux;
 {
        if(f->ipmux)
                return f->ipmux;
@@ -1347,8 +1359,8 @@ Fsrcvpcol(Fs* f, uchar proto)
                return f->t2p[proto];
 }
 
                return f->t2p[proto];
 }
 
-Proto*
-Fsrcvpcolx(Fs *f, uchar proto)
+struct Proto*
+Fsrcvpcolx(struct Fs *f, uint8_t proto)
 {
        return f->t2p[proto];
 }
 {
        return f->t2p[proto];
 }
@@ -1356,38 +1368,39 @@ Fsrcvpcolx(Fs *f, uchar proto)
 /*
  *  called with protocol locked
  */
 /*
  *  called with protocol locked
  */
-Conv*
-Fsnewcall(Conv *c, uchar *raddr, ushort rport, uchar *laddr, ushort lport, uchar version)
+struct conv*
+Fsnewcall(struct conv *c, uint8_t *raddr, uint16_t rport, uint8_t *laddr,
+         uint16_t lport, uint8_t version)
 {
 {
-       Conv *nc;
-       Conv **l;
+       struct conv *nc;
+       struct conv **l;
        int i;
 
        int i;
 
-       qlock(c);
+       qlock(&c->qlock);
        i = 0;
        for(l = &c->incall; *l; l = &(*l)->next)
                i++;
        if(i >= Maxincall) {
        i = 0;
        for(l = &c->incall; *l; l = &(*l)->next)
                i++;
        if(i >= Maxincall) {
-               qunlock(c);
-               return nil;
+               qunlock(&c->qlock);
+               return NULL;
        }
 
        /* find a free conversation */
        nc = Fsprotoclone(c->p, network);
        }
 
        /* find a free conversation */
        nc = Fsprotoclone(c->p, network);
-       if(nc == nil) {
-               qunlock(c);
-               return nil;
+       if(nc == NULL) {
+               qunlock(&c->qlock);
+               return NULL;
        }
        ipmove(nc->raddr, raddr);
        nc->rport = rport;
        ipmove(nc->laddr, laddr);
        nc->lport = lport;
        }
        ipmove(nc->raddr, raddr);
        nc->rport = rport;
        ipmove(nc->laddr, laddr);
        nc->lport = lport;
-       nc->next = nil;
+       nc->next = NULL;
        *l = nc;
        nc->state = Connected;
        nc->ipversion = version;
 
        *l = nc;
        nc->state = Connected;
        nc->ipversion = version;
 
-       qunlock(c);
+       qunlock(&c->qlock);
 
        wakeup(&c->listenr);
 
 
        wakeup(&c->listenr);
 
@@ -1395,7 +1408,7 @@ Fsnewcall(Conv *c, uchar *raddr, ushort rport, uchar *laddr, ushort lport, uchar
 }
 
 static long
 }
 
 static long
-ndbwrite(Fs *f, char *a, ulong off, int n)
+ndbwrite(struct Fs *f, char *a, uint32_t off, int n)
 {
        if(off > strlen(f->ndb))
                error(Eio);
 {
        if(off > strlen(f->ndb))
                error(Eio);
@@ -1408,10 +1421,10 @@ ndbwrite(Fs *f, char *a, ulong off, int n)
        return n;
 }
 
        return n;
 }
 
-ulong
+uint32_t
 scalednconv(void)
 {
 scalednconv(void)
 {
-       if(conf.npage*BY2PG >= 128*MB)
+       //if(conf.npage*BY2PG >= 128*MB)
                return Nchans*4;
                return Nchans*4;
-       return Nchans;
+               //      return Nchans;
 }
 }
index 1877817..5164fca 100644 (file)
@@ -1,47 +1,53 @@
-#include "u.h"
-#include "../port/lib.h"
-#include "mem.h"
-#include "dat.h"
-#include "fns.h"
-#include "../port/error.h"
-
-#include "ip.h"
-#include "ipv6.h"
-#include "kernel.h"
+// INFERNO
+#include <vfs.h>
+#include <kfs.h>
+#include <slab.h>
+#include <kmalloc.h>
+#include <kref.h>
+#include <string.h>
+#include <stdio.h>
+#include <assert.h>
+#include <error.h>
+#include <cpio.h>
+#include <pmap.h>
+#include <smp.h>
+#include <ip.h>
 
 typedef struct Etherhdr Etherhdr;
 struct Etherhdr
 {
 
 typedef struct Etherhdr Etherhdr;
 struct Etherhdr
 {
-       uchar   d[6];
-       uchar   s[6];
-       uchar   t[2];
+       uint8_t d[6];
+       uint8_t s[6];
+       uint8_t t[2];
 };
 
 };
 
-static uchar ipbroadcast[IPaddrlen] = {
+static uint8_t ipbroadcast[IPaddrlen] = {
        0xff,0xff,0xff,0xff,  
        0xff,0xff,0xff,0xff,  
        0xff,0xff,0xff,0xff,  
        0xff,0xff,0xff,0xff,
 };
 
        0xff,0xff,0xff,0xff,  
        0xff,0xff,0xff,0xff,  
        0xff,0xff,0xff,0xff,  
        0xff,0xff,0xff,0xff,
 };
 
-static uchar etherbroadcast[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
+static uint8_t etherbroadcast[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
 
 static void    etherread4(void *a);
 static void    etherread6(void *a);
 
 static void    etherread4(void *a);
 static void    etherread6(void *a);
-static void    etherbind(Ipifc *ifc, int argc, char **argv);
-static void    etherunbind(Ipifc *ifc);
-static void    etherbwrite(Ipifc *ifc, Block *bp, int version, uchar *ip);
-static void    etheraddmulti(Ipifc *ifc, uchar *a, uchar *ia);
-static void    etherremmulti(Ipifc *ifc, uchar *a, uchar *ia);
-static Block*  multicastarp(Fs *f, Arpent *a, Medium*, uchar *mac);
-static void    sendarp(Ipifc *ifc, Arpent *a);
-static void    sendgarp(Ipifc *ifc, uchar*);
-static int     multicastea(uchar *ea, uchar *ip);
+static void    etherbind(struct Ipifc *ifc, int argc, char **argv);
+static void    etherunbind(struct Ipifc *ifc);
+static void    etherbwrite(struct Ipifc *ifc, struct block *bp, int version,
+                              uint8_t *ip);
+static void    etheraddmulti(struct Ipifc *ifc, uint8_t *a, uint8_t *ia);
+static void    etherremmulti(struct Ipifc *ifc, uint8_t *a, uint8_t *ia);
+static struct block*   multicastarp(struct Fs *f, struct arpent *a,
+                                 struct medium*, uint8_t *mac);
+static void    sendarp(struct Ipifc *ifc, struct arpent *a);
+static void    sendgarp(struct Ipifc *ifc, uint8_t *unused_uint8_p_t);
+static int     multicastea(uint8_t *ea, uint8_t *ip);
 static void    recvarpproc(void*);
 static void    recvarpproc(void*);
-static void    resolveaddr6(Ipifc *ifc, Arpent *a);
-static void    etherpref2addr(uchar *pref, uchar *ea);
+static void    resolveaddr6(struct Ipifc *ifc, struct arpent *a);
+static void    etherpref2addr(uint8_t *pref, uint8_t *ea);
 
 
-Medium ethermedium =
+struct medium ethermedium =
 {
 .name=         "ether",
 .hsize=                14,
 {
 .name=         "ether",
 .hsize=                14,
@@ -58,7 +64,7 @@ Medium ethermedium =
 .pref2addr=    etherpref2addr,
 };
 
 .pref2addr=    etherpref2addr,
 };
 
-Medium gbemedium =
+struct medium gbemedium =
 {
 .name=         "gbe",
 .hsize=                14,
 {
 .name=         "gbe",
 .hsize=                14,
@@ -78,15 +84,15 @@ Medium gbemedium =
 typedef struct Etherrock Etherrock;
 struct Etherrock
 {
 typedef struct Etherrock Etherrock;
 struct Etherrock
 {
-       Fs      *f;             /* file system we belong to */
-       Proc    *arpp;          /* arp process */
-       Proc    *read4p;        /* reading process (v4)*/
-       Proc    *read6p;        /* reading process (v6)*/
-       Chan    *mchan4;        /* Data channel for v4 */
-       Chan    *achan;         /* Arp channel */
-       Chan    *cchan4;        /* Control channel for v4 */
-       Chan    *mchan6;        /* Data channel for v6 */
-       Chan    *cchan6;        /* Control channel for v6 */
+       struct Fs       *f;             /* file system we belong to */
+       struct proc     *arpp;          /* arp process */
+       struct proc     *read4p;        /* reading process (v4)*/
+       struct proc     *read6p;        /* reading process (v6)*/
+       struct chan     *mchan4;        /* Data channel for v4 */
+       struct chan     *achan;         /* Arp channel */
+       struct chan     *cchan4;        /* Control channel for v4 */
+       struct chan     *mchan6;        /* Data channel for v6 */
+       struct chan     *cchan6;        /* Control channel for v6 */
 };
 
 /*
 };
 
 /*
@@ -104,18 +110,18 @@ enum
 typedef struct Etherarp Etherarp;
 struct Etherarp
 {
 typedef struct Etherarp Etherarp;
 struct Etherarp
 {
-       uchar   d[6];
-       uchar   s[6];
-       uchar   type[2];
-       uchar   hrd[2];
-       uchar   pro[2];
-       uchar   hln;
-       uchar   pln;
-       uchar   op[2];
-       uchar   sha[6];
-       uchar   spa[4];
-       uchar   tha[6];
-       uchar   tpa[4];
+       uint8_t d[6];
+       uint8_t s[6];
+       uint8_t type[2];
+       uint8_t hrd[2];
+       uint8_t pro[2];
+       uint8_t hln;
+       uint8_t pln;
+       uint8_t op[2];
+       uint8_t sha[6];
+       uint8_t spa[4];
+       uint8_t tha[6];
+       uint8_t tpa[4];
 };
 
 static char *nbmsg = "nonblocking";
 };
 
 static char *nbmsg = "nonblocking";
@@ -125,9 +131,10 @@ static char *nbmsg = "nonblocking";
  *  called with ifc wlock'd
  */
 static void
  *  called with ifc wlock'd
  */
 static void
-etherbind(Ipifc *ifc, int argc, char **argv)
+etherbind(struct Ipifc *ifc, int argc, char **argv)
 {
 {
-       Chan *mchan4, *cchan4, *achan, *mchan6, *cchan6;
+       ERRSTACK(2);
+       struct chan *mchan4, *cchan4, *achan, *mchan6, *cchan6;
        char addr[Maxpath];     //char addr[2*KNAMELEN];
        char dir[Maxpath];      //char dir[2*KNAMELEN];
        char *buf;
        char addr[Maxpath];     //char addr[2*KNAMELEN];
        char dir[Maxpath];      //char dir[2*KNAMELEN];
        char *buf;
@@ -138,21 +145,21 @@ etherbind(Ipifc *ifc, int argc, char **argv)
        if(argc < 2)
                error(Ebadarg);
 
        if(argc < 2)
                error(Ebadarg);
 
-       mchan4 = cchan4 = achan = mchan6 = cchan6 = nil;
-       buf = nil;
+       mchan4 = cchan4 = achan = mchan6 = cchan6 = NULL;
+       buf = NULL;
        if(waserror()){
        if(waserror()){
-               if(mchan4 != nil)
+               if(mchan4 != NULL)
                        cclose(mchan4);
                        cclose(mchan4);
-               if(cchan4 != nil)
+               if(cchan4 != NULL)
                        cclose(cchan4);
                        cclose(cchan4);
-               if(achan != nil)
+               if(achan != NULL)
                        cclose(achan);
                        cclose(achan);
-               if(mchan6 != nil)
+               if(mchan6 != NULL)
                        cclose(mchan6);
                        cclose(mchan6);
-               if(cchan6 != nil)
+               if(cchan6 != NULL)
                        cclose(cchan6);
                        cclose(cchan6);
-               if(buf != nil)
-                       free(buf);
+               if(buf != NULL)
+                       kfree(buf);
                nexterror(); 
        }
 
                nexterror(); 
        }
 
@@ -162,14 +169,14 @@ etherbind(Ipifc *ifc, int argc, char **argv)
         *  the dial will fail if the type is already open on
         *  this device.
         */
         *  the dial will fail if the type is already open on
         *  this device.
         */
-       snprint(addr, sizeof(addr), "%s!0x800", argv[2]);
-       fd = kdial(addr, nil, dir, &cfd);
+       snprintf(addr, sizeof(addr), "%s!0x800", argv[2]);
+       fd = kdial(addr, NULL, dir, &cfd);
        if(fd < 0)
        if(fd < 0)
-               errorf("dial 0x800 failed: %s", up->env->errstr);
+               errorf("dial 0x800 failed: %s", get_cur_errbuf());
        mchan4 = commonfdtochan(fd, ORDWR, 0, 1);
        cchan4 = commonfdtochan(cfd, ORDWR, 0, 1);
        mchan4 = commonfdtochan(fd, ORDWR, 0, 1);
        cchan4 = commonfdtochan(cfd, ORDWR, 0, 1);
-       kclose(fd);
-       kclose(cfd);
+       sysclose(fd);
+       sysclose(cfd);
 
        /*
         *  make it non-blocking
 
        /*
         *  make it non-blocking
@@ -179,14 +186,14 @@ etherbind(Ipifc *ifc, int argc, char **argv)
        /*
         *  get mac address and speed
         */
        /*
         *  get mac address and speed
         */
-       snprint(addr, sizeof(addr), "%s/stats", dir);
-       fd = kopen(addr, OREAD);
+       snprintf(addr, sizeof(addr), "%s/stats", dir);
+       fd = sysopen(addr, OREAD);
        if(fd < 0)
        if(fd < 0)
-               errorf("can't open ether stats: %s", up->env->errstr);
+               errorf("can't open ether stats: %s", get_cur_errbuf());
 
 
-       buf = smalloc(512);
-       n = kread(fd, buf, 511);
-       kclose(fd);
+       buf = kzmalloc(512, 0);
+       n = sysread(fd, buf, 511, 0ULL);
+       sysclose(fd);
        if(n <= 0)
                error(Eio);
        buf[n] = 0;
        if(n <= 0)
                error(Eio);
        buf[n] = 0;
@@ -207,12 +214,12 @@ etherbind(Ipifc *ifc, int argc, char **argv)
        /*
         *  open arp conversation
         */
        /*
         *  open arp conversation
         */
-       snprint(addr, sizeof(addr), "%s!0x806", argv[2]);
-       fd = kdial(addr, nil, nil, nil);
+       snprintf(addr, sizeof(addr), "%s!0x806", argv[2]);
+       fd = kdial(addr, NULL, NULL, NULL);
        if(fd < 0)
        if(fd < 0)
-               errorf("dial 0x806 failed: %s", up->env->errstr);
+               error("dial 0x806 failed: %s", get_cur_errbuf());
        achan = commonfdtochan(fd, ORDWR, 0, 1);
        achan = commonfdtochan(fd, ORDWR, 0, 1);
-       kclose(fd);
+       sysclose(fd);
 
        /*
         *  open ip conversation
 
        /*
         *  open ip conversation
@@ -220,21 +227,21 @@ etherbind(Ipifc *ifc, int argc, char **argv)
         *  the dial will fail if the type is already open on
         *  this device.
         */
         *  the dial will fail if the type is already open on
         *  this device.
         */
-       snprint(addr, sizeof(addr), "%s!0x86DD", argv[2]);
-       fd = kdial(addr, nil, dir, &cfd);
+       snprintf(addr, sizeof(addr), "%s!0x86DD", argv[2]);
+       fd = kdial(addr, NULL, dir, &cfd);
        if(fd < 0)
        if(fd < 0)
-               errorf("dial 0x86DD failed: %s", up->env->errstr);
+               error("dial 0x86DD failed: %s", get_cur_errbuf());
        mchan6 = commonfdtochan(fd, ORDWR, 0, 1);
        cchan6 = commonfdtochan(cfd, ORDWR, 0, 1);
        mchan6 = commonfdtochan(fd, ORDWR, 0, 1);
        cchan6 = commonfdtochan(cfd, ORDWR, 0, 1);
-       kclose(fd);
-       kclose(cfd);
+       sysclose(fd);
+       sysclose(cfd);
 
        /*
         *  make it non-blocking
         */
        devtab[cchan6->type]->write(cchan6, nbmsg, strlen(nbmsg), 0);
 
 
        /*
         *  make it non-blocking
         */
        devtab[cchan6->type]->write(cchan6, nbmsg, strlen(nbmsg), 0);
 
-       er = smalloc(sizeof(*er));
+       er = kzmalloc(sizeof(*er), 0);
        er->mchan4 = mchan4;
        er->cchan4 = cchan4;
        er->achan = achan;
        er->mchan4 = mchan4;
        er->cchan4 = cchan4;
        er->achan = achan;
@@ -243,7 +250,7 @@ etherbind(Ipifc *ifc, int argc, char **argv)
        er->f = ifc->conv->p->f;
        ifc->arg = er;
 
        er->f = ifc->conv->p->f;
        ifc->arg = er;
 
-       free(buf);
+       kfree(buf);
        poperror();
 
        kproc("etherread4", etherread4, ifc, 0);
        poperror();
 
        kproc("etherread4", etherread4, ifc, 0);
@@ -255,44 +262,48 @@ etherbind(Ipifc *ifc, int argc, char **argv)
  *  called with ifc wlock'd
  */
 static void
  *  called with ifc wlock'd
  */
 static void
-etherunbind(Ipifc *ifc)
+etherunbind(struct Ipifc *ifc)
 {
        Etherrock *er = ifc->arg;
 {
        Etherrock *er = ifc->arg;
-
+#warning "postnote"
+#if 0
        if(er->read4p)
                postnote(er->read4p, 1, "unbind", 0);
        if(er->read6p)
                postnote(er->read6p, 1, "unbind", 0);
        if(er->arpp)
                postnote(er->arpp, 1, "unbind", 0);
        if(er->read4p)
                postnote(er->read4p, 1, "unbind", 0);
        if(er->read6p)
                postnote(er->read6p, 1, "unbind", 0);
        if(er->arpp)
                postnote(er->arpp, 1, "unbind", 0);
+#endif
 
        /* wait for readers to die */
        while(er->arpp != 0 || er->read4p != 0 || er->read6p != 0)
 
        /* wait for readers to die */
        while(er->arpp != 0 || er->read4p != 0 || er->read6p != 0)
-               tsleep(&up->sleep, return0, 0, 300);
+               ;
+#warning tsleep
+       //      tsleep(&up->sleep, return0, 0, 300);
 
 
-       if(er->mchan4 != nil)
+       if(er->mchan4 != NULL)
                cclose(er->mchan4);
                cclose(er->mchan4);
-       if(er->achan != nil)
+       if(er->achan != NULL)
                cclose(er->achan);
                cclose(er->achan);
-       if(er->cchan4 != nil)
+       if(er->cchan4 != NULL)
                cclose(er->cchan4);
                cclose(er->cchan4);
-       if(er->mchan6 != nil)
+       if(er->mchan6 != NULL)
                cclose(er->mchan6);
                cclose(er->mchan6);
-       if(er->cchan6 != nil)
+       if(er->cchan6 != NULL)
                cclose(er->cchan6);
 
                cclose(er->cchan6);
 
-       free(er);
+       kfree(er);
 }
 
 /*
  *  called by ipoput with a single block to write with ifc rlock'd
  */
 static void
 }
 
 /*
  *  called by ipoput with a single block to write with ifc rlock'd
  */
 static void
-etherbwrite(Ipifc *ifc, Block *bp, int version, uchar *ip)
+etherbwrite(struct Ipifc *ifc, struct block *bp, int version, uint8_t *ip)
 {
        Etherhdr *eh;
 {
        Etherhdr *eh;
-       Arpent *a;
-       uchar mac[6];
+       struct arpent *a;
+       uint8_t mac[6];
        Etherrock *er = ifc->arg;
 
        /* get mac address of destination */
        Etherrock *er = ifc->arg;
 
        /* get mac address of destination */
@@ -300,7 +311,7 @@ etherbwrite(Ipifc *ifc, Block *bp, int version, uchar *ip)
        if(a){
                /* check for broadcast or multicast */
                bp = multicastarp(er->f, a, ifc->m, mac);
        if(a){
                /* check for broadcast or multicast */
                bp = multicastarp(er->f, a, ifc->m, mac);
-               if(bp==nil){
+               if(bp==NULL){
                        switch(version){
                        case V4:
                                sendarp(ifc, a);
                        switch(version){
                        case V4:
                                sendarp(ifc, a);
@@ -351,34 +362,36 @@ etherbwrite(Ipifc *ifc, Block *bp, int version, uchar *ip)
 static void
 etherread4(void *a)
 {
 static void
 etherread4(void *a)
 {
-       Ipifc *ifc;
-       Block *bp;
+       ERRSTACK(2);
+       struct Ipifc *ifc;
+       struct block *bp;
        Etherrock *er;
 
        ifc = a;
        er = ifc->arg;
        Etherrock *er;
 
        ifc = a;
        er = ifc->arg;
-       er->read4p = up;        /* hide identity under a rock for unbind */
+       er->read4p = current;   /* hide identity under a rock for unbind */
        if(waserror()){
                er->read4p = 0;
        if(waserror()){
                er->read4p = 0;
-               pexit("hangup", 1);
+#warning "pexit"
+               //      pexit("hangup", 1);
        }
        for(;;){
                bp = devtab[er->mchan4->type]->bread(er->mchan4, ifc->maxtu, 0);
        }
        for(;;){
                bp = devtab[er->mchan4->type]->bread(er->mchan4, ifc->maxtu, 0);
-               if(!canrlock(ifc)){
+               if(!canrlock(&ifc->rwlock)){
                        freeb(bp);
                        continue;
                }
                if(waserror()){
                        freeb(bp);
                        continue;
                }
                if(waserror()){
-                       runlock(ifc);
+                       runlock(&ifc->rwlock);
                        nexterror();
                }
                ifc->in++;
                bp->rp += ifc->m->hsize;
                        nexterror();
                }
                ifc->in++;
                bp->rp += ifc->m->hsize;
-               if(ifc->lifc == nil)
+               if(ifc->lifc == NULL)
                        freeb(bp);
                else
                        ipiput4(er->f, ifc, bp);
                        freeb(bp);
                else
                        ipiput4(er->f, ifc, bp);
-               runlock(ifc);
+               runlock(&ifc->rwlock);
                poperror();
        }
 }
                poperror();
        }
 }
@@ -390,48 +403,49 @@ etherread4(void *a)
 static void
 etherread6(void *a)
 {
 static void
 etherread6(void *a)
 {
-       Ipifc *ifc;
-       Block *bp;
+       ERRSTACK(2);
+       struct Ipifc *ifc;
+       struct block *bp;
        Etherrock *er;
 
        ifc = a;
        er = ifc->arg;
        Etherrock *er;
 
        ifc = a;
        er = ifc->arg;
-       er->read6p = up;        /* hide identity under a rock for unbind */
+       er->read6p = current;   /* hide identity under a rock for unbind */
        if(waserror()){
                er->read6p = 0;
        if(waserror()){
                er->read6p = 0;
-               pexit("hangup", 1);
+               //      pexit("hangup", 1);
        }
        for(;;){
                bp = devtab[er->mchan6->type]->bread(er->mchan6, ifc->maxtu, 0);
        }
        for(;;){
                bp = devtab[er->mchan6->type]->bread(er->mchan6, ifc->maxtu, 0);
-               if(!canrlock(ifc)){
+               if(!canrlock(&ifc->rwlock)){
                        freeb(bp);
                        continue;
                }
                if(waserror()){
                        freeb(bp);
                        continue;
                }
                if(waserror()){
-                       runlock(ifc);
+                       runlock(&ifc->rwlock);
                        nexterror();
                }
                ifc->in++;
                bp->rp += ifc->m->hsize;
                        nexterror();
                }
                ifc->in++;
                bp->rp += ifc->m->hsize;
-               if(ifc->lifc == nil)
+               if(ifc->lifc == NULL)
                        freeb(bp);
                else
                        ipiput6(er->f, ifc, bp);
                        freeb(bp);
                else
                        ipiput6(er->f, ifc, bp);
-               runlock(ifc);
+               runlock(&ifc->rwlock);
                poperror();
        }
 }
 
 static void
                poperror();
        }
 }
 
 static void
-etheraddmulti(Ipifc *ifc, uchar *a, uchar *)
+etheraddmulti(struct Ipifc *ifc, uint8_t *a, uint8_t *unused)
 {
 {
-       uchar mac[6];
+       uint8_t mac[6];
        char buf[64];
        Etherrock *er = ifc->arg;
        int version;
 
        version = multicastea(mac, a);
        char buf[64];
        Etherrock *er = ifc->arg;
        int version;
 
        version = multicastea(mac, a);
-       sprint(buf, "addmulti %E", mac);
+       snprintf(buf, sizeof(buf), "addmulti %E", mac);
        switch(version){
        case V4:
                devtab[er->cchan4->type]->write(er->cchan4, buf, strlen(buf), 0);
        switch(version){
        case V4:
                devtab[er->cchan4->type]->write(er->cchan4, buf, strlen(buf), 0);
@@ -445,15 +459,15 @@ etheraddmulti(Ipifc *ifc, uchar *a, uchar *)
 }
 
 static void
 }
 
 static void
-etherremmulti(Ipifc *ifc, uchar *a, uchar *)
+etherremmulti(struct Ipifc *ifc, uint8_t *a, uint8_t *unused)
 {
 {
-       uchar mac[6];
+       uint8_t mac[6];
        char buf[64];
        Etherrock *er = ifc->arg;
        int version;
 
        version = multicastea(mac, a);
        char buf[64];
        Etherrock *er = ifc->arg;
        int version;
 
        version = multicastea(mac, a);
-       sprint(buf, "remmulti %E", mac);
+       snprintf(buf, sizeof(buf), "remmulti %E", mac);
        switch(version){
        case V4:
                devtab[er->cchan4->type]->write(er->cchan4, buf, strlen(buf), 0);
        switch(version){
        case V4:
                devtab[er->cchan4->type]->write(er->cchan4, buf, strlen(buf), 0);
@@ -471,10 +485,10 @@ etherremmulti(Ipifc *ifc, uchar *a, uchar *)
  *  (only v4, v6 uses the neighbor discovery, rfc1970)
  */
 static void
  *  (only v4, v6 uses the neighbor discovery, rfc1970)
  */
 static void
-sendarp(Ipifc *ifc, Arpent *a)
+sendarp(struct Ipifc *ifc, struct arpent *a)
 {
        int n;
 {
        int n;
-       Block *bp;
+       struct block *bp;
        Etherarp *e;
        Etherrock *er = ifc->arg;
 
        Etherarp *e;
        Etherrock *er = ifc->arg;
 
@@ -485,7 +499,7 @@ sendarp(Ipifc *ifc, Arpent *a)
        }
 
        /* remove all but the last message */
        }
 
        /* remove all but the last message */
-       while((bp = a->hold) != nil){
+       while((bp = a->hold) != NULL){
                if(bp == a->last)
                        break;
                a->hold = bp->list;
                if(bp == a->last)
                        break;
                a->hold = bp->list;
@@ -518,16 +532,16 @@ sendarp(Ipifc *ifc, Arpent *a)
 
        n = devtab[er->achan->type]->bwrite(er->achan, bp, 0);
        if(n < 0)
 
        n = devtab[er->achan->type]->bwrite(er->achan, bp, 0);
        if(n < 0)
-               print("arp: send: %r\n");
+               printd("arp: send: %r\n");
 }
 
 static void
 }
 
 static void
-resolveaddr6(Ipifc *ifc, Arpent *a)
+resolveaddr6(struct Ipifc *ifc, struct arpent *a)
 {
        int sflag;
 {
        int sflag;
-       Block *bp;
+       struct block *bp;
        Etherrock *er = ifc->arg;
        Etherrock *er = ifc->arg;
-       uchar ipsrc[IPaddrlen];
+       uint8_t ipsrc[IPaddrlen];
 
        /* don't do anything if it's been less than a second since the last */
        if(NOW - a->ctime < ReTransTimer){
 
        /* don't do anything if it's been less than a second since the last */
        if(NOW - a->ctime < ReTransTimer){
@@ -536,7 +550,7 @@ resolveaddr6(Ipifc *ifc, Arpent *a)
        }
 
        /* remove all but the last message */
        }
 
        /* remove all but the last message */
-       while((bp = a->hold) != nil){
+       while((bp = a->hold) != NULL){
                if(bp == a->last)
                        break;
                a->hold = bp->list;
                if(bp == a->last)
                        break;
                a->hold = bp->list;
@@ -554,7 +568,7 @@ resolveaddr6(Ipifc *ifc, Arpent *a)
        a->rxtsrem--;
        arprelease(er->f->arp, a);
 
        a->rxtsrem--;
        arprelease(er->f->arp, a);
 
-       if(sflag = ipv6anylocal(ifc, ipsrc)) 
+       if((sflag = ipv6anylocal(ifc, ipsrc)) )
                icmpns(er->f, ipsrc, sflag, a->ip, TARG_MULTI, ifc->mac);
 }
 
                icmpns(er->f, ipsrc, sflag, a->ip, TARG_MULTI, ifc->mac);
 }
 
@@ -562,10 +576,10 @@ resolveaddr6(Ipifc *ifc, Arpent *a)
  *  send a gratuitous arp to refresh arp caches
  */
 static void
  *  send a gratuitous arp to refresh arp caches
  */
 static void
-sendgarp(Ipifc *ifc, uchar *ip)
+sendgarp(struct Ipifc *ifc, uint8_t *ip)
 {
        int n;
 {
        int n;
-       Block *bp;
+       struct block *bp;
        Etherarp *e;
        Etherrock *er = ifc->arg;
 
        Etherarp *e;
        Etherrock *er = ifc->arg;
 
@@ -595,22 +609,22 @@ sendgarp(Ipifc *ifc, uchar *ip)
 
        n = devtab[er->achan->type]->bwrite(er->achan, bp, 0);
        if(n < 0)
 
        n = devtab[er->achan->type]->bwrite(er->achan, bp, 0);
        if(n < 0)
-               print("garp: send: %r\n");
+               printd("garp: send: %r\n");
 }
 
 static void
 }
 
 static void
-recvarp(Ipifc *ifc)
+recvarp(struct Ipifc *ifc)
 {
        int n;
 {
        int n;
-       Block *ebp, *rbp;
+       struct block *ebp, *rbp;
        Etherarp *e, *r;
        Etherarp *e, *r;
-       uchar ip[IPaddrlen];
-       static uchar eprinted[4];
+       uint8_t ip[IPaddrlen];
+       static uint8_t eprinted[4];
        Etherrock *er = ifc->arg;
 
        ebp = devtab[er->achan->type]->bread(er->achan, ifc->maxtu, 0);
        Etherrock *er = ifc->arg;
 
        ebp = devtab[er->achan->type]->bread(er->achan, ifc->maxtu, 0);
-       if(ebp == nil) {
-               print("arp: rcv: %r\n");
+       if(ebp == NULL) {
+               printd("arp: rcv: %r\n");
                return;
        }
 
                return;
        }
 
@@ -624,7 +638,7 @@ recvarp(Ipifc *ifc)
                v4tov6(ip, e->spa);
                if(iplocalonifc(ifc, ip) || ipproxyifc(er->f, ifc, ip)){
                        if(memcmp(e->sha, ifc->mac, sizeof(e->sha)) != 0){
                v4tov6(ip, e->spa);
                if(iplocalonifc(ifc, ip) || ipproxyifc(er->f, ifc, ip)){
                        if(memcmp(e->sha, ifc->mac, sizeof(e->sha)) != 0){
-                               print("arprep: 0x%E/0x%E also has ip addr %V\n",
+                               printd("arprep: 0x%E/0x%E also has ip addr %V\n",
                                        e->s, e->sha, e->spa);
                                break;
                        }
                                        e->s, e->sha, e->spa);
                                break;
                        }
@@ -633,7 +647,7 @@ recvarp(Ipifc *ifc)
                /* make sure we're not entering broadcast addresses */
                if(ipcmp(ip, ipbroadcast) == 0 ||
                        !memcmp(e->sha, etherbroadcast, sizeof(e->sha))){
                /* make sure we're not entering broadcast addresses */
                if(ipcmp(ip, ipbroadcast) == 0 ||
                        !memcmp(e->sha, etherbroadcast, sizeof(e->sha))){
-                       print("arprep: 0x%E/0x%E cannot register broadcast address %I\n",
+                       printd("arprep: 0x%E/0x%E cannot register broadcast address %I\n",
                                e->s, e->sha, e->spa);
                        break;
                }
                                e->s, e->sha, e->spa);
                        break;
                }
@@ -652,13 +666,13 @@ recvarp(Ipifc *ifc)
                        if(memcmp(e->sha, ifc->mac, sizeof(e->sha)) != 0){
                                if (memcmp(eprinted, e->spa, sizeof(e->spa))){
                                        /* print only once */
                        if(memcmp(e->sha, ifc->mac, sizeof(e->sha)) != 0){
                                if (memcmp(eprinted, e->spa, sizeof(e->spa))){
                                        /* print only once */
-                                       print("arpreq: 0x%E also has ip addr %V\n", e->sha, e->spa);
+                                       printd("arpreq: 0x%E also has ip addr %V\n", e->sha, e->spa);
                                        memmove(eprinted, e->spa, sizeof(e->spa));
                                }
                        }
                } else {
                        if(memcmp(e->sha, ifc->mac, sizeof(e->sha)) == 0){
                                        memmove(eprinted, e->spa, sizeof(e->spa));
                                }
                        }
                } else {
                        if(memcmp(e->sha, ifc->mac, sizeof(e->sha)) == 0){
-                               print("arpreq: %V also has ether addr %E\n", e->spa, e->sha);
+                               printd("arpreq: %V also has ether addr %E\n", e->spa, e->sha);
                                break;
                        }
                }
                                break;
                        }
                }
@@ -694,7 +708,7 @@ recvarp(Ipifc *ifc)
 
                n = devtab[er->achan->type]->bwrite(er->achan, rbp, 0);
                if(n < 0)
 
                n = devtab[er->achan->type]->bwrite(er->achan, rbp, 0);
                if(n < 0)
-                       print("arp: write: %r\n");
+                       printd("arp: write: %r\n");
        }
        freeb(ebp);
 }
        }
        freeb(ebp);
 }
@@ -702,20 +716,21 @@ recvarp(Ipifc *ifc)
 static void
 recvarpproc(void *v)
 {
 static void
 recvarpproc(void *v)
 {
-       Ipifc *ifc = v;
+       ERRSTACK(2);
+       struct Ipifc *ifc = v;
        Etherrock *er = ifc->arg;
 
        Etherrock *er = ifc->arg;
 
-       er->arpp = up;
+       er->arpp = current;
        if(waserror()){
                er->arpp = 0;
        if(waserror()){
                er->arpp = 0;
-               pexit("hangup", 1);
+               //      pexit("hangup", 1);
        }
        for(;;)
                recvarp(ifc);
 }
 
 static int
        }
        for(;;)
                recvarp(ifc);
 }
 
 static int
-multicastea(uchar *ea, uchar *ip)
+multicastea(uint8_t *ea, uint8_t *ip)
 {
        int x;
 
 {
        int x;
 
@@ -745,13 +760,14 @@ multicastea(uchar *ea, uchar *ip)
  *  addresses.  Return the first queued packet for the
  *  IP address.
  */
  *  addresses.  Return the first queued packet for the
  *  IP address.
  */
-static Block*
-multicastarp(Fs *f, Arpent *a, Medium *medium, uchar *mac)
+static struct block*
+multicastarp(struct Fs *f,
+            struct arpent *a, struct medium *medium, uint8_t *mac)
 {
        /* is it broadcast? */
        switch(ipforme(f, a->ip)){
        case Runi:
 {
        /* is it broadcast? */
        switch(ipforme(f, a->ip)){
        case Runi:
-               return nil;
+               return NULL;
        case Rbcast:
                memset(mac, 0xff, 6);
                return arpresolve(f->arp, a, medium, mac);
        case Rbcast:
                memset(mac, 0xff, 6);
                return arpresolve(f->arp, a, medium, mac);
@@ -767,7 +783,7 @@ multicastarp(Fs *f, Arpent *a, Medium *medium, uchar *mac)
        }
 
        /* let arp take care of it */
        }
 
        /* let arp take care of it */
-       return nil;
+       return NULL;
 }
 
 void
 }
 
 void
@@ -779,7 +795,7 @@ ethermediumlink(void)
 
 
 static void 
 
 
 static void 
-etherpref2addr(uchar *pref, uchar *ea)
+etherpref2addr(uint8_t *pref, uint8_t *ea)
 {
        pref[8]  = ea[0] | 0x2;
        pref[9]  = ea[1];
 {
        pref[8]  = ea[0] | 0x2;
        pref[9]  = ea[1];
index a044a57..02e681f 100644 (file)
@@ -1,12 +1,17 @@
-#include "u.h"
-#include "../port/lib.h"
-#include "mem.h"
-#include "dat.h"
-#include "fns.h"
-#include "../port/error.h"
-
-#include "ip.h"
-#include "ipv6.h"
+// INFERNO
+#include <vfs.h>
+#include <kfs.h>
+#include <slab.h>
+#include <kmalloc.h>
+#include <kref.h>
+#include <string.h>
+#include <stdio.h>
+#include <assert.h>
+#include <error.h>
+#include <cpio.h>
+#include <pmap.h>
+#include <smp.h>
+#include <ip.h>
 
 #define DPRINT if(0)print
 
 
 #define DPRINT if(0)print
 
@@ -18,7 +23,7 @@ enum {
        QMAX = 64*1024-1,
 };
 
        QMAX = 64*1024-1,
 };
 
-Medium *media[Maxmedia] =
+struct medium *media[Maxmedia] =
 {
        0
 };
 {
        0
 };
@@ -28,21 +33,21 @@ Medium *media[Maxmedia] =
  */
 struct Ipself
 {
  */
 struct Ipself
 {
-       uchar   a[IPaddrlen];
-       Ipself  *hnext;         /* next address in the hash table */
-       Iplink  *link;          /* binding twixt Ipself and Ipifc */
-       ulong   expire;
-       uchar   type;           /* type of address */
+       uint8_t a[IPaddrlen];
+       struct Ipself   *hnext;         /* next address in the hash table */
+       struct Iplink   *link;          /* binding twixt Ipself and Ipifc */
+       uint32_t        expire;
+       uint8_t type;           /* type of address */
        int     ref;
        int     ref;
-       Ipself  *next;          /* free list */
+       struct Ipself   *next;          /* free list */
 };
 
 struct Ipselftab
 {
 };
 
 struct Ipselftab
 {
-       QLock;
+       qlock_t qlock;
        int     inited;
        int     acceptall;      /* true if an interface has the null address */
        int     inited;
        int     acceptall;      /* true if an interface has the null address */
-       Ipself  *hash[NHASH];   /* hash chains */
+       struct Ipself   *hash[NHASH];   /* hash chains */
 };
 
 /*
 };
 
 /*
@@ -53,8 +58,8 @@ typedef struct Ipmcast Ipmcast;
 struct Ipmcast
 {
        Ipmcast *next;
 struct Ipmcast
 {
        Ipmcast *next;
-       uchar   ma[IPaddrlen];  /* multicast address */
-       uchar   ia[IPaddrlen];  /* interface address */
+       uint8_t ma[IPaddrlen];  /* multicast address */
+       uint8_t ia[IPaddrlen];  /* interface address */
 };
 
 /* quick hash for ip addresses */
 };
 
 /* quick hash for ip addresses */
@@ -62,23 +67,26 @@ struct Ipmcast
 
 static char tifc[] = "ifc ";
 
 
 static char tifc[] = "ifc ";
 
-static void    addselfcache(Fs *f, Ipifc *ifc, Iplifc *lifc, uchar *a, int type);
-static void    remselfcache(Fs *f, Ipifc *ifc, Iplifc *lifc, uchar *a);
-static char*   ipifcjoinmulti(Ipifc *ifc, char **argv, int argc);
-static char*   ipifcleavemulti(Ipifc *ifc, char **argv, int argc);
-static void    ipifcregisterproxy(Fs*, Ipifc*, uchar*);
-static char*   ipifcremlifc(Ipifc*, Iplifc*);
+static void    addselfcache(struct Fs *f, struct Ipifc *ifc, struct Iplifc *lifc,
+                               uint8_t *a, int type);
+static void    remselfcache(struct Fs *f,
+                               struct Ipifc *ifc,
+                               struct Iplifc *lifc, uint8_t *a);
+static char*   ipifcjoinmulti(struct Ipifc *ifc, char **argv, int argc);
+static char*   ipifcleavemulti(struct Ipifc *ifc, char **argv, int argc);
+static void    ipifcregisterproxy(struct Fs*, struct Ipifc*, uint8_t *unused_uint8_p_t);
+static char*   ipifcremlifc(struct Ipifc*, struct Iplifc*);
 
 /*
  *  link in a new medium
  */
 void
 
 /*
  *  link in a new medium
  */
 void
-addipmedium(Medium *med)
+addipmedium(struct medium *med)
 {
        int i;
 
 {
        int i;
 
-       for(i = 0; i < nelem(media)-1; i++)
-               if(media[i] == nil){
+       for(i = 0; i < ARRAY_SIZE(media)-1; i++)
+               if(media[i] == NULL){
                        media[i] = med;
                        break;
                }
                        media[i] = med;
                        break;
                }
@@ -87,12 +95,12 @@ addipmedium(Medium *med)
 /*
  *  find the medium with this name
  */
 /*
  *  find the medium with this name
  */
-Medium*
+struct medium*
 ipfindmedium(char *name)
 {
 ipfindmedium(char *name)
 {
-       Medium **mp;
+       struct medium **mp;
 
 
-       for(mp = media; *mp != nil; mp++)
+       for(mp = media; *mp != NULL; mp++)
                if(strcmp((*mp)->name, name) == 0)
                        break;
        return *mp;
                if(strcmp((*mp)->name, name) == 0)
                        break;
        return *mp;
@@ -103,28 +111,29 @@ ipfindmedium(char *name)
  *  called with c locked
  */
 static char*
  *  called with c locked
  */
 static char*
-ipifcbind(Conv *c, char **argv, int argc)
+ipifcbind(struct conv *c, char **argv, int argc)
 {
 {
-       Ipifc *ifc;
-       Medium *m;
+       ERRSTACK(2);
+       struct Ipifc *ifc;
+       struct medium *m;
 
        if(argc < 2)
                return Ebadarg;
 
 
        if(argc < 2)
                return Ebadarg;
 
-       ifc = (Ipifc*)c->ptcl;
+       ifc = (struct Ipifc*)c->ptcl;
 
        /* bind the device to the interface */
        m = ipfindmedium(argv[1]);
 
        /* bind the device to the interface */
        m = ipfindmedium(argv[1]);
-       if(m == nil)
+       if(m == NULL)
                return "unknown interface type";
 
                return "unknown interface type";
 
-       wlock(ifc);
-       if(ifc->m != nil){
-               wunlock(ifc);
+       wlock(&ifc->rwlock);
+       if(ifc->m != NULL){
+               wunlock(&ifc->rwlock);
                return "interface already bound";       
        }
        if(waserror()){
                return "interface already bound";       
        }
        if(waserror()){
-               wunlock(ifc);
+               wunlock(&ifc->rwlock);
                nexterror();
        }
 
                nexterror();
        }
 
@@ -135,7 +144,7 @@ ipifcbind(Conv *c, char **argv, int argc)
        if(argc > 2)
                strncpy(ifc->dev, argv[2], sizeof(ifc->dev));
        else
        if(argc > 2)
                strncpy(ifc->dev, argv[2], sizeof(ifc->dev));
        else
-               snprint(ifc->dev, sizeof ifc->dev, "%s%d", m->name, c->x);
+               snprintf(ifc->dev, sizeof ifc->dev, "%s%d", m->name, c->x);
        ifc->dev[sizeof(ifc->dev)-1] = 0;
 
        /* set up parameters */
        ifc->dev[sizeof(ifc->dev)-1] = 0;
 
        /* set up parameters */
@@ -162,10 +171,10 @@ ipifcbind(Conv *c, char **argv, int argc)
        qreopen(c->eq);
        qreopen(c->sq);
 
        qreopen(c->eq);
        qreopen(c->sq);
 
-       wunlock(ifc);
+       wunlock(&ifc->rwlock);
        poperror();
 
        poperror();
 
-       return nil;
+       return NULL;
 }
 
 /*
 }
 
 /*
@@ -173,26 +182,27 @@ ipifcbind(Conv *c, char **argv, int argc)
  *  called with ifc->conv closed
  */
 static char*
  *  called with ifc->conv closed
  */
 static char*
-ipifcunbind(Ipifc *ifc)
+ipifcunbind(struct Ipifc *ifc)
 {
 {
+       ERRSTACK(2);
        char *err;
 
        if(waserror()){
        char *err;
 
        if(waserror()){
-               wunlock(ifc);
+               wunlock(&ifc->rwlock);
                nexterror();
        }
                nexterror();
        }
-       wlock(ifc);
+       wlock(&ifc->rwlock);
 
        /* dissociate routes */
 
        /* dissociate routes */
-       if(ifc->m != nil && ifc->m->unbindonclose == 0)
+       if(ifc->m != NULL && ifc->m->unbindonclose == 0)
                ifc->conv->inuse--;
        ifc->ifcid++;
 
        /* disassociate device */
                ifc->conv->inuse--;
        ifc->ifcid++;
 
        /* disassociate device */
-       if(ifc->m != nil && ifc->m->unbind)
+       if(ifc->m != NULL && ifc->m->unbind)
                (*ifc->m->unbind)(ifc);
        memset(ifc->dev, 0, sizeof(ifc->dev));
                (*ifc->m->unbind)(ifc);
        memset(ifc->dev, 0, sizeof(ifc->dev));
-       ifc->arg = nil;
+       ifc->arg = NULL;
        ifc->reassemble = 0;
 
        /* close queues to stop queuing of packets */
        ifc->reassemble = 0;
 
        /* close queues to stop queuing of packets */
@@ -207,10 +217,10 @@ ipifcunbind(Ipifc *ifc)
                        error(err);
        }
 
                        error(err);
        }
 
-       ifc->m = nil;
-       wunlock(ifc);
+       ifc->m = NULL;
+       wunlock(&ifc->rwlock);
        poperror();
        poperror();
-       return nil;
+       return NULL;
 }
 
 
 }
 
 
@@ -221,62 +231,62 @@ char slineformat[] = "    %-40I %-10M %-40I %-12lud %-12lud\n";
 
 
 static int
 
 
 static int
-ipifcstate(Conv *c, char *state, int n)
+ipifcstate(struct conv *c, char *state, int n)
 {
 {
-       Ipifc *ifc;
-       Iplifc *lifc;
+       struct Ipifc *ifc;
+       struct Iplifc *lifc;
        int m;
 
        int m;
 
-       ifc = (Ipifc*)c->ptcl;
+       ifc = (struct Ipifc*)c->ptcl;
 
 
-       m = snprint(state, n, sfixedformat,
+       m = snprintf(state, n, sfixedformat,
                ifc->dev, ifc->maxtu, ifc->sendra6, ifc->recvra6,
                ifc->dev, ifc->maxtu, ifc->sendra6, ifc->recvra6,
-               ifc->rp.mflag, ifc->rp.oflag, ifc->rp.maxraint,
-               ifc->rp.minraint, ifc->rp.linkmtu, ifc->rp.reachtime,
-               ifc->rp.rxmitra, ifc->rp.ttl, ifc->rp.routerlt,
-               ifc->in, ifc->out, ifc->inerr, ifc->outerr);
+                    ifc->rp.mflag, ifc->rp.oflag, ifc->rp.maxraint,
+                    ifc->rp.minraint, ifc->rp.linkmtu, ifc->rp.reachtime,
+                    ifc->rp.rxmitra, ifc->rp.ttl, ifc->rp.routerlt,
+                    ifc->in, ifc->out, ifc->inerr, ifc->outerr);
 
 
-       rlock(ifc);
+       rlock(&ifc->rwlock);
        for(lifc = ifc->lifc; lifc && n > m; lifc = lifc->next)
        for(lifc = ifc->lifc; lifc && n > m; lifc = lifc->next)
-               m += snprint(state+m, n - m, slineformat,
+               m += snprintf(state+m, n - m, slineformat,
                        lifc->local, lifc->mask, lifc->remote,
                        lifc->validlt, lifc->preflt);
                        lifc->local, lifc->mask, lifc->remote,
                        lifc->validlt, lifc->preflt);
-       if(ifc->lifc == nil)
-               m += snprint(state+m, n - m, "\n");
-       runlock(ifc);
+       if(ifc->lifc == NULL)
+               m += snprintf(state+m, n - m, "\n");
+       runlock(&ifc->rwlock);
        return m;
 }
 
 static int
        return m;
 }
 
 static int
-ipifclocal(Conv *c, char *state, int n)
+ipifclocal(struct conv *c, char *state, int n)
 {
 {
-       Ipifc *ifc;
-       Iplifc *lifc;
-       Iplink *link;
+       struct Ipifc *ifc;
+       struct Iplifc *lifc;
+       struct Iplink *link;
        int m;
 
        int m;
 
-       ifc = (Ipifc*)c->ptcl;
+       ifc = (struct Ipifc*)c->ptcl;
 
        m = 0;
 
 
        m = 0;
 
-       rlock(ifc);
+       rlock(&ifc->rwlock);
        for(lifc = ifc->lifc; lifc; lifc = lifc->next){
        for(lifc = ifc->lifc; lifc; lifc = lifc->next){
-               m += snprint(state+m, n - m, "%-40.40I ->", lifc->local);
+               m += snprintf(state+m, n - m, "%-40.40I ->", lifc->local);
                for(link = lifc->link; link; link = link->lifclink)
                for(link = lifc->link; link; link = link->lifclink)
-                       m += snprint(state+m, n - m, " %-40.40I", link->self->a);
-               m += snprint(state+m, n - m, "\n");
+                       m += snprintf(state+m, n - m, " %-40.40I", link->self->a);
+               m += snprintf(state+m, n - m, "\n");
        }
        }
-       runlock(ifc);
+       runlock(&ifc->rwlock);
        return m;
 }
 
 static int
        return m;
 }
 
 static int
-ipifcinuse(Conv *c)
+ipifcinuse(struct conv *c)
 {
 {
-       Ipifc *ifc;
+       struct Ipifc *ifc;
 
 
-       ifc = (Ipifc*)c->ptcl;
-       return ifc->m != nil;
+       ifc = (struct Ipifc*)c->ptcl;
+       return ifc->m != NULL;
 }
 
 /*
 }
 
 /*
@@ -285,28 +295,29 @@ ipifcinuse(Conv *c)
 static void
 ipifckick(void *x)
 {
 static void
 ipifckick(void *x)
 {
-       Conv *c = x;
-       Block *bp;
-       Ipifc *ifc;
+       ERRSTACK(2);
+       struct conv *c = x;
+       struct block *bp;
+       struct Ipifc *ifc;
 
        bp = qget(c->wq);
 
        bp = qget(c->wq);
-       if(bp == nil)
+       if(bp == NULL)
                return;
 
                return;
 
-       ifc = (Ipifc*)c->ptcl;
-       if(!canrlock(ifc)){
+       ifc = (struct Ipifc*)c->ptcl;
+       if(!canrlock(&ifc->rwlock)){
                freeb(bp);
                return;
        }
        if(waserror()){
                freeb(bp);
                return;
        }
        if(waserror()){
-               runlock(ifc);
+               runlock(&ifc->rwlock);
                nexterror();
        }
                nexterror();
        }
-       if(ifc->m == nil || ifc->m->pktin == nil)
+       if(ifc->m == NULL || ifc->m->pktin == NULL)
                freeb(bp);
        else
                (*ifc->m->pktin)(c->p->f, ifc, bp);
                freeb(bp);
        else
                (*ifc->m->pktin)(c->p->f, ifc, bp);
-       runlock(ifc);
+       runlock(&ifc->rwlock);
        poperror();
 }
 
        poperror();
 }
 
@@ -314,17 +325,17 @@ ipifckick(void *x)
  *  called when a new ipifc structure is created
  */
 static void
  *  called when a new ipifc structure is created
  */
 static void
-ipifccreate(Conv *c)
+ipifccreate(struct conv *c)
 {
 {
-       Ipifc *ifc;
+       struct Ipifc *ifc;
 
        c->rq = qopen(QMAX, 0, 0, 0);
        c->sq = qopen(2*QMAX, 0, 0, 0);
        c->wq = qopen(QMAX, Qkick, ipifckick, c);
 
        c->rq = qopen(QMAX, 0, 0, 0);
        c->sq = qopen(2*QMAX, 0, 0, 0);
        c->wq = qopen(QMAX, Qkick, ipifckick, c);
-       ifc = (Ipifc*)c->ptcl;
+       ifc = (struct Ipifc*)c->ptcl;
        ifc->conv = c;
        ifc->unbinding = 0;
        ifc->conv = c;
        ifc->unbinding = 0;
-       ifc->m = nil;
+       ifc->m = NULL;
        ifc->reassemble = 0;
 }
 
        ifc->reassemble = 0;
 }
 
@@ -333,14 +344,14 @@ ipifccreate(Conv *c)
  *  called with c locked, we must unlock
  */
 static void
  *  called with c locked, we must unlock
  */
 static void
-ipifcclose(Conv *c)
+ipifcclose(struct conv *c)
 {
 {
-       Ipifc *ifc;
-       Medium *m;
+       struct Ipifc *ifc;
+       struct medium *m;
 
 
-       ifc = (Ipifc*)c->ptcl;
+       ifc = (struct Ipifc*)c->ptcl;
        m = ifc->m;
        m = ifc->m;
-       if(m != nil && m->unbindonclose)
+       if(m != NULL && m->unbindonclose)
                ipifcunbind(ifc);
 }
 
                ipifcunbind(ifc);
 }
 
@@ -348,35 +359,36 @@ ipifcclose(Conv *c)
  *  change an interface's mtu
  */
 char*
  *  change an interface's mtu
  */
 char*
-ipifcsetmtu(Ipifc *ifc, char **argv, int argc)
+ipifcsetmtu(struct Ipifc *ifc, char **argv, int argc)
 {
        int mtu;
 
        if(argc < 2)
                return Ebadarg;
 {
        int mtu;
 
        if(argc < 2)
                return Ebadarg;
-       if(ifc->m == nil)
+       if(ifc->m == NULL)
                return Ebadarg;
        mtu = strtoul(argv[1], 0, 0);
        if(mtu < ifc->m->mintu || mtu > ifc->m->maxtu)
                return Ebadarg;
        ifc->maxtu = mtu;
                return Ebadarg;
        mtu = strtoul(argv[1], 0, 0);
        if(mtu < ifc->m->mintu || mtu > ifc->m->maxtu)
                return Ebadarg;
        ifc->maxtu = mtu;
-       return nil;
+       return NULL;
 }
 
 /*
  *  add an address to an interface.
  */
 char*
 }
 
 /*
  *  add an address to an interface.
  */
 char*
-ipifcadd(Ipifc *ifc, char **argv, int argc, int tentative, Iplifc *lifcp)
+ipifcadd(struct Ipifc *ifc, char **argv, int argc, int tentative,
+        struct Iplifc *lifcp)
 {
 {
-       uchar ip[IPaddrlen], mask[IPaddrlen], rem[IPaddrlen];
-       uchar bcast[IPaddrlen], net[IPaddrlen];
-       Iplifc *lifc, **l;
+       uint8_t ip[IPaddrlen], mask[IPaddrlen], rem[IPaddrlen];
+       uint8_t bcast[IPaddrlen], net[IPaddrlen];
+       struct Iplifc *lifc, **l;
        int i, type, mtu;
        int i, type, mtu;
-       Fs *f;
+       struct Fs *f;
        int sendnbrdisc = 0;
 
        int sendnbrdisc = 0;
 
-       if(ifc->m == nil)
+       if(ifc->m == NULL)
                return "ipifc not yet bound to device";
 
        f = ifc->conv->p->f;
                return "ipifc not yet bound to device";
 
        f = ifc->conv->p->f;
@@ -419,14 +431,14 @@ ipifcadd(Ipifc *ifc, char **argv, int argc, int tentative, Iplifc *lifcp)
        }
        if(isv4(ip))
                tentative = 0;
        }
        if(isv4(ip))
                tentative = 0;
-       wlock(ifc);
+       wlock(&ifc->rwlock);
 
        /* ignore if this is already a local address for this ifc */
        for(lifc = ifc->lifc; lifc; lifc = lifc->next) {
                if(ipcmp(lifc->local, ip) == 0) {
                        if(lifc->tentative != tentative)
                                lifc->tentative = tentative;
 
        /* ignore if this is already a local address for this ifc */
        for(lifc = ifc->lifc; lifc; lifc = lifc->next) {
                if(ipcmp(lifc->local, ip) == 0) {
                        if(lifc->tentative != tentative)
                                lifc->tentative = tentative;
-                       if(lifcp != nil) {
+                       if(lifcp != NULL) {
                                lifc->onlink = lifcp->onlink;
                                lifc->autoflag = lifcp->autoflag;
                                lifc->validlt = lifcp->validlt;
                                lifc->onlink = lifcp->onlink;
                                lifc->autoflag = lifcp->autoflag;
                                lifc->validlt = lifcp->validlt;
@@ -438,13 +450,13 @@ ipifcadd(Ipifc *ifc, char **argv, int argc, int tentative, Iplifc *lifcp)
        }
 
        /* add the address to the list of logical ifc's for this ifc */
        }
 
        /* add the address to the list of logical ifc's for this ifc */
-       lifc = smalloc(sizeof(Iplifc));
+       lifc = kzmalloc(sizeof(struct Iplifc), 0);
        ipmove(lifc->local, ip);
        ipmove(lifc->mask, mask);
        ipmove(lifc->remote, rem);
        ipmove(lifc->net, net);
        lifc->tentative = tentative;
        ipmove(lifc->local, ip);
        ipmove(lifc->mask, mask);
        ipmove(lifc->remote, rem);
        ipmove(lifc->net, net);
        lifc->tentative = tentative;
-       if(lifcp != nil) {
+       if(lifcp != NULL) {
                lifc->onlink = lifcp->onlink;
                lifc->autoflag = lifcp->autoflag;
                lifc->validlt = lifcp->validlt;
                lifc->onlink = lifcp->onlink;
                lifc->autoflag = lifcp->autoflag;
                lifc->validlt = lifcp->validlt;
@@ -458,7 +470,7 @@ ipifcadd(Ipifc *ifc, char **argv, int argc, int tentative, Iplifc *lifcp)
                lifc->preflt = 0xffffffff;
                lifc->origint = NOW / 10^3;
        }
                lifc->preflt = 0xffffffff;
                lifc->origint = NOW / 10^3;
        }
-       lifc->next = nil;
+       lifc->next = NULL;
 
        for(l = &ifc->lifc; *l; l = &(*l)->next)
                ;
 
        for(l = &ifc->lifc; *l; l = &(*l)->next)
                ;
@@ -530,14 +542,14 @@ ipifcadd(Ipifc *ifc, char **argv, int argc, int tentative, Iplifc *lifcp)
        }
 
        /* register the address on this network for address resolution */
        }
 
        /* register the address on this network for address resolution */
-       if(isv4(ip) && ifc->m->areg != nil)
+       if(isv4(ip) && ifc->m->areg != NULL)
                (*ifc->m->areg)(ifc, ip);
 
 out:
                (*ifc->m->areg)(ifc, ip);
 
 out:
-       wunlock(ifc);
+       wunlock(&ifc->rwlock);
        if(tentative && sendnbrdisc)
                icmpns(f, 0, SRC_UNSPEC, ip, TARG_MULTI, ifc->mac);
        if(tentative && sendnbrdisc)
                icmpns(f, 0, SRC_UNSPEC, ip, TARG_MULTI, ifc->mac);
-       return nil;
+       return NULL;
 }
 
 /*
 }
 
 /*
@@ -545,10 +557,10 @@ out:
  *  always called with ifc wlock'd
  */
 static char*
  *  always called with ifc wlock'd
  */
 static char*
-ipifcremlifc(Ipifc *ifc, Iplifc *lifc)
+ipifcremlifc(struct Ipifc *ifc, struct Iplifc *lifc)
 {
 {
-       Iplifc **l;
-       Fs *f;
+       struct Iplifc **l;
+       struct Fs *f;
 
        f = ifc->conv->p->f;
 
 
        f = ifc->conv->p->f;
 
@@ -557,9 +569,9 @@ ipifcremlifc(Ipifc *ifc, Iplifc *lifc)
         *  for pt to pt we actually specify the remote address as the
         *  addresss to remove.
         */
         *  for pt to pt we actually specify the remote address as the
         *  addresss to remove.
         */
-       for(l = &ifc->lifc; *l != nil && *l != lifc; l = &(*l)->next)
+       for(l = &ifc->lifc; *l != NULL && *l != lifc; l = &(*l)->next)
                ;
                ;
-       if(*l == nil)
+       if(*l == NULL)
                return "address not on this interface";
        *l = lifc->next;
 
                return "address not on this interface";
        *l = lifc->next;
 
@@ -580,8 +592,8 @@ ipifcremlifc(Ipifc *ifc, Iplifc *lifc)
                        v6delroute(f, v6allnodesL, v6allnodesLmask, 1);
        }
 
                        v6delroute(f, v6allnodesL, v6allnodesLmask, 1);
        }
 
-       free(lifc);
-       return nil;
+       kfree(lifc);
+       return NULL;
 
 }
 
 
 }
 
@@ -590,12 +602,12 @@ ipifcremlifc(Ipifc *ifc, Iplifc *lifc)
  *  called with c locked
  */
 char*
  *  called with c locked
  */
 char*
-ipifcrem(Ipifc *ifc, char **argv, int argc)
+ipifcrem(struct Ipifc *ifc, char **argv, int argc)
 {
 {
-       uchar ip[IPaddrlen];
-       uchar mask[IPaddrlen];
-       uchar rem[IPaddrlen];
-       Iplifc *lifc;
+       uint8_t ip[IPaddrlen];
+       uint8_t mask[IPaddrlen];
+       uint8_t rem[IPaddrlen];
+       struct Iplifc *lifc;
        char *rv;
 
        if(argc < 3)
        char *rv;
 
        if(argc < 3)
@@ -608,14 +620,14 @@ ipifcrem(Ipifc *ifc, char **argv, int argc)
        else
                parseip(rem, argv[3]);
 
        else
                parseip(rem, argv[3]);
 
-       wlock(ifc);
+       wlock(&ifc->rwlock);
 
        /*
         *  find address on this interface and remove from chain.
         *  for pt to pt we actually specify the remote address as the
         *  addresss to remove.
         */
 
        /*
         *  find address on this interface and remove from chain.
         *  for pt to pt we actually specify the remote address as the
         *  addresss to remove.
         */
-       for(lifc = ifc->lifc; lifc != nil; lifc = lifc->next) {
+       for(lifc = ifc->lifc; lifc != NULL; lifc = lifc->next) {
                if (memcmp(ip, lifc->local, IPaddrlen) == 0
                && memcmp(mask, lifc->mask, IPaddrlen) == 0
                && memcmp(rem, lifc->remote, IPaddrlen) == 0)
                if (memcmp(ip, lifc->local, IPaddrlen) == 0
                && memcmp(mask, lifc->mask, IPaddrlen) == 0
                && memcmp(rem, lifc->remote, IPaddrlen) == 0)
@@ -623,7 +635,7 @@ ipifcrem(Ipifc *ifc, char **argv, int argc)
        }
 
        rv = ipifcremlifc(ifc, lifc);
        }
 
        rv = ipifcremlifc(ifc, lifc);
-       wunlock(ifc);
+       wunlock(&ifc->rwlock);
        return rv;
 }
 
        return rv;
 }
 
@@ -632,40 +644,41 @@ ipifcrem(Ipifc *ifc, char **argv, int argc)
  * TRIP linecards
  */
 void
  * TRIP linecards
  */
 void
-ipifcaddroute(Fs *f, int vers, uchar *addr, uchar *mask, uchar *gate, int type)
+ipifcaddroute(struct Fs *f, int vers, uint8_t *addr, uint8_t *mask,
+             uint8_t *gate, int type)
 {
 {
-       Medium *m;
-       Conv **cp, **e;
-       Ipifc *ifc;
+       struct medium *m;
+       struct conv **cp, **e;
+       struct Ipifc *ifc;
 
        e = &f->ipifc->conv[f->ipifc->nc];
        for(cp = f->ipifc->conv; cp < e; cp++){
 
        e = &f->ipifc->conv[f->ipifc->nc];
        for(cp = f->ipifc->conv; cp < e; cp++){
-               if(*cp != nil) {
-                       ifc = (Ipifc*)(*cp)->ptcl;
+               if(*cp != NULL) {
+                       ifc = (struct Ipifc*)(*cp)->ptcl;
                        m = ifc->m;
                        m = ifc->m;
-                       if(m == nil)
+                       if(m == NULL)
                                continue;
                                continue;
-                       if(m->addroute != nil)
+                       if(m->addroute != NULL)
                                m->addroute(ifc, vers, addr, mask, gate, type);
                }
        }
 }
 
 void
                                m->addroute(ifc, vers, addr, mask, gate, type);
                }
        }
 }
 
 void
-ipifcremroute(Fs *f, int vers, uchar *addr, uchar *mask)
+ipifcremroute(struct Fs *f, int vers, uint8_t *addr, uint8_t *mask)
 {
 {
-       Medium *m;
-       Conv **cp, **e;
-       Ipifc *ifc;
+       struct medium *m;
+       struct conv **cp, **e;
+       struct Ipifc *ifc;
 
        e = &f->ipifc->conv[f->ipifc->nc];
        for(cp = f->ipifc->conv; cp < e; cp++){
 
        e = &f->ipifc->conv[f->ipifc->nc];
        for(cp = f->ipifc->conv; cp < e; cp++){
-               if(*cp != nil) {
-                       ifc = (Ipifc*)(*cp)->ptcl;
+               if(*cp != NULL) {
+                       ifc = (struct Ipifc*)(*cp)->ptcl;
                        m = ifc->m;
                        m = ifc->m;
-                       if(m == nil)
+                       if(m == NULL)
                                continue;
                                continue;
-                       if(m->remroute != nil)
+                       if(m->remroute != NULL)
                                m->remroute(ifc, vers, addr, mask);
                }
        }
                                m->remroute(ifc, vers, addr, mask);
                }
        }
@@ -677,40 +690,41 @@ ipifcremroute(Fs *f, int vers, uchar *addr, uchar *mask)
  *  and add a new one.
  */
 static char*
  *  and add a new one.
  */
 static char*
-ipifcconnect(Conv* c, char **argv, int argc)
+ipifcconnect(struct conv* c, char **argv, int argc)
 {
 {
+       ERRSTACK(2);
        char *err;
        char *err;
-       Ipifc *ifc;
+       struct Ipifc *ifc;
 
 
-       ifc = (Ipifc*)c->ptcl;
+       ifc = (struct Ipifc*)c->ptcl;
 
 
-       if(ifc->m == nil)
+       if(ifc->m == NULL)
                 return "ipifc not yet bound to device";
 
        if(waserror()){
                 return "ipifc not yet bound to device";
 
        if(waserror()){
-               wunlock(ifc);
+               wunlock(&ifc->rwlock);
                nexterror();
        }
                nexterror();
        }
-       wlock(ifc);
+       wlock(&ifc->rwlock);
        while(ifc->lifc){
                err = ipifcremlifc(ifc, ifc->lifc);
                if(err)
                        error(err);
        }
        while(ifc->lifc){
                err = ipifcremlifc(ifc, ifc->lifc);
                if(err)
                        error(err);
        }
-       wunlock(ifc);
+       wunlock(&ifc->rwlock);
        poperror();
 
        poperror();
 
-       err = ipifcadd(ifc, argv, argc, 0, nil);
+       err = ipifcadd(ifc, argv, argc, 0, NULL);
        if(err)
                return err;
 
        if(err)
                return err;
 
-       Fsconnected(c, nil);
+       Fsconnected(c, NULL);
 
 
-       return nil;
+       return NULL;
 }
 
 char*
 }
 
 char*
-ipifcsetpar6(Ipifc *ifc, char **argv, int argc)
+ipifcsetpar6(struct Ipifc *ifc, char **argv, int argc)
 {
        int i, argsleft, vmax = ifc->rp.maxraint, vmin = ifc->rp.minraint;
 
 {
        int i, argsleft, vmax = ifc->rp.maxraint, vmin = ifc->rp.minraint;
 
@@ -757,11 +771,11 @@ ipifcsetpar6(Ipifc *ifc, char **argv, int argc)
                return Ebadarg;
        }
 
                return Ebadarg;
        }
 
-       return nil;
+       return NULL;
 }
 
 char*
 }
 
 char*
-ipifcsendra6(Ipifc *ifc, char **argv, int argc)
+ipifcsendra6(struct Ipifc *ifc, char **argv, int argc)
 {
        int i;
        
 {
        int i;
        
@@ -769,11 +783,11 @@ ipifcsendra6(Ipifc *ifc, char **argv, int argc)
        if(argc > 1)
                i = atoi(argv[1]);
        ifc->sendra6 = (i!=0);
        if(argc > 1)
                i = atoi(argv[1]);
        ifc->sendra6 = (i!=0);
-       return nil;
+       return NULL;
 }
 
 char*
 }
 
 char*
-ipifcrecvra6(Ipifc *ifc, char **argv, int argc)
+ipifcrecvra6(struct Ipifc *ifc, char **argv, int argc)
 {
        int i;
        
 {
        int i;
        
@@ -781,7 +795,7 @@ ipifcrecvra6(Ipifc *ifc, char **argv, int argc)
        if(argc > 1)
                i = atoi(argv[1]);
        ifc->recvra6 = (i!=0);  
        if(argc > 1)
                i = atoi(argv[1]);
        ifc->recvra6 = (i!=0);  
-       return nil;
+       return NULL;
 }
 
 /*
 }
 
 /*
@@ -789,18 +803,18 @@ ipifcrecvra6(Ipifc *ifc, char **argv, int argc)
  *  called with c locked.
  */
 static char*
  *  called with c locked.
  */
 static char*
-ipifcctl(Conv* c, char**argv, int argc)
+ipifcctl(struct conv* c, char**argv, int argc)
 {
 {
-       Ipifc *ifc;
+       struct Ipifc *ifc;
        int i;
 
        int i;
 
-       ifc = (Ipifc*)c->ptcl;
+       ifc = (struct Ipifc*)c->ptcl;
        if(strcmp(argv[0], "add") == 0)
        if(strcmp(argv[0], "add") == 0)
-               return ipifcadd(ifc, argv, argc, 0, nil);
+               return ipifcadd(ifc, argv, argc, 0, NULL);
        else if(strcmp(argv[0], "bootp") == 0)
                return bootp(ifc);
        else if(strcmp(argv[0], "try") == 0)
        else if(strcmp(argv[0], "bootp") == 0)
                return bootp(ifc);
        else if(strcmp(argv[0], "try") == 0)
-               return ipifcadd(ifc, argv, argc, 1, nil);
+               return ipifcadd(ifc, argv, argc, 1, NULL);
        else if(strcmp(argv[0], "remove") == 0)
                return ipifcrem(ifc, argv, argc);
        else if(strcmp(argv[0], "unbind") == 0)
        else if(strcmp(argv[0], "remove") == 0)
                return ipifcrem(ifc, argv, argc);
        else if(strcmp(argv[0], "unbind") == 0)
@@ -813,14 +827,14 @@ ipifcctl(Conv* c, char**argv, int argc)
                return ipifcsetmtu(ifc, argv, argc);
        else if(strcmp(argv[0], "reassemble") == 0){
                ifc->reassemble = 1;
                return ipifcsetmtu(ifc, argv, argc);
        else if(strcmp(argv[0], "reassemble") == 0){
                ifc->reassemble = 1;
-               return nil;
+               return NULL;
        }
        else if(strcmp(argv[0], "iprouting") == 0){
                i = 1;
                if(argc > 1)
                        i = atoi(argv[1]);
                iprouting(c->p->f, i);
        }
        else if(strcmp(argv[0], "iprouting") == 0){
                i = 1;
                if(argc > 1)
                        i = atoi(argv[1]);
                iprouting(c->p->f, i);
-               return nil;
+               return NULL;
        }
        else if(strcmp(argv[0], "addpref6") == 0)
                return ipifcaddpref6(ifc, argv, argc);
        }
        else if(strcmp(argv[0], "addpref6") == 0)
                return ipifcaddpref6(ifc, argv, argc);
@@ -833,36 +847,36 @@ ipifcctl(Conv* c, char**argv, int argc)
        return "unsupported ctl";
 }
 
        return "unsupported ctl";
 }
 
-ipifcstats(Proto *ipifc, char *buf, int len)
+int ipifcstats(struct Proto *ipifc, char *buf, int len)
 {
        return ipstats(ipifc->f, buf, len);
 }
 
 void
 {
        return ipstats(ipifc->f, buf, len);
 }
 
 void
-ipifcinit(Fs *f)
+ipifcinit(struct Fs *f)
 {
 {
-       Proto *ipifc;
+       struct Proto *ipifc;
 
 
-       ipifc = smalloc(sizeof(Proto));
+       ipifc = kzmalloc(sizeof(struct Proto), 0);
        ipifc->name = "ipifc";
        ipifc->connect = ipifcconnect;
        ipifc->name = "ipifc";
        ipifc->connect = ipifcconnect;
-       ipifc->announce = nil;
+       ipifc->announce = NULL;
        ipifc->bind = ipifcbind;
        ipifc->state = ipifcstate;
        ipifc->create = ipifccreate;
        ipifc->close = ipifcclose;
        ipifc->bind = ipifcbind;
        ipifc->state = ipifcstate;
        ipifc->create = ipifccreate;
        ipifc->close = ipifcclose;
-       ipifc->rcv = nil;
+       ipifc->rcv = NULL;
        ipifc->ctl = ipifcctl;
        ipifc->ctl = ipifcctl;
-       ipifc->advise = nil;
+       ipifc->advise = NULL;
        ipifc->stats = ipifcstats;
        ipifc->inuse = ipifcinuse;
        ipifc->local = ipifclocal;
        ipifc->ipproto = -1;
        ipifc->nc = Maxmedia;
        ipifc->stats = ipifcstats;
        ipifc->inuse = ipifcinuse;
        ipifc->local = ipifclocal;
        ipifc->ipproto = -1;
        ipifc->nc = Maxmedia;
-       ipifc->ptclsize = sizeof(Ipifc);
+       ipifc->ptclsize = sizeof(struct Ipifc);
 
        f->ipifc = ipifc;                       /* hack for ipifcremroute, findipifc, ... */
 
        f->ipifc = ipifc;                       /* hack for ipifcremroute, findipifc, ... */
-       f->self = smalloc(sizeof(Ipselftab));   /* hack for ipforme */
+       f->self = kzmalloc(sizeof(struct Ipselftab), 0);        /* hack for ipforme */
 
        Fsproto(f, ipifc);
 }
 
        Fsproto(f, ipifc);
 }
@@ -872,13 +886,14 @@ ipifcinit(Fs *f)
  *     called with c locked
  */
 static void
  *     called with c locked
  */
 static void
-addselfcache(Fs *f, Ipifc *ifc, Iplifc *lifc, uchar *a, int type)
+addselfcache(struct Fs *f, struct Ipifc *ifc,
+            struct Iplifc *lifc, uint8_t *a, int type)
 {
 {
-       Ipself *p;
-       Iplink *lp;
+       struct Ipself *p;
+       struct Iplink *lp;
        int h;
 
        int h;
 
-       qlock(f->self);
+       qlock(&f->self->qlock);
 
        /* see if the address already exists */
        h = hashipa(a);
 
        /* see if the address already exists */
        h = hashipa(a);
@@ -887,8 +902,8 @@ addselfcache(Fs *f, Ipifc *ifc, Iplifc *lifc, uchar *a, int type)
                        break;
 
        /* allocate a local address and add to hash chain */
                        break;
 
        /* allocate a local address and add to hash chain */
-       if(p == nil){
-               p = smalloc(sizeof(*p));
+       if(p == NULL){
+               p = kzmalloc(sizeof(*p), 0);
                ipmove(p->a, a);
                p->type = type;
                p->next = f->self->hash[h];
                ipmove(p->a, a);
                p->type = type;
                p->next = f->self->hash[h];
@@ -905,9 +920,9 @@ addselfcache(Fs *f, Ipifc *ifc, Iplifc *lifc, uchar *a, int type)
                        break;
 
        /* allocate a lifc-to-local link and link to both */
                        break;
 
        /* allocate a lifc-to-local link and link to both */
-       if(lp == nil){
-               lp = smalloc(sizeof(*lp));
-               lp->ref = 1;
+       if(lp == NULL){
+               lp = kzmalloc(sizeof(*lp), 0);
+               kref_init(&lp->ref, fake_release, 1);
                lp->lifc = lifc;
                lp->self = p;
                lp->selflink = p->link;
                lp->lifc = lifc;
                lp->self = p;
                lp->selflink = p->link;
@@ -921,13 +936,13 @@ addselfcache(Fs *f, Ipifc *ifc, Iplifc *lifc, uchar *a, int type)
                else
                        v6addroute(f, tifc, a, IPallbits, a, type);
 
                else
                        v6addroute(f, tifc, a, IPallbits, a, type);
 
-               if((type & Rmulti) && ifc->m->addmulti != nil)
+               if((type & Rmulti) && ifc->m->addmulti != NULL)
                        (*ifc->m->addmulti)(ifc, a, lifc->local);
        } else {
                        (*ifc->m->addmulti)(ifc, a, lifc->local);
        } else {
-               lp->ref++;
+               kref_get(&lp->ref, 1);
        }
 
        }
 
-       qunlock(f->self);
+       qunlock(&f->self->qlock);
 }
 
 /*
 }
 
 /*
@@ -936,45 +951,45 @@ addselfcache(Fs *f, Ipifc *ifc, Iplifc *lifc, uchar *a, int type)
  *  just put them aside for a while before freeing them.
  *     called with f->self locked
  */
  *  just put them aside for a while before freeing them.
  *     called with f->self locked
  */
-static Iplink *freeiplink;
-static Ipself *freeipself;
+static struct Iplink *freeiplink;
+static struct Ipself *freeipself;
 
 static void
 
 static void
-iplinkfree(Iplink *p)
+iplinkfree(struct Iplink *p)
 {
 {
-       Iplink **l, *np;
-       ulong now = NOW;
+       struct Iplink **l, *np;
+       uint32_t now = NOW;
 
        l = &freeiplink;
        for(np = *l; np; np = *l){
                if(np->expire > now){
                        *l = np->next;
 
        l = &freeiplink;
        for(np = *l; np; np = *l){
                if(np->expire > now){
                        *l = np->next;
-                       free(np);
+                       kfree(np);
                        continue;
                }
                l = &np->next;
        }
        p->expire = now + 5000;         /* give other threads 5 secs to get out */
                        continue;
                }
                l = &np->next;
        }
        p->expire = now + 5000;         /* give other threads 5 secs to get out */
-       p->next = nil;
+       p->next = NULL;
        *l = p;
 }
 static void
        *l = p;
 }
 static void
-ipselffree(Ipself *p)
+ipselffree(struct Ipself *p)
 {
 {
-       Ipself **l, *np;
-       ulong now = NOW;
+       struct Ipself **l, *np;
+       uint32_t now = NOW;
 
        l = &freeipself;
        for(np = *l; np; np = *l){
                if(np->expire > now){
                        *l = np->next;
 
        l = &freeipself;
        for(np = *l; np; np = *l){
                if(np->expire > now){
                        *l = np->next;
-                       free(np);
+                       kfree(np);
                        continue;
                }
                l = &np->next;
        }
        p->expire = now + 5000;         /* give other threads 5 secs to get out */
                        continue;
                }
                l = &np->next;
        }
        p->expire = now + 5000;         /* give other threads 5 secs to get out */
-       p->next = nil;
+       p->next = NULL;
        *l = p;
 }
 
        *l = p;
 }
 
@@ -984,12 +999,12 @@ ipselffree(Ipself *p)
  *     called with c locked
  */
 static void
  *     called with c locked
  */
 static void
-remselfcache(Fs *f, Ipifc *ifc, Iplifc *lifc, uchar *a)
+remselfcache(struct Fs *f, struct Ipifc *ifc, struct Iplifc *lifc, uint8_t *a)
 {
 {
-       Ipself *p, **l;
-       Iplink *link, **l_self, **l_lifc;
+       struct Ipself *p, **l;
+       struct Iplink *link, **l_self, **l_lifc;
 
 
-       qlock(f->self);
+       qlock(&f->self->qlock);
 
        /* find the unique selftab entry */
        l = &f->self->hash[hashipa(a)];
 
        /* find the unique selftab entry */
        l = &f->self->hash[hashipa(a)];
@@ -999,7 +1014,7 @@ remselfcache(Fs *f, Ipifc *ifc, Iplifc *lifc, uchar *a)
                l = &p->next;
        }
 
                l = &p->next;
        }
 
-       if(p == nil)
+       if(p == NULL)
                goto out;
 
        /*
                goto out;
 
        /*
@@ -1013,7 +1028,7 @@ remselfcache(Fs *f, Ipifc *ifc, Iplifc *lifc, uchar *a)
                l_lifc = &link->lifclink;
        }
 
                l_lifc = &link->lifclink;
        }
 
-       if(link == nil)
+       if(link == NULL)
                goto out;
 
        /*
                goto out;
 
        /*
@@ -1027,13 +1042,13 @@ remselfcache(Fs *f, Ipifc *ifc, Iplifc *lifc, uchar *a)
                l_self = &link->selflink;
        }
 
                l_self = &link->selflink;
        }
 
-       if(link == nil)
+       if(link == NULL)
                panic("remselfcache");
 
                panic("remselfcache");
 
-       if(--(link->ref) != 0)
+       if(kref_refcnt(&link->ref) > 1)
                goto out;
 
                goto out;
 
-       if((p->type & Rmulti) && ifc->m->remmulti != nil)
+       if((p->type & Rmulti) && ifc->m->remmulti != NULL)
                (*ifc->m->remmulti)(ifc, a, lifc->local);
 
        /* ref == 0, remove from both chains and free the link */
                (*ifc->m->remmulti)(ifc, a, lifc->local);
 
        /* ref == 0, remove from both chains and free the link */
@@ -1041,7 +1056,7 @@ remselfcache(Fs *f, Ipifc *ifc, Iplifc *lifc, uchar *a)
        *l_self = link->selflink;
        iplinkfree(link);
 
        *l_self = link->selflink;
        iplinkfree(link);
 
-       if(p->link != nil)
+       if(p->link != NULL)
                goto out;
 
        /* remove from routing table */
                goto out;
 
        /* remove from routing table */
@@ -1059,7 +1074,7 @@ remselfcache(Fs *f, Ipifc *ifc, Iplifc *lifc, uchar *a)
                f->self->acceptall = 0;
 
 out:
                f->self->acceptall = 0;
 
 out:
-       qunlock(f->self);
+       qunlock(&f->self->qlock);
 }
 
 static char *stformat = "%-44.44I %2.2d %4.4s\n";
 }
 
 static char *stformat = "%-44.44I %2.2d %4.4s\n";
@@ -1069,37 +1084,37 @@ enum
 };
 
 long
 };
 
 long
-ipselftabread(Fs *f, char *cp, ulong offset, int n)
+ipselftabread(struct Fs *f, char *cp, uint32_t offset, int n)
 {
        int i, m, nifc, off;
 {
        int i, m, nifc, off;
-       Ipself *p;
-       Iplink *link;
+       struct Ipself *p;
+       struct Iplink *link;
        char state[8];
 
        m = 0;
        off = offset;
        char state[8];
 
        m = 0;
        off = offset;
-       qlock(f->self);
+       qlock(&f->self->qlock);
        for(i = 0; i < NHASH && m < n; i++){
        for(i = 0; i < NHASH && m < n; i++){
-               for(p = f->self->hash[i]; p != nil && m < n; p = p->next){
+               for(p = f->self->hash[i]; p != NULL && m < n; p = p->next){
                        nifc = 0;
                        for(link = p->link; link; link = link->selflink)
                                nifc++;
                        routetype(p->type, state);
                        nifc = 0;
                        for(link = p->link; link; link = link->selflink)
                                nifc++;
                        routetype(p->type, state);
-                       m += snprint(cp + m, n - m, stformat, p->a, nifc, state);
+                       m += snprintf(cp + m, n - m, stformat, p->a, nifc, state);
                        if(off > 0){
                                off -= m;
                                m = 0;
                        }
                }
        }
                        if(off > 0){
                                off -= m;
                                m = 0;
                        }
                }
        }
-       qunlock(f->self);
+       qunlock(&f->self->qlock);
        return m;
 }
 
 int
        return m;
 }
 
 int
-iptentative(Fs *f, uchar *addr)
+iptentative(struct Fs *f, uint8_t *addr)
 {
 {
-       Ipself *p;
+       struct Ipself *p;
 
        p = f->self->hash[hashipa(addr)];
        for(; p; p = p->next){
 
        p = f->self->hash[hashipa(addr)];
        for(; p; p = p->next){
@@ -1118,9 +1133,9 @@ iptentative(Fs *f, uchar *addr)
  *     Rmcast
  */
 int
  *     Rmcast
  */
 int
-ipforme(Fs *f, uchar *addr)
+ipforme(struct Fs *f, uint8_t *addr)
 {
 {
-       Ipself *p;
+       struct Ipself *p;
 
        p = f->self->hash[hashipa(addr)];
        for(; p; p = p->next){
 
        p = f->self->hash[hashipa(addr)];
        for(; p; p = p->next){
@@ -1137,18 +1152,18 @@ ipforme(Fs *f, uchar *addr)
 
 /*
  *  find the ifc on same net as the remote system.  If none,
 
 /*
  *  find the ifc on same net as the remote system.  If none,
- *  return nil.
+ *  return NULL.
  */
  */
-Ipifc*
-findipifc(Fs *f, uchar *remote, int type)
+struct Ipifc*
+findipifc(struct Fs *f, uint8_t *remote, int type)
 {
 {
-       Ipifc *ifc, *x;
-       Iplifc *lifc;
-       Conv **cp, **e;
-       uchar gnet[IPaddrlen];
-       uchar xmask[IPaddrlen];
+       struct Ipifc *ifc, *x;
+       struct Iplifc *lifc;
+       struct conv **cp, **e;
+       uint8_t gnet[IPaddrlen];
+       uint8_t xmask[IPaddrlen];
 
 
-       x = nil; memset(xmask, 0, IPaddrlen);
+       x = NULL; memset(xmask, 0, IPaddrlen);
 
        /* find most specific match */
        e = &f->ipifc->conv[f->ipifc->nc];
 
        /* find most specific match */
        e = &f->ipifc->conv[f->ipifc->nc];
@@ -1156,19 +1171,19 @@ findipifc(Fs *f, uchar *remote, int type)
                if(*cp == 0)
                        continue;
 
                if(*cp == 0)
                        continue;
 
-               ifc = (Ipifc*)(*cp)->ptcl;
+               ifc = (struct Ipifc*)(*cp)->ptcl;
 
                for(lifc = ifc->lifc; lifc; lifc = lifc->next){
                        maskip(remote, lifc->mask, gnet);
                        if(ipcmp(gnet, lifc->net) == 0){
 
                for(lifc = ifc->lifc; lifc; lifc = lifc->next){
                        maskip(remote, lifc->mask, gnet);
                        if(ipcmp(gnet, lifc->net) == 0){
-                               if(x == nil || ipcmp(lifc->mask, xmask) > 0){
+                               if(x == NULL || ipcmp(lifc->mask, xmask) > 0){
                                        x = ifc;
                                        ipmove(xmask, lifc->mask);
                                }
                        }
                }
        }
                                        x = ifc;
                                        ipmove(xmask, lifc->mask);
                                }
                        }
                }
        }
-       if(x != nil)
+       if(x != NULL)
                return x;
 
        /* for now for broadcast and multicast, just use first interface */
                return x;
 
        /* for now for broadcast and multicast, just use first interface */
@@ -1176,13 +1191,13 @@ findipifc(Fs *f, uchar *remote, int type)
                for(cp = f->ipifc->conv; cp < e; cp++){
                        if(*cp == 0)
                                continue;
                for(cp = f->ipifc->conv; cp < e; cp++){
                        if(*cp == 0)
                                continue;
-                       ifc = (Ipifc*)(*cp)->ptcl;
-                       if(ifc->lifc != nil)
+                       ifc = (struct Ipifc*)(*cp)->ptcl;
+                       if(ifc->lifc != NULL)
                                return ifc;
                }
        }
                
                                return ifc;
                }
        }
                
-       return nil;
+       return NULL;
 }
 
 enum {
 }
 
 enum {
@@ -1195,7 +1210,7 @@ enum {
 };
 
 int
 };
 
 int
-v6addrtype(uchar *addr)
+v6addrtype(uint8_t *addr)
 {
        if(isv6global(addr))
                return globalv6;
 {
        if(isv6global(addr))
                return globalv6;
@@ -1211,11 +1226,11 @@ v6addrtype(uchar *addr)
 #define v6addrcurr(lifc) (( (lifc)->origint + (lifc)->preflt >= (NOW/10^3) ) || ( (lifc)->preflt == 0xffffffff ))
 
 static void
 #define v6addrcurr(lifc) (( (lifc)->origint + (lifc)->preflt >= (NOW/10^3) ) || ( (lifc)->preflt == 0xffffffff ))
 
 static void
-findprimaryipv6(Fs *f, uchar *local)
+findprimaryipv6(struct Fs *f, uint8_t *local)
 {
 {
-       Conv **cp, **e;
-       Ipifc *ifc;
-       Iplifc *lifc;
+       struct conv **cp, **e;
+       struct Ipifc *ifc;
+       struct Iplifc *lifc;
        int atype, atypel;
 
        ipmove(local, v6Unspecified);
        int atype, atypel;
 
        ipmove(local, v6Unspecified);
@@ -1228,7 +1243,7 @@ findprimaryipv6(Fs *f, uchar *local)
        for(cp = f->ipifc->conv; cp < e; cp++){
                if(*cp == 0)
                        continue;
        for(cp = f->ipifc->conv; cp < e; cp++){
                if(*cp == 0)
                        continue;
-               ifc = (Ipifc*)(*cp)->ptcl;
+               ifc = (struct Ipifc*)(*cp)->ptcl;
                for(lifc = ifc->lifc; lifc; lifc = lifc->next){
                        atypel = v6addrtype(lifc->local);
                        if(atypel > atype)
                for(lifc = ifc->lifc; lifc; lifc = lifc->next){
                        atypel = v6addrtype(lifc->local);
                        if(atypel > atype)
@@ -1246,19 +1261,19 @@ findprimaryipv6(Fs *f, uchar *local)
  *  returns first ip address configured
  */
 static void
  *  returns first ip address configured
  */
 static void
-findprimaryipv4(Fs *f, uchar *local)
+findprimaryipv4(struct Fs *f, uint8_t *local)
 {
 {
-       Conv **cp, **e;
-       Ipifc *ifc;
-       Iplifc *lifc;
+       struct conv **cp, **e;
+       struct Ipifc *ifc;
+       struct Iplifc *lifc;
 
        /* find first ifc local address */
        e = &f->ipifc->conv[f->ipifc->nc];
        for(cp = f->ipifc->conv; cp < e; cp++){
                if(*cp == 0)
                        continue;
 
        /* find first ifc local address */
        e = &f->ipifc->conv[f->ipifc->nc];
        for(cp = f->ipifc->conv; cp < e; cp++){
                if(*cp == 0)
                        continue;
-               ifc = (Ipifc*)(*cp)->ptcl;
-               if((lifc = ifc->lifc) != nil){
+               ifc = (struct Ipifc*)(*cp)->ptcl;
+               if((lifc = ifc->lifc) != NULL){
                        ipmove(local, lifc->local);
                        return;
                }
                        ipmove(local, lifc->local);
                        return;
                }
@@ -1270,25 +1285,23 @@ findprimaryipv4(Fs *f, uchar *local)
  *  local and return the ifc for that address
  */
 void
  *  local and return the ifc for that address
  */
 void
-findlocalip(Fs *f, uchar *local, uchar *remote)
+findlocalip(struct Fs *f, uint8_t *local, uint8_t *remote)
 {
 {
-       Ipifc *ifc;
-       Iplifc *lifc;
-       Route *r;
-       uchar gate[IPaddrlen];
-       uchar gnet[IPaddrlen];
+       struct Ipifc *ifc;
+       struct Iplifc *lifc;
+       struct route *r;
+       uint8_t gate[IPaddrlen];
+       uint8_t gnet[IPaddrlen];
        int version;
        int atype = unspecifiedv6, atypel = unknownv6;
 
        int version;
        int atype = unspecifiedv6, atypel = unknownv6;
 
-       USED(atype);
-       USED(atypel);
-       qlock(f->ipifc);
-       r = v6lookup(f, remote, nil);
+       qlock(&f->ipifc->qlock);
+       r = v6lookup(f, remote, NULL);
        version = (memcmp(remote, v4prefix, IPv4off) == 0) ? V4 : V6;
        
        version = (memcmp(remote, v4prefix, IPv4off) == 0) ? V4 : V6;
        
-       if(r != nil){
-               ifc = r->ifc;
-               if(r->type & Rv4)
+       if(r != NULL){
+               ifc = r->rt.ifc;
+               if(r->rt.type & Rv4)
                        v4tov6(gate, r->v4.gate);
                else {
                        ipmove(gate, r->v6.gate);
                        v4tov6(gate, r->v4.gate);
                else {
                        ipmove(gate, r->v6.gate);
@@ -1339,16 +1352,16 @@ findlocalip(Fs *f, uchar *local, uchar *remote)
        }
 
 out:
        }
 
 out:
-       qunlock(f->ipifc);
+       qunlock(&f->ipifc->qlock);
 }
 
 /*
  *  return first v4 address associated with an interface
  */
 int
 }
 
 /*
  *  return first v4 address associated with an interface
  */
 int
-ipv4local(Ipifc *ifc, uchar *addr)
+ipv4local(struct Ipifc *ifc, uint8_t *addr)
 {
 {
-       Iplifc *lifc;
+       struct Iplifc *lifc;
 
        for(lifc = ifc->lifc; lifc; lifc = lifc->next){
                if(isv4(lifc->local)){
 
        for(lifc = ifc->lifc; lifc; lifc = lifc->next){
                if(isv4(lifc->local)){
@@ -1363,9 +1376,9 @@ ipv4local(Ipifc *ifc, uchar *addr)
  *  return first v6 address associated with an interface
  */
 int
  *  return first v6 address associated with an interface
  */
 int
-ipv6local(Ipifc *ifc, uchar *addr)
+ipv6local(struct Ipifc *ifc, uint8_t *addr)
 {
 {
-       Iplifc *lifc;
+       struct Iplifc *lifc;
 
        for(lifc = ifc->lifc; lifc; lifc = lifc->next){
                if(!isv4(lifc->local) && !(lifc->tentative)){
 
        for(lifc = ifc->lifc; lifc; lifc = lifc->next){
                if(!isv4(lifc->local) && !(lifc->tentative)){
@@ -1377,9 +1390,9 @@ ipv6local(Ipifc *ifc, uchar *addr)
 }
 
 int
 }
 
 int
-ipv6anylocal(Ipifc *ifc, uchar *addr)
+ipv6anylocal(struct Ipifc *ifc, uint8_t *addr)
 {
 {
-       Iplifc *lifc;
+       struct Iplifc *lifc;
 
        for(lifc = ifc->lifc; lifc; lifc = lifc->next){
                if(!isv4(lifc->local)){
 
        for(lifc = ifc->lifc; lifc; lifc = lifc->next){
                if(!isv4(lifc->local)){
@@ -1393,15 +1406,15 @@ ipv6anylocal(Ipifc *ifc, uchar *addr)
 /*
  *  see if this address is bound to the interface
  */
 /*
  *  see if this address is bound to the interface
  */
-Iplifc*
-iplocalonifc(Ipifc *ifc, uchar *ip)
+struct Iplifc*
+iplocalonifc(struct Ipifc *ifc, uint8_t *ip)
 {
 {
-       Iplifc *lifc;
+       struct Iplifc *lifc;
 
        for(lifc = ifc->lifc; lifc; lifc = lifc->next)
                if(ipcmp(ip, lifc->local) == 0)
                        return lifc;
 
        for(lifc = ifc->lifc; lifc; lifc = lifc->next)
                if(ipcmp(ip, lifc->local) == 0)
                        return lifc;
-       return nil;
+       return NULL;
 }
 
 
 }
 
 
@@ -1409,17 +1422,17 @@ iplocalonifc(Ipifc *ifc, uchar *ip)
  *  See if we're proxying for this address on this interface
  */
 int
  *  See if we're proxying for this address on this interface
  */
 int
-ipproxyifc(Fs *f, Ipifc *ifc, uchar *ip)
+ipproxyifc(struct Fs *f, struct Ipifc *ifc, uint8_t *ip)
 {
 {
-       Route *r;
-       uchar net[IPaddrlen];
-       Iplifc *lifc;
+       struct route *r;
+       uint8_t net[IPaddrlen];
+       struct Iplifc *lifc;
 
        /* see if this is a direct connected pt to pt address */
 
        /* see if this is a direct connected pt to pt address */
-       r = v6lookup(f, ip, nil);
-       if(r == nil)
+       r = v6lookup(f, ip, NULL);
+       if(r == NULL)
                return 0;
                return 0;
-       if((r->type & (Rifc|Rproxy)) != (Rifc|Rproxy))
+       if((r->rt.type & (Rifc|Rproxy)) != (Rifc|Rproxy))
                return 0;
 
        /* see if this is on the right interface */
                return 0;
 
        /* see if this is on the right interface */
@@ -1436,7 +1449,7 @@ ipproxyifc(Fs *f, Ipifc *ifc, uchar *ip)
  *  return multicast version if any
  */
 int
  *  return multicast version if any
  */
 int
-ipismulticast(uchar *ip)
+ipismulticast(uint8_t *ip)
 {
        if(isv4(ip)){
                if(ip[IPv4off] >= 0xe0 && ip[IPv4off] < 0xf0)
 {
        if(isv4(ip)){
                if(ip[IPv4off] >= 0xe0 && ip[IPv4off] < 0xf0)
@@ -1449,7 +1462,7 @@ ipismulticast(uchar *ip)
 }
 
 int
 }
 
 int
-ipisbm(uchar *ip)
+ipisbm(uint8_t *ip)
 {
        if(isv4(ip)){
                if(ip[IPv4off] >= 0xe0 && ip[IPv4off] < 0xf0)
 {
        if(isv4(ip)){
                if(ip[IPv4off] >= 0xe0 && ip[IPv4off] < 0xf0)
@@ -1468,13 +1481,14 @@ ipisbm(uchar *ip)
  *  add a multicast address to an interface, called with c locked
  */
 void
  *  add a multicast address to an interface, called with c locked
  */
 void
-ipifcaddmulti(Conv *c, uchar *ma, uchar *ia)
+ipifcaddmulti(struct conv *c, uint8_t *ma, uint8_t *ia)
 {
 {
-       Ipifc *ifc;
-       Iplifc *lifc;
-       Conv **p;
-       Ipmulti *multi, **l;
-       Fs *f;
+       ERRSTACK(2);
+       struct Ipifc *ifc;
+       struct Iplifc *lifc;
+       struct conv **p;
+       struct Ipmulti *multi, **l;
+       struct Fs *f;
 
        f = c->p->f;
        
 
        f = c->p->f;
        
@@ -1483,24 +1497,24 @@ ipifcaddmulti(Conv *c, uchar *ma, uchar *ia)
                if(ipcmp(ia, (*l)->ia) == 0)
                        return;         /* it's already there */
 
                if(ipcmp(ia, (*l)->ia) == 0)
                        return;         /* it's already there */
 
-       multi = *l = smalloc(sizeof(*multi));
+       multi = *l = kzmalloc(sizeof(*multi), 0);
        ipmove(multi->ma, ma);
        ipmove(multi->ia, ia);
        ipmove(multi->ma, ma);
        ipmove(multi->ia, ia);
-       multi->next = nil;
+       multi->next = NULL;
 
        for(p = f->ipifc->conv; *p; p++){
                if((*p)->inuse == 0)
                        continue;
 
        for(p = f->ipifc->conv; *p; p++){
                if((*p)->inuse == 0)
                        continue;
-               ifc = (Ipifc*)(*p)->ptcl;
+               ifc = (struct Ipifc*)(*p)->ptcl;
                if(waserror()){
                if(waserror()){
-                       wunlock(ifc);
+                       wunlock(&ifc->rwlock);
                        nexterror();
                }
                        nexterror();
                }
-               wlock(ifc);
+               wlock(&ifc->rwlock);
                for(lifc = ifc->lifc; lifc; lifc = lifc->next)
                        if(ipcmp(ia, lifc->local) == 0)
                                addselfcache(f, ifc, lifc, ma, Rmulti);
                for(lifc = ifc->lifc; lifc; lifc = lifc->next)
                        if(ipcmp(ia, lifc->local) == 0)
                                addselfcache(f, ifc, lifc, ma, Rmulti);
-               wunlock(ifc);
+               wunlock(&ifc->rwlock);
                poperror();
        }
 }
                poperror();
        }
 }
@@ -1510,13 +1524,14 @@ ipifcaddmulti(Conv *c, uchar *ma, uchar *ia)
  *  remove a multicast address from an interface, called with c locked
  */
 void
  *  remove a multicast address from an interface, called with c locked
  */
 void
-ipifcremmulti(Conv *c, uchar *ma, uchar *ia)
+ipifcremmulti(struct conv *c, uint8_t *ma, uint8_t *ia)
 {
 {
-       Ipmulti *multi, **l;
-       Iplifc *lifc;
-       Conv **p;
-       Ipifc *ifc;
-       Fs *f;
+       ERRSTACK(2);
+       struct Ipmulti *multi, **l;
+       struct Iplifc *lifc;
+       struct conv **p;
+       struct Ipifc *ifc;
+       struct Fs *f;
 
        f = c->p->f;
        
 
        f = c->p->f;
        
@@ -1526,7 +1541,7 @@ ipifcremmulti(Conv *c, uchar *ma, uchar *ia)
                        break;
 
        multi = *l;
                        break;
 
        multi = *l;
-       if(multi == nil)
+       if(multi == NULL)
                return;         /* we don't have it open */
 
        *l = multi->next;
                return;         /* we don't have it open */
 
        *l = multi->next;
@@ -1535,63 +1550,61 @@ ipifcremmulti(Conv *c, uchar *ma, uchar *ia)
                if((*p)->inuse == 0)
                        continue;
 
                if((*p)->inuse == 0)
                        continue;
 
-               ifc = (Ipifc*)(*p)->ptcl;
+               ifc = (struct Ipifc*)(*p)->ptcl;
                if(waserror()){
                if(waserror()){
-                       wunlock(ifc);
+                       wunlock(&ifc->rwlock);
                        nexterror();
                }
                        nexterror();
                }
-               wlock(ifc);
+               wlock(&ifc->rwlock);
                for(lifc = ifc->lifc; lifc; lifc = lifc->next)
                        if(ipcmp(ia, lifc->local) == 0)
                                remselfcache(f, ifc, lifc, ma);
                for(lifc = ifc->lifc; lifc; lifc = lifc->next)
                        if(ipcmp(ia, lifc->local) == 0)
                                remselfcache(f, ifc, lifc, ma);
-               wunlock(ifc);
+               wunlock(&ifc->rwlock);
                poperror();
        }
 
                poperror();
        }
 
-       free(multi);
+       kfree(multi);
 }
 
 /*
  *  make lifc's join and leave multicast groups
  */
 static char*
 }
 
 /*
  *  make lifc's join and leave multicast groups
  */
 static char*
-ipifcjoinmulti(Ipifc *ifc, char **argv, int argc)
+ipifcjoinmulti(struct Ipifc *ifc, char **argv, int argc)
 {
 {
-       USED(ifc, argv, argc);
-       return nil;
+       return NULL;
 }
 
 static char*
 }
 
 static char*
-ipifcleavemulti(Ipifc *ifc, char **argv, int argc)
+ipifcleavemulti(struct Ipifc *ifc, char **argv, int argc)
 {
 {
-       USED(ifc, argv, argc);
-       return nil;
+       return NULL;
 }
 
 static void
 }
 
 static void
-ipifcregisterproxy(Fs *f, Ipifc *ifc, uchar *ip)
+ipifcregisterproxy(struct Fs *f, struct Ipifc *ifc, uint8_t *ip)
 {
 {
-       Conv **cp, **e;
-       Ipifc *nifc;
-       Iplifc *lifc;
-       Medium *m;
-       uchar net[IPaddrlen];
+       struct conv **cp, **e;
+       struct Ipifc *nifc;
+       struct Iplifc *lifc;
+       struct medium *m;
+       uint8_t net[IPaddrlen];
 
        /* register the address on any network that will proxy for us */
        e = &f->ipifc->conv[f->ipifc->nc];
 
        if(!isv4(ip)) { // V6
                for(cp = f->ipifc->conv; cp < e; cp++){
 
        /* register the address on any network that will proxy for us */
        e = &f->ipifc->conv[f->ipifc->nc];
 
        if(!isv4(ip)) { // V6
                for(cp = f->ipifc->conv; cp < e; cp++){
-                       if(*cp == nil)
+                       if(*cp == NULL)
                                continue;
                                continue;
-                       nifc = (Ipifc*)(*cp)->ptcl;
+                       nifc = (struct Ipifc*)(*cp)->ptcl;
                        if(nifc == ifc)
                                continue;
        
                        if(nifc == ifc)
                                continue;
        
-                       rlock(nifc);
+                       rlock(&nifc->rwlock);
                        m = nifc->m;
                        m = nifc->m;
-                       if(m == nil || m->addmulti == nil) {
-                               runlock(nifc);
+                       if(m == NULL || m->addmulti == NULL) {
+                               runlock(&nifc->rwlock);
                                continue;
                        }
                        for(lifc = nifc->lifc; lifc; lifc = lifc->next){
                                continue;
                        }
                        for(lifc = nifc->lifc; lifc; lifc = lifc->next){
@@ -1604,22 +1617,22 @@ ipifcregisterproxy(Fs *f, Ipifc *ifc, uchar *ip)
                                        break;
                                }
                        }
                                        break;
                                }
                        }
-                       runlock(nifc);
+                       runlock(&nifc->rwlock);
                }
                return;
        }
        else { // V4
                for(cp = f->ipifc->conv; cp < e; cp++){
                }
                return;
        }
        else { // V4
                for(cp = f->ipifc->conv; cp < e; cp++){
-                       if(*cp == nil)
+                       if(*cp == NULL)
                                continue;
                                continue;
-                       nifc = (Ipifc*)(*cp)->ptcl;
+                       nifc = (struct Ipifc*)(*cp)->ptcl;
                        if(nifc == ifc)
                                continue;
        
                        if(nifc == ifc)
                                continue;
        
-                       rlock(nifc);
+                       rlock(&nifc->rwlock);
                        m = nifc->m;
                        m = nifc->m;
-                       if(m == nil || m->areg == nil){
-                               runlock(nifc);
+                       if(m == NULL || m->areg == NULL){
+                               runlock(&nifc->rwlock);
                                continue;
                        }
                        for(lifc = nifc->lifc; lifc; lifc = lifc->next){
                                continue;
                        }
                        for(lifc = nifc->lifc; lifc; lifc = lifc->next){
@@ -1629,7 +1642,7 @@ ipifcregisterproxy(Fs *f, Ipifc *ifc, uchar *ip)
                                        break;
                                }
                        }
                                        break;
                                }
                        }
-                       runlock(nifc);
+                       runlock(&nifc->rwlock);
                }
        }
 }
                }
        }
 }
@@ -1637,13 +1650,13 @@ ipifcregisterproxy(Fs *f, Ipifc *ifc, uchar *ip)
 
 // added for new v6 mesg types
 static void
 
 // added for new v6 mesg types
 static void
-adddefroute6(Fs *f, uchar *gate, int force)
+adddefroute6(struct Fs *f, uint8_t *gate, int force)
 {
 {
-       Route *r;
+       struct route *r;
 
 
-       r = v6lookup(f, v6Unspecified, nil);
-       if(r!=nil)
-       if(!(force) && (strcmp(r->tag,"ra")!=0))        // route entries generated
+       r = v6lookup(f, v6Unspecified, NULL);
+       if(r!=NULL)
+       if(!(force) && (strcmp(r->rt.tag,"ra")!=0))     // route entries generated
                return;                 // by all other means take
                                        // precedence over router annc
 
                return;                 // by all other means take
                                        // precedence over router annc
 
@@ -1657,16 +1670,16 @@ enum
 };
 
 char*
 };
 
 char*
-ipifcaddpref6(Ipifc *ifc, char**argv, int argc)
+ipifcaddpref6(struct Ipifc *ifc, char**argv, int argc)
 {
 {
-       uchar   onlink = 1;
-       uchar   autoflag = 1;
+       uint8_t onlink = 1;
+       uint8_t autoflag = 1;
        long    validlt = 0xffffffff;
        long    preflt = 0xffffffff;
        long    origint = NOW / 10^3;
        long    validlt = 0xffffffff;
        long    preflt = 0xffffffff;
        long    origint = NOW / 10^3;
-       uchar   prefix[IPaddrlen];
+       uint8_t prefix[IPaddrlen];
        int     plen = 64;
        int     plen = 64;
-       Iplifc  *lifc;
+       struct Iplifc   *lifc;
        char    addr[40], preflen[6];
        char    *params[3];
 
        char    addr[40], preflen[6];
        char    *params[3];
 
@@ -1698,20 +1711,20 @@ ipifcaddpref6(Ipifc *ifc, char**argv, int argc)
        )
                return Ebadarg;
 
        )
                return Ebadarg;
 
-       lifc = smalloc(sizeof(Iplifc));
+       lifc = kzmalloc(sizeof(struct Iplifc), 0);
        lifc->onlink = (onlink!=0);
        lifc->autoflag = (autoflag!=0);
        lifc->validlt = validlt;
        lifc->preflt = preflt;
        lifc->origint = origint;
 
        lifc->onlink = (onlink!=0);
        lifc->autoflag = (autoflag!=0);
        lifc->validlt = validlt;
        lifc->preflt = preflt;
        lifc->origint = origint;
 
-       if(ifc->m->pref2addr!=nil)
+       if(ifc->m->pref2addr!=NULL)
                ifc->m->pref2addr(prefix, ifc->mac);
        else
                return Ebadarg;
        
                ifc->m->pref2addr(prefix, ifc->mac);
        else
                return Ebadarg;
        
-       sprint(addr, "%I", prefix);
-       sprint(preflen, "/%d", plen);
+       snprintf(addr, sizeof(addr), "%I", prefix);
+       snprintf(preflen, sizeof(preflen), "/%d", plen);
        params[0] = "add";
        params[1] = addr;
        params[2] = preflen;
        params[0] = "add";
        params[1] = addr;
        params[2] = preflen;
index 2fad0ea..685d602 100644 (file)
@@ -28,7 +28,7 @@ ptclbsum(uint8_t *addr, int len)
        mdsum = 0;
 
        x = 0;
        mdsum = 0;
 
        x = 0;
-       if((uint32_t)addr & 1) {
+       if((uintptr_t)addr & 1) {
                if(len) {
                        hisum += addr[0];
                        len--;
                if(len) {
                        hisum += addr[0];
                        len--;
@@ -72,7 +72,7 @@ ptclbsum(uint8_t *addr, int len)
 
        losum += hisum >> 8;
        losum += (hisum & 0xff) << 8;
 
        losum += hisum >> 8;
        losum += (hisum & 0xff) << 8;
-       while(hisum = losum>>16)
+       while((hisum = losum>>16))
                losum = hisum + (losum & 0xffff);
 
        return losum & 0xffff;
                losum = hisum + (losum & 0xffff);
 
        return losum & 0xffff;
index 5670912..9a0a48b 100644 (file)
@@ -1291,14 +1291,12 @@ if(c->umh != NULL){
        }
 
        poperror();
        }
 
        poperror();
-#warning "how big is genbuf?"
-       /* place final element in genbuf for e.g. exec */
-#if 0
+
        if(e.ARRAY_SIZEs > 0)
        if(e.ARRAY_SIZEs > 0)
-               kstrncpy(get_cur_genbuf(), e.elems[e.ARRAY_SIZEs-1],  sizeof current->genbuf, sizeof(current->genbuf, e.elems[e.ARRAY_SIZEs-1]));
+               strncpy(get_cur_genbuf(), e.elems[e.ARRAY_SIZEs-1], GENBUF_SZ);
        else
        else
-               kstrncpy(get_cur_genbuf(), ".",  sizeof current->genbuf, sizeof(current->genbuf, "."));
-#endif
+               strncpy(get_cur_genbuf(), ".", GENBUF_SZ);
+
        kfree(e.name);
        kfree(e.elems);
        kfree(e.off);
        kfree(e.name);
        kfree(e.elems);
        kfree(e.off);
index ceeb979..7fd63ca 100644 (file)
@@ -4,6 +4,24 @@
 +printd(
 ...)
 
 +printd(
 ...)
 
+@ kopen@
+@@
+-kopen(
++sysopen(
+...)
+
+@ kclose @
+@@
+-kclose(
++sysclose(
+...)
+
+@ kread@
+@@
+-kread(
++sysread(
+...)
+
 @ channel @
 identifier d;
 @@
 @ channel @
 identifier d;
 @@
index b3cb57a..aed5db4 100644 (file)
@@ -20,7 +20,7 @@ typedef Ipifc;
 typedef Iplifc;
 @@
 -Iplifc
 typedef Iplifc;
 @@
 -Iplifc
-+struct iplifc
++struct Iplifc
 
 @@
 typedef Ipv6rp;
 
 @@
 typedef Ipv6rp;
@@ -158,7 +158,7 @@ typedef Medium;
 typedef Proto;
 @@
 -Proto
 typedef Proto;
 @@
 -Proto
-+struct proto
++struct Proto
 
 @@
 typedef Arpent;
 
 @@
 typedef Arpent;