xref: /freebsd/sys/net/if_var.h (revision 8e1af80243ff97f56918b363196832af9406597e)
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 *);
134aff22541SKonstantin Belousov typedef int (*if_spdadd_fn_t)(if_t ifp, void *sp, void *inp, void **priv);
135aff22541SKonstantin Belousov typedef int (*if_spddel_fn_t)(if_t ifp, void *sp, void *priv);
1362131654bSKonstantin Belousov typedef int (*if_sa_newkey_fn_t)(if_t ifp, void *sav, u_int drv_spi,
1372131654bSKonstantin Belousov     void **privp);
1382131654bSKonstantin Belousov typedef int (*if_sa_deinstall_fn_t)(if_t ifp, u_int drv_spi, void *priv);
1392131654bSKonstantin Belousov struct seclifetime;
1402131654bSKonstantin Belousov #define	IF_SA_CNT_UPD	0x80000000
1412131654bSKonstantin Belousov enum IF_SA_CNT_WHICH {
1422131654bSKonstantin Belousov 	IF_SA_CNT_IFP_HW_VAL = 1,
1432131654bSKonstantin Belousov 	IF_SA_CNT_TOTAL_SW_VAL,
1442131654bSKonstantin Belousov 	IF_SA_CNT_TOTAL_HW_VAL,
1452131654bSKonstantin Belousov 	IF_SA_CNT_IFP_HW_UPD = IF_SA_CNT_IFP_HW_VAL | IF_SA_CNT_UPD,
1462131654bSKonstantin Belousov 	IF_SA_CNT_TOTAL_SW_UPD = IF_SA_CNT_TOTAL_SW_VAL | IF_SA_CNT_UPD,
1472131654bSKonstantin Belousov 	IF_SA_CNT_TOTAL_HW_UPD = IF_SA_CNT_TOTAL_HW_VAL | IF_SA_CNT_UPD,
1482131654bSKonstantin Belousov };
1492131654bSKonstantin Belousov typedef int (*if_sa_cnt_fn_t)(if_t ifp, void *sa,
1502131654bSKonstantin Belousov     uint32_t drv_spi, void *priv, struct seclifetime *lt);
151240b7bfeSKonstantin Belousov typedef int (*if_ipsec_hwassist_fn_t)(if_t ifp, void *sav,
152240b7bfeSKonstantin Belousov     u_int drv_spi,void *priv);
153ae330108SJustin Hibbits 
1549fd573c3SHans Petter Selasky struct ifnet_hw_tsomax {
1559fd573c3SHans Petter Selasky 	u_int	tsomaxbytes;	/* TSO total burst length limit in bytes */
1569fd573c3SHans Petter Selasky 	u_int	tsomaxsegcount;	/* TSO maximum segment count */
1579fd573c3SHans Petter Selasky 	u_int	tsomaxsegsize;	/* TSO maximum segment size in bytes */
1589fd573c3SHans Petter Selasky };
1599fd573c3SHans Petter Selasky 
1604fb3a820SAlexander V. Chernikov /* Interface encap request types */
1614fb3a820SAlexander V. Chernikov typedef enum {
1624fb3a820SAlexander V. Chernikov 	IFENCAP_LL = 1			/* pre-calculate link-layer header */
1634fb3a820SAlexander V. Chernikov } ife_type;
1644fb3a820SAlexander V. Chernikov 
1654fb3a820SAlexander V. Chernikov /*
1664fb3a820SAlexander V. Chernikov  * The structure below allows to request various pre-calculated L2/L3 headers
1674fb3a820SAlexander V. Chernikov  * for different media. Requests varies by type (rtype field).
1684fb3a820SAlexander V. Chernikov  *
1694fb3a820SAlexander V. Chernikov  * IFENCAP_LL type: pre-calculates link header based on address family
1704fb3a820SAlexander V. Chernikov  *   and destination lladdr.
1714fb3a820SAlexander V. Chernikov  *
1724fb3a820SAlexander V. Chernikov  *   Input data fields:
1734fb3a820SAlexander V. Chernikov  *     buf: pointer to destination buffer
1744fb3a820SAlexander V. Chernikov  *     bufsize: buffer size
1754fb3a820SAlexander V. Chernikov  *     flags: IFENCAP_FLAG_BROADCAST if destination is broadcast
1764fb3a820SAlexander V. Chernikov  *     family: address family defined by AF_ constant.
1774fb3a820SAlexander V. Chernikov  *     lladdr: pointer to link-layer address
1784fb3a820SAlexander V. Chernikov  *     lladdr_len: length of link-layer address
1794fb3a820SAlexander V. Chernikov  *     hdata: pointer to L3 header (optional, used for ARP requests).
1804fb3a820SAlexander V. Chernikov  *   Output data fields:
1814fb3a820SAlexander V. Chernikov  *     buf: encap data is stored here
1824fb3a820SAlexander V. Chernikov  *     bufsize: resulting encap length is stored here
1834fb3a820SAlexander V. Chernikov  *     lladdr_off: offset of link-layer address from encap hdr start
1844fb3a820SAlexander V. Chernikov  *     hdata: L3 header may be altered if necessary
1854fb3a820SAlexander V. Chernikov  */
1864fb3a820SAlexander V. Chernikov 
1874fb3a820SAlexander V. Chernikov struct if_encap_req {
1884fb3a820SAlexander V. Chernikov 	u_char		*buf;		/* Destination buffer (w) */
1894fb3a820SAlexander V. Chernikov 	size_t		bufsize;	/* size of provided buffer (r) */
1904fb3a820SAlexander V. Chernikov 	ife_type	rtype;		/* request type (r) */
1914fb3a820SAlexander V. Chernikov 	uint32_t	flags;		/* Request flags (r) */
1924fb3a820SAlexander V. Chernikov 	int		family;		/* Address family AF_* (r) */
1934fb3a820SAlexander V. Chernikov 	int		lladdr_off;	/* offset from header start (w) */
1944fb3a820SAlexander V. Chernikov 	int		lladdr_len;	/* lladdr length (r) */
1954fb3a820SAlexander V. Chernikov 	char		*lladdr;	/* link-level address pointer (r) */
1964fb3a820SAlexander V. Chernikov 	char		*hdata;		/* Upper layer header data (rw) */
1974fb3a820SAlexander V. Chernikov };
1984fb3a820SAlexander V. Chernikov 
1994fb3a820SAlexander V. Chernikov #define	IFENCAP_FLAG_BROADCAST	0x02	/* Destination is broadcast */
2004fb3a820SAlexander V. Chernikov 
201f3e7afe2SHans Petter Selasky /*
202f3e7afe2SHans Petter Selasky  * Network interface send tag support. The storage of "struct
203f3e7afe2SHans Petter Selasky  * m_snd_tag" comes from the network driver and it is free to allocate
204f3e7afe2SHans Petter Selasky  * as much additional space as it wants for its own use.
205f3e7afe2SHans Petter Selasky  */
206b2e60773SJohn Baldwin struct ktls_session;
207f3e7afe2SHans Petter Selasky struct m_snd_tag;
208f3e7afe2SHans Petter Selasky 
209f3e7afe2SHans Petter Selasky #define	IF_SND_TAG_TYPE_RATE_LIMIT 0
21095ed5015SHans Petter Selasky #define	IF_SND_TAG_TYPE_UNLIMITED 1
211b2e60773SJohn Baldwin #define	IF_SND_TAG_TYPE_TLS 2
212521eac97SJohn Baldwin #define	IF_SND_TAG_TYPE_TLS_RATE_LIMIT 3
213c8f2c290SHans Petter Selasky #define	IF_SND_TAG_TYPE_TLS_RX 4
214c8f2c290SHans Petter Selasky #define	IF_SND_TAG_TYPE_MAX 5
215f3e7afe2SHans Petter Selasky 
216f3e7afe2SHans Petter Selasky struct if_snd_tag_alloc_header {
217f3e7afe2SHans Petter Selasky 	uint32_t type;		/* send tag type, see IF_SND_TAG_XXX */
218f3e7afe2SHans Petter Selasky 	uint32_t flowid;	/* mbuf hash value */
219f3e7afe2SHans Petter Selasky 	uint32_t flowtype;	/* mbuf hash type */
22098085baeSAndrew Gallatin 	uint8_t numa_domain;	/* numa domain of associated inp */
221f3e7afe2SHans Petter Selasky };
222f3e7afe2SHans Petter Selasky 
223f3e7afe2SHans Petter Selasky struct if_snd_tag_alloc_rate_limit {
224f3e7afe2SHans Petter Selasky 	struct if_snd_tag_alloc_header hdr;
225f3e7afe2SHans Petter Selasky 	uint64_t max_rate;	/* in bytes/s */
22620abea66SRandall Stewart 	uint32_t flags;		/* M_NOWAIT or M_WAITOK */
22720abea66SRandall Stewart 	uint32_t reserved;	/* alignment */
228f3e7afe2SHans Petter Selasky };
229f3e7afe2SHans Petter Selasky 
230b2e60773SJohn Baldwin struct if_snd_tag_alloc_tls {
231b2e60773SJohn Baldwin 	struct if_snd_tag_alloc_header hdr;
232b2e60773SJohn Baldwin 	struct inpcb *inp;
233b2e60773SJohn Baldwin 	const struct ktls_session *tls;
234b2e60773SJohn Baldwin };
235b2e60773SJohn Baldwin 
236c8f2c290SHans Petter Selasky struct if_snd_tag_alloc_tls_rx {
237c8f2c290SHans Petter Selasky 	struct if_snd_tag_alloc_header hdr;
238c8f2c290SHans Petter Selasky 	struct inpcb *inp;
239c8f2c290SHans Petter Selasky 	const struct ktls_session *tls;
240c8f2c290SHans Petter Selasky 	uint16_t vlan_id;	/* valid if non-zero */
241c8f2c290SHans Petter Selasky };
242c8f2c290SHans Petter Selasky 
243521eac97SJohn Baldwin struct if_snd_tag_alloc_tls_rate_limit {
244521eac97SJohn Baldwin 	struct if_snd_tag_alloc_header hdr;
245521eac97SJohn Baldwin 	struct inpcb *inp;
246521eac97SJohn Baldwin 	const struct ktls_session *tls;
247521eac97SJohn Baldwin 	uint64_t max_rate;	/* in bytes/s */
248521eac97SJohn Baldwin };
249521eac97SJohn Baldwin 
250f3e7afe2SHans Petter Selasky struct if_snd_tag_rate_limit_params {
251f3e7afe2SHans Petter Selasky 	uint64_t max_rate;	/* in bytes/s */
25295ed5015SHans Petter Selasky 	uint32_t queue_level;	/* 0 (empty) .. 65535 (full) */
25395ed5015SHans Petter Selasky #define	IF_SND_QUEUE_LEVEL_MIN 0
25495ed5015SHans Petter Selasky #define	IF_SND_QUEUE_LEVEL_MAX 65535
25520abea66SRandall Stewart 	uint32_t flags;		/* M_NOWAIT or M_WAITOK */
256f3e7afe2SHans Petter Selasky };
257f3e7afe2SHans Petter Selasky 
258c8f2c290SHans Petter Selasky struct if_snd_tag_modify_tls_rx {
259c8f2c290SHans Petter Selasky 	/* TCP sequence number of TLS header in host endian format */
260c8f2c290SHans Petter Selasky 	uint32_t tls_hdr_tcp_sn;
261c8f2c290SHans Petter Selasky 
262c8f2c290SHans Petter Selasky 	/*
263c8f2c290SHans Petter Selasky 	 * TLS record length, including all headers, data and trailers.
264c8f2c290SHans Petter Selasky 	 * If the tls_rec_length is zero, it means HW encryption resumed.
265c8f2c290SHans Petter Selasky 	 */
266c8f2c290SHans Petter Selasky 	uint32_t tls_rec_length;
267c8f2c290SHans Petter Selasky 
268c8f2c290SHans Petter Selasky 	/* TLS sequence number in host endian format */
269c8f2c290SHans Petter Selasky 	uint64_t tls_seq_number;
270c8f2c290SHans Petter Selasky };
271c8f2c290SHans Petter Selasky 
272f3e7afe2SHans Petter Selasky union if_snd_tag_alloc_params {
273f3e7afe2SHans Petter Selasky 	struct if_snd_tag_alloc_header hdr;
274f3e7afe2SHans Petter Selasky 	struct if_snd_tag_alloc_rate_limit rate_limit;
27595ed5015SHans Petter Selasky 	struct if_snd_tag_alloc_rate_limit unlimited;
276b2e60773SJohn Baldwin 	struct if_snd_tag_alloc_tls tls;
277c8f2c290SHans Petter Selasky 	struct if_snd_tag_alloc_tls_rx tls_rx;
278521eac97SJohn Baldwin 	struct if_snd_tag_alloc_tls_rate_limit tls_rate_limit;
279f3e7afe2SHans Petter Selasky };
280f3e7afe2SHans Petter Selasky 
281f3e7afe2SHans Petter Selasky union if_snd_tag_modify_params {
282f3e7afe2SHans Petter Selasky 	struct if_snd_tag_rate_limit_params rate_limit;
28395ed5015SHans Petter Selasky 	struct if_snd_tag_rate_limit_params unlimited;
284521eac97SJohn Baldwin 	struct if_snd_tag_rate_limit_params tls_rate_limit;
285c8f2c290SHans Petter Selasky 	struct if_snd_tag_modify_tls_rx tls_rx;
286f3e7afe2SHans Petter Selasky };
287f3e7afe2SHans Petter Selasky 
288f3e7afe2SHans Petter Selasky union if_snd_tag_query_params {
289f3e7afe2SHans Petter Selasky 	struct if_snd_tag_rate_limit_params rate_limit;
29095ed5015SHans Petter Selasky 	struct if_snd_tag_rate_limit_params unlimited;
291521eac97SJohn Baldwin 	struct if_snd_tag_rate_limit_params tls_rate_limit;
292f3e7afe2SHans Petter Selasky };
293f3e7afe2SHans Petter Selasky 
294848d5bb1SKonstantin Belousov typedef int (if_snd_tag_alloc_t)(if_t, union if_snd_tag_alloc_params *,
295ae330108SJustin Hibbits     struct m_snd_tag **);
296ae330108SJustin Hibbits typedef int (if_snd_tag_modify_t)(struct m_snd_tag *, union if_snd_tag_modify_params *);
297ae330108SJustin Hibbits typedef int (if_snd_tag_query_t)(struct m_snd_tag *, union if_snd_tag_query_params *);
298ae330108SJustin Hibbits typedef void (if_snd_tag_free_t)(struct m_snd_tag *);
299ae330108SJustin Hibbits typedef struct m_snd_tag *(if_next_send_tag_t)(struct m_snd_tag *);
300ae330108SJustin Hibbits 
301c782ea8bSJohn Baldwin struct if_snd_tag_sw {
302c782ea8bSJohn Baldwin 	if_snd_tag_modify_t *snd_tag_modify;
303c782ea8bSJohn Baldwin 	if_snd_tag_query_t *snd_tag_query;
304c782ea8bSJohn Baldwin 	if_snd_tag_free_t *snd_tag_free;
305c782ea8bSJohn Baldwin 	if_next_send_tag_t *next_snd_tag;
306c782ea8bSJohn Baldwin 	u_int	type;			/* One of IF_SND_TAG_TYPE_*. */
307c782ea8bSJohn Baldwin };
308c782ea8bSJohn Baldwin 
30920abea66SRandall Stewart /* Query return flags */
31020abea66SRandall Stewart #define RT_NOSUPPORT	  0x00000000	/* Not supported */
31120abea66SRandall Stewart #define RT_IS_INDIRECT    0x00000001	/*
31220abea66SRandall Stewart 					 * Interface like a lagg, select
31320abea66SRandall Stewart 					 * the actual interface for
31420abea66SRandall Stewart 					 * capabilities.
31520abea66SRandall Stewart 					 */
31620abea66SRandall Stewart #define RT_IS_SELECTABLE  0x00000002	/*
31720abea66SRandall Stewart 					 * No rate table, you select
31820abea66SRandall Stewart 					 * rates and the first
31920abea66SRandall Stewart 					 * number_of_rates are created.
32020abea66SRandall Stewart 					 */
32120abea66SRandall Stewart #define RT_IS_FIXED_TABLE 0x00000004	/* A fixed table is attached */
32220abea66SRandall Stewart #define RT_IS_UNUSABLE	  0x00000008	/* It is not usable for this */
323d7313dc6SRandall Stewart #define RT_IS_SETUP_REQ	  0x00000010	/* The interface setup must be called before use */
32420abea66SRandall Stewart 
32520abea66SRandall Stewart struct if_ratelimit_query_results {
32620abea66SRandall Stewart 	const uint64_t *rate_table;	/* Pointer to table if present */
32720abea66SRandall Stewart 	uint32_t flags;			/* Flags indicating results */
32820abea66SRandall Stewart 	uint32_t max_flows;		/* Max flows using, 0=unlimited */
32920abea66SRandall Stewart 	uint32_t number_of_rates;	/* How many unique rates can be created */
33020abea66SRandall Stewart 	uint32_t min_segment_burst;	/* The amount the adapter bursts at each send */
33120abea66SRandall Stewart };
33220abea66SRandall Stewart 
333848d5bb1SKonstantin Belousov typedef void (if_ratelimit_query_t)(if_t,
33420abea66SRandall Stewart     struct if_ratelimit_query_results *);
335848d5bb1SKonstantin Belousov typedef int (if_ratelimit_setup_t)(if_t, uint64_t, uint32_t);
3367687707dSAndrew Gallatin #define	IF_NODOM	255
33719ff91c6SGarrett Wollman /*
338de6073aaSRobert Watson  * Locks for address lists on the network interface.
339de6073aaSRobert Watson  */
340d7c5a620SMatt Macy #define	IF_ADDR_LOCK_INIT(if)	mtx_init(&(if)->if_addr_lock, "if_addr_lock", NULL, MTX_DEF)
341d7c5a620SMatt Macy #define	IF_ADDR_LOCK_DESTROY(if)	mtx_destroy(&(if)->if_addr_lock)
342d7c5a620SMatt Macy 
343d7c5a620SMatt Macy #define	IF_ADDR_WLOCK(if)	mtx_lock(&(if)->if_addr_lock)
344d7c5a620SMatt Macy #define	IF_ADDR_WUNLOCK(if)	mtx_unlock(&(if)->if_addr_lock)
3456573d758SMatt Macy #define	IF_ADDR_LOCK_ASSERT(if)	MPASS(in_epoch(net_epoch_preempt) || mtx_owned(&(if)->if_addr_lock))
346d7c5a620SMatt Macy #define	IF_ADDR_WLOCK_ASSERT(if) mtx_assert(&(if)->if_addr_lock, MA_OWNED)
347de6073aaSRobert Watson 
348664a31e4SPeter Wemm #ifdef _KERNEL
349ea4ca115SAndrew Thompson /* interface link layer address change event */
350848d5bb1SKonstantin Belousov typedef void (*iflladdr_event_handler_t)(void *, if_t);
351ea4ca115SAndrew Thompson EVENTHANDLER_DECLARE(iflladdr_event, iflladdr_event_handler_t);
35225a4adceSMax Laier /* interface address change event */
353848d5bb1SKonstantin Belousov typedef void (*ifaddr_event_handler_t)(void *, if_t);
35425a4adceSMax Laier EVENTHANDLER_DECLARE(ifaddr_event, ifaddr_event_handler_t);
355848d5bb1SKonstantin Belousov typedef void (*ifaddr_event_ext_handler_t)(void *, if_t, struct ifaddr *, int);
35664d63b1eSAndrey V. Elsukov EVENTHANDLER_DECLARE(ifaddr_event_ext, ifaddr_event_ext_handler_t);
35764d63b1eSAndrey V. Elsukov #define	IFADDR_EVENT_ADD	0
35864d63b1eSAndrey V. Elsukov #define	IFADDR_EVENT_DEL	1
35925a4adceSMax Laier /* new interface arrival event */
360848d5bb1SKonstantin Belousov typedef void (*ifnet_arrival_event_handler_t)(void *, if_t);
36125a4adceSMax Laier EVENTHANDLER_DECLARE(ifnet_arrival_event, ifnet_arrival_event_handler_t);
36225a4adceSMax Laier /* interface departure event */
363848d5bb1SKonstantin Belousov typedef void (*ifnet_departure_event_handler_t)(void *, if_t);
36425a4adceSMax Laier EVENTHANDLER_DECLARE(ifnet_departure_event, ifnet_departure_event_handler_t);
365e4cd31ddSJeff Roberson /* Interface link state change event */
366848d5bb1SKonstantin Belousov typedef void (*ifnet_link_event_handler_t)(void *, if_t, int);
367e4cd31ddSJeff Roberson EVENTHANDLER_DECLARE(ifnet_link_event, ifnet_link_event_handler_t);
3686597559eSDexuan Cui /* Interface up/down event */
3696597559eSDexuan Cui #define IFNET_EVENT_UP		0
3706597559eSDexuan Cui #define IFNET_EVENT_DOWN	1
3714a381a9eSHans Petter Selasky #define IFNET_EVENT_PCP		2	/* priority code point, PCP */
372f2ab9160SAndrey V. Elsukov #define	IFNET_EVENT_UPDATE_BAUDRATE	3
3734a381a9eSHans Petter Selasky 
374848d5bb1SKonstantin Belousov typedef void (*ifnet_event_fn)(void *, if_t ifp, int event);
3756597559eSDexuan Cui EVENTHANDLER_DECLARE(ifnet_event, ifnet_event_fn);
37625a4adceSMax Laier 
3770dad3f0eSMax Laier /*
3780dad3f0eSMax Laier  * interface groups
3790dad3f0eSMax Laier  */
3800dad3f0eSMax Laier struct ifg_group {
3810dad3f0eSMax Laier 	char				 ifg_group[IFNAMSIZ];
3820dad3f0eSMax Laier 	u_int				 ifg_refcnt;
3830dad3f0eSMax Laier 	void				*ifg_pf_kif;
3840f8d79d9SMatt Macy 	CK_STAILQ_HEAD(, ifg_member)	 ifg_members; /* (CK_) */
3850f8d79d9SMatt Macy 	CK_STAILQ_ENTRY(ifg_group)		 ifg_next; /* (CK_) */
3860dad3f0eSMax Laier };
3870dad3f0eSMax Laier 
3880dad3f0eSMax Laier struct ifg_member {
3890f8d79d9SMatt Macy 	CK_STAILQ_ENTRY(ifg_member)	 ifgm_next; /* (CK_) */
390848d5bb1SKonstantin Belousov 	if_t				 ifgm_ifp;
3910dad3f0eSMax Laier };
3920dad3f0eSMax Laier 
3930dad3f0eSMax Laier struct ifg_list {
3940dad3f0eSMax Laier 	struct ifg_group	*ifgl_group;
3950f8d79d9SMatt Macy 	CK_STAILQ_ENTRY(ifg_list)	 ifgl_next; /* (CK_) */
3960dad3f0eSMax Laier };
3970dad3f0eSMax Laier 
398eaeb0c13SGleb Smirnoff #ifdef _SYS_EVENTHANDLER_H_
3990dad3f0eSMax Laier /* group attach event */
4000dad3f0eSMax Laier typedef void (*group_attach_event_handler_t)(void *, struct ifg_group *);
4010dad3f0eSMax Laier EVENTHANDLER_DECLARE(group_attach_event, group_attach_event_handler_t);
4020dad3f0eSMax Laier /* group detach event */
4030dad3f0eSMax Laier typedef void (*group_detach_event_handler_t)(void *, struct ifg_group *);
4040dad3f0eSMax Laier EVENTHANDLER_DECLARE(group_detach_event, group_detach_event_handler_t);
4050dad3f0eSMax Laier /* group change event */
4060dad3f0eSMax Laier typedef void (*group_change_event_handler_t)(void *, const char *);
4070dad3f0eSMax Laier EVENTHANDLER_DECLARE(group_change_event, group_change_event_handler_t);
408eaeb0c13SGleb Smirnoff #endif /* _SYS_EVENTHANDLER_H_ */
4090dad3f0eSMax Laier 
410aab3beeeSBrian Somers /*
411aab3beeeSBrian Somers  * 72 was chosen below because it is the size of a TCP/IP
412aab3beeeSBrian Somers  * header (40) + the minimum mss (32).
413aab3beeeSBrian Somers  */
414aab3beeeSBrian Somers #define	IF_MINMTU	72
415aab3beeeSBrian Somers #define	IF_MAXMTU	65535
416aab3beeeSBrian Somers 
417c255d1a4SJustin Hibbits #define	TOEDEV(ifp)		if_getllsoftc(ifp)
418c255d1a4SJustin Hibbits #define	SETTOEDEV(ifp, sc)	if_setllsoftc((ifp), (sc))
41909fe6320SNavdeep Parhar 
42019ff91c6SGarrett Wollman /*
42119ff91c6SGarrett Wollman  * The ifaddr structure contains information about one address
42219ff91c6SGarrett Wollman  * of an interface.  They are maintained by the different address families,
42319ff91c6SGarrett Wollman  * are allocated and attached when an address is set, and are linked
42419ff91c6SGarrett Wollman  * together so all addresses for an interface can be located.
425621b79c4SLuigi Rizzo  *
426621b79c4SLuigi Rizzo  * NOTE: a 'struct ifaddr' is always at the beginning of a larger
427621b79c4SLuigi Rizzo  * chunk of malloc'ed memory, where we store the three addresses
428621b79c4SLuigi Rizzo  * (ifa_addr, ifa_dstaddr and ifa_netmask) referenced here.
42919ff91c6SGarrett Wollman  */
43019ff91c6SGarrett Wollman struct ifaddr {
43119ff91c6SGarrett Wollman 	struct	sockaddr *ifa_addr;	/* address of interface */
43219ff91c6SGarrett Wollman 	struct	sockaddr *ifa_dstaddr;	/* other end of p-to-p link */
43319ff91c6SGarrett Wollman #define	ifa_broadaddr	ifa_dstaddr	/* broadcast address interface */
43419ff91c6SGarrett Wollman 	struct	sockaddr *ifa_netmask;	/* used to determine subnet */
435848d5bb1SKonstantin Belousov 	if_t		 ifa_ifp;		/* back-pointer to interface */
43608b68b0eSGleb Smirnoff 	struct	carp_softc *ifa_carp;	/* pointer to CARP data */
437fd04260dSMatt Macy 	CK_STAILQ_ENTRY(ifaddr) ifa_link;	/* queue macro glue */
43819ff91c6SGarrett Wollman 	u_short	ifa_flags;		/* mostly rt_flags for cloning */
439e072c794SGleb Smirnoff #define	IFA_ROUTE	RTF_UP		/* route installed */
440e072c794SGleb Smirnoff #define	IFA_RTSELF	RTF_HOST	/* loopback route to self installed */
441e3c1388bSPierre Beyssac 	u_int	ifa_refcnt;		/* references to this structure */
4427caf4ab7SGleb Smirnoff 
4437caf4ab7SGleb Smirnoff 	counter_u64_t	ifa_ipackets;
4447caf4ab7SGleb Smirnoff 	counter_u64_t	ifa_opackets;
4457caf4ab7SGleb Smirnoff 	counter_u64_t	ifa_ibytes;
4467caf4ab7SGleb Smirnoff 	counter_u64_t	ifa_obytes;
447d7c5a620SMatt Macy 	struct	epoch_context	ifa_epoch_ctx;
44819ff91c6SGarrett Wollman };
44919ff91c6SGarrett Wollman 
45046758960SGleb Smirnoff struct ifaddr *	ifa_alloc(size_t size, int flags);
4511099f828SRobert Watson void	ifa_free(struct ifaddr *ifa);
4521099f828SRobert Watson void	ifa_ref(struct ifaddr *ifa);
4539e5243d7SAlexander V. Chernikov int __result_use_check ifa_try_ref(struct ifaddr *ifa);
45419fc74fbSJeffrey Hsu 
4551158dfb7SGarrett Wollman /*
4561158dfb7SGarrett Wollman  * Multicast address structure.  This is analogous to the ifaddr
4571158dfb7SGarrett Wollman  * structure except that it keeps track of multicast addresses.
4581158dfb7SGarrett Wollman  */
459f9be0386SMatt Macy #define IFMA_F_ENQUEUED		0x1
4601158dfb7SGarrett Wollman struct ifmultiaddr {
461fd04260dSMatt Macy 	CK_STAILQ_ENTRY(ifmultiaddr) ifma_link; /* queue macro glue */
462373f88edSGarrett Wollman 	struct	sockaddr *ifma_addr; 	/* address this membership is for */
463373f88edSGarrett Wollman 	struct	sockaddr *ifma_lladdr;	/* link-layer translation, if any */
464848d5bb1SKonstantin Belousov 	if_t	ifma_ifp;		/* back-pointer to interface */
465373f88edSGarrett Wollman 	u_int	ifma_refcount;		/* reference count */
466f9be0386SMatt Macy 	int	ifma_flags;
467373f88edSGarrett Wollman 	void	*ifma_protospec;	/* protocol-specific state, if any */
468ec002feeSBruce M Simpson 	struct	ifmultiaddr *ifma_llifma; /* pointer to ifma for ifma_lladdr */
469d7c5a620SMatt Macy 	struct	epoch_context	ifma_epoch_ctx;
4701158dfb7SGarrett Wollman };
4711158dfb7SGarrett Wollman 
47277dfcdc4SRobert Watson extern	struct sx ifnet_sxlock;
47377dfcdc4SRobert Watson 
474a60100fdSKristof Provost #define	IFNET_WLOCK()		sx_xlock(&ifnet_sxlock)
475a60100fdSKristof Provost #define	IFNET_WUNLOCK()		sx_xunlock(&ifnet_sxlock)
47677dfcdc4SRobert Watson #define	IFNET_RLOCK_ASSERT()	sx_assert(&ifnet_sxlock, SA_SLOCKED)
477a60100fdSKristof Provost #define	IFNET_WLOCK_ASSERT()	sx_assert(&ifnet_sxlock, SA_XLOCKED)
47877dfcdc4SRobert Watson #define	IFNET_RLOCK()		sx_slock(&ifnet_sxlock)
47977dfcdc4SRobert Watson #define	IFNET_RUNLOCK()		sx_sunlock(&ifnet_sxlock)
480b30a244cSJeffrey Hsu 
48127d37320SRobert Watson /*
482d74b7baeSGleb Smirnoff  * Look up an ifnet given its index.  The returned value protected from
483d74b7baeSGleb Smirnoff  * being freed by the network epoch.  The _ref variant also acquires a
484d74b7baeSGleb Smirnoff  * reference that must be freed using if_rele().
48527d37320SRobert Watson  */
486848d5bb1SKonstantin Belousov if_t ifnet_byindex(u_int);
487848d5bb1SKonstantin Belousov if_t ifnet_byindex_ref(u_int);
4881887d35fSKip Macy 
4894d7a1361SGleb Smirnoff /*
4904d7a1361SGleb Smirnoff  * ifnet_byindexgen() looks up ifnet by index and generation count,
4914d7a1361SGleb Smirnoff  * attempting to restore a weak pointer that had been stored across
4924d7a1361SGleb Smirnoff  * the epoch.
4934d7a1361SGleb Smirnoff  */
494848d5bb1SKonstantin Belousov if_t ifnet_byindexgen(uint16_t idx, uint16_t gen);
4954d7a1361SGleb Smirnoff 
496eddfbb76SRobert Watson VNET_DECLARE(struct ifnethead, ifnet);
497eddfbb76SRobert Watson VNET_DECLARE(struct ifgrouphead, ifg_head);
498848d5bb1SKonstantin Belousov VNET_DECLARE(if_t, loif);	/* first loopback interface */
499eddfbb76SRobert Watson 
5001e77c105SRobert Watson #define	V_ifnet		VNET(ifnet)
5011e77c105SRobert Watson #define	V_ifg_head	VNET(ifg_head)
5021e77c105SRobert Watson #define	V_loif		VNET(loif)
503eddfbb76SRobert Watson 
504b6f6f880SMatt Macy #ifdef MCAST_VERBOSE
505b6f6f880SMatt Macy #define MCDPRINTF printf
506b6f6f880SMatt Macy #else
507b6f6f880SMatt Macy #define MCDPRINTF(...)
508b6f6f880SMatt Macy #endif
509b6f6f880SMatt Macy 
510848d5bb1SKonstantin Belousov int	if_addgroup(if_t, const char *);
511848d5bb1SKonstantin Belousov int	if_delgroup(if_t, const char *);
512848d5bb1SKonstantin Belousov int	if_addmulti(if_t, struct sockaddr *, struct ifmultiaddr **);
513848d5bb1SKonstantin Belousov int	if_allmulti(if_t, int);
514848d5bb1SKonstantin Belousov if_t	if_alloc(u_char);
515848d5bb1SKonstantin Belousov if_t	if_alloc_dev(u_char, device_t dev);
516848d5bb1SKonstantin Belousov void	if_attach(if_t);
517848d5bb1SKonstantin Belousov void	if_dead(if_t);
518848d5bb1SKonstantin Belousov int	if_delmulti(if_t, struct sockaddr *);
519ec002feeSBruce M Simpson void	if_delmulti_ifma(struct ifmultiaddr *);
520b6f6f880SMatt Macy void	if_delmulti_ifma_flags(struct ifmultiaddr *, int flags);
521848d5bb1SKonstantin Belousov void	if_detach(if_t);
522848d5bb1SKonstantin Belousov void	if_purgeaddrs(if_t);
523848d5bb1SKonstantin Belousov void	if_delallmulti(if_t);
524848d5bb1SKonstantin Belousov void	if_down(if_t);
5255896d124SBruce M Simpson struct ifmultiaddr *
526848d5bb1SKonstantin Belousov 	if_findmulti(if_t, const struct sockaddr *);
527b6f6f880SMatt Macy void	if_freemulti(struct ifmultiaddr *ifma);
528848d5bb1SKonstantin Belousov void	if_free(if_t);
529848d5bb1SKonstantin Belousov void	if_initname(if_t, const char *, int);
530848d5bb1SKonstantin Belousov void	if_link_state_change(if_t, int);
531848d5bb1SKonstantin Belousov int	if_printf(if_t, const char *, ...) __printflike(2, 3);
532848d5bb1SKonstantin Belousov int	if_log(if_t, int, const char *, ...) __printflike(3, 4);
533848d5bb1SKonstantin Belousov void	if_ref(if_t);
534848d5bb1SKonstantin Belousov void	if_rele(if_t);
535848d5bb1SKonstantin Belousov bool	__result_use_check if_try_ref(if_t);
536848d5bb1SKonstantin Belousov int	if_setlladdr(if_t, const u_char *, int);
537848d5bb1SKonstantin Belousov int	if_tunnel_check_nesting(if_t, struct mbuf *, uint32_t, int);
538848d5bb1SKonstantin Belousov void	if_up(if_t);
539929ddbbbSAlfred Perlstein int	ifioctl(struct socket *, u_long, caddr_t, struct thread *);
540848d5bb1SKonstantin Belousov int	ifpromisc(if_t, int);
541848d5bb1SKonstantin Belousov if_t	ifunit(const char *);
542848d5bb1SKonstantin Belousov if_t	ifunit_ref(const char *);
54319ff91c6SGarrett Wollman 
5449bb7d0f4SQing Li int	ifa_add_loopback_route(struct ifaddr *, struct sockaddr *);
5459bb7d0f4SQing Li int	ifa_del_loopback_route(struct ifaddr *, struct sockaddr *);
54659c180c3SAlexander V. Chernikov int	ifa_switch_loopback_route(struct ifaddr *, struct sockaddr *);
5479bb7d0f4SQing Li 
548441f9243SAlexander V. Chernikov struct	ifaddr *ifa_ifwithaddr(const struct sockaddr *);
549441f9243SAlexander V. Chernikov int		ifa_ifwithaddr_check(const struct sockaddr *);
550441f9243SAlexander V. Chernikov struct	ifaddr *ifa_ifwithbroadaddr(const struct sockaddr *, int);
551441f9243SAlexander V. Chernikov struct	ifaddr *ifa_ifwithdstaddr(const struct sockaddr *, int);
552441f9243SAlexander V. Chernikov struct	ifaddr *ifa_ifwithnet(const struct sockaddr *, int, int);
5534d2c2509SAlexander V. Chernikov struct	ifaddr *ifa_ifwithroute(int, const struct sockaddr *,
5544d2c2509SAlexander V. Chernikov     const struct sockaddr *, u_int);
555848d5bb1SKonstantin Belousov struct	ifaddr *ifaof_ifpforaddr(const struct sockaddr *, if_t);
55624421c1cSGleb Smirnoff int	ifa_preferred(struct ifaddr *, struct ifaddr *);
55719ff91c6SGarrett Wollman 
558848d5bb1SKonstantin Belousov int	if_simloop(if_t ifp, struct mbuf *m, int af, int hlen);
559373f88edSGarrett Wollman 
560848d5bb1SKonstantin Belousov typedef	void *if_com_alloc_t(u_char type, if_t ifp);
561fc74a9f9SBrooks Davis typedef	void if_com_free_t(void *com, u_char type);
562fc74a9f9SBrooks Davis void	if_register_com_alloc(u_char type, if_com_alloc_t *a, if_com_free_t *f);
563fc74a9f9SBrooks Davis void	if_deregister_com_alloc(u_char type);
564848d5bb1SKonstantin Belousov void	if_data_copy(if_t, struct if_data *);
565848d5bb1SKonstantin Belousov uint64_t if_get_counter_default(if_t, ift_counter);
566848d5bb1SKonstantin Belousov void	if_inc_counter(if_t, ift_counter, int64_t);
567fc74a9f9SBrooks Davis 
568ae330108SJustin Hibbits uint64_t if_setbaudrate(if_t ifp, uint64_t baudrate);
569ae330108SJustin Hibbits uint64_t if_getbaudrate(const if_t ifp);
570ae330108SJustin Hibbits int if_setcapabilities(if_t ifp, int capabilities);
571ae330108SJustin Hibbits int if_setcapabilitiesbit(if_t ifp, int setbit, int clearbit);
572ae330108SJustin Hibbits int if_getcapabilities(const if_t ifp);
573ae330108SJustin Hibbits int if_togglecapenable(if_t ifp, int togglecap);
574ae330108SJustin Hibbits int if_setcapenable(if_t ifp, int capenable);
575ae330108SJustin Hibbits int if_setcapenablebit(if_t ifp, int setcap, int clearcap);
576ae330108SJustin Hibbits int if_getcapenable(const if_t ifp);
577a3a76c3dSJustin Hibbits int if_setcapabilities2(if_t ifp, int capabilities);
578a3a76c3dSJustin Hibbits int if_setcapabilities2bit(if_t ifp, int setbit, int clearbit);
579a3a76c3dSJustin Hibbits int if_getcapabilities2(const if_t ifp);
580a3a76c3dSJustin Hibbits int if_togglecapenable2(if_t ifp, int togglecap);
581a3a76c3dSJustin Hibbits int if_setcapenable2(if_t ifp, int capenable);
582a3a76c3dSJustin Hibbits int if_setcapenable2bit(if_t ifp, int setcap, int clearcap);
583a3a76c3dSJustin Hibbits int if_getcapenable2(const if_t ifp);
584ae330108SJustin Hibbits int if_getdunit(const if_t ifp);
585ae330108SJustin Hibbits int if_getindex(const if_t ifp);
5861e6131baSJustin Hibbits int if_getidxgen(const if_t ifp);
587ae330108SJustin Hibbits const char *if_getdname(const if_t ifp);
588ae330108SJustin Hibbits void if_setdname(if_t ifp, const char *name);
589ae330108SJustin Hibbits const char *if_name(if_t ifp);
590ae330108SJustin Hibbits int if_setname(if_t ifp, const char *name);
591848d5bb1SKonstantin Belousov int if_rename(if_t ifp, char *new_name);
59279379355SAlexander V. Chernikov const char *if_getdescr(if_t ifp);
593ae330108SJustin Hibbits void if_setdescr(if_t ifp, char *descrbuf);
594ae330108SJustin Hibbits char *if_allocdescr(size_t sz, int malloc_flag);
595ae330108SJustin Hibbits void if_freedescr(char *descrbuf);
59679379355SAlexander V. Chernikov void if_setlastchange(if_t ifp);
597ae330108SJustin Hibbits int if_getalloctype(const if_t ifp);
598113af4fdSJustin Hibbits int if_gettype(const if_t ifp);
599ae330108SJustin Hibbits int if_setdev(if_t ifp, void *dev);
600ae330108SJustin Hibbits int if_setdrvflagbits(if_t ifp, int if_setflags, int clear_flags);
601ae330108SJustin Hibbits int if_getdrvflags(const if_t ifp);
602ae330108SJustin Hibbits int if_setdrvflags(if_t ifp, int flags);
6030d2684e1SJustin Hibbits int if_getlinkstate(if_t ifp);
604ae330108SJustin Hibbits int if_clearhwassist(if_t ifp);
605ae330108SJustin Hibbits int if_sethwassistbits(if_t ifp, int toset, int toclear);
606ae330108SJustin Hibbits int if_sethwassist(if_t ifp, int hwassist_bit);
607ae330108SJustin Hibbits int if_gethwassist(const if_t ifp);
608ae330108SJustin Hibbits int if_togglehwassist(if_t ifp, int toggle_bits);
609ae330108SJustin Hibbits int if_setsoftc(if_t ifp, void *softc);
610ae330108SJustin Hibbits void *if_getsoftc(if_t ifp);
611ae330108SJustin Hibbits int if_setflags(if_t ifp, int flags);
612c255d1a4SJustin Hibbits void if_setllsoftc(if_t ifp, void *softc);
613c255d1a4SJustin Hibbits void *if_getllsoftc(if_t ifp);
6140d2684e1SJustin Hibbits u_int if_getfib(if_t ifp);
615189c3729SJustin Hibbits uint8_t if_getaddrlen(if_t ifp);
616ae330108SJustin Hibbits int if_gethwaddr(const if_t ifp, struct ifreq *);
6170d2684e1SJustin Hibbits const uint8_t *if_getbroadcastaddr(const if_t ifp);
618189c3729SJustin Hibbits void if_setbroadcastaddr(if_t ifp, const uint8_t *);
619ae330108SJustin Hibbits int if_setmtu(if_t ifp, int mtu);
620ae330108SJustin Hibbits int if_getmtu(const if_t ifp);
621ae330108SJustin Hibbits int if_getmtu_family(const if_t ifp, int family);
62266bdbcd5SAlexander V. Chernikov void if_notifymtu(if_t ifp);
623ae330108SJustin Hibbits int if_setflagbits(if_t ifp, int set, int clear);
6240d2684e1SJustin Hibbits int if_setflags(if_t ifp, int flags);
625ae330108SJustin Hibbits int if_getflags(const if_t ifp);
6260d2684e1SJustin Hibbits int if_getnumadomain(if_t ifp);
627ae330108SJustin Hibbits int if_sendq_empty(if_t ifp);
628ae330108SJustin Hibbits int if_setsendqready(if_t ifp);
629ae330108SJustin Hibbits int if_setsendqlen(if_t ifp, int tx_desc_count);
630ae330108SJustin Hibbits int if_sethwtsomax(if_t ifp, u_int if_hw_tsomax);
631ae330108SJustin Hibbits int if_sethwtsomaxsegcount(if_t ifp, u_int if_hw_tsomaxsegcount);
632ae330108SJustin Hibbits int if_sethwtsomaxsegsize(if_t ifp, u_int if_hw_tsomaxsegsize);
633ae330108SJustin Hibbits u_int if_gethwtsomax(const if_t ifp);
634ae330108SJustin Hibbits u_int if_gethwtsomaxsegcount(const if_t ifp);
635ae330108SJustin Hibbits u_int if_gethwtsomaxsegsize(const if_t ifp);
6360d2684e1SJustin Hibbits void if_setnetmapadapter(if_t ifp, struct netmap_adapter *na);
6370d2684e1SJustin Hibbits struct netmap_adapter *if_getnetmapadapter(if_t ifp);
638aac2d19dSJustin Hibbits void if_input(if_t ifp, struct mbuf* sendmp);
639ae330108SJustin Hibbits int if_sendq_prepend(if_t ifp, struct mbuf *m);
640ae330108SJustin Hibbits struct mbuf *if_dequeue(if_t ifp);
641ae330108SJustin Hibbits int if_setifheaderlen(if_t ifp, int len);
642ae330108SJustin Hibbits void if_setrcvif(struct mbuf *m, if_t ifp);
643ae330108SJustin Hibbits void if_setvtag(struct mbuf *m, u_int16_t tag);
644ae330108SJustin Hibbits u_int16_t if_getvtag(struct mbuf *m);
645ae330108SJustin Hibbits int if_vlantrunkinuse(if_t ifp);
646*8e1af802SGleb Smirnoff char *if_getlladdr(const if_t ifp);
6470d2684e1SJustin Hibbits struct vnet *if_getvnet(const if_t ifp);
648ae330108SJustin Hibbits void *if_gethandle(u_char);
649ae330108SJustin Hibbits void if_vlancap(if_t ifp);
650ae330108SJustin Hibbits int if_transmit(if_t ifp, struct mbuf *m);
651aac2d19dSJustin Hibbits void if_init(if_t ifp, void *ctx);
65279379355SAlexander V. Chernikov int if_ioctl(if_t ifp, u_long cmd, void *data);
653189c3729SJustin Hibbits int if_resolvemulti(if_t ifp, struct sockaddr **, struct sockaddr *);
6540d2684e1SJustin Hibbits uint64_t if_getcounter(if_t ifp, ift_counter counter);
65530af2c13SJustin Hibbits struct label *if_getmaclabel(if_t ifp);
65630af2c13SJustin Hibbits void if_setmaclabel(if_t ifp, struct label *label);
6570d2684e1SJustin Hibbits struct bpf_if *if_getbpf(if_t ifp);
6580d2684e1SJustin Hibbits uint8_t if_getpcp(if_t ifp);
65931cfaf19SJustin Hibbits void *if_getl2com(if_t ifp);
6600d2684e1SJustin Hibbits struct ifvlantrunk *if_getvlantrunk(if_t ifp);
661d79539e6SJustin Hibbits bool if_altq_is_enabled(if_t ifp);
662d79539e6SJustin Hibbits 
6630d2684e1SJustin Hibbits void *if_getafdata(if_t ifp, int);
664ae330108SJustin Hibbits 
665848d5bb1SKonstantin Belousov int if_snd_tag_alloc(if_t ifp, union if_snd_tag_alloc_params *params,
6661e6131baSJustin Hibbits     struct m_snd_tag **mstp);
667ae330108SJustin Hibbits /*
668ae330108SJustin Hibbits  * Traversing through interface address lists.
669ae330108SJustin Hibbits  */
670ae330108SJustin Hibbits struct sockaddr_dl;
671ae330108SJustin Hibbits typedef u_int iflladdr_cb_t(void *, struct sockaddr_dl *, u_int);
672ae330108SJustin Hibbits u_int if_foreach_lladdr(if_t, iflladdr_cb_t, void *);
673ae330108SJustin Hibbits u_int if_foreach_llmaddr(if_t, iflladdr_cb_t, void *);
674ae330108SJustin Hibbits u_int if_lladdr_count(if_t);
675ae330108SJustin Hibbits u_int if_llmaddr_count(if_t);
676f766d1d5SJustin Hibbits bool if_maddr_empty(if_t);
677ae330108SJustin Hibbits 
678ae330108SJustin Hibbits struct ifaddr * if_getifaddr(const if_t ifp);
679ae330108SJustin Hibbits typedef u_int if_addr_cb_t(void *, struct ifaddr *, u_int);
680ae330108SJustin Hibbits u_int if_foreach_addr_type(if_t ifp, int type, if_addr_cb_t cb, void *cb_arg);
681ae330108SJustin Hibbits 
6822eeb8083SJustin Hibbits typedef int (*if_foreach_cb_t)(if_t, void *);
683df2b419aSAlexander V. Chernikov typedef bool (*if_foreach_match_t)(if_t, void *);
6842eeb8083SJustin Hibbits int	if_foreach(if_foreach_cb_t, void *);
685df2b419aSAlexander V. Chernikov int	if_foreach_sleep(if_foreach_match_t, void *, if_foreach_cb_t, void *);
6862eeb8083SJustin Hibbits 
687e2427c69SJustin Hibbits /* Opaque iterator structure for iterating over interfaces. */
688e2427c69SJustin Hibbits struct if_iter {
689e2427c69SJustin Hibbits 	void *context[4];
690e2427c69SJustin Hibbits };
691e2427c69SJustin Hibbits 
692e2427c69SJustin Hibbits if_t	if_iter_start(struct if_iter *);
693e2427c69SJustin Hibbits if_t	if_iter_next(struct if_iter *);
694e2427c69SJustin Hibbits void	if_iter_finish(struct if_iter *);
695e2427c69SJustin Hibbits 
69679379355SAlexander V. Chernikov struct ifa_iter {
69779379355SAlexander V. Chernikov 	void *context[4];
69879379355SAlexander V. Chernikov };
69979379355SAlexander V. Chernikov 
70079379355SAlexander V. Chernikov struct ifaddr *ifa_iter_start(if_t ifp, struct ifa_iter *iter);
70179379355SAlexander V. Chernikov struct ifaddr *ifa_iter_next(struct ifa_iter *iter);
70279379355SAlexander V. Chernikov void ifa_iter_finish(struct ifa_iter *iter);
70379379355SAlexander V. Chernikov 
704ae330108SJustin Hibbits /* Functions */
705ae330108SJustin Hibbits void if_setinitfn(if_t ifp, if_init_fn_t);
706ae330108SJustin Hibbits void if_setinputfn(if_t ifp, if_input_fn_t);
7070d2684e1SJustin Hibbits if_input_fn_t if_getinputfn(if_t ifp);
708ae330108SJustin Hibbits void if_setioctlfn(if_t ifp, if_ioctl_fn_t);
7090d2684e1SJustin Hibbits void if_setoutputfn(if_t ifp, if_output_fn_t);
7100d2684e1SJustin Hibbits void if_setstartfn(if_t ifp, if_start_fn_t);
7110d2684e1SJustin Hibbits if_start_fn_t if_getstartfn(if_t ifp);
712ae330108SJustin Hibbits void if_settransmitfn(if_t ifp, if_transmit_fn_t);
7130d2684e1SJustin Hibbits if_transmit_fn_t if_gettransmitfn(if_t ifp);
714ae330108SJustin Hibbits void if_setqflushfn(if_t ifp, if_qflush_fn_t);
715ae330108SJustin Hibbits void if_setgetcounterfn(if_t ifp, if_get_counter_t);
716ae330108SJustin Hibbits void if_setsndtagallocfn(if_t ifp, if_snd_tag_alloc_t);
717848d5bb1SKonstantin Belousov void if_setdebugnet_methods(if_t, struct debugnet_methods *);
7180d2684e1SJustin Hibbits void if_setreassignfn(if_t ifp, if_reassign_fn_t);
7190d2684e1SJustin Hibbits void if_setratelimitqueryfn(if_t ifp, if_ratelimit_query_t);
720ae330108SJustin Hibbits 
7212131654bSKonstantin Belousov /*
7222131654bSKonstantin Belousov  * NB: The interface is not yet stable, drivers implementing IPSEC
7232131654bSKonstantin Belousov  * offload need to be prepared to adapt to changes.
7242131654bSKonstantin Belousov  */
7252131654bSKonstantin Belousov struct if_ipsec_accel_methods {
7262131654bSKonstantin Belousov 	if_spdadd_fn_t		if_spdadd;
7272131654bSKonstantin Belousov 	if_spddel_fn_t		if_spddel;
7282131654bSKonstantin Belousov 	if_sa_newkey_fn_t	if_sa_newkey;
7292131654bSKonstantin Belousov 	if_sa_deinstall_fn_t	if_sa_deinstall;
7302131654bSKonstantin Belousov 	if_sa_cnt_fn_t		if_sa_cnt;
731240b7bfeSKonstantin Belousov 	if_ipsec_hwassist_fn_t	if_hwassist;
7322131654bSKonstantin Belousov };
7332131654bSKonstantin Belousov void if_setipsec_accel_methods(if_t ifp, const struct if_ipsec_accel_methods *);
7342131654bSKonstantin Belousov 
7359fd573c3SHans Petter Selasky /* TSO */
7369fd573c3SHans Petter Selasky void if_hw_tsomax_common(if_t ifp, struct ifnet_hw_tsomax *);
7379fd573c3SHans Petter Selasky int if_hw_tsomax_update(if_t ifp, struct ifnet_hw_tsomax *);
7389fd573c3SHans Petter Selasky 
739ae330108SJustin Hibbits /* accessors for struct ifreq */
740ae330108SJustin Hibbits void *ifr_data_get_ptr(void *ifrp);
741ae330108SJustin Hibbits void *ifr_buffer_get_buffer(void *data);
742ae330108SJustin Hibbits size_t ifr_buffer_get_length(void *data);
743ae330108SJustin Hibbits 
744848d5bb1SKonstantin Belousov int ifhwioctl(u_long, if_t, caddr_t, struct thread *);
7451687b1abSMichael Tuexen 
746ae330108SJustin Hibbits #ifdef DEVICE_POLLING
747ae330108SJustin Hibbits enum poll_cmd { POLL_ONLY, POLL_AND_CHECK_STATUS };
748ae330108SJustin Hibbits 
749ae330108SJustin Hibbits typedef	int poll_handler_t(if_t ifp, enum poll_cmd cmd, int count);
750ae330108SJustin Hibbits int    ether_poll_register(poll_handler_t *h, if_t ifp);
751ae330108SJustin Hibbits int    ether_poll_deregister(if_t ifp);
752ae330108SJustin Hibbits #endif /* DEVICE_POLLING */
753ae330108SJustin Hibbits 
754664a31e4SPeter Wemm #endif /* _KERNEL */
755cbaac009SBjoern A. Zeeb 
756cbaac009SBjoern A. Zeeb #include <net/ifq.h>	/* XXXAO: temporary unconditional include */
757cbaac009SBjoern A. Zeeb 
75819ff91c6SGarrett Wollman #endif /* !_NET_IF_VAR_H_ */
759