if.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  1. /* $OpenBSD: if.h,v 1.164 2015/06/07 12:02:28 jsg Exp $ */
  2. /* $NetBSD: if.h,v 1.23 1996/05/07 02:40:27 thorpej Exp $ */
  3. /*
  4. * Copyright (c) 1982, 1986, 1989, 1993
  5. * The Regents of the University of California. All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. Neither the name of the University nor the names of its contributors
  16. * may be used to endorse or promote products derived from this software
  17. * without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  20. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  22. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  23. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  24. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  25. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  26. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  27. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  28. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  29. * SUCH DAMAGE.
  30. *
  31. * @(#)if.h 8.1 (Berkeley) 6/10/93
  32. */
  33. #ifndef _NET_IF_H_
  34. #define _NET_IF_H_
  35. #include <sys/cdefs.h>
  36. /*
  37. * Length of interface external name, including terminating '\0'.
  38. * Note: this is the same size as a generic device's external name.
  39. */
  40. #define IF_NAMESIZE 16
  41. struct if_nameindex {
  42. unsigned int if_index;
  43. char *if_name;
  44. };
  45. #ifndef _KERNEL
  46. __BEGIN_DECLS
  47. unsigned int if_nametoindex(const char *);
  48. char *if_indextoname(unsigned int, char *);
  49. struct if_nameindex *if_nameindex(void);
  50. void if_freenameindex(struct if_nameindex *);
  51. __END_DECLS
  52. #endif
  53. #if __BSD_VISIBLE
  54. /*
  55. * Structure used to query names of interface cloners.
  56. */
  57. struct if_clonereq {
  58. int ifcr_total; /* total cloners (out) */
  59. int ifcr_count; /* room for this many in user buffer */
  60. char *ifcr_buffer; /* buffer for cloner names */
  61. };
  62. #define MCLPOOLS 7 /* number of cluster pools */
  63. struct if_rxring {
  64. int rxr_adjusted;
  65. u_int rxr_alive;
  66. u_int rxr_cwm;
  67. u_int rxr_lwm;
  68. u_int rxr_hwm;
  69. };
  70. struct if_rxring_info {
  71. char ifr_name[16]; /* name of the ring */
  72. u_int ifr_size; /* size of the packets on the ring */
  73. struct if_rxring ifr_info;
  74. };
  75. /* Structure used in SIOCGIFRXR request. */
  76. struct if_rxrinfo {
  77. u_int ifri_total;
  78. struct if_rxring_info *ifri_entries;
  79. };
  80. /*
  81. * Structure defining statistics and other data kept regarding a network
  82. * interface.
  83. */
  84. struct if_data {
  85. /* generic interface information */
  86. u_char ifi_type; /* ethernet, tokenring, etc. */
  87. u_char ifi_addrlen; /* media address length */
  88. u_char ifi_hdrlen; /* media header length */
  89. u_char ifi_link_state; /* current link state */
  90. u_int32_t ifi_mtu; /* maximum transmission unit */
  91. u_int32_t ifi_metric; /* routing metric (external only) */
  92. u_int32_t ifi_rdomain; /* routing instance */
  93. u_int64_t ifi_baudrate; /* linespeed */
  94. /* volatile statistics */
  95. u_int64_t ifi_ipackets; /* packets received on interface */
  96. u_int64_t ifi_ierrors; /* input errors on interface */
  97. u_int64_t ifi_opackets; /* packets sent on interface */
  98. u_int64_t ifi_oerrors; /* output errors on interface */
  99. u_int64_t ifi_collisions; /* collisions on csma interfaces */
  100. u_int64_t ifi_ibytes; /* total number of octets received */
  101. u_int64_t ifi_obytes; /* total number of octets sent */
  102. u_int64_t ifi_imcasts; /* packets received via multicast */
  103. u_int64_t ifi_omcasts; /* packets sent via multicast */
  104. u_int64_t ifi_iqdrops; /* dropped on input, this interface */
  105. u_int64_t ifi_noproto; /* destined for unsupported protocol */
  106. u_int32_t ifi_capabilities; /* interface capabilities */
  107. struct timeval ifi_lastchange; /* last operational state change */
  108. };
  109. #define IFQ_NQUEUES 8
  110. #define IFQ_MAXPRIO IFQ_NQUEUES - 1
  111. #define IFQ_DEFPRIO 3
  112. /*
  113. * Values for if_link_state.
  114. */
  115. #define LINK_STATE_UNKNOWN 0 /* link unknown */
  116. #define LINK_STATE_INVALID 1 /* link invalid */
  117. #define LINK_STATE_DOWN 2 /* link is down */
  118. #define LINK_STATE_KALIVE_DOWN 3 /* keepalive reports down */
  119. #define LINK_STATE_UP 4 /* link is up */
  120. #define LINK_STATE_HALF_DUPLEX 5 /* link is up and half duplex */
  121. #define LINK_STATE_FULL_DUPLEX 6 /* link is up and full duplex */
  122. #define LINK_STATE_IS_UP(_s) \
  123. ((_s) >= LINK_STATE_UP || (_s) == LINK_STATE_UNKNOWN)
  124. /*
  125. * Status bit descriptions for the various interface types.
  126. */
  127. struct if_status_description {
  128. u_char ifs_type;
  129. u_char ifs_state;
  130. const char *ifs_string;
  131. };
  132. #define LINK_STATE_DESC_MATCH(_ifs, _t, _s) \
  133. (((_ifs)->ifs_type == (_t) || (_ifs)->ifs_type == 0) && \
  134. (_ifs)->ifs_state == (_s))
  135. #define LINK_STATE_DESCRIPTIONS { \
  136. { IFT_ETHER, LINK_STATE_DOWN, "no carrier" }, \
  137. \
  138. { IFT_IEEE80211, LINK_STATE_DOWN, "no network" }, \
  139. \
  140. { IFT_PPP, LINK_STATE_DOWN, "no carrier" }, \
  141. \
  142. { IFT_CARP, LINK_STATE_DOWN, "backup" }, \
  143. { IFT_CARP, LINK_STATE_UP, "master" }, \
  144. { IFT_CARP, LINK_STATE_HALF_DUPLEX, "master" }, \
  145. { IFT_CARP, LINK_STATE_FULL_DUPLEX, "master" }, \
  146. \
  147. { 0, LINK_STATE_UP, "active" }, \
  148. { 0, LINK_STATE_HALF_DUPLEX, "active" }, \
  149. { 0, LINK_STATE_FULL_DUPLEX, "active" }, \
  150. \
  151. { 0, LINK_STATE_UNKNOWN, "unknown" }, \
  152. { 0, LINK_STATE_INVALID, "invalid" }, \
  153. { 0, LINK_STATE_DOWN, "down" }, \
  154. { 0, LINK_STATE_KALIVE_DOWN, "keepalive down" }, \
  155. { 0, 0, NULL } \
  156. }
  157. /* Traditional BSD name for length of interface external name. */
  158. #define IFNAMSIZ IF_NAMESIZE
  159. /*
  160. * Length of interface description, including terminating '\0'.
  161. */
  162. #define IFDESCRSIZE 64
  163. #define IFF_UP 0x1 /* interface is up */
  164. #define IFF_BROADCAST 0x2 /* broadcast address valid */
  165. #define IFF_DEBUG 0x4 /* turn on debugging */
  166. #define IFF_LOOPBACK 0x8 /* is a loopback net */
  167. #define IFF_POINTOPOINT 0x10 /* interface is point-to-point link */
  168. #define IFF_NOTRAILERS 0x20 /* avoid use of trailers */
  169. #define IFF_RUNNING 0x40 /* resources allocated */
  170. #define IFF_NOARP 0x80 /* no address resolution protocol */
  171. #define IFF_PROMISC 0x100 /* receive all packets */
  172. #define IFF_ALLMULTI 0x200 /* receive all multicast packets */
  173. #define IFF_OACTIVE 0x400 /* transmission in progress */
  174. #define IFF_SIMPLEX 0x800 /* can't hear own transmissions */
  175. #define IFF_LINK0 0x1000 /* per link layer defined bit */
  176. #define IFF_LINK1 0x2000 /* per link layer defined bit */
  177. #define IFF_LINK2 0x4000 /* per link layer defined bit */
  178. #define IFF_MULTICAST 0x8000 /* supports multicast */
  179. /* flags set internally only: */
  180. #define IFF_CANTCHANGE \
  181. (IFF_BROADCAST|IFF_POINTOPOINT|IFF_RUNNING|IFF_OACTIVE|\
  182. IFF_SIMPLEX|IFF_MULTICAST|IFF_ALLMULTI)
  183. #define IFXF_TXREADY 0x1 /* interface is ready to tx */
  184. #define IFXF_INET6_NOPRIVACY 0x4 /* don't autoconf privacy */
  185. #define IFXF_MPLS 0x8 /* supports MPLS */
  186. #define IFXF_WOL 0x10 /* wake on lan enabled */
  187. #define IFXF_AUTOCONF6 0x20 /* v6 autoconf enabled */
  188. #define IFXF_CANTCHANGE \
  189. (IFXF_TXREADY)
  190. /*
  191. * Some convenience macros used for setting ifi_baudrate.
  192. */
  193. #define IF_Kbps(x) ((x) * 1000ULL) /* kilobits/sec. */
  194. #define IF_Mbps(x) (IF_Kbps((x) * 1000ULL)) /* megabits/sec. */
  195. #define IF_Gbps(x) (IF_Mbps((x) * 1000ULL)) /* gigabits/sec. */
  196. /* Capabilities that interfaces can advertise. */
  197. #define IFCAP_CSUM_IPv4 0x00000001 /* can do IPv4 header csum */
  198. #define IFCAP_CSUM_TCPv4 0x00000002 /* can do IPv4/TCP csum */
  199. #define IFCAP_CSUM_UDPv4 0x00000004 /* can do IPv4/UDP csum */
  200. #define IFCAP_VLAN_MTU 0x00000010 /* VLAN-compatible MTU */
  201. #define IFCAP_VLAN_HWTAGGING 0x00000020 /* hardware VLAN tag support */
  202. #define IFCAP_CSUM_TCPv6 0x00000080 /* can do IPv6/TCP checksums */
  203. #define IFCAP_CSUM_UDPv6 0x00000100 /* can do IPv6/UDP checksums */
  204. #define IFCAP_WOL 0x00008000 /* can do wake on lan */
  205. #define IFCAP_CSUM_MASK (IFCAP_CSUM_IPv4 | IFCAP_CSUM_TCPv4 | \
  206. IFCAP_CSUM_UDPv4 | IFCAP_CSUM_TCPv6 | IFCAP_CSUM_UDPv6)
  207. /* symbolic names for terminal (per-protocol) CTL_IFQ_ nodes */
  208. #define IFQCTL_LEN 1
  209. #define IFQCTL_MAXLEN 2
  210. #define IFQCTL_DROPS 3
  211. #define IFQCTL_CONGESTION 4
  212. #define IFQCTL_MAXID 5
  213. /* sysctl for ifq (per-protocol packet input queue variant of ifqueue) */
  214. #define CTL_IFQ_NAMES { \
  215. { 0, 0 }, \
  216. { "len", CTLTYPE_INT }, \
  217. { "maxlen", CTLTYPE_INT }, \
  218. { "drops", CTLTYPE_INT }, \
  219. { "congestion", CTLTYPE_INT }, \
  220. }
  221. /*
  222. * Message format for use in obtaining information about interfaces
  223. * from sysctl and the routing socket.
  224. */
  225. struct if_msghdr {
  226. u_short ifm_msglen; /* to skip over non-understood messages */
  227. u_char ifm_version; /* future binary compatibility */
  228. u_char ifm_type; /* message type */
  229. u_short ifm_hdrlen; /* sizeof(if_msghdr) to skip over the header */
  230. u_short ifm_index; /* index for associated ifp */
  231. u_short ifm_tableid; /* routing table id */
  232. u_char ifm_pad1;
  233. u_char ifm_pad2;
  234. int ifm_addrs; /* like rtm_addrs */
  235. int ifm_flags; /* value of if_flags */
  236. int ifm_xflags;
  237. struct if_data ifm_data;/* statistics and other data about if */
  238. };
  239. /*
  240. * Message format for use in obtaining information about interface addresses
  241. * from sysctl and the routing socket.
  242. */
  243. struct ifa_msghdr {
  244. u_short ifam_msglen; /* to skip over non-understood messages */
  245. u_char ifam_version; /* future binary compatibility */
  246. u_char ifam_type; /* message type */
  247. u_short ifam_hdrlen; /* sizeof(ifa_msghdr) to skip over the header */
  248. u_short ifam_index; /* index for associated ifp */
  249. u_short ifam_tableid; /* routing table id */
  250. u_char ifam_pad1;
  251. u_char ifam_pad2;
  252. int ifam_addrs; /* like rtm_addrs */
  253. int ifam_flags; /* value of ifa_flags */
  254. int ifam_metric; /* value of ifa_metric */
  255. };
  256. /*
  257. * Message format announcing the arrival or departure of a network interface.
  258. */
  259. struct if_announcemsghdr {
  260. u_short ifan_msglen; /* to skip over non-understood messages */
  261. u_char ifan_version; /* future binary compatibility */
  262. u_char ifan_type; /* message type */
  263. u_short ifan_hdrlen; /* sizeof(ifa_msghdr) to skip over the header */
  264. u_short ifan_index; /* index for associated ifp */
  265. u_short ifan_what; /* what type of announcement */
  266. char ifan_name[IFNAMSIZ]; /* if name, e.g. "en0" */
  267. };
  268. #define IFAN_ARRIVAL 0 /* interface arrival */
  269. #define IFAN_DEPARTURE 1 /* interface departure */
  270. /*
  271. * interface groups
  272. */
  273. #define IFG_ALL "all" /* group contains all interfaces */
  274. #define IFG_EGRESS "egress" /* if(s) default route(s) point to */
  275. struct ifg_req {
  276. union {
  277. char ifgrqu_group[IFNAMSIZ];
  278. char ifgrqu_member[IFNAMSIZ];
  279. } ifgrq_ifgrqu;
  280. #define ifgrq_group ifgrq_ifgrqu.ifgrqu_group
  281. #define ifgrq_member ifgrq_ifgrqu.ifgrqu_member
  282. };
  283. struct ifg_attrib {
  284. int ifg_carp_demoted;
  285. };
  286. /*
  287. * Used to lookup groups for an interface
  288. */
  289. struct ifgroupreq {
  290. char ifgr_name[IFNAMSIZ];
  291. u_int ifgr_len;
  292. union {
  293. char ifgru_group[IFNAMSIZ];
  294. struct ifg_req *ifgru_groups;
  295. struct ifg_attrib ifgru_attrib;
  296. } ifgr_ifgru;
  297. #define ifgr_group ifgr_ifgru.ifgru_group
  298. #define ifgr_groups ifgr_ifgru.ifgru_groups
  299. #define ifgr_attrib ifgr_ifgru.ifgru_attrib
  300. };
  301. /*
  302. * Interface request structure used for socket
  303. * ioctl's. All interface ioctl's must have parameter
  304. * definitions which begin with ifr_name. The
  305. * remainder may be interface specific.
  306. */
  307. struct ifreq {
  308. char ifr_name[IFNAMSIZ]; /* if name, e.g. "en0" */
  309. union {
  310. struct sockaddr ifru_addr;
  311. struct sockaddr ifru_dstaddr;
  312. struct sockaddr ifru_broadaddr;
  313. short ifru_flags;
  314. int ifru_metric;
  315. caddr_t ifru_data;
  316. } ifr_ifru;
  317. #define ifr_addr ifr_ifru.ifru_addr /* address */
  318. #define ifr_dstaddr ifr_ifru.ifru_dstaddr /* other end of p-to-p link */
  319. #define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */
  320. #define ifr_flags ifr_ifru.ifru_flags /* flags */
  321. #define ifr_metric ifr_ifru.ifru_metric /* metric */
  322. #define ifr_mtu ifr_ifru.ifru_metric /* mtu (overload) */
  323. #define ifr_hardmtu ifr_ifru.ifru_metric /* hardmtu (overload) */
  324. #define ifr_media ifr_ifru.ifru_metric /* media options (overload) */
  325. #define ifr_rdomainid ifr_ifru.ifru_metric /* VRF instance (overload) */
  326. #define ifr_vnetid ifr_ifru.ifru_metric /* Virtual Net Id (overload) */
  327. #define ifr_ttl ifr_ifru.ifru_metric /* tunnel TTL (overload) */
  328. #define ifr_data ifr_ifru.ifru_data /* for use by interface */
  329. };
  330. struct ifaliasreq {
  331. char ifra_name[IFNAMSIZ]; /* if name, e.g. "en0" */
  332. union {
  333. struct sockaddr ifrau_addr;
  334. int ifrau_align;
  335. } ifra_ifrau;
  336. #ifndef ifra_addr
  337. #define ifra_addr ifra_ifrau.ifrau_addr
  338. #endif
  339. struct sockaddr ifra_dstaddr;
  340. #define ifra_broadaddr ifra_dstaddr
  341. struct sockaddr ifra_mask;
  342. };
  343. struct ifmediareq {
  344. char ifm_name[IFNAMSIZ]; /* if name, e.g. "en0" */
  345. int ifm_current; /* current media options */
  346. int ifm_mask; /* don't care mask */
  347. int ifm_status; /* media status */
  348. int ifm_active; /* active options */
  349. int ifm_count; /* # entries in ifm_ulist
  350. array */
  351. int *ifm_ulist; /* media words */
  352. };
  353. struct ifkalivereq {
  354. char ikar_name[IFNAMSIZ]; /* if name, e.g. "en0" */
  355. int ikar_timeo;
  356. int ikar_cnt;
  357. };
  358. /*
  359. * Structure used in SIOCGIFCONF request.
  360. * Used to retrieve interface configuration
  361. * for machine (useful for programs which
  362. * must know all networks accessible).
  363. */
  364. struct ifconf {
  365. int ifc_len; /* size of associated buffer */
  366. union {
  367. caddr_t ifcu_buf;
  368. struct ifreq *ifcu_req;
  369. } ifc_ifcu;
  370. #define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */
  371. #define ifc_req ifc_ifcu.ifcu_req /* array of structures returned */
  372. };
  373. /*
  374. * Structure for SIOC[AGD]LIFADDR
  375. */
  376. struct if_laddrreq {
  377. char iflr_name[IFNAMSIZ];
  378. unsigned int flags;
  379. #define IFLR_PREFIX 0x8000 /* in: prefix given out: kernel fills id */
  380. unsigned int prefixlen; /* in/out */
  381. struct sockaddr_storage addr; /* in/out */
  382. struct sockaddr_storage dstaddr; /* out */
  383. };
  384. /* SIOCIFAFDETACH */
  385. struct if_afreq {
  386. char ifar_name[IFNAMSIZ];
  387. sa_family_t ifar_af;
  388. };
  389. #include <net/if_arp.h>
  390. #ifdef _KERNEL
  391. struct socket;
  392. struct ifnet;
  393. void if_alloc_sadl(struct ifnet *);
  394. void if_free_sadl(struct ifnet *);
  395. void if_attach(struct ifnet *);
  396. void if_attachdomain(void);
  397. void if_attachtail(struct ifnet *);
  398. void if_attachhead(struct ifnet *);
  399. void if_deactivate(struct ifnet *);
  400. void if_detach(struct ifnet *);
  401. void if_down(struct ifnet *);
  402. void if_downall(void);
  403. void if_link_state_change(struct ifnet *);
  404. void if_slowtimo(void *);
  405. void if_up(struct ifnet *);
  406. int ifconf(u_long, caddr_t);
  407. void ifinit(void);
  408. int ifioctl(struct socket *, u_long, caddr_t, struct proc *);
  409. int ifpromisc(struct ifnet *, int);
  410. struct ifg_group *if_creategroup(const char *);
  411. int if_addgroup(struct ifnet *, const char *);
  412. int if_delgroup(struct ifnet *, const char *);
  413. void if_group_routechange(struct sockaddr *, struct sockaddr *);
  414. struct ifnet *ifunit(const char *);
  415. struct ifnet *if_get(unsigned int);
  416. void ifnewlladdr(struct ifnet *);
  417. void if_congestion(void);
  418. int if_congested(void);
  419. __dead void unhandled_af(int);
  420. #endif /* _KERNEL */
  421. #endif /* __BSD_VISIBLE */
  422. #endif /* _NET_IF_H_ */