if.h revision 55205
11541Srgrimes/* 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 * 3. All advertising materials mentioning features or use of this software 141541Srgrimes * must display the following acknowledgement: 151541Srgrimes * This product includes software developed by the University of 161541Srgrimes * California, Berkeley and its contributors. 171541Srgrimes * 4. Neither the name of the University nor the names of its contributors 181541Srgrimes * may be used to endorse or promote products derived from this software 191541Srgrimes * without specific prior written permission. 201541Srgrimes * 211541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 221541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 231541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 241541Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 251541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 261541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 271541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 281541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 291541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 301541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 311541Srgrimes * SUCH DAMAGE. 321541Srgrimes * 331541Srgrimes * @(#)if.h 8.1 (Berkeley) 6/10/93 3450477Speter * $FreeBSD: head/sys/net/if.h 55205 1999-12-29 04:46:21Z peter $ 351541Srgrimes */ 361541Srgrimes 372168Spaul#ifndef _NET_IF_H_ 384507Sbde#define _NET_IF_H_ 392168Spaul 401541Srgrimes/* 4134750Speter * <net/if.h> does not depend on <sys/time.h> on most other systems. This 4234750Speter * helps userland compatability. (struct timeval ifi_lastchange) 4334750Speter */ 4455205Speter#ifndef _KERNEL 4534750Speter#include <sys/time.h> 4634750Speter#endif 4734750Speter 4834750Speter/* 4919079Sfenner * Structure describing information about an interface 5019079Sfenner * which may be of interest to management entities. 5119079Sfenner */ 529457Sjoergstruct if_data { 539457Sjoerg /* generic interface information */ 549457Sjoerg u_char ifi_type; /* ethernet, tokenring, etc */ 559457Sjoerg u_char ifi_physical; /* e.g., AUI, Thinnet, 10base-T, etc */ 569457Sjoerg u_char ifi_addrlen; /* media address length */ 579457Sjoerg u_char ifi_hdrlen; /* media header length */ 5817352Swollman u_char ifi_recvquota; /* polling quota for receive intrs */ 5917352Swollman u_char ifi_xmitquota; /* polling quota for xmit intrs */ 609457Sjoerg u_long ifi_mtu; /* maximum transmission unit */ 619457Sjoerg u_long ifi_metric; /* routing metric (external only) */ 629457Sjoerg u_long ifi_baudrate; /* linespeed */ 639457Sjoerg /* volatile statistics */ 649457Sjoerg u_long ifi_ipackets; /* packets received on interface */ 659457Sjoerg u_long ifi_ierrors; /* input errors on interface */ 669457Sjoerg u_long ifi_opackets; /* packets sent on interface */ 679457Sjoerg u_long ifi_oerrors; /* output errors on interface */ 689457Sjoerg u_long ifi_collisions; /* collisions on csma interfaces */ 699457Sjoerg u_long ifi_ibytes; /* total number of octets received */ 709457Sjoerg u_long ifi_obytes; /* total number of octets sent */ 719457Sjoerg u_long ifi_imcasts; /* packets received via multicast */ 729457Sjoerg u_long ifi_omcasts; /* packets sent via multicast */ 739457Sjoerg u_long ifi_iqdrops; /* dropped on input, this interface */ 749457Sjoerg u_long ifi_noproto; /* destined for unsupported protocol */ 7517352Swollman u_long ifi_recvtiming; /* usec spent receiving when timing */ 7617352Swollman u_long ifi_xmittiming; /* usec spent xmitting when timing */ 7716287Sgpalmer struct timeval ifi_lastchange; /* time of last administrative change */ 789457Sjoerg}; 799457Sjoerg 801541Srgrimes#define IFF_UP 0x1 /* interface is up */ 811541Srgrimes#define IFF_BROADCAST 0x2 /* broadcast address valid */ 821541Srgrimes#define IFF_DEBUG 0x4 /* turn on debugging */ 831541Srgrimes#define IFF_LOOPBACK 0x8 /* is a loopback net */ 841541Srgrimes#define IFF_POINTOPOINT 0x10 /* interface is point-to-point link */ 8547777Sphk#define IFF_SMART 0x20 /* interface manages own routes */ 861541Srgrimes#define IFF_RUNNING 0x40 /* resources allocated */ 871541Srgrimes#define IFF_NOARP 0x80 /* no address resolution protocol */ 881541Srgrimes#define IFF_PROMISC 0x100 /* receive all packets */ 891541Srgrimes#define IFF_ALLMULTI 0x200 /* receive all multicast packets */ 901541Srgrimes#define IFF_OACTIVE 0x400 /* transmission in progress */ 911541Srgrimes#define IFF_SIMPLEX 0x800 /* can't hear own transmissions */ 921541Srgrimes#define IFF_LINK0 0x1000 /* per link layer defined bit */ 931541Srgrimes#define IFF_LINK1 0x2000 /* per link layer defined bit */ 941541Srgrimes#define IFF_LINK2 0x4000 /* per link layer defined bit */ 953274Swollman#define IFF_ALTPHYS IFF_LINK2 /* use alternate physical connection */ 961541Srgrimes#define IFF_MULTICAST 0x8000 /* supports multicast */ 971541Srgrimes 981541Srgrimes/* flags set internally only: */ 991541Srgrimes#define IFF_CANTCHANGE \ 1001541Srgrimes (IFF_BROADCAST|IFF_POINTOPOINT|IFF_RUNNING|IFF_OACTIVE|\ 10147777Sphk IFF_SIMPLEX|IFF_MULTICAST|IFF_ALLMULTI|IFF_SMART) 1021541Srgrimes 1031541Srgrimes#define IFQ_MAXLEN 50 1041541Srgrimes#define IFNET_SLOWHZ 1 /* granularity is 1 second */ 1051541Srgrimes 1061541Srgrimes/* 1071541Srgrimes * Message format for use in obtaining information about interfaces 1081541Srgrimes * from getkerninfo and the routing socket 1091541Srgrimes */ 1101541Srgrimesstruct if_msghdr { 1111541Srgrimes u_short ifm_msglen; /* to skip over non-understood messages */ 1121541Srgrimes u_char ifm_version; /* future binary compatability */ 1131541Srgrimes u_char ifm_type; /* message type */ 1141541Srgrimes int ifm_addrs; /* like rtm_addrs */ 1151541Srgrimes int ifm_flags; /* value of if_flags */ 1161541Srgrimes u_short ifm_index; /* index for associated ifp */ 1171541Srgrimes struct if_data ifm_data;/* statistics and other data about if */ 1181541Srgrimes}; 1191541Srgrimes 1201541Srgrimes/* 1211541Srgrimes * Message format for use in obtaining information about interface addresses 1221541Srgrimes * from getkerninfo and the routing socket 1231541Srgrimes */ 1241541Srgrimesstruct ifa_msghdr { 1251541Srgrimes u_short ifam_msglen; /* to skip over non-understood messages */ 1261541Srgrimes u_char ifam_version; /* future binary compatability */ 1271541Srgrimes u_char ifam_type; /* message type */ 1281541Srgrimes int ifam_addrs; /* like rtm_addrs */ 1291541Srgrimes int ifam_flags; /* value of ifa_flags */ 1301541Srgrimes u_short ifam_index; /* index for associated ifp */ 1311541Srgrimes int ifam_metric; /* value of ifa_metric */ 1321541Srgrimes}; 1331541Srgrimes 1341541Srgrimes/* 13521666Swollman * Message format for use in obtaining information about multicast addresses 13621666Swollman * from the routing socket 13721666Swollman */ 13821666Swollmanstruct ifma_msghdr { 13921666Swollman u_short ifmam_msglen; /* to skip over non-understood messages */ 14021666Swollman u_char ifmam_version; /* future binary compatability */ 14121666Swollman u_char ifmam_type; /* message type */ 14221666Swollman int ifmam_addrs; /* like rtm_addrs */ 14321666Swollman int ifmam_flags; /* value of ifa_flags */ 14421666Swollman u_short ifmam_index; /* index for associated ifp */ 14521666Swollman}; 14621666Swollman 14721666Swollman/* 1481541Srgrimes * Interface request structure used for socket 1491541Srgrimes * ioctl's. All interface ioctl's must have parameter 1501541Srgrimes * definitions which begin with ifr_name. The 1511541Srgrimes * remainder may be interface specific. 1521541Srgrimes */ 1531541Srgrimesstruct ifreq { 1541541Srgrimes#define IFNAMSIZ 16 15552904Sshin#define IF_NAMESIZE IFNAMSIZ 1561541Srgrimes char ifr_name[IFNAMSIZ]; /* if name, e.g. "en0" */ 1571541Srgrimes union { 1581541Srgrimes struct sockaddr ifru_addr; 1591541Srgrimes struct sockaddr ifru_dstaddr; 1601541Srgrimes struct sockaddr ifru_broadaddr; 16144144Sphk short ifru_flags[2]; 1621541Srgrimes int ifru_metric; 1631941Sdg int ifru_mtu; 1645184Swollman int ifru_phys; 16525434Speter int ifru_media; 1661541Srgrimes caddr_t ifru_data; 1671541Srgrimes } ifr_ifru; 1681541Srgrimes#define ifr_addr ifr_ifru.ifru_addr /* address */ 1691541Srgrimes#define ifr_dstaddr ifr_ifru.ifru_dstaddr /* other end of p-to-p link */ 1701541Srgrimes#define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */ 17144144Sphk#define ifr_flags ifr_ifru.ifru_flags[0] /* flags */ 17244144Sphk#define ifr_prevflags ifr_ifru.ifru_flags[1] /* flags */ 1731541Srgrimes#define ifr_metric ifr_ifru.ifru_metric /* metric */ 1741941Sdg#define ifr_mtu ifr_ifru.ifru_mtu /* mtu */ 1755187Sdg#define ifr_phys ifr_ifru.ifru_phys /* physical wire */ 17625434Speter#define ifr_media ifr_ifru.ifru_media /* physical media */ 1771541Srgrimes#define ifr_data ifr_ifru.ifru_data /* for use by interface */ 1781541Srgrimes}; 1791541Srgrimes 18032491Swollman#define _SIZEOF_ADDR_IFREQ(ifr) \ 18132491Swollman ((ifr).ifr_addr.sa_len > sizeof(struct sockaddr) ? \ 18232491Swollman (sizeof(struct ifreq) - sizeof(struct sockaddr) + \ 18332491Swollman (ifr).ifr_addr.sa_len) : sizeof(struct ifreq)) 18432491Swollman 1851541Srgrimesstruct ifaliasreq { 1861541Srgrimes char ifra_name[IFNAMSIZ]; /* if name, e.g. "en0" */ 1871541Srgrimes struct sockaddr ifra_addr; 1881541Srgrimes struct sockaddr ifra_broadaddr; 1891541Srgrimes struct sockaddr ifra_mask; 1901541Srgrimes}; 1911541Srgrimes 19225434Speterstruct ifmediareq { 19325434Speter char ifm_name[IFNAMSIZ]; /* if name, e.g. "en0" */ 19425434Speter int ifm_current; /* current media options */ 19525434Speter int ifm_mask; /* don't care mask */ 19625434Speter int ifm_status; /* media status */ 19725434Speter int ifm_active; /* active options */ 19825434Speter int ifm_count; /* # entries in ifm_ulist array */ 19925434Speter int *ifm_ulist; /* media words */ 20025434Speter}; 20148021Sphk 20248021Sphk/* 20348021Sphk * Structure used to retrieve aux status data from interfaces. 20448589Sbde * Kernel suppliers to this interface should respect the formatting 20548021Sphk * needed by ifconfig(8): each line starts with a TAB and ends with 20648589Sbde * a newline. The canonical example to copy and paste is in if_tun.c. 20748021Sphk */ 20848021Sphk 20948589Sbde#define IFSTATMAX 800 /* 10 lines of text */ 21048021Sphkstruct ifstat { 21148589Sbde char ifs_name[IFNAMSIZ]; /* if name, e.g. "en0" */ 21248589Sbde char ascii[IFSTATMAX + 1]; 21348021Sphk}; 21448021Sphk 2151541Srgrimes/* 2161541Srgrimes * Structure used in SIOCGIFCONF request. 2171541Srgrimes * Used to retrieve interface configuration 2181541Srgrimes * for machine (useful for programs which 2191541Srgrimes * must know all networks accessible). 2201541Srgrimes */ 2211541Srgrimesstruct ifconf { 2221541Srgrimes int ifc_len; /* size of associated buffer */ 2231541Srgrimes union { 2241541Srgrimes caddr_t ifcu_buf; 2251541Srgrimes struct ifreq *ifcu_req; 2261541Srgrimes } ifc_ifcu; 2271541Srgrimes#define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */ 2281541Srgrimes#define ifc_req ifc_ifcu.ifcu_req /* array of structures returned */ 2291541Srgrimes}; 2301541Srgrimes 23152904Sshin 23252904Sshin/* 23352904Sshin * Structure for SIOC[AGD]LIFADDR 23452904Sshin */ 23552904Sshinstruct if_laddrreq { 23652904Sshin char iflr_name[IFNAMSIZ]; 23752904Sshin u_int flags; 23852904Sshin#define IFLR_PREFIX 0x8000 /* in: prefix given out: kernel fills id */ 23952904Sshin u_int prefixlen; /* in/out */ 24052904Sshin struct sockaddr_storage addr; /* in/out */ 24152904Sshin struct sockaddr_storage dstaddr; /* out */ 24252904Sshin}; 24352904Sshin 24455205Speter#ifdef _KERNEL 24530354Sphk#ifdef MALLOC_DECLARE 24630354SphkMALLOC_DECLARE(M_IFADDR); 24730354SphkMALLOC_DECLARE(M_IFMADDR); 24830354Sphk#endif 24930354Sphk#endif 25030354Sphk 25155205Speter#ifndef _KERNEL 25252904Sshinstruct if_nameindex { 25352904Sshin u_int if_index; /* 1, 2, ... */ 25452904Sshin char *if_name; /* null terminated name: "le0", ... */ 25552904Sshin}; 25652904Sshin 25752904Sshin__BEGIN_DECLS 25852904Sshinu_int if_nametoindex __P((const char *)); 25952904Sshinchar *if_indextoname __P((u_int, char *)); 26052904Sshinstruct if_nameindex *if_nameindex __P((void)); 26152904Sshinvoid if_freenameindex __P((struct if_nameindex *)); 26252904Sshin__END_DECLS 26352904Sshin#endif 26452904Sshin 26555205Speter#ifdef _KERNEL 26646678Sphkstruct proc; 26748589Sbde 26846155Sphkint prison_if __P((struct proc *p, struct sockaddr *sa)); 26948589Sbde 27048589Sbde/* XXX - this should go away soon. */ 27121259Swollman#include <net/if_var.h> 2721541Srgrimes#endif 2731541Srgrimes 2744507Sbde#endif /* !_NET_IF_H_ */ 275