]>
Commit | Line | Data |
---|---|---|
718e3744 | 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 | * | |
896014f4 DL |
16 | * You should have received a copy of the GNU General Public License along |
17 | * with this program; see the file COPYING; if not, write to the Free Software | |
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
718e3744 | 19 | */ |
20 | ||
21 | #ifndef _ZEBRA_ROUTEMAP_H | |
22 | #define _ZEBRA_ROUTEMAP_H | |
23 | ||
24873f0c | 24 | #include "prefix.h" |
4a1ab8e4 | 25 | #include "memory.h" |
e80e7cce | 26 | #include "qobj.h" |
0a538fc9 QY |
27 | #include "vty.h" |
28 | ||
4a1ab8e4 DL |
29 | DECLARE_MTYPE(ROUTE_MAP_NAME) |
30 | DECLARE_MTYPE(ROUTE_MAP_RULE) | |
31 | DECLARE_MTYPE(ROUTE_MAP_COMPILED) | |
24873f0c | 32 | |
718e3744 | 33 | /* Route map's type. */ |
d62a17ae | 34 | enum route_map_type { RMAP_PERMIT, RMAP_DENY, RMAP_ANY }; |
35 | ||
36 | typedef enum { | |
37 | RMAP_MATCH, | |
38 | RMAP_DENYMATCH, | |
39 | RMAP_NOMATCH, | |
40 | RMAP_ERROR, | |
41 | RMAP_OKAY | |
718e3744 | 42 | } route_map_result_t; |
43 | ||
d62a17ae | 44 | typedef enum { |
45 | RMAP_RIP, | |
46 | RMAP_RIPNG, | |
47 | RMAP_OSPF, | |
48 | RMAP_OSPF6, | |
49 | RMAP_BGP, | |
50 | RMAP_ZEBRA, | |
51 | RMAP_ISIS, | |
718e3744 | 52 | } route_map_object_t; |
53 | ||
d62a17ae | 54 | typedef enum { RMAP_EXIT, RMAP_GOTO, RMAP_NEXT } route_map_end_t; |
55 | ||
56 | typedef enum { | |
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 | RMAP_EVENT_CALL_ADDED, /* call to another routemap added */ | |
66 | RMAP_EVENT_CALL_DELETED, | |
67 | RMAP_EVENT_PLIST_ADDED, | |
68 | RMAP_EVENT_PLIST_DELETED, | |
69 | RMAP_EVENT_CLIST_ADDED, | |
70 | RMAP_EVENT_CLIST_DELETED, | |
71 | RMAP_EVENT_ECLIST_ADDED, | |
72 | RMAP_EVENT_ECLIST_DELETED, | |
73 | RMAP_EVENT_LLIST_ADDED, | |
74 | RMAP_EVENT_LLIST_DELETED, | |
75 | RMAP_EVENT_ASLIST_ADDED, | |
76 | RMAP_EVENT_ASLIST_DELETED, | |
77 | RMAP_EVENT_FILTER_ADDED, | |
78 | RMAP_EVENT_FILTER_DELETED, | |
718e3744 | 79 | } route_map_event_t; |
80 | ||
fee0f4c6 | 81 | /* Depth limit in RMAP recursion using RMAP_CALL. */ |
82 | #define RMAP_RECURSION_LIMIT 10 | |
83 | ||
718e3744 | 84 | /* Route map rule structure for matching and setting. */ |
d62a17ae | 85 | struct route_map_rule_cmd { |
86 | /* Route map rule name (e.g. as-path, metric) */ | |
87 | const char *str; | |
718e3744 | 88 | |
d62a17ae | 89 | /* Function for value set or match. */ |
90 | route_map_result_t (*func_apply)(void *, struct prefix *, | |
91 | route_map_object_t, void *); | |
718e3744 | 92 | |
d62a17ae | 93 | /* Compile argument and return result as void *. */ |
94 | void *(*func_compile)(const char *); | |
718e3744 | 95 | |
d62a17ae | 96 | /* Free allocated value by func_compile (). */ |
97 | void (*func_free)(void *); | |
718e3744 | 98 | }; |
99 | ||
100 | /* Route map apply error. */ | |
d62a17ae | 101 | enum { |
9ca25fed DS |
102 | RMAP_COMPILE_SUCCESS, |
103 | ||
d62a17ae | 104 | /* Route map rule is missing. */ |
9ca25fed | 105 | RMAP_RULE_MISSING, |
718e3744 | 106 | |
d62a17ae | 107 | /* Route map rule can't compile */ |
108 | RMAP_COMPILE_ERROR | |
718e3744 | 109 | }; |
110 | ||
111 | /* Route map rule list. */ | |
d62a17ae | 112 | struct route_map_rule_list { |
113 | struct route_map_rule *head; | |
114 | struct route_map_rule *tail; | |
718e3744 | 115 | }; |
116 | ||
117 | /* Route map index structure. */ | |
d62a17ae | 118 | struct route_map_index { |
119 | struct route_map *map; | |
120 | char *description; | |
718e3744 | 121 | |
d62a17ae | 122 | /* Preference of this route map rule. */ |
123 | int pref; | |
718e3744 | 124 | |
d62a17ae | 125 | /* Route map type permit or deny. */ |
126 | enum route_map_type type; | |
718e3744 | 127 | |
d62a17ae | 128 | /* Do we follow old rules, or hop forward? */ |
129 | route_map_end_t exitpolicy; | |
718e3744 | 130 | |
d62a17ae | 131 | /* If we're using "GOTO", to where do we go? */ |
132 | int nextpref; | |
718e3744 | 133 | |
d62a17ae | 134 | /* If we're using "CALL", to which route-map do ew go? */ |
135 | char *nextrm; | |
fee0f4c6 | 136 | |
d62a17ae | 137 | /* Matching rule list. */ |
138 | struct route_map_rule_list match_list; | |
139 | struct route_map_rule_list set_list; | |
718e3744 | 140 | |
d62a17ae | 141 | /* Make linked list. */ |
142 | struct route_map_index *next; | |
143 | struct route_map_index *prev; | |
e80e7cce | 144 | |
d62a17ae | 145 | QOBJ_FIELDS |
718e3744 | 146 | }; |
e80e7cce | 147 | DECLARE_QOBJ_TYPE(route_map_index) |
718e3744 | 148 | |
149 | /* Route map list structure. */ | |
d62a17ae | 150 | struct route_map { |
151 | /* Name of route map. */ | |
152 | char *name; | |
718e3744 | 153 | |
d62a17ae | 154 | /* Route map's rule. */ |
155 | struct route_map_index *head; | |
156 | struct route_map_index *tail; | |
718e3744 | 157 | |
d62a17ae | 158 | /* Make linked list. */ |
159 | struct route_map *next; | |
160 | struct route_map *prev; | |
518f0eb1 | 161 | |
d62a17ae | 162 | /* Maintain update info */ |
163 | int to_be_processed; /* True if modification isn't acted on yet */ | |
164 | int deleted; /* If 1, then this node will be deleted */ | |
e80e7cce | 165 | |
d62a17ae | 166 | QOBJ_FIELDS |
718e3744 | 167 | }; |
e80e7cce | 168 | DECLARE_QOBJ_TYPE(route_map) |
718e3744 | 169 | |
170 | /* Prototypes. */ | |
d62a17ae | 171 | extern void route_map_init(void); |
172 | extern void route_map_finish(void); | |
718e3744 | 173 | |
174 | /* Add match statement to route map. */ | |
d62a17ae | 175 | extern int route_map_add_match(struct route_map_index *index, |
176 | const char *match_name, const char *match_arg); | |
718e3744 | 177 | |
178 | /* Delete specified route match rule. */ | |
d62a17ae | 179 | extern int route_map_delete_match(struct route_map_index *index, |
180 | const char *match_name, | |
181 | const char *match_arg); | |
718e3744 | 182 | |
d62a17ae | 183 | extern const char *route_map_get_match_arg(struct route_map_index *index, |
184 | const char *match_name); | |
518f0eb1 | 185 | |
718e3744 | 186 | /* Add route-map set statement to the route map. */ |
d62a17ae | 187 | extern int route_map_add_set(struct route_map_index *index, |
188 | const char *set_name, const char *set_arg); | |
718e3744 | 189 | |
190 | /* Delete route map set rule. */ | |
d62a17ae | 191 | extern int route_map_delete_set(struct route_map_index *index, |
192 | const char *set_name, const char *set_arg); | |
718e3744 | 193 | |
194 | /* Install rule command to the match list. */ | |
d62a17ae | 195 | extern void route_map_install_match(struct route_map_rule_cmd *cmd); |
718e3744 | 196 | |
6a74c5f9 DS |
197 | /* |
198 | * Install rule command to the set list. | |
199 | * | |
200 | * When installing a particular item, Allow a difference of handling | |
201 | * of bad cli inputted(return NULL) -vs- this particular daemon cannot use | |
202 | * this form of the command(return a pointer and handle it appropriately | |
203 | * in the apply command). See 'set metric' command | |
204 | * as it is handled in ripd/ripngd and ospfd. | |
205 | */ | |
d62a17ae | 206 | extern void route_map_install_set(struct route_map_rule_cmd *cmd); |
718e3744 | 207 | |
208 | /* Lookup route map by name. */ | |
d62a17ae | 209 | extern struct route_map *route_map_lookup_by_name(const char *name); |
718e3744 | 210 | |
211 | /* Apply route map to the object. */ | |
d62a17ae | 212 | extern route_map_result_t route_map_apply(struct route_map *map, |
213 | struct prefix *, | |
214 | route_map_object_t object_type, | |
215 | void *object); | |
216 | ||
217 | extern void route_map_add_hook(void (*func)(const char *)); | |
218 | extern void route_map_delete_hook(void (*func)(const char *)); | |
219 | extern void route_map_event_hook(void (*func)(route_map_event_t, const char *)); | |
220 | extern int route_map_mark_updated(const char *name, int deleted); | |
221 | extern int route_map_clear_updated(struct route_map *rmap); | |
222 | extern void route_map_walk_update_list(int (*update_fn)(char *name)); | |
223 | extern void route_map_upd8_dependency(route_map_event_t type, const char *arg, | |
224 | const char *rmap_name); | |
225 | extern void route_map_notify_dependencies(const char *affected_name, | |
226 | route_map_event_t event); | |
227 | ||
228 | extern int generic_match_add(struct vty *vty, struct route_map_index *index, | |
229 | const char *command, const char *arg, | |
230 | route_map_event_t type); | |
231 | ||
232 | extern int generic_match_delete(struct vty *vty, struct route_map_index *index, | |
233 | const char *command, const char *arg, | |
234 | route_map_event_t type); | |
235 | extern int generic_set_add(struct vty *vty, struct route_map_index *index, | |
236 | const char *command, const char *arg); | |
237 | extern int generic_set_delete(struct vty *vty, struct route_map_index *index, | |
238 | const char *command, const char *arg); | |
82f97584 DW |
239 | |
240 | ||
241 | /* match interface */ | |
d62a17ae | 242 | extern void route_map_match_interface_hook(int (*func)( |
243 | struct vty *vty, struct route_map_index *index, const char *command, | |
244 | const char *arg, route_map_event_t type)); | |
82f97584 | 245 | /* no match interface */ |
d62a17ae | 246 | extern void route_map_no_match_interface_hook(int (*func)( |
247 | struct vty *vty, struct route_map_index *index, const char *command, | |
248 | const char *arg, route_map_event_t type)); | |
82f97584 | 249 | /* match ip address */ |
d62a17ae | 250 | extern void route_map_match_ip_address_hook(int (*func)( |
251 | struct vty *vty, struct route_map_index *index, const char *command, | |
252 | const char *arg, route_map_event_t type)); | |
82f97584 | 253 | /* no match ip address */ |
d62a17ae | 254 | extern void route_map_no_match_ip_address_hook(int (*func)( |
255 | struct vty *vty, struct route_map_index *index, const char *command, | |
256 | const char *arg, route_map_event_t type)); | |
82f97584 | 257 | /* match ip address prefix list */ |
d62a17ae | 258 | extern void route_map_match_ip_address_prefix_list_hook(int (*func)( |
259 | struct vty *vty, struct route_map_index *index, const char *command, | |
260 | const char *arg, route_map_event_t type)); | |
82f97584 | 261 | /* no match ip address prefix list */ |
d62a17ae | 262 | extern void route_map_no_match_ip_address_prefix_list_hook(int (*func)( |
263 | struct vty *vty, struct route_map_index *index, const char *command, | |
264 | const char *arg, route_map_event_t type)); | |
82f97584 | 265 | /* match ip next hop */ |
d62a17ae | 266 | extern void route_map_match_ip_next_hop_hook(int (*func)( |
267 | struct vty *vty, struct route_map_index *index, const char *command, | |
268 | const char *arg, route_map_event_t type)); | |
82f97584 | 269 | /* no match ip next hop */ |
d62a17ae | 270 | extern void route_map_no_match_ip_next_hop_hook(int (*func)( |
271 | struct vty *vty, struct route_map_index *index, const char *command, | |
272 | const char *arg, route_map_event_t type)); | |
82f97584 | 273 | /* match ip next hop prefix list */ |
d62a17ae | 274 | extern void route_map_match_ip_next_hop_prefix_list_hook(int (*func)( |
275 | struct vty *vty, struct route_map_index *index, const char *command, | |
276 | const char *arg, route_map_event_t type)); | |
82f97584 | 277 | /* no match ip next hop prefix list */ |
d62a17ae | 278 | extern void route_map_no_match_ip_next_hop_prefix_list_hook(int (*func)( |
279 | struct vty *vty, struct route_map_index *index, const char *command, | |
280 | const char *arg, route_map_event_t type)); | |
82f97584 | 281 | /* match ipv6 address */ |
d62a17ae | 282 | extern void route_map_match_ipv6_address_hook(int (*func)( |
283 | struct vty *vty, struct route_map_index *index, const char *command, | |
284 | const char *arg, route_map_event_t type)); | |
82f97584 | 285 | /* no match ipv6 address */ |
d62a17ae | 286 | extern void route_map_no_match_ipv6_address_hook(int (*func)( |
287 | struct vty *vty, struct route_map_index *index, const char *command, | |
288 | const char *arg, route_map_event_t type)); | |
82f97584 | 289 | /* match ipv6 address prefix list */ |
d62a17ae | 290 | extern void route_map_match_ipv6_address_prefix_list_hook(int (*func)( |
291 | struct vty *vty, struct route_map_index *index, const char *command, | |
292 | const char *arg, route_map_event_t type)); | |
82f97584 | 293 | /* no match ipv6 address prefix list */ |
d62a17ae | 294 | extern void route_map_no_match_ipv6_address_prefix_list_hook(int (*func)( |
295 | struct vty *vty, struct route_map_index *index, const char *command, | |
296 | const char *arg, route_map_event_t type)); | |
82f97584 | 297 | /* match metric */ |
d62a17ae | 298 | extern void route_map_match_metric_hook(int (*func)( |
299 | struct vty *vty, struct route_map_index *index, const char *command, | |
300 | const char *arg, route_map_event_t type)); | |
82f97584 | 301 | /* no match metric */ |
d62a17ae | 302 | extern void route_map_no_match_metric_hook(int (*func)( |
303 | struct vty *vty, struct route_map_index *index, const char *command, | |
304 | const char *arg, route_map_event_t type)); | |
82f97584 | 305 | /* match tag */ |
d62a17ae | 306 | extern void route_map_match_tag_hook(int (*func)( |
307 | struct vty *vty, struct route_map_index *index, const char *command, | |
308 | const char *arg, route_map_event_t type)); | |
82f97584 | 309 | /* no match tag */ |
d62a17ae | 310 | extern void route_map_no_match_tag_hook(int (*func)( |
311 | struct vty *vty, struct route_map_index *index, const char *command, | |
312 | const char *arg, route_map_event_t type)); | |
82f97584 | 313 | /* set ip nexthop */ |
d62a17ae | 314 | extern void route_map_set_ip_nexthop_hook( |
315 | int (*func)(struct vty *vty, struct route_map_index *index, | |
316 | const char *command, const char *arg)); | |
82f97584 | 317 | /* no set ip nexthop */ |
d62a17ae | 318 | extern void route_map_no_set_ip_nexthop_hook( |
319 | int (*func)(struct vty *vty, struct route_map_index *index, | |
320 | const char *command, const char *arg)); | |
82f97584 | 321 | /* set ipv6 nexthop local */ |
d62a17ae | 322 | extern void route_map_set_ipv6_nexthop_local_hook( |
323 | int (*func)(struct vty *vty, struct route_map_index *index, | |
324 | const char *command, const char *arg)); | |
82f97584 | 325 | /* no set ipv6 nexthop local */ |
d62a17ae | 326 | extern void route_map_no_set_ipv6_nexthop_local_hook( |
327 | int (*func)(struct vty *vty, struct route_map_index *index, | |
328 | const char *command, const char *arg)); | |
82f97584 | 329 | /* set metric */ |
d62a17ae | 330 | extern void route_map_set_metric_hook(int (*func)(struct vty *vty, |
331 | struct route_map_index *index, | |
332 | const char *command, | |
333 | const char *arg)); | |
82f97584 | 334 | /* no set metric */ |
d62a17ae | 335 | extern void route_map_no_set_metric_hook( |
336 | int (*func)(struct vty *vty, struct route_map_index *index, | |
337 | const char *command, const char *arg)); | |
82f97584 | 338 | /* set tag */ |
d62a17ae | 339 | extern void route_map_set_tag_hook(int (*func)(struct vty *vty, |
340 | struct route_map_index *index, | |
341 | const char *command, | |
342 | const char *arg)); | |
82f97584 | 343 | /* no set tag */ |
d62a17ae | 344 | extern void route_map_no_set_tag_hook(int (*func)(struct vty *vty, |
345 | struct route_map_index *index, | |
346 | const char *command, | |
347 | const char *arg)); | |
e52702f2 | 348 | |
d62a17ae | 349 | extern void *route_map_rule_tag_compile(const char *arg); |
350 | extern void route_map_rule_tag_free(void *rule); | |
dc9ffce8 | 351 | |
718e3744 | 352 | #endif /* _ZEBRA_ROUTEMAP_H */ |