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