netif.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. uchar addr[Nmaxaddr];
  68. uchar bcast[Nmaxaddr];
  69. Netaddr *maddr; /* known multicast addresses */
  70. int nmaddr; /* number of known multicast addresses */
  71. Netaddr *mhash[Nmhash]; /* hash table of multicast addresses */
  72. int prom; /* number of promiscuous opens */
  73. int scan; /* number of base station scanners */
  74. int all; /* number of -1 multiplexors */
  75. /* statistics */
  76. int misses;
  77. int inpackets;
  78. int outpackets;
  79. int crcs; /* input crc errors */
  80. int oerrs; /* output errors */
  81. int frames; /* framing errors */
  82. int overflows; /* packet overflows */
  83. int buffs; /* buffering errors */
  84. int soverflows; /* software overflow */
  85. /* routines for touching the hardware */
  86. void *arg;
  87. void (*promiscuous)(void*, int);
  88. void (*multicast)(void*, uchar*, int);
  89. void (*scanbs)(void*, uint); /* scan for base stations */
  90. };
  91. void netifinit(Netif*, char*, int, ulong);
  92. Walkqid* netifwalk(Netif*, Chan*, Chan*, char **, int);
  93. Chan* netifopen(Netif*, Chan*, int);
  94. void netifclose(Netif*, Chan*);
  95. long netifread(Netif*, Chan*, void*, long, ulong);
  96. Block* netifbread(Netif*, Chan*, long, ulong);
  97. long netifwrite(Netif*, Chan*, void*, long);
  98. int netifwstat(Netif*, Chan*, uchar*, int);
  99. int netifstat(Netif*, Chan*, uchar*, int);
  100. int activemulti(Netif*, uchar*, int);
  101. /*
  102. * Ethernet specific
  103. */
  104. enum
  105. {
  106. Eaddrlen= 6,
  107. ETHERMINTU = 60, /* minimum transmit size */
  108. ETHERMAXTU = 1514, /* maximum transmit size */
  109. ETHERHDRSIZE = 14, /* size of an ethernet header */
  110. };
  111. struct Etherpkt
  112. {
  113. uchar d[Eaddrlen];
  114. uchar s[Eaddrlen];
  115. uchar type[2];
  116. uchar data[1500];
  117. };