]> git.proxmox.com Git - mirror_frr.git/blob - lib/routemap.h
Merge pull request #10081 from ckishimo/ospf6d_type4
[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_ORIGIN(C) \
280 (strmatch(C, "frr-bgp-route-map:match-origin"))
281 #define IS_MATCH_RPKI(C) (strmatch(C, "frr-bgp-route-map:rpki"))
282 #define IS_MATCH_PROBABILITY(C) \
283 (strmatch(C, "frr-bgp-route-map:probability"))
284 #define IS_MATCH_SRC_VRF(C) \
285 (strmatch(C, "frr-bgp-route-map:source-vrf"))
286 #define IS_MATCH_PEER(C) (strmatch(C, "frr-bgp-route-map:peer"))
287 #define IS_MATCH_AS_LIST(C) \
288 (strmatch(C, "frr-bgp-route-map:as-path-list"))
289 #define IS_MATCH_MAC_LIST(C) \
290 (strmatch(C, "frr-bgp-route-map:mac-address-list"))
291 #define IS_MATCH_EVPN_ROUTE_TYPE(C) \
292 (strmatch(C, "frr-bgp-route-map:evpn-route-type"))
293 #define IS_MATCH_EVPN_DEFAULT_ROUTE(C) \
294 (strmatch(C, "frr-bgp-route-map:evpn-default-route"))
295 #define IS_MATCH_EVPN_VNI(C) \
296 (strmatch(C, "frr-bgp-route-map:evpn-vni"))
297 #define IS_MATCH_EVPN_DEFAULT_ROUTE(C) \
298 (strmatch(C, "frr-bgp-route-map:evpn-default-route"))
299 #define IS_MATCH_EVPN_RD(C) \
300 (strmatch(C, "frr-bgp-route-map:evpn-rd"))
301 #define IS_MATCH_ROUTE_SRC(C) \
302 (strmatch(C, "frr-bgp-route-map:ip-route-source"))
303 #define IS_MATCH_ROUTE_SRC_PL(C) \
304 (strmatch(C, "frr-bgp-route-map:ip-route-source-prefix-list"))
305 #define IS_MATCH_COMMUNITY(C) \
306 (strmatch(C, "frr-bgp-route-map:match-community"))
307 #define IS_MATCH_LCOMMUNITY(C) \
308 (strmatch(C, "frr-bgp-route-map:match-large-community"))
309 #define IS_MATCH_EXTCOMMUNITY(C) \
310 (strmatch(C, "frr-bgp-route-map:match-extcommunity"))
311 #define IS_MATCH_IPV4_NH(C) \
312 (strmatch(C, "frr-bgp-route-map:ipv4-nexthop"))
313 #define IS_MATCH_IPV6_NH(C) \
314 (strmatch(C, "frr-bgp-route-map:ipv6-nexthop"))
315
316 /* Route-map set actions */
317 #define IS_SET_IPv4_NH(A) \
318 (strmatch(A, "frr-route-map:ipv4-next-hop"))
319 #define IS_SET_IPv6_NH(A) \
320 (strmatch(A, "frr-route-map:ipv6-next-hop"))
321 #define IS_SET_METRIC(A) \
322 (strmatch(A, "frr-route-map:set-metric"))
323 #define IS_SET_TAG(A) (strmatch(A, "frr-route-map:set-tag"))
324 #define IS_SET_SR_TE_COLOR(A) \
325 (strmatch(A, "frr-route-map:set-sr-te-color"))
326 /* Zebra route-map set actions */
327 #define IS_SET_SRC(A) \
328 (strmatch(A, "frr-zebra-route-map:src-address"))
329 /* OSPF route-map set actions */
330 #define IS_SET_METRIC_TYPE(A) \
331 (strmatch(A, "frr-ospf-route-map:metric-type"))
332 #define IS_SET_FORWARDING_ADDR(A) \
333 (strmatch(A, "frr-ospf6-route-map:forwarding-address"))
334 /* BGP route-map_set actions */
335 #define IS_SET_WEIGHT(A) \
336 (strmatch(A, "frr-bgp-route-map:weight"))
337 #define IS_SET_TABLE(A) (strmatch(A, "frr-bgp-route-map:table"))
338 #define IS_SET_LOCAL_PREF(A) \
339 (strmatch(A, "frr-bgp-route-map:set-local-preference"))
340 #define IS_SET_LABEL_INDEX(A) \
341 (strmatch(A, "frr-bgp-route-map:label-index"))
342 #define IS_SET_DISTANCE(A) \
343 (strmatch(A, "frr-bgp-route-map:distance"))
344 #define IS_SET_ORIGIN(A) \
345 (strmatch(A, "frr-bgp-route-map:set-origin"))
346 #define IS_SET_ATOMIC_AGGREGATE(A) \
347 (strmatch(A, "frr-bgp-route-map:atomic-aggregate"))
348 #define IS_SET_ORIGINATOR_ID(A) \
349 (strmatch(A, "frr-bgp-route-map:originator-id"))
350 #define IS_SET_COMM_LIST_DEL(A) \
351 (strmatch(A, "frr-bgp-route-map:comm-list-delete"))
352 #define IS_SET_LCOMM_LIST_DEL(A) \
353 (strmatch(A, "frr-bgp-route-map:large-comm-list-delete"))
354 #define IS_SET_LCOMMUNITY(A) \
355 (strmatch(A, "frr-bgp-route-map:set-large-community"))
356 #define IS_SET_COMMUNITY(A) \
357 (strmatch(A, "frr-bgp-route-map:set-community"))
358 #define IS_SET_EXTCOMMUNITY_NONE(A) \
359 (strmatch(A, "frr-bgp-route-map:set-extcommunity-none"))
360 #define IS_SET_EXTCOMMUNITY_RT(A) \
361 (strmatch(A, "frr-bgp-route-map:set-extcommunity-rt"))
362 #define IS_SET_EXTCOMMUNITY_SOO(A) \
363 (strmatch(A, "frr-bgp-route-map:set-extcommunity-soo"))
364 #define IS_SET_EXTCOMMUNITY_LB(A) \
365 (strmatch(A, "frr-bgp-route-map:set-extcommunity-lb"))
366 #define IS_SET_AGGREGATOR(A) \
367 (strmatch(A, "frr-bgp-route-map:aggregator"))
368 #define IS_SET_AS_PREPEND(A) \
369 (strmatch(A, "frr-bgp-route-map:as-path-prepend"))
370 #define IS_SET_AS_EXCLUDE(A) \
371 (strmatch(A, "frr-bgp-route-map:as-path-exclude"))
372 #define IS_SET_IPV6_NH_GLOBAL(A) \
373 (strmatch(A, "frr-bgp-route-map:ipv6-nexthop-global"))
374 #define IS_SET_IPV6_VPN_NH(A) \
375 (strmatch(A, "frr-bgp-route-map:ipv6-vpn-address"))
376 #define IS_SET_IPV6_PEER_ADDR(A) \
377 (strmatch(A, "frr-bgp-route-map:ipv6-peer-address"))
378 #define IS_SET_IPV6_PREFER_GLOBAL(A) \
379 (strmatch(A, "frr-bgp-route-map:ipv6-prefer-global"))
380 #define IS_SET_IPV4_VPN_NH(A) \
381 (strmatch(A, "frr-bgp-route-map:ipv4-vpn-address"))
382 #define IS_SET_BGP_IPV4_NH(A) \
383 (strmatch(A, "frr-bgp-route-map:set-ipv4-nexthop"))
384 #define IS_SET_BGP_EVPN_GATEWAY_IP_IPV4(A) \
385 (strmatch(A, "frr-bgp-route-map:set-evpn-gateway-ip-ipv4"))
386 #define IS_SET_BGP_EVPN_GATEWAY_IP_IPV6(A) \
387 (strmatch(A, "frr-bgp-route-map:set-evpn-gateway-ip-ipv6"))
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);
484 #define route_map_apply(map, prefix, object) \
485 route_map_apply_ext(map, prefix, object, object)
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 tag */
692 extern void route_map_set_tag_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 tag */
698 extern void route_map_no_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
704 extern void *route_map_rule_tag_compile(const char *arg);
705 extern void route_map_rule_tag_free(void *rule);
706
707 /* Increment the route-map used counter */
708 extern void route_map_counter_increment(struct route_map *map);
709
710 /* Decrement the route-map used counter */
711 extern void route_map_counter_decrement(struct route_map *map);
712
713 /* Route map hooks data structure. */
714 struct route_map_match_set_hooks {
715 /* match interface */
716 int (*match_interface)(struct route_map_index *index,
717 const char *command, const char *arg,
718 route_map_event_t type,
719 char *errmsg, size_t errmsg_len);
720
721 /* no match interface */
722 int (*no_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 /* match ip address */
728 int (*match_ip_address)(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 /* no match ip address */
734 int (*no_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 /* match ip address prefix list */
740 int (*match_ip_address_prefix_list)(struct route_map_index *index,
741 const char *command,
742 const char *arg,
743 route_map_event_t type,
744 char *errmsg, size_t errmsg_len);
745
746 /* no match ip address prefix list */
747 int (*no_match_ip_address_prefix_list)(struct route_map_index *index,
748 const char *command,
749 const char *arg,
750 route_map_event_t type,
751 char *errmsg, size_t errmsg_len);
752
753 /* match ip next hop */
754 int (*match_ip_next_hop)(struct route_map_index *index,
755 const char *command, const char *arg,
756 route_map_event_t type,
757 char *errmsg, size_t errmsg_len);
758
759 /* no match ip next hop */
760 int (*no_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 /* match ipv6 next hop */
766 int (*match_ipv6_next_hop)(struct route_map_index *index,
767 const char *command, const char *arg,
768 route_map_event_t type, char *errmsg,
769 size_t errmsg_len);
770
771 /* no match ipv6 next hop */
772 int (*no_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 /* match ipv6 next hop prefix-list */
778 int (*match_ipv6_next_hop_prefix_list)(struct route_map_index *index,
779 const char *command,
780 const char *arg,
781 route_map_event_t type,
782 char *errmsg, size_t errmsg_len);
783
784 /* no match ipv6 next-hop prefix-list */
785 int (*no_match_ipv6_next_hop_prefix_list)(struct route_map_index *index,
786 const char *command,
787 const char *arg,
788 route_map_event_t type,
789 char *errmsg,
790 size_t errmsg_len);
791
792 /* match ip next hop prefix list */
793 int (*match_ip_next_hop_prefix_list)(struct route_map_index *index,
794 const char *command,
795 const char *arg,
796 route_map_event_t type,
797 char *errmsg, size_t errmsg_len);
798
799 /* no match ip next hop prefix list */
800 int (*no_match_ip_next_hop_prefix_list)(struct route_map_index *index,
801 const char *command,
802 const char *arg,
803 route_map_event_t type,
804 char *errmsg,
805 size_t errmsg_len);
806
807 /* match ip next-hop type */
808 int (*match_ip_next_hop_type)(struct route_map_index *index,
809 const char *command,
810 const char *arg,
811 route_map_event_t type,
812 char *errmsg,
813 size_t errmsg_len);
814
815 /* no match ip next-hop type */
816 int (*no_match_ip_next_hop_type)(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 ipv6 address */
824 int (*match_ipv6_address)(struct route_map_index *index,
825 const char *command, const char *arg,
826 route_map_event_t type,
827 char *errmsg, size_t errmsg_len);
828
829 /* no match ipv6 address */
830 int (*no_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
836 /* match ipv6 address prefix list */
837 int (*match_ipv6_address_prefix_list)(struct route_map_index *index,
838 const char *command,
839 const char *arg,
840 route_map_event_t type,
841 char *errmsg, size_t errmsg_len);
842
843 /* no match ipv6 address prefix list */
844 int (*no_match_ipv6_address_prefix_list)(struct route_map_index *index,
845 const char *command,
846 const char *arg,
847 route_map_event_t type,
848 char *errmsg,
849 size_t errmsg_len);
850
851 /* match ipv6 next-hop type */
852 int (*match_ipv6_next_hop_type)(struct route_map_index *index,
853 const char *command,
854 const char *arg,
855 route_map_event_t type,
856 char *errmsg, size_t errmsg_len);
857
858 /* no match ipv6 next-hop type */
859 int (*no_match_ipv6_next_hop_type)(struct route_map_index *index,
860 const char *command, const char *arg,
861 route_map_event_t type,
862 char *errmsg, size_t errmsg_len);
863
864 /* match metric */
865 int (*match_metric)(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 /* no match metric */
871 int (*no_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 /* match tag */
877 int (*match_tag)(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 /* no match tag */
883 int (*no_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 /* set sr-te color */
889 int (*set_srte_color)(struct route_map_index *index,
890 const char *command, const char *arg,
891 char *errmsg, size_t errmsg_len);
892
893 /* no set sr-te color */
894 int (*no_set_srte_color)(struct route_map_index *index,
895 const char *command, const char *arg,
896 char *errmsg, size_t errmsg_len);
897
898 /* set ip nexthop */
899 int (*set_ip_nexthop)(struct route_map_index *index,
900 const char *command, const char *arg,
901 char *errmsg, size_t errmsg_len);
902
903 /* no set ip nexthop */
904 int (*no_set_ip_nexthop)(struct route_map_index *index,
905 const char *command, const char *arg,
906 char *errmsg, size_t errmsg_len);
907
908 /* set ipv6 nexthop local */
909 int (*set_ipv6_nexthop_local)(struct route_map_index *index,
910 const char *command, const char *arg,
911 char *errmsg, size_t errmsg_len);
912
913 /* no set ipv6 nexthop local */
914 int (*no_set_ipv6_nexthop_local)(struct route_map_index *index,
915 const char *command, const char *arg,
916 char *errmsg, size_t errmsg_len);
917
918 /* set metric */
919 int (*set_metric)(struct route_map_index *index,
920 const char *command, const char *arg,
921 char *errmsg, size_t errmsg_len);
922
923 /* no set metric */
924 int (*no_set_metric)(struct route_map_index *index,
925 const char *command, const char *arg,
926 char *errmsg, size_t errmsg_len);
927
928 /* set tag */
929 int (*set_tag)(struct route_map_index *index,
930 const char *command, const char *arg,
931 char *errmsg, size_t errmsg_len);
932
933 /* no set tag */
934 int (*no_set_tag)(struct route_map_index *index,
935 const char *command, const char *arg,
936 char *errmsg, size_t errmsg_len);
937 };
938
939 extern struct route_map_match_set_hooks rmap_match_set_hook;
940
941 /* Making route map list. */
942 struct route_map_list {
943 struct route_map *head;
944 struct route_map *tail;
945
946 void (*add_hook)(const char *);
947 void (*delete_hook)(const char *);
948 void (*event_hook)(const char *);
949 };
950
951 extern struct route_map_list route_map_master;
952
953 extern struct route_map *route_map_get(const char *name);
954 extern void route_map_delete(struct route_map *map);
955 extern struct route_map_index *route_map_index_get(struct route_map *map,
956 enum route_map_type type,
957 int pref);
958 extern void route_map_index_delete(struct route_map_index *index, int notify);
959
960 /* routemap_northbound.c */
961 typedef int (*routemap_match_hook_fun)(struct route_map_index *rmi,
962 const char *command, const char *arg,
963 route_map_event_t event,
964 char *errmsg, size_t errmsg_len);
965 typedef int (*routemap_set_hook_fun)(struct route_map_index *rmi,
966 const char *command, const char *arg,
967 char *errmsg, size_t errmsg_len);
968 struct routemap_hook_context {
969 struct route_map_index *rhc_rmi;
970 const char *rhc_rule;
971 route_map_event_t rhc_event;
972 routemap_set_hook_fun rhc_shook;
973 routemap_match_hook_fun rhc_mhook;
974 TAILQ_ENTRY(routemap_hook_context) rhc_entry;
975 };
976
977 int lib_route_map_entry_match_destroy(struct nb_cb_destroy_args *args);
978 int lib_route_map_entry_set_destroy(struct nb_cb_destroy_args *args);
979
980 struct routemap_hook_context *
981 routemap_hook_context_insert(struct route_map_index *rmi);
982 void routemap_hook_context_free(struct routemap_hook_context *rhc);
983
984 extern const struct frr_yang_module_info frr_route_map_info;
985
986 /* routemap_cli.c */
987 extern int route_map_instance_cmp(const struct lyd_node *dnode1,
988 const struct lyd_node *dnode2);
989 extern void route_map_instance_show(struct vty *vty,
990 const struct lyd_node *dnode,
991 bool show_defaults);
992 extern void route_map_instance_show_end(struct vty *vty,
993 const struct lyd_node *dnode);
994 extern void route_map_condition_show(struct vty *vty,
995 const struct lyd_node *dnode,
996 bool show_defaults);
997 extern void route_map_action_show(struct vty *vty, const struct lyd_node *dnode,
998 bool show_defaults);
999 extern void route_map_exit_policy_show(struct vty *vty,
1000 const struct lyd_node *dnode,
1001 bool show_defaults);
1002 extern void route_map_call_show(struct vty *vty, const struct lyd_node *dnode,
1003 bool show_defaults);
1004 extern void route_map_description_show(struct vty *vty,
1005 const struct lyd_node *dnode,
1006 bool show_defaults);
1007 extern void route_map_optimization_disabled_show(struct vty *vty,
1008 const struct lyd_node *dnode,
1009 bool show_defaults);
1010 extern void route_map_cli_init(void);
1011
1012 #ifdef __cplusplus
1013 }
1014 #endif
1015
1016 #endif /* _ZEBRA_ROUTEMAP_H */