iproute.c compiles
[akaros.git] / kern / src / net / iprouter.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 #include        "../ip/ip.h"
8
9 IProuter iprouter;
10
11 /*
12  *  User level routing.  Ip packets we don't know what to do with
13  *  come here.
14  */
15 void
16 useriprouter(Fs *f, Ipifc *ifc, Block *bp)
17 {
18         qlock(&f->iprouter);
19         if(f->iprouter.q != nil){
20                 bp = padblock(bp, IPaddrlen);
21                 if(bp == nil)
22                         return;
23                 ipmove(bp->rp, ifc->lifc->local);
24                 qpass(f->iprouter.q, bp);
25         }else
26                 freeb(bp);
27         qunlock(&f->iprouter);
28 }
29
30 void
31 iprouteropen(Fs *f)
32 {
33         qlock(&f->iprouter);
34         f->iprouter.opens++;
35         if(f->iprouter.q == nil)
36                 f->iprouter.q = qopen(64*1024, 0, 0, 0);
37         else if(f->iprouter.opens == 1)
38                 qreopen(f->iprouter.q);
39         qunlock(&f->iprouter);
40 }
41
42 void
43 iprouterclose(Fs *f)
44 {
45         qlock(&f->iprouter);
46         f->iprouter.opens--;
47         if(f->iprouter.opens == 0)
48                 qclose(f->iprouter.q);
49         qunlock(&f->iprouter);
50 }
51
52 long
53 iprouterread(Fs *f, void *a, int n)
54 {
55         return qread(f->iprouter.q, a, n);
56 }