]> git.proxmox.com Git - mirror_frr.git/blob - lib/routemap.h
Merge pull request #4778 from mjstapp/dplane_macs
[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
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32
33 DECLARE_MTYPE(ROUTE_MAP_NAME)
34 DECLARE_MTYPE(ROUTE_MAP_RULE)
35 DECLARE_MTYPE(ROUTE_MAP_COMPILED)
36
37 /* Route map's type. */
38 enum route_map_type { RMAP_PERMIT, RMAP_DENY, RMAP_ANY };
39
40 typedef enum {
41 RMAP_DENYMATCH,
42 RMAP_PERMITMATCH
43 } route_map_result_t;
44
45 /*
46 * Route-map match or set result "Eg: match evpn vni xx"
47 * route-map match cmd always returns match/nomatch/noop
48 * match--> found a match
49 * nomatch--> didnt find a match
50 * noop--> not applicable
51 * route-map set retuns okay/error
52 * okay --> set was successful
53 * error --> set was not successful
54 */
55 enum route_map_cmd_result_t {
56 /*
57 * route-map match cmd results
58 */
59 RMAP_MATCH,
60 RMAP_NOMATCH,
61 RMAP_NOOP,
62 /*
63 * route-map set cmd results
64 */
65 RMAP_OKAY,
66 RMAP_ERROR
67 };
68
69
70 typedef enum {
71 RMAP_RIP,
72 RMAP_RIPNG,
73 RMAP_OSPF,
74 RMAP_OSPF6,
75 RMAP_BGP,
76 RMAP_ZEBRA,
77 RMAP_ISIS,
78 } route_map_object_t;
79
80 typedef enum { RMAP_EXIT, RMAP_GOTO, RMAP_NEXT } route_map_end_t;
81
82 typedef enum {
83 RMAP_EVENT_SET_ADDED,
84 RMAP_EVENT_SET_DELETED,
85 RMAP_EVENT_SET_REPLACED,
86 RMAP_EVENT_MATCH_ADDED,
87 RMAP_EVENT_MATCH_DELETED,
88 RMAP_EVENT_MATCH_REPLACED,
89 RMAP_EVENT_INDEX_ADDED,
90 RMAP_EVENT_INDEX_DELETED,
91 RMAP_EVENT_CALL_ADDED, /* call to another routemap added */
92 RMAP_EVENT_CALL_DELETED,
93 RMAP_EVENT_PLIST_ADDED,
94 RMAP_EVENT_PLIST_DELETED,
95 RMAP_EVENT_CLIST_ADDED,
96 RMAP_EVENT_CLIST_DELETED,
97 RMAP_EVENT_ECLIST_ADDED,
98 RMAP_EVENT_ECLIST_DELETED,
99 RMAP_EVENT_LLIST_ADDED,
100 RMAP_EVENT_LLIST_DELETED,
101 RMAP_EVENT_ASLIST_ADDED,
102 RMAP_EVENT_ASLIST_DELETED,
103 RMAP_EVENT_FILTER_ADDED,
104 RMAP_EVENT_FILTER_DELETED,
105 } route_map_event_t;
106
107 /* Depth limit in RMAP recursion using RMAP_CALL. */
108 #define RMAP_RECURSION_LIMIT 10
109
110 /* Route map rule structure for matching and setting. */
111 struct route_map_rule_cmd {
112 /* Route map rule name (e.g. as-path, metric) */
113 const char *str;
114
115 /* Function for value set or match. */
116 enum route_map_cmd_result_t (*func_apply)(void *rule,
117 const struct prefix *prefix,
118 route_map_object_t type,
119 void *object);
120
121 /* Compile argument and return result as void *. */
122 void *(*func_compile)(const char *);
123
124 /* Free allocated value by func_compile (). */
125 void (*func_free)(void *);
126 };
127
128 /* Route map apply error. */
129 enum {
130 RMAP_COMPILE_SUCCESS,
131
132 /* Route map rule is missing. */
133 RMAP_RULE_MISSING,
134
135 /* Route map rule can't compile */
136 RMAP_COMPILE_ERROR,
137
138 /* Route map rule is duplicate */
139 RMAP_DUPLICATE_RULE
140 };
141
142 /* Route map rule list. */
143 struct route_map_rule_list {
144 struct route_map_rule *head;
145 struct route_map_rule *tail;
146 };
147
148 /* Route map index structure. */
149 struct route_map_index {
150 struct route_map *map;
151 char *description;
152
153 /* Preference of this route map rule. */
154 int pref;
155
156 /* Route map type permit or deny. */
157 enum route_map_type type;
158
159 /* Do we follow old rules, or hop forward? */
160 route_map_end_t exitpolicy;
161
162 /* If we're using "GOTO", to where do we go? */
163 int nextpref;
164
165 /* If we're using "CALL", to which route-map do ew go? */
166 char *nextrm;
167
168 /* Matching rule list. */
169 struct route_map_rule_list match_list;
170 struct route_map_rule_list set_list;
171
172 /* Make linked list. */
173 struct route_map_index *next;
174 struct route_map_index *prev;
175
176 /* Keep track how many times we've try to apply */
177 uint64_t applied;
178 uint64_t applied_clear;
179
180 QOBJ_FIELDS
181 };
182 DECLARE_QOBJ_TYPE(route_map_index)
183
184 /* Route map list structure. */
185 struct route_map {
186 /* Name of route map. */
187 char *name;
188
189 /* Route map's rule. */
190 struct route_map_index *head;
191 struct route_map_index *tail;
192
193 /* Make linked list. */
194 struct route_map *next;
195 struct route_map *prev;
196
197 /* Maintain update info */
198 bool to_be_processed; /* True if modification isn't acted on yet */
199 bool deleted; /* If 1, then this node will be deleted */
200
201 /* How many times have we applied this route-map */
202 uint64_t applied;
203 uint64_t applied_clear;
204
205 /* Counter to track active usage of this route-map */
206 uint16_t use_count;
207
208 QOBJ_FIELDS
209 };
210 DECLARE_QOBJ_TYPE(route_map)
211
212 /* Prototypes. */
213 extern void route_map_init(void);
214
215 /*
216 * This should only be called on shutdown
217 * Additionally this function sets the hooks to NULL
218 * before any processing is done.
219 */
220 extern void route_map_finish(void);
221
222 /* Add match statement to route map. */
223 extern int route_map_add_match(struct route_map_index *index,
224 const char *match_name, const char *match_arg,
225 route_map_event_t type);
226
227 /* Delete specified route match rule. */
228 extern int route_map_delete_match(struct route_map_index *index,
229 const char *match_name,
230 const char *match_arg);
231
232 extern const char *route_map_get_match_arg(struct route_map_index *index,
233 const char *match_name);
234
235 /* Add route-map set statement to the route map. */
236 extern int route_map_add_set(struct route_map_index *index,
237 const char *set_name, const char *set_arg);
238
239 /* Delete route map set rule. */
240 extern int route_map_delete_set(struct route_map_index *index,
241 const char *set_name, const char *set_arg);
242
243 /* Install rule command to the match list. */
244 extern void route_map_install_match(struct route_map_rule_cmd *cmd);
245
246 /*
247 * Install rule command to the set list.
248 *
249 * When installing a particular item, Allow a difference of handling
250 * of bad cli inputted(return NULL) -vs- this particular daemon cannot use
251 * this form of the command(return a pointer and handle it appropriately
252 * in the apply command). See 'set metric' command
253 * as it is handled in ripd/ripngd and ospfd.
254 */
255 extern void route_map_install_set(struct route_map_rule_cmd *cmd);
256
257 /* Lookup route map by name. */
258 extern struct route_map *route_map_lookup_by_name(const char *name);
259
260 /* Simple helper to warn if route-map does not exist. */
261 struct route_map *route_map_lookup_warn_noexist(struct vty *vty, const char *name);
262
263 /* Apply route map to the object. */
264 extern route_map_result_t route_map_apply(struct route_map *map,
265 const struct prefix *prefix,
266 route_map_object_t object_type,
267 void *object);
268
269 extern void route_map_add_hook(void (*func)(const char *));
270 extern void route_map_delete_hook(void (*func)(const char *));
271
272 /*
273 * This is the callback for when something has changed about a
274 * route-map. The interested parties can register to receive
275 * this data.
276 *
277 * name - Is the name of the changed route-map
278 */
279 extern void route_map_event_hook(void (*func)(const char *name));
280 extern int route_map_mark_updated(const char *name);
281 extern void route_map_walk_update_list(void (*update_fn)(char *name));
282 extern void route_map_upd8_dependency(route_map_event_t type, const char *arg,
283 const char *rmap_name);
284 extern void route_map_notify_dependencies(const char *affected_name,
285 route_map_event_t event);
286
287 extern int generic_match_add(struct vty *vty, struct route_map_index *index,
288 const char *command, const char *arg,
289 route_map_event_t type);
290
291 extern int generic_match_delete(struct vty *vty, struct route_map_index *index,
292 const char *command, const char *arg,
293 route_map_event_t type);
294 extern int generic_set_add(struct vty *vty, struct route_map_index *index,
295 const char *command, const char *arg);
296 extern int generic_set_delete(struct vty *vty, struct route_map_index *index,
297 const char *command, const char *arg);
298
299
300 /* match interface */
301 extern void route_map_match_interface_hook(int (*func)(
302 struct vty *vty, struct route_map_index *index, const char *command,
303 const char *arg, route_map_event_t type));
304 /* no match interface */
305 extern void route_map_no_match_interface_hook(int (*func)(
306 struct vty *vty, struct route_map_index *index, const char *command,
307 const char *arg, route_map_event_t type));
308 /* match ip address */
309 extern void route_map_match_ip_address_hook(int (*func)(
310 struct vty *vty, struct route_map_index *index, const char *command,
311 const char *arg, route_map_event_t type));
312 /* no match ip address */
313 extern void route_map_no_match_ip_address_hook(int (*func)(
314 struct vty *vty, struct route_map_index *index, const char *command,
315 const char *arg, route_map_event_t type));
316 /* match ip address prefix list */
317 extern void route_map_match_ip_address_prefix_list_hook(int (*func)(
318 struct vty *vty, struct route_map_index *index, const char *command,
319 const char *arg, route_map_event_t type));
320 /* no match ip address prefix list */
321 extern void route_map_no_match_ip_address_prefix_list_hook(int (*func)(
322 struct vty *vty, struct route_map_index *index, const char *command,
323 const char *arg, route_map_event_t type));
324 /* match ip next hop */
325 extern void route_map_match_ip_next_hop_hook(int (*func)(
326 struct vty *vty, struct route_map_index *index, const char *command,
327 const char *arg, route_map_event_t type));
328 /* no match ip next hop */
329 extern void route_map_no_match_ip_next_hop_hook(int (*func)(
330 struct vty *vty, struct route_map_index *index, const char *command,
331 const char *arg, route_map_event_t type));
332 /* match ip next hop prefix list */
333 extern void route_map_match_ip_next_hop_prefix_list_hook(int (*func)(
334 struct vty *vty, struct route_map_index *index, const char *command,
335 const char *arg, route_map_event_t type));
336 /* no match ip next hop prefix list */
337 extern void route_map_no_match_ip_next_hop_prefix_list_hook(int (*func)(
338 struct vty *vty, struct route_map_index *index, const char *command,
339 const char *arg, route_map_event_t type));
340 /* match ip next hop type */
341 extern void route_map_match_ip_next_hop_type_hook(int (*func)(
342 struct vty *vty, struct route_map_index *index, const char *command,
343 const char *arg, route_map_event_t type));
344 /* no match ip next hop type */
345 extern void route_map_no_match_ip_next_hop_type_hook(int (*func)(
346 struct vty *vty, struct route_map_index *index, const char *command,
347 const char *arg, route_map_event_t type));
348 /* match ipv6 address */
349 extern void route_map_match_ipv6_address_hook(int (*func)(
350 struct vty *vty, struct route_map_index *index, const char *command,
351 const char *arg, route_map_event_t type));
352 /* no match ipv6 address */
353 extern void route_map_no_match_ipv6_address_hook(int (*func)(
354 struct vty *vty, struct route_map_index *index, const char *command,
355 const char *arg, route_map_event_t type));
356 /* match ipv6 address prefix list */
357 extern void route_map_match_ipv6_address_prefix_list_hook(int (*func)(
358 struct vty *vty, struct route_map_index *index, const char *command,
359 const char *arg, route_map_event_t type));
360 /* no match ipv6 address prefix list */
361 extern void route_map_no_match_ipv6_address_prefix_list_hook(int (*func)(
362 struct vty *vty, struct route_map_index *index, const char *command,
363 const char *arg, route_map_event_t type));
364 /* match ipv6 next-hop type */
365 extern void route_map_match_ipv6_next_hop_type_hook(int (*func)(
366 struct vty *vty, struct route_map_index *index, const char *command,
367 const char *arg, route_map_event_t type));
368 /* no match ipv6 next-hop type */
369 extern void route_map_no_match_ipv6_next_hop_type_hook(int (*func)(
370 struct vty *vty, struct route_map_index *index, const char *command,
371 const char *arg, route_map_event_t type));
372 /* match metric */
373 extern void route_map_match_metric_hook(int (*func)(
374 struct vty *vty, struct route_map_index *index, const char *command,
375 const char *arg, route_map_event_t type));
376 /* no match metric */
377 extern void route_map_no_match_metric_hook(int (*func)(
378 struct vty *vty, struct route_map_index *index, const char *command,
379 const char *arg, route_map_event_t type));
380 /* match tag */
381 extern void route_map_match_tag_hook(int (*func)(
382 struct vty *vty, struct route_map_index *index, const char *command,
383 const char *arg, route_map_event_t type));
384 /* no match tag */
385 extern void route_map_no_match_tag_hook(int (*func)(
386 struct vty *vty, struct route_map_index *index, const char *command,
387 const char *arg, route_map_event_t type));
388 /* set ip nexthop */
389 extern void route_map_set_ip_nexthop_hook(
390 int (*func)(struct vty *vty, struct route_map_index *index,
391 const char *command, const char *arg));
392 /* no set ip nexthop */
393 extern void route_map_no_set_ip_nexthop_hook(
394 int (*func)(struct vty *vty, struct route_map_index *index,
395 const char *command, const char *arg));
396 /* set ipv6 nexthop local */
397 extern void route_map_set_ipv6_nexthop_local_hook(
398 int (*func)(struct vty *vty, struct route_map_index *index,
399 const char *command, const char *arg));
400 /* no set ipv6 nexthop local */
401 extern void route_map_no_set_ipv6_nexthop_local_hook(
402 int (*func)(struct vty *vty, struct route_map_index *index,
403 const char *command, const char *arg));
404 /* set metric */
405 extern void route_map_set_metric_hook(int (*func)(struct vty *vty,
406 struct route_map_index *index,
407 const char *command,
408 const char *arg));
409 /* no set metric */
410 extern void route_map_no_set_metric_hook(
411 int (*func)(struct vty *vty, struct route_map_index *index,
412 const char *command, const char *arg));
413 /* set tag */
414 extern void route_map_set_tag_hook(int (*func)(struct vty *vty,
415 struct route_map_index *index,
416 const char *command,
417 const char *arg));
418 /* no set tag */
419 extern void route_map_no_set_tag_hook(int (*func)(struct vty *vty,
420 struct route_map_index *index,
421 const char *command,
422 const char *arg));
423
424 extern void *route_map_rule_tag_compile(const char *arg);
425 extern void route_map_rule_tag_free(void *rule);
426
427 /* Increment the route-map used counter */
428 extern void route_map_counter_increment(struct route_map *map);
429
430 /* Decrement the route-map used counter */
431 extern void route_map_counter_decrement(struct route_map *map);
432
433 #ifdef __cplusplus
434 }
435 #endif
436
437 #endif /* _ZEBRA_ROUTEMAP_H */