netif.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 bridge; /* bridge mode */
  37. int headersonly; /* headers only - no data */
  38. uchar maddr[8]; /* bitmask of multicast addresses requested */
  39. int nmaddr; /* number of multicast addresses */
  40. Queue *in; /* input buffer */
  41. };
  42. /*
  43. * a network address
  44. */
  45. struct Netaddr
  46. {
  47. Netaddr *next; /* allocation chain */
  48. Netaddr *hnext;
  49. uchar addr[Nmaxaddr];
  50. int ref;
  51. };
  52. /*
  53. * a network interface
  54. */
  55. struct Netif
  56. {
  57. QLock;
  58. /* multiplexing */
  59. char name[KNAMELEN]; /* for top level directory */
  60. int nfile; /* max number of Netfiles */
  61. Netfile **f;
  62. /* about net */
  63. int limit; /* flow control */
  64. int alen; /* address length */
  65. uchar addr[Nmaxaddr];
  66. uchar bcast[Nmaxaddr];
  67. Netaddr *maddr; /* known multicast addresses */
  68. int nmaddr; /* number of known multicast addresses */
  69. Netaddr *mhash[Nmhash]; /* hash table of multicast addresses */
  70. int prom; /* number of promiscuous opens */
  71. int all; /* number of -1 multiplexors */
  72. /* statistics */
  73. int misses;
  74. int inpackets;
  75. int outpackets;
  76. int crcs; /* input crc errors */
  77. int oerrs; /* output errors */
  78. int frames; /* framing errors */
  79. int overflows; /* packet overflows */
  80. int buffs; /* buffering errors */
  81. int soverflows; /* software overflow */
  82. /* routines for touching the hardware */
  83. void *arg;
  84. void (*promiscuous)(void*, int);
  85. void (*multicast)(void*, uchar*, int);
  86. };
  87. void netifinit(Netif*, char*, int, ulong);
  88. Walkqid* netifwalk(Netif*, Chan*, Chan*, char **, int);
  89. Chan* netifopen(Netif*, Chan*, int);
  90. void netifclose(Netif*, Chan*);
  91. long netifread(Netif*, Chan*, void*, long, ulong);
  92. Block* netifbread(Netif*, Chan*, long, ulong);
  93. long netifwrite(Netif*, Chan*, void*, long);
  94. int netifwstat(Netif*, Chan*, uchar*, int);
  95. int netifstat(Netif*, Chan*, uchar*, int);
  96. int activemulti(Netif*, uchar*, int);
  97. /*
  98. * Ethernet specific
  99. */
  100. enum
  101. {
  102. Eaddrlen= 6,
  103. ETHERMINTU = 60, /* minimum transmit size */
  104. ETHERMAXTU = 1514, /* maximum transmit size */
  105. ETHERHDRSIZE = 14, /* size of an ethernet header */
  106. };
  107. struct Etherpkt
  108. {
  109. uchar d[Eaddrlen];
  110. uchar s[Eaddrlen];
  111. uchar type[2];
  112. uchar data[1500];
  113. };