]> git.proxmox.com Git - mirror_frr.git/blob - lib/routemap.h
Merge pull request #12818 from imzyxwvu/fix/other-table-inactive
[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_SRC_INSTANCE(C) \
263 (strmatch(C, "frr-zebra-route-map:source-instance"))
264 /* BGP route-map match conditions */
265 #define IS_MATCH_LOCAL_PREF(C) \
266 (strmatch(C, "frr-bgp-route-map:match-local-preference"))
267 #define IS_MATCH_ALIAS(C) (strmatch(C, "frr-bgp-route-map:match-alias"))
268 #define IS_MATCH_SCRIPT(C) (strmatch(C, "frr-bgp-route-map:match-script"))
269 #define IS_MATCH_ORIGIN(C) \
270 (strmatch(C, "frr-bgp-route-map:match-origin"))
271 #define IS_MATCH_RPKI(C) (strmatch(C, "frr-bgp-route-map:rpki"))
272 #define IS_MATCH_RPKI_EXTCOMMUNITY(C) \
273 (strmatch(C, "frr-bgp-route-map:rpki-extcommunity"))
274 #define IS_MATCH_PROBABILITY(C) \
275 (strmatch(C, "frr-bgp-route-map:probability"))
276 #define IS_MATCH_SRC_VRF(C) \
277 (strmatch(C, "frr-bgp-route-map:source-vrf"))
278 #define IS_MATCH_PEER(C) (strmatch(C, "frr-bgp-route-map:peer"))
279 #define IS_MATCH_AS_LIST(C) \
280 (strmatch(C, "frr-bgp-route-map:as-path-list"))
281 #define IS_MATCH_MAC_LIST(C) \
282 (strmatch(C, "frr-bgp-route-map:mac-address-list"))
283 #define IS_MATCH_EVPN_ROUTE_TYPE(C) \
284 (strmatch(C, "frr-bgp-route-map:evpn-route-type"))
285 #define IS_MATCH_EVPN_DEFAULT_ROUTE(C) \
286 (strmatch(C, "frr-bgp-route-map:evpn-default-route"))
287 #define IS_MATCH_EVPN_VNI(C) \
288 (strmatch(C, "frr-bgp-route-map:evpn-vni"))
289 #define IS_MATCH_EVPN_DEFAULT_ROUTE(C) \
290 (strmatch(C, "frr-bgp-route-map:evpn-default-route"))
291 #define IS_MATCH_EVPN_RD(C) \
292 (strmatch(C, "frr-bgp-route-map:evpn-rd"))
293 #define IS_MATCH_ROUTE_SRC(C) \
294 (strmatch(C, "frr-bgp-route-map:ip-route-source"))
295 #define IS_MATCH_ROUTE_SRC_PL(C) \
296 (strmatch(C, "frr-bgp-route-map:ip-route-source-prefix-list"))
297 #define IS_MATCH_COMMUNITY(C) \
298 (strmatch(C, "frr-bgp-route-map:match-community"))
299 #define IS_MATCH_LCOMMUNITY(C) \
300 (strmatch(C, "frr-bgp-route-map:match-large-community"))
301 #define IS_MATCH_EXTCOMMUNITY(C) \
302 (strmatch(C, "frr-bgp-route-map:match-extcommunity"))
303 #define IS_MATCH_IPV4_NH(C) \
304 (strmatch(C, "frr-bgp-route-map:ipv4-nexthop"))
305 #define IS_MATCH_IPV6_NH(C) \
306 (strmatch(C, "frr-bgp-route-map:ipv6-nexthop"))
307
308 /* Route-map set actions */
309 #define IS_SET_IPv4_NH(A) \
310 (strmatch(A, "frr-route-map:ipv4-next-hop"))
311 #define IS_SET_IPv6_NH(A) \
312 (strmatch(A, "frr-route-map:ipv6-next-hop"))
313 #define IS_SET_METRIC(A) \
314 (strmatch(A, "frr-route-map:set-metric"))
315 #define IS_SET_TAG(A) (strmatch(A, "frr-route-map:set-tag"))
316 #define IS_SET_SR_TE_COLOR(A) \
317 (strmatch(A, "frr-route-map:set-sr-te-color"))
318 /* Zebra route-map set actions */
319 #define IS_SET_SRC(A) \
320 (strmatch(A, "frr-zebra-route-map:src-address"))
321 /* OSPF route-map set actions */
322 #define IS_SET_METRIC_TYPE(A) \
323 (strmatch(A, "frr-ospf-route-map:metric-type"))
324 #define IS_SET_FORWARDING_ADDR(A) \
325 (strmatch(A, "frr-ospf6-route-map:forwarding-address"))
326 /* BGP route-map_set actions */
327 #define IS_SET_WEIGHT(A) \
328 (strmatch(A, "frr-bgp-route-map:weight"))
329 #define IS_SET_TABLE(A) (strmatch(A, "frr-bgp-route-map:table"))
330 #define IS_SET_LOCAL_PREF(A) \
331 (strmatch(A, "frr-bgp-route-map:set-local-preference"))
332 #define IS_SET_LABEL_INDEX(A) \
333 (strmatch(A, "frr-bgp-route-map:label-index"))
334 #define IS_SET_DISTANCE(A) \
335 (strmatch(A, "frr-bgp-route-map:distance"))
336 #define IS_SET_ORIGIN(A) \
337 (strmatch(A, "frr-bgp-route-map:set-origin"))
338 #define IS_SET_ATOMIC_AGGREGATE(A) \
339 (strmatch(A, "frr-bgp-route-map:atomic-aggregate"))
340 #define IS_SET_AIGP_METRIC(A) (strmatch(A, "frr-bgp-route-map:aigp-metric"))
341 #define IS_SET_ORIGINATOR_ID(A) \
342 (strmatch(A, "frr-bgp-route-map:originator-id"))
343 #define IS_SET_COMM_LIST_DEL(A) \
344 (strmatch(A, "frr-bgp-route-map:comm-list-delete"))
345 #define IS_SET_LCOMM_LIST_DEL(A) \
346 (strmatch(A, "frr-bgp-route-map:large-comm-list-delete"))
347 #define IS_SET_LCOMMUNITY(A) \
348 (strmatch(A, "frr-bgp-route-map:set-large-community"))
349 #define IS_SET_COMMUNITY(A) \
350 (strmatch(A, "frr-bgp-route-map:set-community"))
351 #define IS_SET_EXTCOMMUNITY_NONE(A) \
352 (strmatch(A, "frr-bgp-route-map:set-extcommunity-none"))
353 #define IS_SET_EXTCOMMUNITY_RT(A) \
354 (strmatch(A, "frr-bgp-route-map:set-extcommunity-rt"))
355 #define IS_SET_EXTCOMMUNITY_SOO(A) \
356 (strmatch(A, "frr-bgp-route-map:set-extcommunity-soo"))
357 #define IS_SET_EXTCOMMUNITY_LB(A) \
358 (strmatch(A, "frr-bgp-route-map:set-extcommunity-lb"))
359 #define IS_SET_AGGREGATOR(A) \
360 (strmatch(A, "frr-bgp-route-map:aggregator"))
361 #define IS_SET_AS_PREPEND(A) \
362 (strmatch(A, "frr-bgp-route-map:as-path-prepend"))
363 #define IS_SET_AS_EXCLUDE(A) \
364 (strmatch(A, "frr-bgp-route-map:as-path-exclude"))
365 #define IS_SET_AS_REPLACE(A) (strmatch(A, "frr-bgp-route-map:as-path-replace"))
366 #define IS_SET_IPV6_NH_GLOBAL(A) \
367 (strmatch(A, "frr-bgp-route-map:ipv6-nexthop-global"))
368 #define IS_SET_IPV6_VPN_NH(A) \
369 (strmatch(A, "frr-bgp-route-map:ipv6-vpn-address"))
370 #define IS_SET_IPV6_PEER_ADDR(A) \
371 (strmatch(A, "frr-bgp-route-map:ipv6-peer-address"))
372 #define IS_SET_IPV6_PREFER_GLOBAL(A) \
373 (strmatch(A, "frr-bgp-route-map:ipv6-prefer-global"))
374 #define IS_SET_IPV4_VPN_NH(A) \
375 (strmatch(A, "frr-bgp-route-map:ipv4-vpn-address"))
376 #define IS_SET_BGP_IPV4_NH(A) \
377 (strmatch(A, "frr-bgp-route-map:set-ipv4-nexthop"))
378 #define IS_SET_BGP_EVPN_GATEWAY_IP_IPV4(A) \
379 (strmatch(A, "frr-bgp-route-map:set-evpn-gateway-ip-ipv4"))
380 #define IS_SET_BGP_EVPN_GATEWAY_IP_IPV6(A) \
381 (strmatch(A, "frr-bgp-route-map:set-evpn-gateway-ip-ipv6"))
382 #define IS_SET_BGP_L3VPN_NEXTHOP_ENCAPSULATION(A) \
383 (strmatch(A, "frr-bgp-route-map:set-l3vpn-nexthop-encapsulation"))
384
385 enum ecommunity_lb_type {
386 EXPLICIT_BANDWIDTH,
387 CUMULATIVE_BANDWIDTH,
388 COMPUTED_BANDWIDTH
389 };
390
391 /* Prototypes. */
392 extern void route_map_init(void);
393
394 /*
395 * This should only be called on shutdown
396 * Additionally this function sets the hooks to NULL
397 * before any processing is done.
398 */
399 extern void route_map_finish(void);
400
401 /* Add match statement to route map. */
402 extern enum rmap_compile_rets route_map_add_match(struct route_map_index *index,
403 const char *match_name,
404 const char *match_arg,
405 route_map_event_t type);
406
407 /* Delete specified route match rule. */
408 extern enum rmap_compile_rets
409 route_map_delete_match(struct route_map_index *index,
410 const char *match_name, const char *match_arg,
411 route_map_event_t type);
412
413 extern const char *route_map_get_match_arg(struct route_map_index *index,
414 const char *match_name);
415
416 /* Add route-map set statement to the route map. */
417 extern enum rmap_compile_rets route_map_add_set(struct route_map_index *index,
418 const char *set_name,
419 const char *set_arg);
420
421 /* Delete route map set rule. */
422 extern enum rmap_compile_rets
423 route_map_delete_set(struct route_map_index *index,
424 const char *set_name, const char *set_arg);
425
426 /* struct route_map_rule_cmd is kept const in order to not have writable
427 * function pointers (which is a security benefit.) Hence, below struct is
428 * used as proxy for hashing these for by-name lookup.
429 */
430
431 PREDECL_HASH(rmap_cmd_name);
432
433 struct route_map_rule_cmd_proxy {
434 struct rmap_cmd_name_item itm;
435 const struct route_map_rule_cmd *cmd;
436 };
437
438 /* ... and just automatically create a proxy struct for each call location
439 * to route_map_install_{match,set} to avoid unnecessarily added boilerplate
440 * for each route-map user
441 */
442
443 #define route_map_install_match(c) \
444 do { \
445 static struct route_map_rule_cmd_proxy proxy = {.cmd = c}; \
446 _route_map_install_match(&proxy); \
447 } while (0)
448
449 #define route_map_install_set(c) \
450 do { \
451 static struct route_map_rule_cmd_proxy proxy = {.cmd = c}; \
452 _route_map_install_set(&proxy); \
453 } while (0)
454
455 /* Install rule command to the match list. */
456 extern void _route_map_install_match(struct route_map_rule_cmd_proxy *proxy);
457
458 /*
459 * Install rule command to the set list.
460 *
461 * When installing a particular item, Allow a difference of handling
462 * of bad cli inputted(return NULL) -vs- this particular daemon cannot use
463 * this form of the command(return a pointer and handle it appropriately
464 * in the apply command). See 'set metric' command
465 * as it is handled in ripd/ripngd and ospfd.
466 */
467 extern void _route_map_install_set(struct route_map_rule_cmd_proxy *proxy);
468
469 /* Lookup route map by name. */
470 extern struct route_map *route_map_lookup_by_name(const char *name);
471
472 /* Simple helper to warn if route-map does not exist. */
473 struct route_map *route_map_lookup_warn_noexist(struct vty *vty, const char *name);
474
475 /* Apply route map to the object. */
476 extern route_map_result_t route_map_apply_ext(struct route_map *map,
477 const struct prefix *prefix,
478 void *match_object,
479 void *set_object, int *pref);
480 #define route_map_apply(map, prefix, object) \
481 route_map_apply_ext(map, prefix, object, object, NULL)
482
483 extern void route_map_add_hook(void (*func)(const char *));
484 extern void route_map_delete_hook(void (*func)(const char *));
485
486 /*
487 * This is the callback for when something has changed about a
488 * route-map. The interested parties can register to receive
489 * this data.
490 *
491 * name - Is the name of the changed route-map
492 */
493 extern void route_map_event_hook(void (*func)(const char *name));
494 extern int route_map_mark_updated(const char *name);
495 extern void route_map_walk_update_list(void (*update_fn)(char *name));
496 extern void route_map_upd8_dependency(route_map_event_t type, const char *arg,
497 const char *rmap_name);
498 extern void route_map_notify_dependencies(const char *affected_name,
499 route_map_event_t event);
500 extern void
501 route_map_notify_pentry_dependencies(const char *affected_name,
502 struct prefix_list_entry *pentry,
503 route_map_event_t event);
504 extern int generic_match_add(struct route_map_index *index,
505 const char *command, const char *arg,
506 route_map_event_t type,
507 char *errmsg, size_t errmsg_len);
508 extern int generic_match_delete(struct route_map_index *index,
509 const char *command, const char *arg,
510 route_map_event_t type,
511 char *errmsg, size_t errmsg_len);
512
513 extern int generic_set_add(struct route_map_index *index,
514 const char *command, const char *arg,
515 char *errmsg, size_t errmsg_len);
516 extern int generic_set_delete(struct route_map_index *index,
517 const char *command, const char *arg,
518 char *errmsg, size_t errmsg_len);
519
520
521 /* match interface */
522 extern void route_map_match_interface_hook(int (*func)(
523 struct route_map_index *index, const char *command,
524 const char *arg, route_map_event_t type,
525 char *errmsg, size_t errmsg_len));
526 /* no match interface */
527 extern void route_map_no_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 /* match ip address */
532 extern void route_map_match_ip_address_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 /* no match ip address */
537 extern void route_map_no_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 /* match ip address prefix list */
542 extern void route_map_match_ip_address_prefix_list_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 /* no match ip address prefix list */
547 extern void route_map_no_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 /* match ip next hop */
552 extern void route_map_match_ip_next_hop_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 /* no match ip next hop */
557 extern void route_map_no_match_ip_next_hop_hook(int (*func)(
558 struct route_map_index *index, const char *command, const char *arg,
559 route_map_event_t type, char *errmsg, size_t errmsg_len));
560 /* match ipv6 next hop */
561 extern void route_map_match_ipv6_next_hop_hook(int (*func)(
562 struct route_map_index *index, const char *command, const char *arg,
563 route_map_event_t type, char *errmsg, size_t errmsg_len));
564 /* no match ipv6 next hop */
565 extern void route_map_no_match_ipv6_next_hop_hook(int (*func)(
566 struct route_map_index *index, const char *command, const char *arg,
567 route_map_event_t type, char *errmsg, size_t errmsg_len));
568 /* match ip next hop prefix list */
569 extern void route_map_match_ip_next_hop_prefix_list_hook(int (*func)(
570 struct route_map_index *index, const char *command,
571 const char *arg, route_map_event_t type,
572 char *errmsg, size_t errmsg_len));
573 /* no match ip next hop prefix list */
574 extern void route_map_no_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 /* match ip next hop type */
579 extern void route_map_match_ip_next_hop_type_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 /* no match ip next hop type */
584 extern void route_map_no_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 /* match ipv6 address */
589 extern void route_map_match_ipv6_address_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 /* no match ipv6 address */
594 extern void route_map_no_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 /* match ipv6 address prefix list */
599 extern void route_map_match_ipv6_address_prefix_list_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 /* no match ipv6 address prefix list */
604 extern void route_map_no_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 /* match ipv6 next-hop type */
609 extern void route_map_match_ipv6_next_hop_type_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 /* no match ipv6 next-hop type */
614 extern void route_map_no_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 /* match ipv6 next-hop prefix-list */
619 extern void route_map_match_ipv6_next_hop_prefix_list_hook(int (*func)(
620 struct route_map_index *index, const char *command, const char *arg,
621 route_map_event_t type, char *errmsg, size_t errmsg_len));
622 /* no match ipv6 next-hop prefix-list */
623 extern void route_map_no_match_ipv6_next_hop_prefix_list_hook(int (*func)(
624 struct route_map_index *index, const char *command, const char *arg,
625 route_map_event_t type, char *errmsg, size_t errmsg_len));
626 /* match metric */
627 extern void route_map_match_metric_hook(int (*func)(
628 struct route_map_index *index, const char *command,
629 const char *arg, route_map_event_t type,
630 char *errmsg, size_t errmsg_len));
631 /* no match metric */
632 extern void route_map_no_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 /* match tag */
637 extern void route_map_match_tag_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));
641 /* no match tag */
642 extern void route_map_no_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));
646 /* set sr-te color */
647 extern void route_map_set_srte_color_hook(
648 int (*func)(struct route_map_index *index,
649 const char *command, const char *arg,
650 char *errmsg, size_t errmsg_len));
651 /* no set sr-te color */
652 extern void route_map_no_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 /* set ip nexthop */
657 extern void route_map_set_ip_nexthop_hook(
658 int (*func)(struct route_map_index *index,
659 const char *command, const char *arg,
660 char *errmsg, size_t errmsg_len));
661 /* no set ip nexthop */
662 extern void route_map_no_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 /* set ipv6 nexthop local */
667 extern void route_map_set_ipv6_nexthop_local_hook(
668 int (*func)(struct route_map_index *index,
669 const char *command, const char *arg,
670 char *errmsg, size_t errmsg_len));
671 /* no set ipv6 nexthop local */
672 extern void route_map_no_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 /* set metric */
677 extern void route_map_set_metric_hook(int (*func)(struct route_map_index *index,
678 const char *command,
679 const char *arg,
680 char *errmsg,
681 size_t errmsg_len));
682 /* no set metric */
683 extern void route_map_no_set_metric_hook(
684 int (*func)(struct route_map_index *index,
685 const char *command, const char *arg,
686 char *errmsg, size_t errmsg_len));
687 /* set tag */
688 extern void route_map_set_tag_hook(int (*func)(struct route_map_index *index,
689 const char *command,
690 const char *arg,
691 char *errmsg,
692 size_t errmsg_len));
693 /* no set tag */
694 extern void route_map_no_set_tag_hook(int (*func)(struct route_map_index *index,
695 const char *command,
696 const char *arg,
697 char *errmsg,
698 size_t errmsg_len));
699
700 extern void *route_map_rule_tag_compile(const char *arg);
701 extern void route_map_rule_tag_free(void *rule);
702
703 /* Increment the route-map used counter */
704 extern void route_map_counter_increment(struct route_map *map);
705
706 /* Decrement the route-map used counter */
707 extern void route_map_counter_decrement(struct route_map *map);
708
709 /* Route map hooks data structure. */
710 struct route_map_match_set_hooks {
711 /* match interface */
712 int (*match_interface)(struct route_map_index *index,
713 const char *command, const char *arg,
714 route_map_event_t type,
715 char *errmsg, size_t errmsg_len);
716
717 /* no match interface */
718 int (*no_match_interface)(struct route_map_index *index,
719 const char *command, const char *arg,
720 route_map_event_t type,
721 char *errmsg, size_t errmsg_len);
722
723 /* match ip address */
724 int (*match_ip_address)(struct route_map_index *index,
725 const char *command, const char *arg,
726 route_map_event_t type,
727 char *errmsg, size_t errmsg_len);
728
729 /* no match ip address */
730 int (*no_match_ip_address)(struct route_map_index *index,
731 const char *command, const char *arg,
732 route_map_event_t type,
733 char *errmsg, size_t errmsg_len);
734
735 /* match ip address prefix list */
736 int (*match_ip_address_prefix_list)(struct route_map_index *index,
737 const char *command,
738 const char *arg,
739 route_map_event_t type,
740 char *errmsg, size_t errmsg_len);
741
742 /* no match ip address prefix list */
743 int (*no_match_ip_address_prefix_list)(struct route_map_index *index,
744 const char *command,
745 const char *arg,
746 route_map_event_t type,
747 char *errmsg, size_t errmsg_len);
748
749 /* match ip next hop */
750 int (*match_ip_next_hop)(struct route_map_index *index,
751 const char *command, const char *arg,
752 route_map_event_t type,
753 char *errmsg, size_t errmsg_len);
754
755 /* no match ip next hop */
756 int (*no_match_ip_next_hop)(struct route_map_index *index,
757 const char *command, const char *arg,
758 route_map_event_t type,
759 char *errmsg, size_t errmsg_len);
760
761 /* match ipv6 next hop */
762 int (*match_ipv6_next_hop)(struct route_map_index *index,
763 const char *command, const char *arg,
764 route_map_event_t type, char *errmsg,
765 size_t errmsg_len);
766
767 /* no match ipv6 next hop */
768 int (*no_match_ipv6_next_hop)(struct route_map_index *index,
769 const char *command, const char *arg,
770 route_map_event_t type, char *errmsg,
771 size_t errmsg_len);
772
773 /* match ipv6 next hop prefix-list */
774 int (*match_ipv6_next_hop_prefix_list)(struct route_map_index *index,
775 const char *command,
776 const char *arg,
777 route_map_event_t type,
778 char *errmsg, size_t errmsg_len);
779
780 /* no match ipv6 next-hop prefix-list */
781 int (*no_match_ipv6_next_hop_prefix_list)(struct route_map_index *index,
782 const char *command,
783 const char *arg,
784 route_map_event_t type,
785 char *errmsg,
786 size_t errmsg_len);
787
788 /* match ip next hop prefix list */
789 int (*match_ip_next_hop_prefix_list)(struct route_map_index *index,
790 const char *command,
791 const char *arg,
792 route_map_event_t type,
793 char *errmsg, size_t errmsg_len);
794
795 /* no match ip next hop prefix list */
796 int (*no_match_ip_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,
801 size_t errmsg_len);
802
803 /* match ip next-hop type */
804 int (*match_ip_next_hop_type)(struct route_map_index *index,
805 const char *command,
806 const char *arg,
807 route_map_event_t type,
808 char *errmsg,
809 size_t errmsg_len);
810
811 /* no match ip next-hop type */
812 int (*no_match_ip_next_hop_type)(struct route_map_index *index,
813 const char *command,
814 const char *arg,
815 route_map_event_t type,
816 char *errmsg,
817 size_t errmsg_len);
818
819 /* match ipv6 address */
820 int (*match_ipv6_address)(struct route_map_index *index,
821 const char *command, const char *arg,
822 route_map_event_t type,
823 char *errmsg, size_t errmsg_len);
824
825 /* no match ipv6 address */
826 int (*no_match_ipv6_address)(struct route_map_index *index,
827 const char *command, const char *arg,
828 route_map_event_t type,
829 char *errmsg, size_t errmsg_len);
830
831
832 /* match ipv6 address prefix list */
833 int (*match_ipv6_address_prefix_list)(struct route_map_index *index,
834 const char *command,
835 const char *arg,
836 route_map_event_t type,
837 char *errmsg, size_t errmsg_len);
838
839 /* no match ipv6 address prefix list */
840 int (*no_match_ipv6_address_prefix_list)(struct route_map_index *index,
841 const char *command,
842 const char *arg,
843 route_map_event_t type,
844 char *errmsg,
845 size_t errmsg_len);
846
847 /* match ipv6 next-hop type */
848 int (*match_ipv6_next_hop_type)(struct route_map_index *index,
849 const char *command,
850 const char *arg,
851 route_map_event_t type,
852 char *errmsg, size_t errmsg_len);
853
854 /* no match ipv6 next-hop type */
855 int (*no_match_ipv6_next_hop_type)(struct route_map_index *index,
856 const char *command, const char *arg,
857 route_map_event_t type,
858 char *errmsg, size_t errmsg_len);
859
860 /* match metric */
861 int (*match_metric)(struct route_map_index *index,
862 const char *command, const char *arg,
863 route_map_event_t type,
864 char *errmsg, size_t errmsg_len);
865
866 /* no match metric */
867 int (*no_match_metric)(struct route_map_index *index,
868 const char *command, const char *arg,
869 route_map_event_t type,
870 char *errmsg, size_t errmsg_len);
871
872 /* match tag */
873 int (*match_tag)(struct route_map_index *index,
874 const char *command, const char *arg,
875 route_map_event_t type,
876 char *errmsg, size_t errmsg_len);
877
878 /* no match tag */
879 int (*no_match_tag)(struct route_map_index *index,
880 const char *command, const char *arg,
881 route_map_event_t type,
882 char *errmsg, size_t errmsg_len);
883
884 /* set sr-te color */
885 int (*set_srte_color)(struct route_map_index *index,
886 const char *command, const char *arg,
887 char *errmsg, size_t errmsg_len);
888
889 /* no set sr-te color */
890 int (*no_set_srte_color)(struct route_map_index *index,
891 const char *command, const char *arg,
892 char *errmsg, size_t errmsg_len);
893
894 /* set ip nexthop */
895 int (*set_ip_nexthop)(struct route_map_index *index,
896 const char *command, const char *arg,
897 char *errmsg, size_t errmsg_len);
898
899 /* no set ip nexthop */
900 int (*no_set_ip_nexthop)(struct route_map_index *index,
901 const char *command, const char *arg,
902 char *errmsg, size_t errmsg_len);
903
904 /* set ipv6 nexthop local */
905 int (*set_ipv6_nexthop_local)(struct route_map_index *index,
906 const char *command, const char *arg,
907 char *errmsg, size_t errmsg_len);
908
909 /* no set ipv6 nexthop local */
910 int (*no_set_ipv6_nexthop_local)(struct route_map_index *index,
911 const char *command, const char *arg,
912 char *errmsg, size_t errmsg_len);
913
914 /* set metric */
915 int (*set_metric)(struct route_map_index *index,
916 const char *command, const char *arg,
917 char *errmsg, size_t errmsg_len);
918
919 /* no set metric */
920 int (*no_set_metric)(struct route_map_index *index,
921 const char *command, const char *arg,
922 char *errmsg, size_t errmsg_len);
923
924 /* set tag */
925 int (*set_tag)(struct route_map_index *index,
926 const char *command, const char *arg,
927 char *errmsg, size_t errmsg_len);
928
929 /* no set tag */
930 int (*no_set_tag)(struct route_map_index *index,
931 const char *command, const char *arg,
932 char *errmsg, size_t errmsg_len);
933 };
934
935 extern struct route_map_match_set_hooks rmap_match_set_hook;
936
937 /* Making route map list. */
938 struct route_map_list {
939 struct route_map *head;
940 struct route_map *tail;
941
942 void (*add_hook)(const char *);
943 void (*delete_hook)(const char *);
944 void (*event_hook)(const char *);
945 };
946
947 extern struct route_map_list route_map_master;
948
949 extern struct route_map *route_map_get(const char *name);
950 extern void route_map_delete(struct route_map *map);
951 extern struct route_map_index *route_map_index_get(struct route_map *map,
952 enum route_map_type type,
953 int pref);
954 extern void route_map_index_delete(struct route_map_index *index, int notify);
955
956 /* routemap_northbound.c */
957 typedef int (*routemap_match_hook_fun)(struct route_map_index *rmi,
958 const char *command, const char *arg,
959 route_map_event_t event,
960 char *errmsg, size_t errmsg_len);
961 typedef int (*routemap_set_hook_fun)(struct route_map_index *rmi,
962 const char *command, const char *arg,
963 char *errmsg, size_t errmsg_len);
964 struct routemap_hook_context {
965 struct route_map_index *rhc_rmi;
966 const char *rhc_rule;
967 route_map_event_t rhc_event;
968 routemap_set_hook_fun rhc_shook;
969 routemap_match_hook_fun rhc_mhook;
970 TAILQ_ENTRY(routemap_hook_context) rhc_entry;
971 };
972
973 int lib_route_map_entry_match_destroy(struct nb_cb_destroy_args *args);
974 int lib_route_map_entry_set_destroy(struct nb_cb_destroy_args *args);
975
976 struct routemap_hook_context *
977 routemap_hook_context_insert(struct route_map_index *rmi);
978 void routemap_hook_context_free(struct routemap_hook_context *rhc);
979
980 extern const struct frr_yang_module_info frr_route_map_info;
981
982 /* routemap_cli.c */
983 extern int route_map_instance_cmp(const struct lyd_node *dnode1,
984 const struct lyd_node *dnode2);
985 extern void route_map_instance_show(struct vty *vty,
986 const struct lyd_node *dnode,
987 bool show_defaults);
988 extern void route_map_instance_show_end(struct vty *vty,
989 const struct lyd_node *dnode);
990 extern void route_map_condition_show(struct vty *vty,
991 const struct lyd_node *dnode,
992 bool show_defaults);
993 extern void route_map_action_show(struct vty *vty, const struct lyd_node *dnode,
994 bool show_defaults);
995 extern void route_map_exit_policy_show(struct vty *vty,
996 const struct lyd_node *dnode,
997 bool show_defaults);
998 extern void route_map_call_show(struct vty *vty, const struct lyd_node *dnode,
999 bool show_defaults);
1000 extern void route_map_description_show(struct vty *vty,
1001 const struct lyd_node *dnode,
1002 bool show_defaults);
1003 extern void route_map_optimization_disabled_show(struct vty *vty,
1004 const struct lyd_node *dnode,
1005 bool show_defaults);
1006 extern void route_map_cli_init(void);
1007
1008 extern void route_map_show_debug(struct vty *vty);
1009
1010 #ifdef __cplusplus
1011 }
1012 #endif
1013
1014 #endif /* _ZEBRA_ROUTEMAP_H */