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