2 * Copyright (C) 1998 Kunihiro Ishiguro
4 * This file is part of GNU Zebra.
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
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.
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
22 #ifndef _ZEBRA_ROUTEMAP_H
23 #define _ZEBRA_ROUTEMAP_H
30 DECLARE_MTYPE(ROUTE_MAP_NAME
)
31 DECLARE_MTYPE(ROUTE_MAP_RULE
)
32 DECLARE_MTYPE(ROUTE_MAP_COMPILED
)
34 /* Route map's type. */
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
,
93 /* Depth limit in RMAP recursion using RMAP_CALL. */
94 #define RMAP_RECURSION_LIMIT 10
96 /* Route map rule structure for matching and setting. */
97 struct route_map_rule_cmd
99 /* Route map rule name (e.g. as-path, metric) */
102 /* Function for value set or match. */
103 route_map_result_t (*func_apply
)(void *, struct prefix
*,
104 route_map_object_t
, void *);
106 /* Compile argument and return result as void *. */
107 void *(*func_compile
)(const char *);
109 /* Free allocated value by func_compile (). */
110 void (*func_free
)(void *);
113 /* Route map apply error. */
116 /* Route map rule is missing. */
117 RMAP_RULE_MISSING
= 1,
119 /* Route map rule can't compile */
123 /* Route map rule list. */
124 struct route_map_rule_list
126 struct route_map_rule
*head
;
127 struct route_map_rule
*tail
;
130 /* Route map index structure. */
131 struct route_map_index
133 struct route_map
*map
;
136 /* Preference of this route map rule. */
139 /* Route map type permit or deny. */
140 enum route_map_type type
;
142 /* Do we follow old rules, or hop forward? */
143 route_map_end_t exitpolicy
;
145 /* If we're using "GOTO", to where do we go? */
148 /* If we're using "CALL", to which route-map do ew go? */
151 /* Matching rule list. */
152 struct route_map_rule_list match_list
;
153 struct route_map_rule_list set_list
;
155 /* Make linked list. */
156 struct route_map_index
*next
;
157 struct route_map_index
*prev
;
161 DECLARE_QOBJ_TYPE(route_map_index
)
163 /* Route map list structure. */
166 /* Name of route map. */
169 /* Route map's rule. */
170 struct route_map_index
*head
;
171 struct route_map_index
*tail
;
173 /* Make linked list. */
174 struct route_map
*next
;
175 struct route_map
*prev
;
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 */
183 DECLARE_QOBJ_TYPE(route_map
)
186 extern void route_map_init (void);
187 extern void route_map_finish (void);
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
);
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
);
199 extern const char *route_map_get_match_arg (struct route_map_index
*index
,
200 const char *match_name
);
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
);
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
);
212 /* Install rule command to the match list. */
213 extern void route_map_install_match (struct route_map_rule_cmd
*cmd
);
215 /* Install rule command to the set list. */
216 extern void route_map_install_set (struct route_map_rule_cmd
*cmd
);
218 /* Lookup route map by name. */
219 extern struct route_map
* route_map_lookup_by_name (const char *name
);
221 /* Apply route map to the object. */
222 extern route_map_result_t
route_map_apply (struct route_map
*map
,
224 route_map_object_t object_type
,
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
,
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
);
239 extern int generic_match_add (struct vty
*vty
,
240 struct route_map_index
*index
,
243 route_map_event_t type
);
245 extern int generic_match_delete (struct vty
*vty
,
246 struct route_map_index
*index
,
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
);
256 /* match interface */
257 extern void route_map_match_interface_hook (int (*func
) (struct vty
*vty
,
258 struct route_map_index
*index
,
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
,
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
,
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
,
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
,
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
,
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
,
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
,
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
,
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
,
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
,
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
,
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
,
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
,
339 route_map_event_t type
));
341 extern void route_map_match_metric_hook (int (*func
) (struct vty
*vty
,
342 struct route_map_index
*index
,
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
,
351 route_map_event_t type
));
353 extern void route_map_match_tag_hook (int (*func
) (struct vty
*vty
,
354 struct route_map_index
*index
,
357 route_map_event_t type
));
359 extern void route_map_no_match_tag_hook (int (*func
) (struct vty
*vty
,
360 struct route_map_index
*index
,
363 route_map_event_t type
));
365 extern void route_map_set_ip_nexthop_hook (int (*func
) (struct vty
*vty
,
366 struct route_map_index
*index
,
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
,
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
,
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
,
385 extern void route_map_set_metric_hook (int (*func
) (struct vty
*vty
,
386 struct route_map_index
*index
,
390 extern void route_map_no_set_metric_hook (int (*func
) (struct vty
*vty
,
391 struct route_map_index
*index
,
395 extern void route_map_set_tag_hook (int (*func
) (struct vty
*vty
,
396 struct route_map_index
*index
,
400 extern void route_map_no_set_tag_hook (int (*func
) (struct vty
*vty
,
401 struct route_map_index
*index
,
405 extern void *route_map_rule_tag_compile (const char *arg
);
406 extern void route_map_rule_tag_free (void *rule
);
408 #endif /* _ZEBRA_ROUTEMAP_H */