if_hdr.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. * Mach Operating System
  3. * Copyright (c) 1991,1990,1989 Carnegie Mellon University
  4. * All Rights Reserved.
  5. *
  6. * Permission to use, copy, modify and distribute this software and its
  7. * documentation is hereby granted, provided that both the copyright
  8. * notice and this permission notice appear in all copies of the
  9. * software, derivative works or modified versions, and any portions
  10. * thereof, and that both notices appear in supporting documentation.
  11. *
  12. * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
  13. * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
  14. * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  15. *
  16. * Carnegie Mellon requests users of this software to return to
  17. *
  18. * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
  19. * School of Computer Science
  20. * Carnegie Mellon University
  21. * Pittsburgh PA 15213-3890
  22. *
  23. * any improvements or extensions that they make and grant Carnegie Mellon
  24. * the rights to redistribute these changes.
  25. */
  26. /*
  27. * Taken from (bsd)net/if.h. Modified for MACH kernel.
  28. */
  29. /*
  30. * Copyright (c) 1982, 1986 Regents of the University of California.
  31. * All rights reserved.
  32. *
  33. * Redistribution and use in source and binary forms, with or without
  34. * modification, are permitted provided that the following conditions
  35. * are met:
  36. * 1. Redistributions of source code must retain the above copyright
  37. * notice, this list of conditions and the following disclaimer.
  38. * 2. Redistributions in binary form must reproduce the above copyright
  39. * notice, this list of conditions and the following disclaimer in the
  40. * documentation and/or other materials provided with the distribution.
  41. * 4. The name of the Laboratory may not be used to endorse or promote
  42. * products derived from this software without specific prior written
  43. * permission.
  44. *
  45. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  46. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  47. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  48. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  49. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  50. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  51. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  52. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  53. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  54. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  55. * SUCH DAMAGE.
  56. *
  57. * @(#)if.h 7.3 (Berkeley) 6/27/88
  58. */
  59. #ifndef _IF_HDR_
  60. #define _IF_HDR_
  61. #include <kern/lock.h>
  62. #include <kern/queue.h>
  63. /*
  64. * Queue for network output and filter input.
  65. */
  66. struct ifqueue {
  67. queue_head_t ifq_head; /* queue of io_req_t */
  68. int ifq_len; /* length of queue */
  69. int ifq_maxlen; /* maximum length of queue */
  70. int ifq_drops; /* number of packets dropped
  71. because queue full */
  72. decl_simple_lock_data(,
  73. ifq_lock) /* lock for queue and counters */
  74. };
  75. /*
  76. * Header for network interface drivers.
  77. */
  78. struct ifnet {
  79. short if_unit; /* unit number */
  80. short if_flags; /* up/down, broadcast, etc. */
  81. short if_timer; /* time until if_watchdog called */
  82. short if_mtu; /* maximum transmission unit */
  83. short if_header_size; /* length of header */
  84. short if_header_format; /* format of hardware header */
  85. short if_address_size; /* length of hardware address */
  86. short if_alloc_size; /* size of read buffer to allocate */
  87. char *if_address; /* pointer to hardware address */
  88. struct ifqueue if_snd; /* output queue */
  89. queue_head_t if_rcv_port_list; /* input filter list */
  90. queue_head_t if_snd_port_list; /* output filter list */
  91. decl_simple_lock_data(,
  92. if_rcv_port_list_lock) /* lock for input filter list */
  93. decl_simple_lock_data(,
  94. if_snd_port_list_lock) /* lock for output filter list */
  95. /* statistics */
  96. int if_ipackets; /* packets received */
  97. int if_ierrors; /* input errors */
  98. int if_opackets; /* packets sent */
  99. int if_oerrors; /* output errors */
  100. int if_collisions; /* collisions on csma interfaces */
  101. int if_rcvdrops; /* packets received but dropped */
  102. };
  103. #define IFF_UP 0x0001 /* interface is up */
  104. #define IFF_BROADCAST 0x0002 /* interface can broadcast */
  105. #define IFF_DEBUG 0x0004 /* turn on debugging */
  106. #define IFF_LOOPBACK 0x0008 /* is a loopback net */
  107. #define IFF_POINTOPOINT 0x0010 /* point-to-point link */
  108. #define IFF_RUNNING 0x0040 /* resources allocated */
  109. #define IFF_NOARP 0x0080 /* no address resolution protocol */
  110. #define IFF_PROMISC 0x0100 /* receive all packets */
  111. #define IFF_ALLMULTI 0x0200 /* receive all multicast packets */
  112. #define IFF_BRIDGE 0x0100 /* support token ring routing field */
  113. #define IFF_SNAP 0x0200 /* support extended sap header */
  114. /* internal flags only: */
  115. #define IFF_CANTCHANGE (IFF_BROADCAST | IFF_POINTOPOINT | IFF_RUNNING)
  116. /*
  117. * Output queues (ifp->if_snd)
  118. * have queues of messages stored on ifqueue structures. Entries
  119. * are added to and deleted from these structures by these macros, which
  120. * should be called with ipl raised to splimp().
  121. * XXX locking XXX
  122. */
  123. #define IF_QFULL(ifq) ((ifq)->ifq_len >= (ifq)->ifq_maxlen)
  124. #define IF_DROP(ifq) ((ifq)->ifq_drops++)
  125. #define IF_ENQUEUE(ifq, ior) { \
  126. simple_lock(&(ifq)->ifq_lock); \
  127. enqueue_tail(&(ifq)->ifq_head, (queue_entry_t)ior); \
  128. (ifq)->ifq_len++; \
  129. simple_unlock(&(ifq)->ifq_lock); \
  130. }
  131. #define IF_PREPEND(ifq, ior) { \
  132. simple_lock(&(ifq)->ifq_lock); \
  133. enqueue_head(&(ifq)->ifq_head, (queue_entry_t)ior); \
  134. (ifq)->ifq_len++; \
  135. simple_unlock(&(ifq)->ifq_lock); \
  136. }
  137. #define IF_DEQUEUE(ifq, ior) { \
  138. simple_lock(&(ifq)->ifq_lock); \
  139. if (((ior) = (io_req_t)dequeue_head(&(ifq)->ifq_head)) != 0) \
  140. (ifq)->ifq_len--; \
  141. simple_unlock(&(ifq)->ifq_lock); \
  142. }
  143. #define IFQ_MAXLEN 50
  144. #define IFQ_INIT(ifq) { \
  145. queue_init(&(ifq)->ifq_head); \
  146. simple_lock_init(&(ifq)->ifq_lock); \
  147. (ifq)->ifq_len = 0; \
  148. (ifq)->ifq_maxlen = IFQ_MAXLEN; \
  149. (ifq)->ifq_drops = 0; \
  150. }
  151. #define IFNET_SLOWHZ 1 /* granularity is 1 second */
  152. #endif /* _IF_HDR_ */