summaryrefslogtreecommitdiff
path: root/sys/src/9/ip/pktmedium.c
diff options
context:
space:
mode:
authorTaru Karttunen <taruti@taruti.net>2011-03-30 15:46:40 +0300
committerTaru Karttunen <taruti@taruti.net>2011-03-30 15:46:40 +0300
commite5888a1ffdae813d7575f5fb02275c6bb07e5199 (patch)
treed8d51eac403f07814b9e936eed0c9a79195e2450 /sys/src/9/ip/pktmedium.c
Import sources from 2011-03-30 iso image
Diffstat (limited to 'sys/src/9/ip/pktmedium.c')
-rwxr-xr-xsys/src/9/ip/pktmedium.c79
1 files changed, 79 insertions, 0 deletions
diff --git a/sys/src/9/ip/pktmedium.c b/sys/src/9/ip/pktmedium.c
new file mode 100755
index 000000000..81feb3dfb
--- /dev/null
+++ b/sys/src/9/ip/pktmedium.c
@@ -0,0 +1,79 @@
+#include "u.h"
+#include "../port/lib.h"
+#include "mem.h"
+#include "dat.h"
+#include "fns.h"
+#include "../port/error.h"
+
+#include "ip.h"
+
+
+static void pktbind(Ipifc*, int, char**);
+static void pktunbind(Ipifc*);
+static void pktbwrite(Ipifc*, Block*, int, uchar*);
+static void pktin(Fs*, Ipifc*, Block*);
+
+Medium pktmedium =
+{
+.name= "pkt",
+.hsize= 14,
+.mintu= 40,
+.maxtu= 4*1024,
+.maclen= 6,
+.bind= pktbind,
+.unbind= pktunbind,
+.bwrite= pktbwrite,
+.pktin= pktin,
+};
+
+/*
+ * called to bind an IP ifc to an ethernet device
+ * called with ifc wlock'd
+ */
+static void
+pktbind(Ipifc*, int argc, char **argv)
+{
+ USED(argc, argv);
+}
+
+/*
+ * called with ifc wlock'd
+ */
+static void
+pktunbind(Ipifc*)
+{
+}
+
+/*
+ * called by ipoput with a single packet to write
+ */
+static void
+pktbwrite(Ipifc *ifc, Block *bp, int, uchar*)
+{
+ /* enqueue onto the conversation's rq */
+ bp = concatblock(bp);
+ if(ifc->conv->snoopers.ref > 0)
+ qpass(ifc->conv->sq, copyblock(bp, BLEN(bp)));
+ qpass(ifc->conv->rq, bp);
+}
+
+/*
+ * called with ifc rlocked when someone write's to 'data'
+ */
+static void
+pktin(Fs *f, Ipifc *ifc, Block *bp)
+{
+ if(ifc->lifc == nil)
+ freeb(bp);
+ else {
+ if(ifc->conv->snoopers.ref > 0)
+ qpass(ifc->conv->sq, copyblock(bp, BLEN(bp)));
+ ipiput4(f, ifc, bp);
+ }
+}
+
+void
+pktmediumlink(void)
+{
+ addipmedium(&pktmedium);
+}