Fix a bunch of %lud and %lux
[akaros.git] / kern / src / net / pktmedium.c
1 // INFERNO
2 #include <vfs.h>
3 #include <kfs.h>
4 #include <slab.h>
5 #include <kmalloc.h>
6 #include <kref.h>
7 #include <string.h>
8 #include <stdio.h>
9 #include <assert.h>
10 #include <error.h>
11 #include <cpio.h>
12 #include <pmap.h>
13 #include <smp.h>
14 #include <ip.h>
15
16 static void     pktbind(struct Ipifc*i, int unused_int, char **unused_char_pp_t);
17 static void     pktunbind(struct Ipifc* i);
18 static void     pktbwrite(struct Ipifc*i, struct block*, int unused_int, uint8_t *unused_uint8_p_t);
19 static void     pktin(struct Fs*f, struct Ipifc*i, struct block*b);
20
21 struct medium pktmedium =
22 {
23 .name=          "pkt",
24 .hsize=         14,
25 .mintu=         40,
26 .maxtu=         4*1024,
27 .maclen=        6,
28 .bind=          pktbind,
29 .unbind=        pktunbind,
30 .bwrite=        pktbwrite,
31 .pktin=         pktin,
32 .unbindonclose= 1,
33 };
34
35 /*
36  *  called to bind an IP ifc to an ethernet device
37  *  called with ifc wlock'd
38  */
39 static void
40 pktbind(struct Ipifc*i, int unused_int, char **unused_char_pp_t)
41 {
42 }
43
44 /*
45  *  called with ifc wlock'd
46  */
47 static void
48 pktunbind(struct Ipifc*i)
49 {
50 }
51
52 /*
53  *  called by ipoput with a single packet to write
54  */
55 static void
56 pktbwrite(struct Ipifc *ifc, struct block *bp, int unused_int, uint8_t *unused_uint8_p_t)
57 {
58         /* enqueue onto the conversation's rq */
59         bp = concatblock(bp);
60         if (atomic_read(&ifc->conv->snoopers) > 0)
61                 qpass(ifc->conv->sq, copyblock(bp, BLEN(bp)));
62         qpass(ifc->conv->rq, bp);
63 }
64
65 /*
66  *  called with ifc rlocked when someone write's to 'data'
67  */
68 static void
69 pktin(struct Fs *f, struct Ipifc *ifc, struct block *bp)
70 {
71         if(ifc->lifc == NULL)
72                 freeb(bp);
73         else {
74                 if (atomic_read(&ifc->conv->snoopers) > 0)
75                         qpass(ifc->conv->sq, copyblock(bp, BLEN(bp)));
76                 ipiput4(f, ifc, bp);
77         }
78 }
79
80 void
81 pktmediumlink(void)
82 {
83         addipmedium(&pktmedium);
84 }