master
  1/*-
  2 * SPDX-License-Identifier: BSD-3-Clause
  3 *
  4 * Copyright (c) 1982, 1986, 1989, 1993
  5 *	The Regents of the University of California.  All rights reserved.
  6 *
  7 * Redistribution and use in source and binary forms, with or without
  8 * modification, are permitted provided that the following conditions
  9 * are met:
 10 * 1. Redistributions of source code must retain the above copyright
 11 *    notice, this list of conditions and the following disclaimer.
 12 * 2. Redistributions in binary form must reproduce the above copyright
 13 *    notice, this list of conditions and the following disclaimer in the
 14 *    documentation and/or other materials provided with the distribution.
 15 * 3. Neither the name of the University nor the names of its contributors
 16 *    may be used to endorse or promote products derived from this software
 17 *    without specific prior written permission.
 18 *
 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 22 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 29 * SUCH DAMAGE.
 30 *
 31 *	From: @(#)if.h	8.1 (Berkeley) 6/10/93
 32 */
 33
 34#ifndef	_NET_IF_PRIVATE_H_
 35#define	_NET_IF_PRIVATE_H_
 36
 37#ifdef	_KERNEL
 38/*
 39 * Structure defining a network interface.
 40 */
 41struct ifnet {
 42	/* General book keeping of interface lists. */
 43	CK_STAILQ_ENTRY(ifnet) if_link; 	/* all struct ifnets are chained (CK_) */
 44	LIST_ENTRY(ifnet) if_clones;	/* interfaces of a cloner */
 45	CK_STAILQ_HEAD(, ifg_list) if_groups; /* linked list of groups per if (CK_) */
 46					/* protected by if_addr_lock */
 47	u_char	if_alloctype;		/* if_type at time of allocation */
 48	uint8_t	if_numa_domain;		/* NUMA domain of device */
 49	/* Driver and protocol specific information that remains stable. */
 50	void	*if_softc;		/* pointer to driver state */
 51	void	*if_llsoftc;		/* link layer softc */
 52	void	*if_l2com;		/* pointer to protocol bits */
 53	const char *if_dname;		/* driver name */
 54	int	if_dunit;		/* unit or IF_DUNIT_NONE */
 55	u_short	if_index;		/* numeric abbreviation for this if  */
 56	u_short	if_idxgen;		/* ... and its generation count */
 57	char	if_xname[IFNAMSIZ];	/* external name (name + unit) */
 58	char	*if_description;	/* interface description */
 59
 60	/* Variable fields that are touched by the stack and drivers. */
 61	int	if_flags;		/* up/down, broadcast, etc. */
 62	int	if_drv_flags;		/* driver-managed status flags */
 63	int	if_capabilities;	/* interface features & capabilities */
 64	int	if_capabilities2;	/* part 2 */
 65	int	if_capenable;		/* enabled features & capabilities */
 66	int	if_capenable2;		/* part 2 */
 67	void	*if_linkmib;		/* link-type-specific MIB data */
 68	size_t	if_linkmiblen;		/* length of above data */
 69	u_int	if_refcount;		/* reference count */
 70
 71	/* These fields are shared with struct if_data. */
 72	uint8_t		if_type;	/* ethernet, tokenring, etc */
 73	uint8_t		if_addrlen;	/* media address length */
 74	uint8_t		if_hdrlen;	/* media header length */
 75	uint8_t		if_link_state;	/* current link state */
 76	uint32_t	if_mtu;		/* maximum transmission unit */
 77	uint32_t	if_metric;	/* routing metric (external only) */
 78	uint64_t	if_baudrate;	/* linespeed */
 79	uint64_t	if_hwassist;	/* HW offload capabilities, see IFCAP */
 80	time_t		if_epoch;	/* uptime at attach or stat reset */
 81	struct timeval	if_lastchange;	/* time of last administrative change */
 82
 83	struct  ifaltq if_snd;		/* output queue (includes altq) */
 84	struct	task if_linktask;	/* task for link change events */
 85	struct	task if_addmultitask;	/* task for SIOCADDMULTI */
 86
 87	/* Addresses of different protocol families assigned to this if. */
 88	struct mtx if_addr_lock;	/* lock to protect address lists */
 89		/*
 90		 * if_addrhead is the list of all addresses associated to
 91		 * an interface.
 92		 * Some code in the kernel assumes that first element
 93		 * of the list has type AF_LINK, and contains sockaddr_dl
 94		 * addresses which store the link-level address and the name
 95		 * of the interface.
 96		 * However, access to the AF_LINK address through this
 97		 * field is deprecated. Use if_addr instead.
 98		 */
 99	struct	ifaddrhead if_addrhead;	/* linked list of addresses per if */
100	struct	ifmultihead if_multiaddrs; /* multicast addresses configured */
101	int	if_amcount;		/* number of all-multicast requests */
102	struct	ifaddr	*if_addr;	/* pointer to link-level address */
103	void	*if_hw_addr;		/* hardware link-level address */
104	const u_int8_t *if_broadcastaddr; /* linklevel broadcast bytestring */
105	struct	mtx if_afdata_lock;
106	void	*if_afdata[AF_MAX];
107	int	if_afdata_initialized;
108
109	/* Additional features hung off the interface. */
110	u_int	if_fib;			/* interface FIB */
111	struct	vnet *if_vnet;		/* pointer to network stack instance */
112	struct	vnet *if_home_vnet;	/* where this ifnet originates from */
113	struct  ifvlantrunk *if_vlantrunk; /* pointer to 802.1q data */
114	struct	bpf_if *if_bpf;		/* packet filter structure */
115	int	if_pcount;		/* number of promiscuous listeners */
116	void	*if_bridge;		/* bridge glue */
117	void	*if_lagg;		/* lagg glue */
118	void	*if_pf_kif;		/* pf glue */
119	struct	carp_if *if_carp;	/* carp interface structure */
120	struct	label *if_label;	/* interface MAC label */
121	struct	netmap_adapter *if_netmap; /* netmap(4) softc */
122
123	/* Various procedures of the layer2 encapsulation and drivers. */
124	if_output_fn_t if_output;	/* output routine (enqueue) */
125	if_input_fn_t if_input;		/* input routine (from h/w driver) */
126	struct mbuf *(*if_bridge_input)(struct ifnet *, struct mbuf *);
127	int	(*if_bridge_output)(struct ifnet *, struct mbuf *, struct sockaddr *,
128		    struct rtentry *);
129	void (*if_bridge_linkstate)(struct ifnet *ifp);
130	if_start_fn_t	if_start;	/* initiate output routine */
131	if_ioctl_fn_t	if_ioctl;	/* ioctl routine */
132	if_init_fn_t	if_init;	/* Init routine */
133	int	(*if_resolvemulti)	/* validate/resolve multicast */
134		(struct ifnet *, struct sockaddr **, struct sockaddr *);
135	if_qflush_fn_t	if_qflush;	/* flush any queue */
136	if_transmit_fn_t if_transmit;   /* initiate output routine */
137
138	if_reassign_fn_t if_reassign;		/* reassign to vnet routine */
139	if_get_counter_t if_get_counter; /* get counter values */
140	int	(*if_requestencap)	/* make link header from request */
141		(struct ifnet *, struct if_encap_req *);
142
143	/* Statistics. */
144	counter_u64_t	if_counters[IFCOUNTERS];
145
146	/* Stuff that's only temporary and doesn't belong here. */
147
148	/*
149	 * Network adapter TSO limits:
150	 * ===========================
151	 *
152	 * If the "if_hw_tsomax" field is zero the maximum segment
153	 * length limit does not apply. If the "if_hw_tsomaxsegcount"
154	 * or the "if_hw_tsomaxsegsize" field is zero the TSO segment
155	 * count limit does not apply. If all three fields are zero,
156	 * there is no TSO limit.
157	 *
158	 * NOTE: The TSO limits should reflect the values used in the
159	 * BUSDMA tag a network adapter is using to load a mbuf chain
160	 * for transmission. The TCP/IP network stack will subtract
161	 * space for all linklevel and protocol level headers and
162	 * ensure that the full mbuf chain passed to the network
163	 * adapter fits within the given limits.
164	 */
165	u_int	if_hw_tsomax;		/* TSO maximum size in bytes */
166	u_int	if_hw_tsomaxsegcount;	/* TSO maximum segment count */
167	u_int	if_hw_tsomaxsegsize;	/* TSO maximum segment size in bytes */
168
169	/*
170	 * Network adapter send tag support:
171	 */
172	if_snd_tag_alloc_t *if_snd_tag_alloc;
173
174	/* Ratelimit (packet pacing) */
175	if_ratelimit_query_t *if_ratelimit_query;
176	if_ratelimit_setup_t *if_ratelimit_setup;
177
178	/* Ethernet PCP */
179	uint8_t if_pcp;
180
181	/*
182	 * Debugnet (Netdump) hooks to be called while in db/panic.
183	 */
184	struct debugnet_methods *if_debugnet_methods;
185	struct epoch_context	if_epoch_ctx;
186
187	/*
188	 * Spare fields to be added before branching a stable branch, so
189	 * that structure can be enhanced without changing the kernel
190	 * binary interface.
191	 */
192	int	if_ispare[4];		/* general use */
193};
194
195#define	IF_AFDATA_LOCK_INIT(ifp)	\
196	mtx_init(&(ifp)->if_afdata_lock, "if_afdata", NULL, MTX_DEF)
197
198#define	IF_AFDATA_WLOCK(ifp)	mtx_lock(&(ifp)->if_afdata_lock)
199#define	IF_AFDATA_WUNLOCK(ifp)	mtx_unlock(&(ifp)->if_afdata_lock)
200#define	IF_AFDATA_LOCK(ifp)	IF_AFDATA_WLOCK(ifp)
201#define	IF_AFDATA_UNLOCK(ifp)	IF_AFDATA_WUNLOCK(ifp)
202#define	IF_AFDATA_TRYLOCK(ifp)	mtx_trylock(&(ifp)->if_afdata_lock)
203#define	IF_AFDATA_DESTROY(ifp)	mtx_destroy(&(ifp)->if_afdata_lock)
204
205#define	IF_AFDATA_LOCK_ASSERT(ifp)	MPASS(in_epoch(net_epoch_preempt) || mtx_owned(&(ifp)->if_afdata_lock))
206#define	IF_AFDATA_WLOCK_ASSERT(ifp)	mtx_assert(&(ifp)->if_afdata_lock, MA_OWNED)
207#define	IF_AFDATA_UNLOCK_ASSERT(ifp)	mtx_assert(&(ifp)->if_afdata_lock, MA_NOTOWNED)
208
209#define IF_LLADDR(ifp)							\
210    LLADDR((struct sockaddr_dl *)((ifp)->if_addr->ifa_addr))
211
212#endif	/* _KERNEL */
213
214#endif	/* _NET_IF_PRIVATE_H_ */