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