]> git.proxmox.com Git - mirror_frr.git/blame - lib/routemap.h
Merge branch 'cmaster-next' into vtysh-grammar
[mirror_frr.git] / lib / routemap.h
CommitLineData
718e3744 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
17 * along with GNU Zebra; see the file COPYING. If not, write to the Free
18 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 * 02111-1307, USA.
20 */
21
22#ifndef _ZEBRA_ROUTEMAP_H
23#define _ZEBRA_ROUTEMAP_H
24
24873f0c 25#include "prefix.h"
4a1ab8e4 26#include "memory.h"
e80e7cce 27#include "qobj.h"
4a1ab8e4
DL
28DECLARE_MTYPE(ROUTE_MAP_NAME)
29DECLARE_MTYPE(ROUTE_MAP_RULE)
30DECLARE_MTYPE(ROUTE_MAP_COMPILED)
24873f0c 31
718e3744 32/* Route map's type. */
33enum route_map_type
34{
35 RMAP_PERMIT,
36 RMAP_DENY,
37 RMAP_ANY
38};
39
40typedef enum
41{
42 RMAP_MATCH,
43 RMAP_DENYMATCH,
44 RMAP_NOMATCH,
45 RMAP_ERROR,
46 RMAP_OKAY
47} route_map_result_t;
48
49typedef enum
50{
51 RMAP_RIP,
52 RMAP_RIPNG,
53 RMAP_OSPF,
54 RMAP_OSPF6,
7514fb77 55 RMAP_BGP,
f3ccedaa
CF
56 RMAP_ZEBRA,
57 RMAP_ISIS,
718e3744 58} route_map_object_t;
59
60typedef enum
61{
62 RMAP_EXIT,
63 RMAP_GOTO,
64 RMAP_NEXT
65} route_map_end_t;
66
67typedef enum
68{
69 RMAP_EVENT_SET_ADDED,
70 RMAP_EVENT_SET_DELETED,
71 RMAP_EVENT_SET_REPLACED,
72 RMAP_EVENT_MATCH_ADDED,
73 RMAP_EVENT_MATCH_DELETED,
74 RMAP_EVENT_MATCH_REPLACED,
75 RMAP_EVENT_INDEX_ADDED,
518f0eb1
DS
76 RMAP_EVENT_INDEX_DELETED,
77 RMAP_EVENT_CALL_ADDED, /* call to another routemap added */
78 RMAP_EVENT_CALL_DELETED,
79 RMAP_EVENT_PLIST_ADDED,
80 RMAP_EVENT_PLIST_DELETED,
81 RMAP_EVENT_CLIST_ADDED,
82 RMAP_EVENT_CLIST_DELETED,
83 RMAP_EVENT_ECLIST_ADDED,
84 RMAP_EVENT_ECLIST_DELETED,
85 RMAP_EVENT_ASLIST_ADDED,
86 RMAP_EVENT_ASLIST_DELETED,
87 RMAP_EVENT_FILTER_ADDED,
88 RMAP_EVENT_FILTER_DELETED,
718e3744 89} route_map_event_t;
90
fee0f4c6 91/* Depth limit in RMAP recursion using RMAP_CALL. */
92#define RMAP_RECURSION_LIMIT 10
93
718e3744 94/* Route map rule structure for matching and setting. */
95struct route_map_rule_cmd
96{
97 /* Route map rule name (e.g. as-path, metric) */
27a43a81 98 const char *str;
718e3744 99
100 /* Function for value set or match. */
101 route_map_result_t (*func_apply)(void *, struct prefix *,
102 route_map_object_t, void *);
103
104 /* Compile argument and return result as void *. */
c9eca01b 105 void *(*func_compile)(const char *);
718e3744 106
107 /* Free allocated value by func_compile (). */
108 void (*func_free)(void *);
109};
110
111/* Route map apply error. */
112enum
113{
114 /* Route map rule is missing. */
115 RMAP_RULE_MISSING = 1,
116
117 /* Route map rule can't compile */
118 RMAP_COMPILE_ERROR
119};
120
121/* Route map rule list. */
122struct route_map_rule_list
123{
124 struct route_map_rule *head;
125 struct route_map_rule *tail;
126};
127
128/* Route map index structure. */
129struct route_map_index
130{
131 struct route_map *map;
4a8164e5 132 char *description;
718e3744 133
134 /* Preference of this route map rule. */
135 int pref;
136
137 /* Route map type permit or deny. */
138 enum route_map_type type;
139
140 /* Do we follow old rules, or hop forward? */
141 route_map_end_t exitpolicy;
142
143 /* If we're using "GOTO", to where do we go? */
144 int nextpref;
145
fee0f4c6 146 /* If we're using "CALL", to which route-map do ew go? */
147 char *nextrm;
148
718e3744 149 /* Matching rule list. */
150 struct route_map_rule_list match_list;
151 struct route_map_rule_list set_list;
152
153 /* Make linked list. */
154 struct route_map_index *next;
155 struct route_map_index *prev;
e80e7cce
DL
156
157 QOBJ_FIELDS
718e3744 158};
e80e7cce 159DECLARE_QOBJ_TYPE(route_map_index)
718e3744 160
161/* Route map list structure. */
162struct route_map
163{
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;
518f0eb1
DS
174
175 /* Maintain update info */
176 int to_be_processed; /* True if modification isn't acted on yet */
177 int deleted; /* If 1, then this node will be deleted */
e80e7cce
DL
178
179 QOBJ_FIELDS
718e3744 180};
e80e7cce 181DECLARE_QOBJ_TYPE(route_map)
718e3744 182
183/* Prototypes. */
8cc4198f 184extern void route_map_init (void);
185extern void route_map_init_vty (void);
228da428 186extern void route_map_finish (void);
718e3744 187
188/* Add match statement to route map. */
8cc4198f 189extern int route_map_add_match (struct route_map_index *index,
190 const char *match_name,
191 const char *match_arg);
718e3744 192
193/* Delete specified route match rule. */
8cc4198f 194extern int route_map_delete_match (struct route_map_index *index,
195 const char *match_name,
196 const char *match_arg);
718e3744 197
518f0eb1
DS
198extern const char *route_map_get_match_arg (struct route_map_index *index,
199 const char *match_name);
200
718e3744 201/* Add route-map set statement to the route map. */
8cc4198f 202extern int route_map_add_set (struct route_map_index *index,
203 const char *set_name,
204 const char *set_arg);
718e3744 205
206/* Delete route map set rule. */
8cc4198f 207extern int route_map_delete_set (struct route_map_index *index,
208 const char *set_name,
209 const char *set_arg);
718e3744 210
211/* Install rule command to the match list. */
8cc4198f 212extern void route_map_install_match (struct route_map_rule_cmd *cmd);
718e3744 213
214/* Install rule command to the set list. */
8cc4198f 215extern void route_map_install_set (struct route_map_rule_cmd *cmd);
718e3744 216
217/* Lookup route map by name. */
8cc4198f 218extern struct route_map * route_map_lookup_by_name (const char *name);
718e3744 219
220/* Apply route map to the object. */
8cc4198f 221extern route_map_result_t route_map_apply (struct route_map *map,
222 struct prefix *,
223 route_map_object_t object_type,
224 void *object);
225
226extern void route_map_add_hook (void (*func) (const char *));
227extern void route_map_delete_hook (void (*func) (const char *));
518f0eb1
DS
228extern void route_map_event_hook (void (*func) (route_map_event_t,
229 const char *));
230extern int route_map_mark_updated (const char *name, int deleted);
231extern int route_map_clear_updated (struct route_map *rmap);
5fe9f963 232extern void route_map_walk_update_list (int (*update_fn) (char *name));
518f0eb1
DS
233extern void route_map_upd8_dependency (route_map_event_t type, const char *arg,
234 const char *rmap_name);
235extern void route_map_notify_dependencies (const char *affected_name,
236 route_map_event_t event);
718e3744 237
82f97584
DW
238extern int generic_match_add (struct vty *vty,
239 struct route_map_index *index,
240 const char *command,
241 const char *arg,
242 route_map_event_t type);
243
244extern int generic_match_delete (struct vty *vty,
245 struct route_map_index *index,
246 const char *command,
247 const char *arg,
248 route_map_event_t type);
249extern int generic_set_add (struct vty *vty, struct route_map_index *index,
250 const char *command, const char *arg);
251extern int generic_set_delete (struct vty *vty, struct route_map_index *index,
252 const char *command, const char *arg);
253
254
255/* match interface */
256extern void route_map_match_interface_hook (int (*func) (struct vty *vty,
257 struct route_map_index *index,
258 const char *command,
259 const char *arg,
260 route_map_event_t type));
261/* no match interface */
262extern void route_map_no_match_interface_hook (int (*func) (struct vty *vty,
263 struct route_map_index *index,
264 const char *command,
265 const char *arg,
266 route_map_event_t type));
267/* match ip address */
268extern void route_map_match_ip_address_hook (int (*func) (struct vty *vty,
269 struct route_map_index *index,
270 const char *command,
271 const char *arg,
272 route_map_event_t type));
273/* no match ip address */
274extern void route_map_no_match_ip_address_hook (int (*func) (struct vty *vty,
275 struct route_map_index *index,
276 const char *command,
277 const char *arg,
278 route_map_event_t type));
279/* match ip address prefix list */
280extern void route_map_match_ip_address_prefix_list_hook (int (*func) (struct vty *vty,
281 struct route_map_index *index,
282 const char *command,
283 const char *arg,
284 route_map_event_t type));
285/* no match ip address prefix list */
286extern void route_map_no_match_ip_address_prefix_list_hook (int (*func) (struct vty *vty,
287 struct route_map_index *index,
288 const char *command,
289 const char *arg,
290 route_map_event_t type));
291/* match ip next hop */
292extern void route_map_match_ip_next_hop_hook (int (*func) (struct vty *vty,
293 struct route_map_index *index,
294 const char *command,
295 const char *arg,
296 route_map_event_t type));
297/* no match ip next hop */
298extern void route_map_no_match_ip_next_hop_hook (int (*func) (struct vty *vty,
299 struct route_map_index *index,
300 const char *command,
301 const char *arg,
302 route_map_event_t type));
303/* match ip next hop prefix list */
304extern void route_map_match_ip_next_hop_prefix_list_hook (int (*func) (struct vty *vty,
305 struct route_map_index *index,
306 const char *command,
307 const char *arg,
308 route_map_event_t type));
309/* no match ip next hop prefix list */
310extern void route_map_no_match_ip_next_hop_prefix_list_hook (int (*func) (struct vty *vty,
311 struct route_map_index *index,
312 const char *command,
313 const char *arg,
314 route_map_event_t type));
315/* match ipv6 address */
316extern void route_map_match_ipv6_address_hook (int (*func) (struct vty *vty,
317 struct route_map_index *index,
318 const char *command,
319 const char *arg,
320 route_map_event_t type));
321/* no match ipv6 address */
322extern void route_map_no_match_ipv6_address_hook (int (*func) (struct vty *vty,
323 struct route_map_index *index,
324 const char *command,
325 const char *arg,
326 route_map_event_t type));
327/* match ipv6 address prefix list */
328extern void route_map_match_ipv6_address_prefix_list_hook (int (*func) (struct vty *vty,
329 struct route_map_index *index,
330 const char *command,
331 const char *arg,
332 route_map_event_t type));
333/* no match ipv6 address prefix list */
334extern void route_map_no_match_ipv6_address_prefix_list_hook (int (*func) (struct vty *vty,
335 struct route_map_index *index,
336 const char *command,
337 const char *arg,
338 route_map_event_t type));
339/* match metric */
340extern void route_map_match_metric_hook (int (*func) (struct vty *vty,
341 struct route_map_index *index,
342 const char *command,
343 const char *arg,
344 route_map_event_t type));
345/* no match metric */
346extern void route_map_no_match_metric_hook (int (*func) (struct vty *vty,
347 struct route_map_index *index,
348 const char *command,
349 const char *arg,
350 route_map_event_t type));
351/* match tag */
352extern void route_map_match_tag_hook (int (*func) (struct vty *vty,
353 struct route_map_index *index,
354 const char *command,
355 const char *arg,
356 route_map_event_t type));
357/* no match tag */
358extern void route_map_no_match_tag_hook (int (*func) (struct vty *vty,
359 struct route_map_index *index,
360 const char *command,
361 const char *arg,
362 route_map_event_t type));
363/* set ip nexthop */
364extern void route_map_set_ip_nexthop_hook (int (*func) (struct vty *vty,
365 struct route_map_index *index,
366 const char *command,
367 const char *arg));
368/* no set ip nexthop */
369extern void route_map_no_set_ip_nexthop_hook (int (*func) (struct vty *vty,
370 struct route_map_index *index,
371 const char *command,
372 const char *arg));
373/* set ipv6 nexthop local */
374extern void route_map_set_ipv6_nexthop_local_hook (int (*func) (struct vty *vty,
375 struct route_map_index *index,
376 const char *command,
377 const char *arg));
378/* no set ipv6 nexthop local */
379extern void route_map_no_set_ipv6_nexthop_local_hook (int (*func) (struct vty *vty,
380 struct route_map_index *index,
381 const char *command,
382 const char *arg));
383/* set metric */
384extern void route_map_set_metric_hook (int (*func) (struct vty *vty,
385 struct route_map_index *index,
386 const char *command,
387 const char *arg));
388/* no set metric */
389extern void route_map_no_set_metric_hook (int (*func) (struct vty *vty,
390 struct route_map_index *index,
391 const char *command,
392 const char *arg));
393/* set tag */
394extern void route_map_set_tag_hook (int (*func) (struct vty *vty,
395 struct route_map_index *index,
396 const char *command,
397 const char *arg));
398/* no set tag */
399extern void route_map_no_set_tag_hook (int (*func) (struct vty *vty,
400 struct route_map_index *index,
401 const char *command,
402 const char *arg));
e52702f2 403
dc9ffce8
CF
404extern void *route_map_rule_tag_compile (const char *arg);
405extern void route_map_rule_tag_free (void *rule);
406
718e3744 407#endif /* _ZEBRA_ROUTEMAP_H */