]> git.proxmox.com Git - mirror_frr.git/blob - lib/routemap.h
Merge pull request #13649 from donaldsharp/unlock_the_node_or_else
[mirror_frr.git] / lib / routemap.h
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* Route map function.
3 * Copyright (C) 1998 Kunihiro Ishiguro
4 */
5
6 #ifndef _ZEBRA_ROUTEMAP_H
7 #define _ZEBRA_ROUTEMAP_H
8
9 #include "typesafe.h"
10 #include "prefix.h"
11 #include "memory.h"
12 #include "qobj.h"
13 #include "vty.h"
14 #include "lib/plist.h"
15 #include "lib/plist_int.h"
16
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20
21 DECLARE_MTYPE(ROUTE_MAP_NAME);
22 DECLARE_MTYPE(ROUTE_MAP_RULE);
23 DECLARE_MTYPE(ROUTE_MAP_COMPILED);
24
25 #define DEBUG_ROUTEMAP 0x01
26 #define DEBUG_ROUTEMAP_DETAIL 0x02
27 extern uint32_t rmap_debug;
28
29 /* Route map's type. */
30 enum route_map_type { RMAP_PERMIT, RMAP_DENY, RMAP_ANY };
31
32 typedef enum {
33 RMAP_DENYMATCH,
34 RMAP_PERMITMATCH
35 } route_map_result_t;
36
37 /*
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
46 */
47 enum route_map_cmd_result_t {
48 /*
49 * route-map match cmd results
50 */
51 RMAP_MATCH,
52 RMAP_NOMATCH,
53 RMAP_NOOP,
54 /*
55 * route-map set cmd results
56 */
57 RMAP_OKAY,
58 RMAP_ERROR
59 };
60
61 typedef enum { RMAP_EXIT, RMAP_GOTO, RMAP_NEXT } route_map_end_t;
62
63 typedef enum {
64 RMAP_EVENT_SET_ADDED,
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,
86 } route_map_event_t;
87
88 /* Depth limit in RMAP recursion using RMAP_CALL. */
89 #define RMAP_RECURSION_LIMIT 10
90
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) */
94 const char *str;
95
96 /* Function for value set or match. */
97 enum route_map_cmd_result_t (*func_apply)(void *rule,
98 const struct prefix *prefix,
99 void *object);
100
101 /* Compile argument and return result as void *. */
102 void *(*func_compile)(const char *);
103
104 /* Free allocated value by func_compile (). */
105 void (*func_free)(void *);
106
107 /** To get the rule key after Compilation **/
108 void *(*func_get_rmap_rule_key)(void *val);
109 };
110
111 /* Route map apply error. */
112 enum rmap_compile_rets {
113 RMAP_COMPILE_SUCCESS,
114
115 /* Route map rule is missing. */
116 RMAP_RULE_MISSING,
117
118 /* Route map rule can't compile */
119 RMAP_COMPILE_ERROR,
120
121 };
122
123 /* Route map rule. This rule has both `match' rule and `set' rule. */
124 struct route_map_rule {
125 /* Rule type. */
126 const struct route_map_rule_cmd *cmd;
127
128 /* For pretty printing. */
129 char *rule_str;
130
131 /* Pre-compiled match rule. */
132 void *value;
133
134 /* Linked list. */
135 struct route_map_rule *next;
136 struct route_map_rule *prev;
137 };
138
139 /* Route map rule list. */
140 struct route_map_rule_list {
141 struct route_map_rule *head;
142 struct route_map_rule *tail;
143 };
144
145 /* Forward struct declaration: the complete can be found later this file. */
146 struct routemap_hook_context;
147
148 /* Route map index structure. */
149 struct route_map_index {
150 struct route_map *map;
151 char *description;
152
153 /* Preference of this route map rule. */
154 int pref;
155
156 /* Route map type permit or deny. */
157 enum route_map_type type;
158
159 /* Do we follow old rules, or hop forward? */
160 route_map_end_t exitpolicy;
161
162 /* If we're using "GOTO", to where do we go? */
163 int nextpref;
164
165 /* If we're using "CALL", to which route-map do ew go? */
166 char *nextrm;
167
168 /* Matching rule list. */
169 struct route_map_rule_list match_list;
170 struct route_map_rule_list set_list;
171
172 /* Make linked list. */
173 struct route_map_index *next;
174 struct route_map_index *prev;
175
176 /* Keep track how many times we've try to apply */
177 uint64_t applied;
178 uint64_t applied_clear;
179
180 /* List of match/sets contexts. */
181 TAILQ_HEAD(, routemap_hook_context) rhclist;
182
183 QOBJ_FIELDS;
184 };
185 DECLARE_QOBJ_TYPE(route_map_index);
186
187 /* route map maximum length. Not strictly the maximum xpath length but cannot be
188 * greater
189 */
190 #define RMAP_NAME_MAXLEN XPATH_MAXLEN
191
192 /* Route map list structure. */
193 struct route_map {
194 /* Name of route map. */
195 char *name;
196
197 /* Route map's rule. */
198 struct route_map_index *head;
199 struct route_map_index *tail;
200
201 /* Make linked list. */
202 struct route_map *next;
203 struct route_map *prev;
204
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;
209
210 /* How many times have we applied this route-map */
211 uint64_t applied;
212 uint64_t applied_clear;
213
214 /* Counter to track active usage of this route-map */
215 uint16_t use_count;
216
217 /* Tables to maintain IPv4 and IPv6 prefixes from
218 * the prefix-list match clause.
219 */
220 struct route_table *ipv4_prefix_table;
221 struct route_table *ipv6_prefix_table;
222
223 QOBJ_FIELDS;
224 };
225 DECLARE_QOBJ_TYPE(route_map);
226
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"))
309
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"))
390
391 enum ecommunity_lb_type {
392 EXPLICIT_BANDWIDTH,
393 CUMULATIVE_BANDWIDTH,
394 COMPUTED_BANDWIDTH
395 };
396
397 /* Prototypes. */
398 extern void route_map_init(void);
399
400 /*
401 * This should only be called on shutdown
402 * Additionally this function sets the hooks to NULL
403 * before any processing is done.
404 */
405 extern void route_map_finish(void);
406
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);
412
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);
418
419 extern const char *route_map_get_match_arg(struct route_map_index *index,
420 const char *match_name);
421
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);
426
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);
431
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.
435 */
436
437 PREDECL_HASH(rmap_cmd_name);
438
439 struct route_map_rule_cmd_proxy {
440 struct rmap_cmd_name_item itm;
441 const struct route_map_rule_cmd *cmd;
442 };
443
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
447 */
448
449 #define route_map_install_match(c) \
450 do { \
451 static struct route_map_rule_cmd_proxy proxy = {.cmd = c}; \
452 _route_map_install_match(&proxy); \
453 } while (0)
454
455 #define route_map_install_set(c) \
456 do { \
457 static struct route_map_rule_cmd_proxy proxy = {.cmd = c}; \
458 _route_map_install_set(&proxy); \
459 } while (0)
460
461 /* Install rule command to the match list. */
462 extern void _route_map_install_match(struct route_map_rule_cmd_proxy *proxy);
463
464 /*
465 * Install rule command to the set list.
466 *
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.
472 */
473 extern void _route_map_install_set(struct route_map_rule_cmd_proxy *proxy);
474
475 /* Lookup route map by name. */
476 extern struct route_map *route_map_lookup_by_name(const char *name);
477
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);
480
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,
484 void *match_object,
485 void *set_object, int *pref);
486 #define route_map_apply(map, prefix, object) \
487 route_map_apply_ext(map, prefix, object, object, NULL)
488
489 extern void route_map_add_hook(void (*func)(const char *));
490 extern void route_map_delete_hook(void (*func)(const char *));
491
492 /*
493 * This is the callback for when something has changed about a
494 * route-map. The interested parties can register to receive
495 * this data.
496 *
497 * name - Is the name of the changed route-map
498 */
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);
506 extern void
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);
518
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);
525
526
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));
632 /* match metric */
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));
642 /* match tag */
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));
647 /* no match tag */
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));
662 /* set ip nexthop */
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));
682 /* set metric */
683 extern void route_map_set_metric_hook(int (*func)(struct route_map_index *index,
684 const char *command,
685 const char *arg,
686 char *errmsg,
687 size_t errmsg_len));
688 /* no set metric */
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));
693 /* set metric */
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));
697 /* no set metric */
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));
701 /* set metric */
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));
705 /* no set metric */
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));
709 /* set tag */
710 extern void route_map_set_tag_hook(int (*func)(struct route_map_index *index,
711 const char *command,
712 const char *arg,
713 char *errmsg,
714 size_t errmsg_len));
715 /* no set tag */
716 extern void route_map_no_set_tag_hook(int (*func)(struct route_map_index *index,
717 const char *command,
718 const char *arg,
719 char *errmsg,
720 size_t errmsg_len));
721
722 extern void *route_map_rule_tag_compile(const char *arg);
723 extern void route_map_rule_tag_free(void *rule);
724
725 /* Increment the route-map used counter */
726 extern void route_map_counter_increment(struct route_map *map);
727
728 /* Decrement the route-map used counter */
729 extern void route_map_counter_decrement(struct route_map *map);
730
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);
738
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);
744
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);
750
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);
756
757 /* match ip address prefix list */
758 int (*match_ip_address_prefix_list)(struct route_map_index *index,
759 const char *command,
760 const char *arg,
761 route_map_event_t type,
762 char *errmsg, size_t errmsg_len);
763
764 /* no match ip address prefix list */
765 int (*no_match_ip_address_prefix_list)(struct route_map_index *index,
766 const char *command,
767 const char *arg,
768 route_map_event_t type,
769 char *errmsg, size_t errmsg_len);
770
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);
776
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);
782
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,
787 size_t errmsg_len);
788
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,
793 size_t errmsg_len);
794
795 /* match ipv6 next hop prefix-list */
796 int (*match_ipv6_next_hop_prefix_list)(struct route_map_index *index,
797 const char *command,
798 const char *arg,
799 route_map_event_t type,
800 char *errmsg, size_t errmsg_len);
801
802 /* no match ipv6 next-hop prefix-list */
803 int (*no_match_ipv6_next_hop_prefix_list)(struct route_map_index *index,
804 const char *command,
805 const char *arg,
806 route_map_event_t type,
807 char *errmsg,
808 size_t errmsg_len);
809
810 /* match ip next hop prefix list */
811 int (*match_ip_next_hop_prefix_list)(struct route_map_index *index,
812 const char *command,
813 const char *arg,
814 route_map_event_t type,
815 char *errmsg, size_t errmsg_len);
816
817 /* no match ip next hop prefix list */
818 int (*no_match_ip_next_hop_prefix_list)(struct route_map_index *index,
819 const char *command,
820 const char *arg,
821 route_map_event_t type,
822 char *errmsg,
823 size_t errmsg_len);
824
825 /* match ip next-hop type */
826 int (*match_ip_next_hop_type)(struct route_map_index *index,
827 const char *command,
828 const char *arg,
829 route_map_event_t type,
830 char *errmsg,
831 size_t errmsg_len);
832
833 /* no match ip next-hop type */
834 int (*no_match_ip_next_hop_type)(struct route_map_index *index,
835 const char *command,
836 const char *arg,
837 route_map_event_t type,
838 char *errmsg,
839 size_t errmsg_len);
840
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);
846
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);
852
853
854 /* match ipv6 address prefix list */
855 int (*match_ipv6_address_prefix_list)(struct route_map_index *index,
856 const char *command,
857 const char *arg,
858 route_map_event_t type,
859 char *errmsg, size_t errmsg_len);
860
861 /* no match ipv6 address prefix list */
862 int (*no_match_ipv6_address_prefix_list)(struct route_map_index *index,
863 const char *command,
864 const char *arg,
865 route_map_event_t type,
866 char *errmsg,
867 size_t errmsg_len);
868
869 /* match ipv6 next-hop type */
870 int (*match_ipv6_next_hop_type)(struct route_map_index *index,
871 const char *command,
872 const char *arg,
873 route_map_event_t type,
874 char *errmsg, size_t errmsg_len);
875
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);
881
882 /* match metric */
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);
887
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);
893
894 /* match tag */
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);
899
900 /* no match tag */
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);
905
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);
910
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);
915
916 /* set ip nexthop */
917 int (*set_ip_nexthop)(struct route_map_index *index,
918 const char *command, const char *arg,
919 char *errmsg, size_t errmsg_len);
920
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);
925
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);
930
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);
935
936 /* set metric */
937 int (*set_metric)(struct route_map_index *index,
938 const char *command, const char *arg,
939 char *errmsg, size_t errmsg_len);
940
941 /* no set metric */
942 int (*no_set_metric)(struct route_map_index *index,
943 const char *command, const char *arg,
944 char *errmsg, size_t errmsg_len);
945 /* set min-metric */
946 int (*set_min_metric)(struct route_map_index *index,
947 const char *command, const char *arg,
948 char *errmsg, size_t errmsg_len);
949
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);
954
955 /* set max-metric */
956 int (*set_max_metric)(struct route_map_index *index,
957 const char *command, const char *arg,
958 char *errmsg, size_t errmsg_len);
959
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);
964
965 /* set tag */
966 int (*set_tag)(struct route_map_index *index,
967 const char *command, const char *arg,
968 char *errmsg, size_t errmsg_len);
969
970 /* no set tag */
971 int (*no_set_tag)(struct route_map_index *index,
972 const char *command, const char *arg,
973 char *errmsg, size_t errmsg_len);
974 };
975
976 extern struct route_map_match_set_hooks rmap_match_set_hook;
977
978 /* Making route map list. */
979 struct route_map_list {
980 struct route_map *head;
981 struct route_map *tail;
982
983 void (*add_hook)(const char *);
984 void (*delete_hook)(const char *);
985 void (*event_hook)(const char *);
986 };
987
988 extern struct route_map_list route_map_master;
989
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,
994 int pref);
995 extern void route_map_index_delete(struct route_map_index *index, int notify);
996
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;
1012 };
1013
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);
1016
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);
1020
1021 extern const struct frr_yang_module_info frr_route_map_info;
1022
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);
1048
1049 extern void route_map_show_debug(struct vty *vty);
1050
1051 #ifdef __cplusplus
1052 }
1053 #endif
1054
1055 #endif /* _ZEBRA_ROUTEMAP_H */