routemap.h 4.9 KB

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