netif.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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 Etherpkt Etherpkt;
  10. typedef struct Netaddr Netaddr;
  11. typedef struct Netfile Netfile;
  12. typedef struct Netif Netif;
  13. enum {
  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) (((u32)x) & 0x1f)
  31. #define NETID(x) ((((u32)x)) >> 5)
  32. #define NETQID(i, t) ((((u32)i) << 5) | (t))
  33. /*
  34. * one per multiplexed connection
  35. */
  36. struct Netfile {
  37. QLock q;
  38. int inuse;
  39. u32 mode;
  40. char owner[KNAMELEN];
  41. int type; /* multiplexor type */
  42. int prom; /* promiscuous mode */
  43. int scan; /* base station scanning interval */
  44. int bridge; /* bridge mode */
  45. int headersonly; /* headers only - no data */
  46. u8 maddr[8]; /* bitmask of multicast addresses requested */
  47. int nmaddr; /* number of multicast addresses */
  48. Queue *iq; /* input */
  49. };
  50. /*
  51. * a network address
  52. */
  53. struct Netaddr {
  54. Netaddr *next; /* allocation chain */
  55. Netaddr *hnext;
  56. u8 addr[Nmaxaddr];
  57. int ref;
  58. };
  59. /*
  60. * a network interface
  61. */
  62. struct Netif {
  63. QLock q;
  64. /* multiplexing */
  65. char name[KNAMELEN]; /* for top level directory */
  66. int nfile; /* max number of Netfiles */
  67. Netfile **f;
  68. /* about net */
  69. int limit; /* flow control */
  70. int alen; /* address length */
  71. int mbps; /* megabits per sec */
  72. int link; /* link status */
  73. int minmtu;
  74. int maxmtu;
  75. int mtu;
  76. u8 addr[Nmaxaddr];
  77. u8 bcast[Nmaxaddr];
  78. Netaddr *maddr; /* known multicast addresses */
  79. int nmaddr; /* number of known multicast addresses */
  80. Netaddr *mhash[Nmhash]; /* hash table of multicast addresses */
  81. int prom; /* number of promiscuous opens */
  82. int _scan; /* number of base station scanners */
  83. int all; /* number of -1 multiplexors */
  84. /* statistics */
  85. u64 misses;
  86. u64 inpackets;
  87. u64 outpackets;
  88. u64 crcs; /* input crc errors */
  89. u64 oerrs; /* output errors */
  90. u64 frames; /* framing errors */
  91. u64 overflows; /* packet overflows */
  92. u64 buffs; /* buffering errors */
  93. u64 soverflows; /* software overflow */
  94. /* routines for touching the hardware */
  95. void *arg;
  96. void (*promiscuous)(void *, int);
  97. void (*multicast)(void *, u8 *, int);
  98. int (*hwmtu)(void *, int); /* get/set mtu */
  99. void (*scanbs)(void *, u32); /* scan for base stations */
  100. };
  101. void netifinit(Netif *, char *, int, u32);
  102. Walkqid *netifwalk(Netif *, Chan *, Chan *, char **, int);
  103. Chan *netifopen(Netif *, Chan *, int);
  104. void netifclose(Netif *, Chan *);
  105. i32 netifread(Netif *, Chan *, void *, i32, i64);
  106. Block *netifbread(Netif *, Chan *, i32, i64);
  107. i32 netifwrite(Netif *, Chan *, void *, i32);
  108. i32 netifwstat(Netif *, Chan *, unsigned char *, i32);
  109. i32 netifstat(Netif *, Chan *, unsigned char *, i32);
  110. int activemulti(Netif *, unsigned char *, int);
  111. /*
  112. * Ethernet specific
  113. */
  114. enum {
  115. Eaddrlen = 6,
  116. ETHERMINTU = 60, /* minimum transmit size */
  117. ETHERMAXTU = 1514, /* maximum transmit size */
  118. ETHERHDRSIZE = 14, /* size of an ethernet header */
  119. /* ethernet packet types */
  120. ETARP = 0x0806,
  121. ETIP4 = 0x0800,
  122. ETIP6 = 0x86DD,
  123. };
  124. struct Etherpkt {
  125. u8 d[Eaddrlen];
  126. u8 s[Eaddrlen];
  127. u8 type[2];
  128. u8 data[1500];
  129. };