1 /* if.h 4.6 81/12/03 */ 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 char *if_name; /* name, e.g. ``en'' or ``lo'' */ 36 short if_unit; /* sub-unit for lower level driver */ 37 short if_mtu; /* maximum transmission unit */ 38 short if_net; /* network number of interface */ 39 int if_host[2]; /* local net host number */ 40 struct in_addr if_addr; /* internet address of interface */ 41 struct ifqueue { 42 struct mbuf *ifq_head; 43 struct mbuf *ifq_tail; 44 } if_snd; /* output queue */ 45 /* procedure handles */ 46 int (*if_init)(); /* init routine */ 47 int (*if_output)(); /* output routine */ 48 int (*if_ubareset)(); /* uba reset routine */ 49 /* generic interface statistics */ 50 int if_ipackets; /* packets received on interface */ 51 int if_ierrors; /* input errors on interface */ 52 int if_opackets; /* packets sent on interface */ 53 int if_oerrors; /* output errors on interface */ 54 int if_collisions; /* collisions on csma interfaces */ 55 /* end statistics */ 56 struct ifnet *if_next; 57 }; 58 59 /* 60 * Output queues (ifp->if_snd) and internetwork datagram level (pup level 1) 61 * input routines have queues of messages stored on ifqueue structures 62 * (defined above). Entries are added to and deleted from these structures 63 * by these macros, which should be called with ipl raised to splimp(). 64 */ 65 #define IF_ENQUEUE(ifq, m) { \ 66 (m)->m_act = 0; \ 67 if ((ifq)->ifq_tail == 0) \ 68 (ifq)->ifq_head = m; \ 69 else \ 70 (ifq)->ifq_tail->m_act = m; \ 71 (ifq)->ifq_tail = m; \ 72 } 73 #define IF_DEQUEUE(ifq, m) { \ 74 (m) = (ifq)->ifq_head; \ 75 if (m) { \ 76 if (((ifq)->ifq_head = (m)->m_act) == 0) \ 77 (ifq)->ifq_tail = 0; \ 78 (m)->m_act = 0; \ 79 } \ 80 } 81 82 #ifdef KERNEL 83 #ifdef INET 84 struct ifqueue ipintrq; /* ip packet input queue */ 85 #endif 86 struct ifqueue rawintrq; /* raw packet input queue */ 87 struct ifnet *ifnet; 88 struct ifnet *if_ifwithaddr(), *if_ifonnetof(), *if_gatewayfor(); 89 struct in_addr if_makeaddr(); 90 #endif 91