if_var.h revision 121470
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 3450477Speter * $FreeBSD: head/sys/net/if_var.h 121470 2003-10-24 16:57:59Z ume $ 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 55108533Sschweikh * places it on the input queue of an 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 60108533Sschweikh * or for locating an 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; 7083366Sjulianstruct thread; 7121259Swollmanstruct rtentry; 7285074Srustruct rt_addrinfo; 7321259Swollmanstruct socket; 7421259Swollmanstruct ether_header; 7521259Swollman#endif 7621259Swollman 77101849Srwatson#include <sys/_label.h> /* struct label */ 7821259Swollman#include <sys/queue.h> /* get TAILQ macros */ 7921259Swollman 8069224Sjlemon#ifdef _KERNEL 8169152Sjlemon#include <sys/mbuf.h> 8269224Sjlemon#endif /* _KERNEL */ 8374914Sjhb#include <sys/lock.h> /* XXX */ 8474914Sjhb#include <sys/mutex.h> /* XXX */ 8583130Sjlemon#include <sys/event.h> /* XXX */ 8669152Sjlemon 8760938SjakeTAILQ_HEAD(ifnethead, ifnet); /* we use TAILQs so that the order of */ 8860938SjakeTAILQ_HEAD(ifaddrhead, ifaddr); /* instantiation is preserved in the list */ 8960938SjakeTAILQ_HEAD(ifprefixhead, ifprefix); 9072084SphkTAILQ_HEAD(ifmultihead, ifmultiaddr); 9121259Swollman 9221259Swollman/* 9321259Swollman * Structure defining a queue for a network interface. 9421259Swollman */ 9521259Swollmanstruct ifqueue { 9621259Swollman struct mbuf *ifq_head; 9721259Swollman struct mbuf *ifq_tail; 9821259Swollman int ifq_len; 9921259Swollman int ifq_maxlen; 10021259Swollman int ifq_drops; 10169152Sjlemon struct mtx ifq_mtx; 10221259Swollman}; 10321259Swollman 10421259Swollman/* 10521259Swollman * Structure defining a network interface. 10621259Swollman * 10721259Swollman * (Would like to call this struct ``if'', but C isn't PL/1.) 10821259Swollman */ 10984380Smjacob 11084380Smjacob/* 11184380Smjacob * NB: For FreeBSD, it is assumed that each NIC driver's softc starts with 11284380Smjacob * one of these structures, typically held within an arpcom structure. 11386797Sluigi * 11486797Sluigi * struct <foo>_softc { 11586797Sluigi * struct arpcom { 11686797Sluigi * struct ifnet ac_if; 11786797Sluigi * ... 11886797Sluigi * } <arpcom> ; 11986797Sluigi * ... 12086797Sluigi * }; 12186797Sluigi * 12286797Sluigi * The assumption is used in a number of places, including many 12386797Sluigi * files in sys/net, device drivers, and sys/dev/mii.c:miibus_attach(). 12486797Sluigi * 12586797Sluigi * Unfortunately devices' softc are opaque, so we depend on this layout 12686797Sluigi * to locate the struct ifnet from the softc in the generic code. 12786797Sluigi * 12884380Smjacob */ 12921259Swollmanstruct ifnet { 13021259Swollman void *if_softc; /* pointer to driver state */ 13121259Swollman char *if_name; /* name, e.g. ``en'' or ``lo'' */ 13260938Sjake TAILQ_ENTRY(ifnet) if_link; /* all struct ifnets are chained */ 13321259Swollman struct ifaddrhead if_addrhead; /* linked list of addresses per if */ 13483130Sjlemon struct klist if_klist; /* events attached to this if */ 13583130Sjlemon int if_pcount; /* number of promiscuous listeners */ 13621259Swollman struct bpf_if *if_bpf; /* packet filter structure */ 13721259Swollman u_short if_index; /* numeric abbreviation for this if */ 13821259Swollman short if_unit; /* sub-unit for lower level driver */ 13921259Swollman short if_timer; /* time 'til if_watchdog called */ 140106931Ssam u_short if_nvlans; /* number of active vlans */ 141102052Ssobomax int if_flags; /* up/down, broadcast, etc. */ 14283624Sjlemon int if_capabilities; /* interface capabilities */ 14383624Sjlemon int if_capenable; /* enabled features */ 14421259Swollman int if_ipending; /* interrupts pending */ 14521259Swollman void *if_linkmib; /* link-type-specific MIB data */ 14621259Swollman size_t if_linkmiblen; /* length of above data */ 14721259Swollman struct if_data if_data; 14821404Swollman struct ifmultihead if_multiaddrs; /* multicast addresses configured */ 14921404Swollman int if_amcount; /* number of all-multicast requests */ 15021259Swollman/* procedure handles */ 15121259Swollman int (*if_output) /* output routine (enqueue) */ 15292725Salfred (struct ifnet *, struct mbuf *, struct sockaddr *, 15392725Salfred struct rtentry *); 154106931Ssam void (*if_input) /* input routine (from h/w driver) */ 155106931Ssam (struct ifnet *, struct mbuf *); 15621259Swollman void (*if_start) /* initiate output routine */ 15792725Salfred (struct ifnet *); 15821259Swollman int (*if_done) /* output complete routine */ 15992725Salfred (struct ifnet *); /* (XXX not used; fake prototype) */ 16021259Swollman int (*if_ioctl) /* ioctl routine */ 16192725Salfred (struct ifnet *, u_long, caddr_t); 16221259Swollman void (*if_watchdog) /* timer routine */ 16392725Salfred (struct ifnet *); 16421259Swollman int (*if_poll_recv) /* polled receive routine */ 16592725Salfred (struct ifnet *, int *); 16621259Swollman int (*if_poll_xmit) /* polled transmit routine */ 16792725Salfred (struct ifnet *, int *); 16821259Swollman void (*if_poll_intren) /* polled interrupt reenable routine */ 16992725Salfred (struct ifnet *); 17021259Swollman void (*if_poll_slowinput) /* input routine for slow devices */ 17192725Salfred (struct ifnet *, struct mbuf *); 17221259Swollman void (*if_init) /* Init routine */ 17392725Salfred (void *); 17421404Swollman int (*if_resolvemulti) /* validate/resolve multicast */ 17592725Salfred (struct ifnet *, struct sockaddr **, struct sockaddr *); 17621259Swollman struct ifqueue if_snd; /* output queue */ 17721259Swollman struct ifqueue *if_poll_slowq; /* input queue for slow devices */ 17852904Sshin struct ifprefixhead if_prefixhead; /* list of prefixes per if */ 17984931Sfjoe u_int8_t *if_broadcastaddr; /* linklevel broadcast bytestring */ 180100992Srwatson struct label if_label; /* interface MAC label */ 181121161Sume 182121161Sume void *if_afdata[AF_MAX]; 183121470Sume int if_afdata_initialized; 184121470Sume struct mtx if_afdata_mtx; 18521259Swollman}; 18669152Sjlemon 18792725Salfredtypedef void if_init_f_t(void *); 18821259Swollman 18921259Swollman#define if_mtu if_data.ifi_mtu 19021259Swollman#define if_type if_data.ifi_type 19121259Swollman#define if_physical if_data.ifi_physical 19221259Swollman#define if_addrlen if_data.ifi_addrlen 19321259Swollman#define if_hdrlen if_data.ifi_hdrlen 19421259Swollman#define if_metric if_data.ifi_metric 19521259Swollman#define if_baudrate if_data.ifi_baudrate 19658698Sjlemon#define if_hwassist if_data.ifi_hwassist 19721259Swollman#define if_ipackets if_data.ifi_ipackets 19821259Swollman#define if_ierrors if_data.ifi_ierrors 19921259Swollman#define if_opackets if_data.ifi_opackets 20021259Swollman#define if_oerrors if_data.ifi_oerrors 20121259Swollman#define if_collisions if_data.ifi_collisions 20221259Swollman#define if_ibytes if_data.ifi_ibytes 20321259Swollman#define if_obytes if_data.ifi_obytes 20421259Swollman#define if_imcasts if_data.ifi_imcasts 20521259Swollman#define if_omcasts if_data.ifi_omcasts 20621259Swollman#define if_iqdrops if_data.ifi_iqdrops 20721259Swollman#define if_noproto if_data.ifi_noproto 20821259Swollman#define if_lastchange if_data.ifi_lastchange 20921259Swollman#define if_recvquota if_data.ifi_recvquota 21021259Swollman#define if_xmitquota if_data.ifi_xmitquota 21121259Swollman#define if_rawoutput(if, m, sa) if_output(if, m, sa, (struct rtentry *)0) 21221259Swollman 21353541Sshin/* for compatibility with other BSDs */ 21453541Sshin#define if_addrlist if_addrhead 21553541Sshin#define if_list if_link 21653541Sshin 21721259Swollman/* 21821259Swollman * Bit values in if_ipending 21921259Swollman */ 22021259Swollman#define IFI_RECV 1 /* I want to receive */ 22121259Swollman#define IFI_XMIT 2 /* I want to transmit */ 22221259Swollman 22321259Swollman/* 22421259Swollman * Output queues (ifp->if_snd) and slow device input queues (*ifp->if_slowq) 22521259Swollman * are queues of messages stored on ifqueue structures 22621259Swollman * (defined above). Entries are added to and deleted from these structures 22721259Swollman * by these macros, which should be called with ipl raised to splimp(). 22821259Swollman */ 22972200Sbmilekic#define IF_LOCK(ifq) mtx_lock(&(ifq)->ifq_mtx) 23072200Sbmilekic#define IF_UNLOCK(ifq) mtx_unlock(&(ifq)->ifq_mtx) 23169152Sjlemon#define _IF_QFULL(ifq) ((ifq)->ifq_len >= (ifq)->ifq_maxlen) 23269152Sjlemon#define _IF_DROP(ifq) ((ifq)->ifq_drops++) 23369152Sjlemon#define _IF_QLEN(ifq) ((ifq)->ifq_len) 23421259Swollman 23569152Sjlemon#define _IF_ENQUEUE(ifq, m) do { \ 23669152Sjlemon (m)->m_nextpkt = NULL; \ 23769152Sjlemon if ((ifq)->ifq_tail == NULL) \ 23869152Sjlemon (ifq)->ifq_head = m; \ 23969152Sjlemon else \ 24069152Sjlemon (ifq)->ifq_tail->m_nextpkt = m; \ 24169152Sjlemon (ifq)->ifq_tail = m; \ 24269152Sjlemon (ifq)->ifq_len++; \ 24369152Sjlemon} while (0) 24469152Sjlemon 24569152Sjlemon#define IF_ENQUEUE(ifq, m) do { \ 24669152Sjlemon IF_LOCK(ifq); \ 24769152Sjlemon _IF_ENQUEUE(ifq, m); \ 24869152Sjlemon IF_UNLOCK(ifq); \ 24969152Sjlemon} while (0) 25069152Sjlemon 25169152Sjlemon#define _IF_PREPEND(ifq, m) do { \ 25269152Sjlemon (m)->m_nextpkt = (ifq)->ifq_head; \ 25369152Sjlemon if ((ifq)->ifq_tail == NULL) \ 25469152Sjlemon (ifq)->ifq_tail = (m); \ 25569152Sjlemon (ifq)->ifq_head = (m); \ 25669152Sjlemon (ifq)->ifq_len++; \ 25769152Sjlemon} while (0) 25869152Sjlemon 25969152Sjlemon#define IF_PREPEND(ifq, m) do { \ 26069152Sjlemon IF_LOCK(ifq); \ 26169152Sjlemon _IF_PREPEND(ifq, m); \ 26269152Sjlemon IF_UNLOCK(ifq); \ 26369152Sjlemon} while (0) 26469152Sjlemon 26569152Sjlemon#define _IF_DEQUEUE(ifq, m) do { \ 26669152Sjlemon (m) = (ifq)->ifq_head; \ 26769152Sjlemon if (m) { \ 26869152Sjlemon if (((ifq)->ifq_head = (m)->m_nextpkt) == 0) \ 26969152Sjlemon (ifq)->ifq_tail = NULL; \ 27069152Sjlemon (m)->m_nextpkt = NULL; \ 27169152Sjlemon (ifq)->ifq_len--; \ 27269152Sjlemon } \ 27369152Sjlemon} while (0) 27469152Sjlemon 27569152Sjlemon#define IF_DEQUEUE(ifq, m) do { \ 27669152Sjlemon IF_LOCK(ifq); \ 27769152Sjlemon _IF_DEQUEUE(ifq, m); \ 27869152Sjlemon IF_UNLOCK(ifq); \ 27969152Sjlemon} while (0) 28069152Sjlemon 28169152Sjlemon#define IF_DRAIN(ifq) do { \ 28269152Sjlemon struct mbuf *m; \ 28369152Sjlemon IF_LOCK(ifq); \ 28469152Sjlemon for (;;) { \ 28569152Sjlemon _IF_DEQUEUE(ifq, m); \ 28669152Sjlemon if (m == NULL) \ 28769152Sjlemon break; \ 28869152Sjlemon m_freem(m); \ 28969152Sjlemon } \ 29069152Sjlemon IF_UNLOCK(ifq); \ 29169152Sjlemon} while (0) 29269152Sjlemon 29355205Speter#ifdef _KERNEL 294121470Sume#define IF_AFDATA_LOCK_INIT(ifp) \ 295121470Sume mtx_init(&(ifp)->if_afdata_mtx, "if_afdata", NULL, MTX_DEF) 296121470Sume#define IF_AFDATA_LOCK(ifp) mtx_lock(&(ifp)->if_afdata_mtx) 297121470Sume#define IF_AFDATA_TRYLOCK(ifp) mtx_trylock(&(ifp)->if_afdata_mtx) 298121470Sume#define IF_AFDATA_UNLOCK(ifp) mtx_unlock(&(ifp)->if_afdata_mtx) 299121470Sume#define IF_AFDATA_DESTROY(ifp) mtx_destroy(&(ifp)->if_afdata_mtx) 300121470Sume 30169152Sjlemon#define IF_HANDOFF(ifq, m, ifp) if_handoff(ifq, m, ifp, 0) 30269152Sjlemon#define IF_HANDOFF_ADJ(ifq, m, ifp, adj) if_handoff(ifq, m, ifp, adj) 30321259Swollman 30435210Sbdestatic __inline int 30569152Sjlemonif_handoff(struct ifqueue *ifq, struct mbuf *m, struct ifnet *ifp, int adjust) 30621259Swollman{ 30769152Sjlemon int active = 0; 30821259Swollman 30969152Sjlemon IF_LOCK(ifq); 31069152Sjlemon if (_IF_QFULL(ifq)) { 31169152Sjlemon _IF_DROP(ifq); 31269152Sjlemon IF_UNLOCK(ifq); 31369152Sjlemon m_freem(m); 31469152Sjlemon return (0); 31569152Sjlemon } 31669152Sjlemon if (ifp != NULL) { 31769152Sjlemon ifp->if_obytes += m->m_pkthdr.len + adjust; 31869152Sjlemon if (m->m_flags & M_MCAST) 31969152Sjlemon ifp->if_omcasts++; 32069152Sjlemon active = ifp->if_flags & IFF_OACTIVE; 32169152Sjlemon } 32269152Sjlemon _IF_ENQUEUE(ifq, m); 32369152Sjlemon IF_UNLOCK(ifq); 32486364Sjhb if (ifp != NULL && !active) 32596173Simp (*ifp->if_start)(ifp); 32669152Sjlemon return (1); 32721259Swollman} 32821259Swollman 32949459Sbrian/* 33049459Sbrian * 72 was chosen below because it is the size of a TCP/IP 33149459Sbrian * header (40) + the minimum mss (32). 33249459Sbrian */ 33349459Sbrian#define IF_MINMTU 72 33449459Sbrian#define IF_MAXMTU 65535 33549459Sbrian 33655205Speter#endif /* _KERNEL */ 33721259Swollman 33821259Swollman/* 33921259Swollman * The ifaddr structure contains information about one address 34021259Swollman * of an interface. They are maintained by the different address families, 34121259Swollman * are allocated and attached when an address is set, and are linked 34221259Swollman * together so all addresses for an interface can be located. 34321259Swollman */ 34421259Swollmanstruct ifaddr { 34521259Swollman struct sockaddr *ifa_addr; /* address of interface */ 34621259Swollman struct sockaddr *ifa_dstaddr; /* other end of p-to-p link */ 34721259Swollman#define ifa_broadaddr ifa_dstaddr /* broadcast address interface */ 34821259Swollman struct sockaddr *ifa_netmask; /* used to determine subnet */ 34967334Sjoe struct if_data if_data; /* not all members are meaningful */ 35021259Swollman struct ifnet *ifa_ifp; /* back-pointer to interface */ 35160938Sjake TAILQ_ENTRY(ifaddr) ifa_link; /* queue macro glue */ 35221259Swollman void (*ifa_rtrequest) /* check or clean routes (+ or -)'d */ 35392725Salfred (int, struct rtentry *, struct rt_addrinfo *); 35421259Swollman u_short ifa_flags; /* mostly rt_flags for cloning */ 35547254Spb u_int ifa_refcnt; /* references to this structure */ 35621259Swollman int ifa_metric; /* cost of going out this interface */ 35721259Swollman#ifdef notdef 35821259Swollman struct rtentry *ifa_rt; /* XXXX for ROUTETOIF ????? */ 35921259Swollman#endif 36028845Sjulian int (*ifa_claim_addr) /* check if an addr goes to this if */ 36192725Salfred (struct ifaddr *, struct sockaddr *); 362108033Shsu struct mtx ifa_mtx; 36321259Swollman}; 36421259Swollman#define IFA_ROUTE RTF_UP /* route installed */ 36521259Swollman 36653541Sshin/* for compatibility with other BSDs */ 36753541Sshin#define ifa_list ifa_link 36853541Sshin 369108033Shsu#define IFA_LOCK_INIT(ifa) \ 370108033Shsu mtx_init(&(ifa)->ifa_mtx, "ifaddr", NULL, MTX_DEF) 371108033Shsu#define IFA_LOCK(ifa) mtx_lock(&(ifa)->ifa_mtx) 372108033Shsu#define IFA_UNLOCK(ifa) mtx_unlock(&(ifa)->ifa_mtx) 373108033Shsu#define IFA_DESTROY(ifa) mtx_destroy(&(ifa)->ifa_mtx) 374108033Shsu 37521404Swollman/* 37652904Sshin * The prefix structure contains information about one prefix 37752904Sshin * of an interface. They are maintained by the different address families, 378108470Sschweikh * are allocated and attached when a prefix or an address is set, 37953541Sshin * and are linked together so all prefixes for an interface can be located. 38052904Sshin */ 38152904Sshinstruct ifprefix { 38252904Sshin struct sockaddr *ifpr_prefix; /* prefix of interface */ 38352904Sshin struct ifnet *ifpr_ifp; /* back-pointer to interface */ 38460938Sjake TAILQ_ENTRY(ifprefix) ifpr_list; /* queue macro glue */ 38552904Sshin u_char ifpr_plen; /* prefix length in bits */ 38652904Sshin u_char ifpr_type; /* protocol dependent prefix type */ 38752904Sshin}; 38852904Sshin 38952904Sshin/* 39021404Swollman * Multicast address structure. This is analogous to the ifaddr 39121404Swollman * structure except that it keeps track of multicast addresses. 39221404Swollman * Also, the reference count here is a count of requests for this 39321404Swollman * address, not a count of pointers to this structure. 39421404Swollman */ 39521404Swollmanstruct ifmultiaddr { 39672084Sphk TAILQ_ENTRY(ifmultiaddr) ifma_link; /* queue macro glue */ 39721434Swollman struct sockaddr *ifma_addr; /* address this membership is for */ 39821434Swollman struct sockaddr *ifma_lladdr; /* link-layer translation, if any */ 39921434Swollman struct ifnet *ifma_ifp; /* back-pointer to interface */ 40021434Swollman u_int ifma_refcount; /* reference count */ 40121434Swollman void *ifma_protospec; /* protocol-specific state, if any */ 40221404Swollman}; 40321404Swollman 40455205Speter#ifdef _KERNEL 405108036Shsu#define IFAFREE(ifa) \ 406108036Shsu do { \ 407108036Shsu IFA_LOCK(ifa); \ 408108036Shsu KASSERT((ifa)->ifa_refcnt > 0, \ 409108036Shsu ("ifa %p !(ifa_refcnt > 0)", ifa)); \ 410108036Shsu if (--(ifa)->ifa_refcnt == 0) { \ 411108036Shsu IFA_DESTROY(ifa); \ 412108036Shsu free(ifa, M_IFADDR); \ 413108036Shsu } else \ 414108036Shsu IFA_UNLOCK(ifa); \ 41546568Speter } while (0) 41621259Swollman 417108036Shsu#define IFAREF(ifa) \ 418108036Shsu do { \ 419108036Shsu IFA_LOCK(ifa); \ 420108036Shsu ++(ifa)->ifa_refcnt; \ 421108036Shsu IFA_UNLOCK(ifa); \ 422108033Shsu } while (0) 423108033Shsu 424108172Shsuextern struct mtx ifnet_lock; 425108298Shsu#define IFNET_LOCK_INIT() \ 426108298Shsu mtx_init(&ifnet_lock, "ifnet", NULL, MTX_DEF | MTX_RECURSE) 427108172Shsu#define IFNET_WLOCK() mtx_lock(&ifnet_lock) 428108172Shsu#define IFNET_WUNLOCK() mtx_unlock(&ifnet_lock) 429108172Shsu#define IFNET_RLOCK() IFNET_WLOCK() 430108172Shsu#define IFNET_RUNLOCK() IFNET_WUNLOCK() 431108172Shsu 43283130Sjlemonstruct ifindex_entry { 43387914Sjlemon struct ifnet *ife_ifnet; 43483130Sjlemon struct ifaddr *ife_ifnet_addr; 43583130Sjlemon dev_t ife_dev; 43683130Sjlemon}; 43783130Sjlemon 43883130Sjlemon#define ifnet_byindex(idx) ifindex_table[(idx)].ife_ifnet 43983130Sjlemon#define ifaddr_byindex(idx) ifindex_table[(idx)].ife_ifnet_addr 44083130Sjlemon#define ifdev_byindex(idx) ifindex_table[(idx)].ife_dev 44183130Sjlemon 44221259Swollmanextern struct ifnethead ifnet; 44383130Sjlemonextern struct ifindex_entry *ifindex_table; 44421259Swollmanextern int ifqmaxlen; 44571791Speterextern struct ifnet *loif; /* first loopback interface */ 44621259Swollmanextern int if_index; 44721259Swollman 44892725Salfredint if_addmulti(struct ifnet *, struct sockaddr *, struct ifmultiaddr **); 44992725Salfredint if_allmulti(struct ifnet *, int); 45092725Salfredvoid if_attach(struct ifnet *); 45192725Salfredint if_delmulti(struct ifnet *, struct sockaddr *); 45292725Salfredvoid if_detach(struct ifnet *); 45392725Salfredvoid if_down(struct ifnet *); 454103900Sbrooksint if_printf(struct ifnet *, const char *, ...) __printflike(2, 3); 45592725Salfredvoid if_route(struct ifnet *, int flag, int fam); 45692725Salfredint if_setlladdr(struct ifnet *, const u_char *, int); 45792725Salfredvoid if_unroute(struct ifnet *, int flag, int fam); 45892725Salfredvoid if_up(struct ifnet *); 45992725Salfred/*void ifinit(void);*/ /* declared in systm.h for main() */ 46092725Salfredint ifioctl(struct socket *, u_long, caddr_t, struct thread *); 46192725Salfredint ifpromisc(struct ifnet *, int); 46292725Salfredstruct ifnet *ifunit(const char *); 46392725Salfredstruct ifnet *if_withname(struct sockaddr *); 46421259Swollman 46592725Salfredint if_poll_recv_slow(struct ifnet *ifp, int *quotap); 46692725Salfredvoid if_poll_xmit_slow(struct ifnet *ifp, int *quotap); 46792725Salfredvoid if_poll_throttle(void); 46892725Salfredvoid if_poll_unthrottle(void *); 46992725Salfredvoid if_poll_init(void); 47092725Salfredvoid if_poll(void); 47121259Swollman 47292725Salfredstruct ifaddr *ifa_ifwithaddr(struct sockaddr *); 47392725Salfredstruct ifaddr *ifa_ifwithdstaddr(struct sockaddr *); 47492725Salfredstruct ifaddr *ifa_ifwithnet(struct sockaddr *); 47592725Salfredstruct ifaddr *ifa_ifwithroute(int, struct sockaddr *, struct sockaddr *); 47692725Salfredstruct ifaddr *ifaof_ifpforaddr(struct sockaddr *, struct ifnet *); 47721259Swollman 47892725Salfredstruct ifmultiaddr *ifmaof_ifpforaddr(struct sockaddr *, struct ifnet *); 47992725Salfredint if_simloop(struct ifnet *ifp, struct mbuf *m, int af, int hlen); 48021434Swollman 48192725Salfredvoid if_clone_attach(struct if_clone *); 48292725Salfredvoid if_clone_detach(struct if_clone *); 48379103Sbrooks 48492725Salfredint if_clone_create(char *, int); 48592725Salfredint if_clone_destroy(const char *); 48679103Sbrooks 48784931Sfjoe#define IF_LLADDR(ifp) \ 48884931Sfjoe LLADDR((struct sockaddr_dl *) ifaddr_byindex((ifp)->if_index)->ifa_addr) 48984931Sfjoe 49087902Sluigi#ifdef DEVICE_POLLING 49187902Sluigienum poll_cmd { POLL_ONLY, POLL_AND_CHECK_STATUS, POLL_DEREGISTER }; 49287902Sluigi 49392725Salfredtypedef void poll_handler_t(struct ifnet *ifp, enum poll_cmd cmd, int count); 49492725Salfredint ether_poll_register(poll_handler_t *h, struct ifnet *ifp); 49592725Salfredint ether_poll_deregister(struct ifnet *ifp); 49687902Sluigi#endif /* DEVICE_POLLING */ 49787902Sluigi 49855205Speter#endif /* _KERNEL */ 49921259Swollman 50021259Swollman#endif /* !_NET_IF_VAR_H_ */ 501