ifq.h revision 45720
121259Swollman/* 221259Swollman * Copyright (c) 1982, 1986, 1989, 1993 321259Swollman * The Regents of the University of California. All rights reserved. 421259Swollman * 521259Swollman * Redistribution and use in source and binary forms, with or without 621259Swollman * modification, are permitted provided that the following conditions 721259Swollman * are met: 821259Swollman * 1. Redistributions of source code must retain the above copyright 921259Swollman * notice, this list of conditions and the following disclaimer. 1021259Swollman * 2. Redistributions in binary form must reproduce the above copyright 1121259Swollman * notice, this list of conditions and the following disclaimer in the 1221259Swollman * documentation and/or other materials provided with the distribution. 1321259Swollman * 3. All advertising materials mentioning features or use of this software 1421259Swollman * must display the following acknowledgement: 1521259Swollman * This product includes software developed by the University of 1621259Swollman * California, Berkeley and its contributors. 1721259Swollman * 4. Neither the name of the University nor the names of its contributors 1821259Swollman * may be used to endorse or promote products derived from this software 1921259Swollman * without specific prior written permission. 2021259Swollman * 2121259Swollman * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2221259Swollman * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2321259Swollman * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2421259Swollman * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2521259Swollman * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2621259Swollman * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2721259Swollman * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2821259Swollman * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2921259Swollman * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3021259Swollman * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3121259Swollman * SUCH DAMAGE. 3221259Swollman * 3321259Swollman * From: @(#)if.h 8.1 (Berkeley) 6/10/93 3445720Speter * $Id: if_var.h,v 1.10 1998/12/16 18:30:43 phk Exp $ 3521259Swollman */ 3621259Swollman 3721259Swollman#ifndef _NET_IF_VAR_H_ 3821259Swollman#define _NET_IF_VAR_H_ 3921259Swollman 4021259Swollman/* 4121259Swollman * Structures defining a network interface, providing a packet 4221259Swollman * transport mechanism (ala level 0 of the PUP protocols). 4321259Swollman * 4421259Swollman * Each interface accepts output datagrams of a specified maximum 4521259Swollman * length, and provides higher level routines with input datagrams 4621259Swollman * received from its medium. 4721259Swollman * 4821259Swollman * Output occurs when the routine if_output is called, with three parameters: 4921259Swollman * (*ifp->if_output)(ifp, m, dst, rt) 5021259Swollman * Here m is the mbuf chain to be sent and dst is the destination address. 5121259Swollman * The output routine encapsulates the supplied datagram if necessary, 5221259Swollman * and then transmits it on its medium. 5321259Swollman * 5421259Swollman * On input, each interface unwraps the data received by it, and either 5521259Swollman * places it on the input queue of a internetwork datagram routine 5621259Swollman * and posts the associated software interrupt, or passes the datagram to a raw 5721259Swollman * packet input routine. 5821259Swollman * 5921259Swollman * Routines exist for locating interfaces by their addresses 6021259Swollman * or for locating a interface on a certain network, as well as more general 6121259Swollman * routing and gateway routines maintaining information used to locate 6221259Swollman * interfaces. These routines live in the files if.c and route.c 6321259Swollman */ 6421259Swollman 6521259Swollman#ifdef __STDC__ 6621259Swollman/* 6721259Swollman * Forward structure declarations for function prototypes [sic]. 6821259Swollman */ 6921259Swollmanstruct mbuf; 7021259Swollmanstruct proc; 7121259Swollmanstruct rtentry; 7221259Swollmanstruct socket; 7321259Swollmanstruct ether_header; 7421259Swollman#endif 7521259Swollman 7621259Swollman#include <sys/queue.h> /* get TAILQ macros */ 7721259Swollman 7821259SwollmanTAILQ_HEAD(ifnethead, ifnet); /* we use TAILQs so that the order of */ 7921259SwollmanTAILQ_HEAD(ifaddrhead, ifaddr); /* instantiation is preserved in the list */ 8021404SwollmanLIST_HEAD(ifmultihead, ifmultiaddr); 8121259Swollman 8221259Swollman/* 8321259Swollman * Structure defining a queue for a network interface. 8421259Swollman */ 8521259Swollmanstruct ifqueue { 8621259Swollman struct mbuf *ifq_head; 8721259Swollman struct mbuf *ifq_tail; 8821259Swollman int ifq_len; 8921259Swollman int ifq_maxlen; 9021259Swollman int ifq_drops; 9121259Swollman}; 9221259Swollman 9321259Swollman/* 9421259Swollman * Structure defining a network interface. 9521259Swollman * 9621259Swollman * (Would like to call this struct ``if'', but C isn't PL/1.) 9721259Swollman */ 9821259Swollmanstruct ifnet { 9921259Swollman void *if_softc; /* pointer to driver state */ 10021259Swollman char *if_name; /* name, e.g. ``en'' or ``lo'' */ 10121259Swollman TAILQ_ENTRY(ifnet) if_link; /* all struct ifnets are chained */ 10221259Swollman struct ifaddrhead if_addrhead; /* linked list of addresses per if */ 10321259Swollman int if_pcount; /* number of promiscuous listeners */ 10421259Swollman struct bpf_if *if_bpf; /* packet filter structure */ 10521259Swollman u_short if_index; /* numeric abbreviation for this if */ 10621259Swollman short if_unit; /* sub-unit for lower level driver */ 10721259Swollman short if_timer; /* time 'til if_watchdog called */ 10821259Swollman short if_flags; /* up/down, broadcast, etc. */ 10921259Swollman int if_ipending; /* interrupts pending */ 11021259Swollman void *if_linkmib; /* link-type-specific MIB data */ 11121259Swollman size_t if_linkmiblen; /* length of above data */ 11221259Swollman struct if_data if_data; 11321404Swollman struct ifmultihead if_multiaddrs; /* multicast addresses configured */ 11421404Swollman int if_amcount; /* number of all-multicast requests */ 11521259Swollman/* procedure handles */ 11621259Swollman int (*if_output) /* output routine (enqueue) */ 11721259Swollman __P((struct ifnet *, struct mbuf *, struct sockaddr *, 11821259Swollman struct rtentry *)); 11921259Swollman void (*if_start) /* initiate output routine */ 12021259Swollman __P((struct ifnet *)); 12121259Swollman int (*if_done) /* output complete routine */ 12221259Swollman __P((struct ifnet *)); /* (XXX not used; fake prototype) */ 12321259Swollman int (*if_ioctl) /* ioctl routine */ 12436735Sdfr __P((struct ifnet *, u_long, caddr_t)); 12521259Swollman void (*if_watchdog) /* timer routine */ 12621259Swollman __P((struct ifnet *)); 12721259Swollman int (*if_poll_recv) /* polled receive routine */ 12821259Swollman __P((struct ifnet *, int *)); 12921259Swollman int (*if_poll_xmit) /* polled transmit routine */ 13021259Swollman __P((struct ifnet *, int *)); 13121259Swollman void (*if_poll_intren) /* polled interrupt reenable routine */ 13221259Swollman __P((struct ifnet *)); 13321259Swollman void (*if_poll_slowinput) /* input routine for slow devices */ 13421259Swollman __P((struct ifnet *, struct mbuf *)); 13521259Swollman void (*if_init) /* Init routine */ 13621259Swollman __P((void *)); 13721404Swollman int (*if_resolvemulti) /* validate/resolve multicast */ 13821404Swollman __P((struct ifnet *, struct sockaddr **, struct sockaddr *)); 13921259Swollman struct ifqueue if_snd; /* output queue */ 14021259Swollman struct ifqueue *if_poll_slowq; /* input queue for slow devices */ 14121259Swollman}; 14221259Swollmantypedef void if_init_f_t __P((void *)); 14321259Swollman 14421259Swollman#define if_mtu if_data.ifi_mtu 14521259Swollman#define if_type if_data.ifi_type 14621259Swollman#define if_physical if_data.ifi_physical 14721259Swollman#define if_addrlen if_data.ifi_addrlen 14821259Swollman#define if_hdrlen if_data.ifi_hdrlen 14921259Swollman#define if_metric if_data.ifi_metric 15021259Swollman#define if_baudrate if_data.ifi_baudrate 15121259Swollman#define if_ipackets if_data.ifi_ipackets 15221259Swollman#define if_ierrors if_data.ifi_ierrors 15321259Swollman#define if_opackets if_data.ifi_opackets 15421259Swollman#define if_oerrors if_data.ifi_oerrors 15521259Swollman#define if_collisions if_data.ifi_collisions 15621259Swollman#define if_ibytes if_data.ifi_ibytes 15721259Swollman#define if_obytes if_data.ifi_obytes 15821259Swollman#define if_imcasts if_data.ifi_imcasts 15921259Swollman#define if_omcasts if_data.ifi_omcasts 16021259Swollman#define if_iqdrops if_data.ifi_iqdrops 16121259Swollman#define if_noproto if_data.ifi_noproto 16221259Swollman#define if_lastchange if_data.ifi_lastchange 16321259Swollman#define if_recvquota if_data.ifi_recvquota 16421259Swollman#define if_xmitquota if_data.ifi_xmitquota 16521259Swollman#define if_rawoutput(if, m, sa) if_output(if, m, sa, (struct rtentry *)0) 16621259Swollman 16721259Swollman/* 16821259Swollman * Bit values in if_ipending 16921259Swollman */ 17021259Swollman#define IFI_RECV 1 /* I want to receive */ 17121259Swollman#define IFI_XMIT 2 /* I want to transmit */ 17221259Swollman 17321259Swollman/* 17421259Swollman * Output queues (ifp->if_snd) and slow device input queues (*ifp->if_slowq) 17521259Swollman * are queues of messages stored on ifqueue structures 17621259Swollman * (defined above). Entries are added to and deleted from these structures 17721259Swollman * by these macros, which should be called with ipl raised to splimp(). 17821259Swollman */ 17921259Swollman#define IF_QFULL(ifq) ((ifq)->ifq_len >= (ifq)->ifq_maxlen) 18021259Swollman#define IF_DROP(ifq) ((ifq)->ifq_drops++) 18121259Swollman#define IF_ENQUEUE(ifq, m) { \ 18221259Swollman (m)->m_nextpkt = 0; \ 18321259Swollman if ((ifq)->ifq_tail == 0) \ 18421259Swollman (ifq)->ifq_head = m; \ 18521259Swollman else \ 18621259Swollman (ifq)->ifq_tail->m_nextpkt = m; \ 18721259Swollman (ifq)->ifq_tail = m; \ 18821259Swollman (ifq)->ifq_len++; \ 18921259Swollman} 19021259Swollman#define IF_PREPEND(ifq, m) { \ 19121259Swollman (m)->m_nextpkt = (ifq)->ifq_head; \ 19221259Swollman if ((ifq)->ifq_tail == 0) \ 19321259Swollman (ifq)->ifq_tail = (m); \ 19421259Swollman (ifq)->ifq_head = (m); \ 19521259Swollman (ifq)->ifq_len++; \ 19621259Swollman} 19721259Swollman#define IF_DEQUEUE(ifq, m) { \ 19821259Swollman (m) = (ifq)->ifq_head; \ 19921259Swollman if (m) { \ 20021259Swollman if (((ifq)->ifq_head = (m)->m_nextpkt) == 0) \ 20121259Swollman (ifq)->ifq_tail = 0; \ 20221259Swollman (m)->m_nextpkt = 0; \ 20321259Swollman (ifq)->ifq_len--; \ 20421259Swollman } \ 20521259Swollman} 20621259Swollman 20721259Swollman#ifdef KERNEL 20821259Swollman#define IF_ENQ_DROP(ifq, m) if_enq_drop(ifq, m) 20921259Swollman 21021259Swollman#if defined(__GNUC__) && defined(MT_HEADER) 21135210Sbdestatic __inline int 21221259Swollmanif_queue_drop(struct ifqueue *ifq, struct mbuf *m) 21321259Swollman{ 21421259Swollman IF_DROP(ifq); 21521259Swollman return 0; 21621259Swollman} 21721259Swollman 21835210Sbdestatic __inline int 21921259Swollmanif_enq_drop(struct ifqueue *ifq, struct mbuf *m) 22021259Swollman{ 22121259Swollman if (IF_QFULL(ifq) && 22221259Swollman !if_queue_drop(ifq, m)) 22321259Swollman return 0; 22421259Swollman IF_ENQUEUE(ifq, m); 22521259Swollman return 1; 22621259Swollman} 22721259Swollman#else 22821259Swollman 22921259Swollman#ifdef MT_HEADER 23021259Swollmanint if_enq_drop __P((struct ifqueue *, struct mbuf *)); 23121259Swollman#endif 23221259Swollman 23321259Swollman#endif 23421259Swollman#endif /* KERNEL */ 23521259Swollman 23621259Swollman/* 23721259Swollman * The ifaddr structure contains information about one address 23821259Swollman * of an interface. They are maintained by the different address families, 23921259Swollman * are allocated and attached when an address is set, and are linked 24021259Swollman * together so all addresses for an interface can be located. 24121259Swollman */ 24221259Swollmanstruct ifaddr { 24321259Swollman struct sockaddr *ifa_addr; /* address of interface */ 24421259Swollman struct sockaddr *ifa_dstaddr; /* other end of p-to-p link */ 24521259Swollman#define ifa_broadaddr ifa_dstaddr /* broadcast address interface */ 24621259Swollman struct sockaddr *ifa_netmask; /* used to determine subnet */ 24721259Swollman struct ifnet *ifa_ifp; /* back-pointer to interface */ 24821259Swollman TAILQ_ENTRY(ifaddr) ifa_link; /* queue macro glue */ 24921259Swollman void (*ifa_rtrequest) /* check or clean routes (+ or -)'d */ 25021259Swollman __P((int, struct rtentry *, struct sockaddr *)); 25121259Swollman u_short ifa_flags; /* mostly rt_flags for cloning */ 25221259Swollman short ifa_refcnt; /* references to this structure */ 25321259Swollman int ifa_metric; /* cost of going out this interface */ 25421259Swollman#ifdef notdef 25521259Swollman struct rtentry *ifa_rt; /* XXXX for ROUTETOIF ????? */ 25621259Swollman#endif 25728845Sjulian int (*ifa_claim_addr) /* check if an addr goes to this if */ 25828845Sjulian __P((struct ifaddr *, struct sockaddr *)); 25928845Sjulian 26021259Swollman}; 26121259Swollman#define IFA_ROUTE RTF_UP /* route installed */ 26221259Swollman 26321404Swollman/* 26421404Swollman * Multicast address structure. This is analogous to the ifaddr 26521404Swollman * structure except that it keeps track of multicast addresses. 26621404Swollman * Also, the reference count here is a count of requests for this 26721404Swollman * address, not a count of pointers to this structure. 26821404Swollman */ 26921404Swollmanstruct ifmultiaddr { 27021434Swollman LIST_ENTRY(ifmultiaddr) ifma_link; /* queue macro glue */ 27121434Swollman struct sockaddr *ifma_addr; /* address this membership is for */ 27221434Swollman struct sockaddr *ifma_lladdr; /* link-layer translation, if any */ 27321434Swollman struct ifnet *ifma_ifp; /* back-pointer to interface */ 27421434Swollman u_int ifma_refcount; /* reference count */ 27521434Swollman void *ifma_protospec; /* protocol-specific state, if any */ 27621404Swollman}; 27721404Swollman 27821259Swollman#ifdef KERNEL 27921259Swollman#define IFAFREE(ifa) \ 28021259Swollman if ((ifa)->ifa_refcnt <= 0) \ 28121259Swollman ifafree(ifa); \ 28221259Swollman else \ 28321259Swollman (ifa)->ifa_refcnt--; 28421259Swollman 28521259Swollmanextern struct ifnethead ifnet; 28621259Swollmanextern int ifqmaxlen; 28721259Swollmanextern struct ifnet loif[]; 28821259Swollmanextern int if_index; 28921259Swollmanextern struct ifaddr **ifnet_addrs; 29021259Swollman 29121259Swollmanvoid ether_ifattach __P((struct ifnet *)); 29221259Swollmanvoid ether_input __P((struct ifnet *, struct ether_header *, struct mbuf *)); 29321259Swollmanint ether_output __P((struct ifnet *, 29421259Swollman struct mbuf *, struct sockaddr *, struct rtentry *)); 29521259Swollmanint ether_ioctl __P((struct ifnet *, int, caddr_t)); 29621259Swollman 29721434Swollmanint if_addmulti __P((struct ifnet *, struct sockaddr *, 29821434Swollman struct ifmultiaddr **)); 29921404Swollmanint if_allmulti __P((struct ifnet *, int)); 30021259Swollmanvoid if_attach __P((struct ifnet *)); 30121404Swollmanint if_delmulti __P((struct ifnet *, struct sockaddr *)); 30245720Spetervoid if_detach __P((struct ifnet *)); 30321259Swollmanvoid if_down __P((struct ifnet *)); 30441879Sphkvoid if_route __P((struct ifnet *, int flag, int fam)); 30541879Sphkvoid if_unroute __P((struct ifnet *, int flag, int fam)); 30621259Swollmanvoid if_up __P((struct ifnet *)); 30721259Swollman/*void ifinit __P((void));*/ /* declared in systm.h for main() */ 30836735Sdfrint ifioctl __P((struct socket *, u_long, caddr_t, struct proc *)); 30921259Swollmanint ifpromisc __P((struct ifnet *, int)); 31021259Swollmanstruct ifnet *ifunit __P((char *)); 31121259Swollman 31221259Swollmanint if_poll_recv_slow __P((struct ifnet *ifp, int *quotap)); 31321259Swollmanvoid if_poll_xmit_slow __P((struct ifnet *ifp, int *quotap)); 31421259Swollmanvoid if_poll_throttle __P((void)); 31521259Swollmanvoid if_poll_unthrottle __P((void *)); 31621259Swollmanvoid if_poll_init __P((void)); 31721259Swollmanvoid if_poll __P((void)); 31821259Swollman 31921259Swollmanstruct ifaddr *ifa_ifwithaddr __P((struct sockaddr *)); 32021259Swollmanstruct ifaddr *ifa_ifwithdstaddr __P((struct sockaddr *)); 32121259Swollmanstruct ifaddr *ifa_ifwithnet __P((struct sockaddr *)); 32221259Swollmanstruct ifaddr *ifa_ifwithroute __P((int, struct sockaddr *, 32321259Swollman struct sockaddr *)); 32421259Swollmanstruct ifaddr *ifaof_ifpforaddr __P((struct sockaddr *, struct ifnet *)); 32521259Swollmanvoid ifafree __P((struct ifaddr *)); 32621259Swollman 32721434Swollmanstruct ifmultiaddr *ifmaof_ifpforaddr __P((struct sockaddr *, 32821434Swollman struct ifnet *)); 32936908Sjulianint if_simloop __P((struct ifnet *ifp, struct mbuf *m, 33036908Sjulian struct sockaddr *dst, int hlen)); 33121434Swollman 33221259Swollman#endif /* KERNEL */ 33321259Swollman 33421259Swollman 33521259Swollman#endif /* !_NET_IF_VAR_H_ */ 336