2 * Copyright (C) 1998 Kunihiro Ishiguro
4 * This file is part of GNU Zebra.
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
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.
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
21 #ifndef _ZEBRA_ROUTEMAP_H
22 #define _ZEBRA_ROUTEMAP_H
33 DECLARE_MTYPE(ROUTE_MAP_NAME
)
34 DECLARE_MTYPE(ROUTE_MAP_RULE
)
35 DECLARE_MTYPE(ROUTE_MAP_COMPILED
)
37 /* Route map's type. */
38 enum route_map_type
{ RMAP_PERMIT
, RMAP_DENY
, RMAP_ANY
};
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
55 enum route_map_cmd_result_t
{
57 * route-map match cmd results
63 * route-map set cmd results
80 typedef enum { RMAP_EXIT
, RMAP_GOTO
, RMAP_NEXT
} route_map_end_t
;
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
,
107 /* Depth limit in RMAP recursion using RMAP_CALL. */
108 #define RMAP_RECURSION_LIMIT 10
110 /* Route map rule structure for matching and setting. */
111 struct route_map_rule_cmd
{
112 /* Route map rule name (e.g. as-path, metric) */
115 /* Function for value set or match. */
116 enum route_map_cmd_result_t (*func_apply
)(void *rule
,
117 const struct prefix
*prefix
,
118 route_map_object_t type
,
121 /* Compile argument and return result as void *. */
122 void *(*func_compile
)(const char *);
124 /* Free allocated value by func_compile (). */
125 void (*func_free
)(void *);
127 /** To get the rule key after Compilation **/
128 void *(*func_get_rmap_rule_key
)(void *val
);
131 /* Route map apply error. */
132 enum rmap_compile_rets
{
133 RMAP_COMPILE_SUCCESS
,
135 /* Route map rule is missing. */
138 /* Route map rule can't compile */
143 /* Route map rule. This rule has both `match' rule and `set' rule. */
144 struct route_map_rule
{
146 const struct route_map_rule_cmd
*cmd
;
148 /* For pretty printing. */
151 /* Pre-compiled match rule. */
155 struct route_map_rule
*next
;
156 struct route_map_rule
*prev
;
159 /* Route map rule list. */
160 struct route_map_rule_list
{
161 struct route_map_rule
*head
;
162 struct route_map_rule
*tail
;
165 /* Forward struct declaration: the complete can be found later this file. */
166 struct routemap_hook_context
;
168 /* Route map index structure. */
169 struct route_map_index
{
170 struct route_map
*map
;
173 /* Preference of this route map rule. */
176 /* Route map type permit or deny. */
177 enum route_map_type type
;
179 /* Do we follow old rules, or hop forward? */
180 route_map_end_t exitpolicy
;
182 /* If we're using "GOTO", to where do we go? */
185 /* If we're using "CALL", to which route-map do ew go? */
188 /* Matching rule list. */
189 struct route_map_rule_list match_list
;
190 struct route_map_rule_list set_list
;
192 /* Make linked list. */
193 struct route_map_index
*next
;
194 struct route_map_index
*prev
;
196 /* Keep track how many times we've try to apply */
198 uint64_t applied_clear
;
200 /* List of match/sets contexts. */
201 TAILQ_HEAD(, routemap_hook_context
) rhclist
;
205 DECLARE_QOBJ_TYPE(route_map_index
)
207 /* Route map list structure. */
209 /* Name of route map. */
212 /* Route map's rule. */
213 struct route_map_index
*head
;
214 struct route_map_index
*tail
;
216 /* Make linked list. */
217 struct route_map
*next
;
218 struct route_map
*prev
;
220 /* Maintain update info */
221 bool to_be_processed
; /* True if modification isn't acted on yet */
222 bool deleted
; /* If 1, then this node will be deleted */
224 /* How many times have we applied this route-map */
226 uint64_t applied_clear
;
228 /* Counter to track active usage of this route-map */
233 DECLARE_QOBJ_TYPE(route_map
)
236 extern void route_map_init(void);
239 * This should only be called on shutdown
240 * Additionally this function sets the hooks to NULL
241 * before any processing is done.
243 extern void route_map_finish(void);
245 /* Add match statement to route map. */
246 extern enum rmap_compile_rets
route_map_add_match(struct route_map_index
*index
,
247 const char *match_name
,
248 const char *match_arg
,
249 route_map_event_t type
);
251 /* Delete specified route match rule. */
252 extern enum rmap_compile_rets
253 route_map_delete_match(struct route_map_index
*index
,
254 const char *match_name
, const char *match_arg
,
255 route_map_event_t type
);
257 extern const char *route_map_get_match_arg(struct route_map_index
*index
,
258 const char *match_name
);
260 /* Add route-map set statement to the route map. */
261 extern enum rmap_compile_rets
route_map_add_set(struct route_map_index
*index
,
262 const char *set_name
,
263 const char *set_arg
);
265 /* Delete route map set rule. */
266 extern enum rmap_compile_rets
267 route_map_delete_set(struct route_map_index
*index
,
268 const char *set_name
, const char *set_arg
);
270 /* Install rule command to the match list. */
271 extern void route_map_install_match(const struct route_map_rule_cmd
*cmd
);
274 * Install rule command to the set list.
276 * When installing a particular item, Allow a difference of handling
277 * of bad cli inputted(return NULL) -vs- this particular daemon cannot use
278 * this form of the command(return a pointer and handle it appropriately
279 * in the apply command). See 'set metric' command
280 * as it is handled in ripd/ripngd and ospfd.
282 extern void route_map_install_set(const struct route_map_rule_cmd
*cmd
);
284 /* Lookup route map by name. */
285 extern struct route_map
*route_map_lookup_by_name(const char *name
);
287 /* Simple helper to warn if route-map does not exist. */
288 struct route_map
*route_map_lookup_warn_noexist(struct vty
*vty
, const char *name
);
290 /* Apply route map to the object. */
291 extern route_map_result_t
route_map_apply(struct route_map
*map
,
292 const struct prefix
*prefix
,
293 route_map_object_t object_type
,
296 extern void route_map_add_hook(void (*func
)(const char *));
297 extern void route_map_delete_hook(void (*func
)(const char *));
300 * This is the callback for when something has changed about a
301 * route-map. The interested parties can register to receive
304 * name - Is the name of the changed route-map
306 extern void route_map_event_hook(void (*func
)(const char *name
));
307 extern int route_map_mark_updated(const char *name
);
308 extern void route_map_walk_update_list(void (*update_fn
)(char *name
));
309 extern void route_map_upd8_dependency(route_map_event_t type
, const char *arg
,
310 const char *rmap_name
);
311 extern void route_map_notify_dependencies(const char *affected_name
,
312 route_map_event_t event
);
314 extern int generic_match_add(struct vty
*vty
, struct route_map_index
*index
,
315 const char *command
, const char *arg
,
316 route_map_event_t type
);
318 extern int generic_match_delete(struct vty
*vty
, struct route_map_index
*index
,
319 const char *command
, const char *arg
,
320 route_map_event_t type
);
321 extern int generic_set_add(struct vty
*vty
, struct route_map_index
*index
,
322 const char *command
, const char *arg
);
323 extern int generic_set_delete(struct vty
*vty
, struct route_map_index
*index
,
324 const char *command
, const char *arg
);
327 /* match interface */
328 extern void route_map_match_interface_hook(int (*func
)(
329 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
330 const char *arg
, route_map_event_t type
));
331 /* no match interface */
332 extern void route_map_no_match_interface_hook(int (*func
)(
333 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
334 const char *arg
, route_map_event_t type
));
335 /* match ip address */
336 extern void route_map_match_ip_address_hook(int (*func
)(
337 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
338 const char *arg
, route_map_event_t type
));
339 /* no match ip address */
340 extern void route_map_no_match_ip_address_hook(int (*func
)(
341 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
342 const char *arg
, route_map_event_t type
));
343 /* match ip address prefix list */
344 extern void route_map_match_ip_address_prefix_list_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 address prefix list */
348 extern void route_map_no_match_ip_address_prefix_list_hook(int (*func
)(
349 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
350 const char *arg
, route_map_event_t type
));
351 /* match ip next hop */
352 extern void route_map_match_ip_next_hop_hook(int (*func
)(
353 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
354 const char *arg
, route_map_event_t type
));
355 /* no match ip next hop */
356 extern void route_map_no_match_ip_next_hop_hook(int (*func
)(
357 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
358 const char *arg
, route_map_event_t type
));
359 /* match ip next hop prefix list */
360 extern void route_map_match_ip_next_hop_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
));
363 /* no match ip next hop prefix list */
364 extern void route_map_no_match_ip_next_hop_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
));
367 /* match ip next hop type */
368 extern void route_map_match_ip_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 ip next hop type */
372 extern void route_map_no_match_ip_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
));
375 /* match ipv6 address */
376 extern void route_map_match_ipv6_address_hook(int (*func
)(
377 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
378 const char *arg
, route_map_event_t type
));
379 /* no match ipv6 address */
380 extern void route_map_no_match_ipv6_address_hook(int (*func
)(
381 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
382 const char *arg
, route_map_event_t type
));
383 /* match ipv6 address prefix list */
384 extern void route_map_match_ipv6_address_prefix_list_hook(int (*func
)(
385 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
386 const char *arg
, route_map_event_t type
));
387 /* no match ipv6 address prefix list */
388 extern void route_map_no_match_ipv6_address_prefix_list_hook(int (*func
)(
389 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
390 const char *arg
, route_map_event_t type
));
391 /* match ipv6 next-hop type */
392 extern void route_map_match_ipv6_next_hop_type_hook(int (*func
)(
393 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
394 const char *arg
, route_map_event_t type
));
395 /* no match ipv6 next-hop type */
396 extern void route_map_no_match_ipv6_next_hop_type_hook(int (*func
)(
397 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
398 const char *arg
, route_map_event_t type
));
400 extern void route_map_match_metric_hook(int (*func
)(
401 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
402 const char *arg
, route_map_event_t type
));
403 /* no match metric */
404 extern void route_map_no_match_metric_hook(int (*func
)(
405 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
406 const char *arg
, route_map_event_t type
));
408 extern void route_map_match_tag_hook(int (*func
)(
409 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
410 const char *arg
, route_map_event_t type
));
412 extern void route_map_no_match_tag_hook(int (*func
)(
413 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
414 const char *arg
, route_map_event_t type
));
416 extern void route_map_set_ip_nexthop_hook(
417 int (*func
)(struct vty
*vty
, struct route_map_index
*index
,
418 const char *command
, const char *arg
));
419 /* no set ip nexthop */
420 extern void route_map_no_set_ip_nexthop_hook(
421 int (*func
)(struct vty
*vty
, struct route_map_index
*index
,
422 const char *command
, const char *arg
));
423 /* set ipv6 nexthop local */
424 extern void route_map_set_ipv6_nexthop_local_hook(
425 int (*func
)(struct vty
*vty
, struct route_map_index
*index
,
426 const char *command
, const char *arg
));
427 /* no set ipv6 nexthop local */
428 extern void route_map_no_set_ipv6_nexthop_local_hook(
429 int (*func
)(struct vty
*vty
, struct route_map_index
*index
,
430 const char *command
, const char *arg
));
432 extern void route_map_set_metric_hook(int (*func
)(struct vty
*vty
,
433 struct route_map_index
*index
,
437 extern void route_map_no_set_metric_hook(
438 int (*func
)(struct vty
*vty
, struct route_map_index
*index
,
439 const char *command
, const char *arg
));
441 extern void route_map_set_tag_hook(int (*func
)(struct vty
*vty
,
442 struct route_map_index
*index
,
446 extern void route_map_no_set_tag_hook(int (*func
)(struct vty
*vty
,
447 struct route_map_index
*index
,
451 extern void *route_map_rule_tag_compile(const char *arg
);
452 extern void route_map_rule_tag_free(void *rule
);
454 /* Increment the route-map used counter */
455 extern void route_map_counter_increment(struct route_map
*map
);
457 /* Decrement the route-map used counter */
458 extern void route_map_counter_decrement(struct route_map
*map
);
460 /* Route map hooks data structure. */
461 struct route_map_match_set_hooks
{
462 /* match interface */
463 int (*match_interface
)(struct vty
*vty
, struct route_map_index
*index
,
464 const char *command
, const char *arg
,
465 route_map_event_t type
);
467 /* no match interface */
468 int (*no_match_interface
)(struct vty
*vty
,
469 struct route_map_index
*index
,
470 const char *command
, const char *arg
,
471 route_map_event_t type
);
473 /* match ip address */
474 int (*match_ip_address
)(struct vty
*vty
, struct route_map_index
*index
,
475 const char *command
, const char *arg
,
476 route_map_event_t type
);
478 /* no match ip address */
479 int (*no_match_ip_address
)(struct vty
*vty
,
480 struct route_map_index
*index
,
481 const char *command
, const char *arg
,
482 route_map_event_t type
);
484 /* match ip address prefix list */
485 int (*match_ip_address_prefix_list
)(struct vty
*vty
,
486 struct route_map_index
*index
,
489 route_map_event_t type
);
491 /* no match ip address prefix list */
492 int (*no_match_ip_address_prefix_list
)(struct vty
*vty
,
493 struct route_map_index
*index
,
496 route_map_event_t type
);
498 /* match ip next hop */
499 int (*match_ip_next_hop
)(struct vty
*vty
, struct route_map_index
*index
,
500 const char *command
, const char *arg
,
501 route_map_event_t type
);
503 /* no match ip next hop */
504 int (*no_match_ip_next_hop
)(struct vty
*vty
,
505 struct route_map_index
*index
,
506 const char *command
, const char *arg
,
507 route_map_event_t type
);
509 /* match ip next hop prefix list */
510 int (*match_ip_next_hop_prefix_list
)(struct vty
*vty
,
511 struct route_map_index
*index
,
514 route_map_event_t type
);
516 /* no match ip next hop prefix list */
517 int (*no_match_ip_next_hop_prefix_list
)(struct vty
*vty
,
518 struct route_map_index
*index
,
521 route_map_event_t type
);
523 /* match ip next-hop type */
524 int (*match_ip_next_hop_type
)(struct vty
*vty
,
525 struct route_map_index
*index
,
528 route_map_event_t type
);
530 /* no match ip next-hop type */
531 int (*no_match_ip_next_hop_type
)(struct vty
*vty
,
532 struct route_map_index
*index
,
535 route_map_event_t type
);
537 /* match ipv6 address */
538 int (*match_ipv6_address
)(struct vty
*vty
,
539 struct route_map_index
*index
,
540 const char *command
, const char *arg
,
541 route_map_event_t type
);
543 /* no match ipv6 address */
544 int (*no_match_ipv6_address
)(struct vty
*vty
,
545 struct route_map_index
*index
,
546 const char *command
, const char *arg
,
547 route_map_event_t type
);
550 /* match ipv6 address prefix list */
551 int (*match_ipv6_address_prefix_list
)(struct vty
*vty
,
552 struct route_map_index
*index
,
555 route_map_event_t type
);
557 /* no match ipv6 address prefix list */
558 int (*no_match_ipv6_address_prefix_list
)(struct vty
*vty
,
559 struct route_map_index
*index
,
562 route_map_event_t type
);
564 /* match ipv6 next-hop type */
565 int (*match_ipv6_next_hop_type
)(struct vty
*vty
,
566 struct route_map_index
*index
,
569 route_map_event_t type
);
571 /* no match ipv6 next-hop type */
572 int (*no_match_ipv6_next_hop_type
)(struct vty
*vty
,
573 struct route_map_index
*index
,
574 const char *command
, const char *arg
,
575 route_map_event_t type
);
578 int (*match_metric
)(struct vty
*vty
, struct route_map_index
*index
,
579 const char *command
, const char *arg
,
580 route_map_event_t type
);
582 /* no match metric */
583 int (*no_match_metric
)(struct vty
*vty
, struct route_map_index
*index
,
584 const char *command
, const char *arg
,
585 route_map_event_t type
);
588 int (*match_tag
)(struct vty
*vty
, struct route_map_index
*index
,
589 const char *command
, const char *arg
,
590 route_map_event_t type
);
593 int (*no_match_tag
)(struct vty
*vty
, struct route_map_index
*index
,
594 const char *command
, const char *arg
,
595 route_map_event_t type
);
598 int (*set_ip_nexthop
)(struct vty
*vty
, struct route_map_index
*index
,
599 const char *command
, const char *arg
);
601 /* no set ip nexthop */
602 int (*no_set_ip_nexthop
)(struct vty
*vty
, struct route_map_index
*index
,
603 const char *command
, const char *arg
);
605 /* set ipv6 nexthop local */
606 int (*set_ipv6_nexthop_local
)(struct vty
*vty
,
607 struct route_map_index
*index
,
608 const char *command
, const char *arg
);
610 /* no set ipv6 nexthop local */
611 int (*no_set_ipv6_nexthop_local
)(struct vty
*vty
,
612 struct route_map_index
*index
,
613 const char *command
, const char *arg
);
616 int (*set_metric
)(struct vty
*vty
, struct route_map_index
*index
,
617 const char *command
, const char *arg
);
620 int (*no_set_metric
)(struct vty
*vty
, struct route_map_index
*index
,
621 const char *command
, const char *arg
);
624 int (*set_tag
)(struct vty
*vty
, struct route_map_index
*index
,
625 const char *command
, const char *arg
);
628 int (*no_set_tag
)(struct vty
*vty
, struct route_map_index
*index
,
629 const char *command
, const char *arg
);
632 extern struct route_map_match_set_hooks rmap_match_set_hook
;
634 /* Making route map list. */
635 struct route_map_list
{
636 struct route_map
*head
;
637 struct route_map
*tail
;
639 void (*add_hook
)(const char *);
640 void (*delete_hook
)(const char *);
641 void (*event_hook
)(const char *);
644 extern struct route_map_list route_map_master
;
646 extern struct route_map
*route_map_get(const char *name
);
647 extern void route_map_delete(struct route_map
*map
);
648 extern struct route_map_index
*route_map_index_get(struct route_map
*map
,
649 enum route_map_type type
,
651 extern void route_map_index_delete(struct route_map_index
*index
, int notify
);
653 /* routemap_northbound.c */
654 typedef int (*routemap_match_hook_fun
)(struct vty
*vty
,
655 struct route_map_index
*rmi
,
656 const char *command
, const char *arg
,
657 route_map_event_t event
);
659 typedef int (*routemap_set_hook_fun
)(struct vty
*vty
,
660 struct route_map_index
*rmi
,
661 const char *command
, const char *arg
);
663 struct routemap_hook_context
{
664 struct route_map_index
*rhc_rmi
;
665 const char *rhc_rule
;
666 route_map_event_t rhc_event
;
667 routemap_set_hook_fun rhc_shook
;
668 routemap_match_hook_fun rhc_mhook
;
669 TAILQ_ENTRY(routemap_hook_context
) rhc_entry
;
672 int lib_route_map_entry_match_destroy(enum nb_event event
,
673 const struct lyd_node
*dnode
);
674 int lib_route_map_entry_set_destroy(enum nb_event event
,
675 const struct lyd_node
*dnode
);
677 struct routemap_hook_context
*
678 routemap_hook_context_insert(struct route_map_index
*rmi
);
679 void routemap_hook_context_free(struct routemap_hook_context
*rhc
);
681 extern const struct frr_yang_module_info frr_route_map_info
;
684 extern void route_map_instance_show(struct vty
*vty
, struct lyd_node
*dnode
,
686 extern void route_map_instance_show_end(struct vty
*vty
,
687 struct lyd_node
*dnode
);
688 extern void route_map_condition_show(struct vty
*vty
, struct lyd_node
*dnode
,
690 extern void route_map_action_show(struct vty
*vty
, struct lyd_node
*dnode
,
692 extern void route_map_exit_policy_show(struct vty
*vty
, struct lyd_node
*dnode
,
694 extern void route_map_call_show(struct vty
*vty
, struct lyd_node
*dnode
,
696 extern void route_map_description_show(struct vty
*vty
,
697 struct lyd_node
*dnode
,
699 extern void route_map_cli_init(void);
705 #endif /* _ZEBRA_ROUTEMAP_H */