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