6bba1a4c61e7ff3a5a4a92645cbba1b1b42c6551
[akaros.git] / kern / src / net / pktmedium.c
1 #include "u.h"
2 #include "../port/lib.h"
3 #include "mem.h"
4 #include "dat.h"
5 #include "fns.h"
6 #include "../port/error.h"
7
8 #include "ip.h"
9
10
11 static void     pktbind(Ipifc*, int, char**);
12 static void     pktunbind(Ipifc*);
13 static void     pktbwrite(Ipifc*, Block*, int, uchar*);
14 static void     pktin(Fs*, Ipifc*, Block*);
15
16 Medium pktmedium =
17 {
18 .name=          "pkt",
19 .hsize=         14,
20 .mintu=         40,
21 .maxtu=         4*1024,
22 .maclen=        6,
23 .bind=          pktbind,
24 .unbind=        pktunbind,
25 .bwrite=        pktbwrite,
26 .pktin=         pktin,
27 .unbindonclose= 1,
28 };
29
30 /*
31  *  called to bind an IP ifc to an ethernet device
32  *  called with ifc wlock'd
33  */
34 static void
35 pktbind(Ipifc*, int, char**)
36 {
37 }
38
39 /*
40  *  called with ifc wlock'd
41  */
42 static void
43 pktunbind(Ipifc*)
44 {
45 }
46
47 /*
48  *  called by ipoput with a single packet to write
49  */
50 static void
51 pktbwrite(Ipifc *ifc, Block *bp, int, uchar*)
52 {
53         /* enqueue onto the conversation's rq */
54         bp = concatblock(bp);
55         if(ifc->conv->snoopers.ref > 0)
56                 qpass(ifc->conv->sq, copyblock(bp, BLEN(bp)));
57         qpass(ifc->conv->rq, bp);
58 }
59
60 /*
61  *  called with ifc rlocked when someone write's to 'data'
62  */
63 static void
64 pktin(Fs *f, Ipifc *ifc, Block *bp)
65 {
66         if(ifc->lifc == nil)
67                 freeb(bp);
68         else {
69                 if(ifc->conv->snoopers.ref > 0)
70                         qpass(ifc->conv->sq, copyblock(bp, BLEN(bp)));
71                 ipiput4(f, ifc, bp);
72         }
73 }
74
75 void
76 pktmediumlink(void)
77 {
78         addipmedium(&pktmedium);
79 }