1 /* if.h 4.5 81/12/02 */ 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, pf) 13 * Here m is the mbuf chain to be sent and pf is the protocol family 14 * of the internetwork datagram format in which the data is wrapped 15 * (e.g. PF_PUP or PF_INET). The output routine encapsulates the 16 * supplied datagram if necessary, and then transmits it on its medium. 17 * 18 * On input, each interface unwraps the data received by it, and either 19 * places it on the input queue of a internetwork datagram routine 20 * and posts the associated software interrupt, or passes the datagram to a raw 21 * packet input routine. 22 * 23 * Routines exist for locating interfaces by their internet addresses 24 * or for locating a interface on a certain network, as well as more general 25 * routing and gateway routines maintaining information used to locate 26 * interfaces. These routines live in the files if.c and ip_ggp.c. 27 */ 28 29 /* 30 * Structure defining a queue for a network interface. 31 * 32 * (Would like to call this struct ``if'', but C isn't PL/1.) 33 */ 34 struct ifnet { 35 short if_unit; /* sub-unit for lower level driver */ 36 short if_mtu; /* maximum transmission unit */ 37 short if_net; /* network number of interface */ 38 int if_host[2]; /* local net host number */ 39 struct in_addr if_addr; /* internet address of interface */ 40 struct ifqueue { 41 struct mbuf *ifq_head; 42 struct mbuf *ifq_tail; 43 } if_snd; /* output queue */ 44 /* procedure handles */ 45 int (*if_init)(); /* init routine */ 46 int (*if_output)(); /* output routine */ 47 int (*if_ubareset)(); /* uba reset routine */ 48 /* generic interface statistics */ 49 int if_collisions; /* collisions on csma interfaces */ 50 int if_ierrors; /* input errors */ 51 int if_oerrors; /* output errors */ 52 /* end statistics */ 53 struct ifnet *if_next; 54 }; 55 56 /* 57 * Output queues (ifp->if_snd) and internetwork datagram level (pup level 1) 58 * input routines have queues of messages stored on ifqueue structures 59 * (defined above). Entries are added to and deleted from these structures 60 * by these macros, which should be called with ipl raised to splimp(). 61 */ 62 #define IF_ENQUEUE(ifq, m) { \ 63 (m)->m_act = 0; \ 64 if ((ifq)->ifq_tail == 0) \ 65 (ifq)->ifq_head = m; \ 66 else \ 67 (ifq)->ifq_tail->m_act = m; \ 68 (ifq)->ifq_tail = m; \ 69 } 70 #define IF_DEQUEUE(ifq, m) { \ 71 (m) = (ifq)->ifq_head; \ 72 if (m) { \ 73 if (((ifq)->ifq_head = (m)->m_act) == 0) \ 74 (ifq)->ifq_tail = 0; \ 75 (m)->m_act = 0; \ 76 } \ 77 } 78 79 #ifdef KERNEL 80 #ifdef INET 81 struct ifqueue ipintrq; /* ip packet input queue */ 82 #endif 83 struct ifqueue rawintrq; /* raw packet input queue */ 84 struct ifnet *ifnet; 85 struct ifnet *if_ifwithaddr(), *if_ifonnetof(), *if_gatewayfor(); 86 struct in_addr if_makeaddr(); 87 #endif 88