1*7ecc6a92SDavid van Moolenbroek /* $NetBSD: if.h,v 1.193 2015/10/02 03:08:26 ozaki-r Exp $ */
2*7ecc6a92SDavid van Moolenbroek
3*7ecc6a92SDavid van Moolenbroek /*-
4*7ecc6a92SDavid van Moolenbroek * Copyright (c) 1999, 2000, 2001 The NetBSD Foundation, Inc.
5*7ecc6a92SDavid van Moolenbroek * All rights reserved.
6*7ecc6a92SDavid van Moolenbroek *
7*7ecc6a92SDavid van Moolenbroek * This code is derived from software contributed to The NetBSD Foundation
8*7ecc6a92SDavid van Moolenbroek * by William Studenmund and Jason R. Thorpe.
9*7ecc6a92SDavid van Moolenbroek *
10*7ecc6a92SDavid van Moolenbroek * Redistribution and use in source and binary forms, with or without
11*7ecc6a92SDavid van Moolenbroek * modification, are permitted provided that the following conditions
12*7ecc6a92SDavid van Moolenbroek * are met:
13*7ecc6a92SDavid van Moolenbroek * 1. Redistributions of source code must retain the above copyright
14*7ecc6a92SDavid van Moolenbroek * notice, this list of conditions and the following disclaimer.
15*7ecc6a92SDavid van Moolenbroek * 2. Redistributions in binary form must reproduce the above copyright
16*7ecc6a92SDavid van Moolenbroek * notice, this list of conditions and the following disclaimer in the
17*7ecc6a92SDavid van Moolenbroek * documentation and/or other materials provided with the distribution.
18*7ecc6a92SDavid van Moolenbroek *
19*7ecc6a92SDavid van Moolenbroek * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20*7ecc6a92SDavid van Moolenbroek * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21*7ecc6a92SDavid van Moolenbroek * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22*7ecc6a92SDavid van Moolenbroek * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23*7ecc6a92SDavid van Moolenbroek * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24*7ecc6a92SDavid van Moolenbroek * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25*7ecc6a92SDavid van Moolenbroek * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26*7ecc6a92SDavid van Moolenbroek * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27*7ecc6a92SDavid van Moolenbroek * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28*7ecc6a92SDavid van Moolenbroek * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29*7ecc6a92SDavid van Moolenbroek * POSSIBILITY OF SUCH DAMAGE.
30*7ecc6a92SDavid van Moolenbroek */
31*7ecc6a92SDavid van Moolenbroek
32*7ecc6a92SDavid van Moolenbroek /*
33*7ecc6a92SDavid van Moolenbroek * Copyright (c) 1982, 1986, 1989, 1993
34*7ecc6a92SDavid van Moolenbroek * The Regents of the University of California. All rights reserved.
35*7ecc6a92SDavid van Moolenbroek *
36*7ecc6a92SDavid van Moolenbroek * Redistribution and use in source and binary forms, with or without
37*7ecc6a92SDavid van Moolenbroek * modification, are permitted provided that the following conditions
38*7ecc6a92SDavid van Moolenbroek * are met:
39*7ecc6a92SDavid van Moolenbroek * 1. Redistributions of source code must retain the above copyright
40*7ecc6a92SDavid van Moolenbroek * notice, this list of conditions and the following disclaimer.
41*7ecc6a92SDavid van Moolenbroek * 2. Redistributions in binary form must reproduce the above copyright
42*7ecc6a92SDavid van Moolenbroek * notice, this list of conditions and the following disclaimer in the
43*7ecc6a92SDavid van Moolenbroek * documentation and/or other materials provided with the distribution.
44*7ecc6a92SDavid van Moolenbroek * 3. Neither the name of the University nor the names of its contributors
45*7ecc6a92SDavid van Moolenbroek * may be used to endorse or promote products derived from this software
46*7ecc6a92SDavid van Moolenbroek * without specific prior written permission.
47*7ecc6a92SDavid van Moolenbroek *
48*7ecc6a92SDavid van Moolenbroek * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49*7ecc6a92SDavid van Moolenbroek * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50*7ecc6a92SDavid van Moolenbroek * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51*7ecc6a92SDavid van Moolenbroek * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52*7ecc6a92SDavid van Moolenbroek * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53*7ecc6a92SDavid van Moolenbroek * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54*7ecc6a92SDavid van Moolenbroek * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55*7ecc6a92SDavid van Moolenbroek * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56*7ecc6a92SDavid van Moolenbroek * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57*7ecc6a92SDavid van Moolenbroek * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58*7ecc6a92SDavid van Moolenbroek * SUCH DAMAGE.
59*7ecc6a92SDavid van Moolenbroek *
60*7ecc6a92SDavid van Moolenbroek * @(#)if.h 8.3 (Berkeley) 2/9/95
61*7ecc6a92SDavid van Moolenbroek */
62*7ecc6a92SDavid van Moolenbroek
63*7ecc6a92SDavid van Moolenbroek #ifndef _NET_IF_H_
64*7ecc6a92SDavid van Moolenbroek #define _NET_IF_H_
65*7ecc6a92SDavid van Moolenbroek
66*7ecc6a92SDavid van Moolenbroek #if !defined(_KERNEL) && !defined(_STANDALONE)
67*7ecc6a92SDavid van Moolenbroek #include <stdbool.h>
68*7ecc6a92SDavid van Moolenbroek #endif
69*7ecc6a92SDavid van Moolenbroek
70*7ecc6a92SDavid van Moolenbroek #include <sys/featuretest.h>
71*7ecc6a92SDavid van Moolenbroek
72*7ecc6a92SDavid van Moolenbroek /*
73*7ecc6a92SDavid van Moolenbroek * Length of interface external name, including terminating '\0'.
74*7ecc6a92SDavid van Moolenbroek * Note: this is the same size as a generic device's external name.
75*7ecc6a92SDavid van Moolenbroek */
76*7ecc6a92SDavid van Moolenbroek #define IF_NAMESIZE 16
77*7ecc6a92SDavid van Moolenbroek
78*7ecc6a92SDavid van Moolenbroek #if defined(_NETBSD_SOURCE)
79*7ecc6a92SDavid van Moolenbroek
80*7ecc6a92SDavid van Moolenbroek #include <sys/socket.h>
81*7ecc6a92SDavid van Moolenbroek #include <sys/queue.h>
82*7ecc6a92SDavid van Moolenbroek #include <sys/mutex.h>
83*7ecc6a92SDavid van Moolenbroek
84*7ecc6a92SDavid van Moolenbroek #include <net/dlt.h>
85*7ecc6a92SDavid van Moolenbroek #include <net/pfil.h>
86*7ecc6a92SDavid van Moolenbroek #ifdef _KERNEL
87*7ecc6a92SDavid van Moolenbroek #include <net/pktqueue.h>
88*7ecc6a92SDavid van Moolenbroek #endif
89*7ecc6a92SDavid van Moolenbroek
90*7ecc6a92SDavid van Moolenbroek /*
91*7ecc6a92SDavid van Moolenbroek * Always include ALTQ glue here -- we use the ALTQ interface queue
92*7ecc6a92SDavid van Moolenbroek * structure even when ALTQ is not configured into the kernel so that
93*7ecc6a92SDavid van Moolenbroek * the size of struct ifnet does not changed based on the option. The
94*7ecc6a92SDavid van Moolenbroek * ALTQ queue structure is API-compatible with the legacy ifqueue.
95*7ecc6a92SDavid van Moolenbroek */
96*7ecc6a92SDavid van Moolenbroek #include <altq/if_altq.h>
97*7ecc6a92SDavid van Moolenbroek
98*7ecc6a92SDavid van Moolenbroek /*
99*7ecc6a92SDavid van Moolenbroek * Structures defining a network interface, providing a packet
100*7ecc6a92SDavid van Moolenbroek * transport mechanism (ala level 0 of the PUP protocols).
101*7ecc6a92SDavid van Moolenbroek *
102*7ecc6a92SDavid van Moolenbroek * Each interface accepts output datagrams of a specified maximum
103*7ecc6a92SDavid van Moolenbroek * length, and provides higher level routines with input datagrams
104*7ecc6a92SDavid van Moolenbroek * received from its medium.
105*7ecc6a92SDavid van Moolenbroek *
106*7ecc6a92SDavid van Moolenbroek * Output occurs when the routine if_output is called, with four parameters:
107*7ecc6a92SDavid van Moolenbroek * (*ifp->if_output)(ifp, m, dst, rt)
108*7ecc6a92SDavid van Moolenbroek * Here m is the mbuf chain to be sent and dst is the destination address.
109*7ecc6a92SDavid van Moolenbroek * The output routine encapsulates the supplied datagram if necessary,
110*7ecc6a92SDavid van Moolenbroek * and then transmits it on its medium.
111*7ecc6a92SDavid van Moolenbroek *
112*7ecc6a92SDavid van Moolenbroek * On input, each interface unwraps the data received by it, and either
113*7ecc6a92SDavid van Moolenbroek * places it on the input queue of a internetwork datagram routine
114*7ecc6a92SDavid van Moolenbroek * and posts the associated software interrupt, or passes the datagram to a raw
115*7ecc6a92SDavid van Moolenbroek * packet input routine.
116*7ecc6a92SDavid van Moolenbroek *
117*7ecc6a92SDavid van Moolenbroek * Routines exist for locating interfaces by their addresses
118*7ecc6a92SDavid van Moolenbroek * or for locating a interface on a certain network, as well as more general
119*7ecc6a92SDavid van Moolenbroek * routing and gateway routines maintaining information used to locate
120*7ecc6a92SDavid van Moolenbroek * interfaces. These routines live in the files if.c and route.c
121*7ecc6a92SDavid van Moolenbroek */
122*7ecc6a92SDavid van Moolenbroek #include <sys/time.h>
123*7ecc6a92SDavid van Moolenbroek
124*7ecc6a92SDavid van Moolenbroek #if defined(_KERNEL_OPT)
125*7ecc6a92SDavid van Moolenbroek #include "opt_compat_netbsd.h"
126*7ecc6a92SDavid van Moolenbroek #include "opt_gateway.h"
127*7ecc6a92SDavid van Moolenbroek #endif
128*7ecc6a92SDavid van Moolenbroek
129*7ecc6a92SDavid van Moolenbroek struct mbuf;
130*7ecc6a92SDavid van Moolenbroek struct proc;
131*7ecc6a92SDavid van Moolenbroek struct rtentry;
132*7ecc6a92SDavid van Moolenbroek struct socket;
133*7ecc6a92SDavid van Moolenbroek struct ether_header;
134*7ecc6a92SDavid van Moolenbroek struct ifaddr;
135*7ecc6a92SDavid van Moolenbroek struct ifnet;
136*7ecc6a92SDavid van Moolenbroek struct rt_addrinfo;
137*7ecc6a92SDavid van Moolenbroek
138*7ecc6a92SDavid van Moolenbroek #define IFNAMSIZ IF_NAMESIZE
139*7ecc6a92SDavid van Moolenbroek
140*7ecc6a92SDavid van Moolenbroek /*
141*7ecc6a92SDavid van Moolenbroek * Structure describing a `cloning' interface.
142*7ecc6a92SDavid van Moolenbroek */
143*7ecc6a92SDavid van Moolenbroek struct if_clone {
144*7ecc6a92SDavid van Moolenbroek LIST_ENTRY(if_clone) ifc_list; /* on list of cloners */
145*7ecc6a92SDavid van Moolenbroek const char *ifc_name; /* name of device, e.g. `gif' */
146*7ecc6a92SDavid van Moolenbroek size_t ifc_namelen; /* length of name */
147*7ecc6a92SDavid van Moolenbroek
148*7ecc6a92SDavid van Moolenbroek int (*ifc_create)(struct if_clone *, int);
149*7ecc6a92SDavid van Moolenbroek int (*ifc_destroy)(struct ifnet *);
150*7ecc6a92SDavid van Moolenbroek };
151*7ecc6a92SDavid van Moolenbroek
152*7ecc6a92SDavid van Moolenbroek #define IF_CLONE_INITIALIZER(name, create, destroy) \
153*7ecc6a92SDavid van Moolenbroek { { NULL, NULL }, name, sizeof(name) - 1, create, destroy }
154*7ecc6a92SDavid van Moolenbroek
155*7ecc6a92SDavid van Moolenbroek /*
156*7ecc6a92SDavid van Moolenbroek * Structure used to query names of interface cloners.
157*7ecc6a92SDavid van Moolenbroek */
158*7ecc6a92SDavid van Moolenbroek struct if_clonereq {
159*7ecc6a92SDavid van Moolenbroek int ifcr_total; /* total cloners (out) */
160*7ecc6a92SDavid van Moolenbroek int ifcr_count; /* room for this many in user buffer */
161*7ecc6a92SDavid van Moolenbroek char *ifcr_buffer; /* buffer for cloner names */
162*7ecc6a92SDavid van Moolenbroek };
163*7ecc6a92SDavid van Moolenbroek
164*7ecc6a92SDavid van Moolenbroek /*
165*7ecc6a92SDavid van Moolenbroek * Structure defining statistics and other data kept regarding a network
166*7ecc6a92SDavid van Moolenbroek * interface.
167*7ecc6a92SDavid van Moolenbroek */
168*7ecc6a92SDavid van Moolenbroek struct if_data {
169*7ecc6a92SDavid van Moolenbroek /* generic interface information */
170*7ecc6a92SDavid van Moolenbroek u_char ifi_type; /* ethernet, tokenring, etc. */
171*7ecc6a92SDavid van Moolenbroek u_char ifi_addrlen; /* media address length */
172*7ecc6a92SDavid van Moolenbroek u_char ifi_hdrlen; /* media header length */
173*7ecc6a92SDavid van Moolenbroek int ifi_link_state; /* current link state */
174*7ecc6a92SDavid van Moolenbroek uint64_t ifi_mtu; /* maximum transmission unit */
175*7ecc6a92SDavid van Moolenbroek uint64_t ifi_metric; /* routing metric (external only) */
176*7ecc6a92SDavid van Moolenbroek uint64_t ifi_baudrate; /* linespeed */
177*7ecc6a92SDavid van Moolenbroek /* volatile statistics */
178*7ecc6a92SDavid van Moolenbroek uint64_t ifi_ipackets; /* packets received on interface */
179*7ecc6a92SDavid van Moolenbroek uint64_t ifi_ierrors; /* input errors on interface */
180*7ecc6a92SDavid van Moolenbroek uint64_t ifi_opackets; /* packets sent on interface */
181*7ecc6a92SDavid van Moolenbroek uint64_t ifi_oerrors; /* output errors on interface */
182*7ecc6a92SDavid van Moolenbroek uint64_t ifi_collisions; /* collisions on csma interfaces */
183*7ecc6a92SDavid van Moolenbroek uint64_t ifi_ibytes; /* total number of octets received */
184*7ecc6a92SDavid van Moolenbroek uint64_t ifi_obytes; /* total number of octets sent */
185*7ecc6a92SDavid van Moolenbroek uint64_t ifi_imcasts; /* packets received via multicast */
186*7ecc6a92SDavid van Moolenbroek uint64_t ifi_omcasts; /* packets sent via multicast */
187*7ecc6a92SDavid van Moolenbroek uint64_t ifi_iqdrops; /* dropped on input, this interface */
188*7ecc6a92SDavid van Moolenbroek uint64_t ifi_noproto; /* destined for unsupported protocol */
189*7ecc6a92SDavid van Moolenbroek struct timespec ifi_lastchange;/* last operational state change */
190*7ecc6a92SDavid van Moolenbroek };
191*7ecc6a92SDavid van Moolenbroek
192*7ecc6a92SDavid van Moolenbroek /*
193*7ecc6a92SDavid van Moolenbroek * Values for if_link_state.
194*7ecc6a92SDavid van Moolenbroek */
195*7ecc6a92SDavid van Moolenbroek #define LINK_STATE_UNKNOWN 0 /* link invalid/unknown */
196*7ecc6a92SDavid van Moolenbroek #define LINK_STATE_DOWN 1 /* link is down */
197*7ecc6a92SDavid van Moolenbroek #define LINK_STATE_UP 2 /* link is up */
198*7ecc6a92SDavid van Moolenbroek
199*7ecc6a92SDavid van Moolenbroek /*
200*7ecc6a92SDavid van Moolenbroek * Structure defining a queue for a network interface.
201*7ecc6a92SDavid van Moolenbroek */
202*7ecc6a92SDavid van Moolenbroek struct ifqueue {
203*7ecc6a92SDavid van Moolenbroek struct mbuf *ifq_head;
204*7ecc6a92SDavid van Moolenbroek struct mbuf *ifq_tail;
205*7ecc6a92SDavid van Moolenbroek int ifq_len;
206*7ecc6a92SDavid van Moolenbroek int ifq_maxlen;
207*7ecc6a92SDavid van Moolenbroek int ifq_drops;
208*7ecc6a92SDavid van Moolenbroek kmutex_t *ifq_lock;
209*7ecc6a92SDavid van Moolenbroek };
210*7ecc6a92SDavid van Moolenbroek
211*7ecc6a92SDavid van Moolenbroek struct ifnet_lock;
212*7ecc6a92SDavid van Moolenbroek
213*7ecc6a92SDavid van Moolenbroek #ifdef _KERNEL
214*7ecc6a92SDavid van Moolenbroek #include <sys/condvar.h>
215*7ecc6a92SDavid van Moolenbroek #include <sys/percpu.h>
216*7ecc6a92SDavid van Moolenbroek #include <sys/callout.h>
217*7ecc6a92SDavid van Moolenbroek #ifdef GATEWAY
218*7ecc6a92SDavid van Moolenbroek #include <sys/mutex.h>
219*7ecc6a92SDavid van Moolenbroek #else
220*7ecc6a92SDavid van Moolenbroek #include <sys/rwlock.h>
221*7ecc6a92SDavid van Moolenbroek #endif
222*7ecc6a92SDavid van Moolenbroek
223*7ecc6a92SDavid van Moolenbroek struct ifnet_lock {
224*7ecc6a92SDavid van Moolenbroek kmutex_t il_lock; /* Protects the critical section. */
225*7ecc6a92SDavid van Moolenbroek uint64_t il_nexit; /* Counts threads across all CPUs who
226*7ecc6a92SDavid van Moolenbroek * have exited the critical section.
227*7ecc6a92SDavid van Moolenbroek * Access to il_nexit is synchronized
228*7ecc6a92SDavid van Moolenbroek * by il_lock.
229*7ecc6a92SDavid van Moolenbroek */
230*7ecc6a92SDavid van Moolenbroek percpu_t *il_nenter; /* Counts threads on each CPU who have
231*7ecc6a92SDavid van Moolenbroek * entered or who wait to enter the
232*7ecc6a92SDavid van Moolenbroek * critical section protected by il_lock.
233*7ecc6a92SDavid van Moolenbroek * Synchronization is not required.
234*7ecc6a92SDavid van Moolenbroek */
235*7ecc6a92SDavid van Moolenbroek kcondvar_t il_emptied; /* The ifnet_lock user must arrange for
236*7ecc6a92SDavid van Moolenbroek * the last threads in the critical
237*7ecc6a92SDavid van Moolenbroek * section to signal this condition variable
238*7ecc6a92SDavid van Moolenbroek * before they leave.
239*7ecc6a92SDavid van Moolenbroek */
240*7ecc6a92SDavid van Moolenbroek };
241*7ecc6a92SDavid van Moolenbroek #endif /* _KERNEL */
242*7ecc6a92SDavid van Moolenbroek
243*7ecc6a92SDavid van Moolenbroek /*
244*7ecc6a92SDavid van Moolenbroek * Structure defining a queue for a network interface.
245*7ecc6a92SDavid van Moolenbroek *
246*7ecc6a92SDavid van Moolenbroek * (Would like to call this struct ``if'', but C isn't PL/1.)
247*7ecc6a92SDavid van Moolenbroek */
248*7ecc6a92SDavid van Moolenbroek TAILQ_HEAD(ifnet_head, ifnet); /* the actual queue head */
249*7ecc6a92SDavid van Moolenbroek
250*7ecc6a92SDavid van Moolenbroek struct bridge_softc;
251*7ecc6a92SDavid van Moolenbroek struct bridge_iflist;
252*7ecc6a92SDavid van Moolenbroek struct callout;
253*7ecc6a92SDavid van Moolenbroek struct krwlock;
254*7ecc6a92SDavid van Moolenbroek
255*7ecc6a92SDavid van Moolenbroek typedef struct ifnet {
256*7ecc6a92SDavid van Moolenbroek void *if_softc; /* lower-level data for this if */
257*7ecc6a92SDavid van Moolenbroek TAILQ_ENTRY(ifnet) if_list; /* all struct ifnets are chained */
258*7ecc6a92SDavid van Moolenbroek TAILQ_HEAD(, ifaddr) if_addrlist; /* linked list of addresses per if */
259*7ecc6a92SDavid van Moolenbroek char if_xname[IFNAMSIZ]; /* external name (name + unit) */
260*7ecc6a92SDavid van Moolenbroek int if_pcount; /* number of promiscuous listeners */
261*7ecc6a92SDavid van Moolenbroek struct bpf_if *if_bpf; /* packet filter structure */
262*7ecc6a92SDavid van Moolenbroek u_short if_index; /* numeric abbreviation for this if */
263*7ecc6a92SDavid van Moolenbroek short if_timer; /* time 'til if_slowtimo called */
264*7ecc6a92SDavid van Moolenbroek short if_flags; /* up/down, broadcast, etc. */
265*7ecc6a92SDavid van Moolenbroek short if__pad1; /* be nice to m68k ports */
266*7ecc6a92SDavid van Moolenbroek struct if_data if_data; /* statistics and other data about if */
267*7ecc6a92SDavid van Moolenbroek /*
268*7ecc6a92SDavid van Moolenbroek * Procedure handles. If you add more of these, don't forget the
269*7ecc6a92SDavid van Moolenbroek * corresponding NULL stub in if.c.
270*7ecc6a92SDavid van Moolenbroek */
271*7ecc6a92SDavid van Moolenbroek int (*if_output) /* output routine (enqueue) */
272*7ecc6a92SDavid van Moolenbroek (struct ifnet *, struct mbuf *, const struct sockaddr *,
273*7ecc6a92SDavid van Moolenbroek struct rtentry *);
274*7ecc6a92SDavid van Moolenbroek void (*if_input) /* input routine (from h/w driver) */
275*7ecc6a92SDavid van Moolenbroek (struct ifnet *, struct mbuf *);
276*7ecc6a92SDavid van Moolenbroek void (*if_start) /* initiate output routine */
277*7ecc6a92SDavid van Moolenbroek (struct ifnet *);
278*7ecc6a92SDavid van Moolenbroek int (*if_ioctl) /* ioctl routine */
279*7ecc6a92SDavid van Moolenbroek (struct ifnet *, u_long, void *);
280*7ecc6a92SDavid van Moolenbroek int (*if_init) /* init routine */
281*7ecc6a92SDavid van Moolenbroek (struct ifnet *);
282*7ecc6a92SDavid van Moolenbroek void (*if_stop) /* stop routine */
283*7ecc6a92SDavid van Moolenbroek (struct ifnet *, int);
284*7ecc6a92SDavid van Moolenbroek void (*if_slowtimo) /* timer routine */
285*7ecc6a92SDavid van Moolenbroek (struct ifnet *);
286*7ecc6a92SDavid van Moolenbroek #define if_watchdog if_slowtimo
287*7ecc6a92SDavid van Moolenbroek void (*if_drain) /* routine to release resources */
288*7ecc6a92SDavid van Moolenbroek (struct ifnet *);
289*7ecc6a92SDavid van Moolenbroek struct ifaltq if_snd; /* output queue (includes altq) */
290*7ecc6a92SDavid van Moolenbroek struct ifaddr *if_dl; /* identity of this interface. */
291*7ecc6a92SDavid van Moolenbroek const struct sockaddr_dl *if_sadl; /* pointer to sockaddr_dl
292*7ecc6a92SDavid van Moolenbroek * of if_dl
293*7ecc6a92SDavid van Moolenbroek */
294*7ecc6a92SDavid van Moolenbroek /* if_hwdl: h/w identity
295*7ecc6a92SDavid van Moolenbroek *
296*7ecc6a92SDavid van Moolenbroek * May be NULL. If not NULL, it is the address assigned
297*7ecc6a92SDavid van Moolenbroek * to the interface by the manufacturer, so it very likely
298*7ecc6a92SDavid van Moolenbroek * to be unique. It MUST NOT be deleted. It is highly
299*7ecc6a92SDavid van Moolenbroek * suitable for deriving the EUI64 for the interface.
300*7ecc6a92SDavid van Moolenbroek */
301*7ecc6a92SDavid van Moolenbroek struct ifaddr *if_hwdl;
302*7ecc6a92SDavid van Moolenbroek const uint8_t *if_broadcastaddr;/* linklevel broadcast bytestring */
303*7ecc6a92SDavid van Moolenbroek struct bridge_softc *if_bridge; /* bridge glue */
304*7ecc6a92SDavid van Moolenbroek struct bridge_iflist *if_bridgeif; /* shortcut to interface list entry */
305*7ecc6a92SDavid van Moolenbroek int if_dlt; /* data link type (<net/dlt.h>) */
306*7ecc6a92SDavid van Moolenbroek pfil_head_t * if_pfil; /* filtering point */
307*7ecc6a92SDavid van Moolenbroek uint64_t if_capabilities; /* interface capabilities */
308*7ecc6a92SDavid van Moolenbroek uint64_t if_capenable; /* capabilities enabled */
309*7ecc6a92SDavid van Moolenbroek union {
310*7ecc6a92SDavid van Moolenbroek void * carp_s; /* carp structure (used by !carp ifs) */
311*7ecc6a92SDavid van Moolenbroek struct ifnet *carp_d;/* ptr to carpdev (used by carp ifs) */
312*7ecc6a92SDavid van Moolenbroek } if_carp_ptr;
313*7ecc6a92SDavid van Moolenbroek #define if_carp if_carp_ptr.carp_s
314*7ecc6a92SDavid van Moolenbroek #define if_carpdev if_carp_ptr.carp_d
315*7ecc6a92SDavid van Moolenbroek /*
316*7ecc6a92SDavid van Moolenbroek * These are pre-computed based on an interfaces enabled
317*7ecc6a92SDavid van Moolenbroek * capabilities, for speed elsewhere.
318*7ecc6a92SDavid van Moolenbroek */
319*7ecc6a92SDavid van Moolenbroek int if_csum_flags_tx; /* M_CSUM_* flags for Tx */
320*7ecc6a92SDavid van Moolenbroek int if_csum_flags_rx; /* M_CSUM_* flags for Rx */
321*7ecc6a92SDavid van Moolenbroek
322*7ecc6a92SDavid van Moolenbroek void *if_afdata[AF_MAX];
323*7ecc6a92SDavid van Moolenbroek struct mowner *if_mowner; /* who owns mbufs for this interface */
324*7ecc6a92SDavid van Moolenbroek
325*7ecc6a92SDavid van Moolenbroek void *if_agrprivate; /* used only when #if NAGR > 0 */
326*7ecc6a92SDavid van Moolenbroek
327*7ecc6a92SDavid van Moolenbroek /*
328*7ecc6a92SDavid van Moolenbroek * pf specific data, used only when #if NPF > 0.
329*7ecc6a92SDavid van Moolenbroek */
330*7ecc6a92SDavid van Moolenbroek void *if_pf_kif; /* pf interface abstraction */
331*7ecc6a92SDavid van Moolenbroek void *if_pf_groups; /* pf interface groups */
332*7ecc6a92SDavid van Moolenbroek /*
333*7ecc6a92SDavid van Moolenbroek * During an ifnet's lifetime, it has only one if_index, but
334*7ecc6a92SDavid van Moolenbroek * and if_index is not sufficient to identify an ifnet
335*7ecc6a92SDavid van Moolenbroek * because during the lifetime of the system, many ifnets may occupy a
336*7ecc6a92SDavid van Moolenbroek * given if_index. Let us tell different ifnets at the same
337*7ecc6a92SDavid van Moolenbroek * if_index apart by their if_index_gen, a unique number that each ifnet
338*7ecc6a92SDavid van Moolenbroek * is assigned when it if_attach()s. Now, the kernel can use the
339*7ecc6a92SDavid van Moolenbroek * pair (if_index, if_index_gen) as a weak reference to an ifnet.
340*7ecc6a92SDavid van Moolenbroek */
341*7ecc6a92SDavid van Moolenbroek uint64_t if_index_gen; /* generation number for the ifnet
342*7ecc6a92SDavid van Moolenbroek * at if_index: if two ifnets' index
343*7ecc6a92SDavid van Moolenbroek * and generation number are both the
344*7ecc6a92SDavid van Moolenbroek * same, they are the same ifnet.
345*7ecc6a92SDavid van Moolenbroek */
346*7ecc6a92SDavid van Moolenbroek struct sysctllog *if_sysctl_log;
347*7ecc6a92SDavid van Moolenbroek int (*if_initaddr)(struct ifnet *, struct ifaddr *, bool);
348*7ecc6a92SDavid van Moolenbroek int (*if_mcastop)(struct ifnet *, const unsigned long,
349*7ecc6a92SDavid van Moolenbroek const struct sockaddr *);
350*7ecc6a92SDavid van Moolenbroek int (*if_setflags)(struct ifnet *, const short);
351*7ecc6a92SDavid van Moolenbroek struct ifnet_lock *if_ioctl_lock;
352*7ecc6a92SDavid van Moolenbroek #ifdef _KERNEL /* XXX kvm(3) */
353*7ecc6a92SDavid van Moolenbroek struct callout *if_slowtimo_ch;
354*7ecc6a92SDavid van Moolenbroek #endif
355*7ecc6a92SDavid van Moolenbroek #ifdef GATEWAY
356*7ecc6a92SDavid van Moolenbroek struct kmutex *if_afdata_lock;
357*7ecc6a92SDavid van Moolenbroek #else
358*7ecc6a92SDavid van Moolenbroek struct krwlock *if_afdata_lock;
359*7ecc6a92SDavid van Moolenbroek #endif
360*7ecc6a92SDavid van Moolenbroek } ifnet_t;
361*7ecc6a92SDavid van Moolenbroek
362*7ecc6a92SDavid van Moolenbroek #define if_mtu if_data.ifi_mtu
363*7ecc6a92SDavid van Moolenbroek #define if_type if_data.ifi_type
364*7ecc6a92SDavid van Moolenbroek #define if_addrlen if_data.ifi_addrlen
365*7ecc6a92SDavid van Moolenbroek #define if_hdrlen if_data.ifi_hdrlen
366*7ecc6a92SDavid van Moolenbroek #define if_metric if_data.ifi_metric
367*7ecc6a92SDavid van Moolenbroek #define if_link_state if_data.ifi_link_state
368*7ecc6a92SDavid van Moolenbroek #define if_baudrate if_data.ifi_baudrate
369*7ecc6a92SDavid van Moolenbroek #define if_ipackets if_data.ifi_ipackets
370*7ecc6a92SDavid van Moolenbroek #define if_ierrors if_data.ifi_ierrors
371*7ecc6a92SDavid van Moolenbroek #define if_opackets if_data.ifi_opackets
372*7ecc6a92SDavid van Moolenbroek #define if_oerrors if_data.ifi_oerrors
373*7ecc6a92SDavid van Moolenbroek #define if_collisions if_data.ifi_collisions
374*7ecc6a92SDavid van Moolenbroek #define if_ibytes if_data.ifi_ibytes
375*7ecc6a92SDavid van Moolenbroek #define if_obytes if_data.ifi_obytes
376*7ecc6a92SDavid van Moolenbroek #define if_imcasts if_data.ifi_imcasts
377*7ecc6a92SDavid van Moolenbroek #define if_omcasts if_data.ifi_omcasts
378*7ecc6a92SDavid van Moolenbroek #define if_iqdrops if_data.ifi_iqdrops
379*7ecc6a92SDavid van Moolenbroek #define if_noproto if_data.ifi_noproto
380*7ecc6a92SDavid van Moolenbroek #define if_lastchange if_data.ifi_lastchange
381*7ecc6a92SDavid van Moolenbroek
382*7ecc6a92SDavid van Moolenbroek #define IFF_UP 0x0001 /* interface is up */
383*7ecc6a92SDavid van Moolenbroek #define IFF_BROADCAST 0x0002 /* broadcast address valid */
384*7ecc6a92SDavid van Moolenbroek #define IFF_DEBUG 0x0004 /* turn on debugging */
385*7ecc6a92SDavid van Moolenbroek #define IFF_LOOPBACK 0x0008 /* is a loopback net */
386*7ecc6a92SDavid van Moolenbroek #define IFF_POINTOPOINT 0x0010 /* interface is point-to-point link */
387*7ecc6a92SDavid van Moolenbroek #define IFF_NOTRAILERS 0x0020 /* avoid use of trailers */
388*7ecc6a92SDavid van Moolenbroek #define IFF_RUNNING 0x0040 /* resources allocated */
389*7ecc6a92SDavid van Moolenbroek #define IFF_NOARP 0x0080 /* no address resolution protocol */
390*7ecc6a92SDavid van Moolenbroek #define IFF_PROMISC 0x0100 /* receive all packets */
391*7ecc6a92SDavid van Moolenbroek #define IFF_ALLMULTI 0x0200 /* receive all multicast packets */
392*7ecc6a92SDavid van Moolenbroek #define IFF_OACTIVE 0x0400 /* transmission in progress */
393*7ecc6a92SDavid van Moolenbroek #define IFF_SIMPLEX 0x0800 /* can't hear own transmissions */
394*7ecc6a92SDavid van Moolenbroek #define IFF_LINK0 0x1000 /* per link layer defined bit */
395*7ecc6a92SDavid van Moolenbroek #define IFF_LINK1 0x2000 /* per link layer defined bit */
396*7ecc6a92SDavid van Moolenbroek #define IFF_LINK2 0x4000 /* per link layer defined bit */
397*7ecc6a92SDavid van Moolenbroek #define IFF_MULTICAST 0x8000 /* supports multicast */
398*7ecc6a92SDavid van Moolenbroek
399*7ecc6a92SDavid van Moolenbroek #define IFFBITS \
400*7ecc6a92SDavid van Moolenbroek "\020\1UP\2BROADCAST\3DEBUG\4LOOPBACK\5POINTOPOINT\6NOTRAILERS" \
401*7ecc6a92SDavid van Moolenbroek "\7RUNNING\10NOARP\11PROMISC\12ALLMULTI\13OACTIVE\14SIMPLEX" \
402*7ecc6a92SDavid van Moolenbroek "\15LINK0\16LINK1\17LINK2\20MULTICAST"
403*7ecc6a92SDavid van Moolenbroek
404*7ecc6a92SDavid van Moolenbroek /* flags set internally only: */
405*7ecc6a92SDavid van Moolenbroek #define IFF_CANTCHANGE \
406*7ecc6a92SDavid van Moolenbroek (IFF_BROADCAST|IFF_POINTOPOINT|IFF_RUNNING|IFF_OACTIVE|\
407*7ecc6a92SDavid van Moolenbroek IFF_SIMPLEX|IFF_MULTICAST|IFF_ALLMULTI|IFF_PROMISC)
408*7ecc6a92SDavid van Moolenbroek
409*7ecc6a92SDavid van Moolenbroek /*
410*7ecc6a92SDavid van Moolenbroek * Some convenience macros used for setting ifi_baudrate.
411*7ecc6a92SDavid van Moolenbroek */
412*7ecc6a92SDavid van Moolenbroek #define IF_Kbps(x) ((x) * 1000ULL) /* kilobits/sec. */
413*7ecc6a92SDavid van Moolenbroek #define IF_Mbps(x) (IF_Kbps((x) * 1000ULL)) /* megabits/sec. */
414*7ecc6a92SDavid van Moolenbroek #define IF_Gbps(x) (IF_Mbps((x) * 1000ULL)) /* gigabits/sec. */
415*7ecc6a92SDavid van Moolenbroek
416*7ecc6a92SDavid van Moolenbroek /* Capabilities that interfaces can advertise. */
417*7ecc6a92SDavid van Moolenbroek /* 0x01 .. 0x40 were previously used */
418*7ecc6a92SDavid van Moolenbroek #define IFCAP_TSOv4 0x00080 /* can do TCPv4 segmentation offload */
419*7ecc6a92SDavid van Moolenbroek #define IFCAP_CSUM_IPv4_Rx 0x00100 /* can do IPv4 header checksums (Rx) */
420*7ecc6a92SDavid van Moolenbroek #define IFCAP_CSUM_IPv4_Tx 0x00200 /* can do IPv4 header checksums (Tx) */
421*7ecc6a92SDavid van Moolenbroek #define IFCAP_CSUM_TCPv4_Rx 0x00400 /* can do IPv4/TCP checksums (Rx) */
422*7ecc6a92SDavid van Moolenbroek #define IFCAP_CSUM_TCPv4_Tx 0x00800 /* can do IPv4/TCP checksums (Tx) */
423*7ecc6a92SDavid van Moolenbroek #define IFCAP_CSUM_UDPv4_Rx 0x01000 /* can do IPv4/UDP checksums (Rx) */
424*7ecc6a92SDavid van Moolenbroek #define IFCAP_CSUM_UDPv4_Tx 0x02000 /* can do IPv4/UDP checksums (Tx) */
425*7ecc6a92SDavid van Moolenbroek #define IFCAP_CSUM_TCPv6_Rx 0x04000 /* can do IPv6/TCP checksums (Rx) */
426*7ecc6a92SDavid van Moolenbroek #define IFCAP_CSUM_TCPv6_Tx 0x08000 /* can do IPv6/TCP checksums (Tx) */
427*7ecc6a92SDavid van Moolenbroek #define IFCAP_CSUM_UDPv6_Rx 0x10000 /* can do IPv6/UDP checksums (Rx) */
428*7ecc6a92SDavid van Moolenbroek #define IFCAP_CSUM_UDPv6_Tx 0x20000 /* can do IPv6/UDP checksums (Tx) */
429*7ecc6a92SDavid van Moolenbroek #define IFCAP_TSOv6 0x40000 /* can do TCPv6 segmentation offload */
430*7ecc6a92SDavid van Moolenbroek #define IFCAP_LRO 0x80000 /* can do Large Receive Offload */
431*7ecc6a92SDavid van Moolenbroek #define IFCAP_MASK 0xfff80 /* currently valid capabilities */
432*7ecc6a92SDavid van Moolenbroek
433*7ecc6a92SDavid van Moolenbroek #define IFCAPBITS \
434*7ecc6a92SDavid van Moolenbroek "\020" \
435*7ecc6a92SDavid van Moolenbroek "\10TSO4" \
436*7ecc6a92SDavid van Moolenbroek "\11IP4CSUM_Rx" \
437*7ecc6a92SDavid van Moolenbroek "\12IP4CSUM_Tx" \
438*7ecc6a92SDavid van Moolenbroek "\13TCP4CSUM_Rx" \
439*7ecc6a92SDavid van Moolenbroek "\14TCP4CSUM_Tx" \
440*7ecc6a92SDavid van Moolenbroek "\15UDP4CSUM_Rx" \
441*7ecc6a92SDavid van Moolenbroek "\16UDP4CSUM_Tx" \
442*7ecc6a92SDavid van Moolenbroek "\17TCP6CSUM_Rx" \
443*7ecc6a92SDavid van Moolenbroek "\20TCP6CSUM_Tx" \
444*7ecc6a92SDavid van Moolenbroek "\21UDP6CSUM_Rx" \
445*7ecc6a92SDavid van Moolenbroek "\22UDP6CSUM_Tx" \
446*7ecc6a92SDavid van Moolenbroek "\23TSO6" \
447*7ecc6a92SDavid van Moolenbroek "\24LRO" \
448*7ecc6a92SDavid van Moolenbroek
449*7ecc6a92SDavid van Moolenbroek #ifdef GATEWAY
450*7ecc6a92SDavid van Moolenbroek #define IF_AFDATA_LOCK_INIT(ifp) \
451*7ecc6a92SDavid van Moolenbroek do { \
452*7ecc6a92SDavid van Moolenbroek (ifp)->if_afdata_lock = mutex_obj_alloc(MUTEX_DEFAULT, IPL_NET); \
453*7ecc6a92SDavid van Moolenbroek } while (0)
454*7ecc6a92SDavid van Moolenbroek
455*7ecc6a92SDavid van Moolenbroek #define IF_AFDATA_WLOCK(ifp) mutex_enter((ifp)->if_afdata_lock)
456*7ecc6a92SDavid van Moolenbroek #define IF_AFDATA_RLOCK(ifp) mutex_enter((ifp)->if_afdata_lock)
457*7ecc6a92SDavid van Moolenbroek #define IF_AFDATA_WUNLOCK(ifp) mutex_exit((ifp)->if_afdata_lock)
458*7ecc6a92SDavid van Moolenbroek #define IF_AFDATA_RUNLOCK(ifp) mutex_exit((ifp)->if_afdata_lock)
459*7ecc6a92SDavid van Moolenbroek #define IF_AFDATA_LOCK(ifp) IF_AFDATA_WLOCK(ifp)
460*7ecc6a92SDavid van Moolenbroek #define IF_AFDATA_UNLOCK(ifp) IF_AFDATA_WUNLOCK(ifp)
461*7ecc6a92SDavid van Moolenbroek #define IF_AFDATA_TRYLOCK(ifp) mutex_tryenter((ifp)->if_afdata_lock)
462*7ecc6a92SDavid van Moolenbroek #define IF_AFDATA_DESTROY(ifp) mutex_destroy((ifp)->if_afdata_lock)
463*7ecc6a92SDavid van Moolenbroek
464*7ecc6a92SDavid van Moolenbroek #define IF_AFDATA_LOCK_ASSERT(ifp) \
465*7ecc6a92SDavid van Moolenbroek KASSERT(mutex_owned((ifp)->if_afdata_lock))
466*7ecc6a92SDavid van Moolenbroek #define IF_AFDATA_RLOCK_ASSERT(ifp) \
467*7ecc6a92SDavid van Moolenbroek KASSERT(mutex_owned((ifp)->if_afdata_lock))
468*7ecc6a92SDavid van Moolenbroek #define IF_AFDATA_WLOCK_ASSERT(ifp) \
469*7ecc6a92SDavid van Moolenbroek KASSERT(mutex_owned((ifp)->if_afdata_lock))
470*7ecc6a92SDavid van Moolenbroek #define IF_AFDATA_UNLOCK_ASSERT(ifp) \
471*7ecc6a92SDavid van Moolenbroek KASSERT(!mutex_owned((ifp)->if_afdata_lock))
472*7ecc6a92SDavid van Moolenbroek
473*7ecc6a92SDavid van Moolenbroek #else /* GATEWAY */
474*7ecc6a92SDavid van Moolenbroek #define IF_AFDATA_LOCK_INIT(ifp) \
475*7ecc6a92SDavid van Moolenbroek do {(ifp)->if_afdata_lock = rw_obj_alloc();} while (0)
476*7ecc6a92SDavid van Moolenbroek
477*7ecc6a92SDavid van Moolenbroek #define IF_AFDATA_WLOCK(ifp) rw_enter((ifp)->if_afdata_lock, RW_WRITER)
478*7ecc6a92SDavid van Moolenbroek #define IF_AFDATA_RLOCK(ifp) rw_enter((ifp)->if_afdata_lock, RW_READER)
479*7ecc6a92SDavid van Moolenbroek #define IF_AFDATA_WUNLOCK(ifp) rw_exit((ifp)->if_afdata_lock)
480*7ecc6a92SDavid van Moolenbroek #define IF_AFDATA_RUNLOCK(ifp) rw_exit((ifp)->if_afdata_lock)
481*7ecc6a92SDavid van Moolenbroek #define IF_AFDATA_LOCK(ifp) IF_AFDATA_WLOCK(ifp)
482*7ecc6a92SDavid van Moolenbroek #define IF_AFDATA_UNLOCK(ifp) IF_AFDATA_WUNLOCK(ifp)
483*7ecc6a92SDavid van Moolenbroek #define IF_AFDATA_TRYLOCK(ifp) rw_tryenter((ifp)->if_afdata_lock, RW_WRITER)
484*7ecc6a92SDavid van Moolenbroek #define IF_AFDATA_DESTROY(ifp) rw_destroy((ifp)->if_afdata_lock)
485*7ecc6a92SDavid van Moolenbroek
486*7ecc6a92SDavid van Moolenbroek #define IF_AFDATA_LOCK_ASSERT(ifp) \
487*7ecc6a92SDavid van Moolenbroek KASSERT(rw_lock_held((ifp)->if_afdata_lock))
488*7ecc6a92SDavid van Moolenbroek #define IF_AFDATA_RLOCK_ASSERT(ifp) \
489*7ecc6a92SDavid van Moolenbroek KASSERT(rw_read_held((ifp)->if_afdata_lock))
490*7ecc6a92SDavid van Moolenbroek #define IF_AFDATA_WLOCK_ASSERT(ifp) \
491*7ecc6a92SDavid van Moolenbroek KASSERT(rw_write_held((ifp)->if_afdata_lock))
492*7ecc6a92SDavid van Moolenbroek #define IF_AFDATA_UNLOCK_ASSERT(ifp) \
493*7ecc6a92SDavid van Moolenbroek KASSERT(!rw_lock_held((ifp)->if_afdata_lock))
494*7ecc6a92SDavid van Moolenbroek #endif /* GATEWAY */
495*7ecc6a92SDavid van Moolenbroek
496*7ecc6a92SDavid van Moolenbroek #define IFQ_LOCK(_ifq) if ((_ifq)->ifq_lock) mutex_enter((_ifq)->ifq_lock)
497*7ecc6a92SDavid van Moolenbroek #define IFQ_UNLOCK(_ifq) if ((_ifq)->ifq_lock) mutex_exit((_ifq)->ifq_lock)
498*7ecc6a92SDavid van Moolenbroek
499*7ecc6a92SDavid van Moolenbroek /*
500*7ecc6a92SDavid van Moolenbroek * Output queues (ifp->if_snd) and internetwork datagram level (pup level 1)
501*7ecc6a92SDavid van Moolenbroek * input routines have queues of messages stored on ifqueue structures
502*7ecc6a92SDavid van Moolenbroek * (defined above). Entries are added to and deleted from these structures
503*7ecc6a92SDavid van Moolenbroek * by these macros, which should be called with ipl raised to splnet().
504*7ecc6a92SDavid van Moolenbroek */
505*7ecc6a92SDavid van Moolenbroek #define IF_QFULL(ifq) ((ifq)->ifq_len >= (ifq)->ifq_maxlen)
506*7ecc6a92SDavid van Moolenbroek #define IF_DROP(ifq) ((ifq)->ifq_drops++)
507*7ecc6a92SDavid van Moolenbroek #define IF_ENQUEUE(ifq, m) do { \
508*7ecc6a92SDavid van Moolenbroek (m)->m_nextpkt = 0; \
509*7ecc6a92SDavid van Moolenbroek if ((ifq)->ifq_tail == 0) \
510*7ecc6a92SDavid van Moolenbroek (ifq)->ifq_head = m; \
511*7ecc6a92SDavid van Moolenbroek else \
512*7ecc6a92SDavid van Moolenbroek (ifq)->ifq_tail->m_nextpkt = m; \
513*7ecc6a92SDavid van Moolenbroek (ifq)->ifq_tail = m; \
514*7ecc6a92SDavid van Moolenbroek (ifq)->ifq_len++; \
515*7ecc6a92SDavid van Moolenbroek } while (/*CONSTCOND*/0)
516*7ecc6a92SDavid van Moolenbroek #define IF_PREPEND(ifq, m) do { \
517*7ecc6a92SDavid van Moolenbroek (m)->m_nextpkt = (ifq)->ifq_head; \
518*7ecc6a92SDavid van Moolenbroek if ((ifq)->ifq_tail == 0) \
519*7ecc6a92SDavid van Moolenbroek (ifq)->ifq_tail = (m); \
520*7ecc6a92SDavid van Moolenbroek (ifq)->ifq_head = (m); \
521*7ecc6a92SDavid van Moolenbroek (ifq)->ifq_len++; \
522*7ecc6a92SDavid van Moolenbroek } while (/*CONSTCOND*/0)
523*7ecc6a92SDavid van Moolenbroek #define IF_DEQUEUE(ifq, m) do { \
524*7ecc6a92SDavid van Moolenbroek (m) = (ifq)->ifq_head; \
525*7ecc6a92SDavid van Moolenbroek if (m) { \
526*7ecc6a92SDavid van Moolenbroek if (((ifq)->ifq_head = (m)->m_nextpkt) == 0) \
527*7ecc6a92SDavid van Moolenbroek (ifq)->ifq_tail = 0; \
528*7ecc6a92SDavid van Moolenbroek (m)->m_nextpkt = 0; \
529*7ecc6a92SDavid van Moolenbroek (ifq)->ifq_len--; \
530*7ecc6a92SDavid van Moolenbroek } \
531*7ecc6a92SDavid van Moolenbroek } while (/*CONSTCOND*/0)
532*7ecc6a92SDavid van Moolenbroek #define IF_POLL(ifq, m) ((m) = (ifq)->ifq_head)
533*7ecc6a92SDavid van Moolenbroek #define IF_PURGE(ifq) \
534*7ecc6a92SDavid van Moolenbroek do { \
535*7ecc6a92SDavid van Moolenbroek struct mbuf *__m0; \
536*7ecc6a92SDavid van Moolenbroek \
537*7ecc6a92SDavid van Moolenbroek for (;;) { \
538*7ecc6a92SDavid van Moolenbroek IF_DEQUEUE((ifq), __m0); \
539*7ecc6a92SDavid van Moolenbroek if (__m0 == NULL) \
540*7ecc6a92SDavid van Moolenbroek break; \
541*7ecc6a92SDavid van Moolenbroek else \
542*7ecc6a92SDavid van Moolenbroek m_freem(__m0); \
543*7ecc6a92SDavid van Moolenbroek } \
544*7ecc6a92SDavid van Moolenbroek } while (/*CONSTCOND*/ 0)
545*7ecc6a92SDavid van Moolenbroek #define IF_IS_EMPTY(ifq) ((ifq)->ifq_len == 0)
546*7ecc6a92SDavid van Moolenbroek
547*7ecc6a92SDavid van Moolenbroek #ifndef IFQ_MAXLEN
548*7ecc6a92SDavid van Moolenbroek #define IFQ_MAXLEN 256
549*7ecc6a92SDavid van Moolenbroek #endif
550*7ecc6a92SDavid van Moolenbroek #define IFNET_SLOWHZ 1 /* granularity is 1 second */
551*7ecc6a92SDavid van Moolenbroek
552*7ecc6a92SDavid van Moolenbroek /*
553*7ecc6a92SDavid van Moolenbroek * Structure defining statistics and other data kept regarding an address
554*7ecc6a92SDavid van Moolenbroek * on a network interface.
555*7ecc6a92SDavid van Moolenbroek */
556*7ecc6a92SDavid van Moolenbroek struct ifaddr_data {
557*7ecc6a92SDavid van Moolenbroek int64_t ifad_inbytes;
558*7ecc6a92SDavid van Moolenbroek int64_t ifad_outbytes;
559*7ecc6a92SDavid van Moolenbroek };
560*7ecc6a92SDavid van Moolenbroek
561*7ecc6a92SDavid van Moolenbroek /*
562*7ecc6a92SDavid van Moolenbroek * The ifaddr structure contains information about one address
563*7ecc6a92SDavid van Moolenbroek * of an interface. They are maintained by the different address families,
564*7ecc6a92SDavid van Moolenbroek * are allocated and attached when an address is set, and are linked
565*7ecc6a92SDavid van Moolenbroek * together so all addresses for an interface can be located.
566*7ecc6a92SDavid van Moolenbroek */
567*7ecc6a92SDavid van Moolenbroek struct ifaddr {
568*7ecc6a92SDavid van Moolenbroek struct sockaddr *ifa_addr; /* address of interface */
569*7ecc6a92SDavid van Moolenbroek struct sockaddr *ifa_dstaddr; /* other end of p-to-p link */
570*7ecc6a92SDavid van Moolenbroek #define ifa_broadaddr ifa_dstaddr /* broadcast address interface */
571*7ecc6a92SDavid van Moolenbroek struct sockaddr *ifa_netmask; /* used to determine subnet */
572*7ecc6a92SDavid van Moolenbroek struct ifnet *ifa_ifp; /* back-pointer to interface */
573*7ecc6a92SDavid van Moolenbroek TAILQ_ENTRY(ifaddr) ifa_list; /* list of addresses for interface */
574*7ecc6a92SDavid van Moolenbroek struct ifaddr_data ifa_data; /* statistics on the address */
575*7ecc6a92SDavid van Moolenbroek void (*ifa_rtrequest) /* check or clean routes (+ or -)'d */
576*7ecc6a92SDavid van Moolenbroek (int, struct rtentry *, const struct rt_addrinfo *);
577*7ecc6a92SDavid van Moolenbroek u_int ifa_flags; /* mostly rt_flags for cloning */
578*7ecc6a92SDavid van Moolenbroek int ifa_refcnt; /* count of references */
579*7ecc6a92SDavid van Moolenbroek int ifa_metric; /* cost of going out this interface */
580*7ecc6a92SDavid van Moolenbroek struct ifaddr *(*ifa_getifa)(struct ifaddr *,
581*7ecc6a92SDavid van Moolenbroek const struct sockaddr *);
582*7ecc6a92SDavid van Moolenbroek uint32_t *ifa_seqno;
583*7ecc6a92SDavid van Moolenbroek int16_t ifa_preference; /* preference level for this address */
584*7ecc6a92SDavid van Moolenbroek };
585*7ecc6a92SDavid van Moolenbroek #define IFA_ROUTE RTF_UP /* (0x01) route installed */
586*7ecc6a92SDavid van Moolenbroek
587*7ecc6a92SDavid van Moolenbroek /*
588*7ecc6a92SDavid van Moolenbroek * Message format for use in obtaining information about interfaces from
589*7ecc6a92SDavid van Moolenbroek * sysctl and the routing socket. We need to force 64-bit alignment if we
590*7ecc6a92SDavid van Moolenbroek * aren't using compatiblity definitons.
591*7ecc6a92SDavid van Moolenbroek */
592*7ecc6a92SDavid van Moolenbroek #if !defined(_KERNEL) || !defined(COMPAT_RTSOCK)
593*7ecc6a92SDavid van Moolenbroek #define __align64 __aligned(sizeof(uint64_t))
594*7ecc6a92SDavid van Moolenbroek #else
595*7ecc6a92SDavid van Moolenbroek #define __align64
596*7ecc6a92SDavid van Moolenbroek #endif
597*7ecc6a92SDavid van Moolenbroek struct if_msghdr {
598*7ecc6a92SDavid van Moolenbroek u_short ifm_msglen __align64;
599*7ecc6a92SDavid van Moolenbroek /* to skip over non-understood messages */
600*7ecc6a92SDavid van Moolenbroek u_char ifm_version; /* future binary compatibility */
601*7ecc6a92SDavid van Moolenbroek u_char ifm_type; /* message type */
602*7ecc6a92SDavid van Moolenbroek int ifm_addrs; /* like rtm_addrs */
603*7ecc6a92SDavid van Moolenbroek int ifm_flags; /* value of if_flags */
604*7ecc6a92SDavid van Moolenbroek u_short ifm_index; /* index for associated ifp */
605*7ecc6a92SDavid van Moolenbroek struct if_data ifm_data __align64;
606*7ecc6a92SDavid van Moolenbroek /* statistics and other data about if */
607*7ecc6a92SDavid van Moolenbroek };
608*7ecc6a92SDavid van Moolenbroek
609*7ecc6a92SDavid van Moolenbroek /*
610*7ecc6a92SDavid van Moolenbroek * Message format for use in obtaining information about interface addresses
611*7ecc6a92SDavid van Moolenbroek * from sysctl and the routing socket.
612*7ecc6a92SDavid van Moolenbroek */
613*7ecc6a92SDavid van Moolenbroek struct ifa_msghdr {
614*7ecc6a92SDavid van Moolenbroek u_short ifam_msglen __align64;
615*7ecc6a92SDavid van Moolenbroek /* to skip over non-understood messages */
616*7ecc6a92SDavid van Moolenbroek u_char ifam_version; /* future binary compatibility */
617*7ecc6a92SDavid van Moolenbroek u_char ifam_type; /* message type */
618*7ecc6a92SDavid van Moolenbroek int ifam_addrs; /* like rtm_addrs */
619*7ecc6a92SDavid van Moolenbroek int ifam_flags; /* value of ifa_flags */
620*7ecc6a92SDavid van Moolenbroek int ifam_metric; /* value of ifa_metric */
621*7ecc6a92SDavid van Moolenbroek u_short ifam_index; /* index for associated ifp */
622*7ecc6a92SDavid van Moolenbroek };
623*7ecc6a92SDavid van Moolenbroek
624*7ecc6a92SDavid van Moolenbroek /*
625*7ecc6a92SDavid van Moolenbroek * Message format announcing the arrival or departure of a network interface.
626*7ecc6a92SDavid van Moolenbroek */
627*7ecc6a92SDavid van Moolenbroek struct if_announcemsghdr {
628*7ecc6a92SDavid van Moolenbroek u_short ifan_msglen __align64;
629*7ecc6a92SDavid van Moolenbroek /* to skip over non-understood messages */
630*7ecc6a92SDavid van Moolenbroek u_char ifan_version; /* future binary compatibility */
631*7ecc6a92SDavid van Moolenbroek u_char ifan_type; /* message type */
632*7ecc6a92SDavid van Moolenbroek u_short ifan_index; /* index for associated ifp */
633*7ecc6a92SDavid van Moolenbroek char ifan_name[IFNAMSIZ]; /* if name, e.g. "en0" */
634*7ecc6a92SDavid van Moolenbroek u_short ifan_what; /* what type of announcement */
635*7ecc6a92SDavid van Moolenbroek };
636*7ecc6a92SDavid van Moolenbroek
637*7ecc6a92SDavid van Moolenbroek #define IFAN_ARRIVAL 0 /* interface arrival */
638*7ecc6a92SDavid van Moolenbroek #define IFAN_DEPARTURE 1 /* interface departure */
639*7ecc6a92SDavid van Moolenbroek
640*7ecc6a92SDavid van Moolenbroek #undef __align64
641*7ecc6a92SDavid van Moolenbroek
642*7ecc6a92SDavid van Moolenbroek /*
643*7ecc6a92SDavid van Moolenbroek * Interface request structure used for socket
644*7ecc6a92SDavid van Moolenbroek * ioctl's. All interface ioctl's must have parameter
645*7ecc6a92SDavid van Moolenbroek * definitions which begin with ifr_name. The
646*7ecc6a92SDavid van Moolenbroek * remainder may be interface specific.
647*7ecc6a92SDavid van Moolenbroek */
648*7ecc6a92SDavid van Moolenbroek struct ifreq {
649*7ecc6a92SDavid van Moolenbroek char ifr_name[IFNAMSIZ]; /* if name, e.g. "en0" */
650*7ecc6a92SDavid van Moolenbroek union {
651*7ecc6a92SDavid van Moolenbroek struct sockaddr ifru_addr;
652*7ecc6a92SDavid van Moolenbroek struct sockaddr ifru_dstaddr;
653*7ecc6a92SDavid van Moolenbroek struct sockaddr ifru_broadaddr;
654*7ecc6a92SDavid van Moolenbroek struct sockaddr_storage ifru_space;
655*7ecc6a92SDavid van Moolenbroek short ifru_flags;
656*7ecc6a92SDavid van Moolenbroek int ifru_addrflags;
657*7ecc6a92SDavid van Moolenbroek int ifru_metric;
658*7ecc6a92SDavid van Moolenbroek int ifru_mtu;
659*7ecc6a92SDavid van Moolenbroek int ifru_dlt;
660*7ecc6a92SDavid van Moolenbroek u_int ifru_value;
661*7ecc6a92SDavid van Moolenbroek void * ifru_data;
662*7ecc6a92SDavid van Moolenbroek struct {
663*7ecc6a92SDavid van Moolenbroek uint32_t b_buflen;
664*7ecc6a92SDavid van Moolenbroek void *b_buf;
665*7ecc6a92SDavid van Moolenbroek } ifru_b;
666*7ecc6a92SDavid van Moolenbroek } ifr_ifru;
667*7ecc6a92SDavid van Moolenbroek #define ifr_addr ifr_ifru.ifru_addr /* address */
668*7ecc6a92SDavid van Moolenbroek #define ifr_dstaddr ifr_ifru.ifru_dstaddr /* other end of p-to-p link */
669*7ecc6a92SDavid van Moolenbroek #define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */
670*7ecc6a92SDavid van Moolenbroek #define ifr_space ifr_ifru.ifru_space /* sockaddr_storage */
671*7ecc6a92SDavid van Moolenbroek #define ifr_flags ifr_ifru.ifru_flags /* flags */
672*7ecc6a92SDavid van Moolenbroek #define ifr_addrflags ifr_ifru.ifru_addrflags /* addr flags */
673*7ecc6a92SDavid van Moolenbroek #define ifr_metric ifr_ifru.ifru_metric /* metric */
674*7ecc6a92SDavid van Moolenbroek #define ifr_mtu ifr_ifru.ifru_mtu /* mtu */
675*7ecc6a92SDavid van Moolenbroek #define ifr_dlt ifr_ifru.ifru_dlt /* data link type (DLT_*) */
676*7ecc6a92SDavid van Moolenbroek #define ifr_value ifr_ifru.ifru_value /* generic value */
677*7ecc6a92SDavid van Moolenbroek #define ifr_media ifr_ifru.ifru_metric /* media options (overload) */
678*7ecc6a92SDavid van Moolenbroek #define ifr_data ifr_ifru.ifru_data /* for use by interface
679*7ecc6a92SDavid van Moolenbroek * XXX deprecated
680*7ecc6a92SDavid van Moolenbroek */
681*7ecc6a92SDavid van Moolenbroek #define ifr_buf ifr_ifru.ifru_b.b_buf /* new interface ioctls */
682*7ecc6a92SDavid van Moolenbroek #define ifr_buflen ifr_ifru.ifru_b.b_buflen
683*7ecc6a92SDavid van Moolenbroek #define ifr_index ifr_ifru.ifru_value /* interface index, BSD */
684*7ecc6a92SDavid van Moolenbroek #define ifr_ifindex ifr_index /* interface index, linux */
685*7ecc6a92SDavid van Moolenbroek };
686*7ecc6a92SDavid van Moolenbroek
687*7ecc6a92SDavid van Moolenbroek #ifdef _KERNEL
688*7ecc6a92SDavid van Moolenbroek #define ifreq_setdstaddr ifreq_setaddr
689*7ecc6a92SDavid van Moolenbroek #define ifreq_setbroadaddr ifreq_setaddr
690*7ecc6a92SDavid van Moolenbroek #define ifreq_getdstaddr ifreq_getaddr
691*7ecc6a92SDavid van Moolenbroek #define ifreq_getbroadaddr ifreq_getaddr
692*7ecc6a92SDavid van Moolenbroek
693*7ecc6a92SDavid van Moolenbroek static inline const struct sockaddr *
694*7ecc6a92SDavid van Moolenbroek /*ARGSUSED*/
ifreq_getaddr(u_long cmd,const struct ifreq * ifr)695*7ecc6a92SDavid van Moolenbroek ifreq_getaddr(u_long cmd, const struct ifreq *ifr)
696*7ecc6a92SDavid van Moolenbroek {
697*7ecc6a92SDavid van Moolenbroek return &ifr->ifr_addr;
698*7ecc6a92SDavid van Moolenbroek }
699*7ecc6a92SDavid van Moolenbroek #endif /* _KERNEL */
700*7ecc6a92SDavid van Moolenbroek
701*7ecc6a92SDavid van Moolenbroek struct ifcapreq {
702*7ecc6a92SDavid van Moolenbroek char ifcr_name[IFNAMSIZ]; /* if name, e.g. "en0" */
703*7ecc6a92SDavid van Moolenbroek uint64_t ifcr_capabilities; /* supported capabiliites */
704*7ecc6a92SDavid van Moolenbroek uint64_t ifcr_capenable; /* capabilities enabled */
705*7ecc6a92SDavid van Moolenbroek };
706*7ecc6a92SDavid van Moolenbroek
707*7ecc6a92SDavid van Moolenbroek struct ifaliasreq {
708*7ecc6a92SDavid van Moolenbroek char ifra_name[IFNAMSIZ]; /* if name, e.g. "en0" */
709*7ecc6a92SDavid van Moolenbroek struct sockaddr ifra_addr;
710*7ecc6a92SDavid van Moolenbroek struct sockaddr ifra_dstaddr;
711*7ecc6a92SDavid van Moolenbroek #define ifra_broadaddr ifra_dstaddr
712*7ecc6a92SDavid van Moolenbroek struct sockaddr ifra_mask;
713*7ecc6a92SDavid van Moolenbroek };
714*7ecc6a92SDavid van Moolenbroek
715*7ecc6a92SDavid van Moolenbroek struct ifdatareq {
716*7ecc6a92SDavid van Moolenbroek char ifdr_name[IFNAMSIZ]; /* if name, e.g. "en0" */
717*7ecc6a92SDavid van Moolenbroek struct if_data ifdr_data;
718*7ecc6a92SDavid van Moolenbroek };
719*7ecc6a92SDavid van Moolenbroek
720*7ecc6a92SDavid van Moolenbroek struct ifmediareq {
721*7ecc6a92SDavid van Moolenbroek char ifm_name[IFNAMSIZ]; /* if name, e.g. "en0" */
722*7ecc6a92SDavid van Moolenbroek int ifm_current; /* current media options */
723*7ecc6a92SDavid van Moolenbroek int ifm_mask; /* don't care mask */
724*7ecc6a92SDavid van Moolenbroek int ifm_status; /* media status */
725*7ecc6a92SDavid van Moolenbroek int ifm_active; /* active options */
726*7ecc6a92SDavid van Moolenbroek int ifm_count; /* # entries in ifm_ulist
727*7ecc6a92SDavid van Moolenbroek array */
728*7ecc6a92SDavid van Moolenbroek int *ifm_ulist; /* media words */
729*7ecc6a92SDavid van Moolenbroek };
730*7ecc6a92SDavid van Moolenbroek
731*7ecc6a92SDavid van Moolenbroek
732*7ecc6a92SDavid van Moolenbroek struct ifdrv {
733*7ecc6a92SDavid van Moolenbroek char ifd_name[IFNAMSIZ]; /* if name, e.g. "en0" */
734*7ecc6a92SDavid van Moolenbroek unsigned long ifd_cmd;
735*7ecc6a92SDavid van Moolenbroek size_t ifd_len;
736*7ecc6a92SDavid van Moolenbroek void *ifd_data;
737*7ecc6a92SDavid van Moolenbroek };
738*7ecc6a92SDavid van Moolenbroek #define IFLINKSTR_QUERYLEN 0x01
739*7ecc6a92SDavid van Moolenbroek #define IFLINKSTR_UNSET 0x02
740*7ecc6a92SDavid van Moolenbroek
741*7ecc6a92SDavid van Moolenbroek /*
742*7ecc6a92SDavid van Moolenbroek * Structure used in SIOCGIFCONF request.
743*7ecc6a92SDavid van Moolenbroek * Used to retrieve interface configuration
744*7ecc6a92SDavid van Moolenbroek * for machine (useful for programs which
745*7ecc6a92SDavid van Moolenbroek * must know all networks accessible).
746*7ecc6a92SDavid van Moolenbroek */
747*7ecc6a92SDavid van Moolenbroek struct ifconf {
748*7ecc6a92SDavid van Moolenbroek int ifc_len; /* size of associated buffer */
749*7ecc6a92SDavid van Moolenbroek union {
750*7ecc6a92SDavid van Moolenbroek void * ifcu_buf;
751*7ecc6a92SDavid van Moolenbroek struct ifreq *ifcu_req;
752*7ecc6a92SDavid van Moolenbroek } ifc_ifcu;
753*7ecc6a92SDavid van Moolenbroek #define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */
754*7ecc6a92SDavid van Moolenbroek #define ifc_req ifc_ifcu.ifcu_req /* array of structures returned */
755*7ecc6a92SDavid van Moolenbroek };
756*7ecc6a92SDavid van Moolenbroek
757*7ecc6a92SDavid van Moolenbroek /*
758*7ecc6a92SDavid van Moolenbroek * Structure for SIOC[AGD]LIFADDR
759*7ecc6a92SDavid van Moolenbroek */
760*7ecc6a92SDavid van Moolenbroek struct if_laddrreq {
761*7ecc6a92SDavid van Moolenbroek char iflr_name[IFNAMSIZ];
762*7ecc6a92SDavid van Moolenbroek unsigned int flags;
763*7ecc6a92SDavid van Moolenbroek #define IFLR_PREFIX 0x8000 /* in: prefix given out: kernel fills id */
764*7ecc6a92SDavid van Moolenbroek #define IFLR_ACTIVE 0x4000 /* in/out: link-layer address activation */
765*7ecc6a92SDavid van Moolenbroek #define IFLR_FACTORY 0x2000 /* in/out: factory link-layer address */
766*7ecc6a92SDavid van Moolenbroek unsigned int prefixlen; /* in/out */
767*7ecc6a92SDavid van Moolenbroek struct sockaddr_storage addr; /* in/out */
768*7ecc6a92SDavid van Moolenbroek struct sockaddr_storage dstaddr; /* out */
769*7ecc6a92SDavid van Moolenbroek };
770*7ecc6a92SDavid van Moolenbroek
771*7ecc6a92SDavid van Moolenbroek /*
772*7ecc6a92SDavid van Moolenbroek * Structure for SIOC[SG]IFADDRPREF
773*7ecc6a92SDavid van Moolenbroek */
774*7ecc6a92SDavid van Moolenbroek struct if_addrprefreq {
775*7ecc6a92SDavid van Moolenbroek char ifap_name[IFNAMSIZ];
776*7ecc6a92SDavid van Moolenbroek int16_t ifap_preference; /* in/out */
777*7ecc6a92SDavid van Moolenbroek struct sockaddr_storage ifap_addr; /* in/out */
778*7ecc6a92SDavid van Moolenbroek };
779*7ecc6a92SDavid van Moolenbroek
780*7ecc6a92SDavid van Moolenbroek #include <net/if_arp.h>
781*7ecc6a92SDavid van Moolenbroek
782*7ecc6a92SDavid van Moolenbroek #endif /* _NETBSD_SOURCE */
783*7ecc6a92SDavid van Moolenbroek
784*7ecc6a92SDavid van Moolenbroek #ifdef _KERNEL
785*7ecc6a92SDavid van Moolenbroek #ifdef ALTQ
786*7ecc6a92SDavid van Moolenbroek #define ALTQ_DECL(x) x
787*7ecc6a92SDavid van Moolenbroek #define ALTQ_COMMA ,
788*7ecc6a92SDavid van Moolenbroek
789*7ecc6a92SDavid van Moolenbroek #define IFQ_ENQUEUE(ifq, m, pattr, err) \
790*7ecc6a92SDavid van Moolenbroek do { \
791*7ecc6a92SDavid van Moolenbroek IFQ_LOCK((ifq)); \
792*7ecc6a92SDavid van Moolenbroek if (ALTQ_IS_ENABLED((ifq))) \
793*7ecc6a92SDavid van Moolenbroek ALTQ_ENQUEUE((ifq), (m), (pattr), (err)); \
794*7ecc6a92SDavid van Moolenbroek else { \
795*7ecc6a92SDavid van Moolenbroek if (IF_QFULL((ifq))) { \
796*7ecc6a92SDavid van Moolenbroek m_freem((m)); \
797*7ecc6a92SDavid van Moolenbroek (err) = ENOBUFS; \
798*7ecc6a92SDavid van Moolenbroek } else { \
799*7ecc6a92SDavid van Moolenbroek IF_ENQUEUE((ifq), (m)); \
800*7ecc6a92SDavid van Moolenbroek (err) = 0; \
801*7ecc6a92SDavid van Moolenbroek } \
802*7ecc6a92SDavid van Moolenbroek } \
803*7ecc6a92SDavid van Moolenbroek if ((err)) \
804*7ecc6a92SDavid van Moolenbroek (ifq)->ifq_drops++; \
805*7ecc6a92SDavid van Moolenbroek IFQ_UNLOCK((ifq)); \
806*7ecc6a92SDavid van Moolenbroek } while (/*CONSTCOND*/ 0)
807*7ecc6a92SDavid van Moolenbroek
808*7ecc6a92SDavid van Moolenbroek #define IFQ_DEQUEUE(ifq, m) \
809*7ecc6a92SDavid van Moolenbroek do { \
810*7ecc6a92SDavid van Moolenbroek IFQ_LOCK((ifq)); \
811*7ecc6a92SDavid van Moolenbroek if (TBR_IS_ENABLED((ifq))) \
812*7ecc6a92SDavid van Moolenbroek (m) = tbr_dequeue((ifq), ALTDQ_REMOVE); \
813*7ecc6a92SDavid van Moolenbroek else if (ALTQ_IS_ENABLED((ifq))) \
814*7ecc6a92SDavid van Moolenbroek ALTQ_DEQUEUE((ifq), (m)); \
815*7ecc6a92SDavid van Moolenbroek else \
816*7ecc6a92SDavid van Moolenbroek IF_DEQUEUE((ifq), (m)); \
817*7ecc6a92SDavid van Moolenbroek IFQ_UNLOCK((ifq)); \
818*7ecc6a92SDavid van Moolenbroek } while (/*CONSTCOND*/ 0)
819*7ecc6a92SDavid van Moolenbroek
820*7ecc6a92SDavid van Moolenbroek #define IFQ_POLL(ifq, m) \
821*7ecc6a92SDavid van Moolenbroek do { \
822*7ecc6a92SDavid van Moolenbroek IFQ_LOCK((ifq)); \
823*7ecc6a92SDavid van Moolenbroek if (TBR_IS_ENABLED((ifq))) \
824*7ecc6a92SDavid van Moolenbroek (m) = tbr_dequeue((ifq), ALTDQ_POLL); \
825*7ecc6a92SDavid van Moolenbroek else if (ALTQ_IS_ENABLED((ifq))) \
826*7ecc6a92SDavid van Moolenbroek ALTQ_POLL((ifq), (m)); \
827*7ecc6a92SDavid van Moolenbroek else \
828*7ecc6a92SDavid van Moolenbroek IF_POLL((ifq), (m)); \
829*7ecc6a92SDavid van Moolenbroek IFQ_UNLOCK((ifq)); \
830*7ecc6a92SDavid van Moolenbroek } while (/*CONSTCOND*/ 0)
831*7ecc6a92SDavid van Moolenbroek
832*7ecc6a92SDavid van Moolenbroek #define IFQ_PURGE(ifq) \
833*7ecc6a92SDavid van Moolenbroek do { \
834*7ecc6a92SDavid van Moolenbroek IFQ_LOCK((ifq)); \
835*7ecc6a92SDavid van Moolenbroek if (ALTQ_IS_ENABLED((ifq))) \
836*7ecc6a92SDavid van Moolenbroek ALTQ_PURGE((ifq)); \
837*7ecc6a92SDavid van Moolenbroek else \
838*7ecc6a92SDavid van Moolenbroek IF_PURGE((ifq)); \
839*7ecc6a92SDavid van Moolenbroek IFQ_UNLOCK((ifq)); \
840*7ecc6a92SDavid van Moolenbroek } while (/*CONSTCOND*/ 0)
841*7ecc6a92SDavid van Moolenbroek
842*7ecc6a92SDavid van Moolenbroek #define IFQ_SET_READY(ifq) \
843*7ecc6a92SDavid van Moolenbroek do { \
844*7ecc6a92SDavid van Moolenbroek (ifq)->altq_flags |= ALTQF_READY; \
845*7ecc6a92SDavid van Moolenbroek } while (/*CONSTCOND*/ 0)
846*7ecc6a92SDavid van Moolenbroek
847*7ecc6a92SDavid van Moolenbroek #define IFQ_CLASSIFY(ifq, m, af, pattr) \
848*7ecc6a92SDavid van Moolenbroek do { \
849*7ecc6a92SDavid van Moolenbroek IFQ_LOCK((ifq)); \
850*7ecc6a92SDavid van Moolenbroek if (ALTQ_IS_ENABLED((ifq))) { \
851*7ecc6a92SDavid van Moolenbroek if (ALTQ_NEEDS_CLASSIFY((ifq))) \
852*7ecc6a92SDavid van Moolenbroek (pattr)->pattr_class = (*(ifq)->altq_classify) \
853*7ecc6a92SDavid van Moolenbroek ((ifq)->altq_clfier, (m), (af)); \
854*7ecc6a92SDavid van Moolenbroek (pattr)->pattr_af = (af); \
855*7ecc6a92SDavid van Moolenbroek (pattr)->pattr_hdr = mtod((m), void *); \
856*7ecc6a92SDavid van Moolenbroek } \
857*7ecc6a92SDavid van Moolenbroek IFQ_UNLOCK((ifq)); \
858*7ecc6a92SDavid van Moolenbroek } while (/*CONSTCOND*/ 0)
859*7ecc6a92SDavid van Moolenbroek #else /* ! ALTQ */
860*7ecc6a92SDavid van Moolenbroek #define ALTQ_DECL(x) /* nothing */
861*7ecc6a92SDavid van Moolenbroek #define ALTQ_COMMA
862*7ecc6a92SDavid van Moolenbroek
863*7ecc6a92SDavid van Moolenbroek #define IFQ_ENQUEUE(ifq, m, pattr, err) \
864*7ecc6a92SDavid van Moolenbroek do { \
865*7ecc6a92SDavid van Moolenbroek IFQ_LOCK((ifq)); \
866*7ecc6a92SDavid van Moolenbroek if (IF_QFULL((ifq))) { \
867*7ecc6a92SDavid van Moolenbroek m_freem((m)); \
868*7ecc6a92SDavid van Moolenbroek (err) = ENOBUFS; \
869*7ecc6a92SDavid van Moolenbroek } else { \
870*7ecc6a92SDavid van Moolenbroek IF_ENQUEUE((ifq), (m)); \
871*7ecc6a92SDavid van Moolenbroek (err) = 0; \
872*7ecc6a92SDavid van Moolenbroek } \
873*7ecc6a92SDavid van Moolenbroek if ((err)) \
874*7ecc6a92SDavid van Moolenbroek (ifq)->ifq_drops++; \
875*7ecc6a92SDavid van Moolenbroek IFQ_UNLOCK((ifq)); \
876*7ecc6a92SDavid van Moolenbroek } while (/*CONSTCOND*/ 0)
877*7ecc6a92SDavid van Moolenbroek
878*7ecc6a92SDavid van Moolenbroek #define IFQ_DEQUEUE(ifq, m) \
879*7ecc6a92SDavid van Moolenbroek do { \
880*7ecc6a92SDavid van Moolenbroek IFQ_LOCK((ifq)); \
881*7ecc6a92SDavid van Moolenbroek IF_DEQUEUE((ifq), (m)); \
882*7ecc6a92SDavid van Moolenbroek IFQ_UNLOCK((ifq)); \
883*7ecc6a92SDavid van Moolenbroek } while (/*CONSTCOND*/ 0)
884*7ecc6a92SDavid van Moolenbroek
885*7ecc6a92SDavid van Moolenbroek #define IFQ_POLL(ifq, m) \
886*7ecc6a92SDavid van Moolenbroek do { \
887*7ecc6a92SDavid van Moolenbroek IFQ_LOCK((ifq)); \
888*7ecc6a92SDavid van Moolenbroek IF_POLL((ifq), (m)); \
889*7ecc6a92SDavid van Moolenbroek IFQ_UNLOCK((ifq)); \
890*7ecc6a92SDavid van Moolenbroek } while (/*CONSTCOND*/ 0)
891*7ecc6a92SDavid van Moolenbroek
892*7ecc6a92SDavid van Moolenbroek #define IFQ_PURGE(ifq) \
893*7ecc6a92SDavid van Moolenbroek do { \
894*7ecc6a92SDavid van Moolenbroek IFQ_LOCK((ifq)); \
895*7ecc6a92SDavid van Moolenbroek IF_PURGE((ifq)); \
896*7ecc6a92SDavid van Moolenbroek IFQ_UNLOCK((ifq)); \
897*7ecc6a92SDavid van Moolenbroek } while (/*CONSTCOND*/ 0)
898*7ecc6a92SDavid van Moolenbroek
899*7ecc6a92SDavid van Moolenbroek #define IFQ_SET_READY(ifq) /* nothing */
900*7ecc6a92SDavid van Moolenbroek
901*7ecc6a92SDavid van Moolenbroek #define IFQ_CLASSIFY(ifq, m, af, pattr) /* nothing */
902*7ecc6a92SDavid van Moolenbroek
903*7ecc6a92SDavid van Moolenbroek #endif /* ALTQ */
904*7ecc6a92SDavid van Moolenbroek
905*7ecc6a92SDavid van Moolenbroek #define IFQ_IS_EMPTY(ifq) IF_IS_EMPTY((ifq))
906*7ecc6a92SDavid van Moolenbroek #define IFQ_INC_LEN(ifq) ((ifq)->ifq_len++)
907*7ecc6a92SDavid van Moolenbroek #define IFQ_DEC_LEN(ifq) (--(ifq)->ifq_len)
908*7ecc6a92SDavid van Moolenbroek #define IFQ_INC_DROPS(ifq) ((ifq)->ifq_drops++)
909*7ecc6a92SDavid van Moolenbroek #define IFQ_SET_MAXLEN(ifq, len) ((ifq)->ifq_maxlen = (len))
910*7ecc6a92SDavid van Moolenbroek
911*7ecc6a92SDavid van Moolenbroek #include <sys/mallocvar.h>
912*7ecc6a92SDavid van Moolenbroek MALLOC_DECLARE(M_IFADDR);
913*7ecc6a92SDavid van Moolenbroek MALLOC_DECLARE(M_IFMADDR);
914*7ecc6a92SDavid van Moolenbroek
915*7ecc6a92SDavid van Moolenbroek int ifreq_setaddr(u_long, struct ifreq *, const struct sockaddr *);
916*7ecc6a92SDavid van Moolenbroek
917*7ecc6a92SDavid van Moolenbroek struct ifnet *if_alloc(u_char);
918*7ecc6a92SDavid van Moolenbroek void if_free(struct ifnet *);
919*7ecc6a92SDavid van Moolenbroek void if_initname(struct ifnet *, const char *, int);
920*7ecc6a92SDavid van Moolenbroek struct ifaddr *if_dl_create(const struct ifnet *, const struct sockaddr_dl **);
921*7ecc6a92SDavid van Moolenbroek void if_activate_sadl(struct ifnet *, struct ifaddr *,
922*7ecc6a92SDavid van Moolenbroek const struct sockaddr_dl *);
923*7ecc6a92SDavid van Moolenbroek void if_set_sadl(struct ifnet *, const void *, u_char, bool);
924*7ecc6a92SDavid van Moolenbroek void if_alloc_sadl(struct ifnet *);
925*7ecc6a92SDavid van Moolenbroek void if_initialize(struct ifnet *);
926*7ecc6a92SDavid van Moolenbroek void if_register(struct ifnet *);
927*7ecc6a92SDavid van Moolenbroek void if_attach(struct ifnet *); /* Deprecated. Use if_initialize and if_register */
928*7ecc6a92SDavid van Moolenbroek void if_attachdomain(void);
929*7ecc6a92SDavid van Moolenbroek void if_deactivate(struct ifnet *);
930*7ecc6a92SDavid van Moolenbroek void if_purgeaddrs(struct ifnet *, int, void (*)(struct ifaddr *));
931*7ecc6a92SDavid van Moolenbroek void if_detach(struct ifnet *);
932*7ecc6a92SDavid van Moolenbroek void if_down(struct ifnet *);
933*7ecc6a92SDavid van Moolenbroek void if_link_state_change(struct ifnet *, int);
934*7ecc6a92SDavid van Moolenbroek void if_up(struct ifnet *);
935*7ecc6a92SDavid van Moolenbroek void ifinit(void);
936*7ecc6a92SDavid van Moolenbroek void ifinit1(void);
937*7ecc6a92SDavid van Moolenbroek int ifaddrpref_ioctl(struct socket *, u_long, void *, struct ifnet *);
938*7ecc6a92SDavid van Moolenbroek extern int (*ifioctl)(struct socket *, u_long, void *, struct lwp *);
939*7ecc6a92SDavid van Moolenbroek int ifioctl_common(struct ifnet *, u_long, void *);
940*7ecc6a92SDavid van Moolenbroek int ifpromisc(struct ifnet *, int);
941*7ecc6a92SDavid van Moolenbroek struct ifnet *ifunit(const char *);
942*7ecc6a92SDavid van Moolenbroek int if_addr_init(ifnet_t *, struct ifaddr *, bool);
943*7ecc6a92SDavid van Moolenbroek int if_do_dad(struct ifnet *);
944*7ecc6a92SDavid van Moolenbroek int if_mcast_op(ifnet_t *, const unsigned long, const struct sockaddr *);
945*7ecc6a92SDavid van Moolenbroek int if_flags_set(struct ifnet *, const short);
946*7ecc6a92SDavid van Moolenbroek int if_clone_list(int, char *, int *);
947*7ecc6a92SDavid van Moolenbroek
948*7ecc6a92SDavid van Moolenbroek void ifa_insert(struct ifnet *, struct ifaddr *);
949*7ecc6a92SDavid van Moolenbroek void ifa_remove(struct ifnet *, struct ifaddr *);
950*7ecc6a92SDavid van Moolenbroek
951*7ecc6a92SDavid van Moolenbroek void ifaref(struct ifaddr *);
952*7ecc6a92SDavid van Moolenbroek void ifafree(struct ifaddr *);
953*7ecc6a92SDavid van Moolenbroek
954*7ecc6a92SDavid van Moolenbroek struct ifaddr *ifa_ifwithaddr(const struct sockaddr *);
955*7ecc6a92SDavid van Moolenbroek struct ifaddr *ifa_ifwithaf(int);
956*7ecc6a92SDavid van Moolenbroek struct ifaddr *ifa_ifwithdstaddr(const struct sockaddr *);
957*7ecc6a92SDavid van Moolenbroek struct ifaddr *ifa_ifwithnet(const struct sockaddr *);
958*7ecc6a92SDavid van Moolenbroek struct ifaddr *ifa_ifwithladdr(const struct sockaddr *);
959*7ecc6a92SDavid van Moolenbroek struct ifaddr *ifa_ifwithroute(int, const struct sockaddr *,
960*7ecc6a92SDavid van Moolenbroek const struct sockaddr *);
961*7ecc6a92SDavid van Moolenbroek struct ifaddr *ifaof_ifpforaddr(const struct sockaddr *, struct ifnet *);
962*7ecc6a92SDavid van Moolenbroek void ifafree(struct ifaddr *);
963*7ecc6a92SDavid van Moolenbroek void link_rtrequest(int, struct rtentry *, const struct rt_addrinfo *);
964*7ecc6a92SDavid van Moolenbroek void p2p_rtrequest(int, struct rtentry *, const struct rt_addrinfo *);
965*7ecc6a92SDavid van Moolenbroek
966*7ecc6a92SDavid van Moolenbroek void if_clone_attach(struct if_clone *);
967*7ecc6a92SDavid van Moolenbroek void if_clone_detach(struct if_clone *);
968*7ecc6a92SDavid van Moolenbroek
969*7ecc6a92SDavid van Moolenbroek int ifq_enqueue(struct ifnet *, struct mbuf * ALTQ_COMMA
970*7ecc6a92SDavid van Moolenbroek ALTQ_DECL(struct altq_pktattr *));
971*7ecc6a92SDavid van Moolenbroek int ifq_enqueue2(struct ifnet *, struct ifqueue *, struct mbuf * ALTQ_COMMA
972*7ecc6a92SDavid van Moolenbroek ALTQ_DECL(struct altq_pktattr *));
973*7ecc6a92SDavid van Moolenbroek
974*7ecc6a92SDavid van Moolenbroek int loioctl(struct ifnet *, u_long, void *);
975*7ecc6a92SDavid van Moolenbroek void loopattach(int);
976*7ecc6a92SDavid van Moolenbroek int looutput(struct ifnet *,
977*7ecc6a92SDavid van Moolenbroek struct mbuf *, const struct sockaddr *, struct rtentry *);
978*7ecc6a92SDavid van Moolenbroek void lortrequest(int, struct rtentry *, const struct rt_addrinfo *);
979*7ecc6a92SDavid van Moolenbroek
980*7ecc6a92SDavid van Moolenbroek /*
981*7ecc6a92SDavid van Moolenbroek * These are exported because they're an easy way to tell if
982*7ecc6a92SDavid van Moolenbroek * an interface is going away without having to burn a flag.
983*7ecc6a92SDavid van Moolenbroek */
984*7ecc6a92SDavid van Moolenbroek int if_nulloutput(struct ifnet *, struct mbuf *,
985*7ecc6a92SDavid van Moolenbroek const struct sockaddr *, struct rtentry *);
986*7ecc6a92SDavid van Moolenbroek void if_nullinput(struct ifnet *, struct mbuf *);
987*7ecc6a92SDavid van Moolenbroek void if_nullstart(struct ifnet *);
988*7ecc6a92SDavid van Moolenbroek int if_nullioctl(struct ifnet *, u_long, void *);
989*7ecc6a92SDavid van Moolenbroek int if_nullinit(struct ifnet *);
990*7ecc6a92SDavid van Moolenbroek void if_nullstop(struct ifnet *, int);
991*7ecc6a92SDavid van Moolenbroek void if_nullslowtimo(struct ifnet *);
992*7ecc6a92SDavid van Moolenbroek #define if_nullwatchdog if_nullslowtimo
993*7ecc6a92SDavid van Moolenbroek void if_nulldrain(struct ifnet *);
994*7ecc6a92SDavid van Moolenbroek #else
995*7ecc6a92SDavid van Moolenbroek struct if_nameindex {
996*7ecc6a92SDavid van Moolenbroek unsigned int if_index; /* 1, 2, ... */
997*7ecc6a92SDavid van Moolenbroek char *if_name; /* null terminated name: "le0", ... */
998*7ecc6a92SDavid van Moolenbroek };
999*7ecc6a92SDavid van Moolenbroek
1000*7ecc6a92SDavid van Moolenbroek #include <sys/cdefs.h>
1001*7ecc6a92SDavid van Moolenbroek __BEGIN_DECLS
1002*7ecc6a92SDavid van Moolenbroek unsigned int if_nametoindex(const char *);
1003*7ecc6a92SDavid van Moolenbroek char * if_indextoname(unsigned int, char *);
1004*7ecc6a92SDavid van Moolenbroek struct if_nameindex * if_nameindex(void);
1005*7ecc6a92SDavid van Moolenbroek void if_freenameindex(struct if_nameindex *);
1006*7ecc6a92SDavid van Moolenbroek __END_DECLS
1007*7ecc6a92SDavid van Moolenbroek #endif /* _KERNEL */ /* XXX really ALTQ? */
1008*7ecc6a92SDavid van Moolenbroek
1009*7ecc6a92SDavid van Moolenbroek #ifdef _KERNEL
1010*7ecc6a92SDavid van Moolenbroek
1011*7ecc6a92SDavid van Moolenbroek #define IFNET_FIRST() TAILQ_FIRST(&ifnet_list)
1012*7ecc6a92SDavid van Moolenbroek #define IFNET_EMPTY() TAILQ_EMPTY(&ifnet_list)
1013*7ecc6a92SDavid van Moolenbroek #define IFNET_NEXT(__ifp) TAILQ_NEXT((__ifp), if_list)
1014*7ecc6a92SDavid van Moolenbroek #define IFNET_FOREACH(__ifp) TAILQ_FOREACH(__ifp, &ifnet_list, if_list)
1015*7ecc6a92SDavid van Moolenbroek #define IFADDR_FIRST(__ifp) TAILQ_FIRST(&(__ifp)->if_addrlist)
1016*7ecc6a92SDavid van Moolenbroek #define IFADDR_NEXT(__ifa) TAILQ_NEXT((__ifa), ifa_list)
1017*7ecc6a92SDavid van Moolenbroek #define IFADDR_FOREACH(__ifa, __ifp) TAILQ_FOREACH(__ifa, \
1018*7ecc6a92SDavid van Moolenbroek &(__ifp)->if_addrlist, ifa_list)
1019*7ecc6a92SDavid van Moolenbroek #define IFADDR_FOREACH_SAFE(__ifa, __ifp, __nifa) \
1020*7ecc6a92SDavid van Moolenbroek TAILQ_FOREACH_SAFE(__ifa, \
1021*7ecc6a92SDavid van Moolenbroek &(__ifp)->if_addrlist, ifa_list, __nifa)
1022*7ecc6a92SDavid van Moolenbroek #define IFADDR_EMPTY(__ifp) TAILQ_EMPTY(&(__ifp)->if_addrlist)
1023*7ecc6a92SDavid van Moolenbroek
1024*7ecc6a92SDavid van Moolenbroek extern struct ifnet_head ifnet_list;
1025*7ecc6a92SDavid van Moolenbroek extern struct ifnet *lo0ifp;
1026*7ecc6a92SDavid van Moolenbroek
1027*7ecc6a92SDavid van Moolenbroek ifnet_t * if_byindex(u_int);
1028*7ecc6a92SDavid van Moolenbroek
1029*7ecc6a92SDavid van Moolenbroek /*
1030*7ecc6a92SDavid van Moolenbroek * ifq sysctl support
1031*7ecc6a92SDavid van Moolenbroek */
1032*7ecc6a92SDavid van Moolenbroek int sysctl_ifq(int *name, u_int namelen, void *oldp,
1033*7ecc6a92SDavid van Moolenbroek size_t *oldlenp, void *newp, size_t newlen,
1034*7ecc6a92SDavid van Moolenbroek struct ifqueue *ifq);
1035*7ecc6a92SDavid van Moolenbroek /* symbolic names for terminal (per-protocol) CTL_IFQ_ nodes */
1036*7ecc6a92SDavid van Moolenbroek #define IFQCTL_LEN 1
1037*7ecc6a92SDavid van Moolenbroek #define IFQCTL_MAXLEN 2
1038*7ecc6a92SDavid van Moolenbroek #define IFQCTL_PEAK 3
1039*7ecc6a92SDavid van Moolenbroek #define IFQCTL_DROPS 4
1040*7ecc6a92SDavid van Moolenbroek #define IFQCTL_MAXID 5
1041*7ecc6a92SDavid van Moolenbroek
1042*7ecc6a92SDavid van Moolenbroek #endif /* _KERNEL */
1043*7ecc6a92SDavid van Moolenbroek
1044*7ecc6a92SDavid van Moolenbroek #ifdef _NETBSD_SOURCE
1045*7ecc6a92SDavid van Moolenbroek /*
1046*7ecc6a92SDavid van Moolenbroek * sysctl for ifq (per-protocol packet input queue variant of ifqueue)
1047*7ecc6a92SDavid van Moolenbroek */
1048*7ecc6a92SDavid van Moolenbroek #define CTL_IFQ_NAMES { \
1049*7ecc6a92SDavid van Moolenbroek { 0, 0 }, \
1050*7ecc6a92SDavid van Moolenbroek { "len", CTLTYPE_INT }, \
1051*7ecc6a92SDavid van Moolenbroek { "maxlen", CTLTYPE_INT }, \
1052*7ecc6a92SDavid van Moolenbroek { "peak", CTLTYPE_INT }, \
1053*7ecc6a92SDavid van Moolenbroek { "drops", CTLTYPE_INT }, \
1054*7ecc6a92SDavid van Moolenbroek }
1055*7ecc6a92SDavid van Moolenbroek #endif /* _NETBSD_SOURCE */
1056*7ecc6a92SDavid van Moolenbroek #endif /* !_NET_IF_H_ */
1057