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