commit 3bb63c4b773220f29080a98563b88a2ad9b55f93
parent 9f367c3963f9cae20bc9119b718ce595608b7bd3
Author: Jesus Galan Lopez (yiyus) <yiyu.jgl@gmail.com>
Date: Tue, 15 Jun 2010 18:33:48 +0200
reorganization
--HG--
rename : src/9vx/devtabve.c => src/9vx/devtab.c
rename : src/9vx/etherve.c => src/9vx/etherpcap.c
Diffstat:
6 files changed, 275 insertions(+), 327 deletions(-)
diff --git a/src/9vx/Makefrag b/src/9vx/Makefrag
@@ -32,6 +32,7 @@ PLAN9_OBJS = \
devmntloop.o \
devmouse.o \
devram.o \
+ devtab.o \
factotum.o \
fossil.o \
kprocdev.o \
@@ -114,9 +115,9 @@ PLAN9_IP_OBJS = \
$(addprefix 9vx/,\
devip.o \
devip-posix.o \
- devtabve.o \
+ etherpcap.o \
ethertap.o \
- etherve.o \
+ vether.o \
) \
$(addprefix 9vx/a/,\
devaoe.o \
diff --git a/src/9vx/devtab.c b/src/9vx/devtab.c
@@ -4,9 +4,8 @@
#include "dat.h"
#include "fns.h"
#include "error.h"
-#include "ip/ip.h"
-#include "sd.h"
+extern Dev aoedevtab;
extern Dev consdevtab;
extern Dev rootdevtab;
extern Dev pipedevtab;
@@ -26,15 +25,18 @@ extern Dev mntloopdevtab;
extern Dev dupdevtab;
extern Dev sddevtab;
extern Dev capdevtab;
+extern Dev etherdevtab;
Dev *devtab[] = {
&rootdevtab, /* must be first */
+ &aoedevtab,
&audiodevtab,
&capdevtab,
&consdevtab,
&drawdevtab,
&dupdevtab,
&envdevtab,
+ ðerdevtab,
&fsdevtab,
&ipdevtab,
&mntdevtab,
@@ -49,13 +51,3 @@ Dev *devtab[] = {
&tlsdevtab,
0
};
-
-void
-links(void)
-{
-}
-
-SDifc *sdifc[] =
-{
- 0,
-};
diff --git a/src/9vx/devtabve.c b/src/9vx/devtabve.c
@@ -1,118 +0,0 @@
-#include "u.h"
-#include "mem.h"
-#include "lib.h"
-#include "dat.h"
-#include "fns.h"
-#include "error.h"
-#include "ip/ip.h"
-#include "sd.h"
-
-extern Dev aoedevtab;
-extern Dev consdevtab;
-extern Dev rootdevtab;
-extern Dev pipedevtab;
-extern Dev ramdevtab;
-extern Dev ssldevtab;
-extern Dev tlsdevtab;
-extern Dev mousedevtab;
-extern Dev drawdevtab;
-extern Dev ipdevtab;
-extern Dev fsdevtab;
-extern Dev mntdevtab;
-extern Dev audiodevtab;
-extern Dev envdevtab;
-extern Dev srvdevtab;
-extern Dev procdevtab;
-extern Dev mntloopdevtab;
-extern Dev dupdevtab;
-extern Dev sddevtab;
-extern Dev capdevtab;
-extern Dev etherdevtab;
-
-extern SDifc sdloopifc;
-extern SDifc sdaoeifc;
-
-Dev *devtab[] = {
- &rootdevtab, /* must be first */
- &aoedevtab,
- &audiodevtab,
- &capdevtab,
- &consdevtab,
- &drawdevtab,
- &dupdevtab,
- &envdevtab,
- ðerdevtab,
- &fsdevtab,
- &ipdevtab,
- &mntdevtab,
- &mntloopdevtab,
- &mousedevtab,
- &pipedevtab,
- &procdevtab,
- &ramdevtab,
- &sddevtab,
- &srvdevtab,
- &ssldevtab,
- &tlsdevtab,
- 0
-};
-
-extern int nettap;
-extern void ethertaplink(void);
-extern void ethervelink(void);
-extern void ethermediumlink(void);
-extern void loopbackmediumlink(void);
-extern void netdevmediumlink(void);
-void links(void) {
- ethermediumlink();
- loopbackmediumlink();
- netdevmediumlink();
- if(nettap)
- ethertaplink();
- else
- ethervelink();
-}
-
-extern void ilinit(Fs*);
-extern void tcpinit(Fs*);
-extern void udpinit(Fs*);
-extern void ipifcinit(Fs*);
-extern void icmpinit(Fs*);
-extern void icmp6init(Fs*);
-extern void greinit(Fs*);
-extern void ipmuxinit(Fs*);
-extern void espinit(Fs*);
-void (*ipprotoinit[])(Fs*) = {
- ilinit,
- tcpinit,
- udpinit,
- ipifcinit,
- icmpinit,
- icmp6init,
- greinit,
- ipmuxinit,
- espinit,
- nil,
-};
-
-int
-eafrom(char *ma, uchar ea[6])
-{
- int i;
- char **nc = &ma;
-
- for(i = 0; i < 6; i++){
- if(!ma)
- return -1;
- ea[i] = (uchar)strtoul(ma, nc, 16);
- ma = *nc+1;
- }
- return 0;
-}
-
-SDifc *sdifc[] =
-{
- &sdloopifc,
- &sdaoeifc,
- 0,
-};
diff --git a/src/9vx/etherpcap.c b/src/9vx/etherpcap.c
@@ -0,0 +1,195 @@
+/*
+ * etherve - portable Virtual Ethernet driver for 9vx.
+ *
+ * Copyright (c) 2008 Devon H. O'Dell
+ * copyright © 2008 erik quanstrom
+ * copyright © 2010 Jesus Galan Lopez
+ *
+ * Released under 2-clause BSD license.
+ */
+
+#include "u.h"
+
+#include "a/lib.h"
+#include "a/mem.h"
+#include "a/dat.h"
+#include "a/fns.h"
+#include "a/io.h"
+#include "a/error.h"
+#include "a/netif.h"
+
+#include "a/etherif.h"
+
+#include <pcap.h>
+
+extern char *macaddr;
+extern char *netdev;
+static uvlong txerrs;
+
+extern int eafrom(char *ma, uchar ea[6]);
+
+typedef struct Ctlr Ctlr;
+struct Ctlr {
+ pcap_t *pd;
+};
+
+static uchar ea[6] = {0x00, 0x48, 0x01, 0x23, 0x45, 0x67};
+
+static void *
+veerror(char* err)
+{
+ iprint("ve: %s\n", err);
+ return nil;
+}
+
+static pcap_t *
+setup(void)
+{
+ char filter[30] = "ether dst 00:48:01:23:45:67";
+ char errbuf[PCAP_ERRBUF_SIZE];
+ pcap_t *pd;
+ struct bpf_program prog;
+ bpf_u_int32 net;
+ bpf_u_int32 mask;
+
+ if(macaddr){
+ if(strlen(macaddr)>17)
+ return veerror("wrong mac address");
+ else if(sprintf(filter, "ether dst %s", macaddr) == -1)
+ return veerror("cannot create pcap filter");
+ }
+
+ if (!netdev && (netdev = pcap_lookupdev(errbuf)) == nil)
+ return veerror("cannot find network device");
+
+// if ((pd = pcap_open_live(netdev, 1514, 1, 1, errbuf)) == nil)
+ if ((pd = pcap_open_live(netdev, 65000, 1, 1, errbuf)) == nil)
+ return nil;
+
+ if (macaddr && (eafrom(macaddr, ea) == -1))
+ return veerror("cannot read mac address");
+
+ pcap_lookupnet(netdev, &net, &mask, errbuf);
+ pcap_compile(pd, &prog, filter, 0, net);
+
+ if (pcap_setfilter(pd, &prog) == -1)
+ return nil;
+
+ pcap_freecode(&prog);
+
+ return pd;
+}
+
+static Block *
+vepkt(Ctlr *c)
+{
+ struct pcap_pkthdr hdr;
+ uchar *p;
+ Block *b;
+
+ while ((p = pcap_next(c->pd, &hdr)) == nil);
+
+ b = allocb(hdr.caplen);
+ memcpy(b->rp, p, hdr.caplen);
+ b->wp += hdr.caplen;
+ b->flag |= Btcpck|Budpck|Bpktck;
+
+/*
+ iprint("+++++++++++ packet %d (len %d):\n", ++fn, hdr.caplen);
+ int i=0; uchar* u;
+ static int fn=0;
+
+ for(u=b->rp; u<b->wp; u++){
+ if (i%16 == 0) iprint("%.4ux", i);
+ if (i%8 == 0) iprint(" ");
+ iprint("%2.2ux ", *u);
+ if (++i%16 == 0) iprint("\n");
+ }
+ iprint("\n-------------\n");
+*/
+
+ return b;
+
+}
+
+static void
+verecvkproc(void *v)
+{
+ Ether *e;
+ Block *b;
+
+ e = v;
+ while ((b = vepkt(e->ctlr)))
+ if (b != nil)
+ etheriq(e, b, 1);
+}
+
+static void
+vetransmit(Ether* e)
+{
+ const u_char *u;
+ Block *b;
+ Ctlr *c;
+
+ c = e->ctlr;
+ while ((b = qget(e->oq)) != nil) {
+ int wlen;
+
+ u = (const u_char*)b->rp;
+
+ wlen = pcap_inject(c->pd, u, BLEN(b));
+ // iprint("injected packet len %d\n", wlen);
+ if (wlen == -1)
+ txerrs++;
+
+ freeb(b);
+ }
+}
+
+static long
+veifstat(Ether *e, void *a, long n, ulong offset)
+{
+ char buf[128];
+
+ snprint(buf, sizeof buf, "txerrors: %lud\n", txerrs);
+ return readstr(offset, a, n, buf);
+}
+
+static void
+veattach(Ether* e)
+{
+ kproc("verecv", verecvkproc, e);
+}
+
+static int
+vepnp(Ether* e)
+{
+ Ctlr c;
+ static int nctlr = 0;
+
+ if (nctlr++ > 0)
+ return -1;
+
+ memset(&c, 0, sizeof(c));
+ c.pd = setup();
+ if (c.pd == nil) {
+ iprint("ve: pcap failed to initialize\n");
+ return -1;
+ }
+ e->ctlr = malloc(sizeof(c));
+ memcpy(e->ctlr, &c, sizeof(c));
+ e->tbdf = BUSUNKNOWN;
+ memcpy(e->ea, ea, sizeof(ea));
+ e->attach = veattach;
+ e->transmit = vetransmit;
+ e->ifstat = veifstat;
+ e->ni.arg = e;
+ e->ni.link = 1;
+ return 0;
+}
+
+void
+ethervelink(void)
+{
+ addethercard("ve", vepnp);
+}
diff --git a/src/9vx/etherve.c b/src/9vx/etherve.c
@@ -1,195 +0,0 @@
-/*
- * etherve - portable Virtual Ethernet driver for 9vx.
- *
- * Copyright (c) 2008 Devon H. O'Dell
- * copyright © 2008 erik quanstrom
- * copyright © 2010 Jesus Galan Lopez
- *
- * Released under 2-clause BSD license.
- */
-
-#include "u.h"
-
-#include "a/lib.h"
-#include "a/mem.h"
-#include "a/dat.h"
-#include "a/fns.h"
-#include "a/io.h"
-#include "a/error.h"
-#include "a/netif.h"
-
-#include "a/etherif.h"
-
-#include <pcap.h>
-
-extern char *macaddr;
-extern char *netdev;
-static uvlong txerrs;
-
-extern int eafrom(char *ma, uchar ea[6]);
-
-typedef struct Ctlr Ctlr;
-struct Ctlr {
- pcap_t *pd;
-};
-
-static uchar ea[6] = {0x00, 0x48, 0x01, 0x23, 0x45, 0x67};
-
-static void *
-veerror(char* err)
-{
- iprint("ve: %s\n", err);
- return nil;
-}
-
-static pcap_t *
-setup(void)
-{
- char filter[30] = "ether dst 00:48:01:23:45:67";
- char errbuf[PCAP_ERRBUF_SIZE];
- pcap_t *pd;
- struct bpf_program prog;
- bpf_u_int32 net;
- bpf_u_int32 mask;
-
- if(macaddr){
- if(strlen(macaddr)>17)
- return veerror("wrong mac address");
- else if(sprintf(filter, "ether dst %s", macaddr) == -1)
- return veerror("cannot create pcap filter");
- }
-
- if (!netdev && (netdev = pcap_lookupdev(errbuf)) == nil)
- return veerror("cannot find network device");
-
-// if ((pd = pcap_open_live(netdev, 1514, 1, 1, errbuf)) == nil)
- if ((pd = pcap_open_live(netdev, 65000, 1, 1, errbuf)) == nil)
- return nil;
-
- if (macaddr && (eafrom(macaddr, ea) == -1))
- return veerror("cannot read mac address");
-
- pcap_lookupnet(netdev, &net, &mask, errbuf);
- pcap_compile(pd, &prog, filter, 0, net);
-
- if (pcap_setfilter(pd, &prog) == -1)
- return nil;
-
- pcap_freecode(&prog);
-
- return pd;
-}
-
-static Block *
-vepkt(Ctlr *c)
-{
- struct pcap_pkthdr hdr;
- uchar *p;
- Block *b;
-
- while ((p = pcap_next(c->pd, &hdr)) == nil);
-
- b = allocb(hdr.caplen);
- memcpy(b->rp, p, hdr.caplen);
- b->wp += hdr.caplen;
- b->flag |= Btcpck|Budpck|Bpktck;
-
-/*
- iprint("+++++++++++ packet %d (len %d):\n", ++fn, hdr.caplen);
- int i=0; uchar* u;
- static int fn=0;
-
- for(u=b->rp; u<b->wp; u++){
- if (i%16 == 0) iprint("%.4ux", i);
- if (i%8 == 0) iprint(" ");
- iprint("%2.2ux ", *u);
- if (++i%16 == 0) iprint("\n");
- }
- iprint("\n-------------\n");
-*/
-
- return b;
-
-}
-
-static void
-verecvkproc(void *v)
-{
- Ether *e;
- Block *b;
-
- e = v;
- while ((b = vepkt(e->ctlr)))
- if (b != nil)
- etheriq(e, b, 1);
-}
-
-static void
-vetransmit(Ether* e)
-{
- const u_char *u;
- Block *b;
- Ctlr *c;
-
- c = e->ctlr;
- while ((b = qget(e->oq)) != nil) {
- int wlen;
-
- u = (const u_char*)b->rp;
-
- wlen = pcap_inject(c->pd, u, BLEN(b));
- // iprint("injected packet len %d\n", wlen);
- if (wlen == -1)
- txerrs++;
-
- freeb(b);
- }
-}
-
-static long
-veifstat(Ether *e, void *a, long n, ulong offset)
-{
- char buf[128];
-
- snprint(buf, sizeof buf, "txerrors: %lud\n", txerrs);
- return readstr(offset, a, n, buf);
-}
-
-static void
-veattach(Ether* e)
-{
- kproc("verecv", verecvkproc, e);
-}
-
-static int
-vepnp(Ether* e)
-{
- Ctlr c;
- static int nctlr = 0;
-
- if (nctlr++ > 0)
- return -1;
-
- memset(&c, 0, sizeof(c));
- c.pd = setup();
- if (c.pd == nil) {
- iprint("ve: pcap failed to initialize\n");
- return -1;
- }
- e->ctlr = malloc(sizeof(c));
- memcpy(e->ctlr, &c, sizeof(c));
- e->tbdf = BUSUNKNOWN;
- memcpy(e->ea, ea, sizeof(ea));
- e->attach = veattach;
- e->transmit = vetransmit;
- e->ifstat = veifstat;
- e->ni.arg = e;
- e->ni.link = 1;
- return 0;
-}
-
-void
-ethervelink(void)
-{
- addethercard("ve", vepnp);
-}
diff --git a/src/9vx/vether.c b/src/9vx/vether.c
@@ -0,0 +1,73 @@
+#include "u.h"
+#include "mem.h"
+#include "lib.h"
+#include "dat.h"
+#include "fns.h"
+#include "error.h"
+#include "ip/ip.h"
+#include "sd.h"
+
+extern int nettap;
+extern void ethertaplink(void);
+extern void ethervelink(void);
+extern void ethermediumlink(void);
+extern void loopbackmediumlink(void);
+extern void netdevmediumlink(void);
+
+extern void ilinit(Fs*);
+extern void tcpinit(Fs*);
+extern void udpinit(Fs*);
+extern void ipifcinit(Fs*);
+extern void icmpinit(Fs*);
+extern void icmp6init(Fs*);
+extern void greinit(Fs*);
+extern void ipmuxinit(Fs*);
+extern void espinit(Fs*);
+
+extern SDifc sdloopifc;
+extern SDifc sdaoeifc;
+
+void links(void) {
+ ethermediumlink();
+ loopbackmediumlink();
+ netdevmediumlink();
+ if(nettap)
+ ethertaplink();
+ else
+ ethervelink();
+}
+
+void (*ipprotoinit[])(Fs*) = {
+ ilinit,
+ tcpinit,
+ udpinit,
+ ipifcinit,
+ icmpinit,
+ icmp6init,
+ greinit,
+ ipmuxinit,
+ espinit,
+ nil,
+};
+
+int
+eafrom(char *ma, uchar ea[6])
+{
+ int i;
+ char **nc = &ma;
+
+ for(i = 0; i < 6; i++){
+ if(!ma)
+ return -1;
+ ea[i] = (uchar)strtoul(ma, nc, 16);
+ ma = *nc+1;
+ }
+ return 0;
+}
+
+SDifc *sdifc[] =
+{
+ &sdloopifc,
+ &sdaoeifc,
+ 0,
+};