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