netif.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. typedef struct Etherpkt Etherpkt;
  2. typedef struct Netaddr Netaddr;
  3. typedef struct Netfile Netfile;
  4. typedef struct Netif Netif;
  5. enum
  6. {
  7. Nmaxaddr= 64,
  8. Nmhash= 31,
  9. Ncloneqid= 1,
  10. Naddrqid,
  11. N2ndqid,
  12. N3rdqid,
  13. Ndataqid,
  14. Nctlqid,
  15. Nstatqid,
  16. Ntypeqid,
  17. Nifstatqid,
  18. };
  19. /*
  20. * Macros to manage Qid's used for multiplexed devices
  21. */
  22. #define NETTYPE(x) (((ulong)x)&0x1f)
  23. #define NETID(x) ((((ulong)x))>>5)
  24. #define NETQID(i,t) ((((ulong)i)<<5)|(t))
  25. /*
  26. * one per multiplexed connection
  27. */
  28. struct Netfile
  29. {
  30. QLock;
  31. int inuse;
  32. ulong mode;
  33. char owner[KNAMELEN];
  34. int type; /* multiplexor type */
  35. int prom; /* promiscuous mode */
  36. int scan; /* base station scanning interval */
  37. int bridge; /* bridge mode */
  38. int headersonly; /* headers only - no data */
  39. uchar maddr[8]; /* bitmask of multicast addresses requested */
  40. int nmaddr; /* number of multicast addresses */
  41. Queue *in; /* input buffer */
  42. };
  43. /*
  44. * a network address
  45. */
  46. struct Netaddr
  47. {
  48. Netaddr *next; /* allocation chain */
  49. Netaddr *hnext;
  50. uchar addr[Nmaxaddr];
  51. int ref;
  52. };
  53. /*
  54. * a network interface
  55. */
  56. struct Netif
  57. {
  58. QLock;
  59. /* multiplexing */
  60. char name[KNAMELEN]; /* for top level directory */
  61. int nfile; /* max number of Netfiles */
  62. Netfile **f;
  63. /* about net */
  64. int limit; /* flow control */
  65. int alen; /* address length */
  66. int mbps; /* megabits per sec */
  67. int link; /* link status */
  68. uchar addr[Nmaxaddr];
  69. uchar bcast[Nmaxaddr];
  70. Netaddr *maddr; /* known multicast addresses */
  71. int nmaddr; /* number of known multicast addresses */
  72. Netaddr *mhash[Nmhash]; /* hash table of multicast addresses */
  73. int prom; /* number of promiscuous opens */
  74. int scan; /* number of base station scanners */
  75. int all; /* number of -1 multiplexors */
  76. /* statistics */
  77. int misses;
  78. uvlong inpackets;
  79. uvlong outpackets;
  80. int crcs; /* input crc errors */
  81. int oerrs; /* output errors */
  82. int frames; /* framing errors */
  83. int overflows; /* packet overflows */
  84. int buffs; /* buffering errors */
  85. int soverflows; /* software overflow */
  86. /* routines for touching the hardware */
  87. void *arg;
  88. void (*promiscuous)(void*, int);
  89. void (*multicast)(void*, uchar*, int);
  90. void (*scanbs)(void*, uint); /* scan for base stations */
  91. };
  92. void netifinit(Netif*, char*, int, ulong);
  93. Walkqid* netifwalk(Netif*, Chan*, Chan*, char **, int);
  94. Chan* netifopen(Netif*, Chan*, int);
  95. void netifclose(Netif*, Chan*);
  96. long netifread(Netif*, Chan*, void*, long, ulong);
  97. Block* netifbread(Netif*, Chan*, long, ulong);
  98. long netifwrite(Netif*, Chan*, void*, long);
  99. int netifwstat(Netif*, Chan*, uchar*, int);
  100. int netifstat(Netif*, Chan*, uchar*, int);
  101. int activemulti(Netif*, uchar*, int);
  102. /*
  103. * Ethernet specific
  104. */
  105. enum
  106. {
  107. Eaddrlen= 6,
  108. ETHERMINTU = 60, /* minimum transmit size */
  109. ETHERMAXTU = 1514, /* maximum transmit size */
  110. ETHERHDRSIZE = 14, /* size of an ethernet header */
  111. /* ethernet packet types */
  112. ETARP = 0x0806,
  113. ETIP4 = 0x0800,
  114. ETIP6 = 0x86DD,
  115. };
  116. struct Etherpkt
  117. {
  118. uchar d[Eaddrlen];
  119. uchar s[Eaddrlen];
  120. uchar type[2];
  121. uchar data[1500];
  122. };