]> git.proxmox.com Git - mirror_frr.git/blob - lib/routemap.h
Merge branch 'cmaster-next' into vtysh-grammar
[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
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
25 #include "prefix.h"
26 #include "memory.h"
27 #include "qobj.h"
28 #include "vty.h"
29
30 DECLARE_MTYPE(ROUTE_MAP_NAME)
31 DECLARE_MTYPE(ROUTE_MAP_RULE)
32 DECLARE_MTYPE(ROUTE_MAP_COMPILED)
33
34 /* Route map's type. */
35 enum route_map_type
36 {
37 RMAP_PERMIT,
38 RMAP_DENY,
39 RMAP_ANY
40 };
41
42 typedef enum
43 {
44 RMAP_MATCH,
45 RMAP_DENYMATCH,
46 RMAP_NOMATCH,
47 RMAP_ERROR,
48 RMAP_OKAY
49 } route_map_result_t;
50
51 typedef enum
52 {
53 RMAP_RIP,
54 RMAP_RIPNG,
55 RMAP_OSPF,
56 RMAP_OSPF6,
57 RMAP_BGP,
58 RMAP_ZEBRA,
59 RMAP_ISIS,
60 } route_map_object_t;
61
62 typedef enum
63 {
64 RMAP_EXIT,
65 RMAP_GOTO,
66 RMAP_NEXT
67 } route_map_end_t;
68
69 typedef 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,
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,
91 } route_map_event_t;
92
93 /* Depth limit in RMAP recursion using RMAP_CALL. */
94 #define RMAP_RECURSION_LIMIT 10
95
96 /* Route map rule structure for matching and setting. */
97 struct route_map_rule_cmd
98 {
99 /* Route map rule name (e.g. as-path, metric) */
100 const char *str;
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 *. */
107 void *(*func_compile)(const char *);
108
109 /* Free allocated value by func_compile (). */
110 void (*func_free)(void *);
111 };
112
113 /* Route map apply error. */
114 enum
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. */
124 struct route_map_rule_list
125 {
126 struct route_map_rule *head;
127 struct route_map_rule *tail;
128 };
129
130 /* Route map index structure. */
131 struct route_map_index
132 {
133 struct route_map *map;
134 char *description;
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
148 /* If we're using "CALL", to which route-map do ew go? */
149 char *nextrm;
150
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;
158
159 QOBJ_FIELDS
160 };
161 DECLARE_QOBJ_TYPE(route_map_index)
162
163 /* Route map list structure. */
164 struct 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;
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 */
180
181 QOBJ_FIELDS
182 };
183 DECLARE_QOBJ_TYPE(route_map)
184
185 /* Prototypes. */
186 extern void route_map_init (void);
187 extern void route_map_finish (void);
188
189 /* Add match statement to route map. */
190 extern int route_map_add_match (struct route_map_index *index,
191 const char *match_name,
192 const char *match_arg);
193
194 /* Delete specified route match rule. */
195 extern int route_map_delete_match (struct route_map_index *index,
196 const char *match_name,
197 const char *match_arg);
198
199 extern const char *route_map_get_match_arg (struct route_map_index *index,
200 const char *match_name);
201
202 /* Add route-map set statement to the route map. */
203 extern int route_map_add_set (struct route_map_index *index,
204 const char *set_name,
205 const char *set_arg);
206
207 /* Delete route map set rule. */
208 extern int route_map_delete_set (struct route_map_index *index,
209 const char *set_name,
210 const char *set_arg);
211
212 /* Install rule command to the match list. */
213 extern void route_map_install_match (struct route_map_rule_cmd *cmd);
214
215 /* Install rule command to the set list. */
216 extern void route_map_install_set (struct route_map_rule_cmd *cmd);
217
218 /* Lookup route map by name. */
219 extern struct route_map * route_map_lookup_by_name (const char *name);
220
221 /* Apply route map to the object. */
222 extern 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
227 extern void route_map_add_hook (void (*func) (const char *));
228 extern void route_map_delete_hook (void (*func) (const char *));
229 extern void route_map_event_hook (void (*func) (route_map_event_t,
230 const char *));
231 extern int route_map_mark_updated (const char *name, int deleted);
232 extern int route_map_clear_updated (struct route_map *rmap);
233 extern void route_map_walk_update_list (int (*update_fn) (char *name));
234 extern void route_map_upd8_dependency (route_map_event_t type, const char *arg,
235 const char *rmap_name);
236 extern void route_map_notify_dependencies (const char *affected_name,
237 route_map_event_t event);
238
239 extern 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
245 extern 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);
250 extern int generic_set_add (struct vty *vty, struct route_map_index *index,
251 const char *command, const char *arg);
252 extern int generic_set_delete (struct vty *vty, struct route_map_index *index,
253 const char *command, const char *arg);
254
255
256 /* match interface */
257 extern 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 */
263 extern 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 */
269 extern 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 */
275 extern 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 */
281 extern 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 */
287 extern 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 */
293 extern 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 */
299 extern 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 */
305 extern 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 */
311 extern 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 */
317 extern 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 */
323 extern 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 */
329 extern 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 */
335 extern 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 */
341 extern 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 */
347 extern 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 */
353 extern 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 */
359 extern 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 */
365 extern 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 */
370 extern 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 */
375 extern 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 */
380 extern 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 */
385 extern 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 */
390 extern 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 */
395 extern 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 */
400 extern 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));
404
405 extern void *route_map_rule_tag_compile (const char *arg);
406 extern void route_map_rule_tag_free (void *rule);
407
408 #endif /* _ZEBRA_ROUTEMAP_H */