ifaddrs.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*-
  2. * SPDX-License-Identifier: BSD-2-Clause
  3. *
  4. * Copyright (c) 2022 Alexander V. Chernikov <melifaro@FreeBSD.org>
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  16. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  18. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  19. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  21. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  22. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  23. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  24. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  25. * SUCH DAMAGE.
  26. */
  27. /*
  28. * Interface address-related (RTM_<NEW|DEL|GET>ADDR) message header and attributes.
  29. */
  30. #ifndef _NETLINK_ROUTE_IFADDRS_H_
  31. #define _NETLINK_ROUTE_IFADDRS_H_
  32. /* Base header for all of the relevant messages */
  33. struct ifaddrmsg {
  34. uint8_t ifa_family; /* Address family */
  35. uint8_t ifa_prefixlen; /* Prefix length */
  36. uint8_t ifa_flags; /* Address-specific flags */
  37. uint8_t ifa_scope; /* Address scope */
  38. uint32_t ifa_index; /* Link ifindex */
  39. };
  40. #ifndef _KERNEL
  41. #define _NL_IFA_HDRLEN ((int)sizeof(struct ifaddrmsg))
  42. #define IFA_RTA(_ifa) ((struct rtattr *)(NL_ITEM_DATA(_ifa, _NL_IFA_HDRLEN)))
  43. #define IFA_PAYLOAD(_hdr) NLMSG_PAYLOAD(_hdr, _NL_IFA_HDRLEN)
  44. #endif
  45. /* Defined attributes */
  46. enum {
  47. IFA_UNSPEC,
  48. IFA_ADDRESS = 1, /* binary, prefix address (destination for p2p) */
  49. IFA_LOCAL = 2, /* binary, interface address */
  50. IFA_LABEL = 3, /* string, interface name */
  51. IFA_BROADCAST = 4, /* binary, broadcast ifa */
  52. IFA_ANYCAST = 5, /* not supported */
  53. IFA_CACHEINFO = 6, /* binary, struct ifa_cacheinfo */
  54. IFA_MULTICAST = 7, /* not supported */
  55. IFA_FLAGS = 8, /* u32, IFA_F flags */
  56. IFA_RT_PRIORITY = 9, /* not supported */
  57. IFA_TARGET_NETNSID = 10, /* not supported */
  58. IFA_FREEBSD = 11, /* nested, FreeBSD-specific */
  59. __IFA_MAX,
  60. };
  61. #define IFA_MAX (__IFA_MAX - 1)
  62. enum {
  63. IFAF_UNSPEC,
  64. IFAF_VHID = 1, /* u32: carp vhid */
  65. IFAF_FLAGS = 2, /* u32: FreeBSD-specific ifa flags */
  66. __IFAF_MAX,
  67. };
  68. #define IFAF_MAX (__IFAF_MAX - 1)
  69. /* IFA_FLAGS attribute flags */
  70. #define IFA_F_SECONDARY 0x0001
  71. #define IFA_F_TEMPORARY IFA_F_SECONDARY
  72. #define IFA_F_NODAD 0x0002
  73. #define IFA_F_OPTIMISTIC 0x0004
  74. #define IFA_F_DADFAILED 0x0008
  75. #define IFA_F_HOMEADDRESS 0x0010
  76. #define IFA_F_DEPRECATED 0x0020
  77. #define IFA_F_TENTATIVE 0x0040
  78. #define IFA_F_PERMANENT 0x0080
  79. #define IFA_F_MANAGETEMPADDR 0x0100
  80. #define IFA_F_NOPREFIXROUTE 0x0200
  81. #define IFA_F_MCAUTOJOIN 0x0400
  82. #define IFA_F_STABLE_PRIVACY 0x0800
  83. /* IFA_CACHEINFO value */
  84. struct ifa_cacheinfo {
  85. uint32_t ifa_prefered; /* seconds till the end of the prefix considered preferred */
  86. uint32_t ifa_valid; /* seconds till the end of the prefix considered valid */
  87. uint32_t cstamp; /* creation time in 1ms intervals from the boot time */
  88. uint32_t tstamp; /* update time in 1ms intervals from the boot time */
  89. };
  90. #endif