1 /* if.h 4.18 83/06/12 */ 2 3 /* 4 * Structures defining a network interface, providing a packet 5 * transport mechanism (ala level 0 of the PUP protocols). 6 * 7 * Each interface accepts output datagrams of a specified maximum 8 * length, and provides higher level routines with input datagrams 9 * received from its medium. 10 * 11 * Output occurs when the routine if_output is called, with three parameters: 12 * (*ifp->if_output)(ifp, m, dst) 13 * Here m is the mbuf chain to be sent and dst is the destination address. 14 * The output routine encapsulates the supplied datagram if necessary, 15 * and then transmits it on its medium. 16 * 17 * On input, each interface unwraps the data received by it, and either 18 * places it on the input queue of a internetwork datagram routine 19 * and posts the associated software interrupt, or passes the datagram to a raw 20 * packet input routine. 21 * 22 * Routines exist for locating interfaces by their addresses 23 * or for locating a interface on a certain network, as well as more general 24 * routing and gateway routines maintaining information used to locate 25 * interfaces. These routines live in the files if.c and route.c 26 */ 27 28 /* 29 * Structure defining a queue for a network interface. 30 * 31 * (Would like to call this struct ``if'', but C isn't PL/1.) 32 * 33 * EVENTUALLY PURGE if_net AND if_host FROM STRUCTURE 34 */ 35 struct ifnet { 36 char *if_name; /* name, e.g. ``en'' or ``lo'' */ 37 short if_unit; /* sub-unit for lower level driver */ 38 short if_mtu; /* maximum transmission unit */ 39 int if_net; /* network number of interface */ 40 short if_flags; /* up/down, broadcast, etc. */ 41 short if_timer; /* time 'til if_watchdog called */ 42 int if_host[2]; /* local net host number */ 43 struct sockaddr if_addr; /* address of interface */ 44 union { 45 struct sockaddr ifu_broadaddr; 46 struct sockaddr ifu_dstaddr; 47 } if_ifu; 48 #define if_broadaddr if_ifu.ifu_broadaddr /* broadcast address */ 49 #define if_dstaddr if_ifu.ifu_dstaddr /* other end of p-to-p link */ 50 struct ifqueue { 51 struct mbuf *ifq_head; 52 struct mbuf *ifq_tail; 53 int ifq_len; 54 int ifq_maxlen; 55 int ifq_drops; 56 } if_snd; /* output queue */ 57 /* procedure handles */ 58 int (*if_init)(); /* init routine */ 59 int (*if_output)(); /* output routine */ 60 int (*if_ioctl)(); /* ioctl routine */ 61 int (*if_reset)(); /* bus reset routine */ 62 int (*if_watchdog)(); /* timer routine */ 63 /* generic interface statistics */ 64 int if_ipackets; /* packets received on interface */ 65 int if_ierrors; /* input errors on interface */ 66 int if_opackets; /* packets sent on interface */ 67 int if_oerrors; /* output errors on interface */ 68 int if_collisions; /* collisions on csma interfaces */ 69 /* end statistics */ 70 struct ifnet *if_next; 71 }; 72 73 #define IFF_UP 0x1 /* interface is up */ 74 #define IFF_BROADCAST 0x2 /* broadcast address valid */ 75 #define IFF_DEBUG 0x4 /* turn on debugging */ 76 #define IFF_ROUTE 0x8 /* routing entry installed */ 77 #define IFF_POINTOPOINT 0x10 /* interface is point-to-point link */ 78 #define IFF_NOTRAILERS 0x20 /* avoid use of trailers */ 79 80 /* 81 * Output queues (ifp->if_snd) and internetwork datagram level (pup level 1) 82 * input routines have queues of messages stored on ifqueue structures 83 * (defined above). Entries are added to and deleted from these structures 84 * by these macros, which should be called with ipl raised to splimp(). 85 */ 86 #define IF_QFULL(ifq) ((ifq)->ifq_len >= (ifq)->ifq_maxlen) 87 #define IF_DROP(ifq) ((ifq)->ifq_drops++) 88 #define IF_ENQUEUE(ifq, m) { \ 89 (m)->m_act = 0; \ 90 if ((ifq)->ifq_tail == 0) \ 91 (ifq)->ifq_head = m; \ 92 else \ 93 (ifq)->ifq_tail->m_act = m; \ 94 (ifq)->ifq_tail = m; \ 95 (ifq)->ifq_len++; \ 96 } 97 #define IF_PREPEND(ifq, m) { \ 98 (m)->m_act = (ifq)->ifq_head; \ 99 if ((ifq)->ifq_tail == 0) \ 100 (ifq)->ifq_tail = (m); \ 101 (ifq)->ifq_head = (m); \ 102 (ifq)->ifq_len++; \ 103 } 104 #define IF_DEQUEUE(ifq, m) { \ 105 (m) = (ifq)->ifq_head; \ 106 if (m) { \ 107 if (((ifq)->ifq_head = (m)->m_act) == 0) \ 108 (ifq)->ifq_tail = 0; \ 109 (m)->m_act = 0; \ 110 (ifq)->ifq_len--; \ 111 } \ 112 } 113 114 #define IFQ_MAXLEN 50 115 #define IFNET_SLOWHZ 1 /* granularity is 1 second */ 116 117 /* 118 * Interface request structure used for socket 119 * ioctl's. All interface ioctl's must have parameter 120 * definitions which begin with ifr_name. The 121 * remainder may be interface specific. 122 */ 123 struct ifreq { 124 #define IFNAMSIZ 16 125 char ifr_name[IFNAMSIZ]; /* if name, e.g. "en0" */ 126 union { 127 struct sockaddr ifru_addr; 128 struct sockaddr ifru_dstaddr; 129 short ifru_flags; 130 caddr_t ifru_data; 131 } ifr_ifru; 132 #define ifr_addr ifr_ifru.ifru_addr /* address */ 133 #define ifr_dstaddr ifr_ifru.ifru_dstaddr /* other end of p-to-p link */ 134 #define ifr_flags ifr_ifru.ifru_flags /* flags */ 135 #define ifr_data ifr_ifru.ifru_data /* for use by interface */ 136 }; 137 138 /* 139 * Structure used in SIOCGIFCONF request. 140 * Used to retrieve interface configuration 141 * for machine (useful for programs which 142 * must know all networks accessible). 143 */ 144 struct ifconf { 145 int ifc_len; /* size of associated buffer */ 146 union { 147 caddr_t ifcu_buf; 148 struct ifreq *ifcu_req; 149 } ifc_ifcu; 150 #define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */ 151 #define ifc_req ifc_ifcu.ifcu_req /* array of structures returned */ 152 }; 153 154 #ifdef KERNEL 155 #ifdef INET 156 struct ifqueue ipintrq; /* ip packet input queue */ 157 #endif 158 struct ifqueue rawintrq; /* raw packet input queue */ 159 struct ifnet *ifnet; 160 struct ifnet *if_ifwithaddr(), *if_ifwithnet(), *if_ifwithaf(); 161 struct ifnet *if_ifonnetof(); 162 struct in_addr if_makeaddr(); 163 #endif 164