pktmedium.c (1298B)
1 #include "u.h" 2 #include "lib.h" 3 #include "mem.h" 4 #include "dat.h" 5 #include "fns.h" 6 #include "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 }; 28 29 /* 30 * called to bind an IP ifc to an ethernet device 31 * called with ifc wlock'd 32 */ 33 static void 34 pktbind(Ipifc* _, int argc, char **argv) 35 { 36 } 37 38 /* 39 * called with ifc wlock'd 40 */ 41 static void 42 pktunbind(Ipifc* _) 43 { 44 } 45 46 /* 47 * called by ipoput with a single packet to write 48 */ 49 static void 50 pktbwrite(Ipifc *ifc, Block *bp, int _, uchar* __) 51 { 52 /* enqueue onto the conversation's rq */ 53 bp = concatblock(bp); 54 if(ifc->conv->snoopers.ref > 0) 55 qpass(ifc->conv->sq, copyblock(bp, BLEN(bp))); 56 qpass(ifc->conv->rq, bp); 57 } 58 59 /* 60 * called with ifc rlocked when someone write's to 'data' 61 */ 62 static void 63 pktin(Fs *f, Ipifc *ifc, Block *bp) 64 { 65 if(ifc->lifc == nil) 66 freeb(bp); 67 else { 68 if(ifc->conv->snoopers.ref > 0) 69 qpass(ifc->conv->sq, copyblock(bp, BLEN(bp))); 70 ipiput4(f, ifc, bp); 71 } 72 } 73 74 void 75 pktmediumlink(void) 76 { 77 addipmedium(&pktmedium); 78 }