1 /* if.h 4.8 82/03/09 */ 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 in_addr if_broadaddr; /* broadcast address of interface */ 42 struct ifqueue { 43 struct mbuf *ifq_head; 44 struct mbuf *ifq_tail; 45 } if_snd; /* output queue */ 46 /* procedure handles */ 47 int (*if_init)(); /* init routine */ 48 int (*if_output)(); /* output routine */ 49 int (*if_ubareset)(); /* uba reset routine */ 50 /* generic interface statistics */ 51 int if_ipackets; /* packets received on interface */ 52 int if_ierrors; /* input errors on interface */ 53 int if_opackets; /* packets sent on interface */ 54 int if_oerrors; /* output errors on interface */ 55 int if_collisions; /* collisions on csma interfaces */ 56 /* end statistics */ 57 struct ifnet *if_next; 58 }; 59 60 /* 61 * Output queues (ifp->if_snd) and internetwork datagram level (pup level 1) 62 * input routines have queues of messages stored on ifqueue structures 63 * (defined above). Entries are added to and deleted from these structures 64 * by these macros, which should be called with ipl raised to splimp(). 65 */ 66 #define IF_ENQUEUE(ifq, m) { \ 67 (m)->m_act = 0; \ 68 if ((ifq)->ifq_tail == 0) \ 69 (ifq)->ifq_head = m; \ 70 else \ 71 (ifq)->ifq_tail->m_act = m; \ 72 (ifq)->ifq_tail = m; \ 73 } 74 #define IF_PREPEND(ifq, m) { \ 75 (m)->m_act = (ifq)->ifq_head; \ 76 if ((ifq)->ifq_tail == 0) \ 77 (ifq)->ifq_tail = (m); \ 78 (ifq)->ifq_head = (m); \ 79 } 80 #define IF_DEQUEUE(ifq, m) { \ 81 (m) = (ifq)->ifq_head; \ 82 if (m) { \ 83 if (((ifq)->ifq_head = (m)->m_act) == 0) \ 84 (ifq)->ifq_tail = 0; \ 85 (m)->m_act = 0; \ 86 } \ 87 } 88 89 #ifdef KERNEL 90 #ifdef INET 91 struct ifqueue ipintrq; /* ip packet input queue */ 92 #endif 93 struct ifqueue rawintrq; /* raw packet input queue */ 94 struct ifnet *ifnet; 95 struct ifnet *if_ifwithaddr(), *if_ifonnetof(), *if_gatewayfor(); 96 struct in_addr if_makeaddr(); 97 #endif 98