nexthop.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. * NEXTHOP-related (RTM_<NEW|DEL|GET>NEXTHOP) message header and attributes.
  29. */
  30. #ifndef _NETLINK_ROUTE_NEXTHOP_H_
  31. #define _NETLINK_ROUTE_NEXTHOP_H_
  32. /* Base header for all of the relevant messages */
  33. struct nhmsg {
  34. unsigned char nh_family; /* transport family */
  35. unsigned char nh_scope; /* ignored on RX, filled by kernel */
  36. unsigned char nh_protocol; /* Routing protocol that installed nh */
  37. unsigned char resvd;
  38. unsigned int nh_flags; /* RTNH_F_* flags from route.h */
  39. };
  40. enum {
  41. NHA_UNSPEC,
  42. NHA_ID, /* u32: nexthop userland index, auto-assigned if 0 */
  43. NHA_GROUP, /* binary: array of struct nexthop_grp */
  44. NHA_GROUP_TYPE, /* u16: set to NEXTHOP_GRP_TYPE */
  45. NHA_BLACKHOLE, /* flag: nexthop used to blackhole packets */
  46. NHA_OIF, /* u32: transmit ifindex */
  47. NHA_GATEWAY, /* network: IPv4/IPv6 gateway addr */
  48. NHA_ENCAP_TYPE, /* not supported */
  49. NHA_ENCAP, /* not supported */
  50. NHA_GROUPS, /* flag: match nexthop groups */
  51. NHA_MASTER, /* not supported */
  52. NHA_FDB, /* not supported */
  53. NHA_RES_GROUP, /* not supported */
  54. NHA_RES_BUCKET, /* not supported */
  55. NHA_FREEBSD, /* nested: FreeBSD-specific attributes */
  56. __NHA_MAX,
  57. };
  58. #define NHA_MAX (__NHA_MAX - 1)
  59. enum {
  60. NHAF_UNSPEC,
  61. NHAF_KNHOPS, /* flag: dump kernel nexthops */
  62. NHAF_KGOUPS, /* flag: dump kernel nexthop groups */
  63. NHAF_TABLE, /* u32: rtable id */
  64. NHAF_FAMILY, /* u32: upper family */
  65. NHAF_KID, /* u32: kernel nexthop index */
  66. NHAF_AIF, /* u32: source interface address */
  67. };
  68. /*
  69. * Attributes that can be used as filters:
  70. * NHA_ID (nexhop or group), NHA_OIF, NHA_GROUPS,
  71. */
  72. /*
  73. * NHA_GROUP: array of the following structures.
  74. * If attribute is set, the only other valid attributes are
  75. * NHA_ID and NHA_GROUP_TYPE.
  76. * NHA_RES_GROUP and NHA_RES_BUCKET are not supported yet
  77. */
  78. struct nexthop_grp {
  79. uint32_t id; /* nexhop userland index */
  80. uint8_t weight; /* weight of this nexthop */
  81. uint8_t resvd1;
  82. uint16_t resvd2;
  83. };
  84. /* NHA_GROUP_TYPE: u16 */
  85. enum {
  86. NEXTHOP_GRP_TYPE_MPATH, /* default nexthop group */
  87. NEXTHOP_GRP_TYPE_RES, /* resilient nexthop group */
  88. __NEXTHOP_GRP_TYPE_MAX,
  89. };
  90. #define NEXTHOP_GRP_TYPE_MAX (__NEXTHOP_GRP_TYPE_MAX - 1)
  91. /* NHA_RES_GROUP */
  92. enum {
  93. NHA_RES_GROUP_UNSPEC,
  94. NHA_RES_GROUP_PAD = NHA_RES_GROUP_UNSPEC,
  95. NHA_RES_GROUP_BUCKETS,
  96. NHA_RES_GROUP_IDLE_TIMER,
  97. NHA_RES_GROUP_UNBALANCED_TIMER,
  98. NHA_RES_GROUP_UNBALANCED_TIME,
  99. __NHA_RES_GROUP_MAX,
  100. };
  101. #define NHA_RES_GROUP_MAX (__NHA_RES_GROUP_MAX - 1)
  102. #endif