]> git.proxmox.com Git - mirror_frr.git/blob - lib/routemap.h
Merge pull request #13455 from sri-mohan1/srib-ldpd
[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_MIN_METRIC(A) (strmatch(A, "frr-route-map:set-min-metric"))
316 #define IS_SET_MAX_METRIC(A) (strmatch(A, "frr-route-map:set-max-metric"))
317 #define IS_SET_TAG(A) (strmatch(A, "frr-route-map:set-tag"))
318 #define IS_SET_SR_TE_COLOR(A) \
319 (strmatch(A, "frr-route-map:set-sr-te-color"))
320 /* Zebra route-map set actions */
321 #define IS_SET_SRC(A) \
322 (strmatch(A, "frr-zebra-route-map:src-address"))
323 /* OSPF route-map set actions */
324 #define IS_SET_METRIC_TYPE(A) \
325 (strmatch(A, "frr-ospf-route-map:metric-type"))
326 #define IS_SET_FORWARDING_ADDR(A) \
327 (strmatch(A, "frr-ospf6-route-map:forwarding-address"))
328 /* BGP route-map_set actions */
329 #define IS_SET_WEIGHT(A) \
330 (strmatch(A, "frr-bgp-route-map:weight"))
331 #define IS_SET_TABLE(A) (strmatch(A, "frr-bgp-route-map:table"))
332 #define IS_SET_LOCAL_PREF(A) \
333 (strmatch(A, "frr-bgp-route-map:set-local-preference"))
334 #define IS_SET_LABEL_INDEX(A) \
335 (strmatch(A, "frr-bgp-route-map:label-index"))
336 #define IS_SET_DISTANCE(A) \
337 (strmatch(A, "frr-bgp-route-map:distance"))
338 #define IS_SET_ORIGIN(A) \
339 (strmatch(A, "frr-bgp-route-map:set-origin"))
340 #define IS_SET_ATOMIC_AGGREGATE(A) \
341 (strmatch(A, "frr-bgp-route-map:atomic-aggregate"))
342 #define IS_SET_AIGP_METRIC(A) (strmatch(A, "frr-bgp-route-map:aigp-metric"))
343 #define IS_SET_ORIGINATOR_ID(A) \
344 (strmatch(A, "frr-bgp-route-map:originator-id"))
345 #define IS_SET_COMM_LIST_DEL(A) \
346 (strmatch(A, "frr-bgp-route-map:comm-list-delete"))
347 #define IS_SET_LCOMM_LIST_DEL(A) \
348 (strmatch(A, "frr-bgp-route-map:large-comm-list-delete"))
349 #define IS_SET_LCOMMUNITY(A) \
350 (strmatch(A, "frr-bgp-route-map:set-large-community"))
351 #define IS_SET_COMMUNITY(A) \
352 (strmatch(A, "frr-bgp-route-map:set-community"))
353 #define IS_SET_EXTCOMMUNITY_NONE(A) \
354 (strmatch(A, "frr-bgp-route-map:set-extcommunity-none"))
355 #define IS_SET_EXTCOMMUNITY_RT(A) \
356 (strmatch(A, "frr-bgp-route-map:set-extcommunity-rt"))
357 #define IS_SET_EXTCOMMUNITY_NT(A) \
358 (strmatch(A, "frr-bgp-route-map:set-extcommunity-nt"))
359 #define IS_SET_EXTCOMMUNITY_SOO(A) \
360 (strmatch(A, "frr-bgp-route-map:set-extcommunity-soo"))
361 #define IS_SET_EXTCOMMUNITY_LB(A) \
362 (strmatch(A, "frr-bgp-route-map:set-extcommunity-lb"))
363 #define IS_SET_AGGREGATOR(A) \
364 (strmatch(A, "frr-bgp-route-map:aggregator"))
365 #define IS_SET_AS_PREPEND(A) \
366 (strmatch(A, "frr-bgp-route-map:as-path-prepend"))
367 #define IS_SET_AS_EXCLUDE(A) \
368 (strmatch(A, "frr-bgp-route-map:as-path-exclude"))
369 #define IS_SET_AS_REPLACE(A) (strmatch(A, "frr-bgp-route-map:as-path-replace"))
370 #define IS_SET_IPV6_NH_GLOBAL(A) \
371 (strmatch(A, "frr-bgp-route-map:ipv6-nexthop-global"))
372 #define IS_SET_IPV6_VPN_NH(A) \
373 (strmatch(A, "frr-bgp-route-map:ipv6-vpn-address"))
374 #define IS_SET_IPV6_PEER_ADDR(A) \
375 (strmatch(A, "frr-bgp-route-map:ipv6-peer-address"))
376 #define IS_SET_IPV6_PREFER_GLOBAL(A) \
377 (strmatch(A, "frr-bgp-route-map:ipv6-prefer-global"))
378 #define IS_SET_IPV4_VPN_NH(A) \
379 (strmatch(A, "frr-bgp-route-map:ipv4-vpn-address"))
380 #define IS_SET_BGP_IPV4_NH(A) \
381 (strmatch(A, "frr-bgp-route-map:set-ipv4-nexthop"))
382 #define IS_SET_BGP_EVPN_GATEWAY_IP_IPV4(A) \
383 (strmatch(A, "frr-bgp-route-map:set-evpn-gateway-ip-ipv4"))
384 #define IS_SET_BGP_EVPN_GATEWAY_IP_IPV6(A) \
385 (strmatch(A, "frr-bgp-route-map:set-evpn-gateway-ip-ipv6"))
386 #define IS_SET_BGP_L3VPN_NEXTHOP_ENCAPSULATION(A) \
387 (strmatch(A, "frr-bgp-route-map:set-l3vpn-nexthop-encapsulation"))
388
389 enum ecommunity_lb_type {
390 EXPLICIT_BANDWIDTH,
391 CUMULATIVE_BANDWIDTH,
392 COMPUTED_BANDWIDTH
393 };
394
395 /* Prototypes. */
396 extern void route_map_init(void);
397
398 /*
399 * This should only be called on shutdown
400 * Additionally this function sets the hooks to NULL
401 * before any processing is done.
402 */
403 extern void route_map_finish(void);
404
405 /* Add match statement to route map. */
406 extern enum rmap_compile_rets route_map_add_match(struct route_map_index *index,
407 const char *match_name,
408 const char *match_arg,
409 route_map_event_t type);
410
411 /* Delete specified route match rule. */
412 extern enum rmap_compile_rets
413 route_map_delete_match(struct route_map_index *index,
414 const char *match_name, const char *match_arg,
415 route_map_event_t type);
416
417 extern const char *route_map_get_match_arg(struct route_map_index *index,
418 const char *match_name);
419
420 /* Add route-map set statement to the route map. */
421 extern enum rmap_compile_rets route_map_add_set(struct route_map_index *index,
422 const char *set_name,
423 const char *set_arg);
424
425 /* Delete route map set rule. */
426 extern enum rmap_compile_rets
427 route_map_delete_set(struct route_map_index *index,
428 const char *set_name, const char *set_arg);
429
430 /* struct route_map_rule_cmd is kept const in order to not have writable
431 * function pointers (which is a security benefit.) Hence, below struct is
432 * used as proxy for hashing these for by-name lookup.
433 */
434
435 PREDECL_HASH(rmap_cmd_name);
436
437 struct route_map_rule_cmd_proxy {
438 struct rmap_cmd_name_item itm;
439 const struct route_map_rule_cmd *cmd;
440 };
441
442 /* ... and just automatically create a proxy struct for each call location
443 * to route_map_install_{match,set} to avoid unnecessarily added boilerplate
444 * for each route-map user
445 */
446
447 #define route_map_install_match(c) \
448 do { \
449 static struct route_map_rule_cmd_proxy proxy = {.cmd = c}; \
450 _route_map_install_match(&proxy); \
451 } while (0)
452
453 #define route_map_install_set(c) \
454 do { \
455 static struct route_map_rule_cmd_proxy proxy = {.cmd = c}; \
456 _route_map_install_set(&proxy); \
457 } while (0)
458
459 /* Install rule command to the match list. */
460 extern void _route_map_install_match(struct route_map_rule_cmd_proxy *proxy);
461
462 /*
463 * Install rule command to the set list.
464 *
465 * When installing a particular item, Allow a difference of handling
466 * of bad cli inputted(return NULL) -vs- this particular daemon cannot use
467 * this form of the command(return a pointer and handle it appropriately
468 * in the apply command). See 'set metric' command
469 * as it is handled in ripd/ripngd and ospfd.
470 */
471 extern void _route_map_install_set(struct route_map_rule_cmd_proxy *proxy);
472
473 /* Lookup route map by name. */
474 extern struct route_map *route_map_lookup_by_name(const char *name);
475
476 /* Simple helper to warn if route-map does not exist. */
477 struct route_map *route_map_lookup_warn_noexist(struct vty *vty, const char *name);
478
479 /* Apply route map to the object. */
480 extern route_map_result_t route_map_apply_ext(struct route_map *map,
481 const struct prefix *prefix,
482 void *match_object,
483 void *set_object, int *pref);
484 #define route_map_apply(map, prefix, object) \
485 route_map_apply_ext(map, prefix, object, object, NULL)
486
487 extern void route_map_add_hook(void (*func)(const char *));
488 extern void route_map_delete_hook(void (*func)(const char *));
489
490 /*
491 * This is the callback for when something has changed about a
492 * route-map. The interested parties can register to receive
493 * this data.
494 *
495 * name - Is the name of the changed route-map
496 */
497 extern void route_map_event_hook(void (*func)(const char *name));
498 extern int route_map_mark_updated(const char *name);
499 extern void route_map_walk_update_list(void (*update_fn)(char *name));
500 extern void route_map_upd8_dependency(route_map_event_t type, const char *arg,
501 const char *rmap_name);
502 extern void route_map_notify_dependencies(const char *affected_name,
503 route_map_event_t event);
504 extern void
505 route_map_notify_pentry_dependencies(const char *affected_name,
506 struct prefix_list_entry *pentry,
507 route_map_event_t event);
508 extern int generic_match_add(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 extern int generic_match_delete(struct route_map_index *index,
513 const char *command, const char *arg,
514 route_map_event_t type,
515 char *errmsg, size_t errmsg_len);
516
517 extern int generic_set_add(struct route_map_index *index,
518 const char *command, const char *arg,
519 char *errmsg, size_t errmsg_len);
520 extern int generic_set_delete(struct route_map_index *index,
521 const char *command, const char *arg,
522 char *errmsg, size_t errmsg_len);
523
524
525 /* match interface */
526 extern void route_map_match_interface_hook(int (*func)(
527 struct route_map_index *index, const char *command,
528 const char *arg, route_map_event_t type,
529 char *errmsg, size_t errmsg_len));
530 /* no match interface */
531 extern void route_map_no_match_interface_hook(int (*func)(
532 struct route_map_index *index, const char *command,
533 const char *arg, route_map_event_t type,
534 char *errmsg, size_t errmsg_len));
535 /* match ip address */
536 extern void route_map_match_ip_address_hook(int (*func)(
537 struct route_map_index *index, const char *command,
538 const char *arg, route_map_event_t type,
539 char *errmsg, size_t errmsg_len));
540 /* no match ip address */
541 extern void route_map_no_match_ip_address_hook(int (*func)(
542 struct route_map_index *index, const char *command,
543 const char *arg, route_map_event_t type,
544 char *errmsg, size_t errmsg_len));
545 /* match ip address prefix list */
546 extern void route_map_match_ip_address_prefix_list_hook(int (*func)(
547 struct route_map_index *index, const char *command,
548 const char *arg, route_map_event_t type,
549 char *errmsg, size_t errmsg_len));
550 /* no match ip address prefix list */
551 extern void route_map_no_match_ip_address_prefix_list_hook(int (*func)(
552 struct route_map_index *index, const char *command,
553 const char *arg, route_map_event_t type,
554 char *errmsg, size_t errmsg_len));
555 /* match ip next hop */
556 extern void route_map_match_ip_next_hop_hook(int (*func)(
557 struct route_map_index *index, const char *command,
558 const char *arg, route_map_event_t type,
559 char *errmsg, size_t errmsg_len));
560 /* no match ip next hop */
561 extern void route_map_no_match_ip_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 /* match ipv6 next hop */
565 extern void route_map_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 /* no match ipv6 next hop */
569 extern void route_map_no_match_ipv6_next_hop_hook(int (*func)(
570 struct route_map_index *index, const char *command, const char *arg,
571 route_map_event_t type, char *errmsg, size_t errmsg_len));
572 /* match ip next hop prefix list */
573 extern void route_map_match_ip_next_hop_prefix_list_hook(int (*func)(
574 struct route_map_index *index, const char *command,
575 const char *arg, route_map_event_t type,
576 char *errmsg, size_t errmsg_len));
577 /* no match ip next hop prefix list */
578 extern void route_map_no_match_ip_next_hop_prefix_list_hook(int (*func)(
579 struct route_map_index *index, const char *command,
580 const char *arg, route_map_event_t type,
581 char *errmsg, size_t errmsg_len));
582 /* match ip next hop type */
583 extern void route_map_match_ip_next_hop_type_hook(int (*func)(
584 struct route_map_index *index, const char *command,
585 const char *arg, route_map_event_t type,
586 char *errmsg, size_t errmsg_len));
587 /* no match ip next hop type */
588 extern void route_map_no_match_ip_next_hop_type_hook(int (*func)(
589 struct route_map_index *index, const char *command,
590 const char *arg, route_map_event_t type,
591 char *errmsg, size_t errmsg_len));
592 /* match ipv6 address */
593 extern void route_map_match_ipv6_address_hook(int (*func)(
594 struct route_map_index *index, const char *command,
595 const char *arg, route_map_event_t type,
596 char *errmsg, size_t errmsg_len));
597 /* no match ipv6 address */
598 extern void route_map_no_match_ipv6_address_hook(int (*func)(
599 struct route_map_index *index, const char *command,
600 const char *arg, route_map_event_t type,
601 char *errmsg, size_t errmsg_len));
602 /* match ipv6 address prefix list */
603 extern void route_map_match_ipv6_address_prefix_list_hook(int (*func)(
604 struct route_map_index *index, const char *command,
605 const char *arg, route_map_event_t type,
606 char *errmsg, size_t errmsg_len));
607 /* no match ipv6 address prefix list */
608 extern void route_map_no_match_ipv6_address_prefix_list_hook(int (*func)(
609 struct route_map_index *index, const char *command,
610 const char *arg, route_map_event_t type,
611 char *errmsg, size_t errmsg_len));
612 /* match ipv6 next-hop type */
613 extern void route_map_match_ipv6_next_hop_type_hook(int (*func)(
614 struct route_map_index *index, const char *command,
615 const char *arg, route_map_event_t type,
616 char *errmsg, size_t errmsg_len));
617 /* no match ipv6 next-hop type */
618 extern void route_map_no_match_ipv6_next_hop_type_hook(int (*func)(
619 struct route_map_index *index, const char *command,
620 const char *arg, route_map_event_t type,
621 char *errmsg, size_t errmsg_len));
622 /* match ipv6 next-hop prefix-list */
623 extern void route_map_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 /* no match ipv6 next-hop prefix-list */
627 extern void route_map_no_match_ipv6_next_hop_prefix_list_hook(int (*func)(
628 struct route_map_index *index, const char *command, const char *arg,
629 route_map_event_t type, char *errmsg, size_t errmsg_len));
630 /* match metric */
631 extern void route_map_match_metric_hook(int (*func)(
632 struct route_map_index *index, const char *command,
633 const char *arg, route_map_event_t type,
634 char *errmsg, size_t errmsg_len));
635 /* no match metric */
636 extern void route_map_no_match_metric_hook(int (*func)(
637 struct route_map_index *index, const char *command,
638 const char *arg, route_map_event_t type,
639 char *errmsg, size_t errmsg_len));
640 /* match tag */
641 extern void route_map_match_tag_hook(int (*func)(
642 struct route_map_index *index, const char *command,
643 const char *arg, route_map_event_t type,
644 char *errmsg, size_t errmsg_len));
645 /* no match tag */
646 extern void route_map_no_match_tag_hook(int (*func)(
647 struct route_map_index *index, const char *command,
648 const char *arg, route_map_event_t type,
649 char *errmsg, size_t errmsg_len));
650 /* set sr-te color */
651 extern void route_map_set_srte_color_hook(
652 int (*func)(struct route_map_index *index,
653 const char *command, const char *arg,
654 char *errmsg, size_t errmsg_len));
655 /* no set sr-te color */
656 extern void route_map_no_set_srte_color_hook(
657 int (*func)(struct route_map_index *index,
658 const char *command, const char *arg,
659 char *errmsg, size_t errmsg_len));
660 /* set ip nexthop */
661 extern void route_map_set_ip_nexthop_hook(
662 int (*func)(struct route_map_index *index,
663 const char *command, const char *arg,
664 char *errmsg, size_t errmsg_len));
665 /* no set ip nexthop */
666 extern void route_map_no_set_ip_nexthop_hook(
667 int (*func)(struct route_map_index *index,
668 const char *command, const char *arg,
669 char *errmsg, size_t errmsg_len));
670 /* set ipv6 nexthop local */
671 extern void route_map_set_ipv6_nexthop_local_hook(
672 int (*func)(struct route_map_index *index,
673 const char *command, const char *arg,
674 char *errmsg, size_t errmsg_len));
675 /* no set ipv6 nexthop local */
676 extern void route_map_no_set_ipv6_nexthop_local_hook(
677 int (*func)(struct route_map_index *index,
678 const char *command, const char *arg,
679 char *errmsg, size_t errmsg_len));
680 /* set metric */
681 extern void route_map_set_metric_hook(int (*func)(struct route_map_index *index,
682 const char *command,
683 const char *arg,
684 char *errmsg,
685 size_t errmsg_len));
686 /* no set metric */
687 extern void route_map_no_set_metric_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_max_metric_hook(
693 int (*func)(struct route_map_index *index, const char *command,
694 const char *arg, char *errmsg, size_t errmsg_len));
695 /* no set metric */
696 extern void route_map_no_set_max_metric_hook(
697 int (*func)(struct route_map_index *index, const char *command,
698 const char *arg, char *errmsg, size_t errmsg_len));
699 /* set metric */
700 extern void route_map_set_min_metric_hook(
701 int (*func)(struct route_map_index *index, const char *command,
702 const char *arg, char *errmsg, size_t errmsg_len));
703 /* no set metric */
704 extern void route_map_no_set_min_metric_hook(
705 int (*func)(struct route_map_index *index, const char *command,
706 const char *arg, char *errmsg, size_t errmsg_len));
707 /* set tag */
708 extern void route_map_set_tag_hook(int (*func)(struct route_map_index *index,
709 const char *command,
710 const char *arg,
711 char *errmsg,
712 size_t errmsg_len));
713 /* no set tag */
714 extern void route_map_no_set_tag_hook(int (*func)(struct route_map_index *index,
715 const char *command,
716 const char *arg,
717 char *errmsg,
718 size_t errmsg_len));
719
720 extern void *route_map_rule_tag_compile(const char *arg);
721 extern void route_map_rule_tag_free(void *rule);
722
723 /* Increment the route-map used counter */
724 extern void route_map_counter_increment(struct route_map *map);
725
726 /* Decrement the route-map used counter */
727 extern void route_map_counter_decrement(struct route_map *map);
728
729 /* Route map hooks data structure. */
730 struct route_map_match_set_hooks {
731 /* match interface */
732 int (*match_interface)(struct route_map_index *index,
733 const char *command, const char *arg,
734 route_map_event_t type,
735 char *errmsg, size_t errmsg_len);
736
737 /* no match interface */
738 int (*no_match_interface)(struct route_map_index *index,
739 const char *command, const char *arg,
740 route_map_event_t type,
741 char *errmsg, size_t errmsg_len);
742
743 /* match ip address */
744 int (*match_ip_address)(struct route_map_index *index,
745 const char *command, const char *arg,
746 route_map_event_t type,
747 char *errmsg, size_t errmsg_len);
748
749 /* no match ip address */
750 int (*no_match_ip_address)(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 /* match ip address prefix list */
756 int (*match_ip_address_prefix_list)(struct route_map_index *index,
757 const char *command,
758 const char *arg,
759 route_map_event_t type,
760 char *errmsg, size_t errmsg_len);
761
762 /* no match ip address prefix list */
763 int (*no_match_ip_address_prefix_list)(struct route_map_index *index,
764 const char *command,
765 const char *arg,
766 route_map_event_t type,
767 char *errmsg, size_t errmsg_len);
768
769 /* match ip next hop */
770 int (*match_ip_next_hop)(struct route_map_index *index,
771 const char *command, const char *arg,
772 route_map_event_t type,
773 char *errmsg, size_t errmsg_len);
774
775 /* no match ip next hop */
776 int (*no_match_ip_next_hop)(struct route_map_index *index,
777 const char *command, const char *arg,
778 route_map_event_t type,
779 char *errmsg, size_t errmsg_len);
780
781 /* match ipv6 next hop */
782 int (*match_ipv6_next_hop)(struct route_map_index *index,
783 const char *command, const char *arg,
784 route_map_event_t type, char *errmsg,
785 size_t errmsg_len);
786
787 /* no match ipv6 next hop */
788 int (*no_match_ipv6_next_hop)(struct route_map_index *index,
789 const char *command, const char *arg,
790 route_map_event_t type, char *errmsg,
791 size_t errmsg_len);
792
793 /* match ipv6 next hop prefix-list */
794 int (*match_ipv6_next_hop_prefix_list)(struct route_map_index *index,
795 const char *command,
796 const char *arg,
797 route_map_event_t type,
798 char *errmsg, size_t errmsg_len);
799
800 /* no match ipv6 next-hop prefix-list */
801 int (*no_match_ipv6_next_hop_prefix_list)(struct route_map_index *index,
802 const char *command,
803 const char *arg,
804 route_map_event_t type,
805 char *errmsg,
806 size_t errmsg_len);
807
808 /* match ip next hop prefix list */
809 int (*match_ip_next_hop_prefix_list)(struct route_map_index *index,
810 const char *command,
811 const char *arg,
812 route_map_event_t type,
813 char *errmsg, size_t errmsg_len);
814
815 /* no match ip next hop prefix list */
816 int (*no_match_ip_next_hop_prefix_list)(struct route_map_index *index,
817 const char *command,
818 const char *arg,
819 route_map_event_t type,
820 char *errmsg,
821 size_t errmsg_len);
822
823 /* match ip next-hop type */
824 int (*match_ip_next_hop_type)(struct route_map_index *index,
825 const char *command,
826 const char *arg,
827 route_map_event_t type,
828 char *errmsg,
829 size_t errmsg_len);
830
831 /* no match ip next-hop type */
832 int (*no_match_ip_next_hop_type)(struct route_map_index *index,
833 const char *command,
834 const char *arg,
835 route_map_event_t type,
836 char *errmsg,
837 size_t errmsg_len);
838
839 /* match ipv6 address */
840 int (*match_ipv6_address)(struct route_map_index *index,
841 const char *command, const char *arg,
842 route_map_event_t type,
843 char *errmsg, size_t errmsg_len);
844
845 /* no match ipv6 address */
846 int (*no_match_ipv6_address)(struct route_map_index *index,
847 const char *command, const char *arg,
848 route_map_event_t type,
849 char *errmsg, size_t errmsg_len);
850
851
852 /* match ipv6 address prefix list */
853 int (*match_ipv6_address_prefix_list)(struct route_map_index *index,
854 const char *command,
855 const char *arg,
856 route_map_event_t type,
857 char *errmsg, size_t errmsg_len);
858
859 /* no match ipv6 address prefix list */
860 int (*no_match_ipv6_address_prefix_list)(struct route_map_index *index,
861 const char *command,
862 const char *arg,
863 route_map_event_t type,
864 char *errmsg,
865 size_t errmsg_len);
866
867 /* match ipv6 next-hop type */
868 int (*match_ipv6_next_hop_type)(struct route_map_index *index,
869 const char *command,
870 const char *arg,
871 route_map_event_t type,
872 char *errmsg, size_t errmsg_len);
873
874 /* no match ipv6 next-hop type */
875 int (*no_match_ipv6_next_hop_type)(struct route_map_index *index,
876 const char *command, const char *arg,
877 route_map_event_t type,
878 char *errmsg, size_t errmsg_len);
879
880 /* match metric */
881 int (*match_metric)(struct route_map_index *index,
882 const char *command, const char *arg,
883 route_map_event_t type,
884 char *errmsg, size_t errmsg_len);
885
886 /* no match metric */
887 int (*no_match_metric)(struct route_map_index *index,
888 const char *command, const char *arg,
889 route_map_event_t type,
890 char *errmsg, size_t errmsg_len);
891
892 /* match tag */
893 int (*match_tag)(struct route_map_index *index,
894 const char *command, const char *arg,
895 route_map_event_t type,
896 char *errmsg, size_t errmsg_len);
897
898 /* no match tag */
899 int (*no_match_tag)(struct route_map_index *index,
900 const char *command, const char *arg,
901 route_map_event_t type,
902 char *errmsg, size_t errmsg_len);
903
904 /* set sr-te color */
905 int (*set_srte_color)(struct route_map_index *index,
906 const char *command, const char *arg,
907 char *errmsg, size_t errmsg_len);
908
909 /* no set sr-te color */
910 int (*no_set_srte_color)(struct route_map_index *index,
911 const char *command, const char *arg,
912 char *errmsg, size_t errmsg_len);
913
914 /* set ip nexthop */
915 int (*set_ip_nexthop)(struct route_map_index *index,
916 const char *command, const char *arg,
917 char *errmsg, size_t errmsg_len);
918
919 /* no set ip nexthop */
920 int (*no_set_ip_nexthop)(struct route_map_index *index,
921 const char *command, const char *arg,
922 char *errmsg, size_t errmsg_len);
923
924 /* set ipv6 nexthop local */
925 int (*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 /* no set ipv6 nexthop local */
930 int (*no_set_ipv6_nexthop_local)(struct route_map_index *index,
931 const char *command, const char *arg,
932 char *errmsg, size_t errmsg_len);
933
934 /* set metric */
935 int (*set_metric)(struct route_map_index *index,
936 const char *command, const char *arg,
937 char *errmsg, size_t errmsg_len);
938
939 /* no set metric */
940 int (*no_set_metric)(struct route_map_index *index,
941 const char *command, const char *arg,
942 char *errmsg, size_t errmsg_len);
943 /* set min-metric */
944 int (*set_min_metric)(struct route_map_index *index,
945 const char *command, const char *arg,
946 char *errmsg, size_t errmsg_len);
947
948 /* no set min-metric */
949 int (*no_set_min_metric)(struct route_map_index *index,
950 const char *command, const char *arg,
951 char *errmsg, size_t errmsg_len);
952
953 /* set max-metric */
954 int (*set_max_metric)(struct route_map_index *index,
955 const char *command, const char *arg,
956 char *errmsg, size_t errmsg_len);
957
958 /* no set max-metric */
959 int (*no_set_max_metric)(struct route_map_index *index,
960 const char *command, const char *arg,
961 char *errmsg, size_t errmsg_len);
962
963 /* set tag */
964 int (*set_tag)(struct route_map_index *index,
965 const char *command, const char *arg,
966 char *errmsg, size_t errmsg_len);
967
968 /* no set tag */
969 int (*no_set_tag)(struct route_map_index *index,
970 const char *command, const char *arg,
971 char *errmsg, size_t errmsg_len);
972 };
973
974 extern struct route_map_match_set_hooks rmap_match_set_hook;
975
976 /* Making route map list. */
977 struct route_map_list {
978 struct route_map *head;
979 struct route_map *tail;
980
981 void (*add_hook)(const char *);
982 void (*delete_hook)(const char *);
983 void (*event_hook)(const char *);
984 };
985
986 extern struct route_map_list route_map_master;
987
988 extern struct route_map *route_map_get(const char *name);
989 extern void route_map_delete(struct route_map *map);
990 extern struct route_map_index *route_map_index_get(struct route_map *map,
991 enum route_map_type type,
992 int pref);
993 extern void route_map_index_delete(struct route_map_index *index, int notify);
994
995 /* routemap_northbound.c */
996 typedef int (*routemap_match_hook_fun)(struct route_map_index *rmi,
997 const char *command, const char *arg,
998 route_map_event_t event,
999 char *errmsg, size_t errmsg_len);
1000 typedef int (*routemap_set_hook_fun)(struct route_map_index *rmi,
1001 const char *command, const char *arg,
1002 char *errmsg, size_t errmsg_len);
1003 struct routemap_hook_context {
1004 struct route_map_index *rhc_rmi;
1005 const char *rhc_rule;
1006 route_map_event_t rhc_event;
1007 routemap_set_hook_fun rhc_shook;
1008 routemap_match_hook_fun rhc_mhook;
1009 TAILQ_ENTRY(routemap_hook_context) rhc_entry;
1010 };
1011
1012 int lib_route_map_entry_match_destroy(struct nb_cb_destroy_args *args);
1013 int lib_route_map_entry_set_destroy(struct nb_cb_destroy_args *args);
1014
1015 struct routemap_hook_context *
1016 routemap_hook_context_insert(struct route_map_index *rmi);
1017 void routemap_hook_context_free(struct routemap_hook_context *rhc);
1018
1019 extern const struct frr_yang_module_info frr_route_map_info;
1020
1021 /* routemap_cli.c */
1022 extern int route_map_instance_cmp(const struct lyd_node *dnode1,
1023 const struct lyd_node *dnode2);
1024 extern void route_map_instance_show(struct vty *vty,
1025 const struct lyd_node *dnode,
1026 bool show_defaults);
1027 extern void route_map_instance_show_end(struct vty *vty,
1028 const struct lyd_node *dnode);
1029 extern void route_map_condition_show(struct vty *vty,
1030 const struct lyd_node *dnode,
1031 bool show_defaults);
1032 extern void route_map_action_show(struct vty *vty, const struct lyd_node *dnode,
1033 bool show_defaults);
1034 extern void route_map_exit_policy_show(struct vty *vty,
1035 const struct lyd_node *dnode,
1036 bool show_defaults);
1037 extern void route_map_call_show(struct vty *vty, const struct lyd_node *dnode,
1038 bool show_defaults);
1039 extern void route_map_description_show(struct vty *vty,
1040 const struct lyd_node *dnode,
1041 bool show_defaults);
1042 extern void route_map_optimization_disabled_show(struct vty *vty,
1043 const struct lyd_node *dnode,
1044 bool show_defaults);
1045 extern void route_map_cli_init(void);
1046
1047 extern void route_map_show_debug(struct vty *vty);
1048
1049 #ifdef __cplusplus
1050 }
1051 #endif
1052
1053 #endif /* _ZEBRA_ROUTEMAP_H */