1139823Simp/*- 21541Srgrimes * Copyright (c) 1982, 1986, 1989, 1993 31541Srgrimes * The Regents of the University of California. All rights reserved. 41541Srgrimes * 51541Srgrimes * Redistribution and use in source and binary forms, with or without 61541Srgrimes * modification, are permitted provided that the following conditions 71541Srgrimes * are met: 81541Srgrimes * 1. Redistributions of source code must retain the above copyright 91541Srgrimes * notice, this list of conditions and the following disclaimer. 101541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 111541Srgrimes * notice, this list of conditions and the following disclaimer in the 121541Srgrimes * documentation and/or other materials provided with the distribution. 131541Srgrimes * 4. Neither the name of the University nor the names of its contributors 141541Srgrimes * may be used to endorse or promote products derived from this software 151541Srgrimes * without specific prior written permission. 161541Srgrimes * 171541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 181541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 191541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 201541Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 211541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 221541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 231541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 241541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 251541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 261541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 271541Srgrimes * SUCH DAMAGE. 281541Srgrimes * 291541Srgrimes * @(#)if.h 8.1 (Berkeley) 6/10/93 3050477Speter * $FreeBSD: stable/11/sys/net/if.h 368645 2020-12-14 22:03:13Z brooks $ 311541Srgrimes */ 321541Srgrimes 332168Spaul#ifndef _NET_IF_H_ 344507Sbde#define _NET_IF_H_ 352168Spaul 36104355Smike#include <sys/cdefs.h> 37104355Smike 38104355Smike#if __BSD_VISIBLE 391541Srgrimes/* 4034750Speter * <net/if.h> does not depend on <sys/time.h> on most other systems. This 4172093Sasmodai * helps userland compatibility. (struct timeval ifi_lastchange) 42226610Sed * The same holds for <sys/socket.h>. (struct sockaddr ifru_addr) 4334750Speter */ 4455205Speter#ifndef _KERNEL 4534750Speter#include <sys/time.h> 46226610Sed#include <sys/socket.h> 4734750Speter#endif 48104355Smike#endif 4979103Sbrooks 5034750Speter/* 5179103Sbrooks * Length of interface external name, including terminating '\0'. 5279103Sbrooks * Note: this is the same size as a generic device's external name. 5379103Sbrooks */ 54104355Smike#define IF_NAMESIZE 16 55104355Smike#if __BSD_VISIBLE 56104355Smike#define IFNAMSIZ IF_NAMESIZE 57121816Sbrooks#define IF_MAXUNIT 0x7fff /* historical value */ 58104355Smike#endif 59104355Smike#if __BSD_VISIBLE 60104355Smike 6179103Sbrooks/* 6279103Sbrooks * Structure used to query names of interface cloners. 6379103Sbrooks */ 6479103Sbrooks 6579103Sbrooksstruct if_clonereq { 6679103Sbrooks int ifcr_total; /* total cloners (out) */ 6779103Sbrooks int ifcr_count; /* room for this many in user buffer */ 6879103Sbrooks char *ifcr_buffer; /* buffer for cloner names */ 6979103Sbrooks}; 7079103Sbrooks 7179103Sbrooks/* 7219079Sfenner * Structure describing information about an interface 7319079Sfenner * which may be of interest to management entities. 7419079Sfenner */ 759457Sjoergstruct if_data { 769457Sjoerg /* generic interface information */ 77263102Sglebius uint8_t ifi_type; /* ethernet, tokenring, etc */ 78263102Sglebius uint8_t ifi_physical; /* e.g., AUI, Thinnet, 10base-T, etc */ 79263102Sglebius uint8_t ifi_addrlen; /* media address length */ 80263102Sglebius uint8_t ifi_hdrlen; /* media header length */ 81263102Sglebius uint8_t ifi_link_state; /* current link state */ 82263102Sglebius uint8_t ifi_vhid; /* carp vhid */ 83263102Sglebius uint16_t ifi_datalen; /* length of this data struct */ 84263102Sglebius uint32_t ifi_mtu; /* maximum transmission unit */ 85263102Sglebius uint32_t ifi_metric; /* routing metric (external only) */ 86263102Sglebius uint64_t ifi_baudrate; /* linespeed */ 879457Sjoerg /* volatile statistics */ 88263102Sglebius uint64_t ifi_ipackets; /* packets received on interface */ 89263102Sglebius uint64_t ifi_ierrors; /* input errors on interface */ 90263102Sglebius uint64_t ifi_opackets; /* packets sent on interface */ 91263102Sglebius uint64_t ifi_oerrors; /* output errors on interface */ 92263102Sglebius uint64_t ifi_collisions; /* collisions on csma interfaces */ 93263102Sglebius uint64_t ifi_ibytes; /* total number of octets received */ 94263102Sglebius uint64_t ifi_obytes; /* total number of octets sent */ 95263102Sglebius uint64_t ifi_imcasts; /* packets received via multicast */ 96263102Sglebius uint64_t ifi_omcasts; /* packets sent via multicast */ 97263102Sglebius uint64_t ifi_iqdrops; /* dropped on input */ 98263102Sglebius uint64_t ifi_oqdrops; /* dropped on output */ 99263102Sglebius uint64_t ifi_noproto; /* destined for unsupported protocol */ 100263102Sglebius uint64_t ifi_hwassist; /* HW offload capabilities, see IFCAP */ 101263102Sglebius 102263102Sglebius /* Unions are here to make sizes MI. */ 103263102Sglebius union { /* uptime at attach or stat reset */ 104263102Sglebius time_t tt; 105263102Sglebius uint64_t ph; 106263102Sglebius } __ifi_epoch; 107263102Sglebius#define ifi_epoch __ifi_epoch.tt 108263102Sglebius union { /* time of last administrative change */ 109263102Sglebius struct timeval tv; 110263102Sglebius struct { 111263102Sglebius uint64_t ph1; 112263102Sglebius uint64_t ph2; 113263102Sglebius } ph; 114263102Sglebius } __ifi_lastchange; 115263102Sglebius#define ifi_lastchange __ifi_lastchange.tv 1169457Sjoerg}; 1179457Sjoerg 118148894Srwatson/*- 119148886Srwatson * Interface flags are of two types: network stack owned flags, and driver 120148886Srwatson * owned flags. Historically, these values were stored in the same ifnet 121148886Srwatson * flags field, but with the advent of fine-grained locking, they have been 122148886Srwatson * broken out such that the network stack is responsible for synchronizing 123148886Srwatson * the stack-owned fields, and the device driver the device-owned fields. 124148886Srwatson * Both halves can perform lockless reads of the other half's field, subject 125148886Srwatson * to accepting the involved races. 126148886Srwatson * 127148886Srwatson * Both sets of flags come from the same number space, and should not be 128148886Srwatson * permitted to conflict, as they are exposed to user space via a single 129148886Srwatson * field. 130148886Srwatson * 131148894Srwatson * The following symbols identify read and write requirements for fields: 132148894Srwatson * 133148894Srwatson * (i) if_flags field set by device driver before attach, read-only there 134148894Srwatson * after. 135148894Srwatson * (n) if_flags field written only by the network stack, read by either the 136148894Srwatson * stack or driver. 137148894Srwatson * (d) if_drv_flags field written only by the device driver, read by either 138148894Srwatson * the stack or driver. 139148886Srwatson */ 140148894Srwatson#define IFF_UP 0x1 /* (n) interface is up */ 141148894Srwatson#define IFF_BROADCAST 0x2 /* (i) broadcast address valid */ 142148894Srwatson#define IFF_DEBUG 0x4 /* (n) turn on debugging */ 143148894Srwatson#define IFF_LOOPBACK 0x8 /* (i) is a loopback net */ 144148894Srwatson#define IFF_POINTOPOINT 0x10 /* (i) is a point-to-point link */ 145257699Sglebius/* 0x20 was IFF_SMART */ 146148894Srwatson#define IFF_DRV_RUNNING 0x40 /* (d) resources allocated */ 147148894Srwatson#define IFF_NOARP 0x80 /* (n) no address resolution protocol */ 148148894Srwatson#define IFF_PROMISC 0x100 /* (n) receive all packets */ 149148894Srwatson#define IFF_ALLMULTI 0x200 /* (n) receive all multicast packets */ 150148894Srwatson#define IFF_DRV_OACTIVE 0x400 /* (d) tx hardware queue is full */ 151148894Srwatson#define IFF_SIMPLEX 0x800 /* (i) can't hear own transmissions */ 1521541Srgrimes#define IFF_LINK0 0x1000 /* per link layer defined bit */ 1531541Srgrimes#define IFF_LINK1 0x2000 /* per link layer defined bit */ 1541541Srgrimes#define IFF_LINK2 0x4000 /* per link layer defined bit */ 1553274Swollman#define IFF_ALTPHYS IFF_LINK2 /* use alternate physical connection */ 156148894Srwatson#define IFF_MULTICAST 0x8000 /* (i) supports multicast */ 157216267Sweongyo#define IFF_CANTCONFIG 0x10000 /* (i) unconfigurable using ioctl(2) */ 158148894Srwatson#define IFF_PPROMISC 0x20000 /* (n) user-requested promisc mode */ 159148894Srwatson#define IFF_MONITOR 0x40000 /* (n) user-requested monitor mode */ 160148894Srwatson#define IFF_STATICARP 0x80000 /* (n) static ARP */ 161191416Srwatson#define IFF_DYING 0x200000 /* (n) interface is winding down */ 162201196Sjhb#define IFF_RENAMING 0x400000 /* (n) interface is being renamed */ 163148886Srwatson/* 164148886Srwatson * Old names for driver flags so that user space tools can continue to use 165148894Srwatson * the old (portable) names. 166148886Srwatson */ 167148886Srwatson#ifndef _KERNEL 168148886Srwatson#define IFF_RUNNING IFF_DRV_RUNNING 169148886Srwatson#define IFF_OACTIVE IFF_DRV_OACTIVE 170148886Srwatson#endif 171148886Srwatson 1721541Srgrimes/* flags set internally only: */ 1731541Srgrimes#define IFF_CANTCHANGE \ 174148886Srwatson (IFF_BROADCAST|IFF_POINTOPOINT|IFF_DRV_RUNNING|IFF_DRV_OACTIVE|\ 175257699Sglebius IFF_SIMPLEX|IFF_MULTICAST|IFF_ALLMULTI|IFF_PROMISC|\ 176216268Sweongyo IFF_DYING|IFF_CANTCONFIG) 1771541Srgrimes 178106925Ssam/* 179128871Sandre * Values for if_link_state. 180128871Sandre */ 181128871Sandre#define LINK_STATE_UNKNOWN 0 /* link invalid/unknown */ 182128871Sandre#define LINK_STATE_DOWN 1 /* link is down */ 183128871Sandre#define LINK_STATE_UP 2 /* link is up */ 184128871Sandre 185128871Sandre/* 186106925Ssam * Some convenience macros used for setting ifi_baudrate. 187106925Ssam * XXX 1000 vs. 1024? --thorpej@netbsd.org 188106925Ssam */ 189241646Semax#define IF_Kbps(x) ((uintmax_t)(x) * 1000) /* kilobits/sec. */ 190106925Ssam#define IF_Mbps(x) (IF_Kbps((x) * 1000)) /* megabits/sec. */ 191106925Ssam#define IF_Gbps(x) (IF_Mbps((x) * 1000)) /* gigabits/sec. */ 192106925Ssam 193162070Sandre/* 194162070Sandre * Capabilities that interfaces can advertise. 195162070Sandre * 196162070Sandre * struct ifnet.if_capabilities 197162070Sandre * contains the optional features & capabilities a particular interface 198162070Sandre * supports (not only the driver but also the detected hw revision). 199162070Sandre * Capabilities are defined by IFCAP_* below. 200169207Syar * struct ifnet.if_capenable 201162070Sandre * contains the enabled (either by default or through ifconfig) optional 202162070Sandre * features & capabilities on this interface. 203162070Sandre * Capabilities are defined by IFCAP_* below. 204162070Sandre * struct if_data.ifi_hwassist in mbuf CSUM_ flag form, controlled by above 205162070Sandre * contains the enabled optional feature & capabilites that can be used 206162070Sandre * individually per packet and are specified in the mbuf pkthdr.csum_flags 207162070Sandre * field. IFCAP_* and CSUM_* do not match one to one and CSUM_* may be 208366618Skib * more detailed or differentiated than IFCAP_*. 209162070Sandre * Hwassist features are defined CSUM_* in sys/mbuf.h 210223078Sluigi * 211223078Sluigi * Capabilities that cannot be arbitrarily changed with ifconfig/ioctl 212223078Sluigi * are listed in IFCAP_CANTCHANGE, similar to IFF_CANTCHANGE. 213223078Sluigi * This is not strictly necessary because the common code never 214223078Sluigi * changes capabilities, and it is left to the individual driver 215223078Sluigi * to do the right thing. However, having the filter here 216223078Sluigi * avoids replication of the same code in all individual drivers. 217162070Sandre */ 218182413Sjfv#define IFCAP_RXCSUM 0x00001 /* can offload checksum on RX */ 219182413Sjfv#define IFCAP_TXCSUM 0x00002 /* can offload checksum on TX */ 220182413Sjfv#define IFCAP_NETCONS 0x00004 /* can be a network console */ 221182413Sjfv#define IFCAP_VLAN_MTU 0x00008 /* VLAN-compatible MTU */ 222182413Sjfv#define IFCAP_VLAN_HWTAGGING 0x00010 /* hardware VLAN tag support */ 223182413Sjfv#define IFCAP_JUMBO_MTU 0x00020 /* 9000 byte MTU supported */ 224182413Sjfv#define IFCAP_POLLING 0x00040 /* driver supports polling */ 225182413Sjfv#define IFCAP_VLAN_HWCSUM 0x00080 /* can do IFCAP_HWCSUM on VLANs */ 226182413Sjfv#define IFCAP_TSO4 0x00100 /* can do TCP Segmentation Offload */ 227182413Sjfv#define IFCAP_TSO6 0x00200 /* can do TCP6 Segmentation Offload */ 228182413Sjfv#define IFCAP_LRO 0x00400 /* can do Large Receive Offload */ 229182413Sjfv#define IFCAP_WOL_UCAST 0x00800 /* wake on any unicast frame */ 230182413Sjfv#define IFCAP_WOL_MCAST 0x01000 /* wake on any multicast frame */ 231182413Sjfv#define IFCAP_WOL_MAGIC 0x02000 /* wake on any Magic Packet */ 232182413Sjfv#define IFCAP_TOE4 0x04000 /* interface can offload TCP */ 233182413Sjfv#define IFCAP_TOE6 0x08000 /* interface can offload TCP6 */ 234182413Sjfv#define IFCAP_VLAN_HWFILTER 0x10000 /* interface hw can filter vlan tag */ 235193096Sattilio#define IFCAP_POLLING_NOCOUNT 0x20000 /* polling ticks cannot be fragmented */ 236204149Syongari#define IFCAP_VLAN_HWTSO 0x40000 /* can do IFCAP_TSO on VLANs */ 237205222Sqingli#define IFCAP_LINKSTATE 0x80000 /* the runtime link state is dynamic */ 238223078Sluigi#define IFCAP_NETMAP 0x100000 /* netmap mode supported/enabled */ 239236170Sbz#define IFCAP_RXCSUM_IPV6 0x200000 /* can offload checksum on IPv6 RX */ 240236170Sbz#define IFCAP_TXCSUM_IPV6 0x400000 /* can offload checksum on IPv6 TX */ 241256218Sglebius#define IFCAP_HWSTATS 0x800000 /* manages counters internally */ 24283624Sjlemon 243236170Sbz#define IFCAP_HWCSUM_IPV6 (IFCAP_RXCSUM_IPV6 | IFCAP_TXCSUM_IPV6) 244236170Sbz 245174505Ssam#define IFCAP_HWCSUM (IFCAP_RXCSUM | IFCAP_TXCSUM) 246174505Ssam#define IFCAP_TSO (IFCAP_TSO4 | IFCAP_TSO6) 247174505Ssam#define IFCAP_WOL (IFCAP_WOL_UCAST | IFCAP_WOL_MCAST | IFCAP_WOL_MAGIC) 248174628Skmacy#define IFCAP_TOE (IFCAP_TOE4 | IFCAP_TOE6) 24983636Sjlemon 250223078Sluigi#define IFCAP_CANTCHANGE (IFCAP_NETMAP) 251223078Sluigi 2521541Srgrimes#define IFQ_MAXLEN 50 2531541Srgrimes#define IFNET_SLOWHZ 1 /* granularity is 1 second */ 2541541Srgrimes 2551541Srgrimes/* 2561541Srgrimes * Message format for use in obtaining information about interfaces 2571541Srgrimes * from getkerninfo and the routing socket 258231505Sbz * For the new, extensible interface see struct if_msghdrl below. 2591541Srgrimes */ 2601541Srgrimesstruct if_msghdr { 2611541Srgrimes u_short ifm_msglen; /* to skip over non-understood messages */ 26272093Sasmodai u_char ifm_version; /* future binary compatibility */ 2631541Srgrimes u_char ifm_type; /* message type */ 2641541Srgrimes int ifm_addrs; /* like rtm_addrs */ 2651541Srgrimes int ifm_flags; /* value of if_flags */ 2661541Srgrimes u_short ifm_index; /* index for associated ifp */ 267341241Smarkj u_short _ifm_spare1; 2681541Srgrimes struct if_data ifm_data;/* statistics and other data about if */ 2691541Srgrimes}; 2701541Srgrimes 2711541Srgrimes/* 272231505Sbz * The 'l' version shall be used by new interfaces, like NET_RT_IFLISTL. It is 273231505Sbz * extensible after ifm_data_off or within ifm_data. Both the if_msghdr and 274231505Sbz * if_data now have a member field detailing the struct length in addition to 275231505Sbz * the routing message length. Macros are provided to find the start of 276231505Sbz * ifm_data and the start of the socket address strucutres immediately following 277231505Sbz * struct if_msghdrl given a pointer to struct if_msghdrl. 278231505Sbz */ 279231505Sbz#define IF_MSGHDRL_IFM_DATA(_l) \ 280231505Sbz (struct if_data *)((char *)(_l) + (_l)->ifm_data_off) 281231505Sbz#define IF_MSGHDRL_RTA(_l) \ 282231505Sbz (void *)((uintptr_t)(_l) + (_l)->ifm_len) 283231505Sbzstruct if_msghdrl { 284231505Sbz u_short ifm_msglen; /* to skip over non-understood messages */ 285231505Sbz u_char ifm_version; /* future binary compatibility */ 286231505Sbz u_char ifm_type; /* message type */ 287231505Sbz int ifm_addrs; /* like rtm_addrs */ 288231505Sbz int ifm_flags; /* value of if_flags */ 289231505Sbz u_short ifm_index; /* index for associated ifp */ 290231505Sbz u_short _ifm_spare1; /* spare space to grow if_index, see if_var.h */ 291231505Sbz u_short ifm_len; /* length of if_msghdrl incl. if_data */ 292231505Sbz u_short ifm_data_off; /* offset of if_data from beginning */ 293341241Smarkj int _ifm_spare2; 294231505Sbz struct if_data ifm_data;/* statistics and other data about if */ 295231505Sbz}; 296231505Sbz 297231505Sbz/* 2981541Srgrimes * Message format for use in obtaining information about interface addresses 2991541Srgrimes * from getkerninfo and the routing socket 300231505Sbz * For the new, extensible interface see struct ifa_msghdrl below. 3011541Srgrimes */ 3021541Srgrimesstruct ifa_msghdr { 3031541Srgrimes u_short ifam_msglen; /* to skip over non-understood messages */ 30472093Sasmodai u_char ifam_version; /* future binary compatibility */ 3051541Srgrimes u_char ifam_type; /* message type */ 3061541Srgrimes int ifam_addrs; /* like rtm_addrs */ 3071541Srgrimes int ifam_flags; /* value of ifa_flags */ 3081541Srgrimes u_short ifam_index; /* index for associated ifp */ 309341241Smarkj u_short _ifam_spare1; 310269243Sglebius int ifam_metric; /* value of ifa_ifp->if_metric */ 3111541Srgrimes}; 3121541Srgrimes 3131541Srgrimes/* 314231505Sbz * The 'l' version shall be used by new interfaces, like NET_RT_IFLISTL. It is 315231505Sbz * extensible after ifam_metric or within ifam_data. Both the ifa_msghdrl and 316231505Sbz * if_data now have a member field detailing the struct length in addition to 317231505Sbz * the routing message length. Macros are provided to find the start of 318231505Sbz * ifm_data and the start of the socket address strucutres immediately following 319231505Sbz * struct ifa_msghdrl given a pointer to struct ifa_msghdrl. 320231505Sbz */ 321231505Sbz#define IFA_MSGHDRL_IFAM_DATA(_l) \ 322231505Sbz (struct if_data *)((char *)(_l) + (_l)->ifam_data_off) 323231505Sbz#define IFA_MSGHDRL_RTA(_l) \ 324231505Sbz (void *)((uintptr_t)(_l) + (_l)->ifam_len) 325231505Sbzstruct ifa_msghdrl { 326231505Sbz u_short ifam_msglen; /* to skip over non-understood messages */ 327231505Sbz u_char ifam_version; /* future binary compatibility */ 328231505Sbz u_char ifam_type; /* message type */ 329231505Sbz int ifam_addrs; /* like rtm_addrs */ 330231505Sbz int ifam_flags; /* value of ifa_flags */ 331231505Sbz u_short ifam_index; /* index for associated ifp */ 332231505Sbz u_short _ifam_spare1; /* spare space to grow if_index, see if_var.h */ 333231505Sbz u_short ifam_len; /* length of ifa_msghdrl incl. if_data */ 334231505Sbz u_short ifam_data_off; /* offset of if_data from beginning */ 335269243Sglebius int ifam_metric; /* value of ifa_ifp->if_metric */ 336231505Sbz struct if_data ifam_data;/* statistics and other data about if or 337231505Sbz * address */ 338231505Sbz}; 339231505Sbz 340231505Sbz/* 34121666Swollman * Message format for use in obtaining information about multicast addresses 34221666Swollman * from the routing socket 34321666Swollman */ 34421666Swollmanstruct ifma_msghdr { 34521666Swollman u_short ifmam_msglen; /* to skip over non-understood messages */ 34672093Sasmodai u_char ifmam_version; /* future binary compatibility */ 34721666Swollman u_char ifmam_type; /* message type */ 34821666Swollman int ifmam_addrs; /* like rtm_addrs */ 34921666Swollman int ifmam_flags; /* value of ifa_flags */ 35021666Swollman u_short ifmam_index; /* index for associated ifp */ 351341241Smarkj u_short _ifmam_spare1; 35221666Swollman}; 35321666Swollman 35421666Swollman/* 35589498Sru * Message format announcing the arrival or departure of a network interface. 35689498Sru */ 35789498Srustruct if_announcemsghdr { 35889498Sru u_short ifan_msglen; /* to skip over non-understood messages */ 35989498Sru u_char ifan_version; /* future binary compatibility */ 36089498Sru u_char ifan_type; /* message type */ 36189498Sru u_short ifan_index; /* index for associated ifp */ 36289498Sru char ifan_name[IFNAMSIZ]; /* if name, e.g. "en0" */ 36389498Sru u_short ifan_what; /* what type of announcement */ 36489498Sru}; 36589498Sru 36689498Sru#define IFAN_ARRIVAL 0 /* interface arrival */ 36789498Sru#define IFAN_DEPARTURE 1 /* interface departure */ 36889498Sru 36989498Sru/* 370203052Sdelphij * Buffer with length to be used in SIOCGIFDESCR/SIOCSIFDESCR requests 371203052Sdelphij */ 372203052Sdelphijstruct ifreq_buffer { 373203052Sdelphij size_t length; 374203052Sdelphij void *buffer; 375203052Sdelphij}; 376203052Sdelphij 377203052Sdelphij/* 3781541Srgrimes * Interface request structure used for socket 3791541Srgrimes * ioctl's. All interface ioctl's must have parameter 3801541Srgrimes * definitions which begin with ifr_name. The 3811541Srgrimes * remainder may be interface specific. 3821541Srgrimes */ 383368645Sbrooksstruct ifreq { 3841541Srgrimes char ifr_name[IFNAMSIZ]; /* if name, e.g. "en0" */ 3851541Srgrimes union { 3861541Srgrimes struct sockaddr ifru_addr; 3871541Srgrimes struct sockaddr ifru_dstaddr; 3881541Srgrimes struct sockaddr ifru_broadaddr; 389203052Sdelphij struct ifreq_buffer ifru_buffer; 39044144Sphk short ifru_flags[2]; 39185079Sjlemon short ifru_index; 392194251Sjamie int ifru_jid; 3931541Srgrimes int ifru_metric; 3941941Sdg int ifru_mtu; 3955184Swollman int ifru_phys; 39625434Speter int ifru_media; 3971541Srgrimes caddr_t ifru_data; 39883624Sjlemon int ifru_cap[2]; 399223735Sbz u_int ifru_fib; 400301496Saraujo u_char ifru_vlan_pcp; 4011541Srgrimes } ifr_ifru; 4021541Srgrimes#define ifr_addr ifr_ifru.ifru_addr /* address */ 4031541Srgrimes#define ifr_dstaddr ifr_ifru.ifru_dstaddr /* other end of p-to-p link */ 4041541Srgrimes#define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */ 405332281Sbrooks#ifndef _KERNEL 406203052Sdelphij#define ifr_buffer ifr_ifru.ifru_buffer /* user supplied buffer with its length */ 407332281Sbrooks#endif 408102052Ssobomax#define ifr_flags ifr_ifru.ifru_flags[0] /* flags (low 16 bits) */ 409102052Ssobomax#define ifr_flagshigh ifr_ifru.ifru_flags[1] /* flags (high 16 bits) */ 410194251Sjamie#define ifr_jid ifr_ifru.ifru_jid /* jail/vnet */ 4111541Srgrimes#define ifr_metric ifr_ifru.ifru_metric /* metric */ 4121941Sdg#define ifr_mtu ifr_ifru.ifru_mtu /* mtu */ 4135187Sdg#define ifr_phys ifr_ifru.ifru_phys /* physical wire */ 41425434Speter#define ifr_media ifr_ifru.ifru_media /* physical media */ 415332288Sbrooks#ifndef _KERNEL 4161541Srgrimes#define ifr_data ifr_ifru.ifru_data /* for use by interface */ 417332288Sbrooks#endif 41883624Sjlemon#define ifr_reqcap ifr_ifru.ifru_cap[0] /* requested capabilities */ 41983624Sjlemon#define ifr_curcap ifr_ifru.ifru_cap[1] /* current capabilities */ 42085079Sjlemon#define ifr_index ifr_ifru.ifru_index /* interface index */ 421223735Sbz#define ifr_fib ifr_ifru.ifru_fib /* interface fib */ 422301496Saraujo#define ifr_vlan_pcp ifr_ifru.ifru_vlan_pcp /* VLAN priority */ 423332991Skib#define ifr_lan_pcp ifr_ifru.ifru_vlan_pcp /* VLAN priority */ 4241541Srgrimes}; 4251541Srgrimes 42632491Swollman#define _SIZEOF_ADDR_IFREQ(ifr) \ 42732491Swollman ((ifr).ifr_addr.sa_len > sizeof(struct sockaddr) ? \ 42832491Swollman (sizeof(struct ifreq) - sizeof(struct sockaddr) + \ 42932491Swollman (ifr).ifr_addr.sa_len) : sizeof(struct ifreq)) 43032491Swollman 4311541Srgrimesstruct ifaliasreq { 4321541Srgrimes char ifra_name[IFNAMSIZ]; /* if name, e.g. "en0" */ 4331541Srgrimes struct sockaddr ifra_addr; 4341541Srgrimes struct sockaddr ifra_broadaddr; 4351541Srgrimes struct sockaddr ifra_mask; 436228571Sglebius int ifra_vhid; 4371541Srgrimes}; 4381541Srgrimes 439257761Sglebius/* 9.x compat */ 440257761Sglebiusstruct oifaliasreq { 441257761Sglebius char ifra_name[IFNAMSIZ]; 442257761Sglebius struct sockaddr ifra_addr; 443257761Sglebius struct sockaddr ifra_broadaddr; 444257761Sglebius struct sockaddr ifra_mask; 445257761Sglebius}; 446257761Sglebius 44725434Speterstruct ifmediareq { 44825434Speter char ifm_name[IFNAMSIZ]; /* if name, e.g. "en0" */ 44925434Speter int ifm_current; /* current media options */ 45025434Speter int ifm_mask; /* don't care mask */ 45125434Speter int ifm_status; /* media status */ 45225434Speter int ifm_active; /* active options */ 45325434Speter int ifm_count; /* # entries in ifm_ulist array */ 45425434Speter int *ifm_ulist; /* media words */ 45525434Speter}; 45648021Sphk 457368645Sbrooksstruct ifdrv { 458368645Sbrooks char ifd_name[IFNAMSIZ]; /* if name, e.g. "en0" */ 459368645Sbrooks unsigned long ifd_cmd; 460368645Sbrooks size_t ifd_len; 461368645Sbrooks void *ifd_data; 462146986Sthompsa}; 463146986Sthompsa 46448021Sphk/* 46548021Sphk * Structure used to retrieve aux status data from interfaces. 46648589Sbde * Kernel suppliers to this interface should respect the formatting 46748021Sphk * needed by ifconfig(8): each line starts with a TAB and ends with 46848589Sbde * a newline. The canonical example to copy and paste is in if_tun.c. 46948021Sphk */ 47048021Sphk 47148589Sbde#define IFSTATMAX 800 /* 10 lines of text */ 47248021Sphkstruct ifstat { 47348589Sbde char ifs_name[IFNAMSIZ]; /* if name, e.g. "en0" */ 47448589Sbde char ascii[IFSTATMAX + 1]; 47548021Sphk}; 47648021Sphk 4771541Srgrimes/* 4781541Srgrimes * Structure used in SIOCGIFCONF request. 4791541Srgrimes * Used to retrieve interface configuration 4801541Srgrimes * for machine (useful for programs which 4811541Srgrimes * must know all networks accessible). 4821541Srgrimes */ 483368645Sbrooksstruct ifconf { 4841541Srgrimes int ifc_len; /* size of associated buffer */ 4851541Srgrimes union { 4861541Srgrimes caddr_t ifcu_buf; 4871541Srgrimes struct ifreq *ifcu_req; 4881541Srgrimes } ifc_ifcu; 4891541Srgrimes#define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */ 4901541Srgrimes#define ifc_req ifc_ifcu.ifcu_req /* array of structures returned */ 4911541Srgrimes}; 4921541Srgrimes 49352904Sshin/* 494159781Smlaier * interface groups 495159781Smlaier */ 496159781Smlaier 497159781Smlaier#define IFG_ALL "all" /* group contains all interfaces */ 498159781Smlaier/* XXX: will we implement this? */ 499159781Smlaier#define IFG_EGRESS "egress" /* if(s) default route(s) point to */ 500159781Smlaier 501159781Smlaierstruct ifg_req { 502159781Smlaier union { 503159781Smlaier char ifgrqu_group[IFNAMSIZ]; 504159781Smlaier char ifgrqu_member[IFNAMSIZ]; 505159781Smlaier } ifgrq_ifgrqu; 506159781Smlaier#define ifgrq_group ifgrq_ifgrqu.ifgrqu_group 507159781Smlaier#define ifgrq_member ifgrq_ifgrqu.ifgrqu_member 508159781Smlaier}; 509159781Smlaier 510159781Smlaier/* 511159781Smlaier * Used to lookup groups for an interface 512159781Smlaier */ 513159781Smlaierstruct ifgroupreq { 514159781Smlaier char ifgr_name[IFNAMSIZ]; 515159781Smlaier u_int ifgr_len; 516159781Smlaier union { 517159781Smlaier char ifgru_group[IFNAMSIZ]; 518159781Smlaier struct ifg_req *ifgru_groups; 519159781Smlaier } ifgr_ifgru; 520332493Sbrooks#ifndef _KERNEL 521159781Smlaier#define ifgr_group ifgr_ifgru.ifgru_group 522159781Smlaier#define ifgr_groups ifgr_ifgru.ifgru_groups 523332493Sbrooks#endif 524159781Smlaier}; 525159781Smlaier 526270822Smelifaro/* 527270822Smelifaro * Structure used to request i2c data 528270822Smelifaro * from interface transceivers. 529270822Smelifaro */ 530270822Smelifarostruct ifi2creq { 531270822Smelifaro uint8_t dev_addr; /* i2c address (0xA0, 0xA2) */ 532270822Smelifaro uint8_t offset; /* read offset */ 533270822Smelifaro uint8_t len; /* read length */ 534270822Smelifaro uint8_t spare0; 535270822Smelifaro uint32_t spare1; 536270822Smelifaro uint8_t data[8]; /* read buffer */ 537270822Smelifaro}; 538270822Smelifaro 539324472Ssephe/* 540324472Ssephe * RSS hash. 541324472Ssephe */ 542324472Ssephe 543324472Ssephe#define RSS_FUNC_NONE 0 /* RSS disabled */ 544324472Ssephe#define RSS_FUNC_PRIVATE 1 /* non-standard */ 545324472Ssephe#define RSS_FUNC_TOEPLITZ 2 546324472Ssephe 547324472Ssephe#define RSS_TYPE_IPV4 0x00000001 548324472Ssephe#define RSS_TYPE_TCP_IPV4 0x00000002 549324472Ssephe#define RSS_TYPE_IPV6 0x00000004 550324472Ssephe#define RSS_TYPE_IPV6_EX 0x00000008 551324472Ssephe#define RSS_TYPE_TCP_IPV6 0x00000010 552324472Ssephe#define RSS_TYPE_TCP_IPV6_EX 0x00000020 553324472Ssephe#define RSS_TYPE_UDP_IPV4 0x00000040 554324472Ssephe#define RSS_TYPE_UDP_IPV6 0x00000080 555324472Ssephe#define RSS_TYPE_UDP_IPV6_EX 0x00000100 556324472Ssephe 557324472Ssephe#define RSS_KEYLEN 128 558324472Ssephe 559324472Ssephestruct ifrsskey { 560324472Ssephe char ifrk_name[IFNAMSIZ]; /* if name, e.g. "en0" */ 561324472Ssephe uint8_t ifrk_func; /* RSS_FUNC_ */ 562324472Ssephe uint8_t ifrk_spare0; 563324472Ssephe uint16_t ifrk_keylen; 564324472Ssephe uint8_t ifrk_key[RSS_KEYLEN]; 565324472Ssephe}; 566324472Ssephe 567324472Ssephestruct ifrsshash { 568324472Ssephe char ifrh_name[IFNAMSIZ]; /* if name, e.g. "en0" */ 569324472Ssephe uint8_t ifrh_func; /* RSS_FUNC_ */ 570324472Ssephe uint8_t ifrh_spare0; 571324472Ssephe uint16_t ifrh_spare1; 572324472Ssephe uint32_t ifrh_types; /* RSS_TYPE_ */ 573324472Ssephe}; 574324472Ssephe 575332991Skib#define IFNET_PCP_NONE 0xff /* PCP disabled */ 576332991Skib 577352649Skib#define IFDR_MSG_SIZE 64 578352649Skib#define IFDR_REASON_MSG 1 579352649Skib#define IFDR_REASON_VENDOR 2 580352649Skibstruct ifdownreason { 581352649Skib char ifdr_name[IFNAMSIZ]; 582352649Skib uint32_t ifdr_reason; 583352649Skib uint32_t ifdr_vendor; 584352649Skib char ifdr_msg[IFDR_MSG_SIZE]; 585352649Skib}; 586352649Skib 587104355Smike#endif /* __BSD_VISIBLE */ 588104355Smike 58955205Speter#ifdef _KERNEL 59030354Sphk#ifdef MALLOC_DECLARE 59130354SphkMALLOC_DECLARE(M_IFADDR); 59230354SphkMALLOC_DECLARE(M_IFMADDR); 59330354Sphk#endif 59430354Sphk#endif 59530354Sphk 59655205Speter#ifndef _KERNEL 59752904Sshinstruct if_nameindex { 598104355Smike unsigned int if_index; /* 1, 2, ... */ 599104360Smike char *if_name; /* null terminated name: "le0", ... */ 60052904Sshin}; 60152904Sshin 60252904Sshin__BEGIN_DECLS 603104360Smikevoid if_freenameindex(struct if_nameindex *); 604104360Smikechar *if_indextoname(unsigned int, char *); 605104360Smikestruct if_nameindex *if_nameindex(void); 606104360Smikeunsigned int if_nametoindex(const char *); 60752904Sshin__END_DECLS 60852904Sshin#endif 6094507Sbde#endif /* !_NET_IF_H_ */ 610