routemap.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. /* Route map's type. */
  24. enum route_map_type
  25. {
  26. RMAP_PERMIT,
  27. RMAP_DENY,
  28. RMAP_ANY
  29. };
  30. typedef enum
  31. {
  32. RMAP_MATCH,
  33. RMAP_DENYMATCH,
  34. RMAP_NOMATCH,
  35. RMAP_ERROR,
  36. RMAP_OKAY
  37. } route_map_result_t;
  38. typedef enum
  39. {
  40. RMAP_RIP,
  41. RMAP_RIPNG,
  42. RMAP_BABEL,
  43. RMAP_OSPF,
  44. RMAP_OSPF6,
  45. RMAP_BGP,
  46. RMAP_ZEBRA,
  47. RMAP_ISIS,
  48. } route_map_object_t;
  49. typedef enum
  50. {
  51. RMAP_EXIT,
  52. RMAP_GOTO,
  53. RMAP_NEXT
  54. } route_map_end_t;
  55. typedef enum
  56. {
  57. RMAP_EVENT_SET_ADDED,
  58. RMAP_EVENT_SET_DELETED,
  59. RMAP_EVENT_SET_REPLACED,
  60. RMAP_EVENT_MATCH_ADDED,
  61. RMAP_EVENT_MATCH_DELETED,
  62. RMAP_EVENT_MATCH_REPLACED,
  63. RMAP_EVENT_INDEX_ADDED,
  64. RMAP_EVENT_INDEX_DELETED
  65. } route_map_event_t;
  66. /* Depth limit in RMAP recursion using RMAP_CALL. */
  67. #define RMAP_RECURSION_LIMIT 10
  68. /* Route map rule structure for matching and setting. */
  69. struct route_map_rule_cmd
  70. {
  71. /* Route map rule name (e.g. as-path, metric) */
  72. const char *str;
  73. /* Function for value set or match. */
  74. route_map_result_t (*func_apply)(void *, struct prefix *,
  75. route_map_object_t, void *);
  76. /* Compile argument and return result as void *. */
  77. void *(*func_compile)(const char *);
  78. /* Free allocated value by func_compile (). */
  79. void (*func_free)(void *);
  80. };
  81. /* Route map apply error. */
  82. enum
  83. {
  84. /* Route map rule is missing. */
  85. RMAP_RULE_MISSING = 1,
  86. /* Route map rule can't compile */
  87. RMAP_COMPILE_ERROR
  88. };
  89. /* Route map rule list. */
  90. struct route_map_rule_list
  91. {
  92. struct route_map_rule *head;
  93. struct route_map_rule *tail;
  94. };
  95. /* Route map index structure. */
  96. struct route_map_index
  97. {
  98. struct route_map *map;
  99. char *description;
  100. /* Preference of this route map rule. */
  101. int pref;
  102. /* Route map type permit or deny. */
  103. enum route_map_type type;
  104. /* Do we follow old rules, or hop forward? */
  105. route_map_end_t exitpolicy;
  106. /* If we're using "GOTO", to where do we go? */
  107. int nextpref;
  108. /* If we're using "CALL", to which route-map do ew go? */
  109. char *nextrm;
  110. /* Matching rule list. */
  111. struct route_map_rule_list match_list;
  112. struct route_map_rule_list set_list;
  113. /* Make linked list. */
  114. struct route_map_index *next;
  115. struct route_map_index *prev;
  116. };
  117. /* Route map list structure. */
  118. struct route_map
  119. {
  120. /* Name of route map. */
  121. char *name;
  122. /* Route map's rule. */
  123. struct route_map_index *head;
  124. struct route_map_index *tail;
  125. /* Make linked list. */
  126. struct route_map *next;
  127. struct route_map *prev;
  128. };
  129. /* Prototypes. */
  130. extern void route_map_init (void);
  131. extern void route_map_init_vty (void);
  132. extern void route_map_finish (void);
  133. /* Add match statement to route map. */
  134. extern int route_map_add_match (struct route_map_index *index,
  135. const char *match_name,
  136. const char *match_arg);
  137. /* Delete specified route match rule. */
  138. extern int route_map_delete_match (struct route_map_index *index,
  139. const char *match_name,
  140. const char *match_arg);
  141. /* Add route-map set statement to the route map. */
  142. extern int route_map_add_set (struct route_map_index *index,
  143. const char *set_name,
  144. const char *set_arg);
  145. /* Delete route map set rule. */
  146. extern int route_map_delete_set (struct route_map_index *index,
  147. const char *set_name,
  148. const char *set_arg);
  149. /* Install rule command to the match list. */
  150. extern void route_map_install_match (struct route_map_rule_cmd *cmd);
  151. /* Install rule command to the set list. */
  152. extern void route_map_install_set (struct route_map_rule_cmd *cmd);
  153. /* Lookup route map by name. */
  154. extern struct route_map * route_map_lookup_by_name (const char *name);
  155. /* Apply route map to the object. */
  156. extern route_map_result_t route_map_apply (struct route_map *map,
  157. struct prefix *,
  158. route_map_object_t object_type,
  159. void *object);
  160. extern void route_map_add_hook (void (*func) (const char *));
  161. extern void route_map_delete_hook (void (*func) (const char *));
  162. extern void route_map_event_hook (void (*func) (route_map_event_t, const char *));
  163. extern void *route_map_rule_tag_compile (const char *arg);
  164. extern void route_map_rule_tag_free (void *rule);
  165. #endif /* _ZEBRA_ROUTEMAP_H */