nexthop.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Nexthop structure definition.
  3. * Copyright (C) 1997, 98, 99, 2001 Kunihiro Ishiguro
  4. * Copyright (C) 2013 Cumulus Networks, Inc.
  5. *
  6. * This file is part of Quagga.
  7. *
  8. * Quagga is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2, or (at your option) any
  11. * later version.
  12. *
  13. * Quagga is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with Quagga; see the file COPYING. If not, write to the Free
  20. * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  21. * 02111-1307, USA.
  22. */
  23. #ifndef _LIB_NEXTHOP_H
  24. #define _LIB_NEXTHOP_H
  25. #include "prefix.h"
  26. union g_addr {
  27. struct in_addr ipv4;
  28. #ifdef HAVE_IPV6
  29. struct in6_addr ipv6;
  30. #endif /* HAVE_IPV6 */
  31. };
  32. enum nexthop_types_t
  33. {
  34. NEXTHOP_TYPE_IFINDEX = 1, /* Directly connected. */
  35. NEXTHOP_TYPE_IFNAME, /* Interface route. */
  36. NEXTHOP_TYPE_IPV4, /* IPv4 nexthop. */
  37. NEXTHOP_TYPE_IPV4_IFINDEX, /* IPv4 nexthop with ifindex. */
  38. NEXTHOP_TYPE_IPV4_IFNAME, /* IPv4 nexthop with ifname. */
  39. NEXTHOP_TYPE_IPV6, /* IPv6 nexthop. */
  40. NEXTHOP_TYPE_IPV6_IFINDEX, /* IPv6 nexthop with ifindex. */
  41. NEXTHOP_TYPE_IPV6_IFNAME, /* IPv6 nexthop with ifname. */
  42. NEXTHOP_TYPE_BLACKHOLE, /* Null0 nexthop. */
  43. };
  44. /* Nexthop structure. */
  45. struct nexthop
  46. {
  47. struct nexthop *next;
  48. struct nexthop *prev;
  49. /* Interface index. */
  50. char *ifname;
  51. ifindex_t ifindex;
  52. enum nexthop_types_t type;
  53. u_char flags;
  54. #define NEXTHOP_FLAG_ACTIVE (1 << 0) /* This nexthop is alive. */
  55. #define NEXTHOP_FLAG_FIB (1 << 1) /* FIB nexthop. */
  56. #define NEXTHOP_FLAG_RECURSIVE (1 << 2) /* Recursive nexthop. */
  57. #define NEXTHOP_FLAG_ONLINK (1 << 3) /* Nexthop should be installed onlink. */
  58. #define NEXTHOP_FLAG_MATCHED (1 << 4) /* Already matched vs a nexthop */
  59. /* Nexthop address */
  60. union g_addr gate;
  61. union g_addr src;
  62. /* Nexthops obtained by recursive resolution.
  63. *
  64. * If the nexthop struct needs to be resolved recursively,
  65. * NEXTHOP_FLAG_RECURSIVE will be set in flags and the nexthops
  66. * obtained by recursive resolution will be added to `resolved'.
  67. * Only one level of recursive resolution is currently supported. */
  68. struct nexthop *resolved;
  69. };
  70. struct nexthop *nexthop_new (void);
  71. void nexthop_add (struct nexthop **target, struct nexthop *nexthop);
  72. void copy_nexthops (struct nexthop **tnh, struct nexthop *nh);
  73. void nexthop_free (struct nexthop *nexthop);
  74. void nexthops_free (struct nexthop *nexthop);
  75. extern const char *nexthop_type_to_str (enum nexthop_types_t nh_type);
  76. extern int nexthop_same_no_recurse (struct nexthop *next1, struct nexthop *next2);
  77. #endif /*_LIB_NEXTHOP_H */