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