if.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. /*
  2. * INET An implementation of the TCP/IP protocol suite for the LINUX
  3. * operating system. INET is implemented using the BSD Socket
  4. * interface as the means of communication with the user level.
  5. *
  6. * Global definitions for the INET interface module.
  7. *
  8. * Version: @(#)if.h 1.0.2 04/18/93
  9. *
  10. * Authors: Original taken from Berkeley UNIX 4.3, (c) UCB 1982-1988
  11. * Ross Biro
  12. * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License
  16. * as published by the Free Software Foundation; either version
  17. * 2 of the License, or (at your option) any later version.
  18. */
  19. #ifndef _LINUX_IF_H
  20. #define _LINUX_IF_H
  21. #include <linux/libc-compat.h> /* for compatibility with glibc */
  22. #include <linux/types.h> /* for "__kernel_caddr_t" et al */
  23. #include <linux/socket.h> /* for "struct sockaddr" et al */
  24. /* for "__user" et al */
  25. #if __UAPI_DEF_IF_IFNAMSIZ
  26. #define IFNAMSIZ 16
  27. #endif /* __UAPI_DEF_IF_IFNAMSIZ */
  28. #define IFALIASZ 256
  29. #include <linux/hdlc/ioctl.h>
  30. /* For glibc compatibility. An empty enum does not compile. */
  31. #if __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO != 0 && \
  32. __UAPI_DEF_IF_NET_DEVICE_FLAGS != 0
  33. /**
  34. * enum net_device_flags - &struct net_device flags
  35. *
  36. * These are the &struct net_device flags, they can be set by drivers, the
  37. * kernel and some can be triggered by userspace. Userspace can query and
  38. * set these flags using userspace utilities but there is also a sysfs
  39. * entry available for all dev flags which can be queried and set. These flags
  40. * are shared for all types of net_devices. The sysfs entries are available
  41. * via /sys/class/net/<dev>/flags. Flags which can be toggled through sysfs
  42. * are annotated below, note that only a few flags can be toggled and some
  43. * other flags are always always preserved from the original net_device flags
  44. * even if you try to set them via sysfs. Flags which are always preserved
  45. * are kept under the flag grouping @IFF_VOLATILE. Flags which are __volatile__
  46. * are annotated below as such.
  47. *
  48. * You should have a pretty good reason to be extending these flags.
  49. *
  50. * @IFF_UP: interface is up. Can be toggled through sysfs.
  51. * @IFF_BROADCAST: broadcast address valid. Volatile.
  52. * @IFF_DEBUG: turn on debugging. Can be toggled through sysfs.
  53. * @IFF_LOOPBACK: is a loopback net. Volatile.
  54. * @IFF_POINTOPOINT: interface is has p-p link. Volatile.
  55. * @IFF_NOTRAILERS: avoid use of trailers. Can be toggled through sysfs.
  56. * Volatile.
  57. * @IFF_RUNNING: interface RFC2863 OPER_UP. Volatile.
  58. * @IFF_NOARP: no ARP protocol. Can be toggled through sysfs. Volatile.
  59. * @IFF_PROMISC: receive all packets. Can be toggled through sysfs.
  60. * @IFF_ALLMULTI: receive all multicast packets. Can be toggled through
  61. * sysfs.
  62. * @IFF_MASTER: master of a load balancer. Volatile.
  63. * @IFF_SLAVE: slave of a load balancer. Volatile.
  64. * @IFF_MULTICAST: Supports multicast. Can be toggled through sysfs.
  65. * @IFF_PORTSEL: can set media type. Can be toggled through sysfs.
  66. * @IFF_AUTOMEDIA: auto media select active. Can be toggled through sysfs.
  67. * @IFF_DYNAMIC: dialup device with changing addresses. Can be toggled
  68. * through sysfs.
  69. * @IFF_LOWER_UP: driver signals L1 up. Volatile.
  70. * @IFF_DORMANT: driver signals dormant. Volatile.
  71. * @IFF_ECHO: echo sent packets. Volatile.
  72. */
  73. enum net_device_flags {
  74. /* for compatibility with glibc net/if.h */
  75. #if __UAPI_DEF_IF_NET_DEVICE_FLAGS
  76. IFF_UP = 1<<0, /* sysfs */
  77. IFF_BROADCAST = 1<<1, /* __volatile__ */
  78. IFF_DEBUG = 1<<2, /* sysfs */
  79. IFF_LOOPBACK = 1<<3, /* __volatile__ */
  80. IFF_POINTOPOINT = 1<<4, /* __volatile__ */
  81. IFF_NOTRAILERS = 1<<5, /* sysfs */
  82. IFF_RUNNING = 1<<6, /* __volatile__ */
  83. IFF_NOARP = 1<<7, /* sysfs */
  84. IFF_PROMISC = 1<<8, /* sysfs */
  85. IFF_ALLMULTI = 1<<9, /* sysfs */
  86. IFF_MASTER = 1<<10, /* __volatile__ */
  87. IFF_SLAVE = 1<<11, /* __volatile__ */
  88. IFF_MULTICAST = 1<<12, /* sysfs */
  89. IFF_PORTSEL = 1<<13, /* sysfs */
  90. IFF_AUTOMEDIA = 1<<14, /* sysfs */
  91. IFF_DYNAMIC = 1<<15, /* sysfs */
  92. #endif /* __UAPI_DEF_IF_NET_DEVICE_FLAGS */
  93. #if __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO
  94. IFF_LOWER_UP = 1<<16, /* __volatile__ */
  95. IFF_DORMANT = 1<<17, /* __volatile__ */
  96. IFF_ECHO = 1<<18, /* __volatile__ */
  97. #endif /* __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO */
  98. };
  99. #endif /* __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO != 0 && __UAPI_DEF_IF_NET_DEVICE_FLAGS != 0 */
  100. /* for compatibility with glibc net/if.h */
  101. #if __UAPI_DEF_IF_NET_DEVICE_FLAGS
  102. #define IFF_UP IFF_UP
  103. #define IFF_BROADCAST IFF_BROADCAST
  104. #define IFF_DEBUG IFF_DEBUG
  105. #define IFF_LOOPBACK IFF_LOOPBACK
  106. #define IFF_POINTOPOINT IFF_POINTOPOINT
  107. #define IFF_NOTRAILERS IFF_NOTRAILERS
  108. #define IFF_RUNNING IFF_RUNNING
  109. #define IFF_NOARP IFF_NOARP
  110. #define IFF_PROMISC IFF_PROMISC
  111. #define IFF_ALLMULTI IFF_ALLMULTI
  112. #define IFF_MASTER IFF_MASTER
  113. #define IFF_SLAVE IFF_SLAVE
  114. #define IFF_MULTICAST IFF_MULTICAST
  115. #define IFF_PORTSEL IFF_PORTSEL
  116. #define IFF_AUTOMEDIA IFF_AUTOMEDIA
  117. #define IFF_DYNAMIC IFF_DYNAMIC
  118. #endif /* __UAPI_DEF_IF_NET_DEVICE_FLAGS */
  119. #if __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO
  120. #define IFF_LOWER_UP IFF_LOWER_UP
  121. #define IFF_DORMANT IFF_DORMANT
  122. #define IFF_ECHO IFF_ECHO
  123. #endif /* __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO */
  124. #define IFF_VOLATILE (IFF_LOOPBACK|IFF_POINTOPOINT|IFF_BROADCAST|IFF_ECHO|\
  125. IFF_MASTER|IFF_SLAVE|IFF_RUNNING|IFF_LOWER_UP|IFF_DORMANT)
  126. #define IF_GET_IFACE 0x0001 /* for querying only */
  127. #define IF_GET_PROTO 0x0002
  128. /* For definitions see hdlc.h */
  129. #define IF_IFACE_V35 0x1000 /* V.35 serial interface */
  130. #define IF_IFACE_V24 0x1001 /* V.24 serial interface */
  131. #define IF_IFACE_X21 0x1002 /* X.21 serial interface */
  132. #define IF_IFACE_T1 0x1003 /* T1 telco serial interface */
  133. #define IF_IFACE_E1 0x1004 /* E1 telco serial interface */
  134. #define IF_IFACE_SYNC_SERIAL 0x1005 /* can't be set by software */
  135. #define IF_IFACE_X21D 0x1006 /* X.21 Dual Clocking (FarSite) */
  136. /* For definitions see hdlc.h */
  137. #define IF_PROTO_HDLC 0x2000 /* raw HDLC protocol */
  138. #define IF_PROTO_PPP 0x2001 /* PPP protocol */
  139. #define IF_PROTO_CISCO 0x2002 /* Cisco HDLC protocol */
  140. #define IF_PROTO_FR 0x2003 /* Frame Relay protocol */
  141. #define IF_PROTO_FR_ADD_PVC 0x2004 /* Create FR PVC */
  142. #define IF_PROTO_FR_DEL_PVC 0x2005 /* Delete FR PVC */
  143. #define IF_PROTO_X25 0x2006 /* X.25 */
  144. #define IF_PROTO_HDLC_ETH 0x2007 /* raw HDLC, Ethernet emulation */
  145. #define IF_PROTO_FR_ADD_ETH_PVC 0x2008 /* Create FR Ethernet-bridged PVC */
  146. #define IF_PROTO_FR_DEL_ETH_PVC 0x2009 /* Delete FR Ethernet-bridged PVC */
  147. #define IF_PROTO_FR_PVC 0x200A /* for reading PVC status */
  148. #define IF_PROTO_FR_ETH_PVC 0x200B
  149. #define IF_PROTO_RAW 0x200C /* RAW Socket */
  150. /* RFC 2863 operational status */
  151. enum {
  152. IF_OPER_UNKNOWN,
  153. IF_OPER_NOTPRESENT,
  154. IF_OPER_DOWN,
  155. IF_OPER_LOWERLAYERDOWN,
  156. IF_OPER_TESTING,
  157. IF_OPER_DORMANT,
  158. IF_OPER_UP,
  159. };
  160. /* link modes */
  161. enum {
  162. IF_LINK_MODE_DEFAULT,
  163. IF_LINK_MODE_DORMANT, /* limit upward transition to dormant */
  164. };
  165. /*
  166. * Device mapping structure. I'd just gone off and designed a
  167. * beautiful scheme using only loadable modules with arguments
  168. * for driver options and along come the PCMCIA people 8)
  169. *
  170. * Ah well. The get() side of this is good for WDSETUP, and it'll
  171. * be handy for debugging things. The set side is fine for now and
  172. * being very small might be worth keeping for clean configuration.
  173. */
  174. /* for compatibility with glibc net/if.h */
  175. #if __UAPI_DEF_IF_IFMAP
  176. struct ifmap {
  177. unsigned long mem_start;
  178. unsigned long mem_end;
  179. unsigned short base_addr;
  180. unsigned char irq;
  181. unsigned char dma;
  182. unsigned char port;
  183. /* 3 bytes spare */
  184. };
  185. #endif /* __UAPI_DEF_IF_IFMAP */
  186. struct if_settings {
  187. unsigned int type; /* Type of physical device or protocol */
  188. unsigned int size; /* Size of the data allocated by the caller */
  189. union {
  190. /* {atm/eth/dsl}_settings anyone ? */
  191. raw_hdlc_proto *raw_hdlc;
  192. cisco_proto *cisco;
  193. fr_proto *fr;
  194. fr_proto_pvc *fr_pvc;
  195. fr_proto_pvc_info *fr_pvc_info;
  196. /* interface settings */
  197. sync_serial_settings *sync;
  198. te1_settings *te1;
  199. } ifs_ifsu;
  200. };
  201. /*
  202. * Interface request structure used for socket
  203. * ioctl's. All interface ioctl's must have parameter
  204. * definitions which begin with ifr_name. The
  205. * remainder may be interface specific.
  206. */
  207. /* for compatibility with glibc net/if.h */
  208. #if __UAPI_DEF_IF_IFREQ
  209. struct ifreq {
  210. #define IFHWADDRLEN 6
  211. union
  212. {
  213. char ifrn_name[IFNAMSIZ]; /* if name, e.g. "en0" */
  214. } ifr_ifrn;
  215. union {
  216. struct sockaddr ifru_addr;
  217. struct sockaddr ifru_dstaddr;
  218. struct sockaddr ifru_broadaddr;
  219. struct sockaddr ifru_netmask;
  220. struct sockaddr ifru_hwaddr;
  221. short ifru_flags;
  222. int ifru_ivalue;
  223. int ifru_mtu;
  224. struct ifmap ifru_map;
  225. char ifru_slave[IFNAMSIZ]; /* Just fits the size */
  226. char ifru_newname[IFNAMSIZ];
  227. void * ifru_data;
  228. struct if_settings ifru_settings;
  229. } ifr_ifru;
  230. };
  231. #endif /* __UAPI_DEF_IF_IFREQ */
  232. #define ifr_name ifr_ifrn.ifrn_name /* interface name */
  233. #define ifr_hwaddr ifr_ifru.ifru_hwaddr /* MAC address */
  234. #define ifr_addr ifr_ifru.ifru_addr /* address */
  235. #define ifr_dstaddr ifr_ifru.ifru_dstaddr /* other end of p-p lnk */
  236. #define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */
  237. #define ifr_netmask ifr_ifru.ifru_netmask /* interface net mask */
  238. #define ifr_flags ifr_ifru.ifru_flags /* flags */
  239. #define ifr_metric ifr_ifru.ifru_ivalue /* metric */
  240. #define ifr_mtu ifr_ifru.ifru_mtu /* mtu */
  241. #define ifr_map ifr_ifru.ifru_map /* device map */
  242. #define ifr_slave ifr_ifru.ifru_slave /* slave device */
  243. #define ifr_data ifr_ifru.ifru_data /* for use by interface */
  244. #define ifr_ifindex ifr_ifru.ifru_ivalue /* interface index */
  245. #define ifr_bandwidth ifr_ifru.ifru_ivalue /* link bandwidth */
  246. #define ifr_qlen ifr_ifru.ifru_ivalue /* Queue length */
  247. #define ifr_newname ifr_ifru.ifru_newname /* New name */
  248. #define ifr_settings ifr_ifru.ifru_settings /* Device/proto settings*/
  249. /*
  250. * Structure used in SIOCGIFCONF request.
  251. * Used to retrieve interface configuration
  252. * for machine (useful for programs which
  253. * must know all networks accessible).
  254. */
  255. /* for compatibility with glibc net/if.h */
  256. #if __UAPI_DEF_IF_IFCONF
  257. struct ifconf {
  258. int ifc_len; /* size of buffer */
  259. union {
  260. char *ifcu_buf;
  261. struct ifreq *ifcu_req;
  262. } ifc_ifcu;
  263. };
  264. #endif /* __UAPI_DEF_IF_IFCONF */
  265. #define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */
  266. #define ifc_req ifc_ifcu.ifcu_req /* array of structures */
  267. #endif /* _LINUX_IF_H */