]> git.proxmox.com Git - mirror_frr.git/blob - lib/routemap.h
Merge pull request #11079 from opensourcerouting/staticd-nht-refactor-fix-startrace
[mirror_frr.git] / lib / routemap.h
1 /* Route map function.
2 * Copyright (C) 1998 Kunihiro Ishiguro
3 *
4 * This file is part of GNU Zebra.
5 *
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
9 * later version.
10 *
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.
15 *
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
19 */
20
21 #ifndef _ZEBRA_ROUTEMAP_H
22 #define _ZEBRA_ROUTEMAP_H
23
24 #include "typesafe.h"
25 #include "prefix.h"
26 #include "memory.h"
27 #include "qobj.h"
28 #include "vty.h"
29 #include "lib/plist.h"
30 #include "lib/plist_int.h"
31
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35
36 DECLARE_MTYPE(ROUTE_MAP_NAME);
37 DECLARE_MTYPE(ROUTE_MAP_RULE);
38 DECLARE_MTYPE(ROUTE_MAP_COMPILED);
39
40 /* Route map's type. */
41 enum route_map_type { RMAP_PERMIT, RMAP_DENY, RMAP_ANY };
42
43 typedef enum {
44 RMAP_DENYMATCH,
45 RMAP_PERMITMATCH
46 } route_map_result_t;
47
48 /*
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
57 */
58 enum route_map_cmd_result_t {
59 /*
60 * route-map match cmd results
61 */
62 RMAP_MATCH,
63 RMAP_NOMATCH,
64 RMAP_NOOP,
65 /*
66 * route-map set cmd results
67 */
68 RMAP_OKAY,
69 RMAP_ERROR
70 };
71
72 typedef enum { RMAP_EXIT, RMAP_GOTO, RMAP_NEXT } route_map_end_t;
73
74 typedef enum {
75 RMAP_EVENT_SET_ADDED,
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,
97 } route_map_event_t;
98
99 /* Depth limit in RMAP recursion using RMAP_CALL. */
100 #define RMAP_RECURSION_LIMIT 10
101
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) */
105 const char *str;
106
107 /* Function for value set or match. */
108 enum route_map_cmd_result_t (*func_apply)(void *rule,
109 const struct prefix *prefix,
110 void *object);
111
112 /* Compile argument and return result as void *. */
113 void *(*func_compile)(const char *);
114
115 /* Free allocated value by func_compile (). */
116 void (*func_free)(void *);
117
118 /** To get the rule key after Compilation **/
119 void *(*func_get_rmap_rule_key)(void *val);
120 };
121
122 /* Route map apply error. */
123 enum rmap_compile_rets {
124 RMAP_COMPILE_SUCCESS,
125
126 /* Route map rule is missing. */
127 RMAP_RULE_MISSING,
128
129 /* Route map rule can't compile */
130 RMAP_COMPILE_ERROR,
131
132 };
133
134 /* Route map rule. This rule has both `match' rule and `set' rule. */
135 struct route_map_rule {
136 /* Rule type. */
137 const struct route_map_rule_cmd *cmd;
138
139 /* For pretty printing. */
140 char *rule_str;
141
142 /* Pre-compiled match rule. */
143 void *value;
144
145 /* Linked list. */
146 struct route_map_rule *next;
147 struct route_map_rule *prev;
148 };
149
150 /* Route map rule list. */
151 struct route_map_rule_list {
152 struct route_map_rule *head;
153 struct route_map_rule *tail;
154 };
155
156 /* Forward struct declaration: the complete can be found later this file. */
157 struct routemap_hook_context;
158
159 /* Route map index structure. */
160 struct route_map_index {
161 struct route_map *map;
162 char *description;
163
164 /* Preference of this route map rule. */
165 int pref;
166
167 /* Route map type permit or deny. */
168 enum route_map_type type;
169
170 /* Do we follow old rules, or hop forward? */
171 route_map_end_t exitpolicy;
172
173 /* If we're using "GOTO", to where do we go? */
174 int nextpref;
175
176 /* If we're using "CALL", to which route-map do ew go? */
177 char *nextrm;
178
179 /* Matching rule list. */
180 struct route_map_rule_list match_list;
181 struct route_map_rule_list set_list;
182
183 /* Make linked list. */
184 struct route_map_index *next;
185 struct route_map_index *prev;
186
187 /* Keep track how many times we've try to apply */
188 uint64_t applied;
189 uint64_t applied_clear;
190
191 /* List of match/sets contexts. */
192 TAILQ_HEAD(, routemap_hook_context) rhclist;
193
194 QOBJ_FIELDS;
195 };
196 DECLARE_QOBJ_TYPE(route_map_index);
197
198 /* route map maximum length. Not strictly the maximum xpath length but cannot be
199 * greater
200 */
201 #define RMAP_NAME_MAXLEN XPATH_MAXLEN
202
203 /* Route map list structure. */
204 struct route_map {
205 /* Name of route map. */
206 char *name;
207
208 /* Route map's rule. */
209 struct route_map_index *head;
210 struct route_map_index *tail;
211
212 /* Make linked list. */
213 struct route_map *next;
214 struct route_map *prev;
215
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;
220
221 /* How many times have we applied this route-map */
222 uint64_t applied;
223 uint64_t applied_clear;
224
225 /* Counter to track active usage of this route-map */
226 uint16_t use_count;
227
228 /* Tables to maintain IPv4 and IPv6 prefixes from
229 * the prefix-list match clause.
230 */
231 struct route_table *ipv4_prefix_table;
232 struct route_table *ipv6_prefix_table;
233
234 QOBJ_FIELDS;
235 };
236 DECLARE_QOBJ_TYPE(route_map);
237
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"))
316
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_AS_REPLACE(A) (strmatch(A, "frr-bgp-route-map:as-path-replace"))
374 #define IS_SET_IPV6_NH_GLOBAL(A) \
375 (strmatch(A, "frr-bgp-route-map:ipv6-nexthop-global"))
376 #define IS_SET_IPV6_VPN_NH(A) \
377 (strmatch(A, "frr-bgp-route-map:ipv6-vpn-address"))
378 #define IS_SET_IPV6_PEER_ADDR(A) \
379 (strmatch(A, "frr-bgp-route-map:ipv6-peer-address"))
380 #define IS_SET_IPV6_PREFER_GLOBAL(A) \
381 (strmatch(A, "frr-bgp-route-map:ipv6-prefer-global"))
382 #define IS_SET_IPV4_VPN_NH(A) \
383 (strmatch(A, "frr-bgp-route-map:ipv4-vpn-address"))
384 #define IS_SET_BGP_IPV4_NH(A) \
385 (strmatch(A, "frr-bgp-route-map:set-ipv4-nexthop"))
386 #define IS_SET_BGP_EVPN_GATEWAY_IP_IPV4(A) \
387 (strmatch(A, "frr-bgp-route-map:set-evpn-gateway-ip-ipv4"))
388 #define IS_SET_BGP_EVPN_GATEWAY_IP_IPV6(A) \
389 (strmatch(A, "frr-bgp-route-map:set-evpn-gateway-ip-ipv6"))
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);
486 #define route_map_apply(map, prefix, object) \
487 route_map_apply_ext(map, prefix, object, object)
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 tag */
694 extern void route_map_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 /* no set tag */
700 extern void route_map_no_set_tag_hook(int (*func)(struct route_map_index *index,
701 const char *command,
702 const char *arg,
703 char *errmsg,
704 size_t errmsg_len));
705
706 extern void *route_map_rule_tag_compile(const char *arg);
707 extern void route_map_rule_tag_free(void *rule);
708
709 /* Increment the route-map used counter */
710 extern void route_map_counter_increment(struct route_map *map);
711
712 /* Decrement the route-map used counter */
713 extern void route_map_counter_decrement(struct route_map *map);
714
715 /* Route map hooks data structure. */
716 struct route_map_match_set_hooks {
717 /* match interface */
718 int (*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 /* no match interface */
724 int (*no_match_interface)(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 /* match ip address */
730 int (*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 /* no match ip address */
736 int (*no_match_ip_address)(struct route_map_index *index,
737 const char *command, const char *arg,
738 route_map_event_t type,
739 char *errmsg, size_t errmsg_len);
740
741 /* match ip address prefix list */
742 int (*match_ip_address_prefix_list)(struct route_map_index *index,
743 const char *command,
744 const char *arg,
745 route_map_event_t type,
746 char *errmsg, size_t errmsg_len);
747
748 /* no match ip address prefix list */
749 int (*no_match_ip_address_prefix_list)(struct route_map_index *index,
750 const char *command,
751 const char *arg,
752 route_map_event_t type,
753 char *errmsg, size_t errmsg_len);
754
755 /* match ip next hop */
756 int (*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 /* no match ip next hop */
762 int (*no_match_ip_next_hop)(struct route_map_index *index,
763 const char *command, const char *arg,
764 route_map_event_t type,
765 char *errmsg, size_t errmsg_len);
766
767 /* match ipv6 next hop */
768 int (*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 /* no match ipv6 next hop */
774 int (*no_match_ipv6_next_hop)(struct route_map_index *index,
775 const char *command, const char *arg,
776 route_map_event_t type, char *errmsg,
777 size_t errmsg_len);
778
779 /* match ipv6 next hop prefix-list */
780 int (*match_ipv6_next_hop_prefix_list)(struct route_map_index *index,
781 const char *command,
782 const char *arg,
783 route_map_event_t type,
784 char *errmsg, size_t errmsg_len);
785
786 /* no match ipv6 next-hop prefix-list */
787 int (*no_match_ipv6_next_hop_prefix_list)(struct route_map_index *index,
788 const char *command,
789 const char *arg,
790 route_map_event_t type,
791 char *errmsg,
792 size_t errmsg_len);
793
794 /* match ip next hop prefix list */
795 int (*match_ip_next_hop_prefix_list)(struct route_map_index *index,
796 const char *command,
797 const char *arg,
798 route_map_event_t type,
799 char *errmsg, size_t errmsg_len);
800
801 /* no match ip next hop prefix list */
802 int (*no_match_ip_next_hop_prefix_list)(struct route_map_index *index,
803 const char *command,
804 const char *arg,
805 route_map_event_t type,
806 char *errmsg,
807 size_t errmsg_len);
808
809 /* match ip next-hop type */
810 int (*match_ip_next_hop_type)(struct route_map_index *index,
811 const char *command,
812 const char *arg,
813 route_map_event_t type,
814 char *errmsg,
815 size_t errmsg_len);
816
817 /* no match ip next-hop type */
818 int (*no_match_ip_next_hop_type)(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 ipv6 address */
826 int (*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 /* no match ipv6 address */
832 int (*no_match_ipv6_address)(struct route_map_index *index,
833 const char *command, const char *arg,
834 route_map_event_t type,
835 char *errmsg, size_t errmsg_len);
836
837
838 /* match ipv6 address prefix list */
839 int (*match_ipv6_address_prefix_list)(struct route_map_index *index,
840 const char *command,
841 const char *arg,
842 route_map_event_t type,
843 char *errmsg, size_t errmsg_len);
844
845 /* no match ipv6 address prefix list */
846 int (*no_match_ipv6_address_prefix_list)(struct route_map_index *index,
847 const char *command,
848 const char *arg,
849 route_map_event_t type,
850 char *errmsg,
851 size_t errmsg_len);
852
853 /* match ipv6 next-hop type */
854 int (*match_ipv6_next_hop_type)(struct route_map_index *index,
855 const char *command,
856 const char *arg,
857 route_map_event_t type,
858 char *errmsg, size_t errmsg_len);
859
860 /* no match ipv6 next-hop type */
861 int (*no_match_ipv6_next_hop_type)(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 /* match metric */
867 int (*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 /* no match metric */
873 int (*no_match_metric)(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 /* match tag */
879 int (*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 /* no match tag */
885 int (*no_match_tag)(struct route_map_index *index,
886 const char *command, const char *arg,
887 route_map_event_t type,
888 char *errmsg, size_t errmsg_len);
889
890 /* set sr-te color */
891 int (*set_srte_color)(struct route_map_index *index,
892 const char *command, const char *arg,
893 char *errmsg, size_t errmsg_len);
894
895 /* no set sr-te color */
896 int (*no_set_srte_color)(struct route_map_index *index,
897 const char *command, const char *arg,
898 char *errmsg, size_t errmsg_len);
899
900 /* set ip nexthop */
901 int (*set_ip_nexthop)(struct route_map_index *index,
902 const char *command, const char *arg,
903 char *errmsg, size_t errmsg_len);
904
905 /* no set ip nexthop */
906 int (*no_set_ip_nexthop)(struct route_map_index *index,
907 const char *command, const char *arg,
908 char *errmsg, size_t errmsg_len);
909
910 /* set ipv6 nexthop local */
911 int (*set_ipv6_nexthop_local)(struct route_map_index *index,
912 const char *command, const char *arg,
913 char *errmsg, size_t errmsg_len);
914
915 /* no set ipv6 nexthop local */
916 int (*no_set_ipv6_nexthop_local)(struct route_map_index *index,
917 const char *command, const char *arg,
918 char *errmsg, size_t errmsg_len);
919
920 /* set metric */
921 int (*set_metric)(struct route_map_index *index,
922 const char *command, const char *arg,
923 char *errmsg, size_t errmsg_len);
924
925 /* no set metric */
926 int (*no_set_metric)(struct route_map_index *index,
927 const char *command, const char *arg,
928 char *errmsg, size_t errmsg_len);
929
930 /* set tag */
931 int (*set_tag)(struct route_map_index *index,
932 const char *command, const char *arg,
933 char *errmsg, size_t errmsg_len);
934
935 /* no set tag */
936 int (*no_set_tag)(struct route_map_index *index,
937 const char *command, const char *arg,
938 char *errmsg, size_t errmsg_len);
939 };
940
941 extern struct route_map_match_set_hooks rmap_match_set_hook;
942
943 /* Making route map list. */
944 struct route_map_list {
945 struct route_map *head;
946 struct route_map *tail;
947
948 void (*add_hook)(const char *);
949 void (*delete_hook)(const char *);
950 void (*event_hook)(const char *);
951 };
952
953 extern struct route_map_list route_map_master;
954
955 extern struct route_map *route_map_get(const char *name);
956 extern void route_map_delete(struct route_map *map);
957 extern struct route_map_index *route_map_index_get(struct route_map *map,
958 enum route_map_type type,
959 int pref);
960 extern void route_map_index_delete(struct route_map_index *index, int notify);
961
962 /* routemap_northbound.c */
963 typedef int (*routemap_match_hook_fun)(struct route_map_index *rmi,
964 const char *command, const char *arg,
965 route_map_event_t event,
966 char *errmsg, size_t errmsg_len);
967 typedef int (*routemap_set_hook_fun)(struct route_map_index *rmi,
968 const char *command, const char *arg,
969 char *errmsg, size_t errmsg_len);
970 struct routemap_hook_context {
971 struct route_map_index *rhc_rmi;
972 const char *rhc_rule;
973 route_map_event_t rhc_event;
974 routemap_set_hook_fun rhc_shook;
975 routemap_match_hook_fun rhc_mhook;
976 TAILQ_ENTRY(routemap_hook_context) rhc_entry;
977 };
978
979 int lib_route_map_entry_match_destroy(struct nb_cb_destroy_args *args);
980 int lib_route_map_entry_set_destroy(struct nb_cb_destroy_args *args);
981
982 struct routemap_hook_context *
983 routemap_hook_context_insert(struct route_map_index *rmi);
984 void routemap_hook_context_free(struct routemap_hook_context *rhc);
985
986 extern const struct frr_yang_module_info frr_route_map_info;
987
988 /* routemap_cli.c */
989 extern int route_map_instance_cmp(const struct lyd_node *dnode1,
990 const struct lyd_node *dnode2);
991 extern void route_map_instance_show(struct vty *vty,
992 const struct lyd_node *dnode,
993 bool show_defaults);
994 extern void route_map_instance_show_end(struct vty *vty,
995 const struct lyd_node *dnode);
996 extern void route_map_condition_show(struct vty *vty,
997 const struct lyd_node *dnode,
998 bool show_defaults);
999 extern void route_map_action_show(struct vty *vty, const struct lyd_node *dnode,
1000 bool show_defaults);
1001 extern void route_map_exit_policy_show(struct vty *vty,
1002 const struct lyd_node *dnode,
1003 bool show_defaults);
1004 extern void route_map_call_show(struct vty *vty, const struct lyd_node *dnode,
1005 bool show_defaults);
1006 extern void route_map_description_show(struct vty *vty,
1007 const struct lyd_node *dnode,
1008 bool show_defaults);
1009 extern void route_map_optimization_disabled_show(struct vty *vty,
1010 const struct lyd_node *dnode,
1011 bool show_defaults);
1012 extern void route_map_cli_init(void);
1013
1014 #ifdef __cplusplus
1015 }
1016 #endif
1017
1018 #endif /* _ZEBRA_ROUTEMAP_H */