1df8bae1dSRodney W. Grimes /* 2df8bae1dSRodney W. Grimes * Copyright (c) 1982, 1986, 1989, 1993 3df8bae1dSRodney W. Grimes * The Regents of the University of California. All rights reserved. 4df8bae1dSRodney W. Grimes * 5df8bae1dSRodney W. Grimes * Redistribution and use in source and binary forms, with or without 6df8bae1dSRodney W. Grimes * modification, are permitted provided that the following conditions 7df8bae1dSRodney W. Grimes * are met: 8df8bae1dSRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 9df8bae1dSRodney W. Grimes * notice, this list of conditions and the following disclaimer. 10df8bae1dSRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 11df8bae1dSRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 12df8bae1dSRodney W. Grimes * documentation and/or other materials provided with the distribution. 13df8bae1dSRodney W. Grimes * 3. All advertising materials mentioning features or use of this software 14df8bae1dSRodney W. Grimes * must display the following acknowledgement: 15df8bae1dSRodney W. Grimes * This product includes software developed by the University of 16df8bae1dSRodney W. Grimes * California, Berkeley and its contributors. 17df8bae1dSRodney W. Grimes * 4. Neither the name of the University nor the names of its contributors 18df8bae1dSRodney W. Grimes * may be used to endorse or promote products derived from this software 19df8bae1dSRodney W. Grimes * without specific prior written permission. 20df8bae1dSRodney W. Grimes * 21df8bae1dSRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22df8bae1dSRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23df8bae1dSRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24df8bae1dSRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25df8bae1dSRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26df8bae1dSRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27df8bae1dSRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28df8bae1dSRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29df8bae1dSRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30df8bae1dSRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31df8bae1dSRodney W. Grimes * SUCH DAMAGE. 32df8bae1dSRodney W. Grimes * 33df8bae1dSRodney W. Grimes * @(#)if.h 8.1 (Berkeley) 6/10/93 34c3aac50fSPeter Wemm * $FreeBSD$ 35df8bae1dSRodney W. Grimes */ 36df8bae1dSRodney W. Grimes 37cea1da3bSPaul Richards #ifndef _NET_IF_H_ 38cea1da3bSPaul Richards #define _NET_IF_H_ 39cea1da3bSPaul Richards 40df8bae1dSRodney W. Grimes /* 4109410d0fSPeter Wemm * <net/if.h> does not depend on <sys/time.h> on most other systems. This 4209410d0fSPeter Wemm * helps userland compatability. (struct timeval ifi_lastchange) 4309410d0fSPeter Wemm */ 44664a31e4SPeter Wemm #ifndef _KERNEL 4509410d0fSPeter Wemm #include <sys/time.h> 4609410d0fSPeter Wemm #endif 4709410d0fSPeter Wemm 4809410d0fSPeter Wemm /* 49a73356a1SBill Fenner * Structure describing information about an interface 50a73356a1SBill Fenner * which may be of interest to management entities. 51a73356a1SBill Fenner */ 52df8bae1dSRodney W. Grimes struct if_data { 53df8bae1dSRodney W. Grimes /* generic interface information */ 54df8bae1dSRodney W. Grimes u_char ifi_type; /* ethernet, tokenring, etc */ 55995add1aSGarrett Wollman u_char ifi_physical; /* e.g., AUI, Thinnet, 10base-T, etc */ 56df8bae1dSRodney W. Grimes u_char ifi_addrlen; /* media address length */ 57df8bae1dSRodney W. Grimes u_char ifi_hdrlen; /* media header length */ 58bbd17bf8SGarrett Wollman u_char ifi_recvquota; /* polling quota for receive intrs */ 59bbd17bf8SGarrett Wollman u_char ifi_xmitquota; /* polling quota for xmit intrs */ 60df8bae1dSRodney W. Grimes u_long ifi_mtu; /* maximum transmission unit */ 61df8bae1dSRodney W. Grimes u_long ifi_metric; /* routing metric (external only) */ 62df8bae1dSRodney W. Grimes u_long ifi_baudrate; /* linespeed */ 63df8bae1dSRodney W. Grimes /* volatile statistics */ 64df8bae1dSRodney W. Grimes u_long ifi_ipackets; /* packets received on interface */ 65df8bae1dSRodney W. Grimes u_long ifi_ierrors; /* input errors on interface */ 66df8bae1dSRodney W. Grimes u_long ifi_opackets; /* packets sent on interface */ 67df8bae1dSRodney W. Grimes u_long ifi_oerrors; /* output errors on interface */ 68df8bae1dSRodney W. Grimes u_long ifi_collisions; /* collisions on csma interfaces */ 69df8bae1dSRodney W. Grimes u_long ifi_ibytes; /* total number of octets received */ 70df8bae1dSRodney W. Grimes u_long ifi_obytes; /* total number of octets sent */ 71df8bae1dSRodney W. Grimes u_long ifi_imcasts; /* packets received via multicast */ 72df8bae1dSRodney W. Grimes u_long ifi_omcasts; /* packets sent via multicast */ 73df8bae1dSRodney W. Grimes u_long ifi_iqdrops; /* dropped on input, this interface */ 74df8bae1dSRodney W. Grimes u_long ifi_noproto; /* destined for unsupported protocol */ 75bbd17bf8SGarrett Wollman u_long ifi_recvtiming; /* usec spent receiving when timing */ 76bbd17bf8SGarrett Wollman u_long ifi_xmittiming; /* usec spent xmitting when timing */ 77e39a0280SGary Palmer struct timeval ifi_lastchange; /* time of last administrative change */ 786f64074eSJoerg Wunsch }; 796f64074eSJoerg Wunsch 80df8bae1dSRodney W. Grimes #define IFF_UP 0x1 /* interface is up */ 81df8bae1dSRodney W. Grimes #define IFF_BROADCAST 0x2 /* broadcast address valid */ 82df8bae1dSRodney W. Grimes #define IFF_DEBUG 0x4 /* turn on debugging */ 83df8bae1dSRodney W. Grimes #define IFF_LOOPBACK 0x8 /* is a loopback net */ 84df8bae1dSRodney W. Grimes #define IFF_POINTOPOINT 0x10 /* interface is point-to-point link */ 85cf4b9371SPoul-Henning Kamp #define IFF_SMART 0x20 /* interface manages own routes */ 86df8bae1dSRodney W. Grimes #define IFF_RUNNING 0x40 /* resources allocated */ 87df8bae1dSRodney W. Grimes #define IFF_NOARP 0x80 /* no address resolution protocol */ 88df8bae1dSRodney W. Grimes #define IFF_PROMISC 0x100 /* receive all packets */ 89df8bae1dSRodney W. Grimes #define IFF_ALLMULTI 0x200 /* receive all multicast packets */ 90df8bae1dSRodney W. Grimes #define IFF_OACTIVE 0x400 /* transmission in progress */ 91df8bae1dSRodney W. Grimes #define IFF_SIMPLEX 0x800 /* can't hear own transmissions */ 92df8bae1dSRodney W. Grimes #define IFF_LINK0 0x1000 /* per link layer defined bit */ 93df8bae1dSRodney W. Grimes #define IFF_LINK1 0x2000 /* per link layer defined bit */ 94df8bae1dSRodney W. Grimes #define IFF_LINK2 0x4000 /* per link layer defined bit */ 9537be1da8SGarrett Wollman #define IFF_ALTPHYS IFF_LINK2 /* use alternate physical connection */ 96df8bae1dSRodney W. Grimes #define IFF_MULTICAST 0x8000 /* supports multicast */ 97df8bae1dSRodney W. Grimes 98df8bae1dSRodney W. Grimes /* flags set internally only: */ 99df8bae1dSRodney W. Grimes #define IFF_CANTCHANGE \ 100df8bae1dSRodney W. Grimes (IFF_BROADCAST|IFF_POINTOPOINT|IFF_RUNNING|IFF_OACTIVE|\ 101cf4b9371SPoul-Henning Kamp IFF_SIMPLEX|IFF_MULTICAST|IFF_ALLMULTI|IFF_SMART) 102df8bae1dSRodney W. Grimes 103df8bae1dSRodney W. Grimes #define IFQ_MAXLEN 50 104df8bae1dSRodney W. Grimes #define IFNET_SLOWHZ 1 /* granularity is 1 second */ 105df8bae1dSRodney W. Grimes 106df8bae1dSRodney W. Grimes /* 107df8bae1dSRodney W. Grimes * Message format for use in obtaining information about interfaces 108df8bae1dSRodney W. Grimes * from getkerninfo and the routing socket 109df8bae1dSRodney W. Grimes */ 110df8bae1dSRodney W. Grimes struct if_msghdr { 111df8bae1dSRodney W. Grimes u_short ifm_msglen; /* to skip over non-understood messages */ 112df8bae1dSRodney W. Grimes u_char ifm_version; /* future binary compatability */ 113df8bae1dSRodney W. Grimes u_char ifm_type; /* message type */ 114df8bae1dSRodney W. Grimes int ifm_addrs; /* like rtm_addrs */ 115df8bae1dSRodney W. Grimes int ifm_flags; /* value of if_flags */ 116df8bae1dSRodney W. Grimes u_short ifm_index; /* index for associated ifp */ 117df8bae1dSRodney W. Grimes struct if_data ifm_data;/* statistics and other data about if */ 118df8bae1dSRodney W. Grimes }; 119df8bae1dSRodney W. Grimes 120df8bae1dSRodney W. Grimes /* 121df8bae1dSRodney W. Grimes * Message format for use in obtaining information about interface addresses 122df8bae1dSRodney W. Grimes * from getkerninfo and the routing socket 123df8bae1dSRodney W. Grimes */ 124df8bae1dSRodney W. Grimes struct ifa_msghdr { 125df8bae1dSRodney W. Grimes u_short ifam_msglen; /* to skip over non-understood messages */ 126df8bae1dSRodney W. Grimes u_char ifam_version; /* future binary compatability */ 127df8bae1dSRodney W. Grimes u_char ifam_type; /* message type */ 128df8bae1dSRodney W. Grimes int ifam_addrs; /* like rtm_addrs */ 129df8bae1dSRodney W. Grimes int ifam_flags; /* value of ifa_flags */ 130df8bae1dSRodney W. Grimes u_short ifam_index; /* index for associated ifp */ 131df8bae1dSRodney W. Grimes int ifam_metric; /* value of ifa_metric */ 132df8bae1dSRodney W. Grimes }; 133df8bae1dSRodney W. Grimes 134df8bae1dSRodney W. Grimes /* 135477180fbSGarrett Wollman * Message format for use in obtaining information about multicast addresses 136477180fbSGarrett Wollman * from the routing socket 137477180fbSGarrett Wollman */ 138477180fbSGarrett Wollman struct ifma_msghdr { 139477180fbSGarrett Wollman u_short ifmam_msglen; /* to skip over non-understood messages */ 140477180fbSGarrett Wollman u_char ifmam_version; /* future binary compatability */ 141477180fbSGarrett Wollman u_char ifmam_type; /* message type */ 142477180fbSGarrett Wollman int ifmam_addrs; /* like rtm_addrs */ 143477180fbSGarrett Wollman int ifmam_flags; /* value of ifa_flags */ 144477180fbSGarrett Wollman u_short ifmam_index; /* index for associated ifp */ 145477180fbSGarrett Wollman }; 146477180fbSGarrett Wollman 147477180fbSGarrett Wollman /* 148df8bae1dSRodney W. Grimes * Interface request structure used for socket 149df8bae1dSRodney W. Grimes * ioctl's. All interface ioctl's must have parameter 150df8bae1dSRodney W. Grimes * definitions which begin with ifr_name. The 151df8bae1dSRodney W. Grimes * remainder may be interface specific. 152df8bae1dSRodney W. Grimes */ 153df8bae1dSRodney W. Grimes struct ifreq { 154df8bae1dSRodney W. Grimes #define IFNAMSIZ 16 15576429de4SYoshinobu Inoue #define IF_NAMESIZE IFNAMSIZ 156df8bae1dSRodney W. Grimes char ifr_name[IFNAMSIZ]; /* if name, e.g. "en0" */ 157df8bae1dSRodney W. Grimes union { 158df8bae1dSRodney W. Grimes struct sockaddr ifru_addr; 159df8bae1dSRodney W. Grimes struct sockaddr ifru_dstaddr; 160df8bae1dSRodney W. Grimes struct sockaddr ifru_broadaddr; 1614add131eSPoul-Henning Kamp short ifru_flags[2]; 162df8bae1dSRodney W. Grimes int ifru_metric; 163a7028af7SDavid Greenman int ifru_mtu; 164074c4a4eSGarrett Wollman int ifru_phys; 165a912e453SPeter Wemm int ifru_media; 166df8bae1dSRodney W. Grimes caddr_t ifru_data; 167df8bae1dSRodney W. Grimes } ifr_ifru; 168df8bae1dSRodney W. Grimes #define ifr_addr ifr_ifru.ifru_addr /* address */ 169df8bae1dSRodney W. Grimes #define ifr_dstaddr ifr_ifru.ifru_dstaddr /* other end of p-to-p link */ 170df8bae1dSRodney W. Grimes #define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */ 1714add131eSPoul-Henning Kamp #define ifr_flags ifr_ifru.ifru_flags[0] /* flags */ 1724add131eSPoul-Henning Kamp #define ifr_prevflags ifr_ifru.ifru_flags[1] /* flags */ 173df8bae1dSRodney W. Grimes #define ifr_metric ifr_ifru.ifru_metric /* metric */ 174a7028af7SDavid Greenman #define ifr_mtu ifr_ifru.ifru_mtu /* mtu */ 175511cdd16SDavid Greenman #define ifr_phys ifr_ifru.ifru_phys /* physical wire */ 176a912e453SPeter Wemm #define ifr_media ifr_ifru.ifru_media /* physical media */ 177df8bae1dSRodney W. Grimes #define ifr_data ifr_ifru.ifru_data /* for use by interface */ 178df8bae1dSRodney W. Grimes }; 179df8bae1dSRodney W. Grimes 180906f09bcSGarrett Wollman #define _SIZEOF_ADDR_IFREQ(ifr) \ 181906f09bcSGarrett Wollman ((ifr).ifr_addr.sa_len > sizeof(struct sockaddr) ? \ 182906f09bcSGarrett Wollman (sizeof(struct ifreq) - sizeof(struct sockaddr) + \ 183906f09bcSGarrett Wollman (ifr).ifr_addr.sa_len) : sizeof(struct ifreq)) 184906f09bcSGarrett Wollman 185df8bae1dSRodney W. Grimes struct ifaliasreq { 186df8bae1dSRodney W. Grimes char ifra_name[IFNAMSIZ]; /* if name, e.g. "en0" */ 187df8bae1dSRodney W. Grimes struct sockaddr ifra_addr; 188df8bae1dSRodney W. Grimes struct sockaddr ifra_broadaddr; 189df8bae1dSRodney W. Grimes struct sockaddr ifra_mask; 190df8bae1dSRodney W. Grimes }; 191df8bae1dSRodney W. Grimes 192a912e453SPeter Wemm struct ifmediareq { 193a912e453SPeter Wemm char ifm_name[IFNAMSIZ]; /* if name, e.g. "en0" */ 194a912e453SPeter Wemm int ifm_current; /* current media options */ 195a912e453SPeter Wemm int ifm_mask; /* don't care mask */ 196a912e453SPeter Wemm int ifm_status; /* media status */ 197a912e453SPeter Wemm int ifm_active; /* active options */ 198a912e453SPeter Wemm int ifm_count; /* # entries in ifm_ulist array */ 199a912e453SPeter Wemm int *ifm_ulist; /* media words */ 200a912e453SPeter Wemm }; 201413dd0baSPoul-Henning Kamp 202413dd0baSPoul-Henning Kamp /* 203413dd0baSPoul-Henning Kamp * Structure used to retrieve aux status data from interfaces. 204712020a1SBruce Evans * Kernel suppliers to this interface should respect the formatting 205413dd0baSPoul-Henning Kamp * needed by ifconfig(8): each line starts with a TAB and ends with 206712020a1SBruce Evans * a newline. The canonical example to copy and paste is in if_tun.c. 207413dd0baSPoul-Henning Kamp */ 208413dd0baSPoul-Henning Kamp 209413dd0baSPoul-Henning Kamp #define IFSTATMAX 800 /* 10 lines of text */ 210413dd0baSPoul-Henning Kamp struct ifstat { 211413dd0baSPoul-Henning Kamp char ifs_name[IFNAMSIZ]; /* if name, e.g. "en0" */ 212413dd0baSPoul-Henning Kamp char ascii[IFSTATMAX + 1]; 213413dd0baSPoul-Henning Kamp }; 214413dd0baSPoul-Henning Kamp 215df8bae1dSRodney W. Grimes /* 216df8bae1dSRodney W. Grimes * Structure used in SIOCGIFCONF request. 217df8bae1dSRodney W. Grimes * Used to retrieve interface configuration 218df8bae1dSRodney W. Grimes * for machine (useful for programs which 219df8bae1dSRodney W. Grimes * must know all networks accessible). 220df8bae1dSRodney W. Grimes */ 221df8bae1dSRodney W. Grimes struct ifconf { 222df8bae1dSRodney W. Grimes int ifc_len; /* size of associated buffer */ 223df8bae1dSRodney W. Grimes union { 224df8bae1dSRodney W. Grimes caddr_t ifcu_buf; 225df8bae1dSRodney W. Grimes struct ifreq *ifcu_req; 226df8bae1dSRodney W. Grimes } ifc_ifcu; 227df8bae1dSRodney W. Grimes #define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */ 228df8bae1dSRodney W. Grimes #define ifc_req ifc_ifcu.ifcu_req /* array of structures returned */ 229df8bae1dSRodney W. Grimes }; 230df8bae1dSRodney W. Grimes 23176429de4SYoshinobu Inoue 23276429de4SYoshinobu Inoue /* 23376429de4SYoshinobu Inoue * Structure for SIOC[AGD]LIFADDR 23476429de4SYoshinobu Inoue */ 23576429de4SYoshinobu Inoue struct if_laddrreq { 23676429de4SYoshinobu Inoue char iflr_name[IFNAMSIZ]; 23776429de4SYoshinobu Inoue u_int flags; 23876429de4SYoshinobu Inoue #define IFLR_PREFIX 0x8000 /* in: prefix given out: kernel fills id */ 23976429de4SYoshinobu Inoue u_int prefixlen; /* in/out */ 24076429de4SYoshinobu Inoue struct sockaddr_storage addr; /* in/out */ 24176429de4SYoshinobu Inoue struct sockaddr_storage dstaddr; /* out */ 24276429de4SYoshinobu Inoue }; 24376429de4SYoshinobu Inoue 244664a31e4SPeter Wemm #ifdef _KERNEL 245a1c995b6SPoul-Henning Kamp #ifdef MALLOC_DECLARE 246a1c995b6SPoul-Henning Kamp MALLOC_DECLARE(M_IFADDR); 247a1c995b6SPoul-Henning Kamp MALLOC_DECLARE(M_IFMADDR); 248a1c995b6SPoul-Henning Kamp #endif 249a1c995b6SPoul-Henning Kamp #endif 250a1c995b6SPoul-Henning Kamp 251664a31e4SPeter Wemm #ifndef _KERNEL 25276429de4SYoshinobu Inoue struct if_nameindex { 25376429de4SYoshinobu Inoue u_int if_index; /* 1, 2, ... */ 25476429de4SYoshinobu Inoue char *if_name; /* null terminated name: "le0", ... */ 25576429de4SYoshinobu Inoue }; 25676429de4SYoshinobu Inoue 25776429de4SYoshinobu Inoue __BEGIN_DECLS 25876429de4SYoshinobu Inoue u_int if_nametoindex __P((const char *)); 25976429de4SYoshinobu Inoue char *if_indextoname __P((u_int, char *)); 26076429de4SYoshinobu Inoue struct if_nameindex *if_nameindex __P((void)); 26176429de4SYoshinobu Inoue void if_freenameindex __P((struct if_nameindex *)); 26276429de4SYoshinobu Inoue __END_DECLS 26376429de4SYoshinobu Inoue #endif 26476429de4SYoshinobu Inoue 265664a31e4SPeter Wemm #ifdef _KERNEL 266cb40a67fSPoul-Henning Kamp struct proc; 267712020a1SBruce Evans 26875c13541SPoul-Henning Kamp int prison_if __P((struct proc *p, struct sockaddr *sa)); 269712020a1SBruce Evans 270712020a1SBruce Evans /* XXX - this should go away soon. */ 27119ff91c6SGarrett Wollman #include <net/if_var.h> 272df8bae1dSRodney W. Grimes #endif 273cea1da3bSPaul Richards 274df708ff1SBruce Evans #endif /* !_NET_IF_H_ */ 275