]> git.proxmox.com Git - mirror_frr.git/blob - lib/routemap.h
lib: Fix missing __be16 typedef on CentOS6
[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 /** To get the rule key after Compilation **/
128 void *(*func_get_rmap_rule_key)(void *val);
129 };
130
131 /* Route map apply error. */
132 enum rmap_compile_rets {
133 RMAP_COMPILE_SUCCESS,
134
135 /* Route map rule is missing. */
136 RMAP_RULE_MISSING,
137
138 /* Route map rule can't compile */
139 RMAP_COMPILE_ERROR,
140
141 };
142
143 /* Route map rule list. */
144 struct route_map_rule_list {
145 struct route_map_rule *head;
146 struct route_map_rule *tail;
147 };
148
149 /* Route map index structure. */
150 struct route_map_index {
151 struct route_map *map;
152 char *description;
153
154 /* Preference of this route map rule. */
155 int pref;
156
157 /* Route map type permit or deny. */
158 enum route_map_type type;
159
160 /* Do we follow old rules, or hop forward? */
161 route_map_end_t exitpolicy;
162
163 /* If we're using "GOTO", to where do we go? */
164 int nextpref;
165
166 /* If we're using "CALL", to which route-map do ew go? */
167 char *nextrm;
168
169 /* Matching rule list. */
170 struct route_map_rule_list match_list;
171 struct route_map_rule_list set_list;
172
173 /* Make linked list. */
174 struct route_map_index *next;
175 struct route_map_index *prev;
176
177 /* Keep track how many times we've try to apply */
178 uint64_t applied;
179 uint64_t applied_clear;
180
181 QOBJ_FIELDS
182 };
183 DECLARE_QOBJ_TYPE(route_map_index)
184
185 /* Route map list structure. */
186 struct route_map {
187 /* Name of route map. */
188 char *name;
189
190 /* Route map's rule. */
191 struct route_map_index *head;
192 struct route_map_index *tail;
193
194 /* Make linked list. */
195 struct route_map *next;
196 struct route_map *prev;
197
198 /* Maintain update info */
199 bool to_be_processed; /* True if modification isn't acted on yet */
200 bool deleted; /* If 1, then this node will be deleted */
201
202 /* How many times have we applied this route-map */
203 uint64_t applied;
204 uint64_t applied_clear;
205
206 /* Counter to track active usage of this route-map */
207 uint16_t use_count;
208
209 QOBJ_FIELDS
210 };
211 DECLARE_QOBJ_TYPE(route_map)
212
213 /* Prototypes. */
214 extern void route_map_init(void);
215
216 /*
217 * This should only be called on shutdown
218 * Additionally this function sets the hooks to NULL
219 * before any processing is done.
220 */
221 extern void route_map_finish(void);
222
223 /* Add match statement to route map. */
224 extern enum rmap_compile_rets route_map_add_match(struct route_map_index *index,
225 const char *match_name,
226 const char *match_arg,
227 route_map_event_t type);
228
229 /* Delete specified route match rule. */
230 extern enum rmap_compile_rets
231 route_map_delete_match(struct route_map_index *index,
232 const char *match_name, const char *match_arg,
233 route_map_event_t type);
234
235 extern const char *route_map_get_match_arg(struct route_map_index *index,
236 const char *match_name);
237
238 /* Add route-map set statement to the route map. */
239 extern enum rmap_compile_rets route_map_add_set(struct route_map_index *index,
240 const char *set_name,
241 const char *set_arg);
242
243 /* Delete route map set rule. */
244 extern enum rmap_compile_rets
245 route_map_delete_set(struct route_map_index *index,
246 const char *set_name, const char *set_arg);
247
248 /* Install rule command to the match list. */
249 extern void route_map_install_match(const struct route_map_rule_cmd *cmd);
250
251 /*
252 * Install rule command to the set list.
253 *
254 * When installing a particular item, Allow a difference of handling
255 * of bad cli inputted(return NULL) -vs- this particular daemon cannot use
256 * this form of the command(return a pointer and handle it appropriately
257 * in the apply command). See 'set metric' command
258 * as it is handled in ripd/ripngd and ospfd.
259 */
260 extern void route_map_install_set(const struct route_map_rule_cmd *cmd);
261
262 /* Lookup route map by name. */
263 extern struct route_map *route_map_lookup_by_name(const char *name);
264
265 /* Simple helper to warn if route-map does not exist. */
266 struct route_map *route_map_lookup_warn_noexist(struct vty *vty, const char *name);
267
268 /* Apply route map to the object. */
269 extern route_map_result_t route_map_apply(struct route_map *map,
270 const struct prefix *prefix,
271 route_map_object_t object_type,
272 void *object);
273
274 extern void route_map_add_hook(void (*func)(const char *));
275 extern void route_map_delete_hook(void (*func)(const char *));
276
277 /*
278 * This is the callback for when something has changed about a
279 * route-map. The interested parties can register to receive
280 * this data.
281 *
282 * name - Is the name of the changed route-map
283 */
284 extern void route_map_event_hook(void (*func)(const char *name));
285 extern int route_map_mark_updated(const char *name);
286 extern void route_map_walk_update_list(void (*update_fn)(char *name));
287 extern void route_map_upd8_dependency(route_map_event_t type, const char *arg,
288 const char *rmap_name);
289 extern void route_map_notify_dependencies(const char *affected_name,
290 route_map_event_t event);
291
292 extern int generic_match_add(struct vty *vty, struct route_map_index *index,
293 const char *command, const char *arg,
294 route_map_event_t type);
295
296 extern int generic_match_delete(struct vty *vty, struct route_map_index *index,
297 const char *command, const char *arg,
298 route_map_event_t type);
299 extern int generic_set_add(struct vty *vty, struct route_map_index *index,
300 const char *command, const char *arg);
301 extern int generic_set_delete(struct vty *vty, struct route_map_index *index,
302 const char *command, const char *arg);
303
304
305 /* match interface */
306 extern void route_map_match_interface_hook(int (*func)(
307 struct vty *vty, struct route_map_index *index, const char *command,
308 const char *arg, route_map_event_t type));
309 /* no match interface */
310 extern void route_map_no_match_interface_hook(int (*func)(
311 struct vty *vty, struct route_map_index *index, const char *command,
312 const char *arg, route_map_event_t type));
313 /* match ip address */
314 extern void route_map_match_ip_address_hook(int (*func)(
315 struct vty *vty, struct route_map_index *index, const char *command,
316 const char *arg, route_map_event_t type));
317 /* no match ip address */
318 extern void route_map_no_match_ip_address_hook(int (*func)(
319 struct vty *vty, struct route_map_index *index, const char *command,
320 const char *arg, route_map_event_t type));
321 /* match ip address prefix list */
322 extern void route_map_match_ip_address_prefix_list_hook(int (*func)(
323 struct vty *vty, struct route_map_index *index, const char *command,
324 const char *arg, route_map_event_t type));
325 /* no match ip address prefix list */
326 extern void route_map_no_match_ip_address_prefix_list_hook(int (*func)(
327 struct vty *vty, struct route_map_index *index, const char *command,
328 const char *arg, route_map_event_t type));
329 /* match ip next hop */
330 extern void route_map_match_ip_next_hop_hook(int (*func)(
331 struct vty *vty, struct route_map_index *index, const char *command,
332 const char *arg, route_map_event_t type));
333 /* no match ip next hop */
334 extern void route_map_no_match_ip_next_hop_hook(int (*func)(
335 struct vty *vty, struct route_map_index *index, const char *command,
336 const char *arg, route_map_event_t type));
337 /* match ip next hop prefix list */
338 extern void route_map_match_ip_next_hop_prefix_list_hook(int (*func)(
339 struct vty *vty, struct route_map_index *index, const char *command,
340 const char *arg, route_map_event_t type));
341 /* no match ip next hop prefix list */
342 extern void route_map_no_match_ip_next_hop_prefix_list_hook(int (*func)(
343 struct vty *vty, struct route_map_index *index, const char *command,
344 const char *arg, route_map_event_t type));
345 /* match ip next hop type */
346 extern void route_map_match_ip_next_hop_type_hook(int (*func)(
347 struct vty *vty, struct route_map_index *index, const char *command,
348 const char *arg, route_map_event_t type));
349 /* no match ip next hop type */
350 extern void route_map_no_match_ip_next_hop_type_hook(int (*func)(
351 struct vty *vty, struct route_map_index *index, const char *command,
352 const char *arg, route_map_event_t type));
353 /* match ipv6 address */
354 extern void route_map_match_ipv6_address_hook(int (*func)(
355 struct vty *vty, struct route_map_index *index, const char *command,
356 const char *arg, route_map_event_t type));
357 /* no match ipv6 address */
358 extern void route_map_no_match_ipv6_address_hook(int (*func)(
359 struct vty *vty, struct route_map_index *index, const char *command,
360 const char *arg, route_map_event_t type));
361 /* match ipv6 address prefix list */
362 extern void route_map_match_ipv6_address_prefix_list_hook(int (*func)(
363 struct vty *vty, struct route_map_index *index, const char *command,
364 const char *arg, route_map_event_t type));
365 /* no match ipv6 address prefix list */
366 extern void route_map_no_match_ipv6_address_prefix_list_hook(int (*func)(
367 struct vty *vty, struct route_map_index *index, const char *command,
368 const char *arg, route_map_event_t type));
369 /* match ipv6 next-hop type */
370 extern void route_map_match_ipv6_next_hop_type_hook(int (*func)(
371 struct vty *vty, struct route_map_index *index, const char *command,
372 const char *arg, route_map_event_t type));
373 /* no match ipv6 next-hop type */
374 extern void route_map_no_match_ipv6_next_hop_type_hook(int (*func)(
375 struct vty *vty, struct route_map_index *index, const char *command,
376 const char *arg, route_map_event_t type));
377 /* match metric */
378 extern void route_map_match_metric_hook(int (*func)(
379 struct vty *vty, struct route_map_index *index, const char *command,
380 const char *arg, route_map_event_t type));
381 /* no match metric */
382 extern void route_map_no_match_metric_hook(int (*func)(
383 struct vty *vty, struct route_map_index *index, const char *command,
384 const char *arg, route_map_event_t type));
385 /* match tag */
386 extern void route_map_match_tag_hook(int (*func)(
387 struct vty *vty, struct route_map_index *index, const char *command,
388 const char *arg, route_map_event_t type));
389 /* no match tag */
390 extern void route_map_no_match_tag_hook(int (*func)(
391 struct vty *vty, struct route_map_index *index, const char *command,
392 const char *arg, route_map_event_t type));
393 /* set ip nexthop */
394 extern void route_map_set_ip_nexthop_hook(
395 int (*func)(struct vty *vty, struct route_map_index *index,
396 const char *command, const char *arg));
397 /* no set ip nexthop */
398 extern void route_map_no_set_ip_nexthop_hook(
399 int (*func)(struct vty *vty, struct route_map_index *index,
400 const char *command, const char *arg));
401 /* set ipv6 nexthop local */
402 extern void route_map_set_ipv6_nexthop_local_hook(
403 int (*func)(struct vty *vty, struct route_map_index *index,
404 const char *command, const char *arg));
405 /* no set ipv6 nexthop local */
406 extern void route_map_no_set_ipv6_nexthop_local_hook(
407 int (*func)(struct vty *vty, struct route_map_index *index,
408 const char *command, const char *arg));
409 /* set metric */
410 extern void route_map_set_metric_hook(int (*func)(struct vty *vty,
411 struct route_map_index *index,
412 const char *command,
413 const char *arg));
414 /* no set metric */
415 extern void route_map_no_set_metric_hook(
416 int (*func)(struct vty *vty, struct route_map_index *index,
417 const char *command, const char *arg));
418 /* set tag */
419 extern void route_map_set_tag_hook(int (*func)(struct vty *vty,
420 struct route_map_index *index,
421 const char *command,
422 const char *arg));
423 /* no set tag */
424 extern void route_map_no_set_tag_hook(int (*func)(struct vty *vty,
425 struct route_map_index *index,
426 const char *command,
427 const char *arg));
428
429 extern void *route_map_rule_tag_compile(const char *arg);
430 extern void route_map_rule_tag_free(void *rule);
431
432 /* Increment the route-map used counter */
433 extern void route_map_counter_increment(struct route_map *map);
434
435 /* Decrement the route-map used counter */
436 extern void route_map_counter_decrement(struct route_map *map);
437
438 #ifdef __cplusplus
439 }
440 #endif
441
442 #endif /* _ZEBRA_ROUTEMAP_H */