1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 1998 Kunihiro Ishiguro
6 #ifndef _ZEBRA_ROUTEMAP_H
7 #define _ZEBRA_ROUTEMAP_H
14 #include "lib/plist.h"
15 #include "lib/plist_int.h"
21 DECLARE_MTYPE(ROUTE_MAP_NAME
);
22 DECLARE_MTYPE(ROUTE_MAP_RULE
);
23 DECLARE_MTYPE(ROUTE_MAP_COMPILED
);
25 #define DEBUG_ROUTEMAP 0x01
26 #define DEBUG_ROUTEMAP_DETAIL 0x02
27 extern uint32_t rmap_debug
;
29 /* Route map's type. */
30 enum route_map_type
{ RMAP_PERMIT
, RMAP_DENY
, RMAP_ANY
};
38 * Route-map match or set result "Eg: match evpn vni xx"
39 * route-map match cmd always returns match/nomatch/noop
40 * match--> found a match
41 * nomatch--> didnt find a match
42 * noop--> not applicable
43 * route-map set retuns okay/error
44 * okay --> set was successful
45 * error --> set was not successful
47 enum route_map_cmd_result_t
{
49 * route-map match cmd results
55 * route-map set cmd results
61 typedef enum { RMAP_EXIT
, RMAP_GOTO
, RMAP_NEXT
} route_map_end_t
;
65 RMAP_EVENT_SET_DELETED
,
66 RMAP_EVENT_SET_REPLACED
,
67 RMAP_EVENT_MATCH_ADDED
,
68 RMAP_EVENT_MATCH_DELETED
,
69 RMAP_EVENT_MATCH_REPLACED
,
70 RMAP_EVENT_INDEX_ADDED
,
71 RMAP_EVENT_INDEX_DELETED
,
72 RMAP_EVENT_CALL_ADDED
, /* call to another routemap added */
73 RMAP_EVENT_CALL_DELETED
,
74 RMAP_EVENT_PLIST_ADDED
,
75 RMAP_EVENT_PLIST_DELETED
,
76 RMAP_EVENT_CLIST_ADDED
,
77 RMAP_EVENT_CLIST_DELETED
,
78 RMAP_EVENT_ECLIST_ADDED
,
79 RMAP_EVENT_ECLIST_DELETED
,
80 RMAP_EVENT_LLIST_ADDED
,
81 RMAP_EVENT_LLIST_DELETED
,
82 RMAP_EVENT_ASLIST_ADDED
,
83 RMAP_EVENT_ASLIST_DELETED
,
84 RMAP_EVENT_FILTER_ADDED
,
85 RMAP_EVENT_FILTER_DELETED
,
88 /* Depth limit in RMAP recursion using RMAP_CALL. */
89 #define RMAP_RECURSION_LIMIT 10
91 /* Route map rule structure for matching and setting. */
92 struct route_map_rule_cmd
{
93 /* Route map rule name (e.g. as-path, metric) */
96 /* Function for value set or match. */
97 enum route_map_cmd_result_t (*func_apply
)(void *rule
,
98 const struct prefix
*prefix
,
101 /* Compile argument and return result as void *. */
102 void *(*func_compile
)(const char *);
104 /* Free allocated value by func_compile (). */
105 void (*func_free
)(void *);
107 /** To get the rule key after Compilation **/
108 void *(*func_get_rmap_rule_key
)(void *val
);
111 /* Route map apply error. */
112 enum rmap_compile_rets
{
113 RMAP_COMPILE_SUCCESS
,
115 /* Route map rule is missing. */
118 /* Route map rule can't compile */
123 /* Route map rule. This rule has both `match' rule and `set' rule. */
124 struct route_map_rule
{
126 const struct route_map_rule_cmd
*cmd
;
128 /* For pretty printing. */
131 /* Pre-compiled match rule. */
135 struct route_map_rule
*next
;
136 struct route_map_rule
*prev
;
139 /* Route map rule list. */
140 struct route_map_rule_list
{
141 struct route_map_rule
*head
;
142 struct route_map_rule
*tail
;
145 /* Forward struct declaration: the complete can be found later this file. */
146 struct routemap_hook_context
;
148 /* Route map index structure. */
149 struct route_map_index
{
150 struct route_map
*map
;
153 /* Preference of this route map rule. */
156 /* Route map type permit or deny. */
157 enum route_map_type type
;
159 /* Do we follow old rules, or hop forward? */
160 route_map_end_t exitpolicy
;
162 /* If we're using "GOTO", to where do we go? */
165 /* If we're using "CALL", to which route-map do ew go? */
168 /* Matching rule list. */
169 struct route_map_rule_list match_list
;
170 struct route_map_rule_list set_list
;
172 /* Make linked list. */
173 struct route_map_index
*next
;
174 struct route_map_index
*prev
;
176 /* Keep track how many times we've try to apply */
178 uint64_t applied_clear
;
180 /* List of match/sets contexts. */
181 TAILQ_HEAD(, routemap_hook_context
) rhclist
;
185 DECLARE_QOBJ_TYPE(route_map_index
);
187 /* route map maximum length. Not strictly the maximum xpath length but cannot be
190 #define RMAP_NAME_MAXLEN XPATH_MAXLEN
192 /* Route map list structure. */
194 /* Name of route map. */
197 /* Route map's rule. */
198 struct route_map_index
*head
;
199 struct route_map_index
*tail
;
201 /* Make linked list. */
202 struct route_map
*next
;
203 struct route_map
*prev
;
205 /* Maintain update info */
206 bool to_be_processed
; /* True if modification isn't acted on yet */
207 bool deleted
; /* If 1, then this node will be deleted */
208 bool optimization_disabled
;
210 /* How many times have we applied this route-map */
212 uint64_t applied_clear
;
214 /* Counter to track active usage of this route-map */
217 /* Tables to maintain IPv4 and IPv6 prefixes from
218 * the prefix-list match clause.
220 struct route_table
*ipv4_prefix_table
;
221 struct route_table
*ipv6_prefix_table
;
225 DECLARE_QOBJ_TYPE(route_map
);
227 /* Route-map match conditions */
228 #define IS_MATCH_INTERFACE(C) \
229 (strmatch(C, "frr-route-map:interface"))
230 #define IS_MATCH_IPv4_ADDRESS_LIST(C) \
231 (strmatch(C, "frr-route-map:ipv4-address-list"))
232 #define IS_MATCH_IPv6_ADDRESS_LIST(C) \
233 (strmatch(C, "frr-route-map:ipv6-address-list"))
234 #define IS_MATCH_IPv4_NEXTHOP_LIST(C) \
235 (strmatch(C, "frr-route-map:ipv4-next-hop-list"))
236 #define IS_MATCH_IPv6_NEXTHOP_LIST(C) \
237 (strmatch(C, "frr-route-map:ipv6-next-hop-list"))
238 #define IS_MATCH_IPv4_PREFIX_LIST(C) \
239 (strmatch(C, "frr-route-map:ipv4-prefix-list"))
240 #define IS_MATCH_IPv6_PREFIX_LIST(C) \
241 (strmatch(C, "frr-route-map:ipv6-prefix-list"))
242 #define IS_MATCH_IPv4_NEXTHOP_PREFIX_LIST(C) \
243 (strmatch(C, "frr-route-map:ipv4-next-hop-prefix-list"))
244 #define IS_MATCH_IPv6_NEXTHOP_PREFIX_LIST(C) \
245 (strmatch(C, "frr-route-map:ipv6-next-hop-prefix-list"))
246 #define IS_MATCH_IPv4_NEXTHOP_TYPE(C) \
247 (strmatch(C, "frr-route-map:ipv4-next-hop-type"))
248 #define IS_MATCH_IPv6_NEXTHOP_TYPE(C) \
249 (strmatch(C, "frr-route-map:ipv6-next-hop-type"))
250 #define IS_MATCH_METRIC(C) \
251 (strmatch(C, "frr-route-map:match-metric"))
252 #define IS_MATCH_TAG(C) (strmatch(C, "frr-route-map:match-tag"))
253 /* Zebra route-map match conditions */
254 #define IS_MATCH_IPv4_PREFIX_LEN(C) \
255 (strmatch(C, "frr-zebra-route-map:ipv4-prefix-length"))
256 #define IS_MATCH_IPv6_PREFIX_LEN(C) \
257 (strmatch(C, "frr-zebra-route-map:ipv6-prefix-length"))
258 #define IS_MATCH_IPv4_NH_PREFIX_LEN(C) \
259 (strmatch(C, "frr-zebra-route-map:ipv4-next-hop-prefix-length"))
260 #define IS_MATCH_SRC_PROTO(C) \
261 (strmatch(C, "frr-zebra-route-map:source-protocol"))
262 #define IS_MATCH_BGP_SRC_PROTO(C) \
263 (strmatch(C, "frr-bgp-route-map:source-protocol"))
264 #define IS_MATCH_SRC_INSTANCE(C) \
265 (strmatch(C, "frr-zebra-route-map:source-instance"))
266 /* BGP route-map match conditions */
267 #define IS_MATCH_LOCAL_PREF(C) \
268 (strmatch(C, "frr-bgp-route-map:match-local-preference"))
269 #define IS_MATCH_ALIAS(C) (strmatch(C, "frr-bgp-route-map:match-alias"))
270 #define IS_MATCH_SCRIPT(C) (strmatch(C, "frr-bgp-route-map:match-script"))
271 #define IS_MATCH_ORIGIN(C) \
272 (strmatch(C, "frr-bgp-route-map:match-origin"))
273 #define IS_MATCH_RPKI(C) (strmatch(C, "frr-bgp-route-map:rpki"))
274 #define IS_MATCH_RPKI_EXTCOMMUNITY(C) \
275 (strmatch(C, "frr-bgp-route-map:rpki-extcommunity"))
276 #define IS_MATCH_PROBABILITY(C) \
277 (strmatch(C, "frr-bgp-route-map:probability"))
278 #define IS_MATCH_SRC_VRF(C) \
279 (strmatch(C, "frr-bgp-route-map:source-vrf"))
280 #define IS_MATCH_PEER(C) (strmatch(C, "frr-bgp-route-map:peer"))
281 #define IS_MATCH_AS_LIST(C) \
282 (strmatch(C, "frr-bgp-route-map:as-path-list"))
283 #define IS_MATCH_MAC_LIST(C) \
284 (strmatch(C, "frr-bgp-route-map:mac-address-list"))
285 #define IS_MATCH_EVPN_ROUTE_TYPE(C) \
286 (strmatch(C, "frr-bgp-route-map:evpn-route-type"))
287 #define IS_MATCH_EVPN_DEFAULT_ROUTE(C) \
288 (strmatch(C, "frr-bgp-route-map:evpn-default-route"))
289 #define IS_MATCH_EVPN_VNI(C) \
290 (strmatch(C, "frr-bgp-route-map:evpn-vni"))
291 #define IS_MATCH_EVPN_DEFAULT_ROUTE(C) \
292 (strmatch(C, "frr-bgp-route-map:evpn-default-route"))
293 #define IS_MATCH_EVPN_RD(C) \
294 (strmatch(C, "frr-bgp-route-map:evpn-rd"))
295 #define IS_MATCH_ROUTE_SRC(C) \
296 (strmatch(C, "frr-bgp-route-map:ip-route-source"))
297 #define IS_MATCH_ROUTE_SRC_PL(C) \
298 (strmatch(C, "frr-bgp-route-map:ip-route-source-prefix-list"))
299 #define IS_MATCH_COMMUNITY(C) \
300 (strmatch(C, "frr-bgp-route-map:match-community"))
301 #define IS_MATCH_LCOMMUNITY(C) \
302 (strmatch(C, "frr-bgp-route-map:match-large-community"))
303 #define IS_MATCH_EXTCOMMUNITY(C) \
304 (strmatch(C, "frr-bgp-route-map:match-extcommunity"))
305 #define IS_MATCH_IPV4_NH(C) \
306 (strmatch(C, "frr-bgp-route-map:ipv4-nexthop"))
307 #define IS_MATCH_IPV6_NH(C) \
308 (strmatch(C, "frr-bgp-route-map:ipv6-nexthop"))
310 /* Route-map set actions */
311 #define IS_SET_IPv4_NH(A) \
312 (strmatch(A, "frr-route-map:ipv4-next-hop"))
313 #define IS_SET_IPv6_NH(A) \
314 (strmatch(A, "frr-route-map:ipv6-next-hop"))
315 #define IS_SET_METRIC(A) \
316 (strmatch(A, "frr-route-map:set-metric"))
317 #define IS_SET_MIN_METRIC(A) (strmatch(A, "frr-route-map:set-min-metric"))
318 #define IS_SET_MAX_METRIC(A) (strmatch(A, "frr-route-map:set-max-metric"))
319 #define IS_SET_TAG(A) (strmatch(A, "frr-route-map:set-tag"))
320 #define IS_SET_SR_TE_COLOR(A) \
321 (strmatch(A, "frr-route-map:set-sr-te-color"))
322 /* Zebra route-map set actions */
323 #define IS_SET_SRC(A) \
324 (strmatch(A, "frr-zebra-route-map:src-address"))
325 /* OSPF route-map set actions */
326 #define IS_SET_METRIC_TYPE(A) \
327 (strmatch(A, "frr-ospf-route-map:metric-type"))
328 #define IS_SET_FORWARDING_ADDR(A) \
329 (strmatch(A, "frr-ospf6-route-map:forwarding-address"))
330 /* BGP route-map_set actions */
331 #define IS_SET_WEIGHT(A) \
332 (strmatch(A, "frr-bgp-route-map:weight"))
333 #define IS_SET_TABLE(A) (strmatch(A, "frr-bgp-route-map:table"))
334 #define IS_SET_LOCAL_PREF(A) \
335 (strmatch(A, "frr-bgp-route-map:set-local-preference"))
336 #define IS_SET_LABEL_INDEX(A) \
337 (strmatch(A, "frr-bgp-route-map:label-index"))
338 #define IS_SET_DISTANCE(A) \
339 (strmatch(A, "frr-bgp-route-map:distance"))
340 #define IS_SET_ORIGIN(A) \
341 (strmatch(A, "frr-bgp-route-map:set-origin"))
342 #define IS_SET_ATOMIC_AGGREGATE(A) \
343 (strmatch(A, "frr-bgp-route-map:atomic-aggregate"))
344 #define IS_SET_AIGP_METRIC(A) (strmatch(A, "frr-bgp-route-map:aigp-metric"))
345 #define IS_SET_ORIGINATOR_ID(A) \
346 (strmatch(A, "frr-bgp-route-map:originator-id"))
347 #define IS_SET_COMM_LIST_DEL(A) \
348 (strmatch(A, "frr-bgp-route-map:comm-list-delete"))
349 #define IS_SET_LCOMM_LIST_DEL(A) \
350 (strmatch(A, "frr-bgp-route-map:large-comm-list-delete"))
351 #define IS_SET_LCOMMUNITY(A) \
352 (strmatch(A, "frr-bgp-route-map:set-large-community"))
353 #define IS_SET_COMMUNITY(A) \
354 (strmatch(A, "frr-bgp-route-map:set-community"))
355 #define IS_SET_EXTCOMMUNITY_NONE(A) \
356 (strmatch(A, "frr-bgp-route-map:set-extcommunity-none"))
357 #define IS_SET_EXTCOMMUNITY_RT(A) \
358 (strmatch(A, "frr-bgp-route-map:set-extcommunity-rt"))
359 #define IS_SET_EXTCOMMUNITY_NT(A) \
360 (strmatch(A, "frr-bgp-route-map:set-extcommunity-nt"))
361 #define IS_SET_EXTCOMMUNITY_SOO(A) \
362 (strmatch(A, "frr-bgp-route-map:set-extcommunity-soo"))
363 #define IS_SET_EXTCOMMUNITY_LB(A) \
364 (strmatch(A, "frr-bgp-route-map:set-extcommunity-lb"))
365 #define IS_SET_AGGREGATOR(A) \
366 (strmatch(A, "frr-bgp-route-map:aggregator"))
367 #define IS_SET_AS_PREPEND(A) \
368 (strmatch(A, "frr-bgp-route-map:as-path-prepend"))
369 #define IS_SET_AS_EXCLUDE(A) \
370 (strmatch(A, "frr-bgp-route-map:as-path-exclude"))
371 #define IS_SET_AS_REPLACE(A) (strmatch(A, "frr-bgp-route-map:as-path-replace"))
372 #define IS_SET_IPV6_NH_GLOBAL(A) \
373 (strmatch(A, "frr-bgp-route-map:ipv6-nexthop-global"))
374 #define IS_SET_IPV6_VPN_NH(A) \
375 (strmatch(A, "frr-bgp-route-map:ipv6-vpn-address"))
376 #define IS_SET_IPV6_PEER_ADDR(A) \
377 (strmatch(A, "frr-bgp-route-map:ipv6-peer-address"))
378 #define IS_SET_IPV6_PREFER_GLOBAL(A) \
379 (strmatch(A, "frr-bgp-route-map:ipv6-prefer-global"))
380 #define IS_SET_IPV4_VPN_NH(A) \
381 (strmatch(A, "frr-bgp-route-map:ipv4-vpn-address"))
382 #define IS_SET_BGP_IPV4_NH(A) \
383 (strmatch(A, "frr-bgp-route-map:set-ipv4-nexthop"))
384 #define IS_SET_BGP_EVPN_GATEWAY_IP_IPV4(A) \
385 (strmatch(A, "frr-bgp-route-map:set-evpn-gateway-ip-ipv4"))
386 #define IS_SET_BGP_EVPN_GATEWAY_IP_IPV6(A) \
387 (strmatch(A, "frr-bgp-route-map:set-evpn-gateway-ip-ipv6"))
388 #define IS_SET_BGP_L3VPN_NEXTHOP_ENCAPSULATION(A) \
389 (strmatch(A, "frr-bgp-route-map:set-l3vpn-nexthop-encapsulation"))
391 enum ecommunity_lb_type
{
393 CUMULATIVE_BANDWIDTH
,
398 extern void route_map_init(void);
401 * This should only be called on shutdown
402 * Additionally this function sets the hooks to NULL
403 * before any processing is done.
405 extern void route_map_finish(void);
407 /* Add match statement to route map. */
408 extern enum rmap_compile_rets
route_map_add_match(struct route_map_index
*index
,
409 const char *match_name
,
410 const char *match_arg
,
411 route_map_event_t type
);
413 /* Delete specified route match rule. */
414 extern enum rmap_compile_rets
415 route_map_delete_match(struct route_map_index
*index
,
416 const char *match_name
, const char *match_arg
,
417 route_map_event_t type
);
419 extern const char *route_map_get_match_arg(struct route_map_index
*index
,
420 const char *match_name
);
422 /* Add route-map set statement to the route map. */
423 extern enum rmap_compile_rets
route_map_add_set(struct route_map_index
*index
,
424 const char *set_name
,
425 const char *set_arg
);
427 /* Delete route map set rule. */
428 extern enum rmap_compile_rets
429 route_map_delete_set(struct route_map_index
*index
,
430 const char *set_name
, const char *set_arg
);
432 /* struct route_map_rule_cmd is kept const in order to not have writable
433 * function pointers (which is a security benefit.) Hence, below struct is
434 * used as proxy for hashing these for by-name lookup.
437 PREDECL_HASH(rmap_cmd_name
);
439 struct route_map_rule_cmd_proxy
{
440 struct rmap_cmd_name_item itm
;
441 const struct route_map_rule_cmd
*cmd
;
444 /* ... and just automatically create a proxy struct for each call location
445 * to route_map_install_{match,set} to avoid unnecessarily added boilerplate
446 * for each route-map user
449 #define route_map_install_match(c) \
451 static struct route_map_rule_cmd_proxy proxy = {.cmd = c}; \
452 _route_map_install_match(&proxy); \
455 #define route_map_install_set(c) \
457 static struct route_map_rule_cmd_proxy proxy = {.cmd = c}; \
458 _route_map_install_set(&proxy); \
461 /* Install rule command to the match list. */
462 extern void _route_map_install_match(struct route_map_rule_cmd_proxy
*proxy
);
465 * Install rule command to the set list.
467 * When installing a particular item, Allow a difference of handling
468 * of bad cli inputted(return NULL) -vs- this particular daemon cannot use
469 * this form of the command(return a pointer and handle it appropriately
470 * in the apply command). See 'set metric' command
471 * as it is handled in ripd/ripngd and ospfd.
473 extern void _route_map_install_set(struct route_map_rule_cmd_proxy
*proxy
);
475 /* Lookup route map by name. */
476 extern struct route_map
*route_map_lookup_by_name(const char *name
);
478 /* Simple helper to warn if route-map does not exist. */
479 struct route_map
*route_map_lookup_warn_noexist(struct vty
*vty
, const char *name
);
481 /* Apply route map to the object. */
482 extern route_map_result_t
route_map_apply_ext(struct route_map
*map
,
483 const struct prefix
*prefix
,
485 void *set_object
, int *pref
);
486 #define route_map_apply(map, prefix, object) \
487 route_map_apply_ext(map, prefix, object, object, NULL)
489 extern void route_map_add_hook(void (*func
)(const char *));
490 extern void route_map_delete_hook(void (*func
)(const char *));
493 * This is the callback for when something has changed about a
494 * route-map. The interested parties can register to receive
497 * name - Is the name of the changed route-map
499 extern void route_map_event_hook(void (*func
)(const char *name
));
500 extern int route_map_mark_updated(const char *name
);
501 extern void route_map_walk_update_list(void (*update_fn
)(char *name
));
502 extern void route_map_upd8_dependency(route_map_event_t type
, const char *arg
,
503 const char *rmap_name
);
504 extern void route_map_notify_dependencies(const char *affected_name
,
505 route_map_event_t event
);
507 route_map_notify_pentry_dependencies(const char *affected_name
,
508 struct prefix_list_entry
*pentry
,
509 route_map_event_t event
);
510 extern int generic_match_add(struct route_map_index
*index
,
511 const char *command
, const char *arg
,
512 route_map_event_t type
,
513 char *errmsg
, size_t errmsg_len
);
514 extern int generic_match_delete(struct route_map_index
*index
,
515 const char *command
, const char *arg
,
516 route_map_event_t type
,
517 char *errmsg
, size_t errmsg_len
);
519 extern int generic_set_add(struct route_map_index
*index
,
520 const char *command
, const char *arg
,
521 char *errmsg
, size_t errmsg_len
);
522 extern int generic_set_delete(struct route_map_index
*index
,
523 const char *command
, const char *arg
,
524 char *errmsg
, size_t errmsg_len
);
527 /* match interface */
528 extern void route_map_match_interface_hook(int (*func
)(
529 struct route_map_index
*index
, const char *command
,
530 const char *arg
, route_map_event_t type
,
531 char *errmsg
, size_t errmsg_len
));
532 /* no match interface */
533 extern void route_map_no_match_interface_hook(int (*func
)(
534 struct route_map_index
*index
, const char *command
,
535 const char *arg
, route_map_event_t type
,
536 char *errmsg
, size_t errmsg_len
));
537 /* match ip address */
538 extern void route_map_match_ip_address_hook(int (*func
)(
539 struct route_map_index
*index
, const char *command
,
540 const char *arg
, route_map_event_t type
,
541 char *errmsg
, size_t errmsg_len
));
542 /* no match ip address */
543 extern void route_map_no_match_ip_address_hook(int (*func
)(
544 struct route_map_index
*index
, const char *command
,
545 const char *arg
, route_map_event_t type
,
546 char *errmsg
, size_t errmsg_len
));
547 /* match ip address prefix list */
548 extern void route_map_match_ip_address_prefix_list_hook(int (*func
)(
549 struct route_map_index
*index
, const char *command
,
550 const char *arg
, route_map_event_t type
,
551 char *errmsg
, size_t errmsg_len
));
552 /* no match ip address prefix list */
553 extern void route_map_no_match_ip_address_prefix_list_hook(int (*func
)(
554 struct route_map_index
*index
, const char *command
,
555 const char *arg
, route_map_event_t type
,
556 char *errmsg
, size_t errmsg_len
));
557 /* match ip next hop */
558 extern void route_map_match_ip_next_hop_hook(int (*func
)(
559 struct route_map_index
*index
, const char *command
,
560 const char *arg
, route_map_event_t type
,
561 char *errmsg
, size_t errmsg_len
));
562 /* no match ip next hop */
563 extern void route_map_no_match_ip_next_hop_hook(int (*func
)(
564 struct route_map_index
*index
, const char *command
, const char *arg
,
565 route_map_event_t type
, char *errmsg
, size_t errmsg_len
));
566 /* match ipv6 next hop */
567 extern void route_map_match_ipv6_next_hop_hook(int (*func
)(
568 struct route_map_index
*index
, const char *command
, const char *arg
,
569 route_map_event_t type
, char *errmsg
, size_t errmsg_len
));
570 /* no match ipv6 next hop */
571 extern void route_map_no_match_ipv6_next_hop_hook(int (*func
)(
572 struct route_map_index
*index
, const char *command
, const char *arg
,
573 route_map_event_t type
, char *errmsg
, size_t errmsg_len
));
574 /* match ip next hop prefix list */
575 extern void route_map_match_ip_next_hop_prefix_list_hook(int (*func
)(
576 struct route_map_index
*index
, const char *command
,
577 const char *arg
, route_map_event_t type
,
578 char *errmsg
, size_t errmsg_len
));
579 /* no match ip next hop prefix list */
580 extern void route_map_no_match_ip_next_hop_prefix_list_hook(int (*func
)(
581 struct route_map_index
*index
, const char *command
,
582 const char *arg
, route_map_event_t type
,
583 char *errmsg
, size_t errmsg_len
));
584 /* match ip next hop type */
585 extern void route_map_match_ip_next_hop_type_hook(int (*func
)(
586 struct route_map_index
*index
, const char *command
,
587 const char *arg
, route_map_event_t type
,
588 char *errmsg
, size_t errmsg_len
));
589 /* no match ip next hop type */
590 extern void route_map_no_match_ip_next_hop_type_hook(int (*func
)(
591 struct route_map_index
*index
, const char *command
,
592 const char *arg
, route_map_event_t type
,
593 char *errmsg
, size_t errmsg_len
));
594 /* match ipv6 address */
595 extern void route_map_match_ipv6_address_hook(int (*func
)(
596 struct route_map_index
*index
, const char *command
,
597 const char *arg
, route_map_event_t type
,
598 char *errmsg
, size_t errmsg_len
));
599 /* no match ipv6 address */
600 extern void route_map_no_match_ipv6_address_hook(int (*func
)(
601 struct route_map_index
*index
, const char *command
,
602 const char *arg
, route_map_event_t type
,
603 char *errmsg
, size_t errmsg_len
));
604 /* match ipv6 address prefix list */
605 extern void route_map_match_ipv6_address_prefix_list_hook(int (*func
)(
606 struct route_map_index
*index
, const char *command
,
607 const char *arg
, route_map_event_t type
,
608 char *errmsg
, size_t errmsg_len
));
609 /* no match ipv6 address prefix list */
610 extern void route_map_no_match_ipv6_address_prefix_list_hook(int (*func
)(
611 struct route_map_index
*index
, const char *command
,
612 const char *arg
, route_map_event_t type
,
613 char *errmsg
, size_t errmsg_len
));
614 /* match ipv6 next-hop type */
615 extern void route_map_match_ipv6_next_hop_type_hook(int (*func
)(
616 struct route_map_index
*index
, const char *command
,
617 const char *arg
, route_map_event_t type
,
618 char *errmsg
, size_t errmsg_len
));
619 /* no match ipv6 next-hop type */
620 extern void route_map_no_match_ipv6_next_hop_type_hook(int (*func
)(
621 struct route_map_index
*index
, const char *command
,
622 const char *arg
, route_map_event_t type
,
623 char *errmsg
, size_t errmsg_len
));
624 /* match ipv6 next-hop prefix-list */
625 extern void route_map_match_ipv6_next_hop_prefix_list_hook(int (*func
)(
626 struct route_map_index
*index
, const char *command
, const char *arg
,
627 route_map_event_t type
, char *errmsg
, size_t errmsg_len
));
628 /* no match ipv6 next-hop prefix-list */
629 extern void route_map_no_match_ipv6_next_hop_prefix_list_hook(int (*func
)(
630 struct route_map_index
*index
, const char *command
, const char *arg
,
631 route_map_event_t type
, char *errmsg
, size_t errmsg_len
));
633 extern void route_map_match_metric_hook(int (*func
)(
634 struct route_map_index
*index
, const char *command
,
635 const char *arg
, route_map_event_t type
,
636 char *errmsg
, size_t errmsg_len
));
637 /* no match metric */
638 extern void route_map_no_match_metric_hook(int (*func
)(
639 struct route_map_index
*index
, const char *command
,
640 const char *arg
, route_map_event_t type
,
641 char *errmsg
, size_t errmsg_len
));
643 extern void route_map_match_tag_hook(int (*func
)(
644 struct route_map_index
*index
, const char *command
,
645 const char *arg
, route_map_event_t type
,
646 char *errmsg
, size_t errmsg_len
));
648 extern void route_map_no_match_tag_hook(int (*func
)(
649 struct route_map_index
*index
, const char *command
,
650 const char *arg
, route_map_event_t type
,
651 char *errmsg
, size_t errmsg_len
));
652 /* set sr-te color */
653 extern void route_map_set_srte_color_hook(
654 int (*func
)(struct route_map_index
*index
,
655 const char *command
, const char *arg
,
656 char *errmsg
, size_t errmsg_len
));
657 /* no set sr-te color */
658 extern void route_map_no_set_srte_color_hook(
659 int (*func
)(struct route_map_index
*index
,
660 const char *command
, const char *arg
,
661 char *errmsg
, size_t errmsg_len
));
663 extern void route_map_set_ip_nexthop_hook(
664 int (*func
)(struct route_map_index
*index
,
665 const char *command
, const char *arg
,
666 char *errmsg
, size_t errmsg_len
));
667 /* no set ip nexthop */
668 extern void route_map_no_set_ip_nexthop_hook(
669 int (*func
)(struct route_map_index
*index
,
670 const char *command
, const char *arg
,
671 char *errmsg
, size_t errmsg_len
));
672 /* set ipv6 nexthop local */
673 extern void route_map_set_ipv6_nexthop_local_hook(
674 int (*func
)(struct route_map_index
*index
,
675 const char *command
, const char *arg
,
676 char *errmsg
, size_t errmsg_len
));
677 /* no set ipv6 nexthop local */
678 extern void route_map_no_set_ipv6_nexthop_local_hook(
679 int (*func
)(struct route_map_index
*index
,
680 const char *command
, const char *arg
,
681 char *errmsg
, size_t errmsg_len
));
683 extern void route_map_set_metric_hook(int (*func
)(struct route_map_index
*index
,
689 extern void route_map_no_set_metric_hook(
690 int (*func
)(struct route_map_index
*index
,
691 const char *command
, const char *arg
,
692 char *errmsg
, size_t errmsg_len
));
694 extern void route_map_set_max_metric_hook(
695 int (*func
)(struct route_map_index
*index
, const char *command
,
696 const char *arg
, char *errmsg
, size_t errmsg_len
));
698 extern void route_map_no_set_max_metric_hook(
699 int (*func
)(struct route_map_index
*index
, const char *command
,
700 const char *arg
, char *errmsg
, size_t errmsg_len
));
702 extern void route_map_set_min_metric_hook(
703 int (*func
)(struct route_map_index
*index
, const char *command
,
704 const char *arg
, char *errmsg
, size_t errmsg_len
));
706 extern void route_map_no_set_min_metric_hook(
707 int (*func
)(struct route_map_index
*index
, const char *command
,
708 const char *arg
, char *errmsg
, size_t errmsg_len
));
710 extern void route_map_set_tag_hook(int (*func
)(struct route_map_index
*index
,
716 extern void route_map_no_set_tag_hook(int (*func
)(struct route_map_index
*index
,
722 extern void *route_map_rule_tag_compile(const char *arg
);
723 extern void route_map_rule_tag_free(void *rule
);
725 /* Increment the route-map used counter */
726 extern void route_map_counter_increment(struct route_map
*map
);
728 /* Decrement the route-map used counter */
729 extern void route_map_counter_decrement(struct route_map
*map
);
731 /* Route map hooks data structure. */
732 struct route_map_match_set_hooks
{
733 /* match interface */
734 int (*match_interface
)(struct route_map_index
*index
,
735 const char *command
, const char *arg
,
736 route_map_event_t type
,
737 char *errmsg
, size_t errmsg_len
);
739 /* no match interface */
740 int (*no_match_interface
)(struct route_map_index
*index
,
741 const char *command
, const char *arg
,
742 route_map_event_t type
,
743 char *errmsg
, size_t errmsg_len
);
745 /* match ip address */
746 int (*match_ip_address
)(struct route_map_index
*index
,
747 const char *command
, const char *arg
,
748 route_map_event_t type
,
749 char *errmsg
, size_t errmsg_len
);
751 /* no match ip address */
752 int (*no_match_ip_address
)(struct route_map_index
*index
,
753 const char *command
, const char *arg
,
754 route_map_event_t type
,
755 char *errmsg
, size_t errmsg_len
);
757 /* match ip address prefix list */
758 int (*match_ip_address_prefix_list
)(struct route_map_index
*index
,
761 route_map_event_t type
,
762 char *errmsg
, size_t errmsg_len
);
764 /* no match ip address prefix list */
765 int (*no_match_ip_address_prefix_list
)(struct route_map_index
*index
,
768 route_map_event_t type
,
769 char *errmsg
, size_t errmsg_len
);
771 /* match ip next hop */
772 int (*match_ip_next_hop
)(struct route_map_index
*index
,
773 const char *command
, const char *arg
,
774 route_map_event_t type
,
775 char *errmsg
, size_t errmsg_len
);
777 /* no match ip next hop */
778 int (*no_match_ip_next_hop
)(struct route_map_index
*index
,
779 const char *command
, const char *arg
,
780 route_map_event_t type
,
781 char *errmsg
, size_t errmsg_len
);
783 /* match ipv6 next hop */
784 int (*match_ipv6_next_hop
)(struct route_map_index
*index
,
785 const char *command
, const char *arg
,
786 route_map_event_t type
, char *errmsg
,
789 /* no match ipv6 next hop */
790 int (*no_match_ipv6_next_hop
)(struct route_map_index
*index
,
791 const char *command
, const char *arg
,
792 route_map_event_t type
, char *errmsg
,
795 /* match ipv6 next hop prefix-list */
796 int (*match_ipv6_next_hop_prefix_list
)(struct route_map_index
*index
,
799 route_map_event_t type
,
800 char *errmsg
, size_t errmsg_len
);
802 /* no match ipv6 next-hop prefix-list */
803 int (*no_match_ipv6_next_hop_prefix_list
)(struct route_map_index
*index
,
806 route_map_event_t type
,
810 /* match ip next hop prefix list */
811 int (*match_ip_next_hop_prefix_list
)(struct route_map_index
*index
,
814 route_map_event_t type
,
815 char *errmsg
, size_t errmsg_len
);
817 /* no match ip next hop prefix list */
818 int (*no_match_ip_next_hop_prefix_list
)(struct route_map_index
*index
,
821 route_map_event_t type
,
825 /* match ip next-hop type */
826 int (*match_ip_next_hop_type
)(struct route_map_index
*index
,
829 route_map_event_t type
,
833 /* no match ip next-hop type */
834 int (*no_match_ip_next_hop_type
)(struct route_map_index
*index
,
837 route_map_event_t type
,
841 /* match ipv6 address */
842 int (*match_ipv6_address
)(struct route_map_index
*index
,
843 const char *command
, const char *arg
,
844 route_map_event_t type
,
845 char *errmsg
, size_t errmsg_len
);
847 /* no match ipv6 address */
848 int (*no_match_ipv6_address
)(struct route_map_index
*index
,
849 const char *command
, const char *arg
,
850 route_map_event_t type
,
851 char *errmsg
, size_t errmsg_len
);
854 /* match ipv6 address prefix list */
855 int (*match_ipv6_address_prefix_list
)(struct route_map_index
*index
,
858 route_map_event_t type
,
859 char *errmsg
, size_t errmsg_len
);
861 /* no match ipv6 address prefix list */
862 int (*no_match_ipv6_address_prefix_list
)(struct route_map_index
*index
,
865 route_map_event_t type
,
869 /* match ipv6 next-hop type */
870 int (*match_ipv6_next_hop_type
)(struct route_map_index
*index
,
873 route_map_event_t type
,
874 char *errmsg
, size_t errmsg_len
);
876 /* no match ipv6 next-hop type */
877 int (*no_match_ipv6_next_hop_type
)(struct route_map_index
*index
,
878 const char *command
, const char *arg
,
879 route_map_event_t type
,
880 char *errmsg
, size_t errmsg_len
);
883 int (*match_metric
)(struct route_map_index
*index
,
884 const char *command
, const char *arg
,
885 route_map_event_t type
,
886 char *errmsg
, size_t errmsg_len
);
888 /* no match metric */
889 int (*no_match_metric
)(struct route_map_index
*index
,
890 const char *command
, const char *arg
,
891 route_map_event_t type
,
892 char *errmsg
, size_t errmsg_len
);
895 int (*match_tag
)(struct route_map_index
*index
,
896 const char *command
, const char *arg
,
897 route_map_event_t type
,
898 char *errmsg
, size_t errmsg_len
);
901 int (*no_match_tag
)(struct route_map_index
*index
,
902 const char *command
, const char *arg
,
903 route_map_event_t type
,
904 char *errmsg
, size_t errmsg_len
);
906 /* set sr-te color */
907 int (*set_srte_color
)(struct route_map_index
*index
,
908 const char *command
, const char *arg
,
909 char *errmsg
, size_t errmsg_len
);
911 /* no set sr-te color */
912 int (*no_set_srte_color
)(struct route_map_index
*index
,
913 const char *command
, const char *arg
,
914 char *errmsg
, size_t errmsg_len
);
917 int (*set_ip_nexthop
)(struct route_map_index
*index
,
918 const char *command
, const char *arg
,
919 char *errmsg
, size_t errmsg_len
);
921 /* no set ip nexthop */
922 int (*no_set_ip_nexthop
)(struct route_map_index
*index
,
923 const char *command
, const char *arg
,
924 char *errmsg
, size_t errmsg_len
);
926 /* set ipv6 nexthop local */
927 int (*set_ipv6_nexthop_local
)(struct route_map_index
*index
,
928 const char *command
, const char *arg
,
929 char *errmsg
, size_t errmsg_len
);
931 /* no set ipv6 nexthop local */
932 int (*no_set_ipv6_nexthop_local
)(struct route_map_index
*index
,
933 const char *command
, const char *arg
,
934 char *errmsg
, size_t errmsg_len
);
937 int (*set_metric
)(struct route_map_index
*index
,
938 const char *command
, const char *arg
,
939 char *errmsg
, size_t errmsg_len
);
942 int (*no_set_metric
)(struct route_map_index
*index
,
943 const char *command
, const char *arg
,
944 char *errmsg
, size_t errmsg_len
);
946 int (*set_min_metric
)(struct route_map_index
*index
,
947 const char *command
, const char *arg
,
948 char *errmsg
, size_t errmsg_len
);
950 /* no set min-metric */
951 int (*no_set_min_metric
)(struct route_map_index
*index
,
952 const char *command
, const char *arg
,
953 char *errmsg
, size_t errmsg_len
);
956 int (*set_max_metric
)(struct route_map_index
*index
,
957 const char *command
, const char *arg
,
958 char *errmsg
, size_t errmsg_len
);
960 /* no set max-metric */
961 int (*no_set_max_metric
)(struct route_map_index
*index
,
962 const char *command
, const char *arg
,
963 char *errmsg
, size_t errmsg_len
);
966 int (*set_tag
)(struct route_map_index
*index
,
967 const char *command
, const char *arg
,
968 char *errmsg
, size_t errmsg_len
);
971 int (*no_set_tag
)(struct route_map_index
*index
,
972 const char *command
, const char *arg
,
973 char *errmsg
, size_t errmsg_len
);
976 extern struct route_map_match_set_hooks rmap_match_set_hook
;
978 /* Making route map list. */
979 struct route_map_list
{
980 struct route_map
*head
;
981 struct route_map
*tail
;
983 void (*add_hook
)(const char *);
984 void (*delete_hook
)(const char *);
985 void (*event_hook
)(const char *);
988 extern struct route_map_list route_map_master
;
990 extern struct route_map
*route_map_get(const char *name
);
991 extern void route_map_delete(struct route_map
*map
);
992 extern struct route_map_index
*route_map_index_get(struct route_map
*map
,
993 enum route_map_type type
,
995 extern void route_map_index_delete(struct route_map_index
*index
, int notify
);
997 /* routemap_northbound.c */
998 typedef int (*routemap_match_hook_fun
)(struct route_map_index
*rmi
,
999 const char *command
, const char *arg
,
1000 route_map_event_t event
,
1001 char *errmsg
, size_t errmsg_len
);
1002 typedef int (*routemap_set_hook_fun
)(struct route_map_index
*rmi
,
1003 const char *command
, const char *arg
,
1004 char *errmsg
, size_t errmsg_len
);
1005 struct routemap_hook_context
{
1006 struct route_map_index
*rhc_rmi
;
1007 const char *rhc_rule
;
1008 route_map_event_t rhc_event
;
1009 routemap_set_hook_fun rhc_shook
;
1010 routemap_match_hook_fun rhc_mhook
;
1011 TAILQ_ENTRY(routemap_hook_context
) rhc_entry
;
1014 int lib_route_map_entry_match_destroy(struct nb_cb_destroy_args
*args
);
1015 int lib_route_map_entry_set_destroy(struct nb_cb_destroy_args
*args
);
1017 struct routemap_hook_context
*
1018 routemap_hook_context_insert(struct route_map_index
*rmi
);
1019 void routemap_hook_context_free(struct routemap_hook_context
*rhc
);
1021 extern const struct frr_yang_module_info frr_route_map_info
;
1023 /* routemap_cli.c */
1024 extern int route_map_instance_cmp(const struct lyd_node
*dnode1
,
1025 const struct lyd_node
*dnode2
);
1026 extern void route_map_instance_show(struct vty
*vty
,
1027 const struct lyd_node
*dnode
,
1028 bool show_defaults
);
1029 extern void route_map_instance_show_end(struct vty
*vty
,
1030 const struct lyd_node
*dnode
);
1031 extern void route_map_condition_show(struct vty
*vty
,
1032 const struct lyd_node
*dnode
,
1033 bool show_defaults
);
1034 extern void route_map_action_show(struct vty
*vty
, const struct lyd_node
*dnode
,
1035 bool show_defaults
);
1036 extern void route_map_exit_policy_show(struct vty
*vty
,
1037 const struct lyd_node
*dnode
,
1038 bool show_defaults
);
1039 extern void route_map_call_show(struct vty
*vty
, const struct lyd_node
*dnode
,
1040 bool show_defaults
);
1041 extern void route_map_description_show(struct vty
*vty
,
1042 const struct lyd_node
*dnode
,
1043 bool show_defaults
);
1044 extern void route_map_optimization_disabled_show(struct vty
*vty
,
1045 const struct lyd_node
*dnode
,
1046 bool show_defaults
);
1047 extern void route_map_cli_init(void);
1049 extern void route_map_show_debug(struct vty
*vty
);
1055 #endif /* _ZEBRA_ROUTEMAP_H */