1*5613Swnj /* if.h 4.7 82/01/24 */ 24945Swnj 34945Swnj /* 45104Swnj * Structures defining a network interface, providing a packet 55104Swnj * transport mechanism (ala level 0 of the PUP protocols). 65104Swnj * 75104Swnj * Each interface accepts output datagrams of a specified maximum 85104Swnj * length, and provides higher level routines with input datagrams 95104Swnj * received from its medium. 105104Swnj * 115104Swnj * Output occurs when the routine if_output is called, with three parameters: 125104Swnj * (*ifp->if_output)(ifp, m, pf) 135104Swnj * Here m is the mbuf chain to be sent and pf is the protocol family 145104Swnj * of the internetwork datagram format in which the data is wrapped 155104Swnj * (e.g. PF_PUP or PF_INET). The output routine encapsulates the 165104Swnj * supplied datagram if necessary, and then transmits it on its medium. 175104Swnj * 185104Swnj * On input, each interface unwraps the data received by it, and either 195104Swnj * places it on the input queue of a internetwork datagram routine 205104Swnj * and posts the associated software interrupt, or passes the datagram to a raw 215104Swnj * packet input routine. 225104Swnj * 235104Swnj * Routines exist for locating interfaces by their internet addresses 245104Swnj * or for locating a interface on a certain network, as well as more general 255104Swnj * routing and gateway routines maintaining information used to locate 265104Swnj * interfaces. These routines live in the files if.c and ip_ggp.c. 275083Swnj */ 285083Swnj 295083Swnj /* 305083Swnj * Structure defining a queue for a network interface. 314945Swnj * 324945Swnj * (Would like to call this struct ``if'', but C isn't PL/1.) 334945Swnj */ 344945Swnj struct ifnet { 355171Swnj char *if_name; /* name, e.g. ``en'' or ``lo'' */ 364945Swnj short if_unit; /* sub-unit for lower level driver */ 374945Swnj short if_mtu; /* maximum transmission unit */ 384945Swnj short if_net; /* network number of interface */ 395083Swnj int if_host[2]; /* local net host number */ 404945Swnj struct in_addr if_addr; /* internet address of interface */ 415104Swnj struct ifqueue { 425104Swnj struct mbuf *ifq_head; 435104Swnj struct mbuf *ifq_tail; 445104Swnj } if_snd; /* output queue */ 455104Swnj /* procedure handles */ 465104Swnj int (*if_init)(); /* init routine */ 475083Swnj int (*if_output)(); /* output routine */ 485083Swnj int (*if_ubareset)(); /* uba reset routine */ 495104Swnj /* generic interface statistics */ 505171Swnj int if_ipackets; /* packets received on interface */ 515171Swnj int if_ierrors; /* input errors on interface */ 525171Swnj int if_opackets; /* packets sent on interface */ 535171Swnj int if_oerrors; /* output errors on interface */ 545104Swnj int if_collisions; /* collisions on csma interfaces */ 555104Swnj /* end statistics */ 564951Swnj struct ifnet *if_next; 574945Swnj }; 584945Swnj 595104Swnj /* 605104Swnj * Output queues (ifp->if_snd) and internetwork datagram level (pup level 1) 615104Swnj * input routines have queues of messages stored on ifqueue structures 625104Swnj * (defined above). Entries are added to and deleted from these structures 635104Swnj * by these macros, which should be called with ipl raised to splimp(). 645104Swnj */ 655083Swnj #define IF_ENQUEUE(ifq, m) { \ 665083Swnj (m)->m_act = 0; \ 675083Swnj if ((ifq)->ifq_tail == 0) \ 685160Swnj (ifq)->ifq_head = m; \ 695083Swnj else \ 705083Swnj (ifq)->ifq_tail->m_act = m; \ 715160Swnj (ifq)->ifq_tail = m; \ 725083Swnj } 73*5613Swnj #define IF_PREPEND(ifq, m) { \ 74*5613Swnj (m)->m_act = (ifq)->ifq_head; \ 75*5613Swnj (ifq)->ifq_head = (m); \ 76*5613Swnj } 775083Swnj #define IF_DEQUEUE(ifq, m) { \ 785083Swnj (m) = (ifq)->ifq_head; \ 795083Swnj if (m) { \ 805083Swnj if (((ifq)->ifq_head = (m)->m_act) == 0) \ 815083Swnj (ifq)->ifq_tail = 0; \ 825083Swnj (m)->m_act = 0; \ 835083Swnj } \ 845083Swnj } 854945Swnj 864945Swnj #ifdef KERNEL 875083Swnj #ifdef INET 885083Swnj struct ifqueue ipintrq; /* ip packet input queue */ 895083Swnj #endif 905104Swnj struct ifqueue rawintrq; /* raw packet input queue */ 914945Swnj struct ifnet *ifnet; 925083Swnj struct ifnet *if_ifwithaddr(), *if_ifonnetof(), *if_gatewayfor(); 935104Swnj struct in_addr if_makeaddr(); 944945Swnj #endif 95