pktmedium.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include "u.h"
  10. #include "../port/lib.h"
  11. #include "mem.h"
  12. #include "dat.h"
  13. #include "fns.h"
  14. #include "../port/error.h"
  15. #include "ip.h"
  16. static void pktbind(Ipifc*, int, char**);
  17. static void pktunbind(Ipifc*);
  18. static void pktbwrite(Ipifc*, Block*, int, uint8_t*);
  19. static void pktin(Fs*, Ipifc*, Block*);
  20. Medium pktmedium =
  21. {
  22. .name= "pkt",
  23. .hsize= 14,
  24. .mintu= 40,
  25. .maxtu= 4*1024,
  26. .maclen= 6,
  27. .bind= pktbind,
  28. .unbind= pktunbind,
  29. .bwrite= pktbwrite,
  30. .pktin= pktin,
  31. };
  32. /*
  33. * called to bind an IP ifc to an ethernet device
  34. * called with ifc wlock'd
  35. */
  36. static void
  37. pktbind(Ipifc *ipifc, int argc, char **argv)
  38. {
  39. USED(argc); USED(argv);
  40. }
  41. /*
  42. * called with ifc wlock'd
  43. */
  44. static void
  45. pktunbind(Ipifc *ipifc)
  46. {
  47. }
  48. /*
  49. * called by ipoput with a single packet to write
  50. */
  51. static void
  52. pktbwrite(Ipifc *ifc, Block *bp, int i, uint8_t *c)
  53. {
  54. /* enqueue onto the conversation's rq */
  55. bp = concatblock(bp);
  56. if(ifc->conv->snoopers.ref > 0)
  57. qpass(ifc->conv->sq, copyblock(bp, BLEN(bp)));
  58. qpass(ifc->conv->rq, bp);
  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. void
  75. pktmediumlink(void)
  76. {
  77. addipmedium(&pktmedium);
  78. }