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
29 #include "lib/plist.h"
30 #include "lib/plist_int.h"
36 DECLARE_MTYPE(ROUTE_MAP_NAME
);
37 DECLARE_MTYPE(ROUTE_MAP_RULE
);
38 DECLARE_MTYPE(ROUTE_MAP_COMPILED
);
40 /* Route map's type. */
41 enum route_map_type
{ RMAP_PERMIT
, RMAP_DENY
, RMAP_ANY
};
49 * Route-map match or set result "Eg: match evpn vni xx"
50 * route-map match cmd always returns match/nomatch/noop
51 * match--> found a match
52 * nomatch--> didnt find a match
53 * noop--> not applicable
54 * route-map set retuns okay/error
55 * okay --> set was successful
56 * error --> set was not successful
58 enum route_map_cmd_result_t
{
60 * route-map match cmd results
66 * route-map set cmd results
72 typedef enum { RMAP_EXIT
, RMAP_GOTO
, RMAP_NEXT
} route_map_end_t
;
76 RMAP_EVENT_SET_DELETED
,
77 RMAP_EVENT_SET_REPLACED
,
78 RMAP_EVENT_MATCH_ADDED
,
79 RMAP_EVENT_MATCH_DELETED
,
80 RMAP_EVENT_MATCH_REPLACED
,
81 RMAP_EVENT_INDEX_ADDED
,
82 RMAP_EVENT_INDEX_DELETED
,
83 RMAP_EVENT_CALL_ADDED
, /* call to another routemap added */
84 RMAP_EVENT_CALL_DELETED
,
85 RMAP_EVENT_PLIST_ADDED
,
86 RMAP_EVENT_PLIST_DELETED
,
87 RMAP_EVENT_CLIST_ADDED
,
88 RMAP_EVENT_CLIST_DELETED
,
89 RMAP_EVENT_ECLIST_ADDED
,
90 RMAP_EVENT_ECLIST_DELETED
,
91 RMAP_EVENT_LLIST_ADDED
,
92 RMAP_EVENT_LLIST_DELETED
,
93 RMAP_EVENT_ASLIST_ADDED
,
94 RMAP_EVENT_ASLIST_DELETED
,
95 RMAP_EVENT_FILTER_ADDED
,
96 RMAP_EVENT_FILTER_DELETED
,
99 /* Depth limit in RMAP recursion using RMAP_CALL. */
100 #define RMAP_RECURSION_LIMIT 10
102 /* Route map rule structure for matching and setting. */
103 struct route_map_rule_cmd
{
104 /* Route map rule name (e.g. as-path, metric) */
107 /* Function for value set or match. */
108 enum route_map_cmd_result_t (*func_apply
)(void *rule
,
109 const struct prefix
*prefix
,
112 /* Compile argument and return result as void *. */
113 void *(*func_compile
)(const char *);
115 /* Free allocated value by func_compile (). */
116 void (*func_free
)(void *);
118 /** To get the rule key after Compilation **/
119 void *(*func_get_rmap_rule_key
)(void *val
);
122 /* Route map apply error. */
123 enum rmap_compile_rets
{
124 RMAP_COMPILE_SUCCESS
,
126 /* Route map rule is missing. */
129 /* Route map rule can't compile */
134 /* Route map rule. This rule has both `match' rule and `set' rule. */
135 struct route_map_rule
{
137 const struct route_map_rule_cmd
*cmd
;
139 /* For pretty printing. */
142 /* Pre-compiled match rule. */
146 struct route_map_rule
*next
;
147 struct route_map_rule
*prev
;
150 /* Route map rule list. */
151 struct route_map_rule_list
{
152 struct route_map_rule
*head
;
153 struct route_map_rule
*tail
;
156 /* Forward struct declaration: the complete can be found later this file. */
157 struct routemap_hook_context
;
159 /* Route map index structure. */
160 struct route_map_index
{
161 struct route_map
*map
;
164 /* Preference of this route map rule. */
167 /* Route map type permit or deny. */
168 enum route_map_type type
;
170 /* Do we follow old rules, or hop forward? */
171 route_map_end_t exitpolicy
;
173 /* If we're using "GOTO", to where do we go? */
176 /* If we're using "CALL", to which route-map do ew go? */
179 /* Matching rule list. */
180 struct route_map_rule_list match_list
;
181 struct route_map_rule_list set_list
;
183 /* Make linked list. */
184 struct route_map_index
*next
;
185 struct route_map_index
*prev
;
187 /* Keep track how many times we've try to apply */
189 uint64_t applied_clear
;
191 /* List of match/sets contexts. */
192 TAILQ_HEAD(, routemap_hook_context
) rhclist
;
196 DECLARE_QOBJ_TYPE(route_map_index
);
198 /* route map maximum length. Not strictly the maximum xpath length but cannot be
201 #define RMAP_NAME_MAXLEN XPATH_MAXLEN
203 /* Route map list structure. */
205 /* Name of route map. */
208 /* Route map's rule. */
209 struct route_map_index
*head
;
210 struct route_map_index
*tail
;
212 /* Make linked list. */
213 struct route_map
*next
;
214 struct route_map
*prev
;
216 /* Maintain update info */
217 bool to_be_processed
; /* True if modification isn't acted on yet */
218 bool deleted
; /* If 1, then this node will be deleted */
219 bool optimization_disabled
;
221 /* How many times have we applied this route-map */
223 uint64_t applied_clear
;
225 /* Counter to track active usage of this route-map */
228 /* Tables to maintain IPv4 and IPv6 prefixes from
229 * the prefix-list match clause.
231 struct route_table
*ipv4_prefix_table
;
232 struct route_table
*ipv6_prefix_table
;
236 DECLARE_QOBJ_TYPE(route_map
);
238 /* Route-map match conditions */
239 #define IS_MATCH_INTERFACE(C) \
240 (strmatch(C, "frr-route-map:interface"))
241 #define IS_MATCH_IPv4_ADDRESS_LIST(C) \
242 (strmatch(C, "frr-route-map:ipv4-address-list"))
243 #define IS_MATCH_IPv6_ADDRESS_LIST(C) \
244 (strmatch(C, "frr-route-map:ipv6-address-list"))
245 #define IS_MATCH_IPv4_NEXTHOP_LIST(C) \
246 (strmatch(C, "frr-route-map:ipv4-next-hop-list"))
247 #define IS_MATCH_IPv6_NEXTHOP_LIST(C) \
248 (strmatch(C, "frr-route-map:ipv6-next-hop-list"))
249 #define IS_MATCH_IPv4_PREFIX_LIST(C) \
250 (strmatch(C, "frr-route-map:ipv4-prefix-list"))
251 #define IS_MATCH_IPv6_PREFIX_LIST(C) \
252 (strmatch(C, "frr-route-map:ipv6-prefix-list"))
253 #define IS_MATCH_IPv4_NEXTHOP_PREFIX_LIST(C) \
254 (strmatch(C, "frr-route-map:ipv4-next-hop-prefix-list"))
255 #define IS_MATCH_IPv6_NEXTHOP_PREFIX_LIST(C) \
256 (strmatch(C, "frr-route-map:ipv6-next-hop-prefix-list"))
257 #define IS_MATCH_IPv4_NEXTHOP_TYPE(C) \
258 (strmatch(C, "frr-route-map:ipv4-next-hop-type"))
259 #define IS_MATCH_IPv6_NEXTHOP_TYPE(C) \
260 (strmatch(C, "frr-route-map:ipv6-next-hop-type"))
261 #define IS_MATCH_METRIC(C) \
262 (strmatch(C, "frr-route-map:match-metric"))
263 #define IS_MATCH_TAG(C) (strmatch(C, "frr-route-map:match-tag"))
264 /* Zebra route-map match conditions */
265 #define IS_MATCH_IPv4_PREFIX_LEN(C) \
266 (strmatch(C, "frr-zebra-route-map:ipv4-prefix-length"))
267 #define IS_MATCH_IPv6_PREFIX_LEN(C) \
268 (strmatch(C, "frr-zebra-route-map:ipv6-prefix-length"))
269 #define IS_MATCH_IPv4_NH_PREFIX_LEN(C) \
270 (strmatch(C, "frr-zebra-route-map:ipv4-next-hop-prefix-length"))
271 #define IS_MATCH_SRC_PROTO(C) \
272 (strmatch(C, "frr-zebra-route-map:source-protocol"))
273 #define IS_MATCH_SRC_INSTANCE(C) \
274 (strmatch(C, "frr-zebra-route-map:source-instance"))
275 /* BGP route-map match conditions */
276 #define IS_MATCH_LOCAL_PREF(C) \
277 (strmatch(C, "frr-bgp-route-map:match-local-preference"))
278 #define IS_MATCH_ALIAS(C) (strmatch(C, "frr-bgp-route-map:match-alias"))
279 #define IS_MATCH_SCRIPT(C) (strmatch(C, "frr-bgp-route-map:match-script"))
280 #define IS_MATCH_ORIGIN(C) \
281 (strmatch(C, "frr-bgp-route-map:match-origin"))
282 #define IS_MATCH_RPKI(C) (strmatch(C, "frr-bgp-route-map:rpki"))
283 #define IS_MATCH_PROBABILITY(C) \
284 (strmatch(C, "frr-bgp-route-map:probability"))
285 #define IS_MATCH_SRC_VRF(C) \
286 (strmatch(C, "frr-bgp-route-map:source-vrf"))
287 #define IS_MATCH_PEER(C) (strmatch(C, "frr-bgp-route-map:peer"))
288 #define IS_MATCH_AS_LIST(C) \
289 (strmatch(C, "frr-bgp-route-map:as-path-list"))
290 #define IS_MATCH_MAC_LIST(C) \
291 (strmatch(C, "frr-bgp-route-map:mac-address-list"))
292 #define IS_MATCH_EVPN_ROUTE_TYPE(C) \
293 (strmatch(C, "frr-bgp-route-map:evpn-route-type"))
294 #define IS_MATCH_EVPN_DEFAULT_ROUTE(C) \
295 (strmatch(C, "frr-bgp-route-map:evpn-default-route"))
296 #define IS_MATCH_EVPN_VNI(C) \
297 (strmatch(C, "frr-bgp-route-map:evpn-vni"))
298 #define IS_MATCH_EVPN_DEFAULT_ROUTE(C) \
299 (strmatch(C, "frr-bgp-route-map:evpn-default-route"))
300 #define IS_MATCH_EVPN_RD(C) \
301 (strmatch(C, "frr-bgp-route-map:evpn-rd"))
302 #define IS_MATCH_ROUTE_SRC(C) \
303 (strmatch(C, "frr-bgp-route-map:ip-route-source"))
304 #define IS_MATCH_ROUTE_SRC_PL(C) \
305 (strmatch(C, "frr-bgp-route-map:ip-route-source-prefix-list"))
306 #define IS_MATCH_COMMUNITY(C) \
307 (strmatch(C, "frr-bgp-route-map:match-community"))
308 #define IS_MATCH_LCOMMUNITY(C) \
309 (strmatch(C, "frr-bgp-route-map:match-large-community"))
310 #define IS_MATCH_EXTCOMMUNITY(C) \
311 (strmatch(C, "frr-bgp-route-map:match-extcommunity"))
312 #define IS_MATCH_IPV4_NH(C) \
313 (strmatch(C, "frr-bgp-route-map:ipv4-nexthop"))
314 #define IS_MATCH_IPV6_NH(C) \
315 (strmatch(C, "frr-bgp-route-map:ipv6-nexthop"))
317 /* Route-map set actions */
318 #define IS_SET_IPv4_NH(A) \
319 (strmatch(A, "frr-route-map:ipv4-next-hop"))
320 #define IS_SET_IPv6_NH(A) \
321 (strmatch(A, "frr-route-map:ipv6-next-hop"))
322 #define IS_SET_METRIC(A) \
323 (strmatch(A, "frr-route-map:set-metric"))
324 #define IS_SET_TAG(A) (strmatch(A, "frr-route-map:set-tag"))
325 #define IS_SET_SR_TE_COLOR(A) \
326 (strmatch(A, "frr-route-map:set-sr-te-color"))
327 /* Zebra route-map set actions */
328 #define IS_SET_SRC(A) \
329 (strmatch(A, "frr-zebra-route-map:src-address"))
330 /* OSPF route-map set actions */
331 #define IS_SET_METRIC_TYPE(A) \
332 (strmatch(A, "frr-ospf-route-map:metric-type"))
333 #define IS_SET_FORWARDING_ADDR(A) \
334 (strmatch(A, "frr-ospf6-route-map:forwarding-address"))
335 /* BGP route-map_set actions */
336 #define IS_SET_WEIGHT(A) \
337 (strmatch(A, "frr-bgp-route-map:weight"))
338 #define IS_SET_TABLE(A) (strmatch(A, "frr-bgp-route-map:table"))
339 #define IS_SET_LOCAL_PREF(A) \
340 (strmatch(A, "frr-bgp-route-map:set-local-preference"))
341 #define IS_SET_LABEL_INDEX(A) \
342 (strmatch(A, "frr-bgp-route-map:label-index"))
343 #define IS_SET_DISTANCE(A) \
344 (strmatch(A, "frr-bgp-route-map:distance"))
345 #define IS_SET_ORIGIN(A) \
346 (strmatch(A, "frr-bgp-route-map:set-origin"))
347 #define IS_SET_ATOMIC_AGGREGATE(A) \
348 (strmatch(A, "frr-bgp-route-map:atomic-aggregate"))
349 #define IS_SET_ORIGINATOR_ID(A) \
350 (strmatch(A, "frr-bgp-route-map:originator-id"))
351 #define IS_SET_COMM_LIST_DEL(A) \
352 (strmatch(A, "frr-bgp-route-map:comm-list-delete"))
353 #define IS_SET_LCOMM_LIST_DEL(A) \
354 (strmatch(A, "frr-bgp-route-map:large-comm-list-delete"))
355 #define IS_SET_LCOMMUNITY(A) \
356 (strmatch(A, "frr-bgp-route-map:set-large-community"))
357 #define IS_SET_COMMUNITY(A) \
358 (strmatch(A, "frr-bgp-route-map:set-community"))
359 #define IS_SET_EXTCOMMUNITY_NONE(A) \
360 (strmatch(A, "frr-bgp-route-map:set-extcommunity-none"))
361 #define IS_SET_EXTCOMMUNITY_RT(A) \
362 (strmatch(A, "frr-bgp-route-map:set-extcommunity-rt"))
363 #define IS_SET_EXTCOMMUNITY_SOO(A) \
364 (strmatch(A, "frr-bgp-route-map:set-extcommunity-soo"))
365 #define IS_SET_EXTCOMMUNITY_LB(A) \
366 (strmatch(A, "frr-bgp-route-map:set-extcommunity-lb"))
367 #define IS_SET_AGGREGATOR(A) \
368 (strmatch(A, "frr-bgp-route-map:aggregator"))
369 #define IS_SET_AS_PREPEND(A) \
370 (strmatch(A, "frr-bgp-route-map:as-path-prepend"))
371 #define IS_SET_AS_EXCLUDE(A) \
372 (strmatch(A, "frr-bgp-route-map:as-path-exclude"))
373 #define IS_SET_IPV6_NH_GLOBAL(A) \
374 (strmatch(A, "frr-bgp-route-map:ipv6-nexthop-global"))
375 #define IS_SET_IPV6_VPN_NH(A) \
376 (strmatch(A, "frr-bgp-route-map:ipv6-vpn-address"))
377 #define IS_SET_IPV6_PEER_ADDR(A) \
378 (strmatch(A, "frr-bgp-route-map:ipv6-peer-address"))
379 #define IS_SET_IPV6_PREFER_GLOBAL(A) \
380 (strmatch(A, "frr-bgp-route-map:ipv6-prefer-global"))
381 #define IS_SET_IPV4_VPN_NH(A) \
382 (strmatch(A, "frr-bgp-route-map:ipv4-vpn-address"))
383 #define IS_SET_BGP_IPV4_NH(A) \
384 (strmatch(A, "frr-bgp-route-map:set-ipv4-nexthop"))
385 #define IS_SET_BGP_EVPN_GATEWAY_IP_IPV4(A) \
386 (strmatch(A, "frr-bgp-route-map:set-evpn-gateway-ip-ipv4"))
387 #define IS_SET_BGP_EVPN_GATEWAY_IP_IPV6(A) \
388 (strmatch(A, "frr-bgp-route-map:set-evpn-gateway-ip-ipv6"))
390 enum ecommunity_lb_type
{
392 CUMULATIVE_BANDWIDTH
,
397 extern void route_map_init(void);
400 * This should only be called on shutdown
401 * Additionally this function sets the hooks to NULL
402 * before any processing is done.
404 extern void route_map_finish(void);
406 /* Add match statement to route map. */
407 extern enum rmap_compile_rets
route_map_add_match(struct route_map_index
*index
,
408 const char *match_name
,
409 const char *match_arg
,
410 route_map_event_t type
);
412 /* Delete specified route match rule. */
413 extern enum rmap_compile_rets
414 route_map_delete_match(struct route_map_index
*index
,
415 const char *match_name
, const char *match_arg
,
416 route_map_event_t type
);
418 extern const char *route_map_get_match_arg(struct route_map_index
*index
,
419 const char *match_name
);
421 /* Add route-map set statement to the route map. */
422 extern enum rmap_compile_rets
route_map_add_set(struct route_map_index
*index
,
423 const char *set_name
,
424 const char *set_arg
);
426 /* Delete route map set rule. */
427 extern enum rmap_compile_rets
428 route_map_delete_set(struct route_map_index
*index
,
429 const char *set_name
, const char *set_arg
);
431 /* struct route_map_rule_cmd is kept const in order to not have writable
432 * function pointers (which is a security benefit.) Hence, below struct is
433 * used as proxy for hashing these for by-name lookup.
436 PREDECL_HASH(rmap_cmd_name
);
438 struct route_map_rule_cmd_proxy
{
439 struct rmap_cmd_name_item itm
;
440 const struct route_map_rule_cmd
*cmd
;
443 /* ... and just automatically create a proxy struct for each call location
444 * to route_map_install_{match,set} to avoid unnecessarily added boilerplate
445 * for each route-map user
448 #define route_map_install_match(c) \
450 static struct route_map_rule_cmd_proxy proxy = {.cmd = c}; \
451 _route_map_install_match(&proxy); \
454 #define route_map_install_set(c) \
456 static struct route_map_rule_cmd_proxy proxy = {.cmd = c}; \
457 _route_map_install_set(&proxy); \
460 /* Install rule command to the match list. */
461 extern void _route_map_install_match(struct route_map_rule_cmd_proxy
*proxy
);
464 * Install rule command to the set list.
466 * When installing a particular item, Allow a difference of handling
467 * of bad cli inputted(return NULL) -vs- this particular daemon cannot use
468 * this form of the command(return a pointer and handle it appropriately
469 * in the apply command). See 'set metric' command
470 * as it is handled in ripd/ripngd and ospfd.
472 extern void _route_map_install_set(struct route_map_rule_cmd_proxy
*proxy
);
474 /* Lookup route map by name. */
475 extern struct route_map
*route_map_lookup_by_name(const char *name
);
477 /* Simple helper to warn if route-map does not exist. */
478 struct route_map
*route_map_lookup_warn_noexist(struct vty
*vty
, const char *name
);
480 /* Apply route map to the object. */
481 extern route_map_result_t
route_map_apply_ext(struct route_map
*map
,
482 const struct prefix
*prefix
,
485 #define route_map_apply(map, prefix, object) \
486 route_map_apply_ext(map, prefix, object, object)
488 extern void route_map_add_hook(void (*func
)(const char *));
489 extern void route_map_delete_hook(void (*func
)(const char *));
492 * This is the callback for when something has changed about a
493 * route-map. The interested parties can register to receive
496 * name - Is the name of the changed route-map
498 extern void route_map_event_hook(void (*func
)(const char *name
));
499 extern int route_map_mark_updated(const char *name
);
500 extern void route_map_walk_update_list(void (*update_fn
)(char *name
));
501 extern void route_map_upd8_dependency(route_map_event_t type
, const char *arg
,
502 const char *rmap_name
);
503 extern void route_map_notify_dependencies(const char *affected_name
,
504 route_map_event_t event
);
506 route_map_notify_pentry_dependencies(const char *affected_name
,
507 struct prefix_list_entry
*pentry
,
508 route_map_event_t event
);
509 extern int generic_match_add(struct route_map_index
*index
,
510 const char *command
, const char *arg
,
511 route_map_event_t type
,
512 char *errmsg
, size_t errmsg_len
);
513 extern int generic_match_delete(struct route_map_index
*index
,
514 const char *command
, const char *arg
,
515 route_map_event_t type
,
516 char *errmsg
, size_t errmsg_len
);
518 extern int generic_set_add(struct route_map_index
*index
,
519 const char *command
, const char *arg
,
520 char *errmsg
, size_t errmsg_len
);
521 extern int generic_set_delete(struct route_map_index
*index
,
522 const char *command
, const char *arg
,
523 char *errmsg
, size_t errmsg_len
);
526 /* match interface */
527 extern void route_map_match_interface_hook(int (*func
)(
528 struct route_map_index
*index
, const char *command
,
529 const char *arg
, route_map_event_t type
,
530 char *errmsg
, size_t errmsg_len
));
531 /* no match interface */
532 extern void route_map_no_match_interface_hook(int (*func
)(
533 struct route_map_index
*index
, const char *command
,
534 const char *arg
, route_map_event_t type
,
535 char *errmsg
, size_t errmsg_len
));
536 /* match ip address */
537 extern void route_map_match_ip_address_hook(int (*func
)(
538 struct route_map_index
*index
, const char *command
,
539 const char *arg
, route_map_event_t type
,
540 char *errmsg
, size_t errmsg_len
));
541 /* no match ip address */
542 extern void route_map_no_match_ip_address_hook(int (*func
)(
543 struct route_map_index
*index
, const char *command
,
544 const char *arg
, route_map_event_t type
,
545 char *errmsg
, size_t errmsg_len
));
546 /* match ip address prefix list */
547 extern void route_map_match_ip_address_prefix_list_hook(int (*func
)(
548 struct route_map_index
*index
, const char *command
,
549 const char *arg
, route_map_event_t type
,
550 char *errmsg
, size_t errmsg_len
));
551 /* no match ip address prefix list */
552 extern void route_map_no_match_ip_address_prefix_list_hook(int (*func
)(
553 struct route_map_index
*index
, const char *command
,
554 const char *arg
, route_map_event_t type
,
555 char *errmsg
, size_t errmsg_len
));
556 /* match ip next hop */
557 extern void route_map_match_ip_next_hop_hook(int (*func
)(
558 struct route_map_index
*index
, const char *command
,
559 const char *arg
, route_map_event_t type
,
560 char *errmsg
, size_t errmsg_len
));
561 /* no match ip next hop */
562 extern void route_map_no_match_ip_next_hop_hook(int (*func
)(
563 struct route_map_index
*index
, const char *command
, const char *arg
,
564 route_map_event_t type
, char *errmsg
, size_t errmsg_len
));
565 /* match ipv6 next hop */
566 extern void route_map_match_ipv6_next_hop_hook(int (*func
)(
567 struct route_map_index
*index
, const char *command
, const char *arg
,
568 route_map_event_t type
, char *errmsg
, size_t errmsg_len
));
569 /* no match ipv6 next hop */
570 extern void route_map_no_match_ipv6_next_hop_hook(int (*func
)(
571 struct route_map_index
*index
, const char *command
, const char *arg
,
572 route_map_event_t type
, char *errmsg
, size_t errmsg_len
));
573 /* match ip next hop prefix list */
574 extern void route_map_match_ip_next_hop_prefix_list_hook(int (*func
)(
575 struct route_map_index
*index
, const char *command
,
576 const char *arg
, route_map_event_t type
,
577 char *errmsg
, size_t errmsg_len
));
578 /* no match ip next hop prefix list */
579 extern void route_map_no_match_ip_next_hop_prefix_list_hook(int (*func
)(
580 struct route_map_index
*index
, const char *command
,
581 const char *arg
, route_map_event_t type
,
582 char *errmsg
, size_t errmsg_len
));
583 /* match ip next hop type */
584 extern void route_map_match_ip_next_hop_type_hook(int (*func
)(
585 struct route_map_index
*index
, const char *command
,
586 const char *arg
, route_map_event_t type
,
587 char *errmsg
, size_t errmsg_len
));
588 /* no match ip next hop type */
589 extern void route_map_no_match_ip_next_hop_type_hook(int (*func
)(
590 struct route_map_index
*index
, const char *command
,
591 const char *arg
, route_map_event_t type
,
592 char *errmsg
, size_t errmsg_len
));
593 /* match ipv6 address */
594 extern void route_map_match_ipv6_address_hook(int (*func
)(
595 struct route_map_index
*index
, const char *command
,
596 const char *arg
, route_map_event_t type
,
597 char *errmsg
, size_t errmsg_len
));
598 /* no match ipv6 address */
599 extern void route_map_no_match_ipv6_address_hook(int (*func
)(
600 struct route_map_index
*index
, const char *command
,
601 const char *arg
, route_map_event_t type
,
602 char *errmsg
, size_t errmsg_len
));
603 /* match ipv6 address prefix list */
604 extern void route_map_match_ipv6_address_prefix_list_hook(int (*func
)(
605 struct route_map_index
*index
, const char *command
,
606 const char *arg
, route_map_event_t type
,
607 char *errmsg
, size_t errmsg_len
));
608 /* no match ipv6 address prefix list */
609 extern void route_map_no_match_ipv6_address_prefix_list_hook(int (*func
)(
610 struct route_map_index
*index
, const char *command
,
611 const char *arg
, route_map_event_t type
,
612 char *errmsg
, size_t errmsg_len
));
613 /* match ipv6 next-hop type */
614 extern void route_map_match_ipv6_next_hop_type_hook(int (*func
)(
615 struct route_map_index
*index
, const char *command
,
616 const char *arg
, route_map_event_t type
,
617 char *errmsg
, size_t errmsg_len
));
618 /* no match ipv6 next-hop type */
619 extern void route_map_no_match_ipv6_next_hop_type_hook(int (*func
)(
620 struct route_map_index
*index
, const char *command
,
621 const char *arg
, route_map_event_t type
,
622 char *errmsg
, size_t errmsg_len
));
623 /* match ipv6 next-hop prefix-list */
624 extern void route_map_match_ipv6_next_hop_prefix_list_hook(int (*func
)(
625 struct route_map_index
*index
, const char *command
, const char *arg
,
626 route_map_event_t type
, char *errmsg
, size_t errmsg_len
));
627 /* no match ipv6 next-hop prefix-list */
628 extern void route_map_no_match_ipv6_next_hop_prefix_list_hook(int (*func
)(
629 struct route_map_index
*index
, const char *command
, const char *arg
,
630 route_map_event_t type
, char *errmsg
, size_t errmsg_len
));
632 extern void route_map_match_metric_hook(int (*func
)(
633 struct route_map_index
*index
, const char *command
,
634 const char *arg
, route_map_event_t type
,
635 char *errmsg
, size_t errmsg_len
));
636 /* no match metric */
637 extern void route_map_no_match_metric_hook(int (*func
)(
638 struct route_map_index
*index
, const char *command
,
639 const char *arg
, route_map_event_t type
,
640 char *errmsg
, size_t errmsg_len
));
642 extern void route_map_match_tag_hook(int (*func
)(
643 struct route_map_index
*index
, const char *command
,
644 const char *arg
, route_map_event_t type
,
645 char *errmsg
, size_t errmsg_len
));
647 extern void route_map_no_match_tag_hook(int (*func
)(
648 struct route_map_index
*index
, const char *command
,
649 const char *arg
, route_map_event_t type
,
650 char *errmsg
, size_t errmsg_len
));
651 /* set sr-te color */
652 extern void route_map_set_srte_color_hook(
653 int (*func
)(struct route_map_index
*index
,
654 const char *command
, const char *arg
,
655 char *errmsg
, size_t errmsg_len
));
656 /* no set sr-te color */
657 extern void route_map_no_set_srte_color_hook(
658 int (*func
)(struct route_map_index
*index
,
659 const char *command
, const char *arg
,
660 char *errmsg
, size_t errmsg_len
));
662 extern void route_map_set_ip_nexthop_hook(
663 int (*func
)(struct route_map_index
*index
,
664 const char *command
, const char *arg
,
665 char *errmsg
, size_t errmsg_len
));
666 /* no set ip nexthop */
667 extern void route_map_no_set_ip_nexthop_hook(
668 int (*func
)(struct route_map_index
*index
,
669 const char *command
, const char *arg
,
670 char *errmsg
, size_t errmsg_len
));
671 /* set ipv6 nexthop local */
672 extern void route_map_set_ipv6_nexthop_local_hook(
673 int (*func
)(struct route_map_index
*index
,
674 const char *command
, const char *arg
,
675 char *errmsg
, size_t errmsg_len
));
676 /* no set ipv6 nexthop local */
677 extern void route_map_no_set_ipv6_nexthop_local_hook(
678 int (*func
)(struct route_map_index
*index
,
679 const char *command
, const char *arg
,
680 char *errmsg
, size_t errmsg_len
));
682 extern void route_map_set_metric_hook(int (*func
)(struct route_map_index
*index
,
688 extern void route_map_no_set_metric_hook(
689 int (*func
)(struct route_map_index
*index
,
690 const char *command
, const char *arg
,
691 char *errmsg
, size_t errmsg_len
));
693 extern void route_map_set_tag_hook(int (*func
)(struct route_map_index
*index
,
699 extern void route_map_no_set_tag_hook(int (*func
)(struct route_map_index
*index
,
705 extern void *route_map_rule_tag_compile(const char *arg
);
706 extern void route_map_rule_tag_free(void *rule
);
708 /* Increment the route-map used counter */
709 extern void route_map_counter_increment(struct route_map
*map
);
711 /* Decrement the route-map used counter */
712 extern void route_map_counter_decrement(struct route_map
*map
);
714 /* Route map hooks data structure. */
715 struct route_map_match_set_hooks
{
716 /* match interface */
717 int (*match_interface
)(struct route_map_index
*index
,
718 const char *command
, const char *arg
,
719 route_map_event_t type
,
720 char *errmsg
, size_t errmsg_len
);
722 /* no match interface */
723 int (*no_match_interface
)(struct route_map_index
*index
,
724 const char *command
, const char *arg
,
725 route_map_event_t type
,
726 char *errmsg
, size_t errmsg_len
);
728 /* match ip address */
729 int (*match_ip_address
)(struct route_map_index
*index
,
730 const char *command
, const char *arg
,
731 route_map_event_t type
,
732 char *errmsg
, size_t errmsg_len
);
734 /* no match ip address */
735 int (*no_match_ip_address
)(struct route_map_index
*index
,
736 const char *command
, const char *arg
,
737 route_map_event_t type
,
738 char *errmsg
, size_t errmsg_len
);
740 /* match ip address prefix list */
741 int (*match_ip_address_prefix_list
)(struct route_map_index
*index
,
744 route_map_event_t type
,
745 char *errmsg
, size_t errmsg_len
);
747 /* no match ip address prefix list */
748 int (*no_match_ip_address_prefix_list
)(struct route_map_index
*index
,
751 route_map_event_t type
,
752 char *errmsg
, size_t errmsg_len
);
754 /* match ip next hop */
755 int (*match_ip_next_hop
)(struct route_map_index
*index
,
756 const char *command
, const char *arg
,
757 route_map_event_t type
,
758 char *errmsg
, size_t errmsg_len
);
760 /* no match ip next hop */
761 int (*no_match_ip_next_hop
)(struct route_map_index
*index
,
762 const char *command
, const char *arg
,
763 route_map_event_t type
,
764 char *errmsg
, size_t errmsg_len
);
766 /* match ipv6 next hop */
767 int (*match_ipv6_next_hop
)(struct route_map_index
*index
,
768 const char *command
, const char *arg
,
769 route_map_event_t type
, char *errmsg
,
772 /* no match ipv6 next hop */
773 int (*no_match_ipv6_next_hop
)(struct route_map_index
*index
,
774 const char *command
, const char *arg
,
775 route_map_event_t type
, char *errmsg
,
778 /* match ipv6 next hop prefix-list */
779 int (*match_ipv6_next_hop_prefix_list
)(struct route_map_index
*index
,
782 route_map_event_t type
,
783 char *errmsg
, size_t errmsg_len
);
785 /* no match ipv6 next-hop prefix-list */
786 int (*no_match_ipv6_next_hop_prefix_list
)(struct route_map_index
*index
,
789 route_map_event_t type
,
793 /* match ip next hop prefix list */
794 int (*match_ip_next_hop_prefix_list
)(struct route_map_index
*index
,
797 route_map_event_t type
,
798 char *errmsg
, size_t errmsg_len
);
800 /* no match ip next hop prefix list */
801 int (*no_match_ip_next_hop_prefix_list
)(struct route_map_index
*index
,
804 route_map_event_t type
,
808 /* match ip next-hop type */
809 int (*match_ip_next_hop_type
)(struct route_map_index
*index
,
812 route_map_event_t type
,
816 /* no match ip next-hop type */
817 int (*no_match_ip_next_hop_type
)(struct route_map_index
*index
,
820 route_map_event_t type
,
824 /* match ipv6 address */
825 int (*match_ipv6_address
)(struct route_map_index
*index
,
826 const char *command
, const char *arg
,
827 route_map_event_t type
,
828 char *errmsg
, size_t errmsg_len
);
830 /* no match ipv6 address */
831 int (*no_match_ipv6_address
)(struct route_map_index
*index
,
832 const char *command
, const char *arg
,
833 route_map_event_t type
,
834 char *errmsg
, size_t errmsg_len
);
837 /* match ipv6 address prefix list */
838 int (*match_ipv6_address_prefix_list
)(struct route_map_index
*index
,
841 route_map_event_t type
,
842 char *errmsg
, size_t errmsg_len
);
844 /* no match ipv6 address prefix list */
845 int (*no_match_ipv6_address_prefix_list
)(struct route_map_index
*index
,
848 route_map_event_t type
,
852 /* match ipv6 next-hop type */
853 int (*match_ipv6_next_hop_type
)(struct route_map_index
*index
,
856 route_map_event_t type
,
857 char *errmsg
, size_t errmsg_len
);
859 /* no match ipv6 next-hop type */
860 int (*no_match_ipv6_next_hop_type
)(struct route_map_index
*index
,
861 const char *command
, const char *arg
,
862 route_map_event_t type
,
863 char *errmsg
, size_t errmsg_len
);
866 int (*match_metric
)(struct route_map_index
*index
,
867 const char *command
, const char *arg
,
868 route_map_event_t type
,
869 char *errmsg
, size_t errmsg_len
);
871 /* no match metric */
872 int (*no_match_metric
)(struct route_map_index
*index
,
873 const char *command
, const char *arg
,
874 route_map_event_t type
,
875 char *errmsg
, size_t errmsg_len
);
878 int (*match_tag
)(struct route_map_index
*index
,
879 const char *command
, const char *arg
,
880 route_map_event_t type
,
881 char *errmsg
, size_t errmsg_len
);
884 int (*no_match_tag
)(struct route_map_index
*index
,
885 const char *command
, const char *arg
,
886 route_map_event_t type
,
887 char *errmsg
, size_t errmsg_len
);
889 /* set sr-te color */
890 int (*set_srte_color
)(struct route_map_index
*index
,
891 const char *command
, const char *arg
,
892 char *errmsg
, size_t errmsg_len
);
894 /* no set sr-te color */
895 int (*no_set_srte_color
)(struct route_map_index
*index
,
896 const char *command
, const char *arg
,
897 char *errmsg
, size_t errmsg_len
);
900 int (*set_ip_nexthop
)(struct route_map_index
*index
,
901 const char *command
, const char *arg
,
902 char *errmsg
, size_t errmsg_len
);
904 /* no set ip nexthop */
905 int (*no_set_ip_nexthop
)(struct route_map_index
*index
,
906 const char *command
, const char *arg
,
907 char *errmsg
, size_t errmsg_len
);
909 /* set ipv6 nexthop local */
910 int (*set_ipv6_nexthop_local
)(struct route_map_index
*index
,
911 const char *command
, const char *arg
,
912 char *errmsg
, size_t errmsg_len
);
914 /* no set ipv6 nexthop local */
915 int (*no_set_ipv6_nexthop_local
)(struct route_map_index
*index
,
916 const char *command
, const char *arg
,
917 char *errmsg
, size_t errmsg_len
);
920 int (*set_metric
)(struct route_map_index
*index
,
921 const char *command
, const char *arg
,
922 char *errmsg
, size_t errmsg_len
);
925 int (*no_set_metric
)(struct route_map_index
*index
,
926 const char *command
, const char *arg
,
927 char *errmsg
, size_t errmsg_len
);
930 int (*set_tag
)(struct route_map_index
*index
,
931 const char *command
, const char *arg
,
932 char *errmsg
, size_t errmsg_len
);
935 int (*no_set_tag
)(struct route_map_index
*index
,
936 const char *command
, const char *arg
,
937 char *errmsg
, size_t errmsg_len
);
940 extern struct route_map_match_set_hooks rmap_match_set_hook
;
942 /* Making route map list. */
943 struct route_map_list
{
944 struct route_map
*head
;
945 struct route_map
*tail
;
947 void (*add_hook
)(const char *);
948 void (*delete_hook
)(const char *);
949 void (*event_hook
)(const char *);
952 extern struct route_map_list route_map_master
;
954 extern struct route_map
*route_map_get(const char *name
);
955 extern void route_map_delete(struct route_map
*map
);
956 extern struct route_map_index
*route_map_index_get(struct route_map
*map
,
957 enum route_map_type type
,
959 extern void route_map_index_delete(struct route_map_index
*index
, int notify
);
961 /* routemap_northbound.c */
962 typedef int (*routemap_match_hook_fun
)(struct route_map_index
*rmi
,
963 const char *command
, const char *arg
,
964 route_map_event_t event
,
965 char *errmsg
, size_t errmsg_len
);
966 typedef int (*routemap_set_hook_fun
)(struct route_map_index
*rmi
,
967 const char *command
, const char *arg
,
968 char *errmsg
, size_t errmsg_len
);
969 struct routemap_hook_context
{
970 struct route_map_index
*rhc_rmi
;
971 const char *rhc_rule
;
972 route_map_event_t rhc_event
;
973 routemap_set_hook_fun rhc_shook
;
974 routemap_match_hook_fun rhc_mhook
;
975 TAILQ_ENTRY(routemap_hook_context
) rhc_entry
;
978 int lib_route_map_entry_match_destroy(struct nb_cb_destroy_args
*args
);
979 int lib_route_map_entry_set_destroy(struct nb_cb_destroy_args
*args
);
981 struct routemap_hook_context
*
982 routemap_hook_context_insert(struct route_map_index
*rmi
);
983 void routemap_hook_context_free(struct routemap_hook_context
*rhc
);
985 extern const struct frr_yang_module_info frr_route_map_info
;
988 extern int route_map_instance_cmp(const struct lyd_node
*dnode1
,
989 const struct lyd_node
*dnode2
);
990 extern void route_map_instance_show(struct vty
*vty
,
991 const struct lyd_node
*dnode
,
993 extern void route_map_instance_show_end(struct vty
*vty
,
994 const struct lyd_node
*dnode
);
995 extern void route_map_condition_show(struct vty
*vty
,
996 const struct lyd_node
*dnode
,
998 extern void route_map_action_show(struct vty
*vty
, const struct lyd_node
*dnode
,
1000 extern void route_map_exit_policy_show(struct vty
*vty
,
1001 const struct lyd_node
*dnode
,
1002 bool show_defaults
);
1003 extern void route_map_call_show(struct vty
*vty
, const struct lyd_node
*dnode
,
1004 bool show_defaults
);
1005 extern void route_map_description_show(struct vty
*vty
,
1006 const struct lyd_node
*dnode
,
1007 bool show_defaults
);
1008 extern void route_map_optimization_disabled_show(struct vty
*vty
,
1009 const struct lyd_node
*dnode
,
1010 bool show_defaults
);
1011 extern void route_map_cli_init(void);
1017 #endif /* _ZEBRA_ROUTEMAP_H */