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