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 * From: @(#)if.h 8.1 (Berkeley) 6/10/93 32c3aac50fSPeter Wemm * $FreeBSD$ 3319ff91c6SGarrett Wollman */ 3419ff91c6SGarrett Wollman 3519ff91c6SGarrett Wollman #ifndef _NET_IF_VAR_H_ 3619ff91c6SGarrett Wollman #define _NET_IF_VAR_H_ 3719ff91c6SGarrett Wollman 3819ff91c6SGarrett Wollman /* 3919ff91c6SGarrett Wollman * Structures defining a network interface, providing a packet 4019ff91c6SGarrett Wollman * transport mechanism (ala level 0 of the PUP protocols). 4119ff91c6SGarrett Wollman * 4219ff91c6SGarrett Wollman * Each interface accepts output datagrams of a specified maximum 4319ff91c6SGarrett Wollman * length, and provides higher level routines with input datagrams 4419ff91c6SGarrett Wollman * received from its medium. 4519ff91c6SGarrett Wollman * 4619ff91c6SGarrett Wollman * Output occurs when the routine if_output is called, with three parameters: 4767452942SAlexander V. Chernikov * (*ifp->if_output)(ifp, m, dst, ro) 4819ff91c6SGarrett Wollman * Here m is the mbuf chain to be sent and dst is the destination address. 4919ff91c6SGarrett Wollman * The output routine encapsulates the supplied datagram if necessary, 5019ff91c6SGarrett Wollman * and then transmits it on its medium. 5119ff91c6SGarrett Wollman * 5219ff91c6SGarrett Wollman * On input, each interface unwraps the data received by it, and either 539d5abbddSJens Schweikhardt * places it on the input queue of an internetwork datagram routine 5419ff91c6SGarrett Wollman * and posts the associated software interrupt, or passes the datagram to a raw 5519ff91c6SGarrett Wollman * packet input routine. 5619ff91c6SGarrett Wollman * 5719ff91c6SGarrett Wollman * Routines exist for locating interfaces by their addresses 589d5abbddSJens Schweikhardt * or for locating an interface on a certain network, as well as more general 5919ff91c6SGarrett Wollman * routing and gateway routines maintaining information used to locate 6019ff91c6SGarrett Wollman * interfaces. These routines live in the files if.c and route.c 6119ff91c6SGarrett Wollman */ 6219ff91c6SGarrett Wollman 63c29e1ad9SGleb Smirnoff struct rtentry; /* ifa_rtrequest */ 6419ff91c6SGarrett Wollman struct socket; 65a9771948SGleb Smirnoff struct carp_if; 6608b68b0eSGleb Smirnoff struct carp_softc; 6775ee267cSGleb Smirnoff struct ifvlantrunk; 68c29e1ad9SGleb Smirnoff struct route; /* if_output */ 69bc29160dSMarko Zec struct vnet; 7062d76917SMarcel Moolenaar struct ifmedia; 71997d2d83SGleb Smirnoff struct netmap_adapter; 727790c8c1SConrad Meyer struct debugnet_methods; 7319ff91c6SGarrett Wollman 749ba20c31SJonathan Lemon #ifdef _KERNEL 75e2e050c8SConrad Meyer #include <sys/_eventhandler.h> 76c29e1ad9SGleb Smirnoff #include <sys/mbuf.h> /* ifqueue only? */ 771635d917SKip Macy #include <sys/buf_ring.h> 78eddfbb76SRobert Watson #include <net/vnet.h> 799ba20c31SJonathan Lemon #endif /* _KERNEL */ 80fd04260dSMatt Macy #include <sys/ck.h> 817caf4ab7SGleb Smirnoff #include <sys/counter.h> 82fd04260dSMatt Macy #include <sys/epoch.h> 83f34fa851SJohn Baldwin #include <sys/lock.h> /* XXX */ 84c29e1ad9SGleb Smirnoff #include <sys/mutex.h> /* struct ifqueue */ 85991f8615SKip Macy #include <sys/rwlock.h> /* XXX */ 8677dfcdc4SRobert Watson #include <sys/sx.h> /* XXX */ 87c29e1ad9SGleb Smirnoff #include <sys/_task.h> /* if_link_task */ 889bf40edeSBrooks Davis #define IF_DUNIT_NONE -1 899bf40edeSBrooks Davis 90772e66a6SGleb Smirnoff #include <net/altq/if_altq.h> 9102b199f1SMax Laier 924f6c66ccSMatt Macy CK_STAILQ_HEAD(ifnethead, ifnet); /* we use TAILQs so that the order of */ 93d7c5a620SMatt Macy CK_STAILQ_HEAD(ifaddrhead, ifaddr); /* instantiation is preserved in the list */ 94d7c5a620SMatt Macy CK_STAILQ_HEAD(ifmultihead, ifmultiaddr); 954f6c66ccSMatt Macy CK_STAILQ_HEAD(ifgrouphead, ifg_group); 9619ff91c6SGarrett Wollman 9773c23f3bSAlexander V. Chernikov #ifdef _KERNEL 98b252313fSGleb Smirnoff VNET_DECLARE(struct pfil_head *, link_pfil_head); 99b252313fSGleb Smirnoff #define V_link_pfil_head VNET(link_pfil_head) 100b252313fSGleb Smirnoff #define PFIL_ETHER_NAME "ethernet" 101ef91a976SAndrey V. Elsukov 102ef91a976SAndrey V. Elsukov #define HHOOK_IPSEC_INET 0 103ef91a976SAndrey V. Elsukov #define HHOOK_IPSEC_INET6 1 104ef91a976SAndrey V. Elsukov #define HHOOK_IPSEC_COUNT 2 105ef91a976SAndrey V. Elsukov VNET_DECLARE(struct hhook_head *, ipsec_hhh_in[HHOOK_IPSEC_COUNT]); 106ef91a976SAndrey V. Elsukov VNET_DECLARE(struct hhook_head *, ipsec_hhh_out[HHOOK_IPSEC_COUNT]); 107ef91a976SAndrey V. Elsukov #define V_ipsec_hhh_in VNET(ipsec_hhh_in) 108ef91a976SAndrey V. Elsukov #define V_ipsec_hhh_out VNET(ipsec_hhh_out) 10973c23f3bSAlexander V. Chernikov #endif /* _KERNEL */ 1107d4317bdSAlexander V. Chernikov 111ae330108SJustin Hibbits typedef enum { 112ae330108SJustin Hibbits IFCOUNTER_IPACKETS = 0, 113ae330108SJustin Hibbits IFCOUNTER_IERRORS, 114ae330108SJustin Hibbits IFCOUNTER_OPACKETS, 115ae330108SJustin Hibbits IFCOUNTER_OERRORS, 116ae330108SJustin Hibbits IFCOUNTER_COLLISIONS, 117ae330108SJustin Hibbits IFCOUNTER_IBYTES, 118ae330108SJustin Hibbits IFCOUNTER_OBYTES, 119ae330108SJustin Hibbits IFCOUNTER_IMCASTS, 120ae330108SJustin Hibbits IFCOUNTER_OMCASTS, 121ae330108SJustin Hibbits IFCOUNTER_IQDROPS, 122ae330108SJustin Hibbits IFCOUNTER_OQDROPS, 123ae330108SJustin Hibbits IFCOUNTER_NOPROTO, 124ae330108SJustin Hibbits IFCOUNTERS /* Array size. */ 125ae330108SJustin Hibbits } ift_counter; 126ae330108SJustin Hibbits 127ae330108SJustin Hibbits typedef void (*if_start_fn_t)(if_t); 128ae330108SJustin Hibbits typedef int (*if_ioctl_fn_t)(if_t, u_long, caddr_t); 129ae330108SJustin Hibbits typedef void (*if_init_fn_t)(void *); 130ae330108SJustin Hibbits typedef void (*if_input_fn_t)(struct ifnet *, struct mbuf *); 131ae330108SJustin Hibbits typedef int (*if_output_fn_t) 132ae330108SJustin Hibbits (struct ifnet *, struct mbuf *, const struct sockaddr *, struct route *); 133ae330108SJustin Hibbits typedef void (*if_qflush_fn_t)(if_t); 134ae330108SJustin Hibbits typedef int (*if_transmit_fn_t)(if_t, struct mbuf *); 135ae330108SJustin Hibbits typedef uint64_t (*if_get_counter_t)(if_t, ift_counter); 1360d2684e1SJustin Hibbits typedef void (*if_reassign_fn_t)(struct ifnet *, struct vnet *, char *); 137ae330108SJustin Hibbits 1389fd573c3SHans Petter Selasky struct ifnet_hw_tsomax { 1399fd573c3SHans Petter Selasky u_int tsomaxbytes; /* TSO total burst length limit in bytes */ 1409fd573c3SHans Petter Selasky u_int tsomaxsegcount; /* TSO maximum segment count */ 1419fd573c3SHans Petter Selasky u_int tsomaxsegsize; /* TSO maximum segment size in bytes */ 1429fd573c3SHans Petter Selasky }; 1439fd573c3SHans Petter Selasky 1444fb3a820SAlexander V. Chernikov /* Interface encap request types */ 1454fb3a820SAlexander V. Chernikov typedef enum { 1464fb3a820SAlexander V. Chernikov IFENCAP_LL = 1 /* pre-calculate link-layer header */ 1474fb3a820SAlexander V. Chernikov } ife_type; 1484fb3a820SAlexander V. Chernikov 1494fb3a820SAlexander V. Chernikov /* 1504fb3a820SAlexander V. Chernikov * The structure below allows to request various pre-calculated L2/L3 headers 1514fb3a820SAlexander V. Chernikov * for different media. Requests varies by type (rtype field). 1524fb3a820SAlexander V. Chernikov * 1534fb3a820SAlexander V. Chernikov * IFENCAP_LL type: pre-calculates link header based on address family 1544fb3a820SAlexander V. Chernikov * and destination lladdr. 1554fb3a820SAlexander V. Chernikov * 1564fb3a820SAlexander V. Chernikov * Input data fields: 1574fb3a820SAlexander V. Chernikov * buf: pointer to destination buffer 1584fb3a820SAlexander V. Chernikov * bufsize: buffer size 1594fb3a820SAlexander V. Chernikov * flags: IFENCAP_FLAG_BROADCAST if destination is broadcast 1604fb3a820SAlexander V. Chernikov * family: address family defined by AF_ constant. 1614fb3a820SAlexander V. Chernikov * lladdr: pointer to link-layer address 1624fb3a820SAlexander V. Chernikov * lladdr_len: length of link-layer address 1634fb3a820SAlexander V. Chernikov * hdata: pointer to L3 header (optional, used for ARP requests). 1644fb3a820SAlexander V. Chernikov * Output data fields: 1654fb3a820SAlexander V. Chernikov * buf: encap data is stored here 1664fb3a820SAlexander V. Chernikov * bufsize: resulting encap length is stored here 1674fb3a820SAlexander V. Chernikov * lladdr_off: offset of link-layer address from encap hdr start 1684fb3a820SAlexander V. Chernikov * hdata: L3 header may be altered if necessary 1694fb3a820SAlexander V. Chernikov */ 1704fb3a820SAlexander V. Chernikov 1714fb3a820SAlexander V. Chernikov struct if_encap_req { 1724fb3a820SAlexander V. Chernikov u_char *buf; /* Destination buffer (w) */ 1734fb3a820SAlexander V. Chernikov size_t bufsize; /* size of provided buffer (r) */ 1744fb3a820SAlexander V. Chernikov ife_type rtype; /* request type (r) */ 1754fb3a820SAlexander V. Chernikov uint32_t flags; /* Request flags (r) */ 1764fb3a820SAlexander V. Chernikov int family; /* Address family AF_* (r) */ 1774fb3a820SAlexander V. Chernikov int lladdr_off; /* offset from header start (w) */ 1784fb3a820SAlexander V. Chernikov int lladdr_len; /* lladdr length (r) */ 1794fb3a820SAlexander V. Chernikov char *lladdr; /* link-level address pointer (r) */ 1804fb3a820SAlexander V. Chernikov char *hdata; /* Upper layer header data (rw) */ 1814fb3a820SAlexander V. Chernikov }; 1824fb3a820SAlexander V. Chernikov 1834fb3a820SAlexander V. Chernikov #define IFENCAP_FLAG_BROADCAST 0x02 /* Destination is broadcast */ 1844fb3a820SAlexander V. Chernikov 185f3e7afe2SHans Petter Selasky /* 186f3e7afe2SHans Petter Selasky * Network interface send tag support. The storage of "struct 187f3e7afe2SHans Petter Selasky * m_snd_tag" comes from the network driver and it is free to allocate 188f3e7afe2SHans Petter Selasky * as much additional space as it wants for its own use. 189f3e7afe2SHans Petter Selasky */ 190b2e60773SJohn Baldwin struct ktls_session; 191f3e7afe2SHans Petter Selasky struct m_snd_tag; 192f3e7afe2SHans Petter Selasky 193f3e7afe2SHans Petter Selasky #define IF_SND_TAG_TYPE_RATE_LIMIT 0 19495ed5015SHans Petter Selasky #define IF_SND_TAG_TYPE_UNLIMITED 1 195b2e60773SJohn Baldwin #define IF_SND_TAG_TYPE_TLS 2 196521eac97SJohn Baldwin #define IF_SND_TAG_TYPE_TLS_RATE_LIMIT 3 197c8f2c290SHans Petter Selasky #define IF_SND_TAG_TYPE_TLS_RX 4 198c8f2c290SHans Petter Selasky #define IF_SND_TAG_TYPE_MAX 5 199f3e7afe2SHans Petter Selasky 200f3e7afe2SHans Petter Selasky struct if_snd_tag_alloc_header { 201f3e7afe2SHans Petter Selasky uint32_t type; /* send tag type, see IF_SND_TAG_XXX */ 202f3e7afe2SHans Petter Selasky uint32_t flowid; /* mbuf hash value */ 203f3e7afe2SHans Petter Selasky uint32_t flowtype; /* mbuf hash type */ 20498085baeSAndrew Gallatin uint8_t numa_domain; /* numa domain of associated inp */ 205f3e7afe2SHans Petter Selasky }; 206f3e7afe2SHans Petter Selasky 207f3e7afe2SHans Petter Selasky struct if_snd_tag_alloc_rate_limit { 208f3e7afe2SHans Petter Selasky struct if_snd_tag_alloc_header hdr; 209f3e7afe2SHans Petter Selasky uint64_t max_rate; /* in bytes/s */ 21020abea66SRandall Stewart uint32_t flags; /* M_NOWAIT or M_WAITOK */ 21120abea66SRandall Stewart uint32_t reserved; /* alignment */ 212f3e7afe2SHans Petter Selasky }; 213f3e7afe2SHans Petter Selasky 214b2e60773SJohn Baldwin struct if_snd_tag_alloc_tls { 215b2e60773SJohn Baldwin struct if_snd_tag_alloc_header hdr; 216b2e60773SJohn Baldwin struct inpcb *inp; 217b2e60773SJohn Baldwin const struct ktls_session *tls; 218b2e60773SJohn Baldwin }; 219b2e60773SJohn Baldwin 220c8f2c290SHans Petter Selasky struct if_snd_tag_alloc_tls_rx { 221c8f2c290SHans Petter Selasky struct if_snd_tag_alloc_header hdr; 222c8f2c290SHans Petter Selasky struct inpcb *inp; 223c8f2c290SHans Petter Selasky const struct ktls_session *tls; 224c8f2c290SHans Petter Selasky uint16_t vlan_id; /* valid if non-zero */ 225c8f2c290SHans Petter Selasky }; 226c8f2c290SHans Petter Selasky 227521eac97SJohn Baldwin struct if_snd_tag_alloc_tls_rate_limit { 228521eac97SJohn Baldwin struct if_snd_tag_alloc_header hdr; 229521eac97SJohn Baldwin struct inpcb *inp; 230521eac97SJohn Baldwin const struct ktls_session *tls; 231521eac97SJohn Baldwin uint64_t max_rate; /* in bytes/s */ 232521eac97SJohn Baldwin }; 233521eac97SJohn Baldwin 234f3e7afe2SHans Petter Selasky struct if_snd_tag_rate_limit_params { 235f3e7afe2SHans Petter Selasky uint64_t max_rate; /* in bytes/s */ 23695ed5015SHans Petter Selasky uint32_t queue_level; /* 0 (empty) .. 65535 (full) */ 23795ed5015SHans Petter Selasky #define IF_SND_QUEUE_LEVEL_MIN 0 23895ed5015SHans Petter Selasky #define IF_SND_QUEUE_LEVEL_MAX 65535 23920abea66SRandall Stewart uint32_t flags; /* M_NOWAIT or M_WAITOK */ 240f3e7afe2SHans Petter Selasky }; 241f3e7afe2SHans Petter Selasky 242c8f2c290SHans Petter Selasky struct if_snd_tag_modify_tls_rx { 243c8f2c290SHans Petter Selasky /* TCP sequence number of TLS header in host endian format */ 244c8f2c290SHans Petter Selasky uint32_t tls_hdr_tcp_sn; 245c8f2c290SHans Petter Selasky 246c8f2c290SHans Petter Selasky /* 247c8f2c290SHans Petter Selasky * TLS record length, including all headers, data and trailers. 248c8f2c290SHans Petter Selasky * If the tls_rec_length is zero, it means HW encryption resumed. 249c8f2c290SHans Petter Selasky */ 250c8f2c290SHans Petter Selasky uint32_t tls_rec_length; 251c8f2c290SHans Petter Selasky 252c8f2c290SHans Petter Selasky /* TLS sequence number in host endian format */ 253c8f2c290SHans Petter Selasky uint64_t tls_seq_number; 254c8f2c290SHans Petter Selasky }; 255c8f2c290SHans Petter Selasky 256f3e7afe2SHans Petter Selasky union if_snd_tag_alloc_params { 257f3e7afe2SHans Petter Selasky struct if_snd_tag_alloc_header hdr; 258f3e7afe2SHans Petter Selasky struct if_snd_tag_alloc_rate_limit rate_limit; 25995ed5015SHans Petter Selasky struct if_snd_tag_alloc_rate_limit unlimited; 260b2e60773SJohn Baldwin struct if_snd_tag_alloc_tls tls; 261c8f2c290SHans Petter Selasky struct if_snd_tag_alloc_tls_rx tls_rx; 262521eac97SJohn Baldwin struct if_snd_tag_alloc_tls_rate_limit tls_rate_limit; 263f3e7afe2SHans Petter Selasky }; 264f3e7afe2SHans Petter Selasky 265f3e7afe2SHans Petter Selasky union if_snd_tag_modify_params { 266f3e7afe2SHans Petter Selasky struct if_snd_tag_rate_limit_params rate_limit; 26795ed5015SHans Petter Selasky struct if_snd_tag_rate_limit_params unlimited; 268521eac97SJohn Baldwin struct if_snd_tag_rate_limit_params tls_rate_limit; 269c8f2c290SHans Petter Selasky struct if_snd_tag_modify_tls_rx tls_rx; 270f3e7afe2SHans Petter Selasky }; 271f3e7afe2SHans Petter Selasky 272f3e7afe2SHans Petter Selasky union if_snd_tag_query_params { 273f3e7afe2SHans Petter Selasky struct if_snd_tag_rate_limit_params rate_limit; 27495ed5015SHans Petter Selasky struct if_snd_tag_rate_limit_params unlimited; 275521eac97SJohn Baldwin struct if_snd_tag_rate_limit_params tls_rate_limit; 276f3e7afe2SHans Petter Selasky }; 277f3e7afe2SHans Petter Selasky 278ae330108SJustin Hibbits typedef int (if_snd_tag_alloc_t)(struct ifnet *, union if_snd_tag_alloc_params *, 279ae330108SJustin Hibbits struct m_snd_tag **); 280ae330108SJustin Hibbits typedef int (if_snd_tag_modify_t)(struct m_snd_tag *, union if_snd_tag_modify_params *); 281ae330108SJustin Hibbits typedef int (if_snd_tag_query_t)(struct m_snd_tag *, union if_snd_tag_query_params *); 282ae330108SJustin Hibbits typedef void (if_snd_tag_free_t)(struct m_snd_tag *); 283ae330108SJustin Hibbits typedef struct m_snd_tag *(if_next_send_tag_t)(struct m_snd_tag *); 284ae330108SJustin Hibbits 285c782ea8bSJohn Baldwin struct if_snd_tag_sw { 286c782ea8bSJohn Baldwin if_snd_tag_modify_t *snd_tag_modify; 287c782ea8bSJohn Baldwin if_snd_tag_query_t *snd_tag_query; 288c782ea8bSJohn Baldwin if_snd_tag_free_t *snd_tag_free; 289c782ea8bSJohn Baldwin if_next_send_tag_t *next_snd_tag; 290c782ea8bSJohn Baldwin u_int type; /* One of IF_SND_TAG_TYPE_*. */ 291c782ea8bSJohn Baldwin }; 292c782ea8bSJohn Baldwin 29320abea66SRandall Stewart /* Query return flags */ 29420abea66SRandall Stewart #define RT_NOSUPPORT 0x00000000 /* Not supported */ 29520abea66SRandall Stewart #define RT_IS_INDIRECT 0x00000001 /* 29620abea66SRandall Stewart * Interface like a lagg, select 29720abea66SRandall Stewart * the actual interface for 29820abea66SRandall Stewart * capabilities. 29920abea66SRandall Stewart */ 30020abea66SRandall Stewart #define RT_IS_SELECTABLE 0x00000002 /* 30120abea66SRandall Stewart * No rate table, you select 30220abea66SRandall Stewart * rates and the first 30320abea66SRandall Stewart * number_of_rates are created. 30420abea66SRandall Stewart */ 30520abea66SRandall Stewart #define RT_IS_FIXED_TABLE 0x00000004 /* A fixed table is attached */ 30620abea66SRandall Stewart #define RT_IS_UNUSABLE 0x00000008 /* It is not usable for this */ 307d7313dc6SRandall Stewart #define RT_IS_SETUP_REQ 0x00000010 /* The interface setup must be called before use */ 30820abea66SRandall Stewart 30920abea66SRandall Stewart struct if_ratelimit_query_results { 31020abea66SRandall Stewart const uint64_t *rate_table; /* Pointer to table if present */ 31120abea66SRandall Stewart uint32_t flags; /* Flags indicating results */ 31220abea66SRandall Stewart uint32_t max_flows; /* Max flows using, 0=unlimited */ 31320abea66SRandall Stewart uint32_t number_of_rates; /* How many unique rates can be created */ 31420abea66SRandall Stewart uint32_t min_segment_burst; /* The amount the adapter bursts at each send */ 31520abea66SRandall Stewart }; 31620abea66SRandall Stewart 31720abea66SRandall Stewart typedef void (if_ratelimit_query_t)(struct ifnet *, 31820abea66SRandall Stewart struct if_ratelimit_query_results *); 319d7313dc6SRandall Stewart typedef int (if_ratelimit_setup_t)(struct ifnet *, uint64_t, uint32_t); 3207687707dSAndrew Gallatin #define IF_NODOM 255 32119ff91c6SGarrett Wollman /* 322de6073aaSRobert Watson * Locks for address lists on the network interface. 323de6073aaSRobert Watson */ 324d7c5a620SMatt Macy #define IF_ADDR_LOCK_INIT(if) mtx_init(&(if)->if_addr_lock, "if_addr_lock", NULL, MTX_DEF) 325d7c5a620SMatt Macy #define IF_ADDR_LOCK_DESTROY(if) mtx_destroy(&(if)->if_addr_lock) 326d7c5a620SMatt Macy 327d7c5a620SMatt Macy #define IF_ADDR_WLOCK(if) mtx_lock(&(if)->if_addr_lock) 328d7c5a620SMatt Macy #define IF_ADDR_WUNLOCK(if) mtx_unlock(&(if)->if_addr_lock) 3296573d758SMatt Macy #define IF_ADDR_LOCK_ASSERT(if) MPASS(in_epoch(net_epoch_preempt) || mtx_owned(&(if)->if_addr_lock)) 330d7c5a620SMatt Macy #define IF_ADDR_WLOCK_ASSERT(if) mtx_assert(&(if)->if_addr_lock, MA_OWNED) 331de6073aaSRobert Watson 332664a31e4SPeter Wemm #ifdef _KERNEL 333ea4ca115SAndrew Thompson /* interface link layer address change event */ 334ea4ca115SAndrew Thompson typedef void (*iflladdr_event_handler_t)(void *, struct ifnet *); 335ea4ca115SAndrew Thompson EVENTHANDLER_DECLARE(iflladdr_event, iflladdr_event_handler_t); 33625a4adceSMax Laier /* interface address change event */ 33725a4adceSMax Laier typedef void (*ifaddr_event_handler_t)(void *, struct ifnet *); 33825a4adceSMax Laier EVENTHANDLER_DECLARE(ifaddr_event, ifaddr_event_handler_t); 33964d63b1eSAndrey V. Elsukov typedef void (*ifaddr_event_ext_handler_t)(void *, struct ifnet *, 34064d63b1eSAndrey V. Elsukov struct ifaddr *, int); 34164d63b1eSAndrey V. Elsukov EVENTHANDLER_DECLARE(ifaddr_event_ext, ifaddr_event_ext_handler_t); 34264d63b1eSAndrey V. Elsukov #define IFADDR_EVENT_ADD 0 34364d63b1eSAndrey V. Elsukov #define IFADDR_EVENT_DEL 1 34425a4adceSMax Laier /* new interface arrival event */ 34525a4adceSMax Laier typedef void (*ifnet_arrival_event_handler_t)(void *, struct ifnet *); 34625a4adceSMax Laier EVENTHANDLER_DECLARE(ifnet_arrival_event, ifnet_arrival_event_handler_t); 34725a4adceSMax Laier /* interface departure event */ 34825a4adceSMax Laier typedef void (*ifnet_departure_event_handler_t)(void *, struct ifnet *); 34925a4adceSMax Laier EVENTHANDLER_DECLARE(ifnet_departure_event, ifnet_departure_event_handler_t); 350e4cd31ddSJeff Roberson /* Interface link state change event */ 351e4cd31ddSJeff Roberson typedef void (*ifnet_link_event_handler_t)(void *, struct ifnet *, int); 352e4cd31ddSJeff Roberson EVENTHANDLER_DECLARE(ifnet_link_event, ifnet_link_event_handler_t); 3536597559eSDexuan Cui /* Interface up/down event */ 3546597559eSDexuan Cui #define IFNET_EVENT_UP 0 3556597559eSDexuan Cui #define IFNET_EVENT_DOWN 1 3564a381a9eSHans Petter Selasky #define IFNET_EVENT_PCP 2 /* priority code point, PCP */ 357f2ab9160SAndrey V. Elsukov #define IFNET_EVENT_UPDATE_BAUDRATE 3 3584a381a9eSHans Petter Selasky 3596597559eSDexuan Cui typedef void (*ifnet_event_fn)(void *, struct ifnet *ifp, int event); 3606597559eSDexuan Cui EVENTHANDLER_DECLARE(ifnet_event, ifnet_event_fn); 36125a4adceSMax Laier 3620dad3f0eSMax Laier /* 3630dad3f0eSMax Laier * interface groups 3640dad3f0eSMax Laier */ 3650dad3f0eSMax Laier struct ifg_group { 3660dad3f0eSMax Laier char ifg_group[IFNAMSIZ]; 3670dad3f0eSMax Laier u_int ifg_refcnt; 3680dad3f0eSMax Laier void *ifg_pf_kif; 3690f8d79d9SMatt Macy CK_STAILQ_HEAD(, ifg_member) ifg_members; /* (CK_) */ 3700f8d79d9SMatt Macy CK_STAILQ_ENTRY(ifg_group) ifg_next; /* (CK_) */ 3710dad3f0eSMax Laier }; 3720dad3f0eSMax Laier 3730dad3f0eSMax Laier struct ifg_member { 3740f8d79d9SMatt Macy CK_STAILQ_ENTRY(ifg_member) ifgm_next; /* (CK_) */ 3750dad3f0eSMax Laier struct ifnet *ifgm_ifp; 3760dad3f0eSMax Laier }; 3770dad3f0eSMax Laier 3780dad3f0eSMax Laier struct ifg_list { 3790dad3f0eSMax Laier struct ifg_group *ifgl_group; 3800f8d79d9SMatt Macy CK_STAILQ_ENTRY(ifg_list) ifgl_next; /* (CK_) */ 3810dad3f0eSMax Laier }; 3820dad3f0eSMax Laier 383eaeb0c13SGleb Smirnoff #ifdef _SYS_EVENTHANDLER_H_ 3840dad3f0eSMax Laier /* group attach event */ 3850dad3f0eSMax Laier typedef void (*group_attach_event_handler_t)(void *, struct ifg_group *); 3860dad3f0eSMax Laier EVENTHANDLER_DECLARE(group_attach_event, group_attach_event_handler_t); 3870dad3f0eSMax Laier /* group detach event */ 3880dad3f0eSMax Laier typedef void (*group_detach_event_handler_t)(void *, struct ifg_group *); 3890dad3f0eSMax Laier EVENTHANDLER_DECLARE(group_detach_event, group_detach_event_handler_t); 3900dad3f0eSMax Laier /* group change event */ 3910dad3f0eSMax Laier typedef void (*group_change_event_handler_t)(void *, const char *); 3920dad3f0eSMax Laier EVENTHANDLER_DECLARE(group_change_event, group_change_event_handler_t); 393eaeb0c13SGleb Smirnoff #endif /* _SYS_EVENTHANDLER_H_ */ 3940dad3f0eSMax Laier 395234a35c7SHajimu UMEMOTO #define IF_AFDATA_LOCK_INIT(ifp) \ 3964f6c66ccSMatt Macy mtx_init(&(ifp)->if_afdata_lock, "if_afdata", NULL, MTX_DEF) 397234a35c7SHajimu UMEMOTO 3984f6c66ccSMatt Macy #define IF_AFDATA_WLOCK(ifp) mtx_lock(&(ifp)->if_afdata_lock) 3994f6c66ccSMatt Macy #define IF_AFDATA_WUNLOCK(ifp) mtx_unlock(&(ifp)->if_afdata_lock) 400991f8615SKip Macy #define IF_AFDATA_LOCK(ifp) IF_AFDATA_WLOCK(ifp) 401991f8615SKip Macy #define IF_AFDATA_UNLOCK(ifp) IF_AFDATA_WUNLOCK(ifp) 4024f6c66ccSMatt Macy #define IF_AFDATA_TRYLOCK(ifp) mtx_trylock(&(ifp)->if_afdata_lock) 4034f6c66ccSMatt Macy #define IF_AFDATA_DESTROY(ifp) mtx_destroy(&(ifp)->if_afdata_lock) 404991f8615SKip Macy 4056573d758SMatt Macy #define IF_AFDATA_LOCK_ASSERT(ifp) MPASS(in_epoch(net_epoch_preempt) || mtx_owned(&(ifp)->if_afdata_lock)) 4064f6c66ccSMatt Macy #define IF_AFDATA_WLOCK_ASSERT(ifp) mtx_assert(&(ifp)->if_afdata_lock, MA_OWNED) 4074f6c66ccSMatt Macy #define IF_AFDATA_UNLOCK_ASSERT(ifp) mtx_assert(&(ifp)->if_afdata_lock, MA_NOTOWNED) 4086e6b3f7cSQing Li 409aab3beeeSBrian Somers /* 410aab3beeeSBrian Somers * 72 was chosen below because it is the size of a TCP/IP 411aab3beeeSBrian Somers * header (40) + the minimum mss (32). 412aab3beeeSBrian Somers */ 413aab3beeeSBrian Somers #define IF_MINMTU 72 414aab3beeeSBrian Somers #define IF_MAXMTU 65535 415aab3beeeSBrian Somers 416c255d1a4SJustin Hibbits #define TOEDEV(ifp) if_getllsoftc(ifp) 417c255d1a4SJustin Hibbits #define SETTOEDEV(ifp, sc) if_setllsoftc((ifp), (sc)) 41809fe6320SNavdeep Parhar 41919ff91c6SGarrett Wollman /* 42019ff91c6SGarrett Wollman * The ifaddr structure contains information about one address 42119ff91c6SGarrett Wollman * of an interface. They are maintained by the different address families, 42219ff91c6SGarrett Wollman * are allocated and attached when an address is set, and are linked 42319ff91c6SGarrett Wollman * together so all addresses for an interface can be located. 424621b79c4SLuigi Rizzo * 425621b79c4SLuigi Rizzo * NOTE: a 'struct ifaddr' is always at the beginning of a larger 426621b79c4SLuigi Rizzo * chunk of malloc'ed memory, where we store the three addresses 427621b79c4SLuigi Rizzo * (ifa_addr, ifa_dstaddr and ifa_netmask) referenced here. 42819ff91c6SGarrett Wollman */ 42919ff91c6SGarrett Wollman struct ifaddr { 43019ff91c6SGarrett Wollman struct sockaddr *ifa_addr; /* address of interface */ 43119ff91c6SGarrett Wollman struct sockaddr *ifa_dstaddr; /* other end of p-to-p link */ 43219ff91c6SGarrett Wollman #define ifa_broadaddr ifa_dstaddr /* broadcast address interface */ 43319ff91c6SGarrett Wollman struct sockaddr *ifa_netmask; /* used to determine subnet */ 43419ff91c6SGarrett Wollman struct ifnet *ifa_ifp; /* back-pointer to interface */ 43508b68b0eSGleb Smirnoff struct carp_softc *ifa_carp; /* pointer to CARP data */ 436fd04260dSMatt Macy CK_STAILQ_ENTRY(ifaddr) ifa_link; /* queue macro glue */ 43719ff91c6SGarrett Wollman u_short ifa_flags; /* mostly rt_flags for cloning */ 438e072c794SGleb Smirnoff #define IFA_ROUTE RTF_UP /* route installed */ 439e072c794SGleb Smirnoff #define IFA_RTSELF RTF_HOST /* loopback route to self installed */ 440e3c1388bSPierre Beyssac u_int ifa_refcnt; /* references to this structure */ 4417caf4ab7SGleb Smirnoff 4427caf4ab7SGleb Smirnoff counter_u64_t ifa_ipackets; 4437caf4ab7SGleb Smirnoff counter_u64_t ifa_opackets; 4447caf4ab7SGleb Smirnoff counter_u64_t ifa_ibytes; 4457caf4ab7SGleb Smirnoff counter_u64_t ifa_obytes; 446d7c5a620SMatt Macy struct epoch_context ifa_epoch_ctx; 44719ff91c6SGarrett Wollman }; 44819ff91c6SGarrett Wollman 44946758960SGleb Smirnoff struct ifaddr * ifa_alloc(size_t size, int flags); 4501099f828SRobert Watson void ifa_free(struct ifaddr *ifa); 4511099f828SRobert Watson void ifa_ref(struct ifaddr *ifa); 4529e5243d7SAlexander V. Chernikov int __result_use_check ifa_try_ref(struct ifaddr *ifa); 45319fc74fbSJeffrey Hsu 4541158dfb7SGarrett Wollman /* 4551158dfb7SGarrett Wollman * Multicast address structure. This is analogous to the ifaddr 4561158dfb7SGarrett Wollman * structure except that it keeps track of multicast addresses. 4571158dfb7SGarrett Wollman */ 458f9be0386SMatt Macy #define IFMA_F_ENQUEUED 0x1 4591158dfb7SGarrett Wollman struct ifmultiaddr { 460fd04260dSMatt Macy CK_STAILQ_ENTRY(ifmultiaddr) ifma_link; /* queue macro glue */ 461373f88edSGarrett Wollman struct sockaddr *ifma_addr; /* address this membership is for */ 462373f88edSGarrett Wollman struct sockaddr *ifma_lladdr; /* link-layer translation, if any */ 463373f88edSGarrett Wollman struct ifnet *ifma_ifp; /* back-pointer to interface */ 464373f88edSGarrett Wollman u_int ifma_refcount; /* reference count */ 465f9be0386SMatt Macy int ifma_flags; 466373f88edSGarrett Wollman void *ifma_protospec; /* protocol-specific state, if any */ 467ec002feeSBruce M Simpson struct ifmultiaddr *ifma_llifma; /* pointer to ifma for ifma_lladdr */ 468d7c5a620SMatt Macy struct epoch_context ifma_epoch_ctx; 4691158dfb7SGarrett Wollman }; 4701158dfb7SGarrett Wollman 47177dfcdc4SRobert Watson extern struct sx ifnet_sxlock; 47277dfcdc4SRobert Watson 473a60100fdSKristof Provost #define IFNET_WLOCK() sx_xlock(&ifnet_sxlock) 474a60100fdSKristof Provost #define IFNET_WUNLOCK() sx_xunlock(&ifnet_sxlock) 47577dfcdc4SRobert Watson #define IFNET_RLOCK_ASSERT() sx_assert(&ifnet_sxlock, SA_SLOCKED) 476a60100fdSKristof Provost #define IFNET_WLOCK_ASSERT() sx_assert(&ifnet_sxlock, SA_XLOCKED) 47777dfcdc4SRobert Watson #define IFNET_RLOCK() sx_slock(&ifnet_sxlock) 47877dfcdc4SRobert Watson #define IFNET_RUNLOCK() sx_sunlock(&ifnet_sxlock) 479b30a244cSJeffrey Hsu 48027d37320SRobert Watson /* 481d74b7baeSGleb Smirnoff * Look up an ifnet given its index. The returned value protected from 482d74b7baeSGleb Smirnoff * being freed by the network epoch. The _ref variant also acquires a 483d74b7baeSGleb Smirnoff * reference that must be freed using if_rele(). 48427d37320SRobert Watson */ 485d74b7baeSGleb Smirnoff struct ifnet *ifnet_byindex(u_int); 486d74b7baeSGleb Smirnoff struct ifnet *ifnet_byindex_ref(u_int); 4871887d35fSKip Macy 4884d7a1361SGleb Smirnoff /* 4894d7a1361SGleb Smirnoff * ifnet_byindexgen() looks up ifnet by index and generation count, 4904d7a1361SGleb Smirnoff * attempting to restore a weak pointer that had been stored across 4914d7a1361SGleb Smirnoff * the epoch. 4924d7a1361SGleb Smirnoff */ 4934d7a1361SGleb Smirnoff struct ifnet *ifnet_byindexgen(uint16_t idx, uint16_t gen); 4944d7a1361SGleb Smirnoff 495eddfbb76SRobert Watson VNET_DECLARE(struct ifnethead, ifnet); 496eddfbb76SRobert Watson VNET_DECLARE(struct ifgrouphead, ifg_head); 497eddfbb76SRobert Watson VNET_DECLARE(struct ifnet *, loif); /* first loopback interface */ 498eddfbb76SRobert Watson 4991e77c105SRobert Watson #define V_ifnet VNET(ifnet) 5001e77c105SRobert Watson #define V_ifg_head VNET(ifg_head) 5011e77c105SRobert Watson #define V_loif VNET(loif) 502eddfbb76SRobert Watson 503b6f6f880SMatt Macy #ifdef MCAST_VERBOSE 504b6f6f880SMatt Macy #define MCDPRINTF printf 505b6f6f880SMatt Macy #else 506b6f6f880SMatt Macy #define MCDPRINTF(...) 507b6f6f880SMatt Macy #endif 508b6f6f880SMatt Macy 5090dad3f0eSMax Laier int if_addgroup(struct ifnet *, const char *); 5100dad3f0eSMax Laier int if_delgroup(struct ifnet *, const char *); 511929ddbbbSAlfred Perlstein int if_addmulti(struct ifnet *, struct sockaddr *, struct ifmultiaddr **); 512929ddbbbSAlfred Perlstein int if_allmulti(struct ifnet *, int); 513ae330108SJustin Hibbits struct ifnet* if_alloc(u_char); 514ae330108SJustin Hibbits struct ifnet* if_alloc_dev(u_char, device_t dev); 515ae330108SJustin Hibbits void if_attach(struct ifnet *); 516111c6b61SRobert Watson void if_dead(struct ifnet *); 517929ddbbbSAlfred Perlstein int if_delmulti(struct ifnet *, struct sockaddr *); 518ec002feeSBruce M Simpson void if_delmulti_ifma(struct ifmultiaddr *); 519b6f6f880SMatt Macy void if_delmulti_ifma_flags(struct ifmultiaddr *, int flags); 520929ddbbbSAlfred Perlstein void if_detach(struct ifnet *); 52145778b37SPeter Edwards void if_purgeaddrs(struct ifnet *); 52293ec7edcSShteryana Shopova void if_delallmulti(struct ifnet *); 523ae330108SJustin Hibbits void if_down(struct ifnet *); 5245896d124SBruce M Simpson struct ifmultiaddr * 525441f9243SAlexander V. Chernikov if_findmulti(struct ifnet *, const struct sockaddr *); 526b6f6f880SMatt Macy void if_freemulti(struct ifmultiaddr *ifma); 527ae330108SJustin Hibbits void if_free(struct ifnet *); 528ae330108SJustin Hibbits void if_initname(struct ifnet *, const char *, int); 529ae330108SJustin Hibbits void if_link_state_change(struct ifnet *, int); 530ae330108SJustin Hibbits int if_printf(struct ifnet *, const char *, ...) __printflike(2, 3); 53125bfa448SAdrian Chadd int if_log(struct ifnet *, int, const char *, ...) __printflike(3, 4); 53227d37320SRobert Watson void if_ref(struct ifnet *); 53327d37320SRobert Watson void if_rele(struct ifnet *); 5349e5243d7SAlexander V. Chernikov bool __result_use_check if_try_ref(struct ifnet *); 535929ddbbbSAlfred Perlstein int if_setlladdr(struct ifnet *, const u_char *, int); 53698a8fdf6SAndrey V. Elsukov int if_tunnel_check_nesting(struct ifnet *, struct mbuf *, uint32_t, int); 537929ddbbbSAlfred Perlstein void if_up(struct ifnet *); 538929ddbbbSAlfred Perlstein int ifioctl(struct socket *, u_long, caddr_t, struct thread *); 539929ddbbbSAlfred Perlstein int ifpromisc(struct ifnet *, int); 540929ddbbbSAlfred Perlstein struct ifnet *ifunit(const char *); 5416064c5d3SRobert Watson struct ifnet *ifunit_ref(const char *); 54219ff91c6SGarrett Wollman 5439bb7d0f4SQing Li int ifa_add_loopback_route(struct ifaddr *, struct sockaddr *); 5449bb7d0f4SQing Li int ifa_del_loopback_route(struct ifaddr *, struct sockaddr *); 54559c180c3SAlexander V. Chernikov int ifa_switch_loopback_route(struct ifaddr *, struct sockaddr *); 5469bb7d0f4SQing Li 547441f9243SAlexander V. Chernikov struct ifaddr *ifa_ifwithaddr(const struct sockaddr *); 548441f9243SAlexander V. Chernikov int ifa_ifwithaddr_check(const struct sockaddr *); 549441f9243SAlexander V. Chernikov struct ifaddr *ifa_ifwithbroadaddr(const struct sockaddr *, int); 550441f9243SAlexander V. Chernikov struct ifaddr *ifa_ifwithdstaddr(const struct sockaddr *, int); 551441f9243SAlexander V. Chernikov struct ifaddr *ifa_ifwithnet(const struct sockaddr *, int, int); 5524d2c2509SAlexander V. Chernikov struct ifaddr *ifa_ifwithroute(int, const struct sockaddr *, 5534d2c2509SAlexander V. Chernikov const struct sockaddr *, u_int); 554441f9243SAlexander V. Chernikov struct ifaddr *ifaof_ifpforaddr(const struct sockaddr *, struct ifnet *); 55524421c1cSGleb Smirnoff int ifa_preferred(struct ifaddr *, struct ifaddr *); 55619ff91c6SGarrett Wollman 557929ddbbbSAlfred Perlstein int if_simloop(struct ifnet *ifp, struct mbuf *m, int af, int hlen); 558373f88edSGarrett Wollman 559fc74a9f9SBrooks Davis typedef void *if_com_alloc_t(u_char type, struct ifnet *ifp); 560fc74a9f9SBrooks Davis typedef void if_com_free_t(void *com, u_char type); 561fc74a9f9SBrooks Davis void if_register_com_alloc(u_char type, if_com_alloc_t *a, if_com_free_t *f); 562fc74a9f9SBrooks Davis void if_deregister_com_alloc(u_char type); 563e6485f73SGleb Smirnoff void if_data_copy(struct ifnet *, struct if_data *); 564ae330108SJustin Hibbits uint64_t if_get_counter_default(struct ifnet *, ift_counter); 565ae330108SJustin Hibbits void if_inc_counter(struct ifnet *, ift_counter, int64_t); 566fc74a9f9SBrooks Davis 567322dcb8dSMax Khon #define IF_LLADDR(ifp) \ 5684a0d6638SRuslan Ermilov LLADDR((struct sockaddr_dl *)((ifp)->if_addr->ifa_addr)) 569322dcb8dSMax Khon 570ae330108SJustin Hibbits uint64_t if_setbaudrate(if_t ifp, uint64_t baudrate); 571ae330108SJustin Hibbits uint64_t if_getbaudrate(const if_t ifp); 572ae330108SJustin Hibbits int if_setcapabilities(if_t ifp, int capabilities); 573ae330108SJustin Hibbits int if_setcapabilitiesbit(if_t ifp, int setbit, int clearbit); 574ae330108SJustin Hibbits int if_getcapabilities(const if_t ifp); 575ae330108SJustin Hibbits int if_togglecapenable(if_t ifp, int togglecap); 576ae330108SJustin Hibbits int if_setcapenable(if_t ifp, int capenable); 577ae330108SJustin Hibbits int if_setcapenablebit(if_t ifp, int setcap, int clearcap); 578ae330108SJustin Hibbits int if_getcapenable(const if_t ifp); 579ae330108SJustin Hibbits int if_getdunit(const if_t ifp); 580ae330108SJustin Hibbits int if_getindex(const if_t ifp); 5811e6131baSJustin Hibbits int if_getidxgen(const if_t ifp); 582ae330108SJustin Hibbits const char *if_getdname(const if_t ifp); 583ae330108SJustin Hibbits void if_setdname(if_t ifp, const char *name); 584ae330108SJustin Hibbits const char *if_name(if_t ifp); 585ae330108SJustin Hibbits int if_setname(if_t ifp, const char *name); 586ae330108SJustin Hibbits void if_setdescr(if_t ifp, char *descrbuf); 587ae330108SJustin Hibbits char *if_allocdescr(size_t sz, int malloc_flag); 588ae330108SJustin Hibbits void if_freedescr(char *descrbuf); 589ae330108SJustin Hibbits int if_getalloctype(const if_t ifp); 590113af4fdSJustin Hibbits int if_gettype(const if_t ifp); 591ae330108SJustin Hibbits int if_setdev(if_t ifp, void *dev); 592ae330108SJustin Hibbits int if_setdrvflagbits(if_t ifp, int if_setflags, int clear_flags); 593ae330108SJustin Hibbits int if_getdrvflags(const if_t ifp); 594ae330108SJustin Hibbits int if_setdrvflags(if_t ifp, int flags); 5950d2684e1SJustin Hibbits int if_getlinkstate(if_t ifp); 596ae330108SJustin Hibbits int if_clearhwassist(if_t ifp); 597ae330108SJustin Hibbits int if_sethwassistbits(if_t ifp, int toset, int toclear); 598ae330108SJustin Hibbits int if_sethwassist(if_t ifp, int hwassist_bit); 599ae330108SJustin Hibbits int if_gethwassist(const if_t ifp); 600ae330108SJustin Hibbits int if_togglehwassist(if_t ifp, int toggle_bits); 601ae330108SJustin Hibbits int if_setsoftc(if_t ifp, void *softc); 602ae330108SJustin Hibbits void *if_getsoftc(if_t ifp); 603ae330108SJustin Hibbits int if_setflags(if_t ifp, int flags); 604c255d1a4SJustin Hibbits void if_setllsoftc(if_t ifp, void *softc); 605c255d1a4SJustin Hibbits void *if_getllsoftc(if_t ifp); 6060d2684e1SJustin Hibbits u_int if_getfib(if_t ifp); 607ae330108SJustin Hibbits int if_gethwaddr(const if_t ifp, struct ifreq *); 6080d2684e1SJustin Hibbits const uint8_t *if_getbroadcastaddr(const if_t ifp); 609ae330108SJustin Hibbits int if_setmtu(if_t ifp, int mtu); 610ae330108SJustin Hibbits int if_getmtu(const if_t ifp); 611ae330108SJustin Hibbits int if_getmtu_family(const if_t ifp, int family); 612ae330108SJustin Hibbits int if_setflagbits(if_t ifp, int set, int clear); 6130d2684e1SJustin Hibbits int if_setflags(if_t ifp, int flags); 614ae330108SJustin Hibbits int if_getflags(const if_t ifp); 6150d2684e1SJustin Hibbits int if_getnumadomain(if_t ifp); 616ae330108SJustin Hibbits int if_sendq_empty(if_t ifp); 617ae330108SJustin Hibbits int if_setsendqready(if_t ifp); 618ae330108SJustin Hibbits int if_setsendqlen(if_t ifp, int tx_desc_count); 619ae330108SJustin Hibbits int if_sethwtsomax(if_t ifp, u_int if_hw_tsomax); 620ae330108SJustin Hibbits int if_sethwtsomaxsegcount(if_t ifp, u_int if_hw_tsomaxsegcount); 621ae330108SJustin Hibbits int if_sethwtsomaxsegsize(if_t ifp, u_int if_hw_tsomaxsegsize); 622ae330108SJustin Hibbits u_int if_gethwtsomax(const if_t ifp); 623ae330108SJustin Hibbits u_int if_gethwtsomaxsegcount(const if_t ifp); 624ae330108SJustin Hibbits u_int if_gethwtsomaxsegsize(const if_t ifp); 6250d2684e1SJustin Hibbits void if_setnetmapadapter(if_t ifp, struct netmap_adapter *na); 6260d2684e1SJustin Hibbits struct netmap_adapter *if_getnetmapadapter(if_t ifp); 627ae330108SJustin Hibbits int if_input(if_t ifp, struct mbuf* sendmp); 628ae330108SJustin Hibbits int if_sendq_prepend(if_t ifp, struct mbuf *m); 629ae330108SJustin Hibbits struct mbuf *if_dequeue(if_t ifp); 630ae330108SJustin Hibbits int if_setifheaderlen(if_t ifp, int len); 631ae330108SJustin Hibbits void if_setrcvif(struct mbuf *m, if_t ifp); 632ae330108SJustin Hibbits void if_setvtag(struct mbuf *m, u_int16_t tag); 633ae330108SJustin Hibbits u_int16_t if_getvtag(struct mbuf *m); 634ae330108SJustin Hibbits int if_vlantrunkinuse(if_t ifp); 635ae330108SJustin Hibbits caddr_t if_getlladdr(const if_t ifp); 6360d2684e1SJustin Hibbits struct vnet *if_getvnet(const if_t ifp); 637ae330108SJustin Hibbits void *if_gethandle(u_char); 638ae330108SJustin Hibbits void if_bpfmtap(if_t ifp, struct mbuf *m); 639ae330108SJustin Hibbits void if_etherbpfmtap(if_t ifp, struct mbuf *m); 640ae330108SJustin Hibbits void if_vlancap(if_t ifp); 641ae330108SJustin Hibbits int if_transmit(if_t ifp, struct mbuf *m); 642fa25dbfdSJustin Hibbits int if_init(if_t ifp, void *ctx); 6430d2684e1SJustin Hibbits uint64_t if_getcounter(if_t ifp, ift_counter counter); 64430af2c13SJustin Hibbits struct label *if_getmaclabel(if_t ifp); 64530af2c13SJustin Hibbits void if_setmaclabel(if_t ifp, struct label *label); 6460d2684e1SJustin Hibbits struct bpf_if *if_getbpf(if_t ifp); 6470d2684e1SJustin Hibbits uint8_t if_getpcp(if_t ifp); 64831cfaf19SJustin Hibbits void *if_getl2com(if_t ifp); 6490d2684e1SJustin Hibbits struct ifvlantrunk *if_getvlantrunk(if_t ifp); 650d79539e6SJustin Hibbits bool if_altq_is_enabled(if_t ifp); 651d79539e6SJustin Hibbits 6520d2684e1SJustin Hibbits void *if_getafdata(if_t ifp, int); 653ae330108SJustin Hibbits 6541e6131baSJustin Hibbits int if_snd_tag_alloc(struct ifnet *ifp, union if_snd_tag_alloc_params *params, 6551e6131baSJustin Hibbits struct m_snd_tag **mstp); 656ae330108SJustin Hibbits /* 657ae330108SJustin Hibbits * Traversing through interface address lists. 658ae330108SJustin Hibbits */ 659ae330108SJustin Hibbits struct sockaddr_dl; 660ae330108SJustin Hibbits typedef u_int iflladdr_cb_t(void *, struct sockaddr_dl *, u_int); 661ae330108SJustin Hibbits u_int if_foreach_lladdr(if_t, iflladdr_cb_t, void *); 662ae330108SJustin Hibbits u_int if_foreach_llmaddr(if_t, iflladdr_cb_t, void *); 663ae330108SJustin Hibbits u_int if_lladdr_count(if_t); 664ae330108SJustin Hibbits u_int if_llmaddr_count(if_t); 665ae330108SJustin Hibbits 666ae330108SJustin Hibbits int if_getamcount(const if_t ifp); 667ae330108SJustin Hibbits struct ifaddr * if_getifaddr(const if_t ifp); 668ae330108SJustin Hibbits typedef u_int if_addr_cb_t(void *, struct ifaddr *, u_int); 669ae330108SJustin Hibbits u_int if_foreach_addr_type(if_t ifp, int type, if_addr_cb_t cb, void *cb_arg); 670ae330108SJustin Hibbits 6712eeb8083SJustin Hibbits typedef int (*if_foreach_cb_t)(if_t, void *); 6722eeb8083SJustin Hibbits int if_foreach(if_foreach_cb_t, void *); 6732eeb8083SJustin Hibbits 674ae330108SJustin Hibbits /* Functions */ 675ae330108SJustin Hibbits void if_setinitfn(if_t ifp, if_init_fn_t); 676ae330108SJustin Hibbits void if_setinputfn(if_t ifp, if_input_fn_t); 6770d2684e1SJustin Hibbits if_input_fn_t if_getinputfn(if_t ifp); 678ae330108SJustin Hibbits void if_setioctlfn(if_t ifp, if_ioctl_fn_t); 6790d2684e1SJustin Hibbits void if_setoutputfn(if_t ifp, if_output_fn_t); 6800d2684e1SJustin Hibbits void if_setstartfn(if_t ifp, if_start_fn_t); 6810d2684e1SJustin Hibbits if_start_fn_t if_getstartfn(if_t ifp); 682ae330108SJustin Hibbits void if_settransmitfn(if_t ifp, if_transmit_fn_t); 6830d2684e1SJustin Hibbits if_transmit_fn_t if_gettransmitfn(if_t ifp); 684ae330108SJustin Hibbits void if_setqflushfn(if_t ifp, if_qflush_fn_t); 685ae330108SJustin Hibbits void if_setgetcounterfn(if_t ifp, if_get_counter_t); 686ae330108SJustin Hibbits void if_setsndtagallocfn(if_t ifp, if_snd_tag_alloc_t); 687053a24d1SJustin Hibbits void if_setdebugnet_methods(struct ifnet *, struct debugnet_methods *); 6880d2684e1SJustin Hibbits void if_setreassignfn(if_t ifp, if_reassign_fn_t); 6890d2684e1SJustin Hibbits void if_setratelimitqueryfn(if_t ifp, if_ratelimit_query_t); 690ae330108SJustin Hibbits 6919fd573c3SHans Petter Selasky /* TSO */ 6929fd573c3SHans Petter Selasky void if_hw_tsomax_common(if_t ifp, struct ifnet_hw_tsomax *); 6939fd573c3SHans Petter Selasky int if_hw_tsomax_update(if_t ifp, struct ifnet_hw_tsomax *); 6949fd573c3SHans Petter Selasky 695ae330108SJustin Hibbits /* accessors for struct ifreq */ 696ae330108SJustin Hibbits void *ifr_data_get_ptr(void *ifrp); 697ae330108SJustin Hibbits void *ifr_buffer_get_buffer(void *data); 698ae330108SJustin Hibbits size_t ifr_buffer_get_length(void *data); 699ae330108SJustin Hibbits 7001687b1abSMichael Tuexen int ifhwioctl(u_long, struct ifnet *, caddr_t, struct thread *); 7011687b1abSMichael Tuexen 702ae330108SJustin Hibbits #ifdef DEVICE_POLLING 703ae330108SJustin Hibbits enum poll_cmd { POLL_ONLY, POLL_AND_CHECK_STATUS }; 704ae330108SJustin Hibbits 705ae330108SJustin Hibbits typedef int poll_handler_t(if_t ifp, enum poll_cmd cmd, int count); 706ae330108SJustin Hibbits int ether_poll_register(poll_handler_t *h, if_t ifp); 707ae330108SJustin Hibbits int ether_poll_deregister(if_t ifp); 708ae330108SJustin Hibbits #endif /* DEVICE_POLLING */ 709ae330108SJustin Hibbits 710664a31e4SPeter Wemm #endif /* _KERNEL */ 711cbaac009SBjoern A. Zeeb 7122c2b37adSJustin Hibbits #include <net/if_private.h> /* XXX: temporary until drivers converted. */ 713cbaac009SBjoern A. Zeeb #include <net/ifq.h> /* XXXAO: temporary unconditional include */ 714cbaac009SBjoern A. Zeeb 71519ff91c6SGarrett Wollman #endif /* !_NET_IF_VAR_H_ */ 716