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