xref: /freebsd/sys/net/if_var.h (revision 29363fb4)
1c398230bSWarner Losh /*-
251369649SPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
351369649SPedro F. Giffuni  *
419ff91c6SGarrett Wollman  * Copyright (c) 1982, 1986, 1989, 1993
519ff91c6SGarrett Wollman  *	The Regents of the University of California.  All rights reserved.
619ff91c6SGarrett Wollman  *
719ff91c6SGarrett Wollman  * Redistribution and use in source and binary forms, with or without
819ff91c6SGarrett Wollman  * modification, are permitted provided that the following conditions
919ff91c6SGarrett Wollman  * are met:
1019ff91c6SGarrett Wollman  * 1. Redistributions of source code must retain the above copyright
1119ff91c6SGarrett Wollman  *    notice, this list of conditions and the following disclaimer.
1219ff91c6SGarrett Wollman  * 2. Redistributions in binary form must reproduce the above copyright
1319ff91c6SGarrett Wollman  *    notice, this list of conditions and the following disclaimer in the
1419ff91c6SGarrett Wollman  *    documentation and/or other materials provided with the distribution.
15fbbd9655SWarner Losh  * 3. Neither the name of the University nor the names of its contributors
1619ff91c6SGarrett Wollman  *    may be used to endorse or promote products derived from this software
1719ff91c6SGarrett Wollman  *    without specific prior written permission.
1819ff91c6SGarrett Wollman  *
1919ff91c6SGarrett Wollman  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2019ff91c6SGarrett Wollman  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2119ff91c6SGarrett Wollman  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2219ff91c6SGarrett Wollman  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2319ff91c6SGarrett Wollman  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2419ff91c6SGarrett Wollman  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2519ff91c6SGarrett Wollman  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2619ff91c6SGarrett Wollman  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2719ff91c6SGarrett Wollman  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2819ff91c6SGarrett Wollman  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2919ff91c6SGarrett Wollman  * SUCH DAMAGE.
3019ff91c6SGarrett Wollman  */
3119ff91c6SGarrett Wollman 
3219ff91c6SGarrett Wollman #ifndef	_NET_IF_VAR_H_
3319ff91c6SGarrett Wollman #define	_NET_IF_VAR_H_
3419ff91c6SGarrett Wollman 
3519ff91c6SGarrett Wollman /*
3619ff91c6SGarrett Wollman  * Structures defining a network interface, providing a packet
3719ff91c6SGarrett Wollman  * transport mechanism (ala level 0 of the PUP protocols).
3819ff91c6SGarrett Wollman  *
3919ff91c6SGarrett Wollman  * Each interface accepts output datagrams of a specified maximum
4019ff91c6SGarrett Wollman  * length, and provides higher level routines with input datagrams
4119ff91c6SGarrett Wollman  * received from its medium.
4219ff91c6SGarrett Wollman  *
4319ff91c6SGarrett Wollman  * Output occurs when the routine if_output is called, with three parameters:
4467452942SAlexander V. Chernikov  *	(*ifp->if_output)(ifp, m, dst, ro)
4519ff91c6SGarrett Wollman  * Here m is the mbuf chain to be sent and dst is the destination address.
4619ff91c6SGarrett Wollman  * The output routine encapsulates the supplied datagram if necessary,
4719ff91c6SGarrett Wollman  * and then transmits it on its medium.
4819ff91c6SGarrett Wollman  *
4919ff91c6SGarrett Wollman  * On input, each interface unwraps the data received by it, and either
509d5abbddSJens Schweikhardt  * places it on the input queue of an internetwork datagram routine
5119ff91c6SGarrett Wollman  * and posts the associated software interrupt, or passes the datagram to a raw
5219ff91c6SGarrett Wollman  * packet input routine.
5319ff91c6SGarrett Wollman  *
5419ff91c6SGarrett Wollman  * Routines exist for locating interfaces by their addresses
559d5abbddSJens Schweikhardt  * or for locating an interface on a certain network, as well as more general
5619ff91c6SGarrett Wollman  * routing and gateway routines maintaining information used to locate
5719ff91c6SGarrett Wollman  * interfaces.  These routines live in the files if.c and route.c
5819ff91c6SGarrett Wollman  */
5919ff91c6SGarrett Wollman 
60c29e1ad9SGleb Smirnoff struct	rtentry;		/* ifa_rtrequest */
6119ff91c6SGarrett Wollman struct	socket;
62a9771948SGleb Smirnoff struct	carp_if;
6308b68b0eSGleb Smirnoff struct	carp_softc;
6475ee267cSGleb Smirnoff struct  ifvlantrunk;
65c29e1ad9SGleb Smirnoff struct	route;			/* if_output */
66bc29160dSMarko Zec struct	vnet;
6762d76917SMarcel Moolenaar struct	ifmedia;
68997d2d83SGleb Smirnoff struct	netmap_adapter;
697790c8c1SConrad Meyer struct	debugnet_methods;
7019ff91c6SGarrett Wollman 
719ba20c31SJonathan Lemon #ifdef _KERNEL
72e2e050c8SConrad Meyer #include <sys/_eventhandler.h>
73c29e1ad9SGleb Smirnoff #include <sys/mbuf.h>		/* ifqueue only? */
741635d917SKip Macy #include <sys/buf_ring.h>
75eddfbb76SRobert Watson #include <net/vnet.h>
769ba20c31SJonathan Lemon #endif /* _KERNEL */
77fd04260dSMatt Macy #include <sys/ck.h>
787caf4ab7SGleb Smirnoff #include <sys/counter.h>
79fd04260dSMatt Macy #include <sys/epoch.h>
80f34fa851SJohn Baldwin #include <sys/lock.h>		/* XXX */
81c29e1ad9SGleb Smirnoff #include <sys/mutex.h>		/* struct ifqueue */
82991f8615SKip Macy #include <sys/rwlock.h>		/* XXX */
8377dfcdc4SRobert Watson #include <sys/sx.h>		/* XXX */
84c29e1ad9SGleb Smirnoff #include <sys/_task.h>		/* if_link_task */
859bf40edeSBrooks Davis #define	IF_DUNIT_NONE	-1
869bf40edeSBrooks Davis 
87772e66a6SGleb Smirnoff #include <net/altq/if_altq.h>
8802b199f1SMax Laier 
894f6c66ccSMatt Macy CK_STAILQ_HEAD(ifnethead, ifnet);	/* we use TAILQs so that the order of */
90d7c5a620SMatt Macy CK_STAILQ_HEAD(ifaddrhead, ifaddr);	/* instantiation is preserved in the list */
91d7c5a620SMatt Macy CK_STAILQ_HEAD(ifmultihead, ifmultiaddr);
924f6c66ccSMatt Macy CK_STAILQ_HEAD(ifgrouphead, ifg_group);
9319ff91c6SGarrett Wollman 
9473c23f3bSAlexander V. Chernikov #ifdef _KERNEL
95b252313fSGleb Smirnoff VNET_DECLARE(struct pfil_head *, link_pfil_head);
96b252313fSGleb Smirnoff #define	V_link_pfil_head	VNET(link_pfil_head)
97b252313fSGleb Smirnoff #define	PFIL_ETHER_NAME		"ethernet"
98ef91a976SAndrey V. Elsukov 
99ef91a976SAndrey V. Elsukov #define	HHOOK_IPSEC_INET	0
100ef91a976SAndrey V. Elsukov #define	HHOOK_IPSEC_INET6	1
101ef91a976SAndrey V. Elsukov #define	HHOOK_IPSEC_COUNT	2
102ef91a976SAndrey V. Elsukov VNET_DECLARE(struct hhook_head *, ipsec_hhh_in[HHOOK_IPSEC_COUNT]);
103ef91a976SAndrey V. Elsukov VNET_DECLARE(struct hhook_head *, ipsec_hhh_out[HHOOK_IPSEC_COUNT]);
104ef91a976SAndrey V. Elsukov #define	V_ipsec_hhh_in	VNET(ipsec_hhh_in)
105ef91a976SAndrey V. Elsukov #define	V_ipsec_hhh_out	VNET(ipsec_hhh_out)
10673c23f3bSAlexander V. Chernikov #endif /* _KERNEL */
1077d4317bdSAlexander V. Chernikov 
108ae330108SJustin Hibbits typedef enum {
109ae330108SJustin Hibbits 	IFCOUNTER_IPACKETS = 0,
110ae330108SJustin Hibbits 	IFCOUNTER_IERRORS,
111ae330108SJustin Hibbits 	IFCOUNTER_OPACKETS,
112ae330108SJustin Hibbits 	IFCOUNTER_OERRORS,
113ae330108SJustin Hibbits 	IFCOUNTER_COLLISIONS,
114ae330108SJustin Hibbits 	IFCOUNTER_IBYTES,
115ae330108SJustin Hibbits 	IFCOUNTER_OBYTES,
116ae330108SJustin Hibbits 	IFCOUNTER_IMCASTS,
117ae330108SJustin Hibbits 	IFCOUNTER_OMCASTS,
118ae330108SJustin Hibbits 	IFCOUNTER_IQDROPS,
119ae330108SJustin Hibbits 	IFCOUNTER_OQDROPS,
120ae330108SJustin Hibbits 	IFCOUNTER_NOPROTO,
121ae330108SJustin Hibbits 	IFCOUNTERS /* Array size. */
122ae330108SJustin Hibbits } ift_counter;
123ae330108SJustin Hibbits 
124ae330108SJustin Hibbits typedef	void (*if_start_fn_t)(if_t);
125ae330108SJustin Hibbits typedef	int (*if_ioctl_fn_t)(if_t, u_long, caddr_t);
126ae330108SJustin Hibbits typedef	void (*if_init_fn_t)(void *);
127848d5bb1SKonstantin Belousov typedef	void (*if_input_fn_t)(if_t, struct mbuf *);
128848d5bb1SKonstantin Belousov typedef	int (*if_output_fn_t)(if_t, struct mbuf *, const struct sockaddr *,
129848d5bb1SKonstantin Belousov     struct route *);
130ae330108SJustin Hibbits typedef void (*if_qflush_fn_t)(if_t);
131ae330108SJustin Hibbits typedef int (*if_transmit_fn_t)(if_t, struct mbuf *);
132ae330108SJustin Hibbits typedef	uint64_t (*if_get_counter_t)(if_t, ift_counter);
133848d5bb1SKonstantin Belousov typedef	void (*if_reassign_fn_t)(if_t, struct vnet *, char *);
134ae330108SJustin Hibbits 
1359fd573c3SHans Petter Selasky struct ifnet_hw_tsomax {
1369fd573c3SHans Petter Selasky 	u_int	tsomaxbytes;	/* TSO total burst length limit in bytes */
1379fd573c3SHans Petter Selasky 	u_int	tsomaxsegcount;	/* TSO maximum segment count */
1389fd573c3SHans Petter Selasky 	u_int	tsomaxsegsize;	/* TSO maximum segment size in bytes */
1399fd573c3SHans Petter Selasky };
1409fd573c3SHans Petter Selasky 
1414fb3a820SAlexander V. Chernikov /* Interface encap request types */
1424fb3a820SAlexander V. Chernikov typedef enum {
1434fb3a820SAlexander V. Chernikov 	IFENCAP_LL = 1			/* pre-calculate link-layer header */
1444fb3a820SAlexander V. Chernikov } ife_type;
1454fb3a820SAlexander V. Chernikov 
1464fb3a820SAlexander V. Chernikov /*
1474fb3a820SAlexander V. Chernikov  * The structure below allows to request various pre-calculated L2/L3 headers
1484fb3a820SAlexander V. Chernikov  * for different media. Requests varies by type (rtype field).
1494fb3a820SAlexander V. Chernikov  *
1504fb3a820SAlexander V. Chernikov  * IFENCAP_LL type: pre-calculates link header based on address family
1514fb3a820SAlexander V. Chernikov  *   and destination lladdr.
1524fb3a820SAlexander V. Chernikov  *
1534fb3a820SAlexander V. Chernikov  *   Input data fields:
1544fb3a820SAlexander V. Chernikov  *     buf: pointer to destination buffer
1554fb3a820SAlexander V. Chernikov  *     bufsize: buffer size
1564fb3a820SAlexander V. Chernikov  *     flags: IFENCAP_FLAG_BROADCAST if destination is broadcast
1574fb3a820SAlexander V. Chernikov  *     family: address family defined by AF_ constant.
1584fb3a820SAlexander V. Chernikov  *     lladdr: pointer to link-layer address
1594fb3a820SAlexander V. Chernikov  *     lladdr_len: length of link-layer address
1604fb3a820SAlexander V. Chernikov  *     hdata: pointer to L3 header (optional, used for ARP requests).
1614fb3a820SAlexander V. Chernikov  *   Output data fields:
1624fb3a820SAlexander V. Chernikov  *     buf: encap data is stored here
1634fb3a820SAlexander V. Chernikov  *     bufsize: resulting encap length is stored here
1644fb3a820SAlexander V. Chernikov  *     lladdr_off: offset of link-layer address from encap hdr start
1654fb3a820SAlexander V. Chernikov  *     hdata: L3 header may be altered if necessary
1664fb3a820SAlexander V. Chernikov  */
1674fb3a820SAlexander V. Chernikov 
1684fb3a820SAlexander V. Chernikov struct if_encap_req {
1694fb3a820SAlexander V. Chernikov 	u_char		*buf;		/* Destination buffer (w) */
1704fb3a820SAlexander V. Chernikov 	size_t		bufsize;	/* size of provided buffer (r) */
1714fb3a820SAlexander V. Chernikov 	ife_type	rtype;		/* request type (r) */
1724fb3a820SAlexander V. Chernikov 	uint32_t	flags;		/* Request flags (r) */
1734fb3a820SAlexander V. Chernikov 	int		family;		/* Address family AF_* (r) */
1744fb3a820SAlexander V. Chernikov 	int		lladdr_off;	/* offset from header start (w) */
1754fb3a820SAlexander V. Chernikov 	int		lladdr_len;	/* lladdr length (r) */
1764fb3a820SAlexander V. Chernikov 	char		*lladdr;	/* link-level address pointer (r) */
1774fb3a820SAlexander V. Chernikov 	char		*hdata;		/* Upper layer header data (rw) */
1784fb3a820SAlexander V. Chernikov };
1794fb3a820SAlexander V. Chernikov 
1804fb3a820SAlexander V. Chernikov #define	IFENCAP_FLAG_BROADCAST	0x02	/* Destination is broadcast */
1814fb3a820SAlexander V. Chernikov 
182f3e7afe2SHans Petter Selasky /*
183f3e7afe2SHans Petter Selasky  * Network interface send tag support. The storage of "struct
184f3e7afe2SHans Petter Selasky  * m_snd_tag" comes from the network driver and it is free to allocate
185f3e7afe2SHans Petter Selasky  * as much additional space as it wants for its own use.
186f3e7afe2SHans Petter Selasky  */
187b2e60773SJohn Baldwin struct ktls_session;
188f3e7afe2SHans Petter Selasky struct m_snd_tag;
189f3e7afe2SHans Petter Selasky 
190f3e7afe2SHans Petter Selasky #define	IF_SND_TAG_TYPE_RATE_LIMIT 0
19195ed5015SHans Petter Selasky #define	IF_SND_TAG_TYPE_UNLIMITED 1
192b2e60773SJohn Baldwin #define	IF_SND_TAG_TYPE_TLS 2
193521eac97SJohn Baldwin #define	IF_SND_TAG_TYPE_TLS_RATE_LIMIT 3
194c8f2c290SHans Petter Selasky #define	IF_SND_TAG_TYPE_TLS_RX 4
195c8f2c290SHans Petter Selasky #define	IF_SND_TAG_TYPE_MAX 5
196f3e7afe2SHans Petter Selasky 
197f3e7afe2SHans Petter Selasky struct if_snd_tag_alloc_header {
198f3e7afe2SHans Petter Selasky 	uint32_t type;		/* send tag type, see IF_SND_TAG_XXX */
199f3e7afe2SHans Petter Selasky 	uint32_t flowid;	/* mbuf hash value */
200f3e7afe2SHans Petter Selasky 	uint32_t flowtype;	/* mbuf hash type */
20198085baeSAndrew Gallatin 	uint8_t numa_domain;	/* numa domain of associated inp */
202f3e7afe2SHans Petter Selasky };
203f3e7afe2SHans Petter Selasky 
204f3e7afe2SHans Petter Selasky struct if_snd_tag_alloc_rate_limit {
205f3e7afe2SHans Petter Selasky 	struct if_snd_tag_alloc_header hdr;
206f3e7afe2SHans Petter Selasky 	uint64_t max_rate;	/* in bytes/s */
20720abea66SRandall Stewart 	uint32_t flags;		/* M_NOWAIT or M_WAITOK */
20820abea66SRandall Stewart 	uint32_t reserved;	/* alignment */
209f3e7afe2SHans Petter Selasky };
210f3e7afe2SHans Petter Selasky 
211b2e60773SJohn Baldwin struct if_snd_tag_alloc_tls {
212b2e60773SJohn Baldwin 	struct if_snd_tag_alloc_header hdr;
213b2e60773SJohn Baldwin 	struct inpcb *inp;
214b2e60773SJohn Baldwin 	const struct ktls_session *tls;
215b2e60773SJohn Baldwin };
216b2e60773SJohn Baldwin 
217c8f2c290SHans Petter Selasky struct if_snd_tag_alloc_tls_rx {
218c8f2c290SHans Petter Selasky 	struct if_snd_tag_alloc_header hdr;
219c8f2c290SHans Petter Selasky 	struct inpcb *inp;
220c8f2c290SHans Petter Selasky 	const struct ktls_session *tls;
221c8f2c290SHans Petter Selasky 	uint16_t vlan_id;	/* valid if non-zero */
222c8f2c290SHans Petter Selasky };
223c8f2c290SHans Petter Selasky 
224521eac97SJohn Baldwin struct if_snd_tag_alloc_tls_rate_limit {
225521eac97SJohn Baldwin 	struct if_snd_tag_alloc_header hdr;
226521eac97SJohn Baldwin 	struct inpcb *inp;
227521eac97SJohn Baldwin 	const struct ktls_session *tls;
228521eac97SJohn Baldwin 	uint64_t max_rate;	/* in bytes/s */
229521eac97SJohn Baldwin };
230521eac97SJohn Baldwin 
231f3e7afe2SHans Petter Selasky struct if_snd_tag_rate_limit_params {
232f3e7afe2SHans Petter Selasky 	uint64_t max_rate;	/* in bytes/s */
23395ed5015SHans Petter Selasky 	uint32_t queue_level;	/* 0 (empty) .. 65535 (full) */
23495ed5015SHans Petter Selasky #define	IF_SND_QUEUE_LEVEL_MIN 0
23595ed5015SHans Petter Selasky #define	IF_SND_QUEUE_LEVEL_MAX 65535
23620abea66SRandall Stewart 	uint32_t flags;		/* M_NOWAIT or M_WAITOK */
237f3e7afe2SHans Petter Selasky };
238f3e7afe2SHans Petter Selasky 
239c8f2c290SHans Petter Selasky struct if_snd_tag_modify_tls_rx {
240c8f2c290SHans Petter Selasky 	/* TCP sequence number of TLS header in host endian format */
241c8f2c290SHans Petter Selasky 	uint32_t tls_hdr_tcp_sn;
242c8f2c290SHans Petter Selasky 
243c8f2c290SHans Petter Selasky 	/*
244c8f2c290SHans Petter Selasky 	 * TLS record length, including all headers, data and trailers.
245c8f2c290SHans Petter Selasky 	 * If the tls_rec_length is zero, it means HW encryption resumed.
246c8f2c290SHans Petter Selasky 	 */
247c8f2c290SHans Petter Selasky 	uint32_t tls_rec_length;
248c8f2c290SHans Petter Selasky 
249c8f2c290SHans Petter Selasky 	/* TLS sequence number in host endian format */
250c8f2c290SHans Petter Selasky 	uint64_t tls_seq_number;
251c8f2c290SHans Petter Selasky };
252c8f2c290SHans Petter Selasky 
253f3e7afe2SHans Petter Selasky union if_snd_tag_alloc_params {
254f3e7afe2SHans Petter Selasky 	struct if_snd_tag_alloc_header hdr;
255f3e7afe2SHans Petter Selasky 	struct if_snd_tag_alloc_rate_limit rate_limit;
25695ed5015SHans Petter Selasky 	struct if_snd_tag_alloc_rate_limit unlimited;
257b2e60773SJohn Baldwin 	struct if_snd_tag_alloc_tls tls;
258c8f2c290SHans Petter Selasky 	struct if_snd_tag_alloc_tls_rx tls_rx;
259521eac97SJohn Baldwin 	struct if_snd_tag_alloc_tls_rate_limit tls_rate_limit;
260f3e7afe2SHans Petter Selasky };
261f3e7afe2SHans Petter Selasky 
262f3e7afe2SHans Petter Selasky union if_snd_tag_modify_params {
263f3e7afe2SHans Petter Selasky 	struct if_snd_tag_rate_limit_params rate_limit;
26495ed5015SHans Petter Selasky 	struct if_snd_tag_rate_limit_params unlimited;
265521eac97SJohn Baldwin 	struct if_snd_tag_rate_limit_params tls_rate_limit;
266c8f2c290SHans Petter Selasky 	struct if_snd_tag_modify_tls_rx tls_rx;
267f3e7afe2SHans Petter Selasky };
268f3e7afe2SHans Petter Selasky 
269f3e7afe2SHans Petter Selasky union if_snd_tag_query_params {
270f3e7afe2SHans Petter Selasky 	struct if_snd_tag_rate_limit_params rate_limit;
27195ed5015SHans Petter Selasky 	struct if_snd_tag_rate_limit_params unlimited;
272521eac97SJohn Baldwin 	struct if_snd_tag_rate_limit_params tls_rate_limit;
273f3e7afe2SHans Petter Selasky };
274f3e7afe2SHans Petter Selasky 
275848d5bb1SKonstantin Belousov typedef int (if_snd_tag_alloc_t)(if_t, union if_snd_tag_alloc_params *,
276ae330108SJustin Hibbits     struct m_snd_tag **);
277ae330108SJustin Hibbits typedef int (if_snd_tag_modify_t)(struct m_snd_tag *, union if_snd_tag_modify_params *);
278ae330108SJustin Hibbits typedef int (if_snd_tag_query_t)(struct m_snd_tag *, union if_snd_tag_query_params *);
279ae330108SJustin Hibbits typedef void (if_snd_tag_free_t)(struct m_snd_tag *);
280ae330108SJustin Hibbits typedef struct m_snd_tag *(if_next_send_tag_t)(struct m_snd_tag *);
281ae330108SJustin Hibbits 
282c782ea8bSJohn Baldwin struct if_snd_tag_sw {
283c782ea8bSJohn Baldwin 	if_snd_tag_modify_t *snd_tag_modify;
284c782ea8bSJohn Baldwin 	if_snd_tag_query_t *snd_tag_query;
285c782ea8bSJohn Baldwin 	if_snd_tag_free_t *snd_tag_free;
286c782ea8bSJohn Baldwin 	if_next_send_tag_t *next_snd_tag;
287c782ea8bSJohn Baldwin 	u_int	type;			/* One of IF_SND_TAG_TYPE_*. */
288c782ea8bSJohn Baldwin };
289c782ea8bSJohn Baldwin 
29020abea66SRandall Stewart /* Query return flags */
29120abea66SRandall Stewart #define RT_NOSUPPORT	  0x00000000	/* Not supported */
29220abea66SRandall Stewart #define RT_IS_INDIRECT    0x00000001	/*
29320abea66SRandall Stewart 					 * Interface like a lagg, select
29420abea66SRandall Stewart 					 * the actual interface for
29520abea66SRandall Stewart 					 * capabilities.
29620abea66SRandall Stewart 					 */
29720abea66SRandall Stewart #define RT_IS_SELECTABLE  0x00000002	/*
29820abea66SRandall Stewart 					 * No rate table, you select
29920abea66SRandall Stewart 					 * rates and the first
30020abea66SRandall Stewart 					 * number_of_rates are created.
30120abea66SRandall Stewart 					 */
30220abea66SRandall Stewart #define RT_IS_FIXED_TABLE 0x00000004	/* A fixed table is attached */
30320abea66SRandall Stewart #define RT_IS_UNUSABLE	  0x00000008	/* It is not usable for this */
304d7313dc6SRandall Stewart #define RT_IS_SETUP_REQ	  0x00000010	/* The interface setup must be called before use */
30520abea66SRandall Stewart 
30620abea66SRandall Stewart struct if_ratelimit_query_results {
30720abea66SRandall Stewart 	const uint64_t *rate_table;	/* Pointer to table if present */
30820abea66SRandall Stewart 	uint32_t flags;			/* Flags indicating results */
30920abea66SRandall Stewart 	uint32_t max_flows;		/* Max flows using, 0=unlimited */
31020abea66SRandall Stewart 	uint32_t number_of_rates;	/* How many unique rates can be created */
31120abea66SRandall Stewart 	uint32_t min_segment_burst;	/* The amount the adapter bursts at each send */
31220abea66SRandall Stewart };
31320abea66SRandall Stewart 
314848d5bb1SKonstantin Belousov typedef void (if_ratelimit_query_t)(if_t,
31520abea66SRandall Stewart     struct if_ratelimit_query_results *);
316848d5bb1SKonstantin Belousov typedef int (if_ratelimit_setup_t)(if_t, uint64_t, uint32_t);
3177687707dSAndrew Gallatin #define	IF_NODOM	255
31819ff91c6SGarrett Wollman /*
319de6073aaSRobert Watson  * Locks for address lists on the network interface.
320de6073aaSRobert Watson  */
321d7c5a620SMatt Macy #define	IF_ADDR_LOCK_INIT(if)	mtx_init(&(if)->if_addr_lock, "if_addr_lock", NULL, MTX_DEF)
322d7c5a620SMatt Macy #define	IF_ADDR_LOCK_DESTROY(if)	mtx_destroy(&(if)->if_addr_lock)
323d7c5a620SMatt Macy 
324d7c5a620SMatt Macy #define	IF_ADDR_WLOCK(if)	mtx_lock(&(if)->if_addr_lock)
325d7c5a620SMatt Macy #define	IF_ADDR_WUNLOCK(if)	mtx_unlock(&(if)->if_addr_lock)
3266573d758SMatt Macy #define	IF_ADDR_LOCK_ASSERT(if)	MPASS(in_epoch(net_epoch_preempt) || mtx_owned(&(if)->if_addr_lock))
327d7c5a620SMatt Macy #define	IF_ADDR_WLOCK_ASSERT(if) mtx_assert(&(if)->if_addr_lock, MA_OWNED)
328de6073aaSRobert Watson 
329664a31e4SPeter Wemm #ifdef _KERNEL
330ea4ca115SAndrew Thompson /* interface link layer address change event */
331848d5bb1SKonstantin Belousov typedef void (*iflladdr_event_handler_t)(void *, if_t);
332ea4ca115SAndrew Thompson EVENTHANDLER_DECLARE(iflladdr_event, iflladdr_event_handler_t);
33325a4adceSMax Laier /* interface address change event */
334848d5bb1SKonstantin Belousov typedef void (*ifaddr_event_handler_t)(void *, if_t);
33525a4adceSMax Laier EVENTHANDLER_DECLARE(ifaddr_event, ifaddr_event_handler_t);
336848d5bb1SKonstantin Belousov typedef void (*ifaddr_event_ext_handler_t)(void *, if_t, struct ifaddr *, int);
33764d63b1eSAndrey V. Elsukov EVENTHANDLER_DECLARE(ifaddr_event_ext, ifaddr_event_ext_handler_t);
33864d63b1eSAndrey V. Elsukov #define	IFADDR_EVENT_ADD	0
33964d63b1eSAndrey V. Elsukov #define	IFADDR_EVENT_DEL	1
34025a4adceSMax Laier /* new interface arrival event */
341848d5bb1SKonstantin Belousov typedef void (*ifnet_arrival_event_handler_t)(void *, if_t);
34225a4adceSMax Laier EVENTHANDLER_DECLARE(ifnet_arrival_event, ifnet_arrival_event_handler_t);
34325a4adceSMax Laier /* interface departure event */
344848d5bb1SKonstantin Belousov typedef void (*ifnet_departure_event_handler_t)(void *, if_t);
34525a4adceSMax Laier EVENTHANDLER_DECLARE(ifnet_departure_event, ifnet_departure_event_handler_t);
346e4cd31ddSJeff Roberson /* Interface link state change event */
347848d5bb1SKonstantin Belousov typedef void (*ifnet_link_event_handler_t)(void *, if_t, int);
348e4cd31ddSJeff Roberson EVENTHANDLER_DECLARE(ifnet_link_event, ifnet_link_event_handler_t);
3496597559eSDexuan Cui /* Interface up/down event */
3506597559eSDexuan Cui #define IFNET_EVENT_UP		0
3516597559eSDexuan Cui #define IFNET_EVENT_DOWN	1
3524a381a9eSHans Petter Selasky #define IFNET_EVENT_PCP		2	/* priority code point, PCP */
353f2ab9160SAndrey V. Elsukov #define	IFNET_EVENT_UPDATE_BAUDRATE	3
3544a381a9eSHans Petter Selasky 
355848d5bb1SKonstantin Belousov typedef void (*ifnet_event_fn)(void *, if_t ifp, int event);
3566597559eSDexuan Cui EVENTHANDLER_DECLARE(ifnet_event, ifnet_event_fn);
35725a4adceSMax Laier 
3580dad3f0eSMax Laier /*
3590dad3f0eSMax Laier  * interface groups
3600dad3f0eSMax Laier  */
3610dad3f0eSMax Laier struct ifg_group {
3620dad3f0eSMax Laier 	char				 ifg_group[IFNAMSIZ];
3630dad3f0eSMax Laier 	u_int				 ifg_refcnt;
3640dad3f0eSMax Laier 	void				*ifg_pf_kif;
3650f8d79d9SMatt Macy 	CK_STAILQ_HEAD(, ifg_member)	 ifg_members; /* (CK_) */
3660f8d79d9SMatt Macy 	CK_STAILQ_ENTRY(ifg_group)		 ifg_next; /* (CK_) */
3670dad3f0eSMax Laier };
3680dad3f0eSMax Laier 
3690dad3f0eSMax Laier struct ifg_member {
3700f8d79d9SMatt Macy 	CK_STAILQ_ENTRY(ifg_member)	 ifgm_next; /* (CK_) */
371848d5bb1SKonstantin Belousov 	if_t				 ifgm_ifp;
3720dad3f0eSMax Laier };
3730dad3f0eSMax Laier 
3740dad3f0eSMax Laier struct ifg_list {
3750dad3f0eSMax Laier 	struct ifg_group	*ifgl_group;
3760f8d79d9SMatt Macy 	CK_STAILQ_ENTRY(ifg_list)	 ifgl_next; /* (CK_) */
3770dad3f0eSMax Laier };
3780dad3f0eSMax Laier 
379eaeb0c13SGleb Smirnoff #ifdef _SYS_EVENTHANDLER_H_
3800dad3f0eSMax Laier /* group attach event */
3810dad3f0eSMax Laier typedef void (*group_attach_event_handler_t)(void *, struct ifg_group *);
3820dad3f0eSMax Laier EVENTHANDLER_DECLARE(group_attach_event, group_attach_event_handler_t);
3830dad3f0eSMax Laier /* group detach event */
3840dad3f0eSMax Laier typedef void (*group_detach_event_handler_t)(void *, struct ifg_group *);
3850dad3f0eSMax Laier EVENTHANDLER_DECLARE(group_detach_event, group_detach_event_handler_t);
3860dad3f0eSMax Laier /* group change event */
3870dad3f0eSMax Laier typedef void (*group_change_event_handler_t)(void *, const char *);
3880dad3f0eSMax Laier EVENTHANDLER_DECLARE(group_change_event, group_change_event_handler_t);
389eaeb0c13SGleb Smirnoff #endif /* _SYS_EVENTHANDLER_H_ */
3900dad3f0eSMax Laier 
391aab3beeeSBrian Somers /*
392aab3beeeSBrian Somers  * 72 was chosen below because it is the size of a TCP/IP
393aab3beeeSBrian Somers  * header (40) + the minimum mss (32).
394aab3beeeSBrian Somers  */
395aab3beeeSBrian Somers #define	IF_MINMTU	72
396aab3beeeSBrian Somers #define	IF_MAXMTU	65535
397aab3beeeSBrian Somers 
398c255d1a4SJustin Hibbits #define	TOEDEV(ifp)		if_getllsoftc(ifp)
399c255d1a4SJustin Hibbits #define	SETTOEDEV(ifp, sc)	if_setllsoftc((ifp), (sc))
40009fe6320SNavdeep Parhar 
40119ff91c6SGarrett Wollman /*
40219ff91c6SGarrett Wollman  * The ifaddr structure contains information about one address
40319ff91c6SGarrett Wollman  * of an interface.  They are maintained by the different address families,
40419ff91c6SGarrett Wollman  * are allocated and attached when an address is set, and are linked
40519ff91c6SGarrett Wollman  * together so all addresses for an interface can be located.
406621b79c4SLuigi Rizzo  *
407621b79c4SLuigi Rizzo  * NOTE: a 'struct ifaddr' is always at the beginning of a larger
408621b79c4SLuigi Rizzo  * chunk of malloc'ed memory, where we store the three addresses
409621b79c4SLuigi Rizzo  * (ifa_addr, ifa_dstaddr and ifa_netmask) referenced here.
41019ff91c6SGarrett Wollman  */
41119ff91c6SGarrett Wollman struct ifaddr {
41219ff91c6SGarrett Wollman 	struct	sockaddr *ifa_addr;	/* address of interface */
41319ff91c6SGarrett Wollman 	struct	sockaddr *ifa_dstaddr;	/* other end of p-to-p link */
41419ff91c6SGarrett Wollman #define	ifa_broadaddr	ifa_dstaddr	/* broadcast address interface */
41519ff91c6SGarrett Wollman 	struct	sockaddr *ifa_netmask;	/* used to determine subnet */
416848d5bb1SKonstantin Belousov 	if_t		 ifa_ifp;		/* back-pointer to interface */
41708b68b0eSGleb Smirnoff 	struct	carp_softc *ifa_carp;	/* pointer to CARP data */
418fd04260dSMatt Macy 	CK_STAILQ_ENTRY(ifaddr) ifa_link;	/* queue macro glue */
41919ff91c6SGarrett Wollman 	u_short	ifa_flags;		/* mostly rt_flags for cloning */
420e072c794SGleb Smirnoff #define	IFA_ROUTE	RTF_UP		/* route installed */
421e072c794SGleb Smirnoff #define	IFA_RTSELF	RTF_HOST	/* loopback route to self installed */
422e3c1388bSPierre Beyssac 	u_int	ifa_refcnt;		/* references to this structure */
4237caf4ab7SGleb Smirnoff 
4247caf4ab7SGleb Smirnoff 	counter_u64_t	ifa_ipackets;
4257caf4ab7SGleb Smirnoff 	counter_u64_t	ifa_opackets;
4267caf4ab7SGleb Smirnoff 	counter_u64_t	ifa_ibytes;
4277caf4ab7SGleb Smirnoff 	counter_u64_t	ifa_obytes;
428d7c5a620SMatt Macy 	struct	epoch_context	ifa_epoch_ctx;
42919ff91c6SGarrett Wollman };
43019ff91c6SGarrett Wollman 
43146758960SGleb Smirnoff struct ifaddr *	ifa_alloc(size_t size, int flags);
4321099f828SRobert Watson void	ifa_free(struct ifaddr *ifa);
4331099f828SRobert Watson void	ifa_ref(struct ifaddr *ifa);
4349e5243d7SAlexander V. Chernikov int __result_use_check ifa_try_ref(struct ifaddr *ifa);
43519fc74fbSJeffrey Hsu 
4361158dfb7SGarrett Wollman /*
4371158dfb7SGarrett Wollman  * Multicast address structure.  This is analogous to the ifaddr
4381158dfb7SGarrett Wollman  * structure except that it keeps track of multicast addresses.
4391158dfb7SGarrett Wollman  */
440f9be0386SMatt Macy #define IFMA_F_ENQUEUED		0x1
4411158dfb7SGarrett Wollman struct ifmultiaddr {
442fd04260dSMatt Macy 	CK_STAILQ_ENTRY(ifmultiaddr) ifma_link; /* queue macro glue */
443373f88edSGarrett Wollman 	struct	sockaddr *ifma_addr; 	/* address this membership is for */
444373f88edSGarrett Wollman 	struct	sockaddr *ifma_lladdr;	/* link-layer translation, if any */
445848d5bb1SKonstantin Belousov 	if_t	ifma_ifp;		/* back-pointer to interface */
446373f88edSGarrett Wollman 	u_int	ifma_refcount;		/* reference count */
447f9be0386SMatt Macy 	int	ifma_flags;
448373f88edSGarrett Wollman 	void	*ifma_protospec;	/* protocol-specific state, if any */
449ec002feeSBruce M Simpson 	struct	ifmultiaddr *ifma_llifma; /* pointer to ifma for ifma_lladdr */
450d7c5a620SMatt Macy 	struct	epoch_context	ifma_epoch_ctx;
4511158dfb7SGarrett Wollman };
4521158dfb7SGarrett Wollman 
45377dfcdc4SRobert Watson extern	struct sx ifnet_sxlock;
45477dfcdc4SRobert Watson 
455a60100fdSKristof Provost #define	IFNET_WLOCK()		sx_xlock(&ifnet_sxlock)
456a60100fdSKristof Provost #define	IFNET_WUNLOCK()		sx_xunlock(&ifnet_sxlock)
45777dfcdc4SRobert Watson #define	IFNET_RLOCK_ASSERT()	sx_assert(&ifnet_sxlock, SA_SLOCKED)
458a60100fdSKristof Provost #define	IFNET_WLOCK_ASSERT()	sx_assert(&ifnet_sxlock, SA_XLOCKED)
45977dfcdc4SRobert Watson #define	IFNET_RLOCK()		sx_slock(&ifnet_sxlock)
46077dfcdc4SRobert Watson #define	IFNET_RUNLOCK()		sx_sunlock(&ifnet_sxlock)
461b30a244cSJeffrey Hsu 
46227d37320SRobert Watson /*
463d74b7baeSGleb Smirnoff  * Look up an ifnet given its index.  The returned value protected from
464d74b7baeSGleb Smirnoff  * being freed by the network epoch.  The _ref variant also acquires a
465d74b7baeSGleb Smirnoff  * reference that must be freed using if_rele().
46627d37320SRobert Watson  */
467848d5bb1SKonstantin Belousov if_t ifnet_byindex(u_int);
468848d5bb1SKonstantin Belousov if_t ifnet_byindex_ref(u_int);
4691887d35fSKip Macy 
4704d7a1361SGleb Smirnoff /*
4714d7a1361SGleb Smirnoff  * ifnet_byindexgen() looks up ifnet by index and generation count,
4724d7a1361SGleb Smirnoff  * attempting to restore a weak pointer that had been stored across
4734d7a1361SGleb Smirnoff  * the epoch.
4744d7a1361SGleb Smirnoff  */
475848d5bb1SKonstantin Belousov if_t ifnet_byindexgen(uint16_t idx, uint16_t gen);
4764d7a1361SGleb Smirnoff 
477eddfbb76SRobert Watson VNET_DECLARE(struct ifnethead, ifnet);
478eddfbb76SRobert Watson VNET_DECLARE(struct ifgrouphead, ifg_head);
479848d5bb1SKonstantin Belousov VNET_DECLARE(if_t, loif);	/* first loopback interface */
480eddfbb76SRobert Watson 
4811e77c105SRobert Watson #define	V_ifnet		VNET(ifnet)
4821e77c105SRobert Watson #define	V_ifg_head	VNET(ifg_head)
4831e77c105SRobert Watson #define	V_loif		VNET(loif)
484eddfbb76SRobert Watson 
485b6f6f880SMatt Macy #ifdef MCAST_VERBOSE
486b6f6f880SMatt Macy #define MCDPRINTF printf
487b6f6f880SMatt Macy #else
488b6f6f880SMatt Macy #define MCDPRINTF(...)
489b6f6f880SMatt Macy #endif
490b6f6f880SMatt Macy 
491848d5bb1SKonstantin Belousov int	if_addgroup(if_t, const char *);
492848d5bb1SKonstantin Belousov int	if_delgroup(if_t, const char *);
493848d5bb1SKonstantin Belousov int	if_addmulti(if_t, struct sockaddr *, struct ifmultiaddr **);
494848d5bb1SKonstantin Belousov int	if_allmulti(if_t, int);
495848d5bb1SKonstantin Belousov if_t	if_alloc(u_char);
496848d5bb1SKonstantin Belousov if_t	if_alloc_dev(u_char, device_t dev);
497848d5bb1SKonstantin Belousov void	if_attach(if_t);
498848d5bb1SKonstantin Belousov void	if_dead(if_t);
499848d5bb1SKonstantin Belousov int	if_delmulti(if_t, struct sockaddr *);
500ec002feeSBruce M Simpson void	if_delmulti_ifma(struct ifmultiaddr *);
501b6f6f880SMatt Macy void	if_delmulti_ifma_flags(struct ifmultiaddr *, int flags);
502848d5bb1SKonstantin Belousov void	if_detach(if_t);
503848d5bb1SKonstantin Belousov void	if_purgeaddrs(if_t);
504848d5bb1SKonstantin Belousov void	if_delallmulti(if_t);
505848d5bb1SKonstantin Belousov void	if_down(if_t);
5065896d124SBruce M Simpson struct ifmultiaddr *
507848d5bb1SKonstantin Belousov 	if_findmulti(if_t, const struct sockaddr *);
508b6f6f880SMatt Macy void	if_freemulti(struct ifmultiaddr *ifma);
509848d5bb1SKonstantin Belousov void	if_free(if_t);
510848d5bb1SKonstantin Belousov void	if_initname(if_t, const char *, int);
511848d5bb1SKonstantin Belousov void	if_link_state_change(if_t, int);
512848d5bb1SKonstantin Belousov int	if_printf(if_t, const char *, ...) __printflike(2, 3);
513848d5bb1SKonstantin Belousov int	if_log(if_t, int, const char *, ...) __printflike(3, 4);
514848d5bb1SKonstantin Belousov void	if_ref(if_t);
515848d5bb1SKonstantin Belousov void	if_rele(if_t);
516848d5bb1SKonstantin Belousov bool	__result_use_check if_try_ref(if_t);
517848d5bb1SKonstantin Belousov int	if_setlladdr(if_t, const u_char *, int);
518848d5bb1SKonstantin Belousov int	if_tunnel_check_nesting(if_t, struct mbuf *, uint32_t, int);
519848d5bb1SKonstantin Belousov void	if_up(if_t);
520929ddbbbSAlfred Perlstein int	ifioctl(struct socket *, u_long, caddr_t, struct thread *);
521848d5bb1SKonstantin Belousov int	ifpromisc(if_t, int);
522848d5bb1SKonstantin Belousov if_t	ifunit(const char *);
523848d5bb1SKonstantin Belousov if_t	ifunit_ref(const char *);
52419ff91c6SGarrett Wollman 
5259bb7d0f4SQing Li int	ifa_add_loopback_route(struct ifaddr *, struct sockaddr *);
5269bb7d0f4SQing Li int	ifa_del_loopback_route(struct ifaddr *, struct sockaddr *);
52759c180c3SAlexander V. Chernikov int	ifa_switch_loopback_route(struct ifaddr *, struct sockaddr *);
5289bb7d0f4SQing Li 
529441f9243SAlexander V. Chernikov struct	ifaddr *ifa_ifwithaddr(const struct sockaddr *);
530441f9243SAlexander V. Chernikov int		ifa_ifwithaddr_check(const struct sockaddr *);
531441f9243SAlexander V. Chernikov struct	ifaddr *ifa_ifwithbroadaddr(const struct sockaddr *, int);
532441f9243SAlexander V. Chernikov struct	ifaddr *ifa_ifwithdstaddr(const struct sockaddr *, int);
533441f9243SAlexander V. Chernikov struct	ifaddr *ifa_ifwithnet(const struct sockaddr *, int, int);
5344d2c2509SAlexander V. Chernikov struct	ifaddr *ifa_ifwithroute(int, const struct sockaddr *,
5354d2c2509SAlexander V. Chernikov     const struct sockaddr *, u_int);
536848d5bb1SKonstantin Belousov struct	ifaddr *ifaof_ifpforaddr(const struct sockaddr *, if_t);
53724421c1cSGleb Smirnoff int	ifa_preferred(struct ifaddr *, struct ifaddr *);
53819ff91c6SGarrett Wollman 
539848d5bb1SKonstantin Belousov int	if_simloop(if_t ifp, struct mbuf *m, int af, int hlen);
540373f88edSGarrett Wollman 
541848d5bb1SKonstantin Belousov typedef	void *if_com_alloc_t(u_char type, if_t ifp);
542fc74a9f9SBrooks Davis typedef	void if_com_free_t(void *com, u_char type);
543fc74a9f9SBrooks Davis void	if_register_com_alloc(u_char type, if_com_alloc_t *a, if_com_free_t *f);
544fc74a9f9SBrooks Davis void	if_deregister_com_alloc(u_char type);
545848d5bb1SKonstantin Belousov void	if_data_copy(if_t, struct if_data *);
546848d5bb1SKonstantin Belousov uint64_t if_get_counter_default(if_t, ift_counter);
547848d5bb1SKonstantin Belousov void	if_inc_counter(if_t, ift_counter, int64_t);
548fc74a9f9SBrooks Davis 
549ae330108SJustin Hibbits uint64_t if_setbaudrate(if_t ifp, uint64_t baudrate);
550ae330108SJustin Hibbits uint64_t if_getbaudrate(const if_t ifp);
551ae330108SJustin Hibbits int if_setcapabilities(if_t ifp, int capabilities);
552ae330108SJustin Hibbits int if_setcapabilitiesbit(if_t ifp, int setbit, int clearbit);
553ae330108SJustin Hibbits int if_getcapabilities(const if_t ifp);
554ae330108SJustin Hibbits int if_togglecapenable(if_t ifp, int togglecap);
555ae330108SJustin Hibbits int if_setcapenable(if_t ifp, int capenable);
556ae330108SJustin Hibbits int if_setcapenablebit(if_t ifp, int setcap, int clearcap);
557ae330108SJustin Hibbits int if_getcapenable(const if_t ifp);
558a3a76c3dSJustin Hibbits int if_setcapabilities2(if_t ifp, int capabilities);
559a3a76c3dSJustin Hibbits int if_setcapabilities2bit(if_t ifp, int setbit, int clearbit);
560a3a76c3dSJustin Hibbits int if_getcapabilities2(const if_t ifp);
561a3a76c3dSJustin Hibbits int if_togglecapenable2(if_t ifp, int togglecap);
562a3a76c3dSJustin Hibbits int if_setcapenable2(if_t ifp, int capenable);
563a3a76c3dSJustin Hibbits int if_setcapenable2bit(if_t ifp, int setcap, int clearcap);
564a3a76c3dSJustin Hibbits int if_getcapenable2(const if_t ifp);
565ae330108SJustin Hibbits int if_getdunit(const if_t ifp);
566ae330108SJustin Hibbits int if_getindex(const if_t ifp);
5671e6131baSJustin Hibbits int if_getidxgen(const if_t ifp);
568ae330108SJustin Hibbits const char *if_getdname(const if_t ifp);
569ae330108SJustin Hibbits void if_setdname(if_t ifp, const char *name);
570ae330108SJustin Hibbits const char *if_name(if_t ifp);
571ae330108SJustin Hibbits int if_setname(if_t ifp, const char *name);
572848d5bb1SKonstantin Belousov int if_rename(if_t ifp, char *new_name);
57379379355SAlexander V. Chernikov const char *if_getdescr(if_t ifp);
574ae330108SJustin Hibbits void if_setdescr(if_t ifp, char *descrbuf);
575ae330108SJustin Hibbits char *if_allocdescr(size_t sz, int malloc_flag);
576ae330108SJustin Hibbits void if_freedescr(char *descrbuf);
57779379355SAlexander V. Chernikov void if_setlastchange(if_t ifp);
578ae330108SJustin Hibbits int if_getalloctype(const if_t ifp);
579113af4fdSJustin Hibbits int if_gettype(const if_t ifp);
580ae330108SJustin Hibbits int if_setdev(if_t ifp, void *dev);
581ae330108SJustin Hibbits int if_setdrvflagbits(if_t ifp, int if_setflags, int clear_flags);
582ae330108SJustin Hibbits int if_getdrvflags(const if_t ifp);
583ae330108SJustin Hibbits int if_setdrvflags(if_t ifp, int flags);
5840d2684e1SJustin Hibbits int if_getlinkstate(if_t ifp);
585ae330108SJustin Hibbits int if_clearhwassist(if_t ifp);
586ae330108SJustin Hibbits int if_sethwassistbits(if_t ifp, int toset, int toclear);
587ae330108SJustin Hibbits int if_sethwassist(if_t ifp, int hwassist_bit);
588ae330108SJustin Hibbits int if_gethwassist(const if_t ifp);
589ae330108SJustin Hibbits int if_togglehwassist(if_t ifp, int toggle_bits);
590ae330108SJustin Hibbits int if_setsoftc(if_t ifp, void *softc);
591ae330108SJustin Hibbits void *if_getsoftc(if_t ifp);
592ae330108SJustin Hibbits int if_setflags(if_t ifp, int flags);
593c255d1a4SJustin Hibbits void if_setllsoftc(if_t ifp, void *softc);
594c255d1a4SJustin Hibbits void *if_getllsoftc(if_t ifp);
5950d2684e1SJustin Hibbits u_int if_getfib(if_t ifp);
596189c3729SJustin Hibbits uint8_t if_getaddrlen(if_t ifp);
597ae330108SJustin Hibbits int if_gethwaddr(const if_t ifp, struct ifreq *);
5980d2684e1SJustin Hibbits const uint8_t *if_getbroadcastaddr(const if_t ifp);
599189c3729SJustin Hibbits void if_setbroadcastaddr(if_t ifp, const uint8_t *);
600ae330108SJustin Hibbits int if_setmtu(if_t ifp, int mtu);
601ae330108SJustin Hibbits int if_getmtu(const if_t ifp);
602ae330108SJustin Hibbits int if_getmtu_family(const if_t ifp, int family);
60366bdbcd5SAlexander V. Chernikov void if_notifymtu(if_t ifp);
604ae330108SJustin Hibbits int if_setflagbits(if_t ifp, int set, int clear);
6050d2684e1SJustin Hibbits int if_setflags(if_t ifp, int flags);
606ae330108SJustin Hibbits int if_getflags(const if_t ifp);
6070d2684e1SJustin Hibbits int if_getnumadomain(if_t ifp);
608ae330108SJustin Hibbits int if_sendq_empty(if_t ifp);
609ae330108SJustin Hibbits int if_setsendqready(if_t ifp);
610ae330108SJustin Hibbits int if_setsendqlen(if_t ifp, int tx_desc_count);
611ae330108SJustin Hibbits int if_sethwtsomax(if_t ifp, u_int if_hw_tsomax);
612ae330108SJustin Hibbits int if_sethwtsomaxsegcount(if_t ifp, u_int if_hw_tsomaxsegcount);
613ae330108SJustin Hibbits int if_sethwtsomaxsegsize(if_t ifp, u_int if_hw_tsomaxsegsize);
614ae330108SJustin Hibbits u_int if_gethwtsomax(const if_t ifp);
615ae330108SJustin Hibbits u_int if_gethwtsomaxsegcount(const if_t ifp);
616ae330108SJustin Hibbits u_int if_gethwtsomaxsegsize(const if_t ifp);
6170d2684e1SJustin Hibbits void if_setnetmapadapter(if_t ifp, struct netmap_adapter *na);
6180d2684e1SJustin Hibbits struct netmap_adapter *if_getnetmapadapter(if_t ifp);
619aac2d19dSJustin Hibbits void if_input(if_t ifp, struct mbuf* sendmp);
620ae330108SJustin Hibbits int if_sendq_prepend(if_t ifp, struct mbuf *m);
621ae330108SJustin Hibbits struct mbuf *if_dequeue(if_t ifp);
622ae330108SJustin Hibbits int if_setifheaderlen(if_t ifp, int len);
623ae330108SJustin Hibbits void if_setrcvif(struct mbuf *m, if_t ifp);
624ae330108SJustin Hibbits void if_setvtag(struct mbuf *m, u_int16_t tag);
625ae330108SJustin Hibbits u_int16_t if_getvtag(struct mbuf *m);
626ae330108SJustin Hibbits int if_vlantrunkinuse(if_t ifp);
627ae330108SJustin Hibbits caddr_t if_getlladdr(const if_t ifp);
6280d2684e1SJustin Hibbits struct vnet *if_getvnet(const if_t ifp);
629ae330108SJustin Hibbits void *if_gethandle(u_char);
630ae330108SJustin Hibbits void if_vlancap(if_t ifp);
631ae330108SJustin Hibbits int if_transmit(if_t ifp, struct mbuf *m);
632aac2d19dSJustin Hibbits void if_init(if_t ifp, void *ctx);
63379379355SAlexander V. Chernikov int if_ioctl(if_t ifp, u_long cmd, void *data);
634189c3729SJustin Hibbits int if_resolvemulti(if_t ifp, struct sockaddr **, struct sockaddr *);
6350d2684e1SJustin Hibbits uint64_t if_getcounter(if_t ifp, ift_counter counter);
63630af2c13SJustin Hibbits struct label *if_getmaclabel(if_t ifp);
63730af2c13SJustin Hibbits void if_setmaclabel(if_t ifp, struct label *label);
6380d2684e1SJustin Hibbits struct bpf_if *if_getbpf(if_t ifp);
6390d2684e1SJustin Hibbits uint8_t if_getpcp(if_t ifp);
64031cfaf19SJustin Hibbits void *if_getl2com(if_t ifp);
6410d2684e1SJustin Hibbits struct ifvlantrunk *if_getvlantrunk(if_t ifp);
642d79539e6SJustin Hibbits bool if_altq_is_enabled(if_t ifp);
643d79539e6SJustin Hibbits 
6440d2684e1SJustin Hibbits void *if_getafdata(if_t ifp, int);
645ae330108SJustin Hibbits 
646848d5bb1SKonstantin Belousov int if_snd_tag_alloc(if_t ifp, union if_snd_tag_alloc_params *params,
6471e6131baSJustin Hibbits     struct m_snd_tag **mstp);
648ae330108SJustin Hibbits /*
649ae330108SJustin Hibbits  * Traversing through interface address lists.
650ae330108SJustin Hibbits  */
651ae330108SJustin Hibbits struct sockaddr_dl;
652ae330108SJustin Hibbits typedef u_int iflladdr_cb_t(void *, struct sockaddr_dl *, u_int);
653ae330108SJustin Hibbits u_int if_foreach_lladdr(if_t, iflladdr_cb_t, void *);
654ae330108SJustin Hibbits u_int if_foreach_llmaddr(if_t, iflladdr_cb_t, void *);
655ae330108SJustin Hibbits u_int if_lladdr_count(if_t);
656ae330108SJustin Hibbits u_int if_llmaddr_count(if_t);
657f766d1d5SJustin Hibbits bool if_maddr_empty(if_t);
658ae330108SJustin Hibbits 
659ae330108SJustin Hibbits int if_getamcount(const if_t ifp);
660ae330108SJustin Hibbits struct ifaddr * if_getifaddr(const if_t ifp);
661ae330108SJustin Hibbits typedef u_int if_addr_cb_t(void *, struct ifaddr *, u_int);
662ae330108SJustin Hibbits u_int if_foreach_addr_type(if_t ifp, int type, if_addr_cb_t cb, void *cb_arg);
663ae330108SJustin Hibbits 
6642eeb8083SJustin Hibbits typedef int (*if_foreach_cb_t)(if_t, void *);
665df2b419aSAlexander V. Chernikov typedef bool (*if_foreach_match_t)(if_t, void *);
6662eeb8083SJustin Hibbits int	if_foreach(if_foreach_cb_t, void *);
667df2b419aSAlexander V. Chernikov int	if_foreach_sleep(if_foreach_match_t, void *, if_foreach_cb_t, void *);
6682eeb8083SJustin Hibbits 
669e2427c69SJustin Hibbits /* Opaque iterator structure for iterating over interfaces. */
670e2427c69SJustin Hibbits struct if_iter {
671e2427c69SJustin Hibbits 	void *context[4];
672e2427c69SJustin Hibbits };
673e2427c69SJustin Hibbits 
674e2427c69SJustin Hibbits if_t	if_iter_start(struct if_iter *);
675e2427c69SJustin Hibbits if_t	if_iter_next(struct if_iter *);
676e2427c69SJustin Hibbits void	if_iter_finish(struct if_iter *);
677e2427c69SJustin Hibbits 
67879379355SAlexander V. Chernikov struct ifa_iter {
67979379355SAlexander V. Chernikov 	void *context[4];
68079379355SAlexander V. Chernikov };
68179379355SAlexander V. Chernikov 
68279379355SAlexander V. Chernikov struct ifaddr *ifa_iter_start(if_t ifp, struct ifa_iter *iter);
68379379355SAlexander V. Chernikov struct ifaddr *ifa_iter_next(struct ifa_iter *iter);
68479379355SAlexander V. Chernikov void ifa_iter_finish(struct ifa_iter *iter);
68579379355SAlexander V. Chernikov 
686ae330108SJustin Hibbits /* Functions */
687ae330108SJustin Hibbits void if_setinitfn(if_t ifp, if_init_fn_t);
688ae330108SJustin Hibbits void if_setinputfn(if_t ifp, if_input_fn_t);
6890d2684e1SJustin Hibbits if_input_fn_t if_getinputfn(if_t ifp);
690ae330108SJustin Hibbits void if_setioctlfn(if_t ifp, if_ioctl_fn_t);
6910d2684e1SJustin Hibbits void if_setoutputfn(if_t ifp, if_output_fn_t);
6920d2684e1SJustin Hibbits void if_setstartfn(if_t ifp, if_start_fn_t);
6930d2684e1SJustin Hibbits if_start_fn_t if_getstartfn(if_t ifp);
694ae330108SJustin Hibbits void if_settransmitfn(if_t ifp, if_transmit_fn_t);
6950d2684e1SJustin Hibbits if_transmit_fn_t if_gettransmitfn(if_t ifp);
696ae330108SJustin Hibbits void if_setqflushfn(if_t ifp, if_qflush_fn_t);
697ae330108SJustin Hibbits void if_setgetcounterfn(if_t ifp, if_get_counter_t);
698ae330108SJustin Hibbits void if_setsndtagallocfn(if_t ifp, if_snd_tag_alloc_t);
699848d5bb1SKonstantin Belousov void if_setdebugnet_methods(if_t, struct debugnet_methods *);
7000d2684e1SJustin Hibbits void if_setreassignfn(if_t ifp, if_reassign_fn_t);
7010d2684e1SJustin Hibbits void if_setratelimitqueryfn(if_t ifp, if_ratelimit_query_t);
702ae330108SJustin Hibbits 
7039fd573c3SHans Petter Selasky /* TSO */
7049fd573c3SHans Petter Selasky void if_hw_tsomax_common(if_t ifp, struct ifnet_hw_tsomax *);
7059fd573c3SHans Petter Selasky int if_hw_tsomax_update(if_t ifp, struct ifnet_hw_tsomax *);
7069fd573c3SHans Petter Selasky 
707ae330108SJustin Hibbits /* accessors for struct ifreq */
708ae330108SJustin Hibbits void *ifr_data_get_ptr(void *ifrp);
709ae330108SJustin Hibbits void *ifr_buffer_get_buffer(void *data);
710ae330108SJustin Hibbits size_t ifr_buffer_get_length(void *data);
711ae330108SJustin Hibbits 
712848d5bb1SKonstantin Belousov int ifhwioctl(u_long, if_t, caddr_t, struct thread *);
7131687b1abSMichael Tuexen 
714ae330108SJustin Hibbits #ifdef DEVICE_POLLING
715ae330108SJustin Hibbits enum poll_cmd { POLL_ONLY, POLL_AND_CHECK_STATUS };
716ae330108SJustin Hibbits 
717ae330108SJustin Hibbits typedef	int poll_handler_t(if_t ifp, enum poll_cmd cmd, int count);
718ae330108SJustin Hibbits int    ether_poll_register(poll_handler_t *h, if_t ifp);
719ae330108SJustin Hibbits int    ether_poll_deregister(if_t ifp);
720ae330108SJustin Hibbits #endif /* DEVICE_POLLING */
721ae330108SJustin Hibbits 
722664a31e4SPeter Wemm #endif /* _KERNEL */
723cbaac009SBjoern A. Zeeb 
7242c2b37adSJustin Hibbits #include <net/if_private.h>	/* XXX: temporary until drivers converted. */
725cbaac009SBjoern A. Zeeb #include <net/ifq.h>	/* XXXAO: temporary unconditional include */
726cbaac009SBjoern A. Zeeb 
72719ff91c6SGarrett Wollman #endif /* !_NET_IF_VAR_H_ */
728