netif.h 3.1 KB

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