vrf.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * VRF related header.
  3. * Copyright (C) 2014 6WIND S.A.
  4. *
  5. * This file is part of GNU Zebra.
  6. *
  7. * GNU Zebra is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published
  9. * by the Free Software Foundation; either version 2, or (at your
  10. * option) any later version.
  11. *
  12. * GNU Zebra is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with GNU Zebra; see the file COPYING. If not, write to the
  19. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  20. * Boston, MA 02111-1307, USA.
  21. */
  22. #ifndef _ZEBRA_VRF_H
  23. #define _ZEBRA_VRF_H
  24. #include "linklist.h"
  25. /* The default VRF ID */
  26. #define VRF_DEFAULT 0
  27. /*
  28. * The command strings
  29. */
  30. #define VRF_CMD_STR "vrf <0-65535>"
  31. #define VRF_CMD_HELP_STR "Specify the VRF\nThe VRF ID\n"
  32. #define VRF_ALL_CMD_STR "vrf all"
  33. #define VRF_ALL_CMD_HELP_STR "Specify the VRF\nAll VRFs\n"
  34. /*
  35. * VRF hooks
  36. */
  37. #define VRF_NEW_HOOK 0 /* a new VRF is just created */
  38. #define VRF_DELETE_HOOK 1 /* a VRF is to be deleted */
  39. #define VRF_ENABLE_HOOK 2 /* a VRF is ready to use */
  40. #define VRF_DISABLE_HOOK 3 /* a VRF is to be unusable */
  41. /*
  42. * Add a specific hook to VRF module.
  43. * @param1: hook type
  44. * @param2: the callback function
  45. * - param 1: the VRF ID
  46. * - param 2: the address of the user data pointer (the user data
  47. * can be stored in or freed from there)
  48. */
  49. extern void vrf_add_hook (int, int (*)(vrf_id_t, void **));
  50. /*
  51. * VRF iteration
  52. */
  53. typedef void * vrf_iter_t;
  54. #define VRF_ITER_INVALID NULL /* invalid value of the iterator */
  55. /*
  56. * VRF iteration utilities. Example for the usage:
  57. *
  58. * vrf_iter_t iter = vrf_first();
  59. * for (; iter != VRF_ITER_INVALID; iter = vrf_next (iter))
  60. *
  61. * or
  62. *
  63. * vrf_iter_t iter = vrf_iterator (<a given VRF ID>);
  64. * for (; iter != VRF_ITER_INVALID; iter = vrf_next (iter))
  65. */
  66. /* Return the iterator of the first VRF. */
  67. extern vrf_iter_t vrf_first (void);
  68. /* Return the next VRF iterator to the given iterator. */
  69. extern vrf_iter_t vrf_next (vrf_iter_t);
  70. /* Return the VRF iterator of the given VRF ID. If it does not exist,
  71. * the iterator of the next existing VRF is returned. */
  72. extern vrf_iter_t vrf_iterator (vrf_id_t);
  73. /*
  74. * VRF iterator to properties
  75. */
  76. extern vrf_id_t vrf_iter2id (vrf_iter_t);
  77. extern void *vrf_iter2info (vrf_iter_t);
  78. extern struct list *vrf_iter2iflist (vrf_iter_t);
  79. /*
  80. * Utilities to obtain the user data
  81. */
  82. /* Get the data pointer of the specified VRF. If not found, create one. */
  83. extern void *vrf_info_get (vrf_id_t);
  84. /* Look up the data pointer of the specified VRF. */
  85. extern void *vrf_info_lookup (vrf_id_t);
  86. /*
  87. * Utilities to obtain the interface list
  88. */
  89. /* Look up the interface list of the specified VRF. */
  90. extern struct list *vrf_iflist (vrf_id_t);
  91. /* Get the interface list of the specified VRF. Create one if not find. */
  92. extern struct list *vrf_iflist_get (vrf_id_t);
  93. /*
  94. * VRF bit-map: maintaining flags, one bit per VRF ID
  95. */
  96. typedef void * vrf_bitmap_t;
  97. #define VRF_BITMAP_NULL NULL
  98. extern vrf_bitmap_t vrf_bitmap_init (void);
  99. extern void vrf_bitmap_free (vrf_bitmap_t);
  100. extern void vrf_bitmap_set (vrf_bitmap_t, vrf_id_t);
  101. extern void vrf_bitmap_unset (vrf_bitmap_t, vrf_id_t);
  102. extern int vrf_bitmap_check (vrf_bitmap_t, vrf_id_t);
  103. /*
  104. * VRF initializer/destructor
  105. */
  106. /* Please add hooks before calling vrf_init(). */
  107. extern void vrf_init (void);
  108. extern void vrf_terminate (void);
  109. /*
  110. * VRF utilities
  111. */
  112. /* Create a socket serving for the given VRF */
  113. extern int vrf_socket (int, int, int, vrf_id_t);
  114. #endif /*_ZEBRA_VRF_H*/