]>
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 *); | |
909f3d56 | 126 | |
127 | /** To get the rule key after Compilation **/ | |
128 | void *(*func_get_rmap_rule_key)(void *val); | |
718e3744 | 129 | }; |
130 | ||
131 | /* Route map apply error. */ | |
cda7187d | 132 | enum rmap_compile_rets { |
e2c8d6ce | 133 | RMAP_COMPILE_SUCCESS, |
9ca25fed | 134 | |
e2c8d6ce NT |
135 | /* Route map rule is missing. */ |
136 | RMAP_RULE_MISSING, | |
718e3744 | 137 | |
e2c8d6ce NT |
138 | /* Route map rule can't compile */ |
139 | RMAP_COMPILE_ERROR, | |
140 | ||
e2c8d6ce | 141 | }; |
718e3744 | 142 | |
143 | /* Route map rule list. */ | |
d62a17ae | 144 | struct route_map_rule_list { |
145 | struct route_map_rule *head; | |
146 | struct route_map_rule *tail; | |
718e3744 | 147 | }; |
148 | ||
149 | /* Route map index structure. */ | |
d62a17ae | 150 | struct route_map_index { |
151 | struct route_map *map; | |
152 | char *description; | |
718e3744 | 153 | |
d62a17ae | 154 | /* Preference of this route map rule. */ |
155 | int pref; | |
718e3744 | 156 | |
d62a17ae | 157 | /* Route map type permit or deny. */ |
158 | enum route_map_type type; | |
718e3744 | 159 | |
d62a17ae | 160 | /* Do we follow old rules, or hop forward? */ |
161 | route_map_end_t exitpolicy; | |
718e3744 | 162 | |
d62a17ae | 163 | /* If we're using "GOTO", to where do we go? */ |
164 | int nextpref; | |
718e3744 | 165 | |
d62a17ae | 166 | /* If we're using "CALL", to which route-map do ew go? */ |
167 | char *nextrm; | |
fee0f4c6 | 168 | |
d62a17ae | 169 | /* Matching rule list. */ |
170 | struct route_map_rule_list match_list; | |
171 | struct route_map_rule_list set_list; | |
718e3744 | 172 | |
d62a17ae | 173 | /* Make linked list. */ |
174 | struct route_map_index *next; | |
175 | struct route_map_index *prev; | |
e80e7cce | 176 | |
279b0607 DS |
177 | /* Keep track how many times we've try to apply */ |
178 | uint64_t applied; | |
1fa30509 | 179 | uint64_t applied_clear; |
279b0607 | 180 | |
d62a17ae | 181 | QOBJ_FIELDS |
718e3744 | 182 | }; |
e80e7cce | 183 | DECLARE_QOBJ_TYPE(route_map_index) |
718e3744 | 184 | |
185 | /* Route map list structure. */ | |
d62a17ae | 186 | struct route_map { |
187 | /* Name of route map. */ | |
188 | char *name; | |
718e3744 | 189 | |
d62a17ae | 190 | /* Route map's rule. */ |
191 | struct route_map_index *head; | |
192 | struct route_map_index *tail; | |
718e3744 | 193 | |
d62a17ae | 194 | /* Make linked list. */ |
195 | struct route_map *next; | |
196 | struct route_map *prev; | |
518f0eb1 | 197 | |
d62a17ae | 198 | /* Maintain update info */ |
e4694d0d DS |
199 | bool to_be_processed; /* True if modification isn't acted on yet */ |
200 | bool deleted; /* If 1, then this node will be deleted */ | |
e80e7cce | 201 | |
279b0607 DS |
202 | /* How many times have we applied this route-map */ |
203 | uint64_t applied; | |
1fa30509 | 204 | uint64_t applied_clear; |
279b0607 | 205 | |
4a2a09d0 | 206 | /* Counter to track active usage of this route-map */ |
207 | uint16_t use_count; | |
208 | ||
d62a17ae | 209 | QOBJ_FIELDS |
718e3744 | 210 | }; |
e80e7cce | 211 | DECLARE_QOBJ_TYPE(route_map) |
718e3744 | 212 | |
213 | /* Prototypes. */ | |
d62a17ae | 214 | extern void route_map_init(void); |
8619629a DS |
215 | |
216 | /* | |
217 | * This should only be called on shutdown | |
218 | * Additionally this function sets the hooks to NULL | |
219 | * before any processing is done. | |
220 | */ | |
d62a17ae | 221 | extern void route_map_finish(void); |
718e3744 | 222 | |
223 | /* Add match statement to route map. */ | |
cda7187d DS |
224 | extern enum rmap_compile_rets route_map_add_match(struct route_map_index *index, |
225 | const char *match_name, | |
226 | const char *match_arg, | |
227 | route_map_event_t type); | |
718e3744 | 228 | |
229 | /* Delete specified route match rule. */ | |
cda7187d DS |
230 | extern enum rmap_compile_rets |
231 | route_map_delete_match(struct route_map_index *index, | |
909f3d56 | 232 | const char *match_name, const char *match_arg, |
233 | route_map_event_t type); | |
718e3744 | 234 | |
d62a17ae | 235 | extern const char *route_map_get_match_arg(struct route_map_index *index, |
236 | const char *match_name); | |
518f0eb1 | 237 | |
718e3744 | 238 | /* Add route-map set statement to the route map. */ |
cda7187d DS |
239 | extern enum rmap_compile_rets route_map_add_set(struct route_map_index *index, |
240 | const char *set_name, | |
241 | const char *set_arg); | |
718e3744 | 242 | |
243 | /* Delete route map set rule. */ | |
cda7187d DS |
244 | extern enum rmap_compile_rets |
245 | route_map_delete_set(struct route_map_index *index, | |
246 | const char *set_name, const char *set_arg); | |
718e3744 | 247 | |
248 | /* Install rule command to the match list. */ | |
364deb04 | 249 | extern void route_map_install_match(const struct route_map_rule_cmd *cmd); |
718e3744 | 250 | |
6a74c5f9 DS |
251 | /* |
252 | * Install rule command to the set list. | |
253 | * | |
254 | * When installing a particular item, Allow a difference of handling | |
255 | * of bad cli inputted(return NULL) -vs- this particular daemon cannot use | |
256 | * this form of the command(return a pointer and handle it appropriately | |
257 | * in the apply command). See 'set metric' command | |
258 | * as it is handled in ripd/ripngd and ospfd. | |
259 | */ | |
364deb04 | 260 | extern void route_map_install_set(const struct route_map_rule_cmd *cmd); |
718e3744 | 261 | |
262 | /* Lookup route map by name. */ | |
d62a17ae | 263 | extern struct route_map *route_map_lookup_by_name(const char *name); |
718e3744 | 264 | |
1de27621 DA |
265 | /* Simple helper to warn if route-map does not exist. */ |
266 | struct route_map *route_map_lookup_warn_noexist(struct vty *vty, const char *name); | |
267 | ||
718e3744 | 268 | /* Apply route map to the object. */ |
d62a17ae | 269 | extern route_map_result_t route_map_apply(struct route_map *map, |
123214ef | 270 | const struct prefix *prefix, |
d62a17ae | 271 | route_map_object_t object_type, |
272 | void *object); | |
273 | ||
274 | extern void route_map_add_hook(void (*func)(const char *)); | |
275 | extern void route_map_delete_hook(void (*func)(const char *)); | |
097b5973 DS |
276 | |
277 | /* | |
278 | * This is the callback for when something has changed about a | |
279 | * route-map. The interested parties can register to receive | |
280 | * this data. | |
281 | * | |
282 | * name - Is the name of the changed route-map | |
283 | */ | |
284 | extern void route_map_event_hook(void (*func)(const char *name)); | |
7096e938 | 285 | extern int route_map_mark_updated(const char *name); |
46a69f10 | 286 | extern void route_map_walk_update_list(void (*update_fn)(char *name)); |
d62a17ae | 287 | extern void route_map_upd8_dependency(route_map_event_t type, const char *arg, |
288 | const char *rmap_name); | |
289 | extern void route_map_notify_dependencies(const char *affected_name, | |
290 | route_map_event_t event); | |
291 | ||
292 | extern int generic_match_add(struct vty *vty, struct route_map_index *index, | |
293 | const char *command, const char *arg, | |
294 | route_map_event_t type); | |
295 | ||
296 | extern int generic_match_delete(struct vty *vty, struct route_map_index *index, | |
297 | const char *command, const char *arg, | |
298 | route_map_event_t type); | |
299 | extern int generic_set_add(struct vty *vty, struct route_map_index *index, | |
300 | const char *command, const char *arg); | |
301 | extern int generic_set_delete(struct vty *vty, struct route_map_index *index, | |
302 | const char *command, const char *arg); | |
82f97584 DW |
303 | |
304 | ||
305 | /* match interface */ | |
d62a17ae | 306 | extern void route_map_match_interface_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 interface */ |
d62a17ae | 310 | extern void route_map_no_match_interface_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 | /* match ip address */ |
d62a17ae | 314 | extern void route_map_match_ip_address_hook(int (*func)( |
315 | struct vty *vty, struct route_map_index *index, const char *command, | |
316 | const char *arg, route_map_event_t type)); | |
82f97584 | 317 | /* no match ip address */ |
d62a17ae | 318 | extern void route_map_no_match_ip_address_hook(int (*func)( |
319 | struct vty *vty, struct route_map_index *index, const char *command, | |
320 | const char *arg, route_map_event_t type)); | |
82f97584 | 321 | /* match ip address prefix list */ |
d62a17ae | 322 | extern void route_map_match_ip_address_prefix_list_hook(int (*func)( |
323 | struct vty *vty, struct route_map_index *index, const char *command, | |
324 | const char *arg, route_map_event_t type)); | |
82f97584 | 325 | /* no match ip address prefix list */ |
d62a17ae | 326 | extern void route_map_no_match_ip_address_prefix_list_hook(int (*func)( |
327 | struct vty *vty, struct route_map_index *index, const char *command, | |
328 | const char *arg, route_map_event_t type)); | |
82f97584 | 329 | /* match ip next hop */ |
d62a17ae | 330 | extern void route_map_match_ip_next_hop_hook(int (*func)( |
331 | struct vty *vty, struct route_map_index *index, const char *command, | |
332 | const char *arg, route_map_event_t type)); | |
82f97584 | 333 | /* no match ip next hop */ |
d62a17ae | 334 | extern void route_map_no_match_ip_next_hop_hook(int (*func)( |
335 | struct vty *vty, struct route_map_index *index, const char *command, | |
336 | const char *arg, route_map_event_t type)); | |
82f97584 | 337 | /* match ip next hop prefix list */ |
d62a17ae | 338 | extern void route_map_match_ip_next_hop_prefix_list_hook(int (*func)( |
339 | struct vty *vty, struct route_map_index *index, const char *command, | |
340 | const char *arg, route_map_event_t type)); | |
82f97584 | 341 | /* no match ip next hop prefix list */ |
d62a17ae | 342 | extern void route_map_no_match_ip_next_hop_prefix_list_hook(int (*func)( |
343 | struct vty *vty, struct route_map_index *index, const char *command, | |
344 | const char *arg, route_map_event_t type)); | |
61ad901e DA |
345 | /* match ip next hop type */ |
346 | extern void route_map_match_ip_next_hop_type_hook(int (*func)( | |
347 | struct vty *vty, struct route_map_index *index, const char *command, | |
348 | const char *arg, route_map_event_t type)); | |
349 | /* no match ip next hop type */ | |
350 | extern void route_map_no_match_ip_next_hop_type_hook(int (*func)( | |
351 | struct vty *vty, struct route_map_index *index, const char *command, | |
352 | const char *arg, route_map_event_t type)); | |
82f97584 | 353 | /* match ipv6 address */ |
d62a17ae | 354 | extern void route_map_match_ipv6_address_hook(int (*func)( |
355 | struct vty *vty, struct route_map_index *index, const char *command, | |
356 | const char *arg, route_map_event_t type)); | |
82f97584 | 357 | /* no match ipv6 address */ |
d62a17ae | 358 | extern void route_map_no_match_ipv6_address_hook(int (*func)( |
359 | struct vty *vty, struct route_map_index *index, const char *command, | |
360 | const char *arg, route_map_event_t type)); | |
82f97584 | 361 | /* match ipv6 address prefix list */ |
d62a17ae | 362 | extern void route_map_match_ipv6_address_prefix_list_hook(int (*func)( |
363 | struct vty *vty, struct route_map_index *index, const char *command, | |
364 | const char *arg, route_map_event_t type)); | |
82f97584 | 365 | /* no match ipv6 address prefix list */ |
d62a17ae | 366 | extern void route_map_no_match_ipv6_address_prefix_list_hook(int (*func)( |
367 | struct vty *vty, struct route_map_index *index, const char *command, | |
368 | const char *arg, route_map_event_t type)); | |
61ad901e DA |
369 | /* match ipv6 next-hop type */ |
370 | extern void route_map_match_ipv6_next_hop_type_hook(int (*func)( | |
371 | struct vty *vty, struct route_map_index *index, const char *command, | |
372 | const char *arg, route_map_event_t type)); | |
373 | /* no match ipv6 next-hop type */ | |
374 | extern void route_map_no_match_ipv6_next_hop_type_hook(int (*func)( | |
375 | struct vty *vty, struct route_map_index *index, const char *command, | |
376 | const char *arg, route_map_event_t type)); | |
82f97584 | 377 | /* match metric */ |
d62a17ae | 378 | extern void route_map_match_metric_hook(int (*func)( |
379 | struct vty *vty, struct route_map_index *index, const char *command, | |
380 | const char *arg, route_map_event_t type)); | |
82f97584 | 381 | /* no match metric */ |
d62a17ae | 382 | extern void route_map_no_match_metric_hook(int (*func)( |
383 | struct vty *vty, struct route_map_index *index, const char *command, | |
384 | const char *arg, route_map_event_t type)); | |
82f97584 | 385 | /* match tag */ |
d62a17ae | 386 | extern void route_map_match_tag_hook(int (*func)( |
387 | struct vty *vty, struct route_map_index *index, const char *command, | |
388 | const char *arg, route_map_event_t type)); | |
82f97584 | 389 | /* no match tag */ |
d62a17ae | 390 | extern void route_map_no_match_tag_hook(int (*func)( |
391 | struct vty *vty, struct route_map_index *index, const char *command, | |
392 | const char *arg, route_map_event_t type)); | |
82f97584 | 393 | /* set ip nexthop */ |
d62a17ae | 394 | extern void route_map_set_ip_nexthop_hook( |
395 | int (*func)(struct vty *vty, struct route_map_index *index, | |
396 | const char *command, const char *arg)); | |
82f97584 | 397 | /* no set ip nexthop */ |
d62a17ae | 398 | extern void route_map_no_set_ip_nexthop_hook( |
399 | int (*func)(struct vty *vty, struct route_map_index *index, | |
400 | const char *command, const char *arg)); | |
82f97584 | 401 | /* set ipv6 nexthop local */ |
d62a17ae | 402 | extern void route_map_set_ipv6_nexthop_local_hook( |
403 | int (*func)(struct vty *vty, struct route_map_index *index, | |
404 | const char *command, const char *arg)); | |
82f97584 | 405 | /* no set ipv6 nexthop local */ |
d62a17ae | 406 | extern void route_map_no_set_ipv6_nexthop_local_hook( |
407 | int (*func)(struct vty *vty, struct route_map_index *index, | |
408 | const char *command, const char *arg)); | |
82f97584 | 409 | /* set metric */ |
d62a17ae | 410 | extern void route_map_set_metric_hook(int (*func)(struct vty *vty, |
411 | struct route_map_index *index, | |
412 | const char *command, | |
413 | const char *arg)); | |
82f97584 | 414 | /* no set metric */ |
d62a17ae | 415 | extern void route_map_no_set_metric_hook( |
416 | int (*func)(struct vty *vty, struct route_map_index *index, | |
417 | const char *command, const char *arg)); | |
82f97584 | 418 | /* set tag */ |
d62a17ae | 419 | extern void route_map_set_tag_hook(int (*func)(struct vty *vty, |
420 | struct route_map_index *index, | |
421 | const char *command, | |
422 | const char *arg)); | |
82f97584 | 423 | /* no set tag */ |
d62a17ae | 424 | extern void route_map_no_set_tag_hook(int (*func)(struct vty *vty, |
425 | struct route_map_index *index, | |
426 | const char *command, | |
427 | const char *arg)); | |
e52702f2 | 428 | |
d62a17ae | 429 | extern void *route_map_rule_tag_compile(const char *arg); |
430 | extern void route_map_rule_tag_free(void *rule); | |
dc9ffce8 | 431 | |
4a2a09d0 | 432 | /* Increment the route-map used counter */ |
433 | extern void route_map_counter_increment(struct route_map *map); | |
434 | ||
435 | /* Decrement the route-map used counter */ | |
436 | extern void route_map_counter_decrement(struct route_map *map); | |
437 | ||
5e244469 RW |
438 | #ifdef __cplusplus |
439 | } | |
440 | #endif | |
441 | ||
718e3744 | 442 | #endif /* _ZEBRA_ROUTEMAP_H */ |