]>
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 | ||
5e244469 RW |
29 | #ifdef __cplusplus |
30 | extern "C" { | |
31 | #endif | |
32 | ||
4a1ab8e4 DL |
33 | DECLARE_MTYPE(ROUTE_MAP_NAME) |
34 | DECLARE_MTYPE(ROUTE_MAP_RULE) | |
35 | DECLARE_MTYPE(ROUTE_MAP_COMPILED) | |
24873f0c | 36 | |
718e3744 | 37 | /* Route map's type. */ |
d62a17ae | 38 | enum route_map_type { RMAP_PERMIT, RMAP_DENY, RMAP_ANY }; |
39 | ||
40 | typedef enum { | |
2789041a | 41 | RMAP_MATCH, |
d62a17ae | 42 | RMAP_DENYMATCH, |
2789041a LK |
43 | RMAP_NOMATCH, |
44 | RMAP_ERROR, | |
45 | RMAP_OKAY | |
718e3744 | 46 | } route_map_result_t; |
47 | ||
d62a17ae | 48 | typedef enum { |
49 | RMAP_RIP, | |
50 | RMAP_RIPNG, | |
51 | RMAP_OSPF, | |
52 | RMAP_OSPF6, | |
53 | RMAP_BGP, | |
54 | RMAP_ZEBRA, | |
55 | RMAP_ISIS, | |
718e3744 | 56 | } route_map_object_t; |
57 | ||
d62a17ae | 58 | typedef enum { RMAP_EXIT, RMAP_GOTO, RMAP_NEXT } route_map_end_t; |
59 | ||
60 | typedef enum { | |
61 | RMAP_EVENT_SET_ADDED, | |
62 | RMAP_EVENT_SET_DELETED, | |
63 | RMAP_EVENT_SET_REPLACED, | |
64 | RMAP_EVENT_MATCH_ADDED, | |
65 | RMAP_EVENT_MATCH_DELETED, | |
66 | RMAP_EVENT_MATCH_REPLACED, | |
67 | RMAP_EVENT_INDEX_ADDED, | |
68 | RMAP_EVENT_INDEX_DELETED, | |
69 | RMAP_EVENT_CALL_ADDED, /* call to another routemap added */ | |
70 | RMAP_EVENT_CALL_DELETED, | |
71 | RMAP_EVENT_PLIST_ADDED, | |
72 | RMAP_EVENT_PLIST_DELETED, | |
73 | RMAP_EVENT_CLIST_ADDED, | |
74 | RMAP_EVENT_CLIST_DELETED, | |
75 | RMAP_EVENT_ECLIST_ADDED, | |
76 | RMAP_EVENT_ECLIST_DELETED, | |
77 | RMAP_EVENT_LLIST_ADDED, | |
78 | RMAP_EVENT_LLIST_DELETED, | |
79 | RMAP_EVENT_ASLIST_ADDED, | |
80 | RMAP_EVENT_ASLIST_DELETED, | |
81 | RMAP_EVENT_FILTER_ADDED, | |
82 | RMAP_EVENT_FILTER_DELETED, | |
718e3744 | 83 | } route_map_event_t; |
84 | ||
fee0f4c6 | 85 | /* Depth limit in RMAP recursion using RMAP_CALL. */ |
86 | #define RMAP_RECURSION_LIMIT 10 | |
87 | ||
718e3744 | 88 | /* Route map rule structure for matching and setting. */ |
d62a17ae | 89 | struct route_map_rule_cmd { |
90 | /* Route map rule name (e.g. as-path, metric) */ | |
91 | const char *str; | |
718e3744 | 92 | |
d62a17ae | 93 | /* Function for value set or match. */ |
2789041a LK |
94 | route_map_result_t (*func_apply)(void *rule, |
95 | const struct prefix *prefix, | |
96 | route_map_object_t type, | |
97 | void *object); | |
718e3744 | 98 | |
d62a17ae | 99 | /* Compile argument and return result as void *. */ |
100 | void *(*func_compile)(const char *); | |
718e3744 | 101 | |
d62a17ae | 102 | /* Free allocated value by func_compile (). */ |
103 | void (*func_free)(void *); | |
718e3744 | 104 | }; |
105 | ||
106 | /* Route map apply error. */ | |
e2c8d6ce NT |
107 | enum { |
108 | RMAP_COMPILE_SUCCESS, | |
9ca25fed | 109 | |
e2c8d6ce NT |
110 | /* Route map rule is missing. */ |
111 | RMAP_RULE_MISSING, | |
718e3744 | 112 | |
e2c8d6ce NT |
113 | /* Route map rule can't compile */ |
114 | RMAP_COMPILE_ERROR, | |
115 | ||
116 | /* Route map rule is duplicate */ | |
117 | RMAP_DUPLICATE_RULE | |
118 | }; | |
718e3744 | 119 | |
120 | /* Route map rule list. */ | |
d62a17ae | 121 | struct route_map_rule_list { |
122 | struct route_map_rule *head; | |
123 | struct route_map_rule *tail; | |
718e3744 | 124 | }; |
125 | ||
126 | /* Route map index structure. */ | |
d62a17ae | 127 | struct route_map_index { |
128 | struct route_map *map; | |
129 | char *description; | |
718e3744 | 130 | |
d62a17ae | 131 | /* Preference of this route map rule. */ |
132 | int pref; | |
718e3744 | 133 | |
d62a17ae | 134 | /* Route map type permit or deny. */ |
135 | enum route_map_type type; | |
718e3744 | 136 | |
d62a17ae | 137 | /* Do we follow old rules, or hop forward? */ |
138 | route_map_end_t exitpolicy; | |
718e3744 | 139 | |
d62a17ae | 140 | /* If we're using "GOTO", to where do we go? */ |
141 | int nextpref; | |
718e3744 | 142 | |
d62a17ae | 143 | /* If we're using "CALL", to which route-map do ew go? */ |
144 | char *nextrm; | |
fee0f4c6 | 145 | |
d62a17ae | 146 | /* Matching rule list. */ |
147 | struct route_map_rule_list match_list; | |
148 | struct route_map_rule_list set_list; | |
718e3744 | 149 | |
d62a17ae | 150 | /* Make linked list. */ |
151 | struct route_map_index *next; | |
152 | struct route_map_index *prev; | |
e80e7cce | 153 | |
279b0607 DS |
154 | /* Keep track how many times we've try to apply */ |
155 | uint64_t applied; | |
156 | ||
d62a17ae | 157 | QOBJ_FIELDS |
718e3744 | 158 | }; |
e80e7cce | 159 | DECLARE_QOBJ_TYPE(route_map_index) |
718e3744 | 160 | |
161 | /* Route map list structure. */ | |
d62a17ae | 162 | struct route_map { |
163 | /* Name of route map. */ | |
164 | char *name; | |
718e3744 | 165 | |
d62a17ae | 166 | /* Route map's rule. */ |
167 | struct route_map_index *head; | |
168 | struct route_map_index *tail; | |
718e3744 | 169 | |
d62a17ae | 170 | /* Make linked list. */ |
171 | struct route_map *next; | |
172 | struct route_map *prev; | |
518f0eb1 | 173 | |
d62a17ae | 174 | /* Maintain update info */ |
e4694d0d DS |
175 | bool to_be_processed; /* True if modification isn't acted on yet */ |
176 | bool deleted; /* If 1, then this node will be deleted */ | |
e80e7cce | 177 | |
279b0607 DS |
178 | /* How many times have we applied this route-map */ |
179 | uint64_t applied; | |
180 | ||
4a2a09d0 | 181 | /* Counter to track active usage of this route-map */ |
182 | uint16_t use_count; | |
183 | ||
d62a17ae | 184 | QOBJ_FIELDS |
718e3744 | 185 | }; |
e80e7cce | 186 | DECLARE_QOBJ_TYPE(route_map) |
718e3744 | 187 | |
188 | /* Prototypes. */ | |
d62a17ae | 189 | extern void route_map_init(void); |
8619629a DS |
190 | |
191 | /* | |
192 | * This should only be called on shutdown | |
193 | * Additionally this function sets the hooks to NULL | |
194 | * before any processing is done. | |
195 | */ | |
d62a17ae | 196 | extern void route_map_finish(void); |
718e3744 | 197 | |
198 | /* Add match statement to route map. */ | |
d62a17ae | 199 | extern int route_map_add_match(struct route_map_index *index, |
e2c8d6ce NT |
200 | const char *match_name, const char *match_arg, |
201 | route_map_event_t type); | |
718e3744 | 202 | |
203 | /* Delete specified route match rule. */ | |
d62a17ae | 204 | extern int route_map_delete_match(struct route_map_index *index, |
205 | const char *match_name, | |
206 | const char *match_arg); | |
718e3744 | 207 | |
d62a17ae | 208 | extern const char *route_map_get_match_arg(struct route_map_index *index, |
209 | const char *match_name); | |
518f0eb1 | 210 | |
718e3744 | 211 | /* Add route-map set statement to the route map. */ |
d62a17ae | 212 | extern int route_map_add_set(struct route_map_index *index, |
213 | const char *set_name, const char *set_arg); | |
718e3744 | 214 | |
215 | /* Delete route map set rule. */ | |
d62a17ae | 216 | extern int route_map_delete_set(struct route_map_index *index, |
217 | const char *set_name, const char *set_arg); | |
718e3744 | 218 | |
219 | /* Install rule command to the match list. */ | |
d62a17ae | 220 | extern void route_map_install_match(struct route_map_rule_cmd *cmd); |
718e3744 | 221 | |
6a74c5f9 DS |
222 | /* |
223 | * Install rule command to the set list. | |
224 | * | |
225 | * When installing a particular item, Allow a difference of handling | |
226 | * of bad cli inputted(return NULL) -vs- this particular daemon cannot use | |
227 | * this form of the command(return a pointer and handle it appropriately | |
228 | * in the apply command). See 'set metric' command | |
229 | * as it is handled in ripd/ripngd and ospfd. | |
230 | */ | |
d62a17ae | 231 | extern void route_map_install_set(struct route_map_rule_cmd *cmd); |
718e3744 | 232 | |
233 | /* Lookup route map by name. */ | |
d62a17ae | 234 | extern struct route_map *route_map_lookup_by_name(const char *name); |
718e3744 | 235 | |
1de27621 DA |
236 | /* Simple helper to warn if route-map does not exist. */ |
237 | struct route_map *route_map_lookup_warn_noexist(struct vty *vty, const char *name); | |
238 | ||
718e3744 | 239 | /* Apply route map to the object. */ |
d62a17ae | 240 | extern route_map_result_t route_map_apply(struct route_map *map, |
123214ef | 241 | const struct prefix *prefix, |
d62a17ae | 242 | route_map_object_t object_type, |
243 | void *object); | |
244 | ||
245 | extern void route_map_add_hook(void (*func)(const char *)); | |
246 | extern void route_map_delete_hook(void (*func)(const char *)); | |
097b5973 DS |
247 | |
248 | /* | |
249 | * This is the callback for when something has changed about a | |
250 | * route-map. The interested parties can register to receive | |
251 | * this data. | |
252 | * | |
253 | * name - Is the name of the changed route-map | |
254 | */ | |
255 | extern void route_map_event_hook(void (*func)(const char *name)); | |
7096e938 | 256 | extern int route_map_mark_updated(const char *name); |
46a69f10 | 257 | extern void route_map_walk_update_list(void (*update_fn)(char *name)); |
d62a17ae | 258 | extern void route_map_upd8_dependency(route_map_event_t type, const char *arg, |
259 | const char *rmap_name); | |
260 | extern void route_map_notify_dependencies(const char *affected_name, | |
261 | route_map_event_t event); | |
262 | ||
263 | extern int generic_match_add(struct vty *vty, struct route_map_index *index, | |
264 | const char *command, const char *arg, | |
265 | route_map_event_t type); | |
266 | ||
267 | extern int generic_match_delete(struct vty *vty, struct route_map_index *index, | |
268 | const char *command, const char *arg, | |
269 | route_map_event_t type); | |
270 | extern int generic_set_add(struct vty *vty, struct route_map_index *index, | |
271 | const char *command, const char *arg); | |
272 | extern int generic_set_delete(struct vty *vty, struct route_map_index *index, | |
273 | const char *command, const char *arg); | |
82f97584 DW |
274 | |
275 | ||
276 | /* match interface */ | |
d62a17ae | 277 | extern void route_map_match_interface_hook(int (*func)( |
278 | struct vty *vty, struct route_map_index *index, const char *command, | |
279 | const char *arg, route_map_event_t type)); | |
82f97584 | 280 | /* no match interface */ |
d62a17ae | 281 | extern void route_map_no_match_interface_hook(int (*func)( |
282 | struct vty *vty, struct route_map_index *index, const char *command, | |
283 | const char *arg, route_map_event_t type)); | |
82f97584 | 284 | /* match ip address */ |
d62a17ae | 285 | extern void route_map_match_ip_address_hook(int (*func)( |
286 | struct vty *vty, struct route_map_index *index, const char *command, | |
287 | const char *arg, route_map_event_t type)); | |
82f97584 | 288 | /* no match ip address */ |
d62a17ae | 289 | extern void route_map_no_match_ip_address_hook(int (*func)( |
290 | struct vty *vty, struct route_map_index *index, const char *command, | |
291 | const char *arg, route_map_event_t type)); | |
82f97584 | 292 | /* match ip address prefix list */ |
d62a17ae | 293 | extern void route_map_match_ip_address_prefix_list_hook(int (*func)( |
294 | struct vty *vty, struct route_map_index *index, const char *command, | |
295 | const char *arg, route_map_event_t type)); | |
82f97584 | 296 | /* no match ip address prefix list */ |
d62a17ae | 297 | extern void route_map_no_match_ip_address_prefix_list_hook(int (*func)( |
298 | struct vty *vty, struct route_map_index *index, const char *command, | |
299 | const char *arg, route_map_event_t type)); | |
82f97584 | 300 | /* match ip next hop */ |
d62a17ae | 301 | extern void route_map_match_ip_next_hop_hook(int (*func)( |
302 | struct vty *vty, struct route_map_index *index, const char *command, | |
303 | const char *arg, route_map_event_t type)); | |
82f97584 | 304 | /* no match ip next hop */ |
d62a17ae | 305 | extern void route_map_no_match_ip_next_hop_hook(int (*func)( |
306 | struct vty *vty, struct route_map_index *index, const char *command, | |
307 | const char *arg, route_map_event_t type)); | |
82f97584 | 308 | /* match ip next hop prefix list */ |
d62a17ae | 309 | extern void route_map_match_ip_next_hop_prefix_list_hook(int (*func)( |
310 | struct vty *vty, struct route_map_index *index, const char *command, | |
311 | const char *arg, route_map_event_t type)); | |
82f97584 | 312 | /* no match ip next hop prefix list */ |
d62a17ae | 313 | extern void route_map_no_match_ip_next_hop_prefix_list_hook(int (*func)( |
314 | struct vty *vty, struct route_map_index *index, const char *command, | |
315 | const char *arg, route_map_event_t type)); | |
61ad901e DA |
316 | /* match ip next hop type */ |
317 | extern void route_map_match_ip_next_hop_type_hook(int (*func)( | |
318 | struct vty *vty, struct route_map_index *index, const char *command, | |
319 | const char *arg, route_map_event_t type)); | |
320 | /* no match ip next hop type */ | |
321 | extern void route_map_no_match_ip_next_hop_type_hook(int (*func)( | |
322 | struct vty *vty, struct route_map_index *index, const char *command, | |
323 | const char *arg, route_map_event_t type)); | |
82f97584 | 324 | /* match ipv6 address */ |
d62a17ae | 325 | extern void route_map_match_ipv6_address_hook(int (*func)( |
326 | struct vty *vty, struct route_map_index *index, const char *command, | |
327 | const char *arg, route_map_event_t type)); | |
82f97584 | 328 | /* no match ipv6 address */ |
d62a17ae | 329 | extern void route_map_no_match_ipv6_address_hook(int (*func)( |
330 | struct vty *vty, struct route_map_index *index, const char *command, | |
331 | const char *arg, route_map_event_t type)); | |
82f97584 | 332 | /* match ipv6 address prefix list */ |
d62a17ae | 333 | extern void route_map_match_ipv6_address_prefix_list_hook(int (*func)( |
334 | struct vty *vty, struct route_map_index *index, const char *command, | |
335 | const char *arg, route_map_event_t type)); | |
82f97584 | 336 | /* no match ipv6 address prefix list */ |
d62a17ae | 337 | extern void route_map_no_match_ipv6_address_prefix_list_hook(int (*func)( |
338 | struct vty *vty, struct route_map_index *index, const char *command, | |
339 | const char *arg, route_map_event_t type)); | |
61ad901e DA |
340 | /* match ipv6 next-hop type */ |
341 | extern void route_map_match_ipv6_next_hop_type_hook(int (*func)( | |
342 | struct vty *vty, struct route_map_index *index, const char *command, | |
343 | const char *arg, route_map_event_t type)); | |
344 | /* no match ipv6 next-hop type */ | |
345 | extern void route_map_no_match_ipv6_next_hop_type_hook(int (*func)( | |
346 | struct vty *vty, struct route_map_index *index, const char *command, | |
347 | const char *arg, route_map_event_t type)); | |
82f97584 | 348 | /* match metric */ |
d62a17ae | 349 | extern void route_map_match_metric_hook(int (*func)( |
350 | struct vty *vty, struct route_map_index *index, const char *command, | |
351 | const char *arg, route_map_event_t type)); | |
82f97584 | 352 | /* no match metric */ |
d62a17ae | 353 | extern void route_map_no_match_metric_hook(int (*func)( |
354 | struct vty *vty, struct route_map_index *index, const char *command, | |
355 | const char *arg, route_map_event_t type)); | |
82f97584 | 356 | /* match tag */ |
d62a17ae | 357 | extern void route_map_match_tag_hook(int (*func)( |
358 | struct vty *vty, struct route_map_index *index, const char *command, | |
359 | const char *arg, route_map_event_t type)); | |
82f97584 | 360 | /* no match tag */ |
d62a17ae | 361 | extern void route_map_no_match_tag_hook(int (*func)( |
362 | struct vty *vty, struct route_map_index *index, const char *command, | |
363 | const char *arg, route_map_event_t type)); | |
82f97584 | 364 | /* set ip nexthop */ |
d62a17ae | 365 | extern void route_map_set_ip_nexthop_hook( |
366 | int (*func)(struct vty *vty, struct route_map_index *index, | |
367 | const char *command, const char *arg)); | |
82f97584 | 368 | /* no set ip nexthop */ |
d62a17ae | 369 | extern void route_map_no_set_ip_nexthop_hook( |
370 | int (*func)(struct vty *vty, struct route_map_index *index, | |
371 | const char *command, const char *arg)); | |
82f97584 | 372 | /* set ipv6 nexthop local */ |
d62a17ae | 373 | extern void route_map_set_ipv6_nexthop_local_hook( |
374 | int (*func)(struct vty *vty, struct route_map_index *index, | |
375 | const char *command, const char *arg)); | |
82f97584 | 376 | /* no set ipv6 nexthop local */ |
d62a17ae | 377 | extern void route_map_no_set_ipv6_nexthop_local_hook( |
378 | int (*func)(struct vty *vty, struct route_map_index *index, | |
379 | const char *command, const char *arg)); | |
82f97584 | 380 | /* set metric */ |
d62a17ae | 381 | extern void route_map_set_metric_hook(int (*func)(struct vty *vty, |
382 | struct route_map_index *index, | |
383 | const char *command, | |
384 | const char *arg)); | |
82f97584 | 385 | /* no set metric */ |
d62a17ae | 386 | extern void route_map_no_set_metric_hook( |
387 | int (*func)(struct vty *vty, struct route_map_index *index, | |
388 | const char *command, const char *arg)); | |
82f97584 | 389 | /* set tag */ |
d62a17ae | 390 | extern void route_map_set_tag_hook(int (*func)(struct vty *vty, |
391 | struct route_map_index *index, | |
392 | const char *command, | |
393 | const char *arg)); | |
82f97584 | 394 | /* no set tag */ |
d62a17ae | 395 | extern void route_map_no_set_tag_hook(int (*func)(struct vty *vty, |
396 | struct route_map_index *index, | |
397 | const char *command, | |
398 | const char *arg)); | |
e52702f2 | 399 | |
d62a17ae | 400 | extern void *route_map_rule_tag_compile(const char *arg); |
401 | extern void route_map_rule_tag_free(void *rule); | |
dc9ffce8 | 402 | |
4a2a09d0 | 403 | /* Increment the route-map used counter */ |
404 | extern void route_map_counter_increment(struct route_map *map); | |
405 | ||
406 | /* Decrement the route-map used counter */ | |
407 | extern void route_map_counter_decrement(struct route_map *map); | |
408 | ||
5e244469 RW |
409 | #ifdef __cplusplus |
410 | } | |
411 | #endif | |
412 | ||
718e3744 | 413 | #endif /* _ZEBRA_ROUTEMAP_H */ |