Removes dead code
authorBarret Rhoden <brho@cs.berkeley.edu>
Tue, 24 Jun 2014 18:06:26 +0000 (11:06 -0700)
committerBarret Rhoden <brho@cs.berkeley.edu>
Tue, 24 Jun 2014 18:06:26 +0000 (11:06 -0700)
Was not building any of this, and we can add it back in later if needed.

14 files changed:
kern/src/net/Kbuild
kern/src/net/bootp.c [deleted file]
kern/src/net/compress.c [deleted file]
kern/src/net/dhcp.c [deleted file]
kern/src/net/esp.c [deleted file]
kern/src/net/gre.c [deleted file]
kern/src/net/igmp.c [deleted file]
kern/src/net/ihbootp.c [deleted file]
kern/src/net/ipmux.c [deleted file]
kern/src/net/netdevmedium.c [deleted file]
kern/src/net/ppp.c [deleted file]
kern/src/net/ppp.h [deleted file]
kern/src/net/pppmedium.c [deleted file]
kern/src/net/rudp.c [deleted file]

index a87bfdc..8208fc0 100644 (file)
@@ -1,5 +1,4 @@
 obj-y                                          += arp.o
-#obj-y                                         += compress.o
 obj-y                                          += devip.o
 obj-y                                          += dial.o
 obj-y                                          += eipconv.o
@@ -15,7 +14,6 @@ obj-y                                         += iprouter.o
 obj-y                                          += ipifc.o
 obj-y                                          += loopbackmedium.o
 obj-y                                          += netaux.o
-obj-y                                          += netdevmedium.o
 obj-y                                          += netif.o
 obj-y                                          += netlog.o
 obj-y                                          += nullmedium.o
diff --git a/kern/src/net/bootp.c b/kern/src/net/bootp.c
deleted file mode 100644 (file)
index 556f225..0000000
+++ /dev/null
@@ -1,225 +0,0 @@
-#include "u.h"
-#include "../port/lib.h"
-#include "mem.h"
-#include "dat.h"
-#include "fns.h"
-#include "../port/error.h"
-#include "kernel.h"
-#include "ip.h"
-
-static ulong fsip;
-static ulong auip;
-static ulong gwip;
-static ulong ipmask;
-static ulong ipaddr;
-
-enum {
-       Bootrequest = 1,
-       Bootreply = 2,
-};
-
-typedef struct Bootp {
-       /* udp.c oldheader */
-       uchar raddr[IPaddrlen];
-       uchar laddr[IPaddrlen];
-       uchar rport[2];
-       uchar lport[2];
-       /* bootp itself */
-       uchar op;                                       /* opcode */
-       uchar htype;                            /* hardware type */
-       uchar hlen;                                     /* hardware address len */
-       uchar hops;                                     /* hops */
-       uchar xid[4];                           /* a random number */
-       uchar secs[2];                          /* elapsed snce client started booting */
-       uchar pad[2];
-       uchar ciaddr[4];                        /* client IP address (client tells server) */
-       uchar yiaddr[4];                        /* client IP address (server tells client) */
-       uchar siaddr[4];                        /* server IP address */
-       uchar giaddr[4];                        /* gateway IP address */
-       uchar chaddr[16];                       /* client hardware address */
-       uchar sname[64];                        /* server host name (optional) */
-       uchar file[128];                        /* boot file name */
-       uchar vend[128];                        /* vendor-specific goo */
-} Bootp;
-
-/*
- * bootp returns:
- *
- * "fsip d.d.d.d
- * auip d.d.d.d
- * gwip d.d.d.d
- * ipmask d.d.d.d
- * ipaddr d.d.d.d"
- *
- * where d.d.d.d is the IP address in dotted decimal notation, and each
- * address is followed by a newline.
- */
-
-static Bootp req;
-static Proc *rcvprocp;
-static int recv;
-static int done;
-static Rendez bootpr;
-static char rcvbuf[512 + 2 * IPaddrlen + 2 * 2];
-
-static void rcvbootp(void *a)
-{
-       int n, fd;
-       Bootp *rp;
-       char *field[4];
-       uchar ip[IPaddrlen];
-
-       if (waserror())
-               pexit("", 0);
-       rcvprocp = up;  /* store for postnote below */
-       fd = (int)a;
-       while (done == 0) {
-               n = kread(fd, rcvbuf, sizeof(rcvbuf));
-               if (n <= 0)
-                       break;
-               rp = (Bootp *) rcvbuf;
-               /* currently ignore udp's header */
-               if (memcmp(req.chaddr, rp->chaddr, 6) == 0
-                       && rp->htype == 1 && rp->hlen == 6
-                       && getfields((char *)rp->vend + 4, field, 4, 1, " ") == 4
-                       && strncmp((char *)rp->vend, "p9  ", 4) == 0) {
-                       if (ipaddr == 0)
-                               ipaddr = nhgetl(rp->yiaddr);
-                       if (ipmask == 0)
-                               ipmask = parseip(ip, field[0]);
-                       if (fsip == 0)
-                               fsip = parseip(ip, field[1]);
-                       if (auip == 0)
-                               auip = parseip(ip, field[2]);
-                       if (gwip == 0)
-                               gwip = parseip(ip, field[3]);
-                       break;
-               }
-       }
-       poperror();
-       rcvprocp = nil;
-
-       recv = 1;
-       rendez_wakeup(&bootpr);
-       pexit("", 0);
-}
-
-static char *rbootp(Ipifc * ifc)
-{
-       int cfd, dfd, tries, n;
-       char ia[5 + 3 * 24], im[16], *av[3];
-       uchar nipaddr[4], ngwip[4], nipmask[4];
-       char dir[Maxpath];
-
-       av[1] = "0.0.0.0";
-       av[2] = "0.0.0.0";
-       ipifcadd(ifc, av, 3, 0, nil);
-
-       cfd = kannounce("udp!*!68", dir);
-       if (cfd < 0)
-               return "bootp announce failed";
-       strcat(dir, "/data");
-       if (kwrite(cfd, "headers", 7) < 0) {
-               kclose(cfd);
-               return "bootp ctl headers failed";
-       }
-       kwrite(cfd, "oldheaders", 10);
-       dfd = kopen(dir, ORDWR);
-       if (dfd < 0) {
-               kclose(cfd);
-               return "bootp open data failed";
-       }
-       kclose(cfd);
-
-       /* create request */
-       memset(&req, 0, sizeof(req));
-       ipmove(req.raddr, IPv4bcast);
-       hnputs(req.rport, 67);
-       req.op = Bootrequest;
-       req.htype = 1;  /* ethernet (all we know) */
-       req.hlen = 6;   /* ethernet (all we know) */
-
-       /* Hardware MAC address */
-       memmove(req.chaddr, ifc->mac, 6);
-       /* Fill in the local IP address if we know it */
-       ipv4local(ifc, req.ciaddr);
-       memset(req.file, 0, sizeof(req.file));
-       strcpy((char *)req.vend, "p9  ");
-
-       done = 0;
-       recv = 0;
-
-       ktask("rcvbootp", rcvbootp, (void *)dfd);
-
-       /*
-        * broadcast bootp's till we get a reply,
-        * or fixed number of tries
-        */
-       tries = 0;
-       while (recv == 0) {
-               if (kwrite(dfd, &req, sizeof(req)) < 0)
-                       print("bootp: write: %s\n", commonerror());
-
-               udelay_sched(1000 * 1000);
-               if (++tries > 10) {
-                       print("bootp: timed out\n");
-                       break;
-               }
-       }
-       kclose(dfd);
-       done = 1;
-       if (rcvprocp != nil) {
-               postnote(rcvprocp, 1, "timeout", 0);
-               rcvprocp = nil;
-       }
-
-       av[1] = "0.0.0.0";
-       av[2] = "0.0.0.0";
-       ipifcrem(ifc, av, 3);
-
-       hnputl(nipaddr, ipaddr);
-       sprint(ia, "%V", nipaddr);
-       hnputl(nipmask, ipmask);
-       sprint(im, "%V", nipmask);
-       av[1] = ia;
-       av[2] = im;
-       ipifcadd(ifc, av, 3, 0, nil);
-
-       if (gwip != 0) {
-               hnputl(ngwip, gwip);
-               n = snprint(ia, sizeof(ia), "add 0.0.0.0 0.0.0.0 %V", ngwip);
-               routewrite(ifc->conv->p->f, nil, ia, n);
-       }
-       return nil;
-}
-
-static int rbootpread(char *bp, ulong offset, int len)
-{
-       int n;
-       char *buf;
-       uchar a[4];
-
-       buf = smalloc(READSTR);
-       if (waserror()) {
-               free(buf);
-               nexterror();
-       }
-       hnputl(a, fsip);
-       n = snprint(buf, READSTR, "fsip %15V\n", a);
-       hnputl(a, auip);
-       n += snprint(buf + n, READSTR - n, "auip %15V\n", a);
-       hnputl(a, gwip);
-       n += snprint(buf + n, READSTR - n, "gwip %15V\n", a);
-       hnputl(a, ipmask);
-       n += snprint(buf + n, READSTR - n, "ipmask %15V\n", a);
-       hnputl(a, ipaddr);
-       snprint(buf + n, READSTR - n, "ipaddr %15V\n", a);
-
-       len = readstr(offset, bp, len, buf);
-       poperror();
-       free(buf);
-       return len;
-}
-
-char *(*bootp) (Ipifc *) = rbootp;
-int (*bootpread) (char *, ulong, int) = rbootpread;
diff --git a/kern/src/net/compress.c b/kern/src/net/compress.c
deleted file mode 100644 (file)
index 8e0600d..0000000
+++ /dev/null
@@ -1,516 +0,0 @@
-// 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 Ilhdr Ilhdr;
-typedef struct Hdr Hdr;
-typedef struct Tcpc Tcpc;
-
-struct Iphdr {
-       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 {
-       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 {
-       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 {
-       URG = 0x20,                                     /* Data marked urgent */
-       ACK = 0x10,     /* Aknowledge is valid */
-       PSH = 0x08,     /* Whole data pipe is pushed */
-       RST = 0x04,     /* Reset connection */
-       SYN = 0x02,     /* Pkt. is synchronise */
-       FIN = 0x01,     /* Start close down */
-
-       IP_DF = 0x4000, /* Don't fragment */
-
-       IP_TCPPROTO = 6,
-       IP_ILPROTO = 40,
-       IL_IPHDR = 20,
-};
-
-struct Hdr {
-       uint8_t buf[128];
-       Iphdr *ip;
-       Tcphdr *tcp;
-       int len;
-};
-
-struct Tcpc {
-       uint8_t lastrecv;
-       uint8_t lastxmit;
-       uint8_t basexmit;
-       uint8_t err;
-       uint8_t compressid;
-       Hdr t[MAX_STATES];
-       Hdr r[MAX_STATES];
-};
-
-enum {                                                 /* flag bits for what changed in a packet */
-       NEW_U = (1 << 0),                       /* tcp only */
-       NEW_W = (1 << 1),       /* tcp only */
-       NEW_A = (1 << 2),       /* il tcp */
-       NEW_S = (1 << 3),       /* tcp only */
-       NEW_P = (1 << 4),       /* tcp only */
-       NEW_I = (1 << 5),       /* il tcp */
-       NEW_C = (1 << 6),       /* il tcp */
-       NEW_T = (1 << 7),       /* il only */
-       TCP_PUSH_BIT = 0x10,
-};
-
-/* reserved, special-case values of above for tcp */
-#define SPECIAL_I (NEW_S|NEW_W|NEW_U)  /* echoed interactive traffic */
-#define SPECIAL_D (NEW_S|NEW_A|NEW_W|NEW_U)    /* unidirectional data */
-#define SPECIALS_MASK (NEW_S|NEW_A|NEW_W|NEW_U)
-
-int encode(void *p, uint32_t n)
-{
-       uint8_t *cp;
-
-       cp = p;
-       if (n >= 256 || n == 0) {
-               *cp++ = 0;
-               cp[0] = n >> 8;
-               cp[1] = n;
-               return 3;
-       } else
-               *cp = n;
-       return 1;
-}
-
-#define DECODEL(f) { \
-       if (*cp == 0) {\
-               hnputl(f, nhgetl(f) + ((cp[1] << 8) | cp[2])); \
-               cp += 3; \
-       } else { \
-               hnputl(f, nhgetl(f) + (uint32_t)*cp++); \
-       } \
-}
-#define DECODES(f) { \
-       if (*cp == 0) {\
-               hnputs(f, nhgets(f) + ((cp[1] << 8) | cp[2])); \
-               cp += 3; \
-       } else { \
-               hnputs(f, nhgets(f) + (uint32_t)*cp++); \
-       } \
-}
-
-uint16_t tcpcompress(Tcpc * comp, struct block * b, struct Fs *)
-{
-       Iphdr *ip;                                      /* current packet */
-       Tcphdr *tcp;                            /* current pkt */
-       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;
-
-       /*
-        * Bail if this is not a compressible TCP/IP packet
-        */
-       ip = (Iphdr *) b->rp;
-       iplen = (ip->vihl & 0xf) << 2;
-       tcp = (Tcphdr *) (b->rp + iplen);
-       tcplen = (tcp->flag[0] & 0xf0) >> 2;
-       hlen = iplen + tcplen;
-       if ((tcp->flag[1] & (SYN | FIN | RST | ACK)) != ACK)
-               return Pip;     /* connection control */
-
-       /*
-        * Packet is compressible, look for a connection
-        */
-       changes = 0;
-       cp = new_seq;
-       j = comp->lastxmit;
-       h = &comp->t[j];
-       if (ip->src != h->ip->src || ip->dst != h->ip->dst
-               || tcp->ports != h->tcp->ports) {
-               for (i = 0; i < MAX_STATES; ++i) {
-                       j = (comp->basexmit + i) % MAX_STATES;
-                       h = &comp->t[j];
-                       if (ip->src == h->ip->src && ip->dst == h->ip->dst
-                               && tcp->ports == h->tcp->ports)
-                               goto found;
-               }
-
-               /* no connection, reuse the oldest */
-               if (i == MAX_STATES) {
-                       j = comp->basexmit;
-                       j = (j + MAX_STATES - 1) % MAX_STATES;
-                       comp->basexmit = j;
-                       h = &comp->t[j];
-                       goto raise;
-               }
-       }
-found:
-
-       /*
-        * Make sure that only what we expect to change changed. 
-        */
-       if (ip->vihl != h->ip->vihl || ip->tos != h->ip->tos ||
-               ip->ttl != h->ip->ttl || ip->proto != h->ip->proto)
-               goto raise;     /* headers changed */
-       if (iplen != sizeof(Iphdr)
-               && memcmp(ip + 1, h->ip + 1, iplen - sizeof(Iphdr)))
-               goto raise;     /* ip options changed */
-       if (tcplen != sizeof(Tcphdr)
-               && memcmp(tcp + 1, h->tcp + 1, tcplen - sizeof(Tcphdr)))
-               goto raise;     /* tcp options changed */
-
-       if (tcp->flag[1] & URG) {
-               cp += encode(cp, nhgets(tcp->urg));
-               changes |= NEW_U;
-       } else if (memcmp(tcp->urg, h->tcp->urg, sizeof(tcp->urg)) != 0)
-               goto raise;
-       if (deltaS = nhgets(tcp->win) - nhgets(h->tcp->win)) {
-               cp += encode(cp, deltaS);
-               changes |= NEW_W;
-       }
-       if (deltaA = nhgetl(tcp->ack) - nhgetl(h->tcp->ack)) {
-               if (deltaA > 0xffff)
-                       goto raise;
-               cp += encode(cp, deltaA);
-               changes |= NEW_A;
-       }
-       if (deltaS = nhgetl(tcp->seq) - nhgetl(h->tcp->seq)) {
-               if (deltaS > 0xffff)
-                       goto raise;
-               cp += encode(cp, deltaS);
-               changes |= NEW_S;
-       }
-
-       /*
-        * Look for the special-case encodings.
-        */
-       switch (changes) {
-               case 0:
-                       /*
-                        * Nothing changed. If this packet contains data and the last
-                        * one didn't, this is probably a data packet following an
-                        * ack (normal on an interactive connection) and we send it
-                        * compressed. Otherwise it's probably a retransmit,
-                        * retransmitted ack or window probe.  Send it uncompressed
-                        * in case the other side missed the compressed version.
-                        */
-                       if (nhgets(ip->length) == nhgets(h->ip->length) ||
-                               nhgets(h->ip->length) != hlen)
-                               goto raise;
-                       break;
-               case SPECIAL_I:
-               case SPECIAL_D:
-                       /*
-                        * Actual changes match one of our special case encodings --
-                        * send packet uncompressed.
-                        */
-                       goto raise;
-               case NEW_S | NEW_A:
-                       if (deltaS == deltaA && deltaS == nhgets(h->ip->length) - hlen) {
-                               /* special case for echoed terminal traffic */
-                               changes = SPECIAL_I;
-                               cp = new_seq;
-                       }
-                       break;
-               case NEW_S:
-                       if (deltaS == nhgets(h->ip->length) - hlen) {
-                               /* special case for data xfer */
-                               changes = SPECIAL_D;
-                               cp = new_seq;
-                       }
-                       break;
-       }
-       deltaS = nhgets(ip->id) - nhgets(h->ip->id);
-       if (deltaS != 1) {
-               cp += encode(cp, deltaS);
-               changes |= NEW_I;
-       }
-       if (tcp->flag[1] & PSH)
-               changes |= TCP_PUSH_BIT;
-       /*
-        * Grab the cksum before we overwrite it below. Then update our
-        * state with this packet's header.
-        */
-       deltaA = nhgets(tcp->cksum);
-       memmove(h->buf, b->rp, hlen);
-       h->len = hlen;
-       h->tcp = (Tcphdr *) (h->buf + iplen);
-
-       /*
-        * We want to use the original packet as our compressed packet. (cp -
-        * new_seq) is the number of bytes we need for compressed sequence
-        * numbers. In addition we need one byte for the change mask, one
-        * for the connection id and two for the tcp checksum. So, (cp -
-        * new_seq) + 4 bytes of header are needed. hlen is how many bytes
-        * of the original packet to toss so subtract the two to get the new
-        * packet size. The temporaries are gross -egs.
-        */
-       deltaS = cp - new_seq;
-       cp = b->rp;
-       if (comp->lastxmit != j || comp->compressid == 0) {
-               comp->lastxmit = j;
-               hlen -= deltaS + 4;
-               cp += hlen;
-               *cp++ = (changes | NEW_C);
-               *cp++ = j;
-       } else {
-               hlen -= deltaS + 3;
-               cp += hlen;
-               *cp++ = changes;
-       }
-       b->rp += hlen;
-       hnputs(cp, deltaA);
-       cp += 2;
-       memmove(cp, new_seq, deltaS);
-       return Pvjctcp;
-
-raise:
-       /*
-        * Update connection state & send uncompressed packet
-        */
-       memmove(h->buf, b->rp, hlen);
-       h->tcp = (Tcphdr *) (h->buf + iplen);
-       h->len = hlen;
-       h->ip->proto = j;
-       comp->lastxmit = j;
-       return Pvjutcp;
-}
-
-struct block *tcpuncompress(Tcpc * comp, struct block *b, uint16_t type,
-                                                       struct Fs *f)
-{
-       uint8_t *cp, changes;
-       int i;
-       int iplen, len;
-       Iphdr *ip;
-       Tcphdr *tcp;
-       Hdr *h;
-
-       if (type == Pvjutcp) {
-               /*
-                *  Locate the saved state for this connection. If the state
-                *  index is legal, clear the 'discard' flag.
-                */
-               ip = (Iphdr *) b->rp;
-               if (ip->proto >= MAX_STATES)
-                       goto raise;
-               iplen = (ip->vihl & 0xf) << 2;
-               tcp = (Tcphdr *) (b->rp + iplen);
-               comp->lastrecv = ip->proto;
-               len = iplen + ((tcp->flag[0] & 0xf0) >> 2);
-               comp->err = 0;
-               netlog(f, Logcompress, "uncompressed %d\n", comp->lastrecv);
-               /*
-                * Restore the IP protocol field then save a copy of this
-                * packet header. The checksum is zeroed in the copy so we
-                * don't have to zero it each time we process a compressed
-                * packet.
-                */
-               ip->proto = IP_TCPPROTO;
-               h = &comp->r[comp->lastrecv];
-               memmove(h->buf, b->rp, len);
-               h->tcp = (Tcphdr *) (h->buf + iplen);
-               h->len = len;
-               h->ip->cksum[0] = h->ip->cksum[1] = 0;
-               return b;
-       }
-
-       cp = b->rp;
-       changes = *cp++;
-       if (changes & NEW_C) {
-               /*
-                * Make sure the state index is in range, then grab the
-                * state. If we have a good state index, clear the 'discard'
-                * flag.
-                */
-               if (*cp >= MAX_STATES)
-                       goto raise;
-               comp->err = 0;
-               comp->lastrecv = *cp++;
-               netlog(f, Logcompress, "newc %d\n", comp->lastrecv);
-       } else {
-               /*
-                * This packet has no state index. If we've had a
-                * line error since the last time we got an explicit state
-                * index, we have to toss the packet.
-                */
-               if (comp->err != 0) {
-                       freeblist(b);
-                       return NULL;
-               }
-               netlog(f, Logcompress, "oldc %d\n", comp->lastrecv);
-       }
-
-       /*
-        * Find the state then fill in the TCP checksum and PUSH bit.
-        */
-       h = &comp->r[comp->lastrecv];
-       ip = h->ip;
-       tcp = h->tcp;
-       len = h->len;
-       memmove(tcp->cksum, cp, sizeof tcp->cksum);
-       cp += 2;
-       if (changes & TCP_PUSH_BIT)
-               tcp->flag[1] |= PSH;
-       else
-               tcp->flag[1] &= ~PSH;
-       /*
-        * Fix up the state's ack, seq, urg and win fields based on the
-        * changemask.
-        */
-       switch (changes & SPECIALS_MASK) {
-               case SPECIAL_I:
-                       i = nhgets(ip->length) - len;
-                       hnputl(tcp->ack, nhgetl(tcp->ack) + i);
-                       hnputl(tcp->seq, nhgetl(tcp->seq) + i);
-                       break;
-
-               case SPECIAL_D:
-                       hnputl(tcp->seq, nhgetl(tcp->seq) + nhgets(ip->length) - len);
-                       break;
-
-               default:
-                       if (changes & NEW_U) {
-                               tcp->flag[1] |= URG;
-                               if (*cp == 0) {
-                                       hnputs(tcp->urg, nhgets(cp + 1));
-                                       cp += 3;
-                               } else {
-                                       hnputs(tcp->urg, *cp++);
-                               }
-                       } else {
-                               tcp->flag[1] &= ~URG;
-                       }
-                       if (changes & NEW_W)
-                               DECODES(tcp->win)
-                                       if (changes & NEW_A)
-                                       DECODEL(tcp->ack)
-                                               if (changes & NEW_S)
-                                               DECODEL(tcp->seq)
-                                                       break;
-       }
-
-       /* Update the IP ID */
-       if (changes & NEW_I)
-               DECODES(ip->id)
-                       else
-               hnputs(ip->id, nhgets(ip->id) + 1);
-
-       /*
-        *  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
-        *  up to 128 bytes of header.
-        */
-       b->rp = cp;
-       if (b->rp - b->base < len) {
-               b = padblock(b, len);
-               b = pullupblock(b, blocklen(b));
-       } else
-               b->rp -= len;
-       hnputs(ip->length, BLEN(b));
-       memmove(b->rp, ip, len);
-
-       /* recompute the ip header checksum */
-       ip = (Iphdr *) b->rp;
-       hnputs(ip->cksum, ipcsum(b->rp));
-       return b;
-
-raise:
-       netlog(f, Logcompress, "Bad Packet!\n");
-       comp->err = 1;
-       freeblist(b);
-       return NULL;
-}
-
-Tcpc *compress_init(Tcpc * c)
-{
-       int i;
-       Hdr *h;
-
-       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++) {
-               h = &c->t[i];
-               h->ip = (Iphdr *) h->buf;
-               h->tcp = (Tcphdr *) (h->buf + 10);
-               h->len = 20;
-               h = &c->r[i];
-               h->ip = (Iphdr *) h->buf;
-               h->tcp = (Tcphdr *) (h->buf + 10);
-               h->len = 20;
-       }
-
-       return c;
-}
-
-uint16_t compress(Tcpc * tcp, struct block * b, struct Fs * f)
-{
-       Iphdr *ip;
-
-       /*
-        * Bail if this is not a compressible IP packet
-        */
-       ip = (Iphdr *) b->rp;
-       if ((nhgets(ip->frag) & 0x3fff) != 0)
-               return Pip;
-
-       switch (ip->proto) {
-               case IP_TCPPROTO:
-                       return tcpcompress(tcp, b, f);
-               default:
-                       return Pip;
-       }
-}
-
-int compress_negotiate(Tcpc * tcp, uint8_t * data)
-{
-       if (data[0] != MAX_STATES - 1)
-               return -1;
-       tcp->compressid = data[1];
-       return 0;
-}
diff --git a/kern/src/net/dhcp.c b/kern/src/net/dhcp.c
deleted file mode 100644 (file)
index 81b687d..0000000
+++ /dev/null
@@ -1,480 +0,0 @@
-#include "u.h"
-#include "../port/lib.h"
-#include "mem.h"
-#include "dat.h"
-#include "fns.h"
-#include "../port/error.h"
-#include "kernel.h"
-#include "ip.h"
-#include "ppp.h"
-
-Ipaddr pppdns[2];
-
-static ulong fsip;
-static ulong auip;
-static ulong gwip;
-static ulong ipmask;
-static ulong ipaddr;
-static ulong dns1ip;
-static ulong dns2ip;
-
-int dhcpmsgtype;
-int debug = 0;
-enum {
-       Bootrequest = 1,
-       Bootreply = 2,
-};
-
-typedef struct Bootp {
-       /* udp.c oldheader */
-       uchar raddr[IPaddrlen];
-       uchar laddr[IPaddrlen];
-       uchar rport[2];
-       uchar lport[2];
-       /* bootp itself */
-       uchar op;                                       /* opcode */
-       uchar htype;                            /* hardware type */
-       uchar hlen;                                     /* hardware address len */
-       uchar hops;                                     /* hops */
-       uchar xid[4];                           /* a random number */
-       uchar secs[2];                          /* elapsed snce client started booting */
-       uchar flags[2];                         /* flags */
-       uchar ciaddr[4];                        /* client IP address (client tells server) */
-       uchar yiaddr[4];                        /* client IP address (server tells client) */
-       uchar siaddr[4];                        /* server IP address */
-       uchar giaddr[4];                        /* gateway IP address */
-       uchar chaddr[16];                       /* client hardware address */
-       uchar sname[64];                        /* server host name (optional) */
-       uchar file[128];                        /* boot file name */
-       uchar vend[128];                        /* vendor-specific goo 340 */
-} Bootp;
-
-static Bootp req;
-static Proc *rcvprocp;
-static int recv;
-static int done;
-static Rendez bootpr;
-static char rcvbuf[512 + 2 * IPaddrlen + 2 * 2];       /* 576 */
-static uchar sid[4];
-static ulong iplease;
-
-/*
- * bootp returns:
- *
- * "fsip d.d.d.d
- * auip d.d.d.d
- * gwip d.d.d.d
- * ipmask d.d.d.d
- * ipaddr d.d.d.d
- * dns1ip      d.d.d.d
- * dns2ip      d.d.d.d
- *
- * where d.d.d.d is the IP address in dotted decimal notation, and each
- * address is followed by a newline.
-       Last change:  SUN  13 Sep 2001    4:36 pm
- */
-
-/*
- * Parse the vendor specific fields according to RFC 1084.
- * We are overloading the "cookie server" to be the Inferno 
- * authentication server and the "resource location server"
- * to be the Inferno file server.
- *
- * If the vendor specific field is formatted properly, it
- * will being with the four bytes 99.130.83.99 and end with
- * an 0xFF byte.
- */
-static int parsevend(uchar * pvend)
-{
-       uchar *vend = pvend;
-       int dhcpmsg = 0;
-       /* The field must start with 99.130.83.99 to be compliant */
-       if ((vend[0] != 99) || (vend[1] != 130) || (vend[2] != 83)
-               || (vend[3] != 99)) {
-               print("bad bootp vendor field: %.2x%.2x%.2x%.2x", vend[0], vend[1],
-                         vend[2], vend[3]);
-               return -1;
-       }
-
-       /* Skip over the magic cookie */
-       vend += 4;
-
-       while ((vend[0] != 0) && (vend[0] != 0xFF)) {
-               int i;
-//  
-               if (debug) {
-                       print(">>>Opt[%d] [%d]", vend[0], vend[1]);
-                       for (i = 0; i < vend[1]; i++)
-                               print(" %2.2x", vend[i + 2]);
-                       print("\n");
-               }
-//
-               switch (vend[0]) {
-                       case 1: /* Subnet mask field */
-                               /* There must be only one subnet mask */
-                               if (vend[1] == 4)
-                                       ipmask =
-                                               (vend[2] << 24) | (vend[3] << 16) | (vend[4] << 8) |
-                                               vend[5];
-                               else {
-                                       return -1;
-                               }
-                               break;
-
-                       case 3: /* Gateway/router field */
-                               /* We are only concerned with first address */
-                               if (vend[1] > 0 && vend[1] % 4 == 0)
-                                       gwip =
-                                               (vend[2] << 24) | (vend[3] << 16) | (vend[4] << 8) |
-                                               vend[5];
-                               else
-                                       return -1;
-                               break;
-                       case 6: /* domain name server */
-                               if (vend[1] > 0 && vend[1] % 4 == 0) {
-                                       dns1ip =
-                                               (vend[2] << 24) | (vend[3] << 16) | (vend[4] << 8) |
-                                               vend[5];
-                                       if (vend[1] > 4)
-                                               dns2ip =
-                                                       (vend[6] << 24) | (vend[7] << 16) | (vend[8] << 8) |
-                                                       vend[9];
-                               } else
-                                       return -1;
-                               break;
-
-                       case 8: /* "Cookie server" (auth server) field */
-                               /* We are only concerned with first address */
-                               if (vend[1] > 0 && vend[1] % 4 == 0)
-                                       auip =
-                                               (vend[2] << 24) | (vend[3] << 16) | (vend[4] << 8) |
-                                               vend[5];
-                               else
-                                       return -1;
-                               break;
-
-                       case 11:        /* "Resource loc server" (file server) field */
-                               /* We are only concerned with first address */
-                               if (vend[1] > 0 && vend[1] % 4 == 0)
-                                       fsip =
-                                               (vend[2] << 24) | (vend[3] << 16) | (vend[4] << 8) |
-                                               vend[5];
-                               else
-                                       return -1;
-                               break;
-                       case 51:        /* ip lease time */
-                               if (vend[1] == 4) {
-                                       iplease =
-                                               (vend[2] << 24) | (vend[3] << 16) | (vend[4] << 8) |
-                                               vend[5];
-                               } else
-                                       return -1;
-                               break;
-                       case 53:        /* DHCP message type */
-                               if (vend[1] == 1)
-                                       dhcpmsg = vend[2];
-                               else
-                                       return -1;
-                               break;
-                       case 54:        /* server identifier */
-                               if (vend[1] == 4) {
-                                       memmove(sid, vend + 2, 4);
-                               } else
-                                       return -1;
-                               break;
-
-                       default:        /* Everything else stops us */
-                               break;
-               }
-
-               /* Skip over the field */
-               vend += vend[1] + 2;
-       }
-       if (debug)
-               print(">>>Opt[%d] [%d]\n", vend[0], vend[1]);
-       return dhcpmsg;
-}
-
-static void dispvend(uchar * pvend)
-{
-       uchar *vend = pvend;
-
-       //print("<<<Magic : %2.2x%2.2x%2.2x%2.2x\n", vend[0], vend[1], vend[2], vend[3]);
-
-       vend += 4;      /* Skip over the magic cookie */
-       while ((vend[0] != 0) && (vend[0] != 0xFF)) {
-               //  int i;
-               //    print("<<<Opt[%d] [%d]", vend[0], vend[1]);
-               //for(i=0; i<vend[1]; i++)
-               //  print(" %2.2x", vend[i+2]);
-               //print("\n");
-
-               vend += vend[1] + 2;
-       }
-       //print("<<<Opt[ %2.2x] [%2.2x]\n", vend[0], vend[1]);
-}
-
-static void rcvbootp(void *a)
-{
-       int n, fd, dhcp;
-       Bootp *rp;
-
-       if (waserror())
-               pexit("", 0);
-       rcvprocp = up;  /* store for postnote below */
-       fd = (int)a;
-       while (done == 0) {
-               if (debug)
-                       print("rcvbootp:looping\n");
-
-               n = kread(fd, rcvbuf, sizeof(rcvbuf));
-               if (n <= 0)
-                       break;
-               rp = (Bootp *) rcvbuf;
-               if (memcmp(req.chaddr, rp->chaddr, 6) == 0 && rp->htype == 1
-                       && rp->hlen == 6) {
-                       ipaddr =
-                               (rp->yiaddr[0] << 24) | (rp->yiaddr[1] << 16) | (rp->
-                                                                                                                                yiaddr[2] << 8)
-                               | rp->yiaddr[3];
-                       if (debug)
-                               print("ipaddr = %2.2x %2.2x %2.2x %2.2x \n", rp->yiaddr[0],
-                                         rp->yiaddr[1], rp->yiaddr[2], rp->yiaddr[3]);
-                       //memmove(req.siaddr, rp->siaddr, 4);   /* siaddr */
-                       dhcp = parsevend(rp->vend);
-
-                       if (dhcpmsgtype < dhcp) {
-                               dhcpmsgtype = dhcp;
-                               recv = 1;
-                               rendez_wakeup(&bootpr);
-                               if (dhcp == 0 || dhcp == 5 || dhcp == 6)
-                                       break;
-                       }
-               }
-       }
-       poperror();
-       rcvprocp = nil;
-
-       if (debug)
-               print("rcvbootp exit\n");
-       pexit("", 0);
-}
-
-static char *rbootp(Ipifc * ifc)
-{
-       int cfd, dfd, tries, n;
-       char ia[5 + 3 * 16], im[16], *av[3];
-       uchar nipaddr[4], ngwip[4], nipmask[4];
-       char dir[Maxpath];
-       static uchar vend_rfc1048[] = { 99, 130, 83, 99 };
-       uchar *vend;
-
-       /*
-        * broadcast bootp's till we get a reply,
-        * or fixed number of tries
-        */
-       if (debug)
-               print("dhcp: bootp() called\n");
-       tries = 0;
-       av[1] = "0.0.0.0";
-       av[2] = "0.0.0.0";
-       ipifcadd(ifc, av, 3, 0, nil);
-
-       cfd = kannounce("udp!*!68", dir);
-       if (cfd < 0)
-               return "dhcp announce failed";
-       strcat(dir, "/data");
-       if (kwrite(cfd, "headers", 7) < 0) {
-               kclose(cfd);
-               return "dhcp ctl headers failed";
-       }
-       kwrite(cfd, "oldheaders", 10);
-       dfd = kopen(dir, ORDWR);
-       if (dfd < 0) {
-               kclose(cfd);
-               return "dhcp open data failed";
-       }
-       kclose(cfd);
-
-       while (tries < 1) {
-               tries++;
-               memset(sid, 0, 4);
-               iplease = 0;
-               dhcpmsgtype = -2;
-/* DHCPDISCOVER*/
-               done = 0;
-               recv = 0;
-               ktask("rcvbootp", rcvbootp, (void *)dfd);
-               /* Prepare DHCPDISCOVER */
-               memset(&req, 0, sizeof(req));
-               ipmove(req.raddr, IPv4bcast);
-               hnputs(req.rport, 67);
-               req.op = Bootrequest;
-               req.htype = 1;  /* ethernet (all we know) */
-               req.hlen = 6;   /* ethernet (all we know) */
-
-               memmove(req.chaddr, ifc->mac, 6);       /* Hardware MAC address */
-               //ipv4local(ifc, req.ciaddr);               /* Fill in the local IP address if we know it */
-               memset(req.file, 0, sizeof(req.file));
-               vend = req.vend;
-               memmove(vend, vend_rfc1048, 4);
-               vend += 4;
-               *vend++ = 53;
-               *vend++ = 1;
-               *vend++ = 1;    /* dhcp msg type==3, dhcprequest */
-
-               *vend++ = 61;
-               *vend++ = 7;
-               *vend++ = 1;
-               memmove(vend, ifc->mac, 6);
-               vend += 6;
-               *vend = 0xff;
-
-               if (debug)
-                       dispvend(req.vend);
-               for (n = 0; n < 4; n++) {
-                       if (kwrite(dfd, &req, sizeof(req)) < 0) /* SEND DHCPDISCOVER */
-                               print("DHCPDISCOVER: %r");
-
-                       udelay_sched(1000 * 1000);      /* wait DHCPOFFER */
-                       if (debug)
-                               print("[DHCP] DISCOVER: msgtype = %d\n", dhcpmsgtype);
-
-                       if (dhcpmsgtype == 2)   /* DHCPOFFER */
-                               break;
-                       else if (dhcpmsgtype == 0)      /* bootp */
-                               return nil;
-                       else if (dhcpmsgtype == -2)     /* time out */
-                               continue;
-                       else
-                               break;
-
-               }
-               if (dhcpmsgtype != 2)
-                       continue;
-
-/* DHCPREQUEST */
-               memset(req.vend, 0, sizeof(req.vend));
-               vend = req.vend;
-               memmove(vend, vend_rfc1048, 4);
-               vend += 4;
-
-               *vend++ = 53;
-               *vend++ = 1;
-               *vend++ = 3;    /* dhcp msg type==3, dhcprequest */
-
-               *vend++ = 50;
-               *vend++ = 4;    /* requested ip address */
-               *vend++ = (ipaddr >> 24) & 0xff;
-               *vend++ = (ipaddr >> 16) & 0xff;
-               *vend++ = (ipaddr >> 8) & 0xff;
-               *vend++ = ipaddr & 0xff;
-
-               *vend++ = 51;
-               *vend++ = 4;    /* lease time */
-               *vend++ = (iplease >> 24) & 0xff;
-               *vend++ = (iplease >> 16) & 0xff;
-               *vend++ = (iplease >> 8) & 0xff;
-               *vend++ = iplease & 0xff;
-
-               *vend++ = 54;
-               *vend++ = 4;    /* server identifier */
-               memmove(vend, sid, 4);
-               vend += 4;
-
-               *vend++ = 61;
-               *vend++ = 07;
-               *vend++ = 01;   /* client identifier */
-               memmove(vend, ifc->mac, 6);
-               vend += 6;
-               *vend = 0xff;
-               if (debug)
-                       dispvend(req.vend);
-               if (kwrite(dfd, &req, sizeof(req)) < 0) {
-                       print("DHCPREQUEST: %r");
-                       continue;
-               }
-               udelay_sched(2000 * 1000);
-               if (dhcpmsgtype == 5)   /* wait for DHCPACK */
-                       break;
-               else
-                       continue;
-               /* CHECK ARP */
-               /* DHCPDECLINE */
-       }
-       kclose(dfd);
-       done = 1;
-       if (rcvprocp != nil) {
-               postnote(rcvprocp, 1, "timeout", 0);
-               rcvprocp = nil;
-       }
-
-       av[1] = "0.0.0.0";
-       av[2] = "0.0.0.0";
-       ipifcrem(ifc, av, 3);
-
-       hnputl(nipaddr, ipaddr);
-       sprint(ia, "%V", nipaddr);
-       hnputl(nipmask, ipmask);
-       sprint(im, "%V", nipmask);
-       av[1] = ia;
-       av[2] = im;
-       ipifcadd(ifc, av, 3, 0, nil);
-
-       if (gwip != 0) {
-               hnputl(ngwip, gwip);
-               n = sprint(ia, "add 0.0.0.0 0.0.0.0 %V", ngwip);
-               routewrite(ifc->conv->p->f, nil, ia, n);
-       }
-       return nil;
-}
-
-static int rbootpread(char *bp, ulong offset, int len)
-{
-       int n, i;
-       char *buf;
-       uchar a[4];
-
-       if (debug)
-               print("dhcp: bootpread() \n");
-       buf = smalloc(READSTR);
-       if (waserror()) {
-               free(buf);
-               nexterror();
-       }
-
-       hnputl(a, fsip);
-       n = snprint(buf, READSTR, "fsip %15V\n", a);
-       hnputl(a, auip);
-       n += snprint(buf + n, READSTR - n, "auip %15V\n", a);
-       hnputl(a, gwip);
-       n += snprint(buf + n, READSTR - n, "gwip %15V\n", a);
-       hnputl(a, ipmask);
-       n += snprint(buf + n, READSTR - n, "ipmask %15V\n", a);
-       hnputl(a, ipaddr);
-       n += snprint(buf + n, READSTR - n, "ipaddr %15V\n", a);
-       n += snprint(buf + n, READSTR - n, "expired %lu\n", iplease);
-
-       n += snprint(buf + n, READSTR - n, "dns");
-       if (dns2ip) {
-               hnputl(a, dns2ip);
-               n += snprint(buf + n, READSTR - n, " %15V", a);
-       }
-       if (dns1ip) {
-               hnputl(a, dns1ip);
-               n += snprint(buf + n, READSTR - n, " %15V", a);
-       }
-
-       for (i = 0; i < 2; i++)
-               if (ipcmp(pppdns[i], IPnoaddr) != 0 && ipcmp(pppdns[i], v4prefix) != 0)
-                       n += snprint(buf + n, READSTR - n, " %15I", pppdns[i]);
-
-       snprint(buf + n, READSTR - n, "\n");
-       len = readstr(offset, bp, len, buf);
-       poperror();
-       free(buf);
-       return len;
-}
-
-char *(*bootp) (Ipifc *) = rbootp;
-int (*bootpread) (char *, ulong, int) = rbootpread;
diff --git a/kern/src/net/esp.c b/kern/src/net/esp.c
deleted file mode 100644 (file)
index 9aedc03..0000000
+++ /dev/null
@@ -1,823 +0,0 @@
-#include       "u.h"
-#include       "../port/lib.h"
-#include       "mem.h"
-#include       "dat.h"
-#include       "fns.h"
-#include       "../port/error.h"
-
-#include       "ip.h"
-
-#include       "libsec.h"
-
-typedef struct Esphdr Esphdr;
-typedef struct Esptail Esptail;
-typedef struct Userhdr Userhdr;
-typedef struct Esppriv Esppriv;
-typedef struct Espcb Espcb;
-typedef struct Algorithm Algorithm;
-typedef struct Esprc4 Esprc4;
-
-#define DPRINT if(0)print
-
-enum {
-       IP_ESPPROTO = 50,
-       EsphdrSize = 28,        // includes IP header
-       IphdrSize = 20, // options have been striped
-       EsptailSize = 2,        // does not include pad or auth data
-       UserhdrSize = 4,        // user visable header size - if enabled
-};
-
-struct Esphdr {
-       /* ip header */
-       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 Unused;
-       uchar espproto;                         /* Protocol */
-       uchar espplen[2];                       /* Header plus data length */
-       uchar espsrc[4];                        /* Ip source */
-       uchar espdst[4];                        /* Ip destination */
-
-       /* esp header */
-       uchar espspi[4];                        /* Security parameter index */
-       uchar espseq[4];                        /* Sequence number */
-};
-
-struct Esptail {
-       uchar pad;
-       uchar nexthdr;
-};
-
-/* header as seen by the user */
-struct Userhdr {
-       uchar nexthdr;                          // next protocol
-       uchar unused[3];
-};
-
-struct Esppriv {
-       ulong in;
-       ulong inerrors;
-};
-
-/*
- *  protocol specific part of Conv
- */
-struct Espcb {
-       int incoming;
-       int header;                                     // user user level header
-       ulong spi;
-       ulong seq;                                      // last seq sent
-       ulong window;                           // for replay attacks
-       char *espalg;
-       void *espstate;                         // other state for esp
-       int espivlen;                           // in bytes
-       int espblklen;
-       int (*cipher) (Espcb *, uchar * buf, int len);
-       char *ahalg;
-       void *ahstate;                          // other state for esp
-       int ahlen;                                      // auth data length in bytes
-       int ahblklen;
-       int (*auth) (Espcb *, uchar * buf, int len, uchar * hash);
-};
-
-struct Algorithm {
-       char *name;
-       int keylen;                                     // in bits
-       void (*init) (Espcb *, char *name, uchar * key, int keylen);
-};
-
-enum {
-       RC4forward = 10 * 1024 * 1024,  // maximum skip forward
-       RC4back = 100 * 1024,   // maximum look back
-};
-
-struct Esprc4 {
-       ulong cseq;                                     // current byte sequence number
-       RC4state current;
-
-       int ovalid;                                     // old is valid
-       ulong lgseq;                            // last good sequence
-       ulong oseq;                                     // old byte sequence number
-       RC4state old;
-};
-
-static Conv *convlookup(Proto * esp, ulong spi);
-static char *setalg(Espcb * ecb, char **f, int n, Algorithm * alg);
-static void nullespinit(Espcb *, char *, uchar * key, int keylen);
-static void nullahinit(Espcb *, char *, uchar * key, int keylen);
-static void shaahinit(Espcb *, char *, uchar * key, int keylen);
-static void md5ahinit(Espcb *, char *, uchar * key, int keylen);
-static void desespinit(Espcb * ecb, char *name, uchar * k, int n);
-static void rc4espinit(Espcb * ecb, char *name, uchar * k, int n);
-static void espkick(void *x);
-
-static Algorithm espalg[] = {
-       "null", 0, nullespinit,
-       "des_56_cbc", 64, desespinit,
-       "rc4_128", 128, rc4espinit,
-       nil, 0, nil,
-};
-
-static Algorithm ahalg[] = {
-       "null", 0, nullahinit,
-       "hmac_sha1_96", 128, shaahinit,
-       "hmac_md5_96", 128, md5ahinit,
-       nil, 0, nil,
-};
-
-static char *espconnect(Conv * c, char **argv, int argc)
-{
-       char *p, *pp;
-       char *e = nil;
-       ulong spi;
-       Espcb *ecb = (Espcb *) c->ptcl;
-
-       switch (argc) {
-               default:
-                       e = "bad args to connect";
-                       break;
-               case 2:
-                       p = strchr(argv[1], '!');
-                       if (p == nil) {
-                               e = "malformed address";
-                               break;
-                       }
-                       *p++ = 0;
-                       parseip(c->raddr, argv[1]);
-                       findlocalip(c->p->f, c->laddr, c->raddr);
-                       ecb->incoming = 0;
-                       ecb->seq = 0;
-                       if (strcmp(p, "*") == 0) {
-                               qlock(c->p);
-                               for (;;) {
-                                       spi = nrand(1 << 16) + 256;
-                                       if (convlookup(c->p, spi) == nil)
-                                               break;
-                               }
-                               qunlock(c->p);
-                               ecb->spi = spi;
-                               ecb->incoming = 1;
-                               qhangup(c->wq, nil);
-                       } else {
-                               spi = strtoul(p, &pp, 10);
-                               if (pp == p) {
-                                       e = "malformed address";
-                                       break;
-                               }
-                               ecb->spi = spi;
-                               qhangup(c->rq, nil);
-                       }
-                       nullespinit(ecb, "null", nil, 0);
-                       nullahinit(ecb, "null", nil, 0);
-       }
-       Fsconnected(c, e);
-
-       return e;
-}
-
-static int espstate(Conv * c, char *state, int n)
-{
-       return snprint(state, n, "%s", c->inuse ? "Open\n" : "Closed\n");
-}
-
-static void espcreate(Conv * c)
-{
-       c->rq = qopen(64 * 1024, Qmsg, 0, 0);
-       c->wq = qopen(64 * 1024, Qkick, espkick, c);
-}
-
-static void espclose(Conv * c)
-{
-       Espcb *ecb;
-
-       qclose(c->rq);
-       qclose(c->wq);
-       qclose(c->eq);
-       ipmove(c->laddr, IPnoaddr);
-       ipmove(c->raddr, IPnoaddr);
-
-       ecb = (Espcb *) c->ptcl;
-       free(ecb->espstate);
-       free(ecb->ahstate);
-       memset(ecb, 0, sizeof(Espcb));
-}
-
-static void espkick(void *x)
-{
-       Conv *c = x;
-       Esphdr *eh;
-       Esptail *et;
-       Userhdr *uh;
-       Espcb *ecb;
-       Block *bp;
-       int nexthdr;
-       int payload;
-       int pad;
-       int align;
-       uchar *auth;
-
-       bp = qget(c->wq);
-       if (bp == nil)
-               return;
-
-       qlock(c);
-       ecb = c->ptcl;
-
-       if (ecb->header) {
-               /* make sure the message has a User header */
-               bp = pullupblock(bp, UserhdrSize);
-               if (bp == nil) {
-                       qunlock(c);
-                       return;
-               }
-               uh = (Userhdr *) bp->rp;
-               nexthdr = uh->nexthdr;
-               bp->rp += UserhdrSize;
-       } else {
-               nexthdr = 0;    // what should this be?
-       }
-
-       payload = BLEN(bp) + ecb->espivlen;
-
-       /* Make space to fit ip header */
-       bp = padblock(bp, EsphdrSize + ecb->espivlen);
-
-       align = 4;
-       if (ecb->espblklen > align)
-               align = ecb->espblklen;
-       if (align % ecb->ahblklen != 0)
-               panic("espkick: ahblklen is important after all");
-       pad = (align - 1) - (payload + EsptailSize - 1) % align;
-
-       /*
-        * Make space for tail
-        * this is done by calling padblock with a negative size
-        * Padblock does not change bp->wp!
-        */
-       bp = padblock(bp, -(pad + EsptailSize + ecb->ahlen));
-       bp->wp += pad + EsptailSize + ecb->ahlen;
-
-       eh = (Esphdr *) (bp->rp);
-       et = (Esptail *) (bp->rp + EsphdrSize + payload + pad);
-
-       // fill in tail
-       et->pad = pad;
-       et->nexthdr = nexthdr;
-
-       ecb->cipher(ecb, bp->rp + EsphdrSize, payload + pad + EsptailSize);
-       auth = bp->rp + EsphdrSize + payload + pad + EsptailSize;
-
-       // fill in head
-       eh->vihl = IP_VER4;
-       hnputl(eh->espspi, ecb->spi);
-       hnputl(eh->espseq, ++ecb->seq);
-       v6tov4(eh->espsrc, c->laddr);
-       v6tov4(eh->espdst, c->raddr);
-       eh->espproto = IP_ESPPROTO;
-       eh->frag[0] = 0;
-       eh->frag[1] = 0;
-
-       ecb->auth(ecb, bp->rp + IphdrSize,
-                         (EsphdrSize - IphdrSize) + payload + pad + EsptailSize, auth);
-
-       qunlock(c);
-       //print("esp: pass down: %uld\n", BLEN(bp));
-       ipoput4(c->p->f, bp, 0, c->ttl, c->tos, c);
-}
-
-void espiput(Proto * esp, Ipifc *, Block * bp)
-{
-       Esphdr *eh;
-       Esptail *et;
-       Userhdr *uh;
-       Conv *c;
-       Espcb *ecb;
-       uchar raddr[IPaddrlen], laddr[IPaddrlen];
-       Fs *f;
-       uchar *auth;
-       ulong spi;
-       int payload, nexthdr;
-
-       f = esp->f;
-
-       bp = pullupblock(bp, EsphdrSize + EsptailSize);
-       if (bp == nil) {
-               netlog(f, Logesp, "esp: short packet\n");
-               return;
-       }
-
-       eh = (Esphdr *) (bp->rp);
-       spi = nhgetl(eh->espspi);
-       v4tov6(raddr, eh->espsrc);
-       v4tov6(laddr, eh->espdst);
-
-       qlock(esp);
-       /* Look for a conversation structure for this port */
-       c = convlookup(esp, spi);
-       if (c == nil) {
-               qunlock(esp);
-               netlog(f, Logesp, "esp: no conv %I -> %I!%d\n", raddr, laddr, spi);
-               icmpnoconv(f, bp);
-               freeblist(bp);
-               return;
-       }
-
-       qlock(c);
-       qunlock(esp);
-
-       ecb = c->ptcl;
-       // too hard to do decryption/authentication on block lists
-       if (bp->next)
-               bp = concatblock(bp);
-
-       if (BLEN(bp) < EsphdrSize + ecb->espivlen + EsptailSize + ecb->ahlen) {
-               qunlock(c);
-               netlog(f, Logesp, "esp: short block %I -> %I!%d\n", raddr, laddr, spi);
-               freeb(bp);
-               return;
-       }
-
-       eh = (Esphdr *) (bp->rp);
-       auth = bp->wp - ecb->ahlen;
-       if (!ecb->auth(ecb, eh->espspi, auth - eh->espspi, auth)) {
-               qunlock(c);
-               print("esp: bad auth %I -> %I!%ld\n", raddr, laddr, spi);
-               netlog(f, Logesp, "esp: bad auth %I -> %I!%d\n", raddr, laddr, spi);
-               freeb(bp);
-               return;
-       }
-
-       payload = BLEN(bp) - EsphdrSize - ecb->ahlen;
-       if (payload <= 0 || payload % 4 != 0 || payload % ecb->espblklen != 0) {
-               qunlock(c);
-               netlog(f, Logesp, "esp: bad length %I -> %I!%d payload=%d BLEN=%d\n",
-                          raddr, laddr, spi, payload, BLEN(bp));
-               freeb(bp);
-               return;
-       }
-       if (!ecb->cipher(ecb, bp->rp + EsphdrSize, payload)) {
-               qunlock(c);
-               print("esp: cipher failed %I -> %I!%ld: %r\n", raddr, laddr, spi);
-               netlog(f, Logesp, "esp: cipher failed %I -> %I!%d: %r\n", raddr,
-                          laddr, spi);
-               freeb(bp);
-               return;
-       }
-
-       payload -= EsptailSize;
-       et = (Esptail *) (bp->rp + EsphdrSize + payload);
-       payload -= et->pad + ecb->espivlen;
-       nexthdr = et->nexthdr;
-       if (payload <= 0) {
-               qunlock(c);
-               netlog(f, Logesp, "esp: short packet after decrypt %I -> %I!%d\n",
-                          raddr, laddr, spi);
-               freeb(bp);
-               return;
-       }
-       // trim packet
-       bp->rp += EsphdrSize + ecb->espivlen;
-       bp->wp = bp->rp + payload;
-       if (ecb->header) {
-               // assume UserhdrSize < EsphdrSize
-               bp->rp -= UserhdrSize;
-               uh = (Userhdr *) bp->rp;
-               memset(uh, 0, UserhdrSize);
-               uh->nexthdr = nexthdr;
-       }
-
-       if (qfull(c->rq)) {
-               netlog(f, Logesp, "esp: qfull %I -> %I.%uld\n", raddr, laddr, spi);
-               freeblist(bp);
-       } else {
-//print("esp: pass up: %uld\n", BLEN(bp));
-               qpass(c->rq, bp);
-       }
-
-       qunlock(c);
-}
-
-char *espctl(Conv * c, char **f, int n)
-{
-       Espcb *ecb = c->ptcl;
-       char *e = nil;
-
-       if (strcmp(f[0], "esp") == 0)
-               e = setalg(ecb, f, n, espalg);
-       else if (strcmp(f[0], "ah") == 0)
-               e = setalg(ecb, f, n, ahalg);
-       else if (strcmp(f[0], "header") == 0)
-               ecb->header = 1;
-       else if (strcmp(f[0], "noheader") == 0)
-               ecb->header = 0;
-       else
-               e = "unknown control request";
-       return e;
-}
-
-void espadvise(Proto * esp, Block * bp, char *msg)
-{
-       Esphdr *h;
-       Conv *c;
-       ulong spi;
-
-       h = (Esphdr *) (bp->rp);
-
-       spi = nhgets(h->espspi);
-       qlock(esp);
-       c = convlookup(esp, spi);
-       if (c != nil) {
-               qhangup(c->rq, msg);
-               qhangup(c->wq, msg);
-       }
-       qunlock(esp);
-       freeblist(bp);
-}
-
-int espstats(Proto * esp, char *buf, int len)
-{
-       Esppriv *upriv;
-
-       upriv = esp->priv;
-       return snprint(buf, len, "%lu %lu\n", upriv->in, upriv->inerrors);
-}
-
-static int esplocal(Conv * c, char *buf, int len)
-{
-       Espcb *ecb = c->ptcl;
-       int n;
-
-       qlock(c);
-       if (ecb->incoming)
-               n = snprint(buf, len, "%I!%lu\n", c->laddr, ecb->spi);
-       else
-               n = snprint(buf, len, "%I\n", c->laddr);
-       qunlock(c);
-       return n;
-}
-
-static int espremote(Conv * c, char *buf, int len)
-{
-       Espcb *ecb = c->ptcl;
-       int n;
-
-       qlock(c);
-       if (ecb->incoming)
-               n = snprint(buf, len, "%I\n", c->raddr);
-       else
-               n = snprint(buf, len, "%I!%uld\n", c->raddr, ecb->spi);
-       qunlock(c);
-       return n;
-}
-
-static Conv *convlookup(Proto * esp, ulong spi)
-{
-       Conv *c, **p;
-       Espcb *ecb;
-
-       for (p = esp->conv; *p; p++) {
-               c = *p;
-               ecb = c->ptcl;
-               if (ecb->incoming && ecb->spi == spi)
-                       return c;
-       }
-       return nil;
-}
-
-static char *setalg(Espcb * ecb, char **f, int n, Algorithm * alg)
-{
-       uchar *key;
-       int i, nbyte, nchar;
-       int c;
-
-       if (n < 2)
-               return "bad format";
-       for (; alg->name; alg++)
-               if (strcmp(f[1], alg->name) == 0)
-                       break;
-       if (alg->name == nil)
-               return "unknown algorithm";
-
-       if (n != 3)
-               return "bad format";
-       nbyte = (alg->keylen + 7) >> 3;
-       nchar = strlen(f[2]);
-       for (i = 0; i < nchar; i++) {
-               c = f[2][i];
-               if (c >= '0' && c <= '9')
-                       f[2][i] -= '0';
-               else if (c >= 'a' && c <= 'f')
-                       f[2][i] -= 'a' - 10;
-               else if (c >= 'A' && c <= 'F')
-                       f[2][i] -= 'A' - 10;
-               else
-                       return "bad character in key";
-       }
-       key = smalloc(nbyte);
-       for (i = 0; i < nchar && i * 2 < nbyte; i++) {
-               c = f[2][nchar - i - 1];
-               if (i & 1)
-                       c <<= 4;
-               key[i >> 1] |= c;
-       }
-
-       alg->init(ecb, alg->name, key, alg->keylen);
-       free(key);
-       return nil;
-}
-
-static int nullcipher(Espcb *, uchar *, int)
-{
-       return 1;
-}
-
-static void nullespinit(Espcb * ecb, char *name, uchar *, int)
-{
-       ecb->espalg = name;
-       ecb->espblklen = 1;
-       ecb->espivlen = 0;
-       ecb->cipher = nullcipher;
-}
-
-static int nullauth(Espcb *, uchar *, int, uchar *)
-{
-       return 1;
-}
-
-static void nullahinit(Espcb * ecb, char *name, uchar *, int)
-{
-       ecb->ahalg = name;
-       ecb->ahblklen = 1;
-       ecb->ahlen = 0;
-       ecb->auth = nullauth;
-}
-
-void
-seanq_hmac_sha1(uchar hash[SHA1dlen], uchar * t, long tlen, uchar * key,
-                               long klen)
-{
-       uchar ipad[65], opad[65];
-       int i;
-       DigestState *digest;
-       uchar innerhash[SHA1dlen];
-
-       for (i = 0; i < 64; i++) {
-               ipad[i] = 0x36;
-               opad[i] = 0x5c;
-       }
-       ipad[64] = opad[64] = 0;
-       for (i = 0; i < klen; i++) {
-               ipad[i] ^= key[i];
-               opad[i] ^= key[i];
-       }
-       digest = sha1(ipad, 64, nil, nil);
-       sha1(t, tlen, innerhash, digest);
-       digest = sha1(opad, 64, nil, nil);
-       sha1(innerhash, SHA1dlen, hash, digest);
-}
-
-static int shaauth(Espcb * ecb, uchar * t, int tlen, uchar * auth)
-{
-       uchar hash[SHA1dlen];
-       int r;
-
-       memset(hash, 0, SHA1dlen);
-       seanq_hmac_sha1(hash, t, tlen, (uchar *) ecb->ahstate, 16);
-       r = memcmp(auth, hash, ecb->ahlen) == 0;
-       memmove(auth, hash, ecb->ahlen);
-       return r;
-}
-
-static void shaahinit(Espcb * ecb, char *name, uchar * key, int klen)
-{
-       if (klen != 128)
-               panic("shaahinit: bad keylen");
-       klen >>= 8;     // convert to bytes
-
-       ecb->ahalg = name;
-       ecb->ahblklen = 1;
-       ecb->ahlen = 12;
-       ecb->auth = shaauth;
-       ecb->ahstate = smalloc(klen);
-       memmove(ecb->ahstate, key, klen);
-}
-
-void
-seanq_hmac_md5(uchar hash[MD5dlen], uchar * t, long tlen, uchar * key,
-                          long klen)
-{
-       uchar ipad[65], opad[65];
-       int i;
-       DigestState *digest;
-       uchar innerhash[MD5dlen];
-
-       for (i = 0; i < 64; i++) {
-               ipad[i] = 0x36;
-               opad[i] = 0x5c;
-       }
-       ipad[64] = opad[64] = 0;
-       for (i = 0; i < klen; i++) {
-               ipad[i] ^= key[i];
-               opad[i] ^= key[i];
-       }
-       digest = md5(ipad, 64, nil, nil);
-       md5(t, tlen, innerhash, digest);
-       digest = md5(opad, 64, nil, nil);
-       md5(innerhash, MD5dlen, hash, digest);
-}
-
-static int md5auth(Espcb * ecb, uchar * t, int tlen, uchar * auth)
-{
-       uchar hash[MD5dlen];
-       int r;
-
-       memset(hash, 0, MD5dlen);
-       seanq_hmac_md5(hash, t, tlen, (uchar *) ecb->ahstate, 16);
-       r = memcmp(auth, hash, ecb->ahlen) == 0;
-       memmove(auth, hash, ecb->ahlen);
-       return r;
-}
-
-static void md5ahinit(Espcb * ecb, char *name, uchar * key, int klen)
-{
-       if (klen != 128)
-               panic("md5ahinit: bad keylen");
-       klen >>= 3;     // convert to bytes
-
-       ecb->ahalg = name;
-       ecb->ahblklen = 1;
-       ecb->ahlen = 12;
-       ecb->auth = md5auth;
-       ecb->ahstate = smalloc(klen);
-       memmove(ecb->ahstate, key, klen);
-}
-
-static int descipher(Espcb * ecb, uchar * p, int n)
-{
-       uchar tmp[8];
-       uchar *pp, *tp, *ip, *eip, *ep;
-       DESstate *ds = ecb->espstate;
-
-       ep = p + n;
-       if (ecb->incoming) {
-               memmove(ds->ivec, p, 8);
-               p += 8;
-               while (p < ep) {
-                       memmove(tmp, p, 8);
-                       block_cipher(ds->expanded, p, 1);
-                       tp = tmp;
-                       ip = ds->ivec;
-                       for (eip = ip + 8; ip < eip;) {
-                               *p++ ^= *ip;
-                               *ip++ = *tp++;
-                       }
-               }
-       } else {
-               memmove(p, ds->ivec, 8);
-               for (p += 8; p < ep; p += 8) {
-                       pp = p;
-                       ip = ds->ivec;
-                       for (eip = ip + 8; ip < eip;)
-                               *pp++ ^= *ip++;
-                       block_cipher(ds->expanded, p, 0);
-                       memmove(ds->ivec, p, 8);
-               }
-       }
-       return 1;
-}
-
-static void desespinit(Espcb * ecb, char *name, uchar * k, int n)
-{
-       uchar key[8];
-       uchar ivec[8];
-       int i;
-
-       // bits to bytes
-       n = (n + 7) >> 3;
-       if (n > 8)
-               n = 8;
-       memset(key, 0, sizeof(key));
-       memmove(key, k, n);
-       for (i = 0; i < 8; i++)
-               ivec[i] = nrand(256);
-       ecb->espalg = name;
-       ecb->espblklen = 8;
-       ecb->espivlen = 8;
-       ecb->cipher = descipher;
-       ecb->espstate = smalloc(sizeof(DESstate));
-       setupDESstate(ecb->espstate, key, ivec);
-}
-
-static int rc4cipher(Espcb * ecb, uchar * p, int n)
-{
-       Esprc4 *esprc4;
-       RC4state tmpstate;
-       ulong seq;
-       long d, dd;
-
-       if (n < 4)
-               return 0;
-
-       esprc4 = ecb->espstate;
-       if (ecb->incoming) {
-               seq = nhgetl(p);
-               p += 4;
-               n -= 4;
-               d = seq - esprc4->cseq;
-               if (d == 0) {
-                       rc4(&esprc4->current, p, n);
-                       esprc4->cseq += n;
-                       if (esprc4->ovalid) {
-                               dd = esprc4->cseq - esprc4->lgseq;
-                               if (dd > RC4back)
-                                       esprc4->ovalid = 0;
-                       }
-               } else if (d > 0) {
-                       print("missing packet: %uld %ld\n", seq, d);
-                       // this link is hosed
-                       if (d > RC4forward) {
-                               strcpy(up->errstr, "rc4cipher: skipped too much");
-                               return 0;
-                       }
-                       esprc4->lgseq = seq;
-                       if (!esprc4->ovalid) {
-                               esprc4->ovalid = 1;
-                               esprc4->oseq = esprc4->cseq;
-                               memmove(&esprc4->old, &esprc4->current, sizeof(RC4state));
-                       }
-                       rc4skip(&esprc4->current, d);
-                       rc4(&esprc4->current, p, n);
-                       esprc4->cseq = seq + n;
-               } else {
-                       print("reordered packet: %uld %ld\n", seq, d);
-                       dd = seq - esprc4->oseq;
-                       if (!esprc4->ovalid || -d > RC4back || dd < 0) {
-                               strcpy(up->errstr, "rc4cipher: too far back");
-                               return 0;
-                       }
-                       memmove(&tmpstate, &esprc4->old, sizeof(RC4state));
-                       rc4skip(&tmpstate, dd);
-                       rc4(&tmpstate, p, n);
-                       return 1;
-               }
-
-               // move old state up
-               if (esprc4->ovalid) {
-                       dd = esprc4->cseq - RC4back - esprc4->oseq;
-                       if (dd > 0) {
-                               rc4skip(&esprc4->old, dd);
-                               esprc4->oseq += dd;
-                       }
-               }
-       } else {
-               hnputl(p, esprc4->cseq);
-               p += 4;
-               n -= 4;
-               rc4(&esprc4->current, p, n);
-               esprc4->cseq += n;
-       }
-       return 1;
-}
-
-static void rc4espinit(Espcb * ecb, char *name, uchar * k, int n)
-{
-       Esprc4 *esprc4;
-
-       // bits to bytes
-       n = (n + 7) >> 3;
-       esprc4 = smalloc(sizeof(Esprc4));
-       memset(esprc4, 0, sizeof(Esprc4));
-       setupRC4state(&esprc4->current, k, n);
-       ecb->espalg = name;
-       ecb->espblklen = 4;
-       ecb->espivlen = 4;
-       ecb->cipher = rc4cipher;
-       ecb->espstate = esprc4;
-}
-
-void espinit(Fs * fs)
-{
-       Proto *esp;
-
-       esp = smalloc(sizeof(Proto));
-       esp->priv = smalloc(sizeof(Esppriv));
-       esp->name = "esp";
-       esp->connect = espconnect;
-       esp->announce = nil;
-       esp->ctl = espctl;
-       esp->state = espstate;
-       esp->create = espcreate;
-       esp->close = espclose;
-       esp->rcv = espiput;
-       esp->advise = espadvise;
-       esp->stats = espstats;
-       esp->local = esplocal;
-       esp->remote = espremote;
-       esp->ipproto = IP_ESPPROTO;
-       esp->nc = Nchans;
-       esp->ptclsize = sizeof(Espcb);
-
-       Fsproto(fs, esp);
-}
diff --git a/kern/src/net/gre.c b/kern/src/net/gre.c
deleted file mode 100644 (file)
index 23268e6..0000000
+++ /dev/null
@@ -1,267 +0,0 @@
-#include "u.h"
-#include "../port/lib.h"
-#include "mem.h"
-#include "dat.h"
-#include "fns.h"
-#include "../port/error.h"
-
-#include "ip.h"
-
-#define DPRINT if(0)print
-
-enum {
-       GRE_IPONLY = 12,                        /* size of ip header */
-       GRE_IPPLUSGRE = 12,     /* minimum size of GRE header */
-       IP_GREPROTO = 47,
-
-       GRErxms = 200,
-       GREtickms = 100,
-       GREmaxxmit = 10,
-};
-
-typedef struct GREhdr {
-       /* ip header */
-       uchar vihl;                                     /* Version and header length */
-       uchar tos;                                      /* Type of service */
-       uchar len[2];                           /* packet length (including headers) */
-       uchar id[2];                            /* Identification */
-       uchar frag[2];                          /* Fragment information */
-       uchar Unused;
-       uchar proto;                            /* Protocol */
-       uchar cksum[2];                         /* checksum */
-       uchar src[4];                           /* Ip source */
-       uchar dst[4];                           /* Ip destination */
-
-       /* gre header */
-       uchar flags[2];
-       uchar eproto[2];                        /* encapsulation protocol */
-} GREhdr;
-
-typedef struct GREpriv GREpriv;
-struct GREpriv {
-       int raw;                                        /* Raw GRE mode */
-
-       /* non-MIB stats */
-       ulong csumerr;                          /* checksum errors */
-       ulong lenerr;                           /* short packet */
-};
-
-static void grekick(void *x, Block * bp);
-
-static char *greconnect(Conv * c, char **argv, int argc)
-{
-       Proto *p;
-       char *err;
-       Conv *tc, **cp, **ecp;
-
-       err = Fsstdconnect(c, argv, argc);
-       if (err != nil)
-               return err;
-
-       /* make sure noone's already connected to this other sys */
-       p = c->p;
-       qlock(p);
-       ecp = &p->conv[p->nc];
-       for (cp = p->conv; cp < ecp; cp++) {
-               tc = *cp;
-               if (tc == nil)
-                       break;
-               if (tc == c)
-                       continue;
-               if (tc->rport == c->rport && ipcmp(tc->raddr, c->raddr) == 0) {
-                       err = "already connected to that addr/proto";
-                       ipmove(c->laddr, IPnoaddr);
-                       ipmove(c->raddr, IPnoaddr);
-                       break;
-               }
-       }
-       qunlock(p);
-
-       if (err != nil)
-               return err;
-       Fsconnected(c, nil);
-
-       return nil;
-}
-
-static void grecreate(Conv * c)
-{
-       c->rq = qopen(64 * 1024, Qmsg, 0, c);
-       c->wq = qbypass(grekick, c);
-}
-
-static int grestate(Conv * c, char *state, int n)
-{
-       USED(c);
-       return snprint(state, n, "%s", "Datagram");
-}
-
-static char *greannounce(Conv *, char **, int)
-{
-       return "pktifc does not support announce";
-}
-
-static void greclose(Conv * c)
-{
-       qclose(c->rq);
-       qclose(c->wq);
-       qclose(c->eq);
-       ipmove(c->laddr, IPnoaddr);
-       ipmove(c->raddr, IPnoaddr);
-       c->lport = 0;
-       c->rport = 0;
-}
-
-int drop;
-
-static void grekick(void *x, Block * bp)
-{
-       Conv *c = x;
-       GREhdr *ghp;
-       uchar laddr[IPaddrlen], raddr[IPaddrlen];
-
-       if (bp == nil)
-               return;
-
-       /* Make space to fit ip header (gre header already there) */
-       bp = padblock(bp, GRE_IPONLY);
-       if (bp == nil)
-               return;
-
-       /* make sure the message has a GRE header */
-       bp = pullupblock(bp, GRE_IPONLY + GRE_IPPLUSGRE);
-       if (bp == nil)
-               return;
-
-       ghp = (GREhdr *) (bp->rp);
-       ghp->vihl = IP_VER4;
-
-       if (!((GREpriv *) c->p->priv)->raw) {
-               v4tov6(raddr, ghp->dst);
-               if (ipcmp(raddr, v4prefix) == 0)
-                       memmove(ghp->dst, c->raddr + IPv4off, IPv4addrlen);
-               v4tov6(laddr, ghp->src);
-               if (ipcmp(laddr, v4prefix) == 0) {
-                       if (ipcmp(c->laddr, IPnoaddr) == 0)
-                               findlocalip(c->p->f, c->laddr, raddr);  /* pick interface closest to dest */
-                       memmove(ghp->src, c->laddr + IPv4off, IPv4addrlen);
-               }
-               hnputs(ghp->eproto, c->rport);
-       }
-
-       ghp->proto = IP_GREPROTO;
-       ghp->frag[0] = 0;
-       ghp->frag[1] = 0;
-
-       ipoput4(c->p->f, bp, 0, c->ttl, c->tos, nil);
-}
-
-static void greiput(Proto * gre, Ipifc *, Block * bp)
-{
-       int len;
-       GREhdr *ghp;
-       Conv *c, **p;
-       ushort eproto;
-       uchar raddr[IPaddrlen];
-       GREpriv *gpriv;
-
-       gpriv = gre->priv;
-       ghp = (GREhdr *) (bp->rp);
-
-       v4tov6(raddr, ghp->src);
-       eproto = nhgets(ghp->eproto);
-       qlock(gre);
-
-       /* Look for a conversation structure for this port and address */
-       c = nil;
-       for (p = gre->conv; *p; p++) {
-               c = *p;
-               if (c->inuse == 0)
-                       continue;
-               if (c->rport == eproto && (gpriv->raw || ipcmp(c->raddr, raddr) == 0))
-                       break;
-       }
-
-       if (*p == nil) {
-               qunlock(gre);
-               freeblist(bp);
-               return;
-       }
-
-       qunlock(gre);
-
-       /*
-        * Trim the packet down to data size
-        */
-       len = nhgets(ghp->len) - GRE_IPONLY;
-       if (len < GRE_IPPLUSGRE) {
-               freeblist(bp);
-               return;
-       }
-       bp = trimblock(bp, GRE_IPONLY, len);
-       if (bp == nil) {
-               gpriv->lenerr++;
-               return;
-       }
-
-       /*
-        *  Can't delimit packet so pull it all into one block.
-        */
-       if (qlen(c->rq) > 64 * 1024)
-               freeblist(bp);
-       else {
-               bp = concatblock(bp);
-               if (bp == 0)
-                       panic("greiput");
-               qpass(c->rq, bp);
-       }
-}
-
-int grestats(Proto * gre, char *buf, int len)
-{
-       GREpriv *gpriv;
-
-       gpriv = gre->priv;
-
-       return snprint(buf, len, "gre: len %lu\n", gpriv->lenerr);
-}
-
-char *grectl(Conv * c, char **f, int n)
-{
-       GREpriv *gpriv;
-
-       gpriv = c->p->priv;
-       if (n == 1) {
-               if (strcmp(f[0], "raw") == 0) {
-                       gpriv->raw = 1;
-                       return nil;
-               } else if (strcmp(f[0], "cooked") == 0) {
-                       gpriv->raw = 0;
-                       return nil;
-               }
-       }
-       return "unknown control request";
-}
-
-void greinit(Fs * fs)
-{
-       Proto *gre;
-
-       gre = smalloc(sizeof(Proto));
-       gre->priv = smalloc(sizeof(GREpriv));
-       gre->name = "gre";
-       gre->connect = greconnect;
-       gre->announce = greannounce;
-       gre->state = grestate;
-       gre->create = grecreate;
-       gre->close = greclose;
-       gre->rcv = greiput;
-       gre->ctl = grectl;
-       gre->advise = nil;
-       gre->stats = grestats;
-       gre->ipproto = IP_GREPROTO;
-       gre->nc = 64;
-       gre->ptclsize = 0;
-
-       Fsproto(fs, gre);
-}
diff --git a/kern/src/net/igmp.c b/kern/src/net/igmp.c
deleted file mode 100644 (file)
index 5b3260f..0000000
+++ /dev/null
@@ -1,279 +0,0 @@
-#include "u.h"
-#include "../port/lib.h"
-#include "mem.h"
-#include "dat.h"
-#include "fns.h"
-#include "../port/error.h"
-
-#include "ip.h"
-
-enum {
-       IGMP_IPHDRSIZE = 20,            /* size of ip header */
-       IGMP_HDRSIZE = 8,       /* size of IGMP header */
-       IP_IGMPPROTO = 2,
-
-       IGMPquery = 1,
-       IGMPreport = 2,
-
-       MSPTICK = 100,
-       MAXTIMEOUT = 10000 / MSPTICK,   /* at most 10 secs for a response */
-};
-
-typedef struct IGMPpkt IGMPpkt;
-struct IGMPpkt {
-       /* ip header */
-       uchar vihl;                                     /* Version and header length */
-       uchar tos;                                      /* Type of service */
-       uchar len[2];                           /* packet length (including headers) */
-       uchar id[2];                            /* Identification */
-       uchar frag[2];                          /* Fragment information */
-       uchar Unused;
-       uchar proto;                            /* Protocol */
-       uchar cksum[2];                         /* checksum of ip portion */
-       uchar src[IPaddrlen];           /* Ip source */
-       uchar dst[IPaddrlen];           /* Ip destination */
-
-       /* igmp header */
-       uchar vertype;                          /* version and type */
-       uchar unused;
-       uchar igmpcksum[2];                     /* checksum of igmp portion */
-       uchar group[IPaddrlen];         /* multicast group */
-};
-
-/*
- *  lists for group reports
- */
-typedef struct IGMPrep IGMPrep;
-struct IGMPrep {
-       IGMPrep *next;
-       Media *m;
-       int ticks;
-       Multicast *multi;
-};
-
-typedef struct IGMP IGMP;
-struct IGMP {
-       Lock;
-       Rendez r;
-       IGMPrep *reports;
-};
-
-IGMP igmpalloc;
-
-Proto igmp;
-extern Fs fs;
-
-static struct Stats {
-       ulong inqueries;
-       ulong outqueries;
-       ulong inreports;
-       ulong outreports;
-} stats;
-
-void igmpsendreport(Media * m, uchar * addr)
-{
-       IGMPpkt *p;
-       Block *bp;
-
-       bp = allocb(sizeof(IGMPpkt));
-       if (bp == nil)
-               return;
-       p = (IGMPpkt *) bp->wp;
-       p->vihl = IP_VER4;
-       bp->wp += sizeof(IGMPpkt);
-       memset(bp->rp, 0, sizeof(IGMPpkt));
-       hnputl(p->src, Mediagetaddr(m));
-       hnputl(p->dst, Ipallsys);
-       p->vertype = (1 << 4) | IGMPreport;
-       p->proto = IP_IGMPPROTO;
-       memmove(p->group, addr, IPaddrlen);
-       hnputs(p->igmpcksum, ptclcsum(bp, IGMP_IPHDRSIZE, IGMP_HDRSIZE));
-       netlog(Logigmp, "igmpreport %I\n", p->group);
-       stats.outreports++;
-       ipoput4(bp, 0, 1, DFLTTOS, nil);        /* TTL of 1 */
-}
-
-static int isreport(void *a)
-{
-       USED(a);
-       return igmpalloc.reports != 0;
-}
-
-void igmpproc(void *a)
-{
-       IGMPrep *rp, **lrp;
-       Multicast *mp, **lmp;
-       uchar ip[IPaddrlen];
-
-       USED(a);
-
-       for (;;) {
-               rendez_sleep(&igmpalloc.r, isreport, 0);
-               for (;;) {
-                       lock(&igmpalloc);
-
-                       if (igmpalloc.reports == nil)
-                               break;
-
-                       /* look for a single report */
-                       lrp = &igmpalloc.reports;
-                       mp = nil;
-                       for (rp = *lrp; rp; rp = *lrp) {
-                               rp->ticks++;
-                               lmp = &rp->multi;
-                               for (mp = *lmp; mp; mp = *lmp) {
-                                       if (rp->ticks >= mp->timeout) {
-                                               *lmp = mp->next;
-                                               break;
-                                       }
-                                       lmp = &mp->next;
-                               }
-                               if (mp != nil)
-                                       break;
-
-                               if (rp->multi != nil) {
-                                       lrp = &rp->next;
-                                       continue;
-                               } else {
-                                       *lrp = rp->next;
-                                       free(rp);
-                               }
-                       }
-                       unlock(&igmpalloc);
-
-                       if (mp) {
-                               /* do a single report and try again */
-                               hnputl(ip, mp->addr);
-                               igmpsendreport(rp->m, ip);
-                               free(mp);
-                               continue;
-                       }
-
-                       udelay_sched(MSPTICK * 1000);
-               }
-               unlock(&igmpalloc);
-       }
-
-}
-
-void igmpiput(Media * m, Ipifc *, Block * bp)
-{
-       int n;
-       IGMPpkt *ghp;
-       Ipaddr group;
-       IGMPrep *rp, **lrp;
-       Multicast *mp, **lmp;
-
-       ghp = (IGMPpkt *) (bp->rp);
-       netlog(Logigmp, "igmpiput: %d %I\n", ghp->vertype, ghp->group);
-
-       n = blocklen(bp);
-       if (n < IGMP_IPHDRSIZE + IGMP_HDRSIZE) {
-               netlog(Logigmp, "igmpiput: bad len\n");
-               goto error;
-       }
-       if ((ghp->vertype >> 4) != 1) {
-               netlog(Logigmp, "igmpiput: bad igmp type\n");
-               goto error;
-       }
-       if (ptclcsum(bp, IGMP_IPHDRSIZE, IGMP_HDRSIZE)) {
-               netlog(Logigmp, "igmpiput: checksum error %I\n", ghp->src);
-               goto error;
-       }
-
-       group = nhgetl(ghp->group);
-
-       lock(&igmpalloc);
-       switch (ghp->vertype & 0xf) {
-               case IGMPquery:
-                       /*
-                        *  start reporting groups that we're a member of.
-                        */
-                       stats.inqueries++;
-                       for (rp = igmpalloc.reports; rp; rp = rp->next)
-                               if (rp->m == m)
-                                       break;
-                       if (rp != nil)
-                               break;  /* already reporting */
-
-                       mp = Mediacopymulti(m);
-                       if (mp == nil)
-                               break;
-
-                       rp = malloc(sizeof(*rp));
-                       if (rp == nil)
-                               break;
-
-                       rp->m = m;
-                       rp->multi = mp;
-                       rp->ticks = 0;
-                       for (; mp; mp = mp->next)
-                               mp->timeout = nrand(MAXTIMEOUT);
-                       rp->next = igmpalloc.reports;
-                       igmpalloc.reports = rp;
-
-                       rendez_wakeup(&igmpalloc.r);
-
-                       break;
-               case IGMPreport:
-                       /*
-                        *  find report list for this medium
-                        */
-                       stats.inreports++;
-                       lrp = &igmpalloc.reports;
-                       for (rp = *lrp; rp; rp = *lrp) {
-                               if (rp->m == m)
-                                       break;
-                               lrp = &rp->next;
-                       }
-                       if (rp == nil)
-                               break;
-
-                       /*
-                        *  if someone else has reported a group,
-                        *  we don't have to.
-                        */
-                       lmp = &rp->multi;
-                       for (mp = *lmp; mp; mp = *lmp) {
-                               if (mp->addr == group) {
-                                       *lmp = mp->next;
-                                       free(mp);
-                                       break;
-                               }
-                               lmp = &mp->next;
-                       }
-
-                       break;
-       }
-       unlock(&igmpalloc);
-
-error:
-       freeb(bp);
-}
-
-int igmpstats(char *buf, int len)
-{
-       return snprint(buf, len, "\trcvd %d %d\n\tsent %d %d\n",
-                                  stats.inqueries, stats.inreports,
-                                  stats.outqueries, stats.outreports);
-}
-
-void igmpinit(Fs * fs)
-{
-       igmp.name = "igmp";
-       igmp.connect = nil;
-       igmp.announce = nil;
-       igmp.ctl = nil;
-       igmp.state = nil;
-       igmp.close = nil;
-       igmp.rcv = igmpiput;
-       igmp.stats = igmpstats;
-       igmp.ipproto = IP_IGMPPROTO;
-       igmp.nc = 0;
-       igmp.ptclsize = 0;
-
-       igmpreportfn = igmpsendreport;
-       ktask("igmpproc", igmpproc, 0);
-
-       Fsproto(fs, &igmp);
-}
diff --git a/kern/src/net/ihbootp.c b/kern/src/net/ihbootp.c
deleted file mode 100644 (file)
index a18e656..0000000
+++ /dev/null
@@ -1,306 +0,0 @@
-#include "u.h"
-#include "../port/lib.h"
-#include "mem.h"
-#include "dat.h"
-#include "fns.h"
-#include "../port/error.h"
-#include "kernel.h"
-#include "ip.h"
-
-static ulong fsip;
-static ulong auip;
-static ulong gwip;
-static ulong ipmask;
-static ulong ipaddr;
-static ulong dnsip;
-
-enum {
-       Bootrequest = 1,
-       Bootreply = 2,
-};
-
-typedef struct Bootp {
-       /* udp.c oldheader */
-       uchar raddr[IPaddrlen];
-       uchar laddr[IPaddrlen];
-       uchar rport[2];
-       uchar lport[2];
-       /* bootp itself */
-       uchar op;                                       /* opcode */
-       uchar htype;                            /* hardware type */
-       uchar hlen;                                     /* hardware address len */
-       uchar hops;                                     /* hops */
-       uchar xid[4];                           /* a random number */
-       uchar secs[2];                          /* elapsed snce client started booting */
-       uchar pad[2];
-       uchar ciaddr[4];                        /* client IP address (client tells server) */
-       uchar yiaddr[4];                        /* client IP address (server tells client) */
-       uchar siaddr[4];                        /* server IP address */
-       uchar giaddr[4];                        /* gateway IP address */
-       uchar chaddr[16];                       /* client hardware address */
-       uchar sname[64];                        /* server host name (optional) */
-       uchar file[128];                        /* boot file name */
-       uchar vend[128];                        /* vendor-specific goo */
-} Bootp;
-
-/*
- * bootp returns:
- *
- * "fsip d.d.d.d
- * auip d.d.d.d
- * gwip d.d.d.d
- * ipmask d.d.d.d
- * ipaddr d.d.d.d
- * dnsip d.d.d.d"
- *
- * where d.d.d.d is the IP address in dotted decimal notation, and each
- * address is followed by a newline.
- */
-
-static Bootp req;
-static Proc *rcvprocp;
-static int recv;
-static int done;
-static Rendez bootpr;
-static char rcvbuf[512];
-static int bootpdebug;
-
-/*
- * Parse the vendor specific fields according to RFC 1084.
- * We are overloading the "cookie server" to be the Inferno 
- * authentication server and the "resource location server"
- * to be the Inferno file server.
- *
- * If the vendor specific field is formatted properly, it
- * will begin with the four bytes 99.130.83.99 and end with
- * an 0xFF byte.
- */
-static void parsevend(uchar * vend)
-{
-       /* The field must start with 99.130.83.99 to be compliant */
-       if ((vend[0] != 99) || (vend[1] != 130) ||
-               (vend[2] != 83) || (vend[3] != 99)) {
-               if (bootpdebug)
-                       print("bad bootp vendor field: %.2x%.2x%.2x%.2x", vend[0], vend[1],
-                                 vend[2], vend[3]);
-               return;
-       }
-
-       /* Skip over the magic cookie */
-       vend += 4;
-
-       while ((vend[0] != 0) && (vend[0] != 0xFF)) {
-               if (bootpdebug) {
-                       int i;
-                       print("vend %d [%d]", vend[0], vend[1]);
-                       for (i = 0; i < vend[1]; i++)
-                               print(" %2.2x", vend[i]);
-                       print("\n");
-               }
-               switch (vend[0]) {
-                       case 1: /* Subnet mask field */
-                               /* There must be only one subnet mask */
-                               if (vend[1] != 4)
-                                       return;
-
-                               ipmask = (vend[2] << 24) |
-                                       (vend[3] << 16) | (vend[4] << 8) | vend[5];
-                               break;
-
-                       case 3: /* Gateway/router field */
-                               /* We are only concerned with first address */
-                               if (vend[1] < 4)
-                                       break;
-
-                               gwip = (vend[2] << 24) |
-                                       (vend[3] << 16) | (vend[4] << 8) | vend[5];
-                               break;
-
-                       case 6: /* DNS server */
-                               /* We are only concerned with first address */
-                               if (vend[1] < 4)
-                                       break;
-
-                               dnsip = (vend[2] << 24) |
-                                       (vend[3] << 16) | (vend[4] << 8) | vend[5];
-                               break;
-
-                       case 8: /* "Cookie server" (auth server) field */
-                               /* We are only concerned with first address */
-                               if (vend[1] < 4)
-                                       break;
-
-                               auip = (vend[2] << 24) |
-                                       (vend[3] << 16) | (vend[4] << 8) | vend[5];
-                               break;
-
-                       case 11:        /* "Resource loc server" (file server) field */
-                               /* We are only concerned with first address */
-                               if (vend[1] < 4)
-                                       break;
-
-                               fsip = (vend[2] << 24) |
-                                       (vend[3] << 16) | (vend[4] << 8) | vend[5];
-                               break;
-
-                       default:        /* Ignore everything else */
-                               break;
-               }
-
-               /* Skip over the field */
-               vend += vend[1] + 2;
-       }
-}
-
-static void rcvbootp(void *a)
-{
-       int n, fd;
-       Bootp *rp;
-
-       if (waserror())
-               pexit("", 0);
-       rcvprocp = up;  /* store for postnote below */
-       fd = (int)a;
-       while (done == 0) {
-               n = kread(fd, rcvbuf, sizeof(rcvbuf));
-               if (n <= 0)
-                       break;
-               rp = (Bootp *) rcvbuf;
-               if (memcmp(req.chaddr, rp->chaddr, 6) == 0 &&
-                       rp->htype == 1 && rp->hlen == 6) {
-                       ipaddr = (rp->yiaddr[0] << 24) |
-                               (rp->yiaddr[1] << 16) | (rp->yiaddr[2] << 8) | rp->yiaddr[3];
-                       parsevend(rp->vend);
-                       break;
-               }
-       }
-       poperror();
-       rcvprocp = nil;
-
-       recv = 1;
-       rendez_wakeup(&bootpr);
-       pexit("", 0);
-}
-
-static char *rbootp(Ipifc * ifc)
-{
-       int cfd, dfd, tries, n;
-       char ia[5 + 3 * 16], im[16], *av[3];
-       uchar nipaddr[4], ngwip[4], nipmask[4];
-       char dir[Maxpath];
-       static uchar vend_rfc1048[] = { 99, 130, 83, 99 };
-
-       av[1] = "0.0.0.0";
-       av[2] = "0.0.0.0";
-       ipifcadd(ifc, av, 3, 0, nil);
-
-       cfd = kannounce("udp!*!68", dir);
-       if (cfd < 0)
-               return "bootp announce failed";
-       strcat(dir, "/data");
-       if (kwrite(cfd, "headers", 7) < 0) {
-               kclose(cfd);
-               return "bootp ctl headers failed";
-       }
-       kwrite(cfd, "oldheaders", 10);
-       dfd = kopen(dir, ORDWR);
-       if (dfd < 0) {
-               kclose(cfd);
-               return "bootp open data failed";
-       }
-       kclose(cfd);
-
-       /* create request */
-       memset(&req, 0, sizeof(req));
-       ipmove(req.raddr, IPv4bcast);
-       hnputs(req.rport, 67);
-       req.op = Bootrequest;
-       req.htype = 1;  /* ethernet (all we know) */
-       req.hlen = 6;   /* ethernet (all we know) */
-
-       /* Hardware MAC address */
-       memmove(req.chaddr, ifc->mac, 6);
-       /* Fill in the local IP address if we know it */
-       ipv4local(ifc, req.ciaddr);
-       memset(req.file, 0, sizeof(req.file));
-       memmove(req.vend, vend_rfc1048, 4);
-
-       done = 0;
-       recv = 0;
-
-       ktask("rcvbootp", rcvbootp, (void *)dfd);
-
-       /*
-        * broadcast bootp's till we get a reply,
-        * or fixed number of tries
-        */
-       tries = 0;
-       while (recv == 0) {
-               if (kwrite(dfd, &req, sizeof(req)) < 0)
-                       print("bootp: write: %r");
-
-               udelay_sched(1000 * 1000);
-               if (++tries > 10) {
-                       print("bootp: timed out\n");
-                       break;
-               }
-       }
-       kclose(dfd);
-       done = 1;
-       if (rcvprocp != nil) {
-               postnote(rcvprocp, 1, "timeout", 0);
-               rcvprocp = nil;
-       }
-
-       av[1] = "0.0.0.0";
-       av[2] = "0.0.0.0";
-       ipifcrem(ifc, av, 3);
-
-       hnputl(nipaddr, ipaddr);
-       sprint(ia, "%V", nipaddr);
-       hnputl(nipmask, ipmask);
-       sprint(im, "%V", nipmask);
-       av[1] = ia;
-       av[2] = im;
-       ipifcadd(ifc, av, 3, 0, nil);
-
-       if (gwip != 0) {
-               hnputl(ngwip, gwip);
-               n = sprint(ia, "add 0.0.0.0 0.0.0.0 %V", ngwip);
-               routewrite(ifc->conv->p->f, nil, ia, n);
-       }
-       return nil;
-}
-
-static int rbootpread(char *bp, ulong offset, int len)
-{
-       int n;
-       char *buf;
-       uchar a[4];
-
-       buf = smalloc(READSTR);
-       if (waserror()) {
-               free(buf);
-               nexterror();
-       }
-       hnputl(a, fsip);
-       n = snprint(buf, READSTR, "fsip %15V\n", a);
-       hnputl(a, auip);
-       n += snprint(buf + n, READSTR - n, "auip %15V\n", a);
-       hnputl(a, gwip);
-       n += snprint(buf + n, READSTR - n, "gwip %15V\n", a);
-       hnputl(a, ipmask);
-       n += snprint(buf + n, READSTR - n, "ipmask %15V\n", a);
-       hnputl(a, ipaddr);
-       n += snprint(buf + n, READSTR - n, "ipaddr %15V\n", a);
-       hnputl(a, dnsip);
-       snprint(buf + n, READSTR - n, "dnsip %15V\n", a);
-
-       len = readstr(offset, bp, len, buf);
-       poperror();
-       free(buf);
-       return len;
-}
-
-char *(*bootp) (Ipifc *) = rbootp;
-int (*bootpread) (char *, ulong, int) = rbootpread;
diff --git a/kern/src/net/ipmux.c b/kern/src/net/ipmux.c
deleted file mode 100644 (file)
index a42968f..0000000
+++ /dev/null
@@ -1,823 +0,0 @@
-#include "u.h"
-#include "../port/lib.h"
-#include "mem.h"
-#include "dat.h"
-#include "fns.h"
-#include "../port/error.h"
-
-#include "ip.h"
-#define DPRINT if(0)print
-
-typedef struct Ipmuxrock Ipmuxrock;
-typedef struct Ipmux Ipmux;
-typedef struct Ip4hdr Ip4hdr;
-typedef struct Ip6hdr Ip6hdr;
-
-enum {
-       IPHDR = 20,                                     /* sizeof(Ip4hdr) */
-};
-
-struct Ip4hdr {
-       uchar vihl;                                     /* Version and header length */
-       uchar tos;                                      /* Type of service */
-       uchar length[2];                        /* packet length */
-       uchar id[2];                            /* ip->identification */
-       uchar frag[2];                          /* Fragment information */
-       uchar ttl;                                      /* Time to live */
-       uchar proto;                            /* Protocol */
-       uchar cksum[2];                         /* Header checksum */
-       uchar src[4];                           /* IP source */
-       uchar dst[4];                           /* IP destination */
-       uchar data[1];                          /* start of data */
-};
-
-struct Ip6hdr {
-       uchar vcf[4];                           /* version, class label, and flow label */
-       uchar ploadlen[2];                      /* payload length */
-       uchar proto;                            /* next header, i.e. proto */
-       uchar ttl;                                      /* hop limit, i.e. ttl */
-       uchar src[16];                          /* IP source */
-       uchar dst[16];                          /* IP destination */
-};
-
-enum {
-       Tproto,
-       Tdata,
-       Tiph,
-       Tdst,
-       Tsrc,
-       Tifc,
-
-       Cother = 0,
-       Cbyte,  /* single byte */
-       Cmbyte, /* single byte with mask */
-       Cshort, /* single short */
-       Cmshort,        /* single short with mask */
-       Clong,  /* single long */
-       Cmlong, /* single long with mask */
-       Cifc,
-       Cmifc,
-};
-
-char *ftname[] = {
-       [Tproto] "proto",
-       [Tdata] "data",
-       [Tiph] "iph",
-       [Tdst] "dst",
-       [Tsrc] "src",
-       [Tifc] "ifc",
-};
-
-/*
- *  a node in the decision tree
- */
-struct Ipmux {
-       Ipmux *yes;
-       Ipmux *no;
-       uchar type;                                     /* type of field(Txxxx) */
-       uchar ctype;                            /* tupe of comparison(Cxxxx) */
-       uchar len;                                      /* length in bytes of item to compare */
-       uchar n;                                        /* number of items val points to */
-       short off;                                      /* offset of comparison */
-       short eoff;                                     /* end offset of comparison */
-       uchar skiphdr;                          /* should offset start after ipheader */
-       uchar *val;
-       uchar *mask;
-       uchar *e;                                       /* val+n*len */
-
-       int ref;                                        /* so we can garbage collect */
-       Conv *conv;
-};
-
-/*
- *  someplace to hold per conversation data
- */
-struct Ipmuxrock {
-       Ipmux *chain;
-};
-
-static int ipmuxsprint(Ipmux *, int, char *, int);
-static void ipmuxkick(void *x);
-
-static char *skipwhite(char *p)
-{
-       while (*p == ' ' || *p == '\t')
-               p++;
-       return p;
-}
-
-static char *follows(char *p, char c)
-{
-       char *f;
-
-       f = strchr(p, c);
-       if (f == nil)
-               return nil;
-       *f++ = 0;
-       f = skipwhite(f);
-       if (*f == 0)
-               return nil;
-       return f;
-}
-
-static Ipmux *parseop(char **pp)
-{
-       char *p = *pp;
-       int type, off, end, len;
-       Ipmux *f;
-
-       p = skipwhite(p);
-       if (strncmp(p, "dst", 3) == 0) {
-               type = Tdst;
-               off = offsetof(Ip4hdr, dst[0]);
-               len = IPv4addrlen;
-               p += 3;
-       } else if (strncmp(p, "src", 3) == 0) {
-               type = Tsrc;
-               off = offsetof(Ip4hdr, src[0]);
-               len = IPv4addrlen;
-               p += 3;
-       } else if (strncmp(p, "ifc", 3) == 0) {
-               type = Tifc;
-               off = -IPv4addrlen;
-               len = IPv4addrlen;
-               p += 3;
-       } else if (strncmp(p, "proto", 5) == 0) {
-               type = Tproto;
-               off = offsetof(Ip4hdr, proto);
-               len = 1;
-               p += 5;
-       } else if (strncmp(p, "data", 4) == 0 || strncmp(p, "iph", 3) == 0) {
-               if (strncmp(p, "data", 4) == 0) {
-                       type = Tdata;
-                       p += 4;
-               } else {
-                       type = Tiph;
-                       p += 3;
-               }
-               p = skipwhite(p);
-               if (*p != '[')
-                       return nil;
-               p++;
-               off = strtoul(p, &p, 0);
-               if (off < 0 || off > (64 - IPHDR))
-                       return nil;
-               p = skipwhite(p);
-               if (*p != ':')
-                       end = off;
-               else {
-                       p++;
-                       p = skipwhite(p);
-                       end = strtoul(p, &p, 0);
-                       if (end < off)
-                               return nil;
-                       p = skipwhite(p);
-               }
-               if (*p != ']')
-                       return nil;
-               p++;
-               len = end - off + 1;
-       } else
-               return nil;
-
-       f = smalloc(sizeof(*f));
-       f->type = type;
-       f->len = len;
-       f->off = off;
-       f->val = nil;
-       f->mask = nil;
-       f->n = 1;
-       f->ref = 1;
-       if (type == Tdata)
-               f->skiphdr = 1;
-       else
-               f->skiphdr = 0;
-
-       return f;
-}
-
-static int htoi(char x)
-{
-       if (x >= '0' && x <= '9')
-               x -= '0';
-       else if (x >= 'a' && x <= 'f')
-               x -= 'a' - 10;
-       else if (x >= 'A' && x <= 'F')
-               x -= 'A' - 10;
-       else
-               x = 0;
-       return x;
-}
-
-static int hextoi(char *p)
-{
-       return (htoi(p[0]) << 4) | htoi(p[1]);
-}
-
-static void parseval(uchar * v, char *p, int len)
-{
-       while (*p && len-- > 0) {
-               *v++ = hextoi(p);
-               p += 2;
-       }
-}
-
-static Ipmux *parsemux(char *p)
-{
-       int n, nomask;
-       Ipmux *f;
-       char *val;
-       char *mask;
-       char *vals[20];
-       uchar *v;
-
-       /* parse operand */
-       f = parseop(&p);
-       if (f == nil)
-               return nil;
-
-       /* find value */
-       val = follows(p, '=');
-       if (val == nil)
-               goto parseerror;
-
-       /* parse mask */
-       mask = follows(val, '&');
-       if (mask != nil) {
-               switch (f->type) {
-                       case Tsrc:
-                       case Tdst:
-                       case Tifc:
-                               f->mask = smalloc(f->len);
-                               v4parseip(f->mask, mask);
-                               break;
-                       case Tdata:
-                       case Tiph:
-                               f->mask = smalloc(f->len);
-                               parseval(f->mask, mask, f->len);
-                               break;
-                       default:
-                               goto parseerror;
-               }
-               nomask = 0;
-       } else {
-               nomask = 1;
-               f->mask = smalloc(f->len);
-               memset(f->mask, 0xff, f->len);
-       }
-
-       /* parse vals */
-       f->n = getfields(val, vals, sizeof(vals) / sizeof(char *), 1, "|");
-       if (f->n == 0)
-               goto parseerror;
-       f->val = smalloc(f->n * f->len);
-       v = f->val;
-       for (n = 0; n < f->n; n++) {
-               switch (f->type) {
-                       case Tsrc:
-                       case Tdst:
-                       case Tifc:
-                               v4parseip(v, vals[n]);
-                               break;
-                       case Tproto:
-                       case Tdata:
-                       case Tiph:
-                               parseval(v, vals[n], f->len);
-                               break;
-               }
-               v += f->len;
-       }
-
-       f->eoff = f->off + f->len;
-       f->e = f->val + f->n * f->len;
-       f->ctype = Cother;
-       if (f->n == 1) {
-               switch (f->len) {
-                       case 1:
-                               f->ctype = nomask ? Cbyte : Cmbyte;
-                               break;
-                       case 2:
-                               f->ctype = nomask ? Cshort : Cmshort;
-                               break;
-                       case 4:
-                               if (f->type == Tifc)
-                                       f->ctype = nomask ? Cifc : Cmifc;
-                               else
-                                       f->ctype = nomask ? Clong : Cmlong;
-                               break;
-               }
-       }
-       return f;
-
-parseerror:
-       if (f->mask)
-               free(f->mask);
-       if (f->val)
-               free(f->val);
-       free(f);
-       return nil;
-}
-
-/*
- *  Compare relative ordering of two ipmuxs.  This doesn't compare the
- *  values, just the fields being looked at.  
- *
- *  returns:   <0 if a is a more specific match
- *              0 if a and b are matching on the same fields
- *             >0 if b is a more specific match
- */
-static int ipmuxcmp(Ipmux * a, Ipmux * b)
-{
-       int n;
-
-       /* compare types, lesser ones are more important */
-       n = a->type - b->type;
-       if (n != 0)
-               return n;
-
-       /* compare offsets, call earlier ones more specific */
-       n = (a->off + ((int)a->skiphdr) * offsetof(Ip4hdr, data[0])) -
-               (b->off + ((int)b->skiphdr) * offsetof(Ip4hdr, data[0]));
-       if (n != 0)
-               return n;
-
-       /* compare match lengths, longer ones are more specific */
-       n = b->len - a->len;
-       if (n != 0)
-               return n;
-
-       /*
-        *  if we get here we have two entries matching
-        *  the same bytes of the record.  Now check
-        *  the mask for equality.  Longer masks are
-        *  more specific.
-        */
-       if (a->mask != nil && b->mask == nil)
-               return -1;
-       if (a->mask == nil && b->mask != nil)
-               return 1;
-       if (a->mask != nil && b->mask != nil) {
-               n = memcmp(b->mask, a->mask, a->len);
-               if (n != 0)
-                       return n;
-       }
-       return 0;
-}
-
-/*
- *  Compare the values of two ipmuxs.  We're assuming that ipmuxcmp
- *  returned 0 comparing them.
- */
-static int ipmuxvalcmp(Ipmux * a, Ipmux * b)
-{
-       int n;
-
-       n = b->len * b->n - a->len * a->n;
-       if (n != 0)
-               return n;
-       return memcmp(a->val, b->val, a->len * a->n);
-}
-
-/*
- *  add onto an existing ipmux chain in the canonical comparison
- *  order
- */
-static void ipmuxchain(Ipmux ** l, Ipmux * f)
-{
-       for (; *l; l = &(*l)->yes)
-               if (ipmuxcmp(f, *l) < 0)
-                       break;
-       f->yes = *l;
-       *l = f;
-}
-
-/*
- *  copy a tree
- */
-static Ipmux *ipmuxcopy(Ipmux * f)
-{
-       Ipmux *nf;
-
-       if (f == nil)
-               return nil;
-       nf = smalloc(sizeof *nf);
-       *nf = *f;
-       nf->no = ipmuxcopy(f->no);
-       nf->yes = ipmuxcopy(f->yes);
-       nf->val = smalloc(f->n * f->len);
-       nf->e = nf->val + f->len * f->n;
-       memmove(nf->val, f->val, f->n * f->len);
-       return nf;
-}
-
-static void ipmuxfree(Ipmux * f)
-{
-       if (f->val != nil)
-               free(f->val);
-       free(f);
-}
-
-static void ipmuxtreefree(Ipmux * f)
-{
-       if (f == nil)
-               return;
-       if (f->no != nil)
-               ipmuxfree(f->no);
-       if (f->yes != nil)
-               ipmuxfree(f->yes);
-       ipmuxfree(f);
-}
-
-/*
- *  merge two trees
- */
-static Ipmux *ipmuxmerge(Ipmux * a, Ipmux * b)
-{
-       int n;
-       Ipmux *f;
-
-       if (a == nil)
-               return b;
-       if (b == nil)
-               return a;
-       n = ipmuxcmp(a, b);
-       if (n < 0) {
-               f = ipmuxcopy(b);
-               a->yes = ipmuxmerge(a->yes, b);
-               a->no = ipmuxmerge(a->no, f);
-               return a;
-       }
-       if (n > 0) {
-               f = ipmuxcopy(a);
-               b->yes = ipmuxmerge(b->yes, a);
-               b->no = ipmuxmerge(b->no, f);
-               return b;
-       }
-       if (ipmuxvalcmp(a, b) == 0) {
-               a->yes = ipmuxmerge(a->yes, b->yes);
-               a->no = ipmuxmerge(a->no, b->no);
-               a->ref++;
-               ipmuxfree(b);
-               return a;
-       }
-       a->no = ipmuxmerge(a->no, b);
-       return a;
-}
-
-/*
- *  remove a chain from a demux tree.  This is like merging accept that
- *  we remove instead of insert.
- */
-static int ipmuxremove(Ipmux ** l, Ipmux * f)
-{
-       int n, rv;
-       Ipmux *ft;
-
-       if (f == nil)
-               return 0;       /* we've removed it all */
-       if (*l == nil)
-               return -1;
-
-       ft = *l;
-       n = ipmuxcmp(ft, f);
-       if (n < 0) {
-               /* *l is maching an earlier field, descend both paths */
-               rv = ipmuxremove(&ft->yes, f);
-               rv += ipmuxremove(&ft->no, f);
-               return rv;
-       }
-       if (n > 0) {
-               /* f represents an earlier field than *l, this should be impossible */
-               return -1;
-       }
-
-       /* if we get here f and *l are comparing the same fields */
-       if (ipmuxvalcmp(ft, f) != 0) {
-               /* different values mean mutually exclusive */
-               return ipmuxremove(&ft->no, f);
-       }
-
-       /* we found a match */
-       if (--(ft->ref) == 0) {
-               /*
-                *  a dead node implies the whole yes side is also dead.
-                *  since our chain is constrained to be on that side,
-                *  we're done.
-                */
-               ipmuxtreefree(ft->yes);
-               *l = ft->no;
-               ipmuxfree(ft);
-               return 0;
-       }
-
-       /*
-        *  free the rest of the chain.  it is constrained to match the
-        *  yes side.
-        */
-       return ipmuxremove(&ft->yes, f->yes);
-}
-
-/*
- *  connection request is a semi separated list of filters
- *  e.g. proto=17;dat[0:4]=11aa22bb;ifc=135.104.9.2&255.255.255.0
- *
- *  there's no protection against overlapping specs.
- */
-static char *ipmuxconnect(Conv * c, char **argv, int argc)
-{
-       int i, n;
-       char *field[10];
-       Ipmux *mux, *chain;
-       Ipmuxrock *r;
-       Fs *f;
-
-       f = c->p->f;
-
-       if (argc != 2)
-               return Ebadarg;
-
-       n = getfields(argv[1], field, nelem(field), 1, ";");
-       if (n <= 0)
-               return Ebadarg;
-
-       chain = nil;
-       mux = nil;
-       for (i = 0; i < n; i++) {
-               mux = parsemux(field[i]);
-               if (mux == nil) {
-                       ipmuxtreefree(chain);
-                       return Ebadarg;
-               }
-               ipmuxchain(&chain, mux);
-       }
-       if (chain == nil)
-               return Ebadarg;
-       mux->conv = c;
-
-       /* save a copy of the chain so we can later remove it */
-       mux = ipmuxcopy(chain);
-       r = (Ipmuxrock *) (c->ptcl);
-       r->chain = chain;
-
-       /* add the chain to the protocol demultiplexor tree */
-       wlock(f);
-       f->ipmux->priv = ipmuxmerge(f->ipmux->priv, mux);
-       wunlock(f);
-
-       Fsconnected(c, nil);
-       return nil;
-}
-
-static int ipmuxstate(Conv * c, char *state, int n)
-{
-       Ipmuxrock *r;
-
-       r = (Ipmuxrock *) (c->ptcl);
-       return ipmuxsprint(r->chain, 0, state, n);
-}
-
-static void ipmuxcreate(Conv * c)
-{
-       Ipmuxrock *r;
-
-       c->rq = qopen(64 * 1024, Qmsg, 0, c);
-       c->wq = qopen(64 * 1024, Qkick, ipmuxkick, c);
-       r = (Ipmuxrock *) (c->ptcl);
-       r->chain = nil;
-}
-
-static char *ipmuxannounce(Conv *, char **, int)
-{
-       return "ipmux does not support announce";
-}
-
-static void ipmuxclose(Conv * c)
-{
-       Ipmuxrock *r;
-       Fs *f = c->p->f;
-
-       r = (Ipmuxrock *) (c->ptcl);
-
-       qclose(c->rq);
-       qclose(c->wq);
-       qclose(c->eq);
-       ipmove(c->laddr, IPnoaddr);
-       ipmove(c->raddr, IPnoaddr);
-       c->lport = 0;
-       c->rport = 0;
-
-       wlock(f);
-       ipmuxremove(&(c->p->priv), r->chain);
-       wunlock(f);
-       ipmuxtreefree(r->chain);
-       r->chain = nil;
-}
-
-/*
- *  takes a fully formed ip packet and just passes it down
- *  the stack
- */
-static void ipmuxkick(void *x)
-{
-       Conv *c = x;
-       Block *bp;
-
-       bp = qget(c->wq);
-       if (bp == nil)
-               return;
-       else {
-               Ip4hdr *ih4 = (Ip4hdr *) (bp->rp);
-               if ((ih4->vihl) & 0xF0 != 0x60)
-                       ipoput4(c->p->f, bp, 0, ih4->ttl, ih4->tos, nil);
-               else {
-                       Ip6hdr *ih6 = (Ip6hdr *) (bp->rp);
-                       ipoput6(c->p->f, bp, 0, ih6->ttl, 0, nil);
-               }
-       }
-}
-
-static void ipmuxiput(Proto * p, Ipifc * ifc, Block * bp)
-{
-       int len, hl;
-       Fs *f = p->f;
-       uchar *m, *h, *v, *e, *ve, *hp;
-       Conv *c;
-       Ipmux *mux;
-       Ip4hdr *ip;
-       Ip6hdr *ip6;
-
-       ip = (Ip4hdr *) bp->rp;
-       hl = (ip->vihl & 0x0F) << 2;
-
-       if (p->priv == nil)
-               goto nomatch;
-
-       h = bp->rp;
-       len = BLEN(bp);
-
-       /* run the v4 filter */
-       rlock(f);
-       c = nil;
-       mux = f->ipmux->priv;
-       while (mux != nil) {
-               if (mux->eoff > len) {
-                       mux = mux->no;
-                       continue;
-               }
-               hp = h + mux->off + ((int)mux->skiphdr) * hl;
-               switch (mux->ctype) {
-                       case Cbyte:
-                               if (*mux->val == *hp)
-                                       goto yes;
-                               break;
-                       case Cmbyte:
-                               if ((*hp & *mux->mask) == *mux->val)
-                                       goto yes;
-                               break;
-                       case Cshort:
-                               if (*((ushort *) mux->val) == *(ushort *) hp)
-                                       goto yes;
-                               break;
-                       case Cmshort:
-                               if ((*(ushort *) hp & (*((ushort *) mux->mask))) ==
-                                       *((ushort *) mux->val))
-                                       goto yes;
-                               break;
-                       case Clong:
-                               if (*((ulong *) mux->val) == *(ulong *) hp)
-                                       goto yes;
-                               break;
-                       case Cmlong:
-                               if ((*(ulong *) hp & (*((ulong *) mux->mask))) ==
-                                       *((ulong *) mux->val))
-                                       goto yes;
-                               break;
-                       case Cifc:
-                               if (*((ulong *) mux->val) ==
-                                       *(ulong *) (ifc->lifc->local + IPv4off))
-                                       goto yes;
-                               break;
-                       case Cmifc:
-                               if ((*(ulong *) (ifc->lifc->local + IPv4off) &
-                                        (*((ulong *) mux->mask))) == *((ulong *) mux->val))
-                                       goto yes;
-                               break;
-                       default:
-                               v = mux->val;
-                               for (e = mux->e; v < e; v = ve) {
-                                       m = mux->mask;
-                                       hp = h + mux->off;
-                                       for (ve = v + mux->len; v < ve; v++) {
-                                               if ((*hp++ & *m++) != *v)
-                                                       break;
-                                       }
-                                       if (v == ve)
-                                               goto yes;
-                               }
-               }
-               mux = mux->no;
-               continue;
-yes:
-               if (mux->conv != nil)
-                       c = mux->conv;
-               mux = mux->yes;
-       }
-       runlock(f);
-
-       if (c != nil) {
-               /* tack on interface address */
-               bp = padblock(bp, IPaddrlen);
-               ipmove(bp->rp, ifc->lifc->local);
-               bp = concatblock(bp);
-               if (bp != nil)
-                       if (qpass(c->rq, bp) < 0)
-                               print("Q");
-               return;
-       }
-
-nomatch:
-       /* doesn't match any filter, hand it to the specific protocol handler */
-       ip = (Ip4hdr *) bp->rp;
-       if ((ip->vihl & 0xF0) == 0x40) {
-               p = f->t2p[ip->proto];
-       } else {
-               ip6 = (Ip6hdr *) bp->rp;
-               p = f->t2p[ip6->proto];
-       }
-       if (p && p->rcv)
-               (*p->rcv) (p, ifc, bp);
-       else
-               freeblist(bp);
-       return;
-}
-
-static int ipmuxsprint(Ipmux * mux, int level, char *buf, int len)
-{
-       int i, j, n;
-       uchar *v;
-
-       n = 0;
-       for (i = 0; i < level; i++)
-               n += snprint(buf + n, len - n, " ");
-       if (mux == nil) {
-               n += snprint(buf + n, len - n, "\n");
-               return n;
-       }
-       n += snprint(buf + n, len - n, "h[%d:%d]&",
-                                mux->off +
-                                ((int)mux->skiphdr) * ((int)offsetof(Ip4hdr, data[0])),
-                                mux->off +
-                                (((int)mux->skiphdr) * ((int)offsetof(Ip4hdr, data[0]))) +
-                                mux->len - 1);
-       for (i = 0; i < mux->len; i++)
-               n += snprint(buf + n, len - n, "0x%2.2x", mux->mask[i]);
-       n += snprint(buf + n, len - n, "=");
-       v = mux->val;
-       for (j = 0; j < mux->n; j++) {
-               for (i = 0; i < mux->len; i++)
-                       n += snprint(buf + n, len - n, "0x%2.2x", *v++);
-               n += snprint(buf + n, len - n, "|");
-       }
-       n += snprint(buf + n, len - n, "\n");
-       level++;
-       n += ipmuxsprint(mux->no, level, buf + n, len - n);
-       n += ipmuxsprint(mux->yes, level, buf + n, len - n);
-       return n;
-}
-
-static int ipmuxstats(Proto * p, char *buf, int len)
-{
-       int n;
-       Fs *f = p->f;
-
-       rlock(f);
-       n = ipmuxsprint(p->priv, 0, buf, len);
-       runlock(f);
-
-       return n;
-}
-
-void ipmuxinit(Fs * f)
-{
-       Proto *ipmux;
-
-       ipmux = smalloc(sizeof(Proto));
-       ipmux->priv = nil;
-       ipmux->name = "ipmux";
-       ipmux->connect = ipmuxconnect;
-       ipmux->announce = ipmuxannounce;
-       ipmux->state = ipmuxstate;
-       ipmux->create = ipmuxcreate;
-       ipmux->close = ipmuxclose;
-       ipmux->rcv = ipmuxiput;
-       ipmux->ctl = nil;
-       ipmux->advise = nil;
-       ipmux->stats = ipmuxstats;
-       ipmux->ipproto = -1;
-       ipmux->nc = 64;
-       ipmux->ptclsize = sizeof(Ipmuxrock);
-
-       f->ipmux = ipmux;       /* hack for Fsrcvpcol */
-
-       Fsproto(f, ipmux);
-}
diff --git a/kern/src/net/netdevmedium.c b/kern/src/net/netdevmedium.c
deleted file mode 100644 (file)
index 199425f..0000000
+++ /dev/null
@@ -1,163 +0,0 @@
-// 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>
-
-static void netdevbind(struct Ipifc *ifc, int argc, char **argv);
-static void netdevunbind(struct Ipifc *ifc);
-static void netdevbwrite(struct Ipifc *ifc, struct block *bp, int version,
-                                                uint8_t * ip);
-static void netdevread(void *a);
-
-typedef struct Netdevrock Netdevrock;
-struct Netdevrock {
-       struct Fs *f;                           /* file system we belong to */
-       struct proc *readp;                     /* reading process */
-       struct chan *mchan;                     /* Data channel */
-};
-
-struct medium netdevmedium = {
-       .name = "netdev",
-       .hsize = 0,
-       .mintu = 0,
-       .maxtu = 64000,
-       .maclen = 0,
-       .bind = netdevbind,
-       .unbind = netdevunbind,
-       .bwrite = netdevbwrite,
-       .unbindonclose = 0,
-};
-
-/*
- *  called to bind an IP ifc to a generic network device
- *  called with ifc qlock'd
- */
-static void netdevbind(struct Ipifc *ifc, int argc, char **argv)
-{
-       struct chan *mchan;
-       Netdevrock *er;
-
-       if (argc < 2)
-               error(Ebadarg);
-
-       mchan = namec(argv[2], Aopen, ORDWR, 0);
-
-       er = kzmalloc(sizeof(*er), 0);
-       er->mchan = mchan;
-       er->f = ifc->conv->p->f;
-
-       ifc->arg = er;
-
-       ktask("netdevread", netdevread, ifc);
-}
-
-/*
- *  called with ifc wlock'd
- */
-static void netdevunbind(struct Ipifc *ifc)
-{
-       Netdevrock *er = ifc->arg;
-/*
-       if(er->readp != NULL)
-               postnote(er->readp, 1, "unbind", 0);
-*/
-       printk("%s is messed up, shouldn't track procs\n", __FUNCTION__);
-       /* wait for readers to die */
-       while (er->readp != NULL)
-               udelay_sched(300 * 1000);
-
-       if (er->mchan != NULL)
-               cclose(er->mchan);
-
-       kfree(er);
-}
-
-/*
- *  called by ipoput with a single block to write
- */
-static void
-netdevbwrite(struct Ipifc *ifc, struct block *bp, int unused_int,
-                        uint8_t * unused_uint8_p_t)
-{
-       Netdevrock *er = ifc->arg;
-
-       if (bp->next)
-               bp = concatblock(bp);
-       if (BLEN(bp) < ifc->mintu)
-               bp = adjustblock(bp, ifc->mintu);
-
-       ptclcsum_finalize(bp, 0);
-       devtab[er->mchan->type].bwrite(er->mchan, bp, 0);
-       ifc->out++;
-}
-
-/*
- *  process to read from the device
- */
-static void netdevread(void *a)
-{
-       ERRSTACK(2);
-       struct Ipifc *ifc;
-       struct block *bp;
-       Netdevrock *er;
-       char *argv[1];
-
-       ifc = a;
-       er = ifc->arg;
-       er->readp = current;    /* hide identity under a rock for unbind */
-       if (waserror()) {
-               er->readp = NULL;
-               warn("netdevread returns unexpectedly");
-               poperror();
-               return;
-       }
-       for (;;) {
-               bp = devtab[er->mchan->type].bread(er->mchan, ifc->maxtu, 0);
-               if (bp == NULL) {
-                       /*
-                        * get here if mchan is a pipe and other side hangs up
-                        * clean up this interface & get out
-                        ZZZ is this a good idea?  (watch your errors btw)
-                        */
-                       poperror();
-                       er->readp = NULL;
-                       argv[0] = "unbind";
-                       if (!waserror())
-                               ifc->conv->p->ctl(ifc->conv, argv, 1);
-                       poperror();
-                       warn("netdevread returns unexpectedly");
-                       return;
-               }
-               if (!canrlock(&ifc->rwlock)) {
-                       freeb(bp);
-                       continue;
-               }
-               if (waserror()) {
-                       runlock(&ifc->rwlock);
-                       nexterror();
-               }
-               ifc->in++;
-               if (ifc->lifc == NULL)
-                       freeb(bp);
-               else
-                       ipiput4(er->f, ifc, bp);
-               runlock(&ifc->rwlock);
-               poperror();
-       }
-       poperror();
-}
-
-void netdevmediumlink(void)
-{
-       addipmedium(&netdevmedium);
-}
diff --git a/kern/src/net/ppp.c b/kern/src/net/ppp.c
deleted file mode 100644 (file)
index 96ae623..0000000
+++ /dev/null
@@ -1,1653 +0,0 @@
-#include       "u.h"
-#include       "../port/lib.h"
-#include       "mem.h"
-#include       "dat.h"
-#include       "fns.h"
-#include       "../port/error.h"
-#include       <libcrypt.h>
-#include       <kernel.h>
-#include       "ip.h"
-#include       "ppp.h"
-
-int nocompress;
-Ipaddr pppdns[2];
-
-/*
- * Calculate FCS - rfc 1331
- */
-ushort fcstab[256] = {
-       0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf,
-       0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7,
-       0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e,
-       0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876,
-       0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd,
-       0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5,
-       0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c,
-       0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974,
-       0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb,
-       0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3,
-       0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a,
-       0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72,
-       0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9,
-       0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1,
-       0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738,
-       0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70,
-       0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7,
-       0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff,
-       0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036,
-       0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e,
-       0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5,
-       0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd,
-       0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134,
-       0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c,
-       0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3,
-       0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb,
-       0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232,
-       0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a,
-       0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1,
-       0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9,
-       0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330,
-       0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78
-};
-
-static char *snames[] = {
-       "Sclosed",
-       "Sclosing",
-       "Sreqsent",
-       "Sackrcvd",
-       "Sacksent",
-       "Sopened",
-};
-
-static void init(PPP *);
-static void setphase(PPP *, int);
-static void pinit(PPP *, Pstate *);
-static void ppptimer(void *);
-static void ptimer(PPP *, Pstate *);
-static int getframe(PPP *, Block **);
-static Block *putframe(PPP *, int, Block *);
-static uchar *escapebyte(PPP *, ulong, uchar *, ushort *);
-static void config(PPP *, Pstate *, int);
-static int getopts(PPP *, Pstate *, Block *);
-static void rejopts(PPP *, Pstate *, Block *, int);
-static void newstate(PPP *, Pstate *, int);
-static void rcv(PPP *, Pstate *, Block *);
-static void getchap(PPP *, Block *);
-static void getpap(PPP *, Block *);
-static void sendpap(PPP *);
-static void getlqm(PPP *, Block *);
-static void putlqm(PPP *);
-static void hangup(PPP *);
-static void remove(PPP *);
-
-static int validv4(Ipaddr);
-static void invalidate(Ipaddr);
-static void ipconnect(PPP *);
-static void setdefroute(PPP *, Ipaddr);
-static void printopts(PPP *, Pstate *, Block *, int);
-static void sendtermreq(PPP *, Pstate *);
-
-static void errlog(PPP * ppp, char *err)
-{
-       int n;
-       char msg[64];
-
-       n = snprint(msg, sizeof(msg), "%s\n", err);
-       qproduce(ppp->ifc->conv->eq, msg, n);
-}
-
-static void init(PPP * ppp)
-{
-       if (ppp->inbuf == nil) {
-               ppp->inbuf = allocb(4096);
-               ppp->outbuf = allocb(4096);
-
-               ppp->lcp = malloc(sizeof(Pstate));
-               ppp->ipcp = malloc(sizeof(Pstate));
-               if (ppp->lcp == nil || ppp->ipcp == nil)
-                       error("ppp init: malloc");
-
-               ppp->lcp->proto = Plcp;
-               ppp->lcp->state = Sclosed;
-               ppp->ipcp->proto = Pipcp;
-               ppp->ipcp->state = Sclosed;
-
-               ktask("ppptimer", ppptimer, ppp);
-       }
-
-       pinit(ppp, ppp->lcp);
-       setphase(ppp, Plink);
-}
-
-static void setphase(PPP * ppp, int phase)
-{
-       int oldphase;
-
-       oldphase = ppp->phase;
-
-       ppp->phase = phase;
-       switch (phase) {
-               default:
-                       panic("ppp: unknown phase %d", phase);
-               case Pdead:
-                       /* restart or exit? */
-                       pinit(ppp, ppp->lcp);
-                       setphase(ppp, Plink);
-                       break;
-               case Plink:
-                       /* link down */
-                       switch (oldphase) {
-                               case Pnet:
-                                       newstate(ppp, ppp->ipcp, Sclosed);
-                       }
-                       break;
-               case Pauth:
-                       if (ppp->usepap)
-                               sendpap(ppp);
-                       else if (!ppp->usechap)
-                               setphase(ppp, Pnet);
-                       break;
-               case Pnet:
-                       pinit(ppp, ppp->ipcp);
-                       break;
-               case Pterm:
-                       /* what? */
-                       break;
-       }
-}
-
-static void pinit(PPP * ppp, Pstate * p)
-{
-       p->timeout = 0;
-
-       switch (p->proto) {
-               case Plcp:
-                       ppp->magic = TK2MS(MACHP(0)->ticks);
-                       ppp->xctlmap = 0xffffffff;
-                       ppp->period = 0;
-                       p->optmask = 0xffffffff;
-                       ppp->rctlmap = 0;
-                       ppp->ipcp->state = Sclosed;
-                       ppp->ipcp->optmask = 0xffffffff;
-
-                       /* quality goo */
-                       ppp->timeout = 0;
-                       memset(&ppp->in, 0, sizeof(ppp->in));
-                       memset(&ppp->out, 0, sizeof(ppp->out));
-                       memset(&ppp->pin, 0, sizeof(ppp->pin));
-                       memset(&ppp->pout, 0, sizeof(ppp->pout));
-                       memset(&ppp->sin, 0, sizeof(ppp->sin));
-                       break;
-               case Pipcp:
-                       if (ppp->localfrozen == 0)
-                               invalidate(ppp->local);
-                       if (ppp->remotefrozen == 0)
-                               invalidate(ppp->remote);
-                       p->optmask = 0xffffffff;
-                       ppp->ctcp = compress_init(ppp->ctcp);
-                       ppp->usedns = 3;
-                       invalidate(ppp->dns1);
-                       invalidate(ppp->dns2);
-                       break;
-       }
-       p->confid = p->rcvdconfid = -1;
-       config(ppp, p, 1);
-       newstate(ppp, p, Sreqsent);
-}
-
-/*
- *  change protocol to a new state.
- */
-static void newstate(PPP * ppp, Pstate * p, int state)
-{
-       netlog(ppp->f, Logppp,
-                  "0x%x 0x%x %s->%s ctlmap 0x%lx/0x%lx flags 0x%x mtu %d mru %d\n",
-                  ppp, p->proto, snames[p->state], snames[state], ppp->rctlmap,
-                  ppp->xctlmap, p->flags, ppp->mtu, ppp->mru);
-
-       if (p->proto == Plcp) {
-               if (state == Sopened)
-                       setphase(ppp, Pauth);
-               else if (state == Sclosed)
-                       setphase(ppp, Pdead);
-               else if (p->state == Sopened)
-                       setphase(ppp, Plink);
-       }
-
-       if (p->proto == Pipcp && state == Sopened && validv4(ppp->local)
-               && validv4(ppp->remote)) {
-               netlog(ppp->f, Logppp, "pppnewstate: local %I remote %I\n", ppp->local,
-                          ppp->remote);
-               ipmove(pppdns[0], ppp->dns1);
-               ipmove(pppdns[1], ppp->dns2);
-               ipconnect(ppp);
-               /* if this is the only network, set up a default route */
-//      if(ppp->ifc->link==nil)     /* how??? */
-               setdefroute(ppp, ppp->remote);
-               errlog(ppp, Enoerror);
-       }
-
-       p->state = state;
-}
-
-static void remove(PPP * ppp)
-{
-       free(ppp->ipcp);
-       ppp->ipcp = 0;
-       free(ppp->ctcp);
-       ppp->ctcp = 0;
-       free(ppp->lcp);
-       ppp->lcp = 0;
-       if (ppp->inbuf) {
-               freeb(ppp->inbuf);
-               ppp->inbuf = nil;
-       }
-       if (ppp->outbuf) {
-               freeb(ppp->outbuf);
-               ppp->outbuf = nil;
-       }
-       free(ppp);
-}
-
-void pppclose(PPP * ppp)
-{
-       hangup(ppp);
-       remove(ppp);
-}
-
-static void dumpblock(Block * b)
-{
-       char x[256];
-       int i;
-
-       for (i = 0; i < (sizeof(x) - 1) / 3 && b->rp + i < b->wp; i++)
-               sprint(&x[3 * i], "0x%2.2x ", b->rp[i]);
-       print("%s\n", x);
-}
-
-/* returns (protocol, information) */
-static int getframe(PPP * ppp, Block ** info)
-{
-       uchar *p, *from, *to;
-       int n, len, proto;
-       ulong c;
-       ushort fcs;
-       Block *buf, *b;
-
-       buf = ppp->inbuf;
-       for (;;) {
-               /* read till we hit a frame byte or run out of room */
-               for (p = buf->rp; buf->wp < buf->lim;) {
-                       for (; p < buf->wp; p++)
-                               if (*p == HDLC_frame)
-                                       goto break2;
-
-                       len = buf->lim - buf->wp;
-                       n = 0;
-                       if (ppp->dchan != nil)
-                               n = kchanio(ppp->dchan, buf->wp, len, OREAD);
-                       netlog(ppp->f, Logppp, "ppp kchanio %d bytes\n", n);
-                       if (n <= 0) {
-                               buf->wp = buf->rp;
-//              if(n < 0)
-//                  print("ppp kchanio(%s) returned %d: %r",
-//                      ppp->dchan->path->elem, n);
-                               *info = nil;
-                               return 0;
-                       }
-                       buf->wp += n;
-               }
-break2:
-
-               /* copy into block, undoing escapes, and caculating fcs */
-               fcs = PPP_initfcs;
-               b = allocb(p - buf->rp);
-               to = b->wp;
-               for (from = buf->rp; from != p;) {
-                       c = *from++;
-                       if (c == HDLC_esc) {
-                               if (from == p)
-                                       break;
-                               c = *from++ ^ 0x20;
-                       } else if ((c < 0x20) && (ppp->rctlmap & (1 << c)))
-                               continue;
-                       *to++ = c;
-                       fcs = (fcs >> 8) ^ fcstab[(fcs ^ c) & 0xff];
-               }
-
-               /* copy down what's left in buffer */
-               p++;
-               memmove(buf->rp, p, buf->wp - p);
-               n = p - buf->rp;
-               buf->wp -= n;
-               b->wp = to - 2;
-
-               /* return to caller if checksum matches */
-               if (fcs == PPP_goodfcs) {
-                       if (b->rp[0] == PPP_addr && b->rp[1] == PPP_ctl)
-                               b->rp += 2;
-                       proto = *b->rp++;
-                       if ((proto & 0x1) == 0)
-                               proto = (proto << 8) | *b->rp++;
-                       if (b->rp < b->wp) {
-                               ppp->in.bytes += n;
-                               ppp->in.packets++;
-                               *info = b;
-                               return proto;
-                       }
-               } else if (BLEN(b) > 0) {
-                       ppp->ifc->inerr++;
-                       ppp->in.discards++;
-                       netlog(ppp->f, Logppp,
-                                  "len %d/%d cksum 0x%x (0x%x 0x%x 0x%x 0x%x)\n", BLEN(b),
-                                  BLEN(buf), fcs, b->rp[0], b->rp[1], b->rp[2], b->rp[3]);
-               }
-
-               freeblist(b);
-       }
-       *info = nil;
-       return 0;
-}
-
-/* send a PPP frame */
-static Block *putframe(PPP * ppp, int proto, Block * b)
-{
-       Block *buf;
-       uchar *to, *from;
-       ushort fcs;
-       ulong ctlmap;
-       int c;
-       Block *bp;
-
-       if (ppp->dchan == nil) {
-               netlog(ppp->f, Logppp, "putframe: dchan down\n");
-               errlog(ppp, Ehungup);
-               return b;
-       }
-       netlog(ppp->f, Logppp, "putframe 0x%x %d %d (%d bytes)\n", proto, b->rp[0],
-                  b->rp[1], BLEN(b));
-
-       ppp->out.packets++;
-
-       if (proto == Plcp)
-               ctlmap = 0xffffffff;
-       else
-               ctlmap = ppp->xctlmap;
-
-       /* make sure we have head room */
-       if (b->rp - b->base < 4) {
-               b = padblock(b, 4);
-               b->rp += 4;
-       }
-
-       /* add in the protocol and address, we'd better have left room */
-       from = b->rp;
-       *--from = proto;
-       if (!(ppp->lcp->flags & Fpc) || proto > 0x100 || proto == Plcp)
-               *--from = proto >> 8;
-       if (!(ppp->lcp->flags & Fac) || proto == Plcp) {
-               *--from = PPP_ctl;
-               *--from = PPP_addr;
-       }
-
-       qlock(&ppp->outlock);
-       buf = ppp->outbuf;
-
-       /* escape and checksum the body */
-       fcs = PPP_initfcs;
-       to = buf->rp;
-
-       *to++ = HDLC_frame;
-
-       for (bp = b; bp; bp = bp->next) {
-               if (bp != b)
-                       from = bp->rp;
-               for (; from < bp->wp; from++) {
-                       c = *from;
-                       if (c == HDLC_frame || c == HDLC_esc
-                               || (c < 0x20 && ((1 << c) & ctlmap))) {
-                               *to++ = HDLC_esc;
-                               *to++ = c ^ 0x20;
-                       } else
-                               *to++ = c;
-                       fcs = (fcs >> 8) ^ fcstab[(fcs ^ c) & 0xff];
-               }
-       }
-
-       /* add on and escape the checksum */
-       fcs = ~fcs;
-       c = fcs;
-       if (c == HDLC_frame || c == HDLC_esc || (c < 0x20 && ((1 << c) & ctlmap))) {
-               *to++ = HDLC_esc;
-               *to++ = c ^ 0x20;
-       } else
-               *to++ = c;
-       c = fcs >> 8;
-       if (c == HDLC_frame || c == HDLC_esc || (c < 0x20 && ((1 << c) & ctlmap))) {
-               *to++ = HDLC_esc;
-               *to++ = c ^ 0x20;
-       } else
-               *to++ = c;
-
-       /* add frame marker and send */
-       *to++ = HDLC_frame;
-       buf->wp = to;
-       if (ppp->dchan == nil) {
-               netlog(ppp->f, Logppp, "putframe: dchan down\n");
-               errlog(ppp, Ehungup);
-       } else {
-               kchanio(ppp->dchan, buf->rp, BLEN(buf), OWRITE);
-               ppp->out.bytes += BLEN(buf);
-       }
-
-       qunlock(&ppp->outlock);
-       return b;
-}
-
-#define IPB2LCP(b) ((Lcpmsg*)((b)->wp-4))
-
-static Block *alloclcp(int code, int id, int len)
-{
-       Block *b;
-       Lcpmsg *m;
-
-       /*
-        *  leave room for header
-        */
-       b = allocb(len);
-
-       m = (Lcpmsg *) b->wp;
-       m->code = code;
-       m->id = id;
-       b->wp += 4;
-
-       return b;
-}
-
-static void putao(Block * b, int type, int aproto, int alg)
-{
-       *b->wp++ = type;
-       *b->wp++ = 5;
-       hnputs(b->wp, aproto);
-       b->wp += 2;
-       *b->wp++ = alg;
-}
-
-static void putlo(Block * b, int type, ulong val)
-{
-       *b->wp++ = type;
-       *b->wp++ = 6;
-       hnputl(b->wp, val);
-       b->wp += 4;
-}
-
-static void putv4o(Block * b, int type, Ipaddr val)
-{
-       *b->wp++ = type;
-       *b->wp++ = 6;
-       if (v6tov4(b->wp, val) < 0) {
-               /*panic("putv4o") */ ;
-       }
-       b->wp += 4;
-}
-
-static void putso(Block * b, int type, ulong val)
-{
-       *b->wp++ = type;
-       *b->wp++ = 4;
-       hnputs(b->wp, val);
-       b->wp += 2;
-}
-
-static void puto(Block * b, int type)
-{
-       *b->wp++ = type;
-       *b->wp++ = 2;
-}
-
-/*
- *  send configuration request
- */
-static void config(PPP * ppp, Pstate * p, int newid)
-{
-       Block *b;
-       Lcpmsg *m;
-       int id;
-
-       if (newid) {
-               id = ++(p->id);
-               p->confid = id;
-               p->timeout = Timeout;
-       } else
-               id = p->confid;
-       b = alloclcp(Lconfreq, id, 256);
-       m = IPB2LCP(b);
-       USED(m);
-
-       switch (p->proto) {
-               case Plcp:
-                       if (p->optmask & Fmagic)
-                               putlo(b, Omagic, ppp->magic);
-                       if (p->optmask & Fmtu)
-                               putso(b, Omtu, ppp->mru);
-                       if (p->optmask & Fac)
-                               puto(b, Oac);
-                       if (p->optmask & Fpc)
-                               puto(b, Opc);
-                       if (p->optmask & Fctlmap)
-                               putlo(b, Octlmap, 0);   /* we don't want anything escaped */
-                       break;
-               case Pipcp:
-                       if ((p->optmask & Fipaddr) /*&& validv4(ppp->local) */ )
-                               putv4o(b, Oipaddr, ppp->local);
-                       if (!nocompress && (p->optmask & Fipcompress)) {
-                               *b->wp++ = Oipcompress;
-                               *b->wp++ = 6;
-                               hnputs(b->wp, Pvjctcp);
-                               b->wp += 2;
-                               *b->wp++ = MAX_STATES - 1;
-                               *b->wp++ = 1;
-                       }
-                       if (ppp->usedns & 1)
-                               putlo(b, Oipdns, 0);
-                       if (ppp->usedns & 2)
-                               putlo(b, Oipdns2, 0);
-                       break;
-       }
-
-       hnputs(m->len, BLEN(b));
-       b = putframe(ppp, p->proto, b);
-       freeblist(b);
-}
-
-/*
- *  parse configuration request, sends an ack or reject packet
- *
- *     returns:        -1 if request was syntacticly incorrect
- *                      0 if packet was accepted
- *                      1 if packet was rejected
- */
-static int getopts(PPP * ppp, Pstate * p, Block * b)
-{
-       Lcpmsg *m, *repm;
-       Lcpopt *o;
-       uchar *cp;
-       ulong rejecting, nacking, flags, proto;
-       ulong mtu, ctlmap, period;
-       ulong x;
-       Block *repb;
-       Ipaddr ipaddr;
-
-       rejecting = 0;
-       nacking = 0;
-       flags = 0;
-
-       /* defaults */
-       invalidate(ipaddr);
-       mtu = ppp->mtu;
-
-       ctlmap = 0xffffffff;
-       period = 0;
-
-       m = (Lcpmsg *) b->rp;
-       repb = alloclcp(Lconfack, m->id, BLEN(b));
-       repm = IPB2LCP(repb);
-
-       /* copy options into ack packet */
-       memmove(repm->data, m->data, b->wp - m->data);
-       repb->wp += b->wp - m->data;
-
-       /* look for options we don't recognize or like */
-       for (cp = m->data; cp < b->wp; cp += o->len) {
-               o = (Lcpopt *) cp;
-               if (cp + o->len > b->wp || o->len == 0) {
-                       freeblist(repb);
-                       netlog(ppp->f, Logppp, "ppp %s: bad option length 0x%x\n",
-                                  ppp->ifc->dev, o->type);
-                       return -1;
-               }
-
-               switch (p->proto) {
-                       case Plcp:
-                               switch (o->type) {
-                                       case Oac:
-                                               flags |= Fac;
-                                               continue;
-                                       case Opc:
-                                               flags |= Fpc;
-                                               continue;
-                                       case Omtu:
-                                               mtu = nhgets(o->data);
-                                               if (mtu < ppp->ifc->m->mintu) {
-                                                       netlog(ppp->f, Logppp, "bogus mtu %d\n", mtu);
-                                                       mtu = ppp->ifc->m->mintu;
-                                               }
-                                               continue;
-                                       case Omagic:
-                                               if (ppp->magic == nhgetl(o->data))
-                                                       netlog(ppp->f, Logppp, "ppp: possible loop\n");
-                                               continue;
-                                       case Octlmap:
-                                               ctlmap = nhgetl(o->data);
-                                               continue;
-                                       case Oquality:
-                                               proto = nhgets(o->data);
-                                               if (proto != Plqm)
-                                                       break;
-                                               x = nhgetl(o->data + 2) * 10;
-                                               period = (x + Period - 1) / Period;
-                                               continue;
-                                       case Oauth:
-                                               proto = nhgets(o->data);
-                                               if (proto == Ppap && ppp->chapname[0] && ppp->secret[0]) {
-                                                       ppp->usepap = 1;
-                                                       netlog(ppp->f, Logppp, "PPP %s: select PAP\n",
-                                                                  ppp->ifc->dev);
-                                                       continue;
-                                               }
-                                               if (proto != Pchap || o->data[2] != APmd5) {
-                                                       if (!nacking) {
-                                                               nacking = 1;
-                                                               repb->wp = repm->data;
-                                                               repm->code = Lconfnak;
-                                                       }
-                                                       putao(repb, Oauth, Pchap, APmd5);
-                                               } else
-                                                       ppp->usechap = 1;
-                                               ppp->usepap = 0;
-                                               continue;
-                               }
-                               break;
-                       case Pipcp:
-                               switch (o->type) {
-                                       case Oipaddr:
-                                               v4tov6(ipaddr, o->data);
-                                               if (!validv4(ppp->remote))
-                                                       continue;
-                                               if (!validv4(ipaddr) && !rejecting) {
-                                                       /* other side requesting an address */
-                                                       if (!nacking) {
-                                                               nacking = 1;
-                                                               repb->wp = repm->data;
-                                                               repm->code = Lconfnak;
-                                                       }
-                                                       putv4o(repb, Oipaddr, ppp->remote);
-                                               }
-                                               continue;
-                                       case Oipcompress:
-                                               proto = nhgets(o->data);
-                                               if (nocompress || proto != Pvjctcp
-                                                       || compress_negotiate(ppp->ctcp, o->data + 2) < 0)
-                                                       break;
-                                               flags |= Fipcompress;
-                                               continue;
-                               }
-                               break;
-               }
-
-               /* come here if option is not recognized */
-               if (!rejecting) {
-                       rejecting = 1;
-                       repb->wp = repm->data;
-                       repm->code = Lconfrej;
-               }
-               netlog(ppp->f, Logppp, "ppp %s: bad 0x%x option %d\n", ppp->ifc->dev,
-                          p->proto, o->type);
-               memmove(repb->wp, o, o->len);
-               repb->wp += o->len;
-       }
-
-       /* permanent changes only after we know that we liked the packet */
-       if (!rejecting && !nacking) {
-               switch (p->proto) {
-                       case Plcp:
-                               netlog(ppp->f, Logppp,
-                                          "Plcp: mtu: %d %d x:0x%lx/r:0x%lx 0x%lx\n", mtu,
-                                          ppp->mtu, ppp->xctlmap, ppp->rctlmap, ctlmap);
-                               ppp->period = period;
-                               ppp->xctlmap = ctlmap;
-                               if (mtu > Maxmtu)
-                                       mtu = Maxmtu;
-                               if (mtu < Minmtu)
-                                       mtu = Minmtu;
-                               ppp->mtu = mtu;
-                               break;
-                       case Pipcp:
-                               if (validv4(ipaddr) && ppp->remotefrozen == 0)
-                                       ipmove(ppp->remote, ipaddr);
-                               break;
-               }
-               p->flags = flags;
-       }
-
-       hnputs(repm->len, BLEN(repb));
-       repb = putframe(ppp, p->proto, repb);
-       freeblist(repb);
-
-       return rejecting || nacking;
-}
-
-/*
- *  parse configuration rejection, just stop sending anything that they
- *  don't like (except for ipcp address nak).
- */
-static void rejopts(PPP * ppp, Pstate * p, Block * b, int code)
-{
-       Lcpmsg *m;
-       Lcpopt *o;
-
-       /* just give up trying what the other side doesn't like */
-       m = (Lcpmsg *) b->rp;
-       for (b->rp = m->data; b->rp < b->wp; b->rp += o->len) {
-               o = (Lcpopt *) b->rp;
-               if (b->rp + o->len > b->wp || o->len == 0) {
-                       netlog(ppp->f, Logppp, "ppp %s: bad roption length 0x%x\n",
-                                  ppp->ifc->dev, o->type);
-                       return;
-               }
-
-               if (code == Lconfrej) {
-                       if (o->type < 8 * sizeof(p->optmask))
-                               p->optmask &= ~(1 << o->type);
-                       if (o->type == Oipdns)
-                               ppp->usedns &= ~1;
-                       else if (o->type == Oipdns2)
-                               ppp->usedns &= ~2;
-                       netlog(ppp->f, Logppp, "ppp %s: 0x%x rejecting %d\n", ppp->ifc->dev,
-                                  p->proto, o->type);
-                       continue;
-               }
-
-               switch (p->proto) {
-                       case Plcp:
-                               switch (o->type) {
-                                       case Octlmap:
-                                               ppp->rctlmap = nhgetl(o->data);
-                                               break;
-                                       default:
-                                               if (o->type < 8 * sizeof(p->optmask))
-                                                       p->optmask &= ~(1 << o->type);
-                                               break;
-                               };
-                       case Pipcp:
-                               switch (o->type) {
-                                       case Oipaddr:
-                                               if (!validv4(ppp->local))
-                                                       v4tov6(ppp->local, o->data);
-//              if(o->type < 8*sizeof(p->optmask))
-//                  p->optmask &= ~(1<<o->type);
-                                               break;
-                                       case Oipdns:
-                                               if (!validv4(ppp->dns1))
-                                                       v4tov6(ppp->dns1, o->data);
-                                               ppp->usedns &= ~1;
-                                               break;
-                                       case Oipdns2:
-                                               if (!validv4(ppp->dns2))
-                                                       v4tov6(ppp->dns2, o->data);
-                                               ppp->usedns &= ~2;
-                                               break;
-                                       default:
-                                               if (o->type < 8 * sizeof(p->optmask))
-                                                       p->optmask &= ~(1 << o->type);
-                                               break;
-                               }
-                               break;
-               }
-       }
-}
-
-/*
- *  put a messages through the lcp or ipcp state machine.  They are
- *  very similar.
- */
-static void rcv(PPP * ppp, Pstate * p, Block * b)
-{
-       ulong len;
-       int err;
-       Lcpmsg *m;
-
-       if (BLEN(b) < 4) {
-               netlog(ppp->f, Logppp, "ppp %s: short lcp message\n", ppp->ifc->dev);
-               freeblist(b);
-               return;
-       }
-       m = (Lcpmsg *) b->rp;
-       len = nhgets(m->len);
-       if (BLEN(b) < len) {
-               netlog(ppp->f, Logppp, "ppp %s: short lcp message\n", ppp->ifc->dev);
-               freeblist(b);
-               return;
-       }
-
-       netlog(ppp->f, Logppp, "ppp: 0x%x rcv %d len %d id %d/%d/%d\n",
-                  p->proto, m->code, len, m->id, p->confid, p->id);
-
-       if (p->proto != Plcp && ppp->lcp->state != Sopened) {
-               netlog(ppp->f, Logppp, "ppp: non-lcp with lcp not open\n");
-               freeb(b);
-               return;
-       }
-
-       qlock(ppp);
-       switch (m->code) {
-               case Lconfreq:
-                       /* flush the output queue */
-                       if (p->state == Sopened && p->proto == Plcp)
-                               kchanio(ppp->cchan, "f", 1, OWRITE);
-
-                       printopts(ppp, p, b, 0);
-                       err = getopts(ppp, p, b);
-                       if (err < 0)
-                               break;
-
-                       if (m->id == p->rcvdconfid)
-                               break;  /* don't change state for duplicates */
-                       p->rcvdconfid = m->id;
-
-                       switch (p->state) {
-                               case Sackrcvd:
-                                       if (err)
-                                               break;
-                                       newstate(ppp, p, Sopened);
-                                       break;
-                               case Sclosed:
-                               case Sopened:
-                                       config(ppp, p, 1);
-                                       if (err == 0)
-                                               newstate(ppp, p, Sacksent);
-                                       else
-                                               newstate(ppp, p, Sreqsent);
-                                       break;
-                                       break;
-                               case Sreqsent:
-                               case Sacksent:
-                                       if (err == 0)
-                                               newstate(ppp, p, Sacksent);
-                                       else
-                                               newstate(ppp, p, Sreqsent);
-                                       break;
-                       }
-                       break;
-               case Lconfack:
-                       if (p->confid != m->id) {
-                               /* ignore if it isn't the message we're sending */
-                               netlog(ppp->f, Logppp, "ppp: dropping confack\n");
-                               break;
-                       }
-                       p->confid = -1; /* ignore duplicates */
-                       p->id++;        /* avoid sending duplicates */
-
-                       switch (p->state) {
-                               case Sopened:
-                               case Sackrcvd:
-                                       config(ppp, p, 1);
-                                       newstate(ppp, p, Sreqsent);
-                                       break;
-                               case Sreqsent:
-                                       newstate(ppp, p, Sackrcvd);
-                                       break;
-                               case Sacksent:
-                                       newstate(ppp, p, Sopened);
-                                       break;
-                       }
-                       break;
-               case Lconfrej:
-               case Lconfnak:
-                       if (p->confid != m->id) {
-                               /* ignore if it isn't the message we're sending */
-                               netlog(ppp->f, Logppp, "ppp: dropping confrej or confnak\n");
-                               break;
-                       }
-                       p->confid = -1; /* ignore duplicates */
-                       p->id++;        /* avoid sending duplicates */
-
-                       switch (p->state) {
-                               case Sopened:
-                               case Sackrcvd:
-                                       config(ppp, p, 1);
-                                       newstate(ppp, p, Sreqsent);
-                                       break;
-                               case Sreqsent:
-                               case Sacksent:
-                                       printopts(ppp, p, b, 0);
-                                       rejopts(ppp, p, b, m->code);
-                                       config(ppp, p, 1);
-                                       break;
-                       }
-                       break;
-               case Ltermreq:
-                       m->code = Ltermack;
-                       b = putframe(ppp, p->proto, b);
-
-                       switch (p->state) {
-                               case Sackrcvd:
-                               case Sacksent:
-                                       newstate(ppp, p, Sreqsent);
-                                       break;
-                               case Sopened:
-                                       newstate(ppp, p, Sclosing);
-                                       break;
-                       }
-                       break;
-               case Ltermack:
-                       if (p->termid != m->id) /* ignore if it isn't the message we're sending */
-                               break;
-
-                       if (p->proto == Plcp)
-                               ppp->ipcp->state = Sclosed;
-                       switch (p->state) {
-                               case Sclosing:
-                                       newstate(ppp, p, Sclosed);
-                                       break;
-                               case Sackrcvd:
-                                       newstate(ppp, p, Sreqsent);
-                                       break;
-                               case Sopened:
-                                       config(ppp, p, 0);
-                                       newstate(ppp, p, Sreqsent);
-                                       break;
-                       }
-                       break;
-               case Lcoderej:
-                       netlog(ppp->f, Logppp, "ppp %s: code reject %d\n", ppp->ifc->dev,
-                                  m->data[0]);
-                       break;
-               case Lprotorej:
-                       netlog(ppp->f, Logppp, "ppp %s: proto reject 0x%lx\n",
-                                  ppp->ifc->dev, nhgets(m->data));
-                       break;
-               case Lechoreq:
-                       m->code = Lechoack;
-                       b = putframe(ppp, p->proto, b);
-                       break;
-               case Lechoack:
-               case Ldiscard:
-                       /* nothing to do */
-                       break;
-       }
-
-       qunlock(ppp);
-       freeblist(b);
-}
-
-/*
- *  timer for protocol state machine
- */
-static void ptimer(PPP * ppp, Pstate * p)
-{
-       if (p->state == Sopened || p->state == Sclosed)
-               return;
-
-       p->timeout--;
-       switch (p->state) {
-               case Sclosing:
-                       sendtermreq(ppp, p);
-                       break;
-               case Sreqsent:
-               case Sacksent:
-                       if (p->timeout <= 0) {
-                               if (p->proto && ppp->cchan != nil)
-                                       kchanio(ppp->cchan, "f", 1, OWRITE);    /* flush output queue */
-                               newstate(ppp, p, Sclosed);
-                       } else {
-                               config(ppp, p, 0);
-                       }
-                       break;
-               case Sackrcvd:
-                       if (p->timeout <= 0) {
-                               if (p->proto && ppp->cchan != nil)
-                                       kchanio(ppp->cchan, "f", 1, OWRITE);    /* flush output queue */
-                               newstate(ppp, p, Sclosed);
-                       } else {
-                               config(ppp, p, 0);
-                               newstate(ppp, p, Sreqsent);
-                       }
-                       break;
-       }
-}
-
-/*
- *  timer for ppp
- */
-static void ppptimer(void *arg)
-{
-       PPP *ppp;
-
-       ppp = arg;
-       ppp->timep = up;
-       if (waserror()) {
-               netlog(ppp->f, Logppp, "ppptimer: %I: %s\n", ppp->local,
-                          up->env->errstr);
-               ppp->timep = 0;
-               pexit("hangup", 1);
-       }
-       for (;;) {
-               udelay_sched(Period * 1000);
-               if (ppp->pppup) {
-                       qlock(ppp);
-
-                       ptimer(ppp, ppp->lcp);
-                       if (ppp->lcp->state == Sopened)
-                               ptimer(ppp, ppp->ipcp);
-
-                       if (ppp->period && --(ppp->timeout) <= 0) {
-                               ppp->timeout = ppp->period;
-                               putlqm(ppp);
-                       }
-
-                       qunlock(ppp);
-               }
-       }
-}
-
-static void setdefroute(PPP * ppp, Ipaddr gate)
-{
-       int fd, n;
-       char path[128], msg[128];
-
-       snprint(path, sizeof path, "#I%d/iproute", ppp->f->dev);
-       fd = kopen(path, ORDWR);
-       if (fd < 0)
-               return;
-       n = snprint(msg, sizeof(msg), "add 0 0 %I", gate);
-       kwrite(fd, msg, n);
-       kclose(fd);
-}
-
-static void ipconnect(PPP * ppp)
-{
-       int fd, n;
-       char path[128], msg[128];
-
-       snprint(path, sizeof path, "#I%d/ipifc/%d/ctl", ppp->f->dev,
-                       ppp->ifc->conv->x);
-       fd = kopen(path, ORDWR);
-       if (fd < 0)
-               return;
-       n = snprint(msg, sizeof(msg), "connect %I 255.255.255.255 %I", ppp->local,
-                               ppp->remote);
-       if (kwrite(fd, msg, n) != n)
-               print("ppp ipconnect: %s: %r\n", msg);
-       kclose(fd);
-}
-
-PPP *pppopen(PPP * ppp, char *dev,
-                        Ipaddr ipaddr, Ipaddr remip,
-                        int mtu, int framing, char *chapname, char *secret)
-{
-       int fd, cfd;
-       char ctl[Maxpath];
-
-       invalidate(ppp->remote);
-       invalidate(ppp->local);
-       invalidate(ppp->dns1);
-       invalidate(ppp->dns2);
-       ppp->mtu = Defmtu;
-       ppp->mru = mtu;
-       ppp->framing = framing;
-
-       if (remip != nil && validv4(remip)) {
-               ipmove(ppp->remote, remip);
-               ppp->remotefrozen = 1;
-       }
-       if (ipaddr != nil && validv4(ipaddr)) {
-               ipmove(ppp->local, ipaddr);
-               ppp->localfrozen = 1;
-       }
-
-       /* authentication goo */
-       ppp->secret[0] = 0;
-       if (secret != nil)
-               strncpy(ppp->secret, secret, sizeof(ppp->secret));
-       ppp->chapname[0] = 0;
-       if (chapname != nil)
-               strncpy(ppp->chapname, chapname, sizeof(ppp->chapname));
-
-       if (strchr(dev, '!'))
-               fd = kdial(dev, nil, nil, nil);
-       else
-               fd = kopen(dev, ORDWR);
-       if (fd < 0) {
-               netlog(ppp->f, Logppp, "ppp: can't open %s\n", dev);
-               return nil;
-       }
-       ppp->dchan = fdtochan(up->env->fgrp, fd, ORDWR, 0, 1);
-       kclose(fd);
-
-       /* set up serial line */
-/* XXX this stuff belongs in application, not driver */
-       sprint(ctl, "%sctl", dev);
-       cfd = kopen(ctl, ORDWR);
-       if (cfd >= 0) {
-               ppp->cchan = fdtochan(up->env->fgrp, cfd, ORDWR, 0, 1);
-               kclose(cfd);
-               kchanio(ppp->cchan, "m1", 2, OWRITE);   /* cts/rts flow control/fifo's) on */
-               kchanio(ppp->cchan, "q64000", 6, OWRITE);       /* increas q size to 64k */
-               kchanio(ppp->cchan, "n1", 2, OWRITE);   /* nonblocking writes on */
-               kchanio(ppp->cchan, "r1", 2, OWRITE);   /* rts on */
-               kchanio(ppp->cchan, "d1", 2, OWRITE);   /* dtr on */
-       }
-
-       ppp->pppup = 1;
-       init(ppp);
-       return ppp;
-}
-
-static void hangup(PPP * ppp)
-{
-       qlock(ppp);
-       if (waserror()) {
-               qunlock(ppp);
-               nexterror();
-       }
-       netlog(ppp->f, Logppp, "PPP Hangup\n");
-       errlog(ppp, Ehungup);
-       if (ppp->pppup && ppp->cchan != nil) {
-               kchanio(ppp->cchan, "f", 1, OWRITE);    /* flush */
-               kchanio(ppp->cchan, "h", 1, OWRITE);    /* hangup */
-       }
-       cclose(ppp->dchan);
-       cclose(ppp->cchan);
-       ppp->dchan = nil;
-       ppp->cchan = nil;
-       ppp->pppup = 0;
-       qunlock(ppp);
-       poperror();
-}
-
-/* return next input IP packet */
-Block *pppread(PPP * ppp)
-{
-       Block *b;
-       int proto;
-       Lcpmsg *m;
-
-       for (;;) {
-               proto = getframe(ppp, &b);
-               if (b == nil)
-                       return nil;
-               netlog(ppp->f, Logppp, "ppp: read proto %d len %d\n", proto,
-                          blocklen(b));
-               switch (proto) {
-                       case Plcp:
-                               rcv(ppp, ppp->lcp, b);
-                               break;
-                       case Pipcp:
-                               rcv(ppp, ppp->ipcp, b);
-                               break;
-                       case Pip:
-                               if (ppp->ipcp->state == Sopened)
-                                       return b;
-                               freeblist(b);
-                               break;
-                       case Plqm:
-                               getlqm(ppp, b);
-                               break;
-                       case Pchap:
-                               getchap(ppp, b);
-                               break;
-                       case Ppap:
-                               getpap(ppp, b);
-                               break;
-                       case Pvjctcp:
-                       case Pvjutcp:
-                               if (ppp->ipcp->state == Sopened) {
-                                       b = tcpuncompress(ppp->ctcp, b, proto, ppp->f);
-                                       if (b != nil)
-                                               return b;
-                               }
-                               freeblist(b);
-                               break;
-                       default:
-                               netlog(ppp->f, Logppp, "unknown proto 0x%x\n", proto);
-                               if (ppp->lcp->state == Sopened) {
-                                       /* reject the protocol */
-                                       b->rp -= 6;
-                                       m = (Lcpmsg *) b->rp;
-                                       m->code = Lprotorej;
-                                       m->id = ++ppp->lcp->id;
-                                       hnputs(m->data, proto);
-                                       hnputs(m->len, BLEN(b));
-                                       b = putframe(ppp, Plcp, b);
-                               }
-                               freeblist(b);
-                               break;
-               }
-       }
-       return nil;     /* compiler confused */
-}
-
-/* transmit an IP packet */
-int pppwrite(PPP * ppp, Block * b)
-{
-       ushort proto;
-       int r;
-
-       qlock(ppp);
-
-       /* can't send ip packets till we're established */
-       if (ppp->ipcp->state != Sopened)
-               goto ret;
-
-       /* link hung up */
-       if (ppp->dchan == nil)
-               goto ret;
-
-       b = concatblock(b);     /* or else compression will barf */
-
-       proto = Pip;
-       if (ppp->ipcp->flags & Fipcompress)
-               proto = compress(ppp->ctcp, b, ppp->f);
-       b = putframe(ppp, proto, b);
-
-ret:
-       qunlock(ppp);
-
-       r = blocklen(b);
-       netlog(ppp->f, Logppp, "ppp wrt len %d\n", r);
-
-       freeblist(b);
-       return r;
-}
-
-/*
- *  link quality management
- */
-static void getlqm(PPP * ppp, Block * b)
-{
-       Qualpkt *p;
-
-       p = (Qualpkt *) b->rp;
-       if (BLEN(b) == sizeof(Qualpkt)) {
-               ppp->in.reports++;
-               ppp->pout.reports = nhgetl(p->peeroutreports);
-               ppp->pout.packets = nhgetl(p->peeroutpackets);
-               ppp->pout.bytes = nhgetl(p->peeroutbytes);
-               ppp->pin.reports = nhgetl(p->peerinreports);
-               ppp->pin.packets = nhgetl(p->peerinpackets);
-               ppp->pin.discards = nhgetl(p->peerindiscards);
-               ppp->pin.errors = nhgetl(p->peerinerrors);
-               ppp->pin.bytes = nhgetl(p->peerinbytes);
-
-               /* save our numbers at time of reception */
-               memmove(&ppp->sin, &ppp->in, sizeof(Qualstats));
-
-       }
-       freeblist(b);
-       if (ppp->period == 0)
-               putlqm(ppp);
-
-}
-
-static void putlqm(PPP * ppp)
-{
-       Qualpkt *p;
-       Block *b;
-
-       b = allocb(sizeof(Qualpkt));
-       b->wp += sizeof(Qualpkt);
-       p = (Qualpkt *) b->rp;
-       hnputl(p->magic, 0);
-
-       /* heresay (what he last told us) */
-       hnputl(p->lastoutreports, ppp->pout.reports);
-       hnputl(p->lastoutpackets, ppp->pout.packets);
-       hnputl(p->lastoutbytes, ppp->pout.bytes);
-
-       /* our numbers at time of last reception */
-       hnputl(p->peerinreports, ppp->sin.reports);
-       hnputl(p->peerinpackets, ppp->sin.packets);
-       hnputl(p->peerindiscards, ppp->sin.discards);
-       hnputl(p->peerinerrors, ppp->sin.errors);
-       hnputl(p->peerinbytes, ppp->sin.bytes);
-
-       /* our numbers now */
-       hnputl(p->peeroutreports, ppp->out.reports + 1);
-       hnputl(p->peeroutpackets, ppp->out.packets + 1);
-       hnputl(p->peeroutbytes, ppp->out.bytes + 53 /*hack */ );
-
-       b = putframe(ppp, Plqm, b);
-       freeblist(b);
-       ppp->out.reports++;
-}
-
-/*
- *  challenge response dialog
- */
-static void getchap(PPP * ppp, Block * b)
-{
-       Lcpmsg *m;
-       int len, vlen, n;
-       char md5buf[512];
-
-       m = (Lcpmsg *) b->rp;
-       len = nhgets(m->len);
-       if (BLEN(b) < len) {
-               netlog(ppp->f, Logppp, "ppp %s: short chap message\n", ppp->ifc->dev);
-               freeblist(b);
-               return;
-       }
-
-       switch (m->code) {
-               case Cchallenge:
-                       vlen = m->data[0];
-                       if (vlen > len - 5) {
-                               netlog(ppp->f, Logppp, "PPP %s: bad challenge len\n",
-                                          ppp->ifc->dev);
-                               freeblist(b);
-                               break;
-                       }
-
-                       netlog(ppp->f, Logppp, "PPP %s: CHAP Challenge\n", ppp->ifc->dev);
-                       netlog(ppp->f, Logppp, "(secret %s chapname %s id %d)\n",
-                                  ppp->secret, ppp->chapname, m->id);
-                       /* create string to hash */
-                       md5buf[0] = m->id;
-                       strcpy(md5buf + 1, ppp->secret);
-                       n = strlen(ppp->secret) + 1;
-                       memmove(md5buf + n, m->data + 1, vlen);
-                       n += vlen;
-                       freeblist(b);
-
-                       /* send reply */
-                       len = 4 + 1 + 16 + strlen(ppp->chapname);
-                       b = alloclcp(2, md5buf[0], len);
-                       m = IPB2LCP(b);
-                       m->data[0] = 16;
-                       md5((uchar *) md5buf, n, m->data + 1, 0);
-                       memmove((char *)m->data + 17, ppp->chapname, strlen(ppp->chapname));
-                       hnputs(m->len, len);
-                       b->wp += len - 4;
-                       b = putframe(ppp, Pchap, b);
-                       break;
-               case Cresponse:
-                       netlog(ppp->f, Logppp, "PPP %s: chap response?\n", ppp->ifc->dev);
-                       break;
-               case Csuccess:
-                       netlog(ppp->f, Logppp, "PPP %s: chap succeeded\n", ppp->ifc->dev);
-                       setphase(ppp, Pnet);
-                       break;
-               case Cfailure:
-                       netlog(ppp->f, Logppp, "PPP %s: chap failed: %.*s\n", ppp->ifc->dev,
-                                  len - 4, m->data);
-                       errlog(ppp, Eperm);
-                       break;
-               default:
-                       netlog(ppp->f, Logppp, "PPP %s: chap code %d?\n", ppp->ifc->dev,
-                                  m->code);
-                       break;
-       }
-       freeblist(b);
-}
-
-/*
- *  password authentication protocol dialog
- *     -- obsolete but all we know how to use with NT just now
- */
-static void sendpap(PPP * ppp)
-{
-       Lcpmsg *m;
-       int clen, slen, len;
-       Block *b;
-       uchar *p;
-
-       clen = strlen(ppp->chapname);
-       slen = strlen(ppp->secret);
-       len = 4 + 1 + clen + 1 + slen;
-       ppp->papid = ++ppp->lcp->id;
-       b = alloclcp(Cpapreq, ppp->papid, len);
-       m = IPB2LCP(b);
-       p = m->data;
-       p[0] = clen;
-       memmove(p + 1, ppp->chapname, clen);
-       p += clen + 1;
-       p[0] = slen;
-       memmove(p + 1, ppp->secret, slen);
-       hnputs(m->len, len);
-       b->wp += len - 4;
-       b = putframe(ppp, Ppap, b);
-       netlog(ppp->f, Logppp, "PPP %s: sent pap auth req (%d)\n", ppp->ifc->dev,
-                  len);
-       freeblist(b);
-}
-
-static void getpap(PPP * ppp, Block * b)
-{
-       Lcpmsg *m;
-       int len;
-
-       m = (Lcpmsg *) b->rp;
-       len = nhgets(m->len);
-       if (BLEN(b) < len) {
-               netlog(ppp->f, Logppp, "ppp %s: short pap message\n", ppp->ifc->dev);
-               freeblist(b);
-               return;
-       }
-
-       switch (m->code) {
-               case Cpapreq:
-                       netlog(ppp->f, Logppp, "PPP %s: pap request?\n", ppp->ifc->dev);
-                       break;
-               case Cpapack:
-                       netlog(ppp->f, Logppp, "PPP %s: PAP succeeded\n", ppp->ifc->dev);
-                       setphase(ppp, Pnet);
-                       break;
-               case Cpapnak:
-                       if (m->data[0])
-                               netlog(ppp->f, Logppp, "PPP %s: PAP failed: %.*s\n",
-                                          ppp->ifc->dev, len - 5, m->data + 1);
-                       else
-                               netlog(ppp->f, Logppp, "PPP %s: PAP failed\n", ppp->ifc->dev);
-                       errlog(ppp, Eperm);
-                       break;
-               default:
-                       netlog(ppp->f, Logppp, "PPP %s: pap code %d?\n", ppp->ifc->dev,
-                                  m->code);
-                       break;
-       }
-       freeblist(b);
-}
-
-static void printopts(PPP * ppp, Pstate * p, Block * b, int send)
-{
-       Lcpmsg *m;
-       Lcpopt *o;
-       int proto, x, period;
-       uchar *cp;
-       char *code, *dir;
-
-       m = (Lcpmsg *) b->rp;
-       switch (m->code) {
-               default:
-                       code = "<unknown>";
-                       break;
-               case Lconfreq:
-                       code = "confrequest";
-                       break;
-               case Lconfack:
-                       code = "confack";
-                       break;
-               case Lconfnak:
-                       code = "confnak";
-                       break;
-               case Lconfrej:
-                       code = "confreject";
-                       break;
-       }
-
-       if (send)
-               dir = "send";
-       else
-               dir = "recv";
-
-       netlog(ppp->f, Logppp, "ppp: %s %s: id=%d\n", dir, code, m->id);
-
-       for (cp = m->data; cp < b->wp; cp += o->len) {
-               o = (Lcpopt *) cp;
-               if (cp + o->len > b->wp || o->len == 0) {
-                       netlog(ppp->f, Logppp, "\tbad option length 0x%x\n", o->type);
-                       return;
-               }
-
-               switch (p->proto) {
-                       case Plcp:
-                               switch (o->type) {
-                                       default:
-                                               netlog(ppp->f, Logppp, "\tunknown %d len=%d\n", o->type,
-                                                          o->len);
-                                               break;
-                                       case Omtu:
-                                               netlog(ppp->f, Logppp, "\tmtu = %d\n", nhgets(o->data));
-                                               break;
-                                       case Octlmap:
-                                               netlog(ppp->f, Logppp, "\tctlmap = 0x%x\n",
-                                                          nhgetl(o->data));
-                                               break;
-                                       case Oauth:
-                                               netlog(ppp->f, Logppp, "\tauth = ", nhgetl(o->data));
-                                               proto = nhgets(o->data);
-                                               switch (proto) {
-                                                       default:
-                                                               netlog(ppp->f, Logppp,
-                                                                          "unknown auth proto %d\n", proto);
-                                                               break;
-                                                       case Ppap:
-                                                               netlog(ppp->f, Logppp, "password\n");
-                                                               break;
-                                                       case Pchap:
-                                                               netlog(ppp->f, Logppp, "chap 0x%x\n",
-                                                                          o->data[2]);
-                                                               break;
-                                               }
-                                               break;
-                                       case Oquality:
-                                               proto = nhgets(o->data);
-                                               switch (proto) {
-                                                       default:
-                                                               netlog(ppp->f, Logppp,
-                                                                          "\tunknown quality proto %d\n", proto);
-                                                               break;
-                                                       case Plqm:
-                                                               x = nhgetl(o->data + 2) * 10;
-                                                               period = (x + Period - 1) / Period;
-                                                               netlog(ppp->f, Logppp, "\tlqm period = %d\n",
-                                                                          period);
-                                                               break;
-                                               }
-                                       case Omagic:
-                                               netlog(ppp->f, Logppp, "\tmagic = 0x%x\n",
-                                                          nhgetl(o->data));
-                                               break;
-                                       case Opc:
-                                               netlog(ppp->f, Logppp, "\tprotocol compress\n");
-                                               break;
-                                       case Oac:
-                                               netlog(ppp->f, Logppp, "\taddr compress\n");
-                                               break;
-                               }
-                               break;
-                       case Pccp:
-                               switch (o->type) {
-                                       default:
-                                               netlog(ppp->f, Logppp, "\tunknown %d len=%d\n", o->type,
-                                                          o->len);
-                                               break;
-                                       case Ocoui:
-                                               netlog(ppp->f, Logppp, "\tOUI\n");
-                                               break;
-                                       case Ocstac:
-                                               netlog(ppp->f, Logppp, "\tstac LZS\n");
-                                               break;
-                                       case Ocmppc:
-                                               netlog(ppp->f, Logppp, "\tMicrosoft PPC len=%d 0x%x\n",
-                                                          o->len, nhgetl(o->data));
-                                               break;
-                               }
-                               break;
-                       case Pecp:
-                               switch (o->type) {
-                                       default:
-                                               netlog(ppp->f, Logppp, "\tunknown %d len=%d\n", o->type,
-                                                          o->len);
-                                               break;
-                                       case Oeoui:
-                                               netlog(ppp->f, Logppp, "\tOUI\n");
-                                               break;
-                                       case Oedese:
-                                               netlog(ppp->f, Logppp, "\tDES\n");
-                                               break;
-                               }
-                               break;
-                       case Pipcp:
-                               switch (o->type) {
-                                       default:
-                                               netlog(ppp->f, Logppp, "\tunknown %d len=%d\n", o->type,
-                                                          o->len);
-                                               break;
-                                       case Oipaddrs:
-                                               netlog(ppp->f, Logppp, "\tip addrs - deprecated\n");
-                                               break;
-                                       case Oipcompress:
-                                               netlog(ppp->f, Logppp, "\tip compress\n");
-                                               break;
-                                       case Oipaddr:
-                                               netlog(ppp->f, Logppp, "\tip addr %V\n", o->data);
-                                               break;
-                                       case Oipdns:
-                                               netlog(ppp->f, Logppp, "\tdns addr %V\n", o->data);
-                                               break;
-                                       case Oipwins:
-                                               netlog(ppp->f, Logppp, "\twins addr %V\n", o->data);
-                                               break;
-                                       case Oipdns2:
-                                               netlog(ppp->f, Logppp, "\tdns2 addr %V\n", o->data);
-                                               break;
-                                       case Oipwins2:
-                                               netlog(ppp->f, Logppp, "\twins2 addr %V\n", o->data);
-                                               break;
-                               }
-                               break;
-               }
-       }
-}
-
-static void sendtermreq(PPP * ppp, Pstate * p)
-{
-       Block *b;
-       Lcpmsg *m;
-
-       p->termid = ++(p->id);
-       b = alloclcp(Ltermreq, p->termid, 4);
-       m = IPB2LCP(b);
-       hnputs(m->len, 4);
-       putframe(ppp, p->proto, b);
-       freeb(b);
-       newstate(ppp, p, Sclosing);
-}
-
-static void sendechoreq(PPP * ppp, Pstate * p)
-{
-       Block *b;
-       Lcpmsg *m;
-
-       p->termid = ++(p->id);
-       b = alloclcp(Lechoreq, p->id, 4);
-       m = IPB2LCP(b);
-       hnputs(m->len, 4);
-       putframe(ppp, p->proto, b);
-       freeb(b);
-}
-
-/*
- *  return non-zero if this is a valid v4 address
- */
-static int validv4(Ipaddr addr)
-{
-       return memcmp(addr, v4prefix, IPv4off) == 0;
-}
-
-static void invalidate(Ipaddr addr)
-{
-       ipmove(addr, IPnoaddr);
-}
diff --git a/kern/src/net/ppp.h b/kern/src/net/ppp.h
deleted file mode 100644 (file)
index 23efbf4..0000000
+++ /dev/null
@@ -1,250 +0,0 @@
-typedef struct PPP PPP;
-typedef struct Pstate Pstate;
-typedef struct Lcpmsg Lcpmsg;
-typedef struct Lcpopt Lcpopt;
-typedef struct Qualpkt Qualpkt;
-typedef struct Qualstats Qualstats;
-typedef struct Tcpc Tcpc;
-
-typedef uchar Ipaddr[IPaddrlen];
-
-enum {
-       HDLC_frame = 0x7e,
-       HDLC_esc = 0x7d,
-
-       /* PPP frame fields */
-       PPP_addr = 0xff,
-       PPP_ctl = 0x3,
-       PPP_initfcs = 0xffff,
-       PPP_goodfcs = 0xf0b8,
-
-       /* PPP phases */
-       Pdead = 0,
-       Plink,  /* doing LCP */
-       Pauth,  /* doing chap */
-       Pnet,   /* doing IPCP, CCP */
-       Pterm,  /* closing down */
-
-       /* PPP protocol types */
-       Pip = 0x21,     /* internet */
-       Pvjctcp = 0x2d, /* compressing van jacobson tcp */
-       Pvjutcp = 0x2f, /* uncompressing van jacobson tcp */
-       Pcdata = 0xfd,  /* compressed datagram */
-       Pipcp = 0x8021, /* ip control */
-       Pecp = 0x8053,  /* encryption control */
-       Pccp = 0x80fd,  /* compressed datagram control */
-       Plcp = 0xc021,  /* link control */
-       Ppap = 0xc023,  /* password auth. protocol */
-       Plqm = 0xc025,  /* link quality monitoring */
-       Pchap = 0xc223, /* challenge/response */
-
-       /* LCP codes */
-       Lconfreq = 1,
-       Lconfack = 2,
-       Lconfnak = 3,
-       Lconfrej = 4,
-       Ltermreq = 5,
-       Ltermack = 6,
-       Lcoderej = 7,
-       Lprotorej = 8,
-       Lechoreq = 9,
-       Lechoack = 10,
-       Ldiscard = 11,
-
-       /* Lcp configure options */
-       Omtu = 1,
-       Octlmap = 2,
-       Oauth = 3,
-       Oquality = 4,
-       Omagic = 5,
-       Opc = 7,
-       Oac = 8,
-       Obad = 12,      /* for testing */
-
-       /* authentication protocols */
-       APmd5 = 5,
-
-       /* lcp flags */
-       Fmtu = 1 << Omtu,
-       Fctlmap = 1 << Octlmap,
-       Fauth = 1 << Oauth,
-       Fquality = 1 << Oquality,
-       Fmagic = 1 << Omagic,
-       Fpc = 1 << Opc,
-       Fac = 1 << Oac,
-       Fbad = 1 << Obad,
-
-       /* Chap codes */
-       Cchallenge = 1,
-       Cresponse = 2,
-       Csuccess = 3,
-       Cfailure = 4,
-
-       /* Pap codes */
-       Cpapreq = 1,
-       Cpapack = 2,
-       Cpapnak = 3,
-
-       /* link states */
-       Sclosed = 0,
-       Sclosing,
-       Sreqsent,
-       Sackrcvd,
-       Sacksent,
-       Sopened,
-
-       /* ccp configure options */
-       Ocoui = 0,      /* proprietary compression */
-       Ocstac = 17,    /* stac electronics LZS */
-       Ocmppc = 18,    /* microsoft ppc */
-
-       /* ccp flags */
-       Fcoui = 1 << Ocoui,
-       Fcstac = 1 << Ocstac,
-       Fcmppc = 1 << Ocmppc,
-
-       /* ecp configure options */
-       Oeoui = 0,      /* proprietary compression */
-       Oedese = 1,     /* DES */
-
-       /* ecp flags */
-       Feoui = 1 << Oeoui,
-       Fedese = 1 << Oedese,
-
-       /* ipcp configure options */
-       Oipaddrs = 1,
-       Oipcompress = 2,
-       Oipaddr = 3,
-       Oipdns = 129,
-       Oipwins = 130,
-       Oipdns2 = 131,
-       Oipwins2 = 132,
-
-       /* ipcp flags */
-       Fipaddrs = 1 << Oipaddrs,
-       Fipcompress = 1 << Oipcompress,
-       Fipaddr = 1 << Oipaddr,
-
-       Period = 3 * 1000,      /* period of retransmit process (in ms) */
-       Timeout = 10,   /* xmit timeout (in Periods) */
-
-       MAX_STATES = 16,        /* van jacobson compression states */
-       Defmtu = 1450,  /* default that we will ask for */
-       Minmtu = 128,   /* minimum that we will accept */
-       Maxmtu = 2000,  /* maximum that we will accept */
-};
-
-struct Pstate {
-       int proto;                                      /* protocol type */
-       int timeout;                            /* for current state */
-       int rxtimeout;                          /* for current retransmit */
-       ulong flags;                            /* options received */
-       uchar id;                                       /* id of current message */
-       uchar confid;                           /* id of current config message */
-       uchar termid;                           /* id of current termination message */
-       uchar rcvdconfid;                       /* id of last conf message received */
-       uchar state;                            /* PPP link state */
-       ulong optmask;                          /* which options to request */
-       int echoack;                            /* recieved echo ack */
-       int echotimeout;                        /* echo timeout */
-};
-
-struct Qualstats {
-       ulong reports;
-       ulong packets;
-       ulong bytes;
-       ulong discards;
-       ulong errors;
-};
-
-struct PPP {
-       QLock;
-
-       Chan *dchan;                            /* serial line */
-       Chan *cchan;                            /* serial line control */
-       int framing;                            /* non-zero to use framing characters */
-       Ipaddr local;
-       int localfrozen;
-       Ipaddr remote;
-       int remotefrozen;
-
-       int pppup;
-       Fs *f;                                          /* file system we belong to */
-       Ipifc *ifc;
-       Proc *readp;                            /* reading process */
-       Proc *timep;                            /* timer process */
-       Block *inbuf;                           /* input buffer */
-       Block *outbuf;                          /* output buffer */
-       QLock outlock;                          /*  and its lock */
-
-       ulong magic;                            /* magic number to detect loop backs */
-       ulong rctlmap;                          /* map of chars to ignore in rcvr */
-       ulong xctlmap;                          /* map of chars to excape in xmit */
-       int phase;                                      /* PPP phase */
-       Pstate *lcp;                            /* lcp state */
-       Pstate *ipcp;                           /* ipcp state */
-       char secret[256];                       /* md5 key */
-       char chapname[256];                     /* chap system name */
-       Tcpc *ctcp;
-       ulong mtu;                                      /* maximum xmit size */
-       ulong mru;                                      /* maximum recv size */
-
-       int baud;
-       int usepap;                                     /* authentication is PAP in every sense, not CHAP */
-       int papid;
-       int usechap;
-
-       /* rfc */
-       int usedns;
-       Ipaddr dns1;
-       Ipaddr dns2;
-
-       /* link quality monitoring */
-       int period;                                     /* lqm period */
-       int timeout;                            /* time to next lqm packet */
-       Qualstats in;                           /* local */
-       Qualstats out;
-       Qualstats pin;                          /* peer */
-       Qualstats pout;
-       Qualstats sin;                          /* saved */
-};
-
-PPP *pppopen(PPP *, char *, Ipaddr, Ipaddr, int, int, char *, char *);
-Block *pppread(PPP *);
-int pppwrite(PPP *, Block *);
-void pppclose(PPP *);
-
-struct Lcpmsg {
-       uchar code;
-       uchar id;
-       uchar len[2];
-       uchar data[1];
-};
-
-struct Lcpopt {
-       uchar type;
-       uchar len;
-       uchar data[1];
-};
-
-struct Qualpkt {
-       uchar magic[4];
-
-       uchar lastoutreports[4];
-       uchar lastoutpackets[4];
-       uchar lastoutbytes[4];
-       uchar peerinreports[4];
-       uchar peerinpackets[4];
-       uchar peerindiscards[4];
-       uchar peerinerrors[4];
-       uchar peerinbytes[4];
-       uchar peeroutreports[4];
-       uchar peeroutpackets[4];
-       uchar peeroutbytes[4];
-};
-
-ushort compress(Tcpc *, Block *, Fs *);
-Tcpc *compress_init(Tcpc *);
-int compress_negotiate(Tcpc *, uchar *);
-ushort tcpcompress(Tcpc *, Block *, Fs *);
-Block *tcpuncompress(Tcpc *, Block *, ushort, Fs *);
diff --git a/kern/src/net/pppmedium.c b/kern/src/net/pppmedium.c
deleted file mode 100644 (file)
index 56dc2b3..0000000
+++ /dev/null
@@ -1,188 +0,0 @@
-#include "u.h"
-#include "../port/lib.h"
-#include "mem.h"
-#include "dat.h"
-#include "fns.h"
-#include "../port/error.h"
-
-#include "ip.h"
-#include "kernel.h"
-#include "ppp.h"
-
-static void pppreader(void *a);
-static void pppbind(Ipifc * ifc, int argc, char **argv);
-static void pppunbind(Ipifc * ifc);
-static void pppbwrite(Ipifc * ifc, Block * bp, int version, uchar * ip);
-static void deadremote(Ipifc * ifc);
-
-Medium pppmedium = {
-       .name = "ppp",
-       .hsize = 4,
-       .mintu = Minmtu,
-       .maxtu = Maxmtu,
-       .maclen = 0,
-       .bind = pppbind,
-       .unbind = pppunbind,
-       .bwrite = pppbwrite,
-       .unbindonclose = 0,     /* don't unbind on last close */
-};
-
-/*
- *  called to bind an IP ifc to an ethernet device
- *  called with ifc wlock'd
- */
-static void pppbind(Ipifc * ifc, int argc, char **argv)
-{
-       PPP *ppp;
-       Ipaddr ipaddr, remip;
-       int mtu, framing;
-       char *chapname, *secret;
-
-       if (argc < 3)
-               error(Ebadarg);
-
-       ipmove(ipaddr, IPnoaddr);
-       ipmove(remip, IPnoaddr);
-       mtu = Defmtu;
-       framing = 1;
-       chapname = nil;
-       secret = nil;
-
-       switch (argc) {
-               default:
-               case 9:
-                       if (argv[8][0] != '-')
-                               secret = argv[8];
-               case 8:
-                       if (argv[7][0] != '-')
-                               chapname = argv[7];
-               case 7:
-                       if (argv[6][0] != '-')
-                               framing = strtoul(argv[6], 0, 0);
-               case 6:
-                       if (argv[5][0] != '-')
-                               mtu = strtoul(argv[5], 0, 0);
-               case 5:
-                       if (argv[4][0] != '-')
-                               parseip(remip, argv[4]);
-               case 4:
-                       if (argv[3][0] != '-')
-                               parseip(ipaddr, argv[3]);
-               case 3:
-                       break;
-       }
-
-       ppp = smalloc(sizeof(*ppp));
-       ppp->ifc = ifc;
-       ppp->f = ifc->conv->p->f;
-       ifc->arg = ppp;
-       if (waserror()) {
-               pppunbind(ifc);
-               nexterror();
-       }
-       if (pppopen(ppp, argv[2], ipaddr, remip, mtu, framing, chapname, secret) ==
-               nil)
-               error("ppp open failed");
-       poperror();
-       ktask("pppreader", pppreader, ifc);
-}
-
-static void pppreader(void *a)
-{
-       Ipifc *ifc;
-       Block *bp;
-       PPP *ppp;
-
-       ifc = a;
-       ppp = ifc->arg;
-       ppp->readp = up;        /* hide identity under a rock for unbind */
-       setpri(PriHi);
-
-       if (waserror()) {
-               netlog(ppp->f, Logppp, "pppreader: %I: %s\n", ppp->local,
-                          up->env->errstr);
-               ppp->readp = 0;
-               deadremote(ifc);
-               pexit("hangup", 1);
-       }
-
-       for (;;) {
-               bp = pppread(ppp);
-               if (bp == nil)
-                       error("hungup");
-               if (!canrlock(ifc)) {
-                       freeb(bp);
-                       continue;
-               }
-               if (waserror()) {
-                       runlock(ifc);
-                       nexterror();
-               }
-               ifc->in++;
-               if (ifc->lifc == nil)
-                       freeb(bp);
-               else
-                       ipiput(ppp->f, ifc, bp);
-               runlock(ifc);
-               poperror();
-       }
-}
-
-/*
- *  called with ifc wlock'd
- */
-static void pppunbind(Ipifc * ifc)
-{
-       PPP *ppp = ifc->arg;
-
-       if (ppp == nil)
-               return;
-       if (ppp->readp)
-               postnote(ppp->readp, 1, "unbind", 0);
-       if (ppp->timep)
-               postnote(ppp->timep, 1, "unbind", 0);
-
-       /* wait for kprocs to die */
-       while (ppp->readp != 0 || ppp->timep != 0)
-               udelay_sched(300 * 1000);
-
-       pppclose(ppp);
-       qclose(ifc->conv->eq);
-       ifc->arg = nil;
-}
-
-/*
- *  called by ipoput with a single packet to write with ifc rlock'd
- */
-static void pppbwrite(Ipifc * ifc, Block * bp, int, uchar *)
-{
-       PPP *ppp = ifc->arg;
-
-       ptclcsum_finalize(bp, 0);
-       pppwrite(ppp, bp);
-       ifc->out++;
-}
-
-/*
- *     If the other end hangs up, we have to unbind the interface.  An extra
- *     unbind (in the case where we are hanging up) won't do any harm.
- */
-static void deadremote(Ipifc * ifc)
-{
-       int fd;
-       char path[128];
-       PPP *ppp;
-
-       ppp = ifc->arg;
-       snprint(path, sizeof path, "#I%d/ipifc/%d/ctl", ppp->f->dev, ifc->conv->x);
-       fd = kopen(path, ORDWR);
-       if (fd < 0)
-               return;
-       kwrite(fd, "unbind", sizeof("unbind") - 1);
-       kclose(fd);
-}
-
-void pppmediumlink(void)
-{
-       addipmedium(&pppmedium);
-}
diff --git a/kern/src/net/rudp.c b/kern/src/net/rudp.c
deleted file mode 100644 (file)
index 78288a0..0000000
+++ /dev/null
@@ -1,1051 +0,0 @@
-/*
- *  This protocol is compatible with UDP's packet format.
- *  It could be done over UDP if need be.
- */
-#include       "u.h"
-#include       "../port/lib.h"
-#include       "mem.h"
-#include       "dat.h"
-#include       "fns.h"
-#include       "../port/error.h"
-
-#include       "ip.h"
-
-#define DEBUG  0
-#define DPRINT if(DEBUG)print
-
-#define SEQDIFF(a,b) ( (a)>=(b)?\
-                       (a)-(b):\
-                       0xffffffffUL-((b)-(a)) )
-#define INSEQ(a,start,end) ( (start)<=(end)?\
-                               ((a)>(start)&&(a)<=(end)):\
-                               ((a)>(start)||(a)<=(end)) )
-#define UNACKED(r) SEQDIFF(r->sndseq, r->ackrcvd)
-#define NEXTSEQ(a) ( (a)+1 == 0 ? 1 : (a)+1 )
-
-enum {
-       UDP_HDRSIZE = 20,                       /* pseudo header + udp header */
-       UDP_PHDRSIZE = 12,      /* pseudo header */
-       UDP_RHDRSIZE = 36,      /* pseudo header + udp header + rudp header */
-       UDP_IPHDR = 8,  /* ip header */
-       IP_UDPPROTO = 254,
-       UDP_USEAD7 = 52,
-       UDP_USEAD6 = 36,
-       UDP_USEAD4 = 12,
-
-       Rudprxms = 200,
-       Rudptickms = 50,
-       Rudpmaxxmit = 10,
-       Maxunacked = 100,
-
-};
-
-#define Hangupgen      0xffffffff      /* used only in hangup messages */
-
-typedef struct Udphdr Udphdr;
-struct Udphdr {
-       /* ip header */
-       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 */
-
-       /* pseudo header starts here */
-       uchar Unused;
-       uchar udpproto;                         /* Protocol */
-       uchar udpplen[2];                       /* Header plus data length */
-       uchar udpsrc[4];                        /* Ip source */
-       uchar udpdst[4];                        /* Ip destination */
-
-       /* udp header */
-       uchar udpsport[2];                      /* Source port */
-       uchar udpdport[2];                      /* Destination port */
-       uchar udplen[2];                        /* data length */
-       uchar udpcksum[2];                      /* Checksum */
-};
-
-typedef struct Rudphdr Rudphdr;
-struct Rudphdr {
-       /* ip header */
-       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 */
-
-       /* pseudo header starts here */
-       uchar Unused;
-       uchar udpproto;                         /* Protocol */
-       uchar udpplen[2];                       /* Header plus data length */
-       uchar udpsrc[4];                        /* Ip source */
-       uchar udpdst[4];                        /* Ip destination */
-
-       /* udp header */
-       uchar udpsport[2];                      /* Source port */
-       uchar udpdport[2];                      /* Destination port */
-       uchar udplen[2];                        /* data length (includes rudp header) */
-       uchar udpcksum[2];                      /* Checksum */
-
-       /* rudp header */
-       uchar relseq[4];                        /* id of this packet (or 0) */
-       uchar relsgen[4];                       /* generation/time stamp */
-       uchar relack[4];                        /* packet being acked (or 0) */
-       uchar relagen[4];                       /* generation/time stamp */
-};
-
-/*
- *  one state structure per destination
- */
-typedef struct Reliable Reliable;
-struct Reliable {
-       Ref;
-
-       Reliable *next;
-
-       uchar addr[IPaddrlen];          /* always V6 when put here */
-       ushort port;
-
-       Block *unacked;                         /* unacked msg list */
-       Block *unackedtail;                     /*  and its tail */
-
-       int timeout;                            /* time since first unacked msg sent */
-       int xmits;                                      /* number of times first unacked msg sent */
-
-       ulong sndseq;                           /* next packet to be sent */
-       ulong sndgen;                           /*  and its generation */
-
-       ulong rcvseq;                           /* last packet received */
-       ulong rcvgen;                           /*  and its generation */
-
-       ulong acksent;                          /* last ack sent */
-       ulong ackrcvd;                          /* last msg for which ack was rcvd */
-
-       /* flow control */
-       QLock lock;
-       Rendez vous;
-       int blocked;
-};
-
-/* MIB II counters */
-typedef struct Rudpstats Rudpstats;
-struct Rudpstats {
-       ulong rudpInDatagrams;
-       ulong rudpNoPorts;
-       ulong rudpInErrors;
-       ulong rudpOutDatagrams;
-};
-
-typedef struct Rudppriv Rudppriv;
-struct Rudppriv {
-       Ipht ht;
-
-       /* MIB counters */
-       Rudpstats ustats;
-
-       /* non-MIB stats */
-       ulong csumerr;                          /* checksum errors */
-       ulong lenerr;                           /* short packet */
-       ulong rxmits;                           /* # of retransmissions */
-       ulong orders;                           /* # of out of order pkts */
-
-       /* keeping track of the ack kproc */
-       int ackprocstarted;
-       QLock apl;
-};
-
-static ulong generation = 0;
-static Rendez rend;
-
-/*
- *  protocol specific part of Conv
- */
-typedef struct Rudpcb Rudpcb;
-struct Rudpcb {
-       QLock;
-       uchar headers;
-       uchar randdrop;
-       Reliable *r;
-};
-
-/*
- * local functions 
- */
-void relsendack(Conv *, Reliable *, int);
-int reliput(Conv *, Block *, uchar *, ushort);
-Reliable *relstate(Rudpcb *, uchar *, ushort, char *);
-void relput(Reliable *);
-void relforget(Conv *, uchar *, int, int);
-void relackproc(void *);
-void relackq(Reliable *, Block *);
-void relhangup(Conv *, Reliable *);
-void relrexmit(Conv *, Reliable *);
-void relput(Reliable *);
-void rudpkick(void *x);
-
-static void rudpstartackproc(Proto * rudp)
-{
-       Rudppriv *rpriv;
-       char kpname[KNAMELEN];
-
-       rpriv = rudp->priv;
-       if (rpriv->ackprocstarted == 0) {
-               qlock(&rpriv->apl);
-               if (rpriv->ackprocstarted == 0) {
-                       sprint(kpname, "#I%drudpack", rudp->f->dev);
-                       ktask(kpname, relackproc, rudp);
-                       rpriv->ackprocstarted = 1;
-               }
-               qunlock(&rpriv->apl);
-       }
-}
-
-static char *rudpconnect(Conv * c, char **argv, int argc)
-{
-       char *e;
-       Rudppriv *upriv;
-
-       upriv = c->p->priv;
-       rudpstartackproc(c->p);
-       e = Fsstdconnect(c, argv, argc);
-       Fsconnected(c, e);
-       iphtadd(&upriv->ht, c);
-
-       return e;
-}
-
-static int rudpstate(Conv * c, char *state, int n)
-{
-       Rudpcb *ucb;
-       Reliable *r;
-       int m;
-
-       m = snprint(state, n, "%s", c->inuse ? "Open" : "Closed");
-       ucb = (Rudpcb *) c->ptcl;
-       qlock(ucb);
-       for (r = ucb->r; r; r = r->next)
-               m += snprint(state + m, n - m, " %I/%ld", r->addr, UNACKED(r));
-       qunlock(ucb);
-       return m;
-}
-
-static char *rudpannounce(Conv * c, char **argv, int argc)
-{
-       char *e;
-       Rudppriv *upriv;
-
-       upriv = c->p->priv;
-       rudpstartackproc(c->p);
-       e = Fsstdannounce(c, argv, argc);
-       if (e != nil)
-               return e;
-       Fsconnected(c, nil);
-       iphtadd(&upriv->ht, c);
-
-       return nil;
-}
-
-static void rudpcreate(Conv * c)
-{
-       c->rq = qopen(64 * 1024, Qmsg, 0, 0);
-       c->wq = qopen(64 * 1024, Qkick, rudpkick, c);
-}
-
-static void rudpclose(Conv * c)
-{
-       Rudpcb *ucb;
-       Reliable *r, *nr;
-       Rudppriv *upriv;
-
-       upriv = c->p->priv;
-       iphtrem(&upriv->ht, c);
-
-       /* force out any delayed acks */
-       ucb = (Rudpcb *) c->ptcl;
-       qlock(ucb);
-       for (r = ucb->r; r; r = r->next) {
-               if (r->acksent != r->rcvseq)
-                       relsendack(c, r, 0);
-       }
-       qunlock(ucb);
-
-       qclose(c->rq);
-       qclose(c->wq);
-       qclose(c->eq);
-       ipmove(c->laddr, IPnoaddr);
-       ipmove(c->raddr, IPnoaddr);
-       c->lport = 0;
-       c->rport = 0;
-
-       ucb->headers = 0;
-       ucb->randdrop = 0;
-       qlock(ucb);
-       for (r = ucb->r; r; r = nr) {
-               if (r->acksent != r->rcvseq)
-                       relsendack(c, r, 0);
-               nr = r->next;
-               relhangup(c, r);
-               relput(r);
-       }
-       ucb->r = 0;
-
-       qunlock(ucb);
-}
-
-/*
- *  randomly don't send packets
- */
-static void doipoput(Conv * c, Fs * f, Block * bp, int x, int ttl, int tos)
-{
-       Rudpcb *ucb;
-
-       ucb = (Rudpcb *) c->ptcl;
-       if (ucb->randdrop && nrand(100) < ucb->randdrop)
-               freeblist(bp);
-       else
-               ipoput4(f, bp, x, ttl, tos, nil);
-}
-
-int flow(void *v)
-{
-       Reliable *r = v;
-
-       return UNACKED(r) <= Maxunacked;
-}
-
-void rudpkick(void *x)
-{
-       Conv *c = x;
-       Udphdr *uh;
-       ushort rport;
-       uchar laddr[IPaddrlen], raddr[IPaddrlen];
-       Block *bp;
-       Rudpcb *ucb;
-       Rudphdr *rh;
-       Reliable *r;
-       int dlen, ptcllen;
-       Rudppriv *upriv;
-       Fs *f;
-
-       upriv = c->p->priv;
-       f = c->p->f;
-
-       netlog(c->p->f, Logrudp, "rudp: kick\n");
-       bp = qget(c->wq);
-       if (bp == nil)
-               return;
-
-       ucb = (Rudpcb *) c->ptcl;
-       switch (ucb->headers) {
-               case 7:
-                       /* get user specified addresses */
-                       bp = pullupblock(bp, UDP_USEAD7);
-                       if (bp == nil)
-                               return;
-                       ipmove(raddr, bp->rp);
-                       bp->rp += IPaddrlen;
-                       ipmove(laddr, bp->rp);
-                       bp->rp += IPaddrlen;
-                       /* pick interface closest to dest */
-                       if (ipforme(f, laddr) != Runi)
-                               findlocalip(f, laddr, raddr);
-                       bp->rp += IPaddrlen;    /* Ignore ifc address */
-                       rport = nhgets(bp->rp);
-                       bp->rp += 2 + 2;        /* Ignore local port */
-                       break;
-               case 6:
-                       /* get user specified addresses */
-                       bp = pullupblock(bp, UDP_USEAD6);
-                       if (bp == nil)
-                               return;
-                       ipmove(raddr, bp->rp);
-                       bp->rp += IPaddrlen;
-                       ipmove(laddr, bp->rp);
-                       bp->rp += IPaddrlen;
-                       /* pick interface closest to dest */
-                       if (ipforme(f, laddr) != Runi)
-                               findlocalip(f, laddr, raddr);
-                       rport = nhgets(bp->rp);
-
-                       bp->rp += 4;    /* Igonore local port */
-                       break;
-               default:
-                       ipmove(raddr, c->raddr);
-                       ipmove(laddr, c->laddr);
-                       rport = c->rport;
-
-                       break;
-       }
-
-       dlen = blocklen(bp);
-
-       /* Make space to fit rudp & ip header */
-       bp = padblock(bp, UDP_IPHDR + UDP_RHDRSIZE);
-       if (bp == nil)
-               return;
-
-       uh = (Udphdr *) (bp->rp);
-       uh->vihl = IP_VER4;
-
-       rh = (Rudphdr *) uh;
-
-       ptcllen = dlen + (UDP_RHDRSIZE - UDP_PHDRSIZE);
-       uh->Unused = 0;
-       uh->udpproto = IP_UDPPROTO;
-       uh->frag[0] = 0;
-       uh->frag[1] = 0;
-       hnputs(uh->udpplen, ptcllen);
-       switch (ucb->headers) {
-               case 6:
-               case 7:
-                       v6tov4(uh->udpdst, raddr);
-                       hnputs(uh->udpdport, rport);
-                       v6tov4(uh->udpsrc, laddr);
-                       break;
-               default:
-                       v6tov4(uh->udpdst, c->raddr);
-                       hnputs(uh->udpdport, c->rport);
-                       if (ipcmp(c->laddr, IPnoaddr) == 0)
-                               findlocalip(f, c->laddr, c->raddr);
-                       v6tov4(uh->udpsrc, c->laddr);
-                       break;
-       }
-       hnputs(uh->udpsport, c->lport);
-       hnputs(uh->udplen, ptcllen);
-       uh->udpcksum[0] = 0;
-       uh->udpcksum[1] = 0;
-
-       qlock(ucb);
-       r = relstate(ucb, raddr, rport, "kick");
-       r->sndseq = NEXTSEQ(r->sndseq);
-       hnputl(rh->relseq, r->sndseq);
-       hnputl(rh->relsgen, r->sndgen);
-
-       hnputl(rh->relack, r->rcvseq);  /* ACK last rcvd packet */
-       hnputl(rh->relagen, r->rcvgen);
-
-       if (r->rcvseq != r->acksent)
-               r->acksent = r->rcvseq;
-
-       hnputs(uh->udpcksum, ptclcsum(bp, UDP_IPHDR, dlen + UDP_RHDRSIZE));
-
-       relackq(r, bp);
-       qunlock(ucb);
-
-       upriv->ustats.rudpOutDatagrams++;
-
-       DPRINT("sent: %lu/%lu, %lu/%lu\n",
-                  r->sndseq, r->sndgen, r->rcvseq, r->rcvgen);
-
-       doipoput(c, f, bp, 0, c->ttl, c->tos);
-
-       if (waserror()) {
-               relput(r);
-               qunlock(&r->lock);
-               nexterror();
-       }
-
-       /* flow control of sorts */
-       qlock(&r->lock);
-       if (UNACKED(r) > Maxunacked) {
-               r->blocked = 1;
-               rendez_sleep(&r->vous, flow, r);
-               r->blocked = 0;
-       }
-
-       qunlock(&r->lock);
-       relput(r);
-       poperror();
-}
-
-void rudpiput(Proto * rudp, Ipifc * ifc, Block * bp)
-{
-       int len, olen, ottl;
-       Udphdr *uh;
-       Conv *c;
-       Rudpcb *ucb;
-       uchar raddr[IPaddrlen], laddr[IPaddrlen];
-       ushort rport, lport;
-       Rudppriv *upriv;
-       Fs *f;
-       uchar *p;
-
-       upriv = rudp->priv;
-       f = rudp->f;
-
-       upriv->ustats.rudpInDatagrams++;
-
-       uh = (Udphdr *) (bp->rp);
-
-       /* Put back pseudo header for checksum 
-        * (remember old values for icmpnoconv()) 
-        */
-       ottl = uh->Unused;
-       uh->Unused = 0;
-       len = nhgets(uh->udplen);
-       olen = nhgets(uh->udpplen);
-       hnputs(uh->udpplen, len);
-
-       v4tov6(raddr, uh->udpsrc);
-       v4tov6(laddr, uh->udpdst);
-       lport = nhgets(uh->udpdport);
-       rport = nhgets(uh->udpsport);
-
-       if (nhgets(uh->udpcksum)) {
-               if (ptclcsum(bp, UDP_IPHDR, len + UDP_PHDRSIZE)) {
-                       upriv->ustats.rudpInErrors++;
-                       upriv->csumerr++;
-                       netlog(f, Logrudp, "rudp: checksum error %I\n", raddr);
-                       DPRINT("rudp: checksum error %I\n", raddr);
-                       freeblist(bp);
-                       return;
-               }
-       }
-
-       qlock(rudp);
-
-       c = iphtlook(&upriv->ht, raddr, rport, laddr, lport);
-       if (c == nil) {
-               /* no converstation found */
-               upriv->ustats.rudpNoPorts++;
-               qunlock(rudp);
-               netlog(f, Logudp, "udp: no conv %I!%d -> %I!%d\n", raddr, rport,
-                          laddr, lport);
-               uh->Unused = ottl;
-               hnputs(uh->udpplen, olen);
-               icmpnoconv(f, bp);
-               freeblist(bp);
-               return;
-       }
-       ucb = (Rudpcb *) c->ptcl;
-       qlock(ucb);
-       qunlock(rudp);
-
-       if (reliput(c, bp, raddr, rport) < 0) {
-               qunlock(ucb);
-               freeb(bp);
-               return;
-       }
-
-       /*
-        * Trim the packet down to data size
-        */
-
-       len -= (UDP_RHDRSIZE - UDP_PHDRSIZE);
-       bp = trimblock(bp, UDP_IPHDR + UDP_RHDRSIZE, len);
-       if (bp == nil) {
-               netlog(f, Logrudp, "rudp: len err %I.%d -> %I.%d\n",
-                          raddr, rport, laddr, lport);
-               DPRINT("rudp: len err %I.%d -> %I.%d\n", raddr, rport, laddr, lport);
-               upriv->lenerr++;
-               return;
-       }
-
-       netlog(f, Logrudpmsg, "rudp: %I.%d -> %I.%d l %d\n",
-                  raddr, rport, laddr, lport, len);
-
-       switch (ucb->headers) {
-               case 7:
-                       /* pass the src address */
-                       bp = padblock(bp, UDP_USEAD7);
-                       p = bp->rp;
-                       ipmove(p, raddr);
-                       p += IPaddrlen;
-                       ipmove(p, laddr);
-                       p += IPaddrlen;
-                       ipmove(p, ifc->lifc->local);
-                       p += IPaddrlen;
-                       hnputs(p, rport);
-                       p += 2;
-                       hnputs(p, lport);
-                       break;
-               case 6:
-                       /* pass the src address */
-                       bp = padblock(bp, UDP_USEAD6);
-                       p = bp->rp;
-                       ipmove(p, raddr);
-                       p += IPaddrlen;
-                       ipmove(p, ipforme(f, laddr) == Runi ? laddr : ifc->lifc->local);
-                       p += IPaddrlen;
-                       hnputs(p, rport);
-                       p += 2;
-                       hnputs(p, lport);
-                       break;
-               default:
-                       /* connection oriented rudp */
-                       if (ipcmp(c->raddr, IPnoaddr) == 0) {
-                               /* save the src address in the conversation */
-                               ipmove(c->raddr, raddr);
-                               c->rport = rport;
-
-                               /* reply with the same ip address (if not broadcast) */
-                               if (ipforme(f, laddr) == Runi)
-                                       ipmove(c->laddr, laddr);
-                               else
-                                       v4tov6(c->laddr, ifc->lifc->local);
-                       }
-                       break;
-       }
-       if (bp->next)
-               bp = concatblock(bp);
-
-       if (qfull(c->rq)) {
-               netlog(f, Logrudp, "rudp: qfull %I.%d -> %I.%d\n", raddr, rport,
-                          laddr, lport);
-               freeblist(bp);
-       } else
-               qpass(c->rq, bp);
-
-       qunlock(ucb);
-}
-
-static char *rudpunknown = "unknown rudp ctl request";
-
-char *rudpctl(Conv * c, char **f, int n)
-{
-       Rudpcb *ucb;
-       uchar ip[IPaddrlen];
-       int x;
-
-       ucb = (Rudpcb *) c->ptcl;
-       if (n < 1)
-               return rudpunknown;
-
-       if (strcmp(f[0], "headers++4") == 0) {
-               ucb->headers = 7;
-               return nil;
-       } else if (strcmp(f[0], "headers") == 0) {
-               ucb->headers = 6;
-               return nil;
-       } else if (strcmp(f[0], "hangup") == 0) {
-               if (n < 3)
-                       return "bad syntax";
-               parseip(ip, f[1]);
-               x = atoi(f[2]);
-               qlock(ucb);
-               relforget(c, ip, x, 1);
-               qunlock(ucb);
-               return nil;
-       } else if (strcmp(f[0], "randdrop") == 0) {
-               x = 10; /* default is 10% */
-               if (n > 1)
-                       x = atoi(f[1]);
-               if (x > 100 || x < 0)
-                       return "illegal rudp drop rate";
-               ucb->randdrop = x;
-               return nil;
-       }
-       return rudpunknown;
-}
-
-void rudpadvise(Proto * rudp, Block * bp, char *msg)
-{
-       Udphdr *h;
-       uchar source[IPaddrlen], dest[IPaddrlen];
-       ushort psource, pdest;
-       Conv *s, **p;
-
-       h = (Udphdr *) (bp->rp);
-
-       v4tov6(dest, h->udpdst);
-       v4tov6(source, h->udpsrc);
-       psource = nhgets(h->udpsport);
-       pdest = nhgets(h->udpdport);
-
-       /* Look for a connection */
-       for (p = rudp->conv; *p; p++) {
-               s = *p;
-               if (s->rport == pdest)
-                       if (s->lport == psource)
-                               if (ipcmp(s->raddr, dest) == 0)
-                                       if (ipcmp(s->laddr, source) == 0) {
-                                               qhangup(s->rq, msg);
-                                               qhangup(s->wq, msg);
-                                               break;
-                                       }
-       }
-       freeblist(bp);
-}
-
-int rudpstats(Proto * rudp, char *buf, int len)
-{
-       Rudppriv *upriv;
-
-       upriv = rudp->priv;
-       return snprint(buf, len, "%lu %lu %lu %lu %lu %lu\n",
-                                  upriv->ustats.rudpInDatagrams,
-                                  upriv->ustats.rudpNoPorts,
-                                  upriv->ustats.rudpInErrors,
-                                  upriv->ustats.rudpOutDatagrams,
-                                  upriv->rxmits, upriv->orders);
-}
-
-void rudpinit(Fs * fs)
-{
-
-       Proto *rudp;
-
-       rudp = smalloc(sizeof(Proto));
-       rudp->priv = smalloc(sizeof(Rudppriv));
-       rudp->name = "rudp";
-       rudp->connect = rudpconnect;
-       rudp->announce = rudpannounce;
-       rudp->ctl = rudpctl;
-       rudp->state = rudpstate;
-       rudp->create = rudpcreate;
-       rudp->close = rudpclose;
-       rudp->rcv = rudpiput;
-       rudp->advise = rudpadvise;
-       rudp->stats = rudpstats;
-       rudp->ipproto = IP_UDPPROTO;
-       rudp->nc = 16;
-       rudp->ptclsize = sizeof(Rudpcb);
-
-       Fsproto(fs, rudp);
-}
-
-/*********************************************/
-/* Here starts the reliable helper functions */
-/*********************************************/
-/*
- *  Enqueue a copy of an unacked block for possible retransmissions
- */
-void relackq(Reliable * r, Block * bp)
-{
-       Block *np;
-
-       np = copyblock(bp, blocklen(bp));
-       if (r->unacked)
-               r->unackedtail->list = np;
-       else {
-               /* restart timer */
-               r->timeout = 0;
-               r->xmits = 1;
-               r->unacked = np;
-       }
-       r->unackedtail = np;
-       np->list = nil;
-}
-
-/*
- *  retransmit unacked blocks
- */
-void relackproc(void *a)
-{
-       Rudpcb *ucb;
-       Proto *rudp;
-       Reliable *r;
-       Conv **s, *c;
-
-       rudp = (Proto *) a;
-
-loop:
-       udelay_sched(Rudptickms * 1000);
-
-       for (s = rudp->conv; *s; s++) {
-               c = *s;
-               ucb = (Rudpcb *) c->ptcl;
-               qlock(ucb);
-
-               for (r = ucb->r; r; r = r->next) {
-                       if (r->unacked != nil) {
-                               r->timeout += Rudptickms;
-                               if (r->timeout > Rudprxms * r->xmits)
-                                       relrexmit(c, r);
-                       }
-                       if (r->acksent != r->rcvseq)
-                               relsendack(c, r, 0);
-               }
-               qunlock(ucb);
-       }
-       goto loop;
-}
-
-/*
- *  get the state record for a conversation
- */
-Reliable *relstate(Rudpcb * ucb, uchar * addr, ushort port, char *from)
-{
-       Reliable *r, **l;
-
-       l = &ucb->r;
-       for (r = *l; r; r = *l) {
-               if (memcmp(addr, r->addr, IPaddrlen) == 0 && port == r->port)
-                       break;
-               l = &r->next;
-       }
-
-       /* no state for this addr/port, create some */
-       if (r == nil) {
-               while (generation == 0)
-                       generation = rand();
-
-               DPRINT("from %s new state %lu for %I!%u\n",
-                          from, generation, addr, port);
-
-               r = smalloc(sizeof(Reliable));
-               memmove(r->addr, addr, IPaddrlen);
-               r->port = port;
-               r->unacked = 0;
-               if (generation == Hangupgen)
-                       generation++;
-               r->sndgen = generation++;
-               r->sndseq = 0;
-               r->ackrcvd = 0;
-               r->rcvgen = 0;
-               r->rcvseq = 0;
-               r->acksent = 0;
-               r->xmits = 0;
-               r->timeout = 0;
-               r->ref = 0;
-               incref(r);      /* one reference for being in the list */
-
-               *l = r;
-       }
-
-       incref(r);
-       return r;
-}
-
-void relput(Reliable * r)
-{
-       if (decref(r) == 0)
-               free(r);
-}
-
-/*
- *  forget a Reliable state
- */
-void relforget(Conv * c, uchar * ip, int port, int originator)
-{
-       Rudpcb *ucb;
-       Reliable *r, **l;
-
-       ucb = (Rudpcb *) c->ptcl;
-
-       l = &ucb->r;
-       for (r = *l; r; r = *l) {
-               if (ipcmp(ip, r->addr) == 0 && port == r->port) {
-                       *l = r->next;
-                       if (originator)
-                               relsendack(c, r, 1);
-                       relhangup(c, r);
-                       relput(r);      /* remove from the list */
-                       break;
-               }
-               l = &r->next;
-       }
-}
-
-/* 
- *  process a rcvd reliable packet. return -1 if not to be passed to user process,
- *  0 therwise.
- *
- *  called with ucb locked.
- */
-int reliput(Conv * c, Block * bp, uchar * addr, ushort port)
-{
-       Block *nbp;
-       Rudpcb *ucb;
-       Rudppriv *upriv;
-       Udphdr *uh;
-       Reliable *r;
-       Rudphdr *rh;
-       ulong seq, ack, sgen, agen, ackreal;
-       int rv = -1;
-
-       /* get fields */
-       uh = (Udphdr *) (bp->rp);
-       rh = (Rudphdr *) uh;
-       seq = nhgetl(rh->relseq);
-       sgen = nhgetl(rh->relsgen);
-       ack = nhgetl(rh->relack);
-       agen = nhgetl(rh->relagen);
-
-       upriv = c->p->priv;
-       ucb = (Rudpcb *) c->ptcl;
-       r = relstate(ucb, addr, port, "input");
-
-       DPRINT("rcvd %lu/%lu, %lu/%lu, r->sndgen = %lu\n",
-                  seq, sgen, ack, agen, r->sndgen);
-
-       /* if acking an incorrect generation, ignore */
-       if (ack && agen != r->sndgen)
-               goto out;
-
-       /* Look for a hangup */
-       if (sgen == Hangupgen) {
-               if (agen == r->sndgen)
-                       relforget(c, addr, port, 0);
-               goto out;
-       }
-
-       /* make sure we're not talking to a new remote side */
-       if (r->rcvgen != sgen) {
-               if (seq != 0 && seq != 1)
-                       goto out;
-
-               /* new connection */
-               if (r->rcvgen != 0) {
-                       DPRINT("new con r->rcvgen = %lu, sgen = %lu\n", r->rcvgen, sgen);
-                       relhangup(c, r);
-               }
-               r->rcvgen = sgen;
-       }
-
-       /* dequeue acked packets */
-       if (ack && agen == r->sndgen) {
-               ackreal = 0;
-               while (r->unacked != nil && INSEQ(ack, r->ackrcvd, r->sndseq)) {
-                       nbp = r->unacked;
-                       r->unacked = nbp->list;
-                       DPRINT("%lu/%lu acked, r->sndgen = %lu\n", ack, agen, r->sndgen);
-                       freeb(nbp);
-                       r->ackrcvd = NEXTSEQ(r->ackrcvd);
-                       ackreal = 1;
-               }
-
-               /* flow control */
-               if (UNACKED(r) < Maxunacked / 8 && r->blocked)
-                       rendez_wakeup(&r->vous);
-
-               /*
-                *  retransmit next packet if the acked packet
-                *  was transmitted more than once
-                */
-               if (ackreal && r->unacked != nil) {
-                       r->timeout = 0;
-                       if (r->xmits > 1) {
-                               r->xmits = 1;
-                               relrexmit(c, r);
-                       }
-               }
-
-       }
-
-       /* no message or input queue full */
-       if (seq == 0 || qfull(c->rq))
-               goto out;
-
-       /* refuse out of order delivery */
-       if (seq != NEXTSEQ(r->rcvseq)) {
-               relsendack(c, r, 0);    /* tell him we got it already */
-               upriv->orders++;
-               DPRINT("out of sequence %lu not %lu\n", seq, NEXTSEQ(r->rcvseq));
-               goto out;
-       }
-       r->rcvseq = seq;
-
-       rv = 0;
-out:
-       relput(r);
-       return rv;
-}
-
-void relsendack(Conv * c, Reliable * r, int hangup)
-{
-       Udphdr *uh;
-       Block *bp;
-       Rudphdr *rh;
-       int ptcllen;
-       Fs *f;
-
-       bp = allocb(UDP_IPHDR + UDP_RHDRSIZE);
-       if (bp == nil)
-               return;
-       bp->wp += UDP_IPHDR + UDP_RHDRSIZE;
-       f = c->p->f;
-       uh = (Udphdr *) (bp->rp);
-       uh->vihl = IP_VER4;
-       rh = (Rudphdr *) uh;
-
-       ptcllen = (UDP_RHDRSIZE - UDP_PHDRSIZE);
-       uh->Unused = 0;
-       uh->udpproto = IP_UDPPROTO;
-       uh->frag[0] = 0;
-       uh->frag[1] = 0;
-       hnputs(uh->udpplen, ptcllen);
-
-       v6tov4(uh->udpdst, r->addr);
-       hnputs(uh->udpdport, r->port);
-       hnputs(uh->udpsport, c->lport);
-       if (ipcmp(c->laddr, IPnoaddr) == 0)
-               findlocalip(f, c->laddr, c->raddr);
-       v6tov4(uh->udpsrc, c->laddr);
-       hnputs(uh->udplen, ptcllen);
-
-       if (hangup)
-               hnputl(rh->relsgen, Hangupgen);
-       else
-               hnputl(rh->relsgen, r->sndgen);
-       hnputl(rh->relseq, 0);
-       hnputl(rh->relagen, r->rcvgen);
-       hnputl(rh->relack, r->rcvseq);
-
-       if (r->acksent < r->rcvseq)
-               r->acksent = r->rcvseq;
-
-       uh->udpcksum[0] = 0;
-       uh->udpcksum[1] = 0;
-       hnputs(uh->udpcksum, ptclcsum(bp, UDP_IPHDR, UDP_RHDRSIZE));
-
-       DPRINT("sendack: %lu/%lu, %lu/%lu\n", 0L, r->sndgen, r->rcvseq, r->rcvgen);
-       doipoput(c, f, bp, 0, c->ttl, c->tos);
-}
-
-/*
- *  called with ucb locked (and c locked if user initiated close)
- */
-void relhangup(Conv * c, Reliable * r)
-{
-       int n;
-       Block *bp;
-       char hup[ERRMAX];
-
-       n = snprint(hup, sizeof(hup), "hangup %I!%d", r->addr, r->port);
-       qproduce(c->eq, hup, n);
-
-       /*
-        *  dump any unacked outgoing messages
-        */
-       for (bp = r->unacked; bp != nil; bp = r->unacked) {
-               r->unacked = bp->list;
-               bp->list = nil;
-               freeb(bp);
-       }
-
-       r->rcvgen = 0;
-       r->rcvseq = 0;
-       r->acksent = 0;
-       if (generation == Hangupgen)
-               generation++;
-       r->sndgen = generation++;
-       r->sndseq = 0;
-       r->ackrcvd = 0;
-       r->xmits = 0;
-       r->timeout = 0;
-       rendez_wakeup(&r->vous);
-}
-
-/*
- *  called with ucb locked
- */
-void relrexmit(Conv * c, Reliable * r)
-{
-       Rudppriv *upriv;
-       Block *np;
-       Fs *f;
-
-       upriv = c->p->priv;
-       f = c->p->f;
-       r->timeout = 0;
-       if (r->xmits++ > Rudpmaxxmit) {
-               relhangup(c, r);
-               return;
-       }
-
-       upriv->rxmits++;
-       np = copyblock(r->unacked, blocklen(r->unacked));
-       DPRINT("rxmit r->ackrvcd+1 = %lu\n", r->ackrcvd + 1);
-       doipoput(c, f, np, 0, c->ttl, c->tos);
-}