Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
0002 /*
0003  * INET     An implementation of the TCP/IP protocol suite for the LINUX
0004  *      operating system.  INET is implemented using the  BSD Socket
0005  *      interface as the means of communication with the user level.
0006  *
0007  *      Global definitions for the INET interface module.
0008  *
0009  * Version: @(#)if.h    1.0.2   04/18/93
0010  *
0011  * Authors: Original taken from Berkeley UNIX 4.3, (c) UCB 1982-1988
0012  *      Ross Biro
0013  *      Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
0014  *
0015  *      This program is free software; you can redistribute it and/or
0016  *      modify it under the terms of the GNU General Public License
0017  *      as published by the Free Software Foundation; either version
0018  *      2 of the License, or (at your option) any later version.
0019  */
0020 #ifndef _LINUX_IF_H
0021 #define _LINUX_IF_H
0022 
0023 #include <linux/libc-compat.h>          /* for compatibility with glibc */
0024 #include <linux/types.h>        /* for "__kernel_caddr_t" et al */
0025 #include <linux/socket.h>       /* for "struct sockaddr" et al  */
0026 #include <linux/compiler.h>     /* for "__user" et al           */
0027 
0028 #ifndef __KERNEL__
0029 #include <sys/socket.h>         /* for struct sockaddr.     */
0030 #endif
0031 
0032 #if __UAPI_DEF_IF_IFNAMSIZ
0033 #define IFNAMSIZ    16
0034 #endif /* __UAPI_DEF_IF_IFNAMSIZ */
0035 #define IFALIASZ    256
0036 #define ALTIFNAMSIZ 128
0037 #include <linux/hdlc/ioctl.h>
0038 
0039 /* For glibc compatibility. An empty enum does not compile. */
0040 #if __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO != 0 || \
0041     __UAPI_DEF_IF_NET_DEVICE_FLAGS != 0
0042 /**
0043  * enum net_device_flags - &struct net_device flags
0044  *
0045  * These are the &struct net_device flags, they can be set by drivers, the
0046  * kernel and some can be triggered by userspace. Userspace can query and
0047  * set these flags using userspace utilities but there is also a sysfs
0048  * entry available for all dev flags which can be queried and set. These flags
0049  * are shared for all types of net_devices. The sysfs entries are available
0050  * via /sys/class/net/<dev>/flags. Flags which can be toggled through sysfs
0051  * are annotated below, note that only a few flags can be toggled and some
0052  * other flags are always preserved from the original net_device flags
0053  * even if you try to set them via sysfs. Flags which are always preserved
0054  * are kept under the flag grouping @IFF_VOLATILE. Flags which are volatile
0055  * are annotated below as such.
0056  *
0057  * You should have a pretty good reason to be extending these flags.
0058  *
0059  * @IFF_UP: interface is up. Can be toggled through sysfs.
0060  * @IFF_BROADCAST: broadcast address valid. Volatile.
0061  * @IFF_DEBUG: turn on debugging. Can be toggled through sysfs.
0062  * @IFF_LOOPBACK: is a loopback net. Volatile.
0063  * @IFF_POINTOPOINT: interface is has p-p link. Volatile.
0064  * @IFF_NOTRAILERS: avoid use of trailers. Can be toggled through sysfs.
0065  *  Volatile.
0066  * @IFF_RUNNING: interface RFC2863 OPER_UP. Volatile.
0067  * @IFF_NOARP: no ARP protocol. Can be toggled through sysfs. Volatile.
0068  * @IFF_PROMISC: receive all packets. Can be toggled through sysfs.
0069  * @IFF_ALLMULTI: receive all multicast packets. Can be toggled through
0070  *  sysfs.
0071  * @IFF_MASTER: master of a load balancer. Volatile.
0072  * @IFF_SLAVE: slave of a load balancer. Volatile.
0073  * @IFF_MULTICAST: Supports multicast. Can be toggled through sysfs.
0074  * @IFF_PORTSEL: can set media type. Can be toggled through sysfs.
0075  * @IFF_AUTOMEDIA: auto media select active. Can be toggled through sysfs.
0076  * @IFF_DYNAMIC: dialup device with changing addresses. Can be toggled
0077  *  through sysfs.
0078  * @IFF_LOWER_UP: driver signals L1 up. Volatile.
0079  * @IFF_DORMANT: driver signals dormant. Volatile.
0080  * @IFF_ECHO: echo sent packets. Volatile.
0081  */
0082 enum net_device_flags {
0083 /* for compatibility with glibc net/if.h */
0084 #if __UAPI_DEF_IF_NET_DEVICE_FLAGS
0085     IFF_UP              = 1<<0,  /* sysfs */
0086     IFF_BROADCAST           = 1<<1,  /* volatile */
0087     IFF_DEBUG           = 1<<2,  /* sysfs */
0088     IFF_LOOPBACK            = 1<<3,  /* volatile */
0089     IFF_POINTOPOINT         = 1<<4,  /* volatile */
0090     IFF_NOTRAILERS          = 1<<5,  /* sysfs */
0091     IFF_RUNNING         = 1<<6,  /* volatile */
0092     IFF_NOARP           = 1<<7,  /* sysfs */
0093     IFF_PROMISC         = 1<<8,  /* sysfs */
0094     IFF_ALLMULTI            = 1<<9,  /* sysfs */
0095     IFF_MASTER          = 1<<10, /* volatile */
0096     IFF_SLAVE           = 1<<11, /* volatile */
0097     IFF_MULTICAST           = 1<<12, /* sysfs */
0098     IFF_PORTSEL         = 1<<13, /* sysfs */
0099     IFF_AUTOMEDIA           = 1<<14, /* sysfs */
0100     IFF_DYNAMIC         = 1<<15, /* sysfs */
0101 #endif /* __UAPI_DEF_IF_NET_DEVICE_FLAGS */
0102 #if __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO
0103     IFF_LOWER_UP            = 1<<16, /* volatile */
0104     IFF_DORMANT         = 1<<17, /* volatile */
0105     IFF_ECHO            = 1<<18, /* volatile */
0106 #endif /* __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO */
0107 };
0108 #endif /* __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO != 0 || __UAPI_DEF_IF_NET_DEVICE_FLAGS != 0 */
0109 
0110 /* for compatibility with glibc net/if.h */
0111 #if __UAPI_DEF_IF_NET_DEVICE_FLAGS
0112 #define IFF_UP              IFF_UP
0113 #define IFF_BROADCAST           IFF_BROADCAST
0114 #define IFF_DEBUG           IFF_DEBUG
0115 #define IFF_LOOPBACK            IFF_LOOPBACK
0116 #define IFF_POINTOPOINT         IFF_POINTOPOINT
0117 #define IFF_NOTRAILERS          IFF_NOTRAILERS
0118 #define IFF_RUNNING         IFF_RUNNING
0119 #define IFF_NOARP           IFF_NOARP
0120 #define IFF_PROMISC         IFF_PROMISC
0121 #define IFF_ALLMULTI            IFF_ALLMULTI
0122 #define IFF_MASTER          IFF_MASTER
0123 #define IFF_SLAVE           IFF_SLAVE
0124 #define IFF_MULTICAST           IFF_MULTICAST
0125 #define IFF_PORTSEL         IFF_PORTSEL
0126 #define IFF_AUTOMEDIA           IFF_AUTOMEDIA
0127 #define IFF_DYNAMIC         IFF_DYNAMIC
0128 #endif /* __UAPI_DEF_IF_NET_DEVICE_FLAGS */
0129 
0130 #if __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO
0131 #define IFF_LOWER_UP            IFF_LOWER_UP
0132 #define IFF_DORMANT         IFF_DORMANT
0133 #define IFF_ECHO            IFF_ECHO
0134 #endif /* __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO */
0135 
0136 #define IFF_VOLATILE    (IFF_LOOPBACK|IFF_POINTOPOINT|IFF_BROADCAST|IFF_ECHO|\
0137         IFF_MASTER|IFF_SLAVE|IFF_RUNNING|IFF_LOWER_UP|IFF_DORMANT)
0138 
0139 #define IF_GET_IFACE    0x0001      /* for querying only */
0140 #define IF_GET_PROTO    0x0002
0141 
0142 /* For definitions see hdlc.h */
0143 #define IF_IFACE_V35    0x1000      /* V.35 serial interface    */
0144 #define IF_IFACE_V24    0x1001      /* V.24 serial interface    */
0145 #define IF_IFACE_X21    0x1002      /* X.21 serial interface    */
0146 #define IF_IFACE_T1 0x1003      /* T1 telco serial interface    */
0147 #define IF_IFACE_E1 0x1004      /* E1 telco serial interface    */
0148 #define IF_IFACE_SYNC_SERIAL 0x1005 /* can't be set by software */
0149 #define IF_IFACE_X21D   0x1006          /* X.21 Dual Clocking (FarSite) */
0150 
0151 /* For definitions see hdlc.h */
0152 #define IF_PROTO_HDLC   0x2000      /* raw HDLC protocol        */
0153 #define IF_PROTO_PPP    0x2001      /* PPP protocol         */
0154 #define IF_PROTO_CISCO  0x2002      /* Cisco HDLC protocol      */
0155 #define IF_PROTO_FR 0x2003      /* Frame Relay protocol     */
0156 #define IF_PROTO_FR_ADD_PVC 0x2004  /*    Create FR PVC     */
0157 #define IF_PROTO_FR_DEL_PVC 0x2005  /*    Delete FR PVC     */
0158 #define IF_PROTO_X25    0x2006      /* X.25             */
0159 #define IF_PROTO_HDLC_ETH 0x2007    /* raw HDLC, Ethernet emulation */
0160 #define IF_PROTO_FR_ADD_ETH_PVC 0x2008  /*  Create FR Ethernet-bridged PVC */
0161 #define IF_PROTO_FR_DEL_ETH_PVC 0x2009  /*  Delete FR Ethernet-bridged PVC */
0162 #define IF_PROTO_FR_PVC 0x200A      /* for reading PVC status   */
0163 #define IF_PROTO_FR_ETH_PVC 0x200B
0164 #define IF_PROTO_RAW    0x200C          /* RAW Socket                   */
0165 
0166 /* RFC 2863 operational status */
0167 enum {
0168     IF_OPER_UNKNOWN,
0169     IF_OPER_NOTPRESENT,
0170     IF_OPER_DOWN,
0171     IF_OPER_LOWERLAYERDOWN,
0172     IF_OPER_TESTING,
0173     IF_OPER_DORMANT,
0174     IF_OPER_UP,
0175 };
0176 
0177 /* link modes */
0178 enum {
0179     IF_LINK_MODE_DEFAULT,
0180     IF_LINK_MODE_DORMANT,   /* limit upward transition to dormant */
0181     IF_LINK_MODE_TESTING,   /* limit upward transition to testing */
0182 };
0183 
0184 /*
0185  *  Device mapping structure. I'd just gone off and designed a 
0186  *  beautiful scheme using only loadable modules with arguments
0187  *  for driver options and along come the PCMCIA people 8)
0188  *
0189  *  Ah well. The get() side of this is good for WDSETUP, and it'll
0190  *  be handy for debugging things. The set side is fine for now and
0191  *  being very small might be worth keeping for clean configuration.
0192  */
0193 
0194 /* for compatibility with glibc net/if.h */
0195 #if __UAPI_DEF_IF_IFMAP
0196 struct ifmap {
0197     unsigned long mem_start;
0198     unsigned long mem_end;
0199     unsigned short base_addr; 
0200     unsigned char irq;
0201     unsigned char dma;
0202     unsigned char port;
0203     /* 3 bytes spare */
0204 };
0205 #endif /* __UAPI_DEF_IF_IFMAP */
0206 
0207 struct if_settings {
0208     unsigned int type;  /* Type of physical device or protocol */
0209     unsigned int size;  /* Size of the data allocated by the caller */
0210     union {
0211         /* {atm/eth/dsl}_settings anyone ? */
0212         raw_hdlc_proto      __user *raw_hdlc;
0213         cisco_proto     __user *cisco;
0214         fr_proto        __user *fr;
0215         fr_proto_pvc        __user *fr_pvc;
0216         fr_proto_pvc_info   __user *fr_pvc_info;
0217         x25_hdlc_proto      __user *x25;
0218 
0219         /* interface settings */
0220         sync_serial_settings    __user *sync;
0221         te1_settings        __user *te1;
0222     } ifs_ifsu;
0223 };
0224 
0225 /*
0226  * Interface request structure used for socket
0227  * ioctl's.  All interface ioctl's must have parameter
0228  * definitions which begin with ifr_name.  The
0229  * remainder may be interface specific.
0230  */
0231 
0232 /* for compatibility with glibc net/if.h */
0233 #if __UAPI_DEF_IF_IFREQ
0234 struct ifreq {
0235 #define IFHWADDRLEN 6
0236     union
0237     {
0238         char    ifrn_name[IFNAMSIZ];        /* if name, e.g. "en0" */
0239     } ifr_ifrn;
0240     
0241     union {
0242         struct  sockaddr ifru_addr;
0243         struct  sockaddr ifru_dstaddr;
0244         struct  sockaddr ifru_broadaddr;
0245         struct  sockaddr ifru_netmask;
0246         struct  sockaddr ifru_hwaddr;
0247         short   ifru_flags;
0248         int ifru_ivalue;
0249         int ifru_mtu;
0250         struct  ifmap ifru_map;
0251         char    ifru_slave[IFNAMSIZ];   /* Just fits the size */
0252         char    ifru_newname[IFNAMSIZ];
0253         void __user *   ifru_data;
0254         struct  if_settings ifru_settings;
0255     } ifr_ifru;
0256 };
0257 #endif /* __UAPI_DEF_IF_IFREQ */
0258 
0259 #define ifr_name    ifr_ifrn.ifrn_name  /* interface name   */
0260 #define ifr_hwaddr  ifr_ifru.ifru_hwaddr    /* MAC address      */
0261 #define ifr_addr    ifr_ifru.ifru_addr  /* address      */
0262 #define ifr_dstaddr ifr_ifru.ifru_dstaddr   /* other end of p-p lnk */
0263 #define ifr_broadaddr   ifr_ifru.ifru_broadaddr /* broadcast address    */
0264 #define ifr_netmask ifr_ifru.ifru_netmask   /* interface net mask   */
0265 #define ifr_flags   ifr_ifru.ifru_flags /* flags        */
0266 #define ifr_metric  ifr_ifru.ifru_ivalue    /* metric       */
0267 #define ifr_mtu     ifr_ifru.ifru_mtu   /* mtu          */
0268 #define ifr_map     ifr_ifru.ifru_map   /* device map       */
0269 #define ifr_slave   ifr_ifru.ifru_slave /* slave device     */
0270 #define ifr_data    ifr_ifru.ifru_data  /* for use by interface */
0271 #define ifr_ifindex ifr_ifru.ifru_ivalue    /* interface index  */
0272 #define ifr_bandwidth   ifr_ifru.ifru_ivalue    /* link bandwidth   */
0273 #define ifr_qlen    ifr_ifru.ifru_ivalue    /* Queue length     */
0274 #define ifr_newname ifr_ifru.ifru_newname   /* New name     */
0275 #define ifr_settings    ifr_ifru.ifru_settings  /* Device/proto settings*/
0276 
0277 /*
0278  * Structure used in SIOCGIFCONF request.
0279  * Used to retrieve interface configuration
0280  * for machine (useful for programs which
0281  * must know all networks accessible).
0282  */
0283 
0284 /* for compatibility with glibc net/if.h */
0285 #if __UAPI_DEF_IF_IFCONF
0286 struct ifconf  {
0287     int ifc_len;            /* size of buffer   */
0288     union {
0289         char __user *ifcu_buf;
0290         struct ifreq __user *ifcu_req;
0291     } ifc_ifcu;
0292 };
0293 #endif /* __UAPI_DEF_IF_IFCONF */
0294 
0295 #define ifc_buf ifc_ifcu.ifcu_buf       /* buffer address   */
0296 #define ifc_req ifc_ifcu.ifcu_req       /* array of structures  */
0297 
0298 #endif /* _LINUX_IF_H */