]> git.proxmox.com Git - mirror_frr.git/blob - lib/routemap.h
Merge pull request #3509 from faickermo/fix_bgp_ipv6_default_nexthop
[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
157 QOBJ_FIELDS
158 };
159 DECLARE_QOBJ_TYPE(route_map_index)
160
161 /* Route map list structure. */
162 struct route_map {
163 /* Name of route map. */
164 char *name;
165
166 /* Route map's rule. */
167 struct route_map_index *head;
168 struct route_map_index *tail;
169
170 /* Make linked list. */
171 struct route_map *next;
172 struct route_map *prev;
173
174 /* Maintain update info */
175 bool to_be_processed; /* True if modification isn't acted on yet */
176 bool deleted; /* If 1, then this node will be deleted */
177
178 /* How many times have we applied this route-map */
179 uint64_t applied;
180
181 /* Counter to track active usage of this route-map */
182 uint16_t use_count;
183
184 QOBJ_FIELDS
185 };
186 DECLARE_QOBJ_TYPE(route_map)
187
188 /* Prototypes. */
189 extern void route_map_init(void);
190
191 /*
192 * This should only be called on shutdown
193 * Additionally this function sets the hooks to NULL
194 * before any processing is done.
195 */
196 extern void route_map_finish(void);
197
198 /* Add match statement to route map. */
199 extern int route_map_add_match(struct route_map_index *index,
200 const char *match_name, const char *match_arg,
201 route_map_event_t type);
202
203 /* Delete specified route match rule. */
204 extern int route_map_delete_match(struct route_map_index *index,
205 const char *match_name,
206 const char *match_arg);
207
208 extern const char *route_map_get_match_arg(struct route_map_index *index,
209 const char *match_name);
210
211 /* Add route-map set statement to the route map. */
212 extern int route_map_add_set(struct route_map_index *index,
213 const char *set_name, const char *set_arg);
214
215 /* Delete route map set rule. */
216 extern int route_map_delete_set(struct route_map_index *index,
217 const char *set_name, const char *set_arg);
218
219 /* Install rule command to the match list. */
220 extern void route_map_install_match(struct route_map_rule_cmd *cmd);
221
222 /*
223 * Install rule command to the set list.
224 *
225 * When installing a particular item, Allow a difference of handling
226 * of bad cli inputted(return NULL) -vs- this particular daemon cannot use
227 * this form of the command(return a pointer and handle it appropriately
228 * in the apply command). See 'set metric' command
229 * as it is handled in ripd/ripngd and ospfd.
230 */
231 extern void route_map_install_set(struct route_map_rule_cmd *cmd);
232
233 /* Lookup route map by name. */
234 extern struct route_map *route_map_lookup_by_name(const char *name);
235
236 /* Simple helper to warn if route-map does not exist. */
237 struct route_map *route_map_lookup_warn_noexist(struct vty *vty, const char *name);
238
239 /* Apply route map to the object. */
240 extern route_map_result_t route_map_apply(struct route_map *map,
241 const struct prefix *prefix,
242 route_map_object_t object_type,
243 void *object);
244
245 extern void route_map_add_hook(void (*func)(const char *));
246 extern void route_map_delete_hook(void (*func)(const char *));
247
248 /*
249 * This is the callback for when something has changed about a
250 * route-map. The interested parties can register to receive
251 * this data.
252 *
253 * name - Is the name of the changed route-map
254 */
255 extern void route_map_event_hook(void (*func)(const char *name));
256 extern int route_map_mark_updated(const char *name);
257 extern void route_map_walk_update_list(void (*update_fn)(char *name));
258 extern void route_map_upd8_dependency(route_map_event_t type, const char *arg,
259 const char *rmap_name);
260 extern void route_map_notify_dependencies(const char *affected_name,
261 route_map_event_t event);
262
263 extern int generic_match_add(struct vty *vty, struct route_map_index *index,
264 const char *command, const char *arg,
265 route_map_event_t type);
266
267 extern int generic_match_delete(struct vty *vty, struct route_map_index *index,
268 const char *command, const char *arg,
269 route_map_event_t type);
270 extern int generic_set_add(struct vty *vty, struct route_map_index *index,
271 const char *command, const char *arg);
272 extern int generic_set_delete(struct vty *vty, struct route_map_index *index,
273 const char *command, const char *arg);
274
275
276 /* match interface */
277 extern void route_map_match_interface_hook(int (*func)(
278 struct vty *vty, struct route_map_index *index, const char *command,
279 const char *arg, route_map_event_t type));
280 /* no match interface */
281 extern void route_map_no_match_interface_hook(int (*func)(
282 struct vty *vty, struct route_map_index *index, const char *command,
283 const char *arg, route_map_event_t type));
284 /* match ip address */
285 extern void route_map_match_ip_address_hook(int (*func)(
286 struct vty *vty, struct route_map_index *index, const char *command,
287 const char *arg, route_map_event_t type));
288 /* no match ip address */
289 extern void route_map_no_match_ip_address_hook(int (*func)(
290 struct vty *vty, struct route_map_index *index, const char *command,
291 const char *arg, route_map_event_t type));
292 /* match ip address prefix list */
293 extern void route_map_match_ip_address_prefix_list_hook(int (*func)(
294 struct vty *vty, struct route_map_index *index, const char *command,
295 const char *arg, route_map_event_t type));
296 /* no match ip address prefix list */
297 extern void route_map_no_match_ip_address_prefix_list_hook(int (*func)(
298 struct vty *vty, struct route_map_index *index, const char *command,
299 const char *arg, route_map_event_t type));
300 /* match ip next hop */
301 extern void route_map_match_ip_next_hop_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 ip next hop */
305 extern void route_map_no_match_ip_next_hop_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 next hop prefix list */
309 extern void route_map_match_ip_next_hop_prefix_list_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 next hop prefix list */
313 extern void route_map_no_match_ip_next_hop_prefix_list_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 next hop type */
317 extern void route_map_match_ip_next_hop_type_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 next hop type */
321 extern void route_map_no_match_ip_next_hop_type_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 ipv6 address */
325 extern void route_map_match_ipv6_address_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 ipv6 address */
329 extern void route_map_no_match_ipv6_address_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 ipv6 address prefix list */
333 extern void route_map_match_ipv6_address_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 ipv6 address prefix list */
337 extern void route_map_no_match_ipv6_address_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 ipv6 next-hop type */
341 extern void route_map_match_ipv6_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 ipv6 next-hop type */
345 extern void route_map_no_match_ipv6_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 metric */
349 extern void route_map_match_metric_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 metric */
353 extern void route_map_no_match_metric_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 tag */
357 extern void route_map_match_tag_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 tag */
361 extern void route_map_no_match_tag_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 /* set ip nexthop */
365 extern void route_map_set_ip_nexthop_hook(
366 int (*func)(struct vty *vty, struct route_map_index *index,
367 const char *command, const char *arg));
368 /* no set ip nexthop */
369 extern void route_map_no_set_ip_nexthop_hook(
370 int (*func)(struct vty *vty, struct route_map_index *index,
371 const char *command, const char *arg));
372 /* set ipv6 nexthop local */
373 extern void route_map_set_ipv6_nexthop_local_hook(
374 int (*func)(struct vty *vty, struct route_map_index *index,
375 const char *command, const char *arg));
376 /* no set ipv6 nexthop local */
377 extern void route_map_no_set_ipv6_nexthop_local_hook(
378 int (*func)(struct vty *vty, struct route_map_index *index,
379 const char *command, const char *arg));
380 /* set metric */
381 extern void route_map_set_metric_hook(int (*func)(struct vty *vty,
382 struct route_map_index *index,
383 const char *command,
384 const char *arg));
385 /* no set metric */
386 extern void route_map_no_set_metric_hook(
387 int (*func)(struct vty *vty, struct route_map_index *index,
388 const char *command, const char *arg));
389 /* set tag */
390 extern void route_map_set_tag_hook(int (*func)(struct vty *vty,
391 struct route_map_index *index,
392 const char *command,
393 const char *arg));
394 /* no set tag */
395 extern void route_map_no_set_tag_hook(int (*func)(struct vty *vty,
396 struct route_map_index *index,
397 const char *command,
398 const char *arg));
399
400 extern void *route_map_rule_tag_compile(const char *arg);
401 extern void route_map_rule_tag_free(void *rule);
402
403 /* Increment the route-map used counter */
404 extern void route_map_counter_increment(struct route_map *map);
405
406 /* Decrement the route-map used counter */
407 extern void route_map_counter_decrement(struct route_map *map);
408
409 #ifdef __cplusplus
410 }
411 #endif
412
413 #endif /* _ZEBRA_ROUTEMAP_H */