routemap.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /* Route map function.
  2. * Copyright (C) 1998 Kunihiro Ishiguro
  3. *
  4. * This file is part of GNU Zebra.
  5. *
  6. * GNU Zebra is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; either version 2, or (at your option) any
  9. * later version.
  10. *
  11. * GNU Zebra is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with GNU Zebra; see the file COPYING. If not, write to the Free
  18. * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  19. * 02111-1307, USA.
  20. */
  21. #ifndef _ZEBRA_ROUTEMAP_H
  22. #define _ZEBRA_ROUTEMAP_H
  23. #include "prefix.h"
  24. /* Route map's type. */
  25. enum route_map_type
  26. {
  27. RMAP_PERMIT,
  28. RMAP_DENY,
  29. RMAP_ANY
  30. };
  31. typedef enum
  32. {
  33. RMAP_MATCH,
  34. RMAP_DENYMATCH,
  35. RMAP_NOMATCH,
  36. RMAP_ERROR,
  37. RMAP_OKAY
  38. } route_map_result_t;
  39. typedef enum
  40. {
  41. RMAP_RIP,
  42. RMAP_RIPNG,
  43. RMAP_BABEL,
  44. RMAP_OSPF,
  45. RMAP_OSPF6,
  46. RMAP_BGP,
  47. RMAP_ZEBRA,
  48. RMAP_ISIS,
  49. } route_map_object_t;
  50. typedef enum
  51. {
  52. RMAP_EXIT,
  53. RMAP_GOTO,
  54. RMAP_NEXT
  55. } route_map_end_t;
  56. typedef enum
  57. {
  58. RMAP_EVENT_SET_ADDED,
  59. RMAP_EVENT_SET_DELETED,
  60. RMAP_EVENT_SET_REPLACED,
  61. RMAP_EVENT_MATCH_ADDED,
  62. RMAP_EVENT_MATCH_DELETED,
  63. RMAP_EVENT_MATCH_REPLACED,
  64. RMAP_EVENT_INDEX_ADDED,
  65. RMAP_EVENT_INDEX_DELETED
  66. } route_map_event_t;
  67. /* Depth limit in RMAP recursion using RMAP_CALL. */
  68. #define RMAP_RECURSION_LIMIT 10
  69. /* Route map rule structure for matching and setting. */
  70. struct route_map_rule_cmd
  71. {
  72. /* Route map rule name (e.g. as-path, metric) */
  73. const char *str;
  74. /* Function for value set or match. */
  75. route_map_result_t (*func_apply)(void *, struct prefix *,
  76. route_map_object_t, void *);
  77. /* Compile argument and return result as void *. */
  78. void *(*func_compile)(const char *);
  79. /* Free allocated value by func_compile (). */
  80. void (*func_free)(void *);
  81. };
  82. /* Route map apply error. */
  83. enum
  84. {
  85. /* Route map rule is missing. */
  86. RMAP_RULE_MISSING = 1,
  87. /* Route map rule can't compile */
  88. RMAP_COMPILE_ERROR
  89. };
  90. /* Route map rule list. */
  91. struct route_map_rule_list
  92. {
  93. struct route_map_rule *head;
  94. struct route_map_rule *tail;
  95. };
  96. /* Route map index structure. */
  97. struct route_map_index
  98. {
  99. struct route_map *map;
  100. char *description;
  101. /* Preference of this route map rule. */
  102. int pref;
  103. /* Route map type permit or deny. */
  104. enum route_map_type type;
  105. /* Do we follow old rules, or hop forward? */
  106. route_map_end_t exitpolicy;
  107. /* If we're using "GOTO", to where do we go? */
  108. int nextpref;
  109. /* If we're using "CALL", to which route-map do ew go? */
  110. char *nextrm;
  111. /* Matching rule list. */
  112. struct route_map_rule_list match_list;
  113. struct route_map_rule_list set_list;
  114. /* Make linked list. */
  115. struct route_map_index *next;
  116. struct route_map_index *prev;
  117. };
  118. /* Route map list structure. */
  119. struct route_map
  120. {
  121. /* Name of route map. */
  122. char *name;
  123. /* Route map's rule. */
  124. struct route_map_index *head;
  125. struct route_map_index *tail;
  126. /* Make linked list. */
  127. struct route_map *next;
  128. struct route_map *prev;
  129. };
  130. /* Prototypes. */
  131. extern void route_map_init (void);
  132. extern void route_map_init_vty (void);
  133. extern void route_map_finish (void);
  134. /* Add match statement to route map. */
  135. extern int route_map_add_match (struct route_map_index *index,
  136. const char *match_name,
  137. const char *match_arg);
  138. /* Delete specified route match rule. */
  139. extern int route_map_delete_match (struct route_map_index *index,
  140. const char *match_name,
  141. const char *match_arg);
  142. /* Add route-map set statement to the route map. */
  143. extern int route_map_add_set (struct route_map_index *index,
  144. const char *set_name,
  145. const char *set_arg);
  146. /* Delete route map set rule. */
  147. extern int route_map_delete_set (struct route_map_index *index,
  148. const char *set_name,
  149. const char *set_arg);
  150. /* Install rule command to the match list. */
  151. extern void route_map_install_match (struct route_map_rule_cmd *cmd);
  152. /* Install rule command to the set list. */
  153. extern void route_map_install_set (struct route_map_rule_cmd *cmd);
  154. /* Lookup route map by name. */
  155. extern struct route_map * route_map_lookup_by_name (const char *name);
  156. /* Apply route map to the object. */
  157. extern route_map_result_t route_map_apply (struct route_map *map,
  158. struct prefix *,
  159. route_map_object_t object_type,
  160. void *object);
  161. extern void route_map_add_hook (void (*func) (const char *));
  162. extern void route_map_delete_hook (void (*func) (const char *));
  163. extern void route_map_event_hook (void (*func) (route_map_event_t, const char *));
  164. extern void *route_map_rule_tag_compile (const char *arg);
  165. extern void route_map_rule_tag_free (void *rule);
  166. #endif /* _ZEBRA_ROUTEMAP_H */