paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 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 | |
| 22 | #ifndef _ZEBRA_ROUTEMAP_H |
| 23 | #define _ZEBRA_ROUTEMAP_H |
| 24 | |
| 25 | /* Route map's type. */ |
| 26 | enum route_map_type |
| 27 | { |
| 28 | RMAP_PERMIT, |
| 29 | RMAP_DENY, |
| 30 | RMAP_ANY |
| 31 | }; |
| 32 | |
| 33 | typedef enum |
| 34 | { |
| 35 | RMAP_MATCH, |
| 36 | RMAP_DENYMATCH, |
| 37 | RMAP_NOMATCH, |
| 38 | RMAP_ERROR, |
| 39 | RMAP_OKAY |
| 40 | } route_map_result_t; |
| 41 | |
| 42 | typedef enum |
| 43 | { |
| 44 | RMAP_RIP, |
| 45 | RMAP_RIPNG, |
Paul Jakma | 5734509 | 2011-12-25 17:52:09 +0100 | [diff] [blame] | 46 | RMAP_BABEL, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 47 | RMAP_OSPF, |
| 48 | RMAP_OSPF6, |
Paul Jakma | 7514fb7 | 2007-05-02 16:05:35 +0000 | [diff] [blame] | 49 | RMAP_BGP, |
| 50 | RMAP_ZEBRA |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 51 | } route_map_object_t; |
| 52 | |
| 53 | typedef enum |
| 54 | { |
| 55 | RMAP_EXIT, |
| 56 | RMAP_GOTO, |
| 57 | RMAP_NEXT |
| 58 | } route_map_end_t; |
| 59 | |
| 60 | typedef enum |
| 61 | { |
| 62 | RMAP_EVENT_SET_ADDED, |
| 63 | RMAP_EVENT_SET_DELETED, |
| 64 | RMAP_EVENT_SET_REPLACED, |
| 65 | RMAP_EVENT_MATCH_ADDED, |
| 66 | RMAP_EVENT_MATCH_DELETED, |
| 67 | RMAP_EVENT_MATCH_REPLACED, |
| 68 | RMAP_EVENT_INDEX_ADDED, |
| 69 | RMAP_EVENT_INDEX_DELETED |
| 70 | } route_map_event_t; |
| 71 | |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 72 | /* Depth limit in RMAP recursion using RMAP_CALL. */ |
| 73 | #define RMAP_RECURSION_LIMIT 10 |
| 74 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 75 | /* Route map rule structure for matching and setting. */ |
| 76 | struct route_map_rule_cmd |
| 77 | { |
| 78 | /* Route map rule name (e.g. as-path, metric) */ |
hasso | 27a43a8 | 2004-10-08 06:29:12 +0000 | [diff] [blame] | 79 | const char *str; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 80 | |
| 81 | /* Function for value set or match. */ |
| 82 | route_map_result_t (*func_apply)(void *, struct prefix *, |
| 83 | route_map_object_t, void *); |
| 84 | |
| 85 | /* Compile argument and return result as void *. */ |
paul | c9eca01 | 2004-10-11 11:28:44 +0000 | [diff] [blame] | 86 | void *(*func_compile)(const char *); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 87 | |
| 88 | /* Free allocated value by func_compile (). */ |
| 89 | void (*func_free)(void *); |
| 90 | }; |
| 91 | |
| 92 | /* Route map apply error. */ |
| 93 | enum |
| 94 | { |
| 95 | /* Route map rule is missing. */ |
| 96 | RMAP_RULE_MISSING = 1, |
| 97 | |
| 98 | /* Route map rule can't compile */ |
| 99 | RMAP_COMPILE_ERROR |
| 100 | }; |
| 101 | |
| 102 | /* Route map rule list. */ |
| 103 | struct route_map_rule_list |
| 104 | { |
| 105 | struct route_map_rule *head; |
| 106 | struct route_map_rule *tail; |
| 107 | }; |
| 108 | |
| 109 | /* Route map index structure. */ |
| 110 | struct route_map_index |
| 111 | { |
| 112 | struct route_map *map; |
hasso | 4a8164e | 2005-04-08 14:20:18 +0000 | [diff] [blame] | 113 | char *description; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 114 | |
| 115 | /* Preference of this route map rule. */ |
| 116 | int pref; |
| 117 | |
| 118 | /* Route map type permit or deny. */ |
| 119 | enum route_map_type type; |
| 120 | |
| 121 | /* Do we follow old rules, or hop forward? */ |
| 122 | route_map_end_t exitpolicy; |
| 123 | |
| 124 | /* If we're using "GOTO", to where do we go? */ |
| 125 | int nextpref; |
| 126 | |
paul | fee0f4c | 2004-09-13 05:12:46 +0000 | [diff] [blame] | 127 | /* If we're using "CALL", to which route-map do ew go? */ |
| 128 | char *nextrm; |
| 129 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 130 | /* Matching rule list. */ |
| 131 | struct route_map_rule_list match_list; |
| 132 | struct route_map_rule_list set_list; |
| 133 | |
| 134 | /* Make linked list. */ |
| 135 | struct route_map_index *next; |
| 136 | struct route_map_index *prev; |
| 137 | }; |
| 138 | |
| 139 | /* Route map list structure. */ |
| 140 | struct route_map |
| 141 | { |
| 142 | /* Name of route map. */ |
| 143 | char *name; |
| 144 | |
| 145 | /* Route map's rule. */ |
| 146 | struct route_map_index *head; |
| 147 | struct route_map_index *tail; |
| 148 | |
| 149 | /* Make linked list. */ |
| 150 | struct route_map *next; |
| 151 | struct route_map *prev; |
| 152 | }; |
| 153 | |
| 154 | /* Prototypes. */ |
paul | 8cc4198 | 2005-05-06 21:25:49 +0000 | [diff] [blame] | 155 | extern void route_map_init (void); |
| 156 | extern void route_map_init_vty (void); |
Chris Caputo | 228da42 | 2009-07-18 05:44:03 +0000 | [diff] [blame] | 157 | extern void route_map_finish (void); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 158 | |
| 159 | /* Add match statement to route map. */ |
paul | 8cc4198 | 2005-05-06 21:25:49 +0000 | [diff] [blame] | 160 | extern int route_map_add_match (struct route_map_index *index, |
| 161 | const char *match_name, |
| 162 | const char *match_arg); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 163 | |
| 164 | /* Delete specified route match rule. */ |
paul | 8cc4198 | 2005-05-06 21:25:49 +0000 | [diff] [blame] | 165 | extern int route_map_delete_match (struct route_map_index *index, |
| 166 | const char *match_name, |
| 167 | const char *match_arg); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 168 | |
| 169 | /* Add route-map set statement to the route map. */ |
paul | 8cc4198 | 2005-05-06 21:25:49 +0000 | [diff] [blame] | 170 | extern int route_map_add_set (struct route_map_index *index, |
| 171 | const char *set_name, |
| 172 | const char *set_arg); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 173 | |
| 174 | /* Delete route map set rule. */ |
paul | 8cc4198 | 2005-05-06 21:25:49 +0000 | [diff] [blame] | 175 | extern int route_map_delete_set (struct route_map_index *index, |
| 176 | const char *set_name, |
| 177 | const char *set_arg); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 178 | |
| 179 | /* Install rule command to the match list. */ |
paul | 8cc4198 | 2005-05-06 21:25:49 +0000 | [diff] [blame] | 180 | extern void route_map_install_match (struct route_map_rule_cmd *cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 181 | |
| 182 | /* Install rule command to the set list. */ |
paul | 8cc4198 | 2005-05-06 21:25:49 +0000 | [diff] [blame] | 183 | extern void route_map_install_set (struct route_map_rule_cmd *cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 184 | |
| 185 | /* Lookup route map by name. */ |
paul | 8cc4198 | 2005-05-06 21:25:49 +0000 | [diff] [blame] | 186 | extern struct route_map * route_map_lookup_by_name (const char *name); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 187 | |
| 188 | /* Apply route map to the object. */ |
paul | 8cc4198 | 2005-05-06 21:25:49 +0000 | [diff] [blame] | 189 | extern route_map_result_t route_map_apply (struct route_map *map, |
| 190 | struct prefix *, |
| 191 | route_map_object_t object_type, |
| 192 | void *object); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 193 | |
paul | 8cc4198 | 2005-05-06 21:25:49 +0000 | [diff] [blame] | 194 | extern void route_map_add_hook (void (*func) (const char *)); |
| 195 | extern void route_map_delete_hook (void (*func) (const char *)); |
| 196 | extern void route_map_event_hook (void (*func) (route_map_event_t, const char *)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 197 | |
| 198 | #endif /* _ZEBRA_ROUTEMAP_H */ |