]> git.proxmox.com Git - mirror_frr.git/blob - lib/routemap.h
doc: Add `show ipv6 rpf X:X::X:X` command to docs
[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 #define DEBUG_ROUTEMAP 0x01
41 #define DEBUG_ROUTEMAP_DETAIL 0x02
42 extern uint32_t rmap_debug;
43
44 /* Route map's type. */
45 enum route_map_type { RMAP_PERMIT, RMAP_DENY, RMAP_ANY };
46
47 typedef enum {
48 RMAP_DENYMATCH,
49 RMAP_PERMITMATCH
50 } route_map_result_t;
51
52 /*
53 * Route-map match or set result "Eg: match evpn vni xx"
54 * route-map match cmd always returns match/nomatch/noop
55 * match--> found a match
56 * nomatch--> didnt find a match
57 * noop--> not applicable
58 * route-map set retuns okay/error
59 * okay --> set was successful
60 * error --> set was not successful
61 */
62 enum route_map_cmd_result_t {
63 /*
64 * route-map match cmd results
65 */
66 RMAP_MATCH,
67 RMAP_NOMATCH,
68 RMAP_NOOP,
69 /*
70 * route-map set cmd results
71 */
72 RMAP_OKAY,
73 RMAP_ERROR
74 };
75
76 typedef enum { RMAP_EXIT, RMAP_GOTO, RMAP_NEXT } route_map_end_t;
77
78 typedef enum {
79 RMAP_EVENT_SET_ADDED,
80 RMAP_EVENT_SET_DELETED,
81 RMAP_EVENT_SET_REPLACED,
82 RMAP_EVENT_MATCH_ADDED,
83 RMAP_EVENT_MATCH_DELETED,
84 RMAP_EVENT_MATCH_REPLACED,
85 RMAP_EVENT_INDEX_ADDED,
86 RMAP_EVENT_INDEX_DELETED,
87 RMAP_EVENT_CALL_ADDED, /* call to another routemap added */
88 RMAP_EVENT_CALL_DELETED,
89 RMAP_EVENT_PLIST_ADDED,
90 RMAP_EVENT_PLIST_DELETED,
91 RMAP_EVENT_CLIST_ADDED,
92 RMAP_EVENT_CLIST_DELETED,
93 RMAP_EVENT_ECLIST_ADDED,
94 RMAP_EVENT_ECLIST_DELETED,
95 RMAP_EVENT_LLIST_ADDED,
96 RMAP_EVENT_LLIST_DELETED,
97 RMAP_EVENT_ASLIST_ADDED,
98 RMAP_EVENT_ASLIST_DELETED,
99 RMAP_EVENT_FILTER_ADDED,
100 RMAP_EVENT_FILTER_DELETED,
101 } route_map_event_t;
102
103 /* Depth limit in RMAP recursion using RMAP_CALL. */
104 #define RMAP_RECURSION_LIMIT 10
105
106 /* Route map rule structure for matching and setting. */
107 struct route_map_rule_cmd {
108 /* Route map rule name (e.g. as-path, metric) */
109 const char *str;
110
111 /* Function for value set or match. */
112 enum route_map_cmd_result_t (*func_apply)(void *rule,
113 const struct prefix *prefix,
114 void *object);
115
116 /* Compile argument and return result as void *. */
117 void *(*func_compile)(const char *);
118
119 /* Free allocated value by func_compile (). */
120 void (*func_free)(void *);
121
122 /** To get the rule key after Compilation **/
123 void *(*func_get_rmap_rule_key)(void *val);
124 };
125
126 /* Route map apply error. */
127 enum rmap_compile_rets {
128 RMAP_COMPILE_SUCCESS,
129
130 /* Route map rule is missing. */
131 RMAP_RULE_MISSING,
132
133 /* Route map rule can't compile */
134 RMAP_COMPILE_ERROR,
135
136 };
137
138 /* Route map rule. This rule has both `match' rule and `set' rule. */
139 struct route_map_rule {
140 /* Rule type. */
141 const struct route_map_rule_cmd *cmd;
142
143 /* For pretty printing. */
144 char *rule_str;
145
146 /* Pre-compiled match rule. */
147 void *value;
148
149 /* Linked list. */
150 struct route_map_rule *next;
151 struct route_map_rule *prev;
152 };
153
154 /* Route map rule list. */
155 struct route_map_rule_list {
156 struct route_map_rule *head;
157 struct route_map_rule *tail;
158 };
159
160 /* Forward struct declaration: the complete can be found later this file. */
161 struct routemap_hook_context;
162
163 /* Route map index structure. */
164 struct route_map_index {
165 struct route_map *map;
166 char *description;
167
168 /* Preference of this route map rule. */
169 int pref;
170
171 /* Route map type permit or deny. */
172 enum route_map_type type;
173
174 /* Do we follow old rules, or hop forward? */
175 route_map_end_t exitpolicy;
176
177 /* If we're using "GOTO", to where do we go? */
178 int nextpref;
179
180 /* If we're using "CALL", to which route-map do ew go? */
181 char *nextrm;
182
183 /* Matching rule list. */
184 struct route_map_rule_list match_list;
185 struct route_map_rule_list set_list;
186
187 /* Make linked list. */
188 struct route_map_index *next;
189 struct route_map_index *prev;
190
191 /* Keep track how many times we've try to apply */
192 uint64_t applied;
193 uint64_t applied_clear;
194
195 /* List of match/sets contexts. */
196 TAILQ_HEAD(, routemap_hook_context) rhclist;
197
198 QOBJ_FIELDS;
199 };
200 DECLARE_QOBJ_TYPE(route_map_index);
201
202 /* route map maximum length. Not strictly the maximum xpath length but cannot be
203 * greater
204 */
205 #define RMAP_NAME_MAXLEN XPATH_MAXLEN
206
207 /* Route map list structure. */
208 struct route_map {
209 /* Name of route map. */
210 char *name;
211
212 /* Route map's rule. */
213 struct route_map_index *head;
214 struct route_map_index *tail;
215
216 /* Make linked list. */
217 struct route_map *next;
218 struct route_map *prev;
219
220 /* Maintain update info */
221 bool to_be_processed; /* True if modification isn't acted on yet */
222 bool deleted; /* If 1, then this node will be deleted */
223 bool optimization_disabled;
224
225 /* How many times have we applied this route-map */
226 uint64_t applied;
227 uint64_t applied_clear;
228
229 /* Counter to track active usage of this route-map */
230 uint16_t use_count;
231
232 /* Tables to maintain IPv4 and IPv6 prefixes from
233 * the prefix-list match clause.
234 */
235 struct route_table *ipv4_prefix_table;
236 struct route_table *ipv6_prefix_table;
237
238 QOBJ_FIELDS;
239 };
240 DECLARE_QOBJ_TYPE(route_map);
241
242 /* Route-map match conditions */
243 #define IS_MATCH_INTERFACE(C) \
244 (strmatch(C, "frr-route-map:interface"))
245 #define IS_MATCH_IPv4_ADDRESS_LIST(C) \
246 (strmatch(C, "frr-route-map:ipv4-address-list"))
247 #define IS_MATCH_IPv6_ADDRESS_LIST(C) \
248 (strmatch(C, "frr-route-map:ipv6-address-list"))
249 #define IS_MATCH_IPv4_NEXTHOP_LIST(C) \
250 (strmatch(C, "frr-route-map:ipv4-next-hop-list"))
251 #define IS_MATCH_IPv6_NEXTHOP_LIST(C) \
252 (strmatch(C, "frr-route-map:ipv6-next-hop-list"))
253 #define IS_MATCH_IPv4_PREFIX_LIST(C) \
254 (strmatch(C, "frr-route-map:ipv4-prefix-list"))
255 #define IS_MATCH_IPv6_PREFIX_LIST(C) \
256 (strmatch(C, "frr-route-map:ipv6-prefix-list"))
257 #define IS_MATCH_IPv4_NEXTHOP_PREFIX_LIST(C) \
258 (strmatch(C, "frr-route-map:ipv4-next-hop-prefix-list"))
259 #define IS_MATCH_IPv6_NEXTHOP_PREFIX_LIST(C) \
260 (strmatch(C, "frr-route-map:ipv6-next-hop-prefix-list"))
261 #define IS_MATCH_IPv4_NEXTHOP_TYPE(C) \
262 (strmatch(C, "frr-route-map:ipv4-next-hop-type"))
263 #define IS_MATCH_IPv6_NEXTHOP_TYPE(C) \
264 (strmatch(C, "frr-route-map:ipv6-next-hop-type"))
265 #define IS_MATCH_METRIC(C) \
266 (strmatch(C, "frr-route-map:match-metric"))
267 #define IS_MATCH_TAG(C) (strmatch(C, "frr-route-map:match-tag"))
268 /* Zebra route-map match conditions */
269 #define IS_MATCH_IPv4_PREFIX_LEN(C) \
270 (strmatch(C, "frr-zebra-route-map:ipv4-prefix-length"))
271 #define IS_MATCH_IPv6_PREFIX_LEN(C) \
272 (strmatch(C, "frr-zebra-route-map:ipv6-prefix-length"))
273 #define IS_MATCH_IPv4_NH_PREFIX_LEN(C) \
274 (strmatch(C, "frr-zebra-route-map:ipv4-next-hop-prefix-length"))
275 #define IS_MATCH_SRC_PROTO(C) \
276 (strmatch(C, "frr-zebra-route-map:source-protocol"))
277 #define IS_MATCH_SRC_INSTANCE(C) \
278 (strmatch(C, "frr-zebra-route-map:source-instance"))
279 /* BGP route-map match conditions */
280 #define IS_MATCH_LOCAL_PREF(C) \
281 (strmatch(C, "frr-bgp-route-map:match-local-preference"))
282 #define IS_MATCH_ALIAS(C) (strmatch(C, "frr-bgp-route-map:match-alias"))
283 #define IS_MATCH_SCRIPT(C) (strmatch(C, "frr-bgp-route-map:match-script"))
284 #define IS_MATCH_ORIGIN(C) \
285 (strmatch(C, "frr-bgp-route-map:match-origin"))
286 #define IS_MATCH_RPKI(C) (strmatch(C, "frr-bgp-route-map:rpki"))
287 #define IS_MATCH_RPKI_EXTCOMMUNITY(C) \
288 (strmatch(C, "frr-bgp-route-map:rpki-extcommunity"))
289 #define IS_MATCH_PROBABILITY(C) \
290 (strmatch(C, "frr-bgp-route-map:probability"))
291 #define IS_MATCH_SRC_VRF(C) \
292 (strmatch(C, "frr-bgp-route-map:source-vrf"))
293 #define IS_MATCH_PEER(C) (strmatch(C, "frr-bgp-route-map:peer"))
294 #define IS_MATCH_AS_LIST(C) \
295 (strmatch(C, "frr-bgp-route-map:as-path-list"))
296 #define IS_MATCH_MAC_LIST(C) \
297 (strmatch(C, "frr-bgp-route-map:mac-address-list"))
298 #define IS_MATCH_EVPN_ROUTE_TYPE(C) \
299 (strmatch(C, "frr-bgp-route-map:evpn-route-type"))
300 #define IS_MATCH_EVPN_DEFAULT_ROUTE(C) \
301 (strmatch(C, "frr-bgp-route-map:evpn-default-route"))
302 #define IS_MATCH_EVPN_VNI(C) \
303 (strmatch(C, "frr-bgp-route-map:evpn-vni"))
304 #define IS_MATCH_EVPN_DEFAULT_ROUTE(C) \
305 (strmatch(C, "frr-bgp-route-map:evpn-default-route"))
306 #define IS_MATCH_EVPN_RD(C) \
307 (strmatch(C, "frr-bgp-route-map:evpn-rd"))
308 #define IS_MATCH_ROUTE_SRC(C) \
309 (strmatch(C, "frr-bgp-route-map:ip-route-source"))
310 #define IS_MATCH_ROUTE_SRC_PL(C) \
311 (strmatch(C, "frr-bgp-route-map:ip-route-source-prefix-list"))
312 #define IS_MATCH_COMMUNITY(C) \
313 (strmatch(C, "frr-bgp-route-map:match-community"))
314 #define IS_MATCH_LCOMMUNITY(C) \
315 (strmatch(C, "frr-bgp-route-map:match-large-community"))
316 #define IS_MATCH_EXTCOMMUNITY(C) \
317 (strmatch(C, "frr-bgp-route-map:match-extcommunity"))
318 #define IS_MATCH_IPV4_NH(C) \
319 (strmatch(C, "frr-bgp-route-map:ipv4-nexthop"))
320 #define IS_MATCH_IPV6_NH(C) \
321 (strmatch(C, "frr-bgp-route-map:ipv6-nexthop"))
322
323 /* Route-map set actions */
324 #define IS_SET_IPv4_NH(A) \
325 (strmatch(A, "frr-route-map:ipv4-next-hop"))
326 #define IS_SET_IPv6_NH(A) \
327 (strmatch(A, "frr-route-map:ipv6-next-hop"))
328 #define IS_SET_METRIC(A) \
329 (strmatch(A, "frr-route-map:set-metric"))
330 #define IS_SET_TAG(A) (strmatch(A, "frr-route-map:set-tag"))
331 #define IS_SET_SR_TE_COLOR(A) \
332 (strmatch(A, "frr-route-map:set-sr-te-color"))
333 /* Zebra route-map set actions */
334 #define IS_SET_SRC(A) \
335 (strmatch(A, "frr-zebra-route-map:src-address"))
336 /* OSPF route-map set actions */
337 #define IS_SET_METRIC_TYPE(A) \
338 (strmatch(A, "frr-ospf-route-map:metric-type"))
339 #define IS_SET_FORWARDING_ADDR(A) \
340 (strmatch(A, "frr-ospf6-route-map:forwarding-address"))
341 /* BGP route-map_set actions */
342 #define IS_SET_WEIGHT(A) \
343 (strmatch(A, "frr-bgp-route-map:weight"))
344 #define IS_SET_TABLE(A) (strmatch(A, "frr-bgp-route-map:table"))
345 #define IS_SET_LOCAL_PREF(A) \
346 (strmatch(A, "frr-bgp-route-map:set-local-preference"))
347 #define IS_SET_LABEL_INDEX(A) \
348 (strmatch(A, "frr-bgp-route-map:label-index"))
349 #define IS_SET_DISTANCE(A) \
350 (strmatch(A, "frr-bgp-route-map:distance"))
351 #define IS_SET_ORIGIN(A) \
352 (strmatch(A, "frr-bgp-route-map:set-origin"))
353 #define IS_SET_ATOMIC_AGGREGATE(A) \
354 (strmatch(A, "frr-bgp-route-map:atomic-aggregate"))
355 #define IS_SET_AIGP_METRIC(A) (strmatch(A, "frr-bgp-route-map:aigp-metric"))
356 #define IS_SET_ORIGINATOR_ID(A) \
357 (strmatch(A, "frr-bgp-route-map:originator-id"))
358 #define IS_SET_COMM_LIST_DEL(A) \
359 (strmatch(A, "frr-bgp-route-map:comm-list-delete"))
360 #define IS_SET_LCOMM_LIST_DEL(A) \
361 (strmatch(A, "frr-bgp-route-map:large-comm-list-delete"))
362 #define IS_SET_LCOMMUNITY(A) \
363 (strmatch(A, "frr-bgp-route-map:set-large-community"))
364 #define IS_SET_COMMUNITY(A) \
365 (strmatch(A, "frr-bgp-route-map:set-community"))
366 #define IS_SET_EXTCOMMUNITY_NONE(A) \
367 (strmatch(A, "frr-bgp-route-map:set-extcommunity-none"))
368 #define IS_SET_EXTCOMMUNITY_RT(A) \
369 (strmatch(A, "frr-bgp-route-map:set-extcommunity-rt"))
370 #define IS_SET_EXTCOMMUNITY_SOO(A) \
371 (strmatch(A, "frr-bgp-route-map:set-extcommunity-soo"))
372 #define IS_SET_EXTCOMMUNITY_LB(A) \
373 (strmatch(A, "frr-bgp-route-map:set-extcommunity-lb"))
374 #define IS_SET_AGGREGATOR(A) \
375 (strmatch(A, "frr-bgp-route-map:aggregator"))
376 #define IS_SET_AS_PREPEND(A) \
377 (strmatch(A, "frr-bgp-route-map:as-path-prepend"))
378 #define IS_SET_AS_EXCLUDE(A) \
379 (strmatch(A, "frr-bgp-route-map:as-path-exclude"))
380 #define IS_SET_AS_REPLACE(A) (strmatch(A, "frr-bgp-route-map:as-path-replace"))
381 #define IS_SET_IPV6_NH_GLOBAL(A) \
382 (strmatch(A, "frr-bgp-route-map:ipv6-nexthop-global"))
383 #define IS_SET_IPV6_VPN_NH(A) \
384 (strmatch(A, "frr-bgp-route-map:ipv6-vpn-address"))
385 #define IS_SET_IPV6_PEER_ADDR(A) \
386 (strmatch(A, "frr-bgp-route-map:ipv6-peer-address"))
387 #define IS_SET_IPV6_PREFER_GLOBAL(A) \
388 (strmatch(A, "frr-bgp-route-map:ipv6-prefer-global"))
389 #define IS_SET_IPV4_VPN_NH(A) \
390 (strmatch(A, "frr-bgp-route-map:ipv4-vpn-address"))
391 #define IS_SET_BGP_IPV4_NH(A) \
392 (strmatch(A, "frr-bgp-route-map:set-ipv4-nexthop"))
393 #define IS_SET_BGP_EVPN_GATEWAY_IP_IPV4(A) \
394 (strmatch(A, "frr-bgp-route-map:set-evpn-gateway-ip-ipv4"))
395 #define IS_SET_BGP_EVPN_GATEWAY_IP_IPV6(A) \
396 (strmatch(A, "frr-bgp-route-map:set-evpn-gateway-ip-ipv6"))
397 #define IS_SET_BGP_L3VPN_NEXTHOP_ENCAPSULATION(A) \
398 (strmatch(A, "frr-bgp-route-map:set-l3vpn-nexthop-encapsulation"))
399
400 enum ecommunity_lb_type {
401 EXPLICIT_BANDWIDTH,
402 CUMULATIVE_BANDWIDTH,
403 COMPUTED_BANDWIDTH
404 };
405
406 /* Prototypes. */
407 extern void route_map_init(void);
408
409 /*
410 * This should only be called on shutdown
411 * Additionally this function sets the hooks to NULL
412 * before any processing is done.
413 */
414 extern void route_map_finish(void);
415
416 /* Add match statement to route map. */
417 extern enum rmap_compile_rets route_map_add_match(struct route_map_index *index,
418 const char *match_name,
419 const char *match_arg,
420 route_map_event_t type);
421
422 /* Delete specified route match rule. */
423 extern enum rmap_compile_rets
424 route_map_delete_match(struct route_map_index *index,
425 const char *match_name, const char *match_arg,
426 route_map_event_t type);
427
428 extern const char *route_map_get_match_arg(struct route_map_index *index,
429 const char *match_name);
430
431 /* Add route-map set statement to the route map. */
432 extern enum rmap_compile_rets route_map_add_set(struct route_map_index *index,
433 const char *set_name,
434 const char *set_arg);
435
436 /* Delete route map set rule. */
437 extern enum rmap_compile_rets
438 route_map_delete_set(struct route_map_index *index,
439 const char *set_name, const char *set_arg);
440
441 /* struct route_map_rule_cmd is kept const in order to not have writable
442 * function pointers (which is a security benefit.) Hence, below struct is
443 * used as proxy for hashing these for by-name lookup.
444 */
445
446 PREDECL_HASH(rmap_cmd_name);
447
448 struct route_map_rule_cmd_proxy {
449 struct rmap_cmd_name_item itm;
450 const struct route_map_rule_cmd *cmd;
451 };
452
453 /* ... and just automatically create a proxy struct for each call location
454 * to route_map_install_{match,set} to avoid unnecessarily added boilerplate
455 * for each route-map user
456 */
457
458 #define route_map_install_match(c) \
459 do { \
460 static struct route_map_rule_cmd_proxy proxy = {.cmd = c}; \
461 _route_map_install_match(&proxy); \
462 } while (0)
463
464 #define route_map_install_set(c) \
465 do { \
466 static struct route_map_rule_cmd_proxy proxy = {.cmd = c}; \
467 _route_map_install_set(&proxy); \
468 } while (0)
469
470 /* Install rule command to the match list. */
471 extern void _route_map_install_match(struct route_map_rule_cmd_proxy *proxy);
472
473 /*
474 * Install rule command to the set list.
475 *
476 * When installing a particular item, Allow a difference of handling
477 * of bad cli inputted(return NULL) -vs- this particular daemon cannot use
478 * this form of the command(return a pointer and handle it appropriately
479 * in the apply command). See 'set metric' command
480 * as it is handled in ripd/ripngd and ospfd.
481 */
482 extern void _route_map_install_set(struct route_map_rule_cmd_proxy *proxy);
483
484 /* Lookup route map by name. */
485 extern struct route_map *route_map_lookup_by_name(const char *name);
486
487 /* Simple helper to warn if route-map does not exist. */
488 struct route_map *route_map_lookup_warn_noexist(struct vty *vty, const char *name);
489
490 /* Apply route map to the object. */
491 extern route_map_result_t route_map_apply_ext(struct route_map *map,
492 const struct prefix *prefix,
493 void *match_object,
494 void *set_object, int *pref);
495 #define route_map_apply(map, prefix, object) \
496 route_map_apply_ext(map, prefix, object, object, NULL)
497
498 extern void route_map_add_hook(void (*func)(const char *));
499 extern void route_map_delete_hook(void (*func)(const char *));
500
501 /*
502 * This is the callback for when something has changed about a
503 * route-map. The interested parties can register to receive
504 * this data.
505 *
506 * name - Is the name of the changed route-map
507 */
508 extern void route_map_event_hook(void (*func)(const char *name));
509 extern int route_map_mark_updated(const char *name);
510 extern void route_map_walk_update_list(void (*update_fn)(char *name));
511 extern void route_map_upd8_dependency(route_map_event_t type, const char *arg,
512 const char *rmap_name);
513 extern void route_map_notify_dependencies(const char *affected_name,
514 route_map_event_t event);
515 extern void
516 route_map_notify_pentry_dependencies(const char *affected_name,
517 struct prefix_list_entry *pentry,
518 route_map_event_t event);
519 extern int generic_match_add(struct route_map_index *index,
520 const char *command, const char *arg,
521 route_map_event_t type,
522 char *errmsg, size_t errmsg_len);
523 extern int generic_match_delete(struct route_map_index *index,
524 const char *command, const char *arg,
525 route_map_event_t type,
526 char *errmsg, size_t errmsg_len);
527
528 extern int generic_set_add(struct route_map_index *index,
529 const char *command, const char *arg,
530 char *errmsg, size_t errmsg_len);
531 extern int generic_set_delete(struct route_map_index *index,
532 const char *command, const char *arg,
533 char *errmsg, size_t errmsg_len);
534
535
536 /* match interface */
537 extern void route_map_match_interface_hook(int (*func)(
538 struct route_map_index *index, const char *command,
539 const char *arg, route_map_event_t type,
540 char *errmsg, size_t errmsg_len));
541 /* no match interface */
542 extern void route_map_no_match_interface_hook(int (*func)(
543 struct route_map_index *index, const char *command,
544 const char *arg, route_map_event_t type,
545 char *errmsg, size_t errmsg_len));
546 /* match ip address */
547 extern void route_map_match_ip_address_hook(int (*func)(
548 struct route_map_index *index, const char *command,
549 const char *arg, route_map_event_t type,
550 char *errmsg, size_t errmsg_len));
551 /* no match ip address */
552 extern void route_map_no_match_ip_address_hook(int (*func)(
553 struct route_map_index *index, const char *command,
554 const char *arg, route_map_event_t type,
555 char *errmsg, size_t errmsg_len));
556 /* match ip address prefix list */
557 extern void route_map_match_ip_address_prefix_list_hook(int (*func)(
558 struct route_map_index *index, const char *command,
559 const char *arg, route_map_event_t type,
560 char *errmsg, size_t errmsg_len));
561 /* no match ip address prefix list */
562 extern void route_map_no_match_ip_address_prefix_list_hook(int (*func)(
563 struct route_map_index *index, const char *command,
564 const char *arg, route_map_event_t type,
565 char *errmsg, size_t errmsg_len));
566 /* match ip next hop */
567 extern void route_map_match_ip_next_hop_hook(int (*func)(
568 struct route_map_index *index, const char *command,
569 const char *arg, route_map_event_t type,
570 char *errmsg, size_t errmsg_len));
571 /* no match ip next hop */
572 extern void route_map_no_match_ip_next_hop_hook(int (*func)(
573 struct route_map_index *index, const char *command, const char *arg,
574 route_map_event_t type, char *errmsg, size_t errmsg_len));
575 /* match ipv6 next hop */
576 extern void route_map_match_ipv6_next_hop_hook(int (*func)(
577 struct route_map_index *index, const char *command, const char *arg,
578 route_map_event_t type, char *errmsg, size_t errmsg_len));
579 /* no match ipv6 next hop */
580 extern void route_map_no_match_ipv6_next_hop_hook(int (*func)(
581 struct route_map_index *index, const char *command, const char *arg,
582 route_map_event_t type, char *errmsg, size_t errmsg_len));
583 /* match ip next hop prefix list */
584 extern void route_map_match_ip_next_hop_prefix_list_hook(int (*func)(
585 struct route_map_index *index, const char *command,
586 const char *arg, route_map_event_t type,
587 char *errmsg, size_t errmsg_len));
588 /* no match ip next hop prefix list */
589 extern void route_map_no_match_ip_next_hop_prefix_list_hook(int (*func)(
590 struct route_map_index *index, const char *command,
591 const char *arg, route_map_event_t type,
592 char *errmsg, size_t errmsg_len));
593 /* match ip next hop type */
594 extern void route_map_match_ip_next_hop_type_hook(int (*func)(
595 struct route_map_index *index, const char *command,
596 const char *arg, route_map_event_t type,
597 char *errmsg, size_t errmsg_len));
598 /* no match ip next hop type */
599 extern void route_map_no_match_ip_next_hop_type_hook(int (*func)(
600 struct route_map_index *index, const char *command,
601 const char *arg, route_map_event_t type,
602 char *errmsg, size_t errmsg_len));
603 /* match ipv6 address */
604 extern void route_map_match_ipv6_address_hook(int (*func)(
605 struct route_map_index *index, const char *command,
606 const char *arg, route_map_event_t type,
607 char *errmsg, size_t errmsg_len));
608 /* no match ipv6 address */
609 extern void route_map_no_match_ipv6_address_hook(int (*func)(
610 struct route_map_index *index, const char *command,
611 const char *arg, route_map_event_t type,
612 char *errmsg, size_t errmsg_len));
613 /* match ipv6 address prefix list */
614 extern void route_map_match_ipv6_address_prefix_list_hook(int (*func)(
615 struct route_map_index *index, const char *command,
616 const char *arg, route_map_event_t type,
617 char *errmsg, size_t errmsg_len));
618 /* no match ipv6 address prefix list */
619 extern void route_map_no_match_ipv6_address_prefix_list_hook(int (*func)(
620 struct route_map_index *index, const char *command,
621 const char *arg, route_map_event_t type,
622 char *errmsg, size_t errmsg_len));
623 /* match ipv6 next-hop type */
624 extern void route_map_match_ipv6_next_hop_type_hook(int (*func)(
625 struct route_map_index *index, const char *command,
626 const char *arg, route_map_event_t type,
627 char *errmsg, size_t errmsg_len));
628 /* no match ipv6 next-hop type */
629 extern void route_map_no_match_ipv6_next_hop_type_hook(int (*func)(
630 struct route_map_index *index, const char *command,
631 const char *arg, route_map_event_t type,
632 char *errmsg, size_t errmsg_len));
633 /* match ipv6 next-hop prefix-list */
634 extern void route_map_match_ipv6_next_hop_prefix_list_hook(int (*func)(
635 struct route_map_index *index, const char *command, const char *arg,
636 route_map_event_t type, char *errmsg, size_t errmsg_len));
637 /* no match ipv6 next-hop prefix-list */
638 extern void route_map_no_match_ipv6_next_hop_prefix_list_hook(int (*func)(
639 struct route_map_index *index, const char *command, const char *arg,
640 route_map_event_t type, char *errmsg, size_t errmsg_len));
641 /* match metric */
642 extern void route_map_match_metric_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 /* no match metric */
647 extern void route_map_no_match_metric_hook(int (*func)(
648 struct route_map_index *index, const char *command,
649 const char *arg, route_map_event_t type,
650 char *errmsg, size_t errmsg_len));
651 /* match tag */
652 extern void route_map_match_tag_hook(int (*func)(
653 struct route_map_index *index, const char *command,
654 const char *arg, route_map_event_t type,
655 char *errmsg, size_t errmsg_len));
656 /* no match tag */
657 extern void route_map_no_match_tag_hook(int (*func)(
658 struct route_map_index *index, const char *command,
659 const char *arg, route_map_event_t type,
660 char *errmsg, size_t errmsg_len));
661 /* set sr-te color */
662 extern void route_map_set_srte_color_hook(
663 int (*func)(struct route_map_index *index,
664 const char *command, const char *arg,
665 char *errmsg, size_t errmsg_len));
666 /* no set sr-te color */
667 extern void route_map_no_set_srte_color_hook(
668 int (*func)(struct route_map_index *index,
669 const char *command, const char *arg,
670 char *errmsg, size_t errmsg_len));
671 /* set ip nexthop */
672 extern void route_map_set_ip_nexthop_hook(
673 int (*func)(struct route_map_index *index,
674 const char *command, const char *arg,
675 char *errmsg, size_t errmsg_len));
676 /* no set ip nexthop */
677 extern void route_map_no_set_ip_nexthop_hook(
678 int (*func)(struct route_map_index *index,
679 const char *command, const char *arg,
680 char *errmsg, size_t errmsg_len));
681 /* set ipv6 nexthop local */
682 extern void route_map_set_ipv6_nexthop_local_hook(
683 int (*func)(struct route_map_index *index,
684 const char *command, const char *arg,
685 char *errmsg, size_t errmsg_len));
686 /* no set ipv6 nexthop local */
687 extern void route_map_no_set_ipv6_nexthop_local_hook(
688 int (*func)(struct route_map_index *index,
689 const char *command, const char *arg,
690 char *errmsg, size_t errmsg_len));
691 /* set metric */
692 extern void route_map_set_metric_hook(int (*func)(struct route_map_index *index,
693 const char *command,
694 const char *arg,
695 char *errmsg,
696 size_t errmsg_len));
697 /* no set metric */
698 extern void route_map_no_set_metric_hook(
699 int (*func)(struct route_map_index *index,
700 const char *command, const char *arg,
701 char *errmsg, size_t errmsg_len));
702 /* set tag */
703 extern void route_map_set_tag_hook(int (*func)(struct route_map_index *index,
704 const char *command,
705 const char *arg,
706 char *errmsg,
707 size_t errmsg_len));
708 /* no set tag */
709 extern void route_map_no_set_tag_hook(int (*func)(struct route_map_index *index,
710 const char *command,
711 const char *arg,
712 char *errmsg,
713 size_t errmsg_len));
714
715 extern void *route_map_rule_tag_compile(const char *arg);
716 extern void route_map_rule_tag_free(void *rule);
717
718 /* Increment the route-map used counter */
719 extern void route_map_counter_increment(struct route_map *map);
720
721 /* Decrement the route-map used counter */
722 extern void route_map_counter_decrement(struct route_map *map);
723
724 /* Route map hooks data structure. */
725 struct route_map_match_set_hooks {
726 /* match interface */
727 int (*match_interface)(struct route_map_index *index,
728 const char *command, const char *arg,
729 route_map_event_t type,
730 char *errmsg, size_t errmsg_len);
731
732 /* no match interface */
733 int (*no_match_interface)(struct route_map_index *index,
734 const char *command, const char *arg,
735 route_map_event_t type,
736 char *errmsg, size_t errmsg_len);
737
738 /* match ip address */
739 int (*match_ip_address)(struct route_map_index *index,
740 const char *command, const char *arg,
741 route_map_event_t type,
742 char *errmsg, size_t errmsg_len);
743
744 /* no match ip address */
745 int (*no_match_ip_address)(struct route_map_index *index,
746 const char *command, const char *arg,
747 route_map_event_t type,
748 char *errmsg, size_t errmsg_len);
749
750 /* match ip address prefix list */
751 int (*match_ip_address_prefix_list)(struct route_map_index *index,
752 const char *command,
753 const char *arg,
754 route_map_event_t type,
755 char *errmsg, size_t errmsg_len);
756
757 /* no match ip address prefix list */
758 int (*no_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 /* match ip next hop */
765 int (*match_ip_next_hop)(struct route_map_index *index,
766 const char *command, const char *arg,
767 route_map_event_t type,
768 char *errmsg, size_t errmsg_len);
769
770 /* no match ip next hop */
771 int (*no_match_ip_next_hop)(struct route_map_index *index,
772 const char *command, const char *arg,
773 route_map_event_t type,
774 char *errmsg, size_t errmsg_len);
775
776 /* match ipv6 next hop */
777 int (*match_ipv6_next_hop)(struct route_map_index *index,
778 const char *command, const char *arg,
779 route_map_event_t type, char *errmsg,
780 size_t errmsg_len);
781
782 /* no match ipv6 next hop */
783 int (*no_match_ipv6_next_hop)(struct route_map_index *index,
784 const char *command, const char *arg,
785 route_map_event_t type, char *errmsg,
786 size_t errmsg_len);
787
788 /* match ipv6 next hop prefix-list */
789 int (*match_ipv6_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 ipv6 next-hop prefix-list */
796 int (*no_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,
801 size_t errmsg_len);
802
803 /* match ip next hop prefix list */
804 int (*match_ip_next_hop_prefix_list)(struct route_map_index *index,
805 const char *command,
806 const char *arg,
807 route_map_event_t type,
808 char *errmsg, size_t errmsg_len);
809
810 /* no match ip next hop prefix list */
811 int (*no_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,
816 size_t errmsg_len);
817
818 /* match ip next-hop type */
819 int (*match_ip_next_hop_type)(struct route_map_index *index,
820 const char *command,
821 const char *arg,
822 route_map_event_t type,
823 char *errmsg,
824 size_t errmsg_len);
825
826 /* no match ip next-hop type */
827 int (*no_match_ip_next_hop_type)(struct route_map_index *index,
828 const char *command,
829 const char *arg,
830 route_map_event_t type,
831 char *errmsg,
832 size_t errmsg_len);
833
834 /* match ipv6 address */
835 int (*match_ipv6_address)(struct route_map_index *index,
836 const char *command, const char *arg,
837 route_map_event_t type,
838 char *errmsg, size_t errmsg_len);
839
840 /* no match ipv6 address */
841 int (*no_match_ipv6_address)(struct route_map_index *index,
842 const char *command, const char *arg,
843 route_map_event_t type,
844 char *errmsg, size_t errmsg_len);
845
846
847 /* match ipv6 address prefix list */
848 int (*match_ipv6_address_prefix_list)(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 address prefix list */
855 int (*no_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,
860 size_t errmsg_len);
861
862 /* match ipv6 next-hop type */
863 int (*match_ipv6_next_hop_type)(struct route_map_index *index,
864 const char *command,
865 const char *arg,
866 route_map_event_t type,
867 char *errmsg, size_t errmsg_len);
868
869 /* no match ipv6 next-hop type */
870 int (*no_match_ipv6_next_hop_type)(struct route_map_index *index,
871 const char *command, const char *arg,
872 route_map_event_t type,
873 char *errmsg, size_t errmsg_len);
874
875 /* match metric */
876 int (*match_metric)(struct route_map_index *index,
877 const char *command, const char *arg,
878 route_map_event_t type,
879 char *errmsg, size_t errmsg_len);
880
881 /* no match metric */
882 int (*no_match_metric)(struct route_map_index *index,
883 const char *command, const char *arg,
884 route_map_event_t type,
885 char *errmsg, size_t errmsg_len);
886
887 /* match tag */
888 int (*match_tag)(struct route_map_index *index,
889 const char *command, const char *arg,
890 route_map_event_t type,
891 char *errmsg, size_t errmsg_len);
892
893 /* no match tag */
894 int (*no_match_tag)(struct route_map_index *index,
895 const char *command, const char *arg,
896 route_map_event_t type,
897 char *errmsg, size_t errmsg_len);
898
899 /* set sr-te color */
900 int (*set_srte_color)(struct route_map_index *index,
901 const char *command, const char *arg,
902 char *errmsg, size_t errmsg_len);
903
904 /* no set sr-te color */
905 int (*no_set_srte_color)(struct route_map_index *index,
906 const char *command, const char *arg,
907 char *errmsg, size_t errmsg_len);
908
909 /* set ip nexthop */
910 int (*set_ip_nexthop)(struct route_map_index *index,
911 const char *command, const char *arg,
912 char *errmsg, size_t errmsg_len);
913
914 /* no set ip nexthop */
915 int (*no_set_ip_nexthop)(struct route_map_index *index,
916 const char *command, const char *arg,
917 char *errmsg, size_t errmsg_len);
918
919 /* set ipv6 nexthop local */
920 int (*set_ipv6_nexthop_local)(struct route_map_index *index,
921 const char *command, const char *arg,
922 char *errmsg, size_t errmsg_len);
923
924 /* no set ipv6 nexthop local */
925 int (*no_set_ipv6_nexthop_local)(struct route_map_index *index,
926 const char *command, const char *arg,
927 char *errmsg, size_t errmsg_len);
928
929 /* set metric */
930 int (*set_metric)(struct route_map_index *index,
931 const char *command, const char *arg,
932 char *errmsg, size_t errmsg_len);
933
934 /* no set metric */
935 int (*no_set_metric)(struct route_map_index *index,
936 const char *command, const char *arg,
937 char *errmsg, size_t errmsg_len);
938
939 /* set tag */
940 int (*set_tag)(struct route_map_index *index,
941 const char *command, const char *arg,
942 char *errmsg, size_t errmsg_len);
943
944 /* no set tag */
945 int (*no_set_tag)(struct route_map_index *index,
946 const char *command, const char *arg,
947 char *errmsg, size_t errmsg_len);
948 };
949
950 extern struct route_map_match_set_hooks rmap_match_set_hook;
951
952 /* Making route map list. */
953 struct route_map_list {
954 struct route_map *head;
955 struct route_map *tail;
956
957 void (*add_hook)(const char *);
958 void (*delete_hook)(const char *);
959 void (*event_hook)(const char *);
960 };
961
962 extern struct route_map_list route_map_master;
963
964 extern struct route_map *route_map_get(const char *name);
965 extern void route_map_delete(struct route_map *map);
966 extern struct route_map_index *route_map_index_get(struct route_map *map,
967 enum route_map_type type,
968 int pref);
969 extern void route_map_index_delete(struct route_map_index *index, int notify);
970
971 /* routemap_northbound.c */
972 typedef int (*routemap_match_hook_fun)(struct route_map_index *rmi,
973 const char *command, const char *arg,
974 route_map_event_t event,
975 char *errmsg, size_t errmsg_len);
976 typedef int (*routemap_set_hook_fun)(struct route_map_index *rmi,
977 const char *command, const char *arg,
978 char *errmsg, size_t errmsg_len);
979 struct routemap_hook_context {
980 struct route_map_index *rhc_rmi;
981 const char *rhc_rule;
982 route_map_event_t rhc_event;
983 routemap_set_hook_fun rhc_shook;
984 routemap_match_hook_fun rhc_mhook;
985 TAILQ_ENTRY(routemap_hook_context) rhc_entry;
986 };
987
988 int lib_route_map_entry_match_destroy(struct nb_cb_destroy_args *args);
989 int lib_route_map_entry_set_destroy(struct nb_cb_destroy_args *args);
990
991 struct routemap_hook_context *
992 routemap_hook_context_insert(struct route_map_index *rmi);
993 void routemap_hook_context_free(struct routemap_hook_context *rhc);
994
995 extern const struct frr_yang_module_info frr_route_map_info;
996
997 /* routemap_cli.c */
998 extern int route_map_instance_cmp(const struct lyd_node *dnode1,
999 const struct lyd_node *dnode2);
1000 extern void route_map_instance_show(struct vty *vty,
1001 const struct lyd_node *dnode,
1002 bool show_defaults);
1003 extern void route_map_instance_show_end(struct vty *vty,
1004 const struct lyd_node *dnode);
1005 extern void route_map_condition_show(struct vty *vty,
1006 const struct lyd_node *dnode,
1007 bool show_defaults);
1008 extern void route_map_action_show(struct vty *vty, const struct lyd_node *dnode,
1009 bool show_defaults);
1010 extern void route_map_exit_policy_show(struct vty *vty,
1011 const struct lyd_node *dnode,
1012 bool show_defaults);
1013 extern void route_map_call_show(struct vty *vty, const struct lyd_node *dnode,
1014 bool show_defaults);
1015 extern void route_map_description_show(struct vty *vty,
1016 const struct lyd_node *dnode,
1017 bool show_defaults);
1018 extern void route_map_optimization_disabled_show(struct vty *vty,
1019 const struct lyd_node *dnode,
1020 bool show_defaults);
1021 extern void route_map_cli_init(void);
1022
1023 extern void route_map_show_debug(struct vty *vty);
1024
1025 #ifdef __cplusplus
1026 }
1027 #endif
1028
1029 #endif /* _ZEBRA_ROUTEMAP_H */