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 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
21 #ifndef _ZEBRA_ROUTEMAP_H
22 #define _ZEBRA_ROUTEMAP_H
29 DECLARE_MTYPE(ROUTE_MAP_NAME
)
30 DECLARE_MTYPE(ROUTE_MAP_RULE
)
31 DECLARE_MTYPE(ROUTE_MAP_COMPILED
)
33 /* Route map's type. */
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
,
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
,
86 RMAP_EVENT_LLIST_ADDED
,
87 RMAP_EVENT_LLIST_DELETED
,
88 RMAP_EVENT_ASLIST_ADDED
,
89 RMAP_EVENT_ASLIST_DELETED
,
90 RMAP_EVENT_FILTER_ADDED
,
91 RMAP_EVENT_FILTER_DELETED
,
94 /* Depth limit in RMAP recursion using RMAP_CALL. */
95 #define RMAP_RECURSION_LIMIT 10
97 /* Route map rule structure for matching and setting. */
98 struct route_map_rule_cmd
100 /* Route map rule name (e.g. as-path, metric) */
103 /* Function for value set or match. */
104 route_map_result_t (*func_apply
)(void *, struct prefix
*,
105 route_map_object_t
, void *);
107 /* Compile argument and return result as void *. */
108 void *(*func_compile
)(const char *);
110 /* Free allocated value by func_compile (). */
111 void (*func_free
)(void *);
114 /* Route map apply error. */
117 /* Route map rule is missing. */
118 RMAP_RULE_MISSING
= 1,
120 /* Route map rule can't compile */
124 /* Route map rule list. */
125 struct route_map_rule_list
127 struct route_map_rule
*head
;
128 struct route_map_rule
*tail
;
131 /* Route map index structure. */
132 struct route_map_index
134 struct route_map
*map
;
137 /* Preference of this route map rule. */
140 /* Route map type permit or deny. */
141 enum route_map_type type
;
143 /* Do we follow old rules, or hop forward? */
144 route_map_end_t exitpolicy
;
146 /* If we're using "GOTO", to where do we go? */
149 /* If we're using "CALL", to which route-map do ew go? */
152 /* Matching rule list. */
153 struct route_map_rule_list match_list
;
154 struct route_map_rule_list set_list
;
156 /* Make linked list. */
157 struct route_map_index
*next
;
158 struct route_map_index
*prev
;
162 DECLARE_QOBJ_TYPE(route_map_index
)
164 /* Route map list structure. */
167 /* Name of route map. */
170 /* Route map's rule. */
171 struct route_map_index
*head
;
172 struct route_map_index
*tail
;
174 /* Make linked list. */
175 struct route_map
*next
;
176 struct route_map
*prev
;
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 */
184 DECLARE_QOBJ_TYPE(route_map
)
187 extern void route_map_init (void);
188 extern void route_map_finish (void);
190 /* Add match statement to route map. */
191 extern int route_map_add_match (struct route_map_index
*index
,
192 const char *match_name
,
193 const char *match_arg
);
195 /* Delete specified route match rule. */
196 extern int route_map_delete_match (struct route_map_index
*index
,
197 const char *match_name
,
198 const char *match_arg
);
200 extern const char *route_map_get_match_arg (struct route_map_index
*index
,
201 const char *match_name
);
203 /* Add route-map set statement to the route map. */
204 extern int route_map_add_set (struct route_map_index
*index
,
205 const char *set_name
,
206 const char *set_arg
);
208 /* Delete route map set rule. */
209 extern int route_map_delete_set (struct route_map_index
*index
,
210 const char *set_name
,
211 const char *set_arg
);
213 /* Install rule command to the match list. */
214 extern void route_map_install_match (struct route_map_rule_cmd
*cmd
);
216 /* Install rule command to the set list. */
217 extern void route_map_install_set (struct route_map_rule_cmd
*cmd
);
219 /* Lookup route map by name. */
220 extern struct route_map
* route_map_lookup_by_name (const char *name
);
222 /* Apply route map to the object. */
223 extern route_map_result_t
route_map_apply (struct route_map
*map
,
225 route_map_object_t object_type
,
228 extern void route_map_add_hook (void (*func
) (const char *));
229 extern void route_map_delete_hook (void (*func
) (const char *));
230 extern void route_map_event_hook (void (*func
) (route_map_event_t
,
232 extern int route_map_mark_updated (const char *name
, int deleted
);
233 extern int route_map_clear_updated (struct route_map
*rmap
);
234 extern void route_map_walk_update_list (int (*update_fn
) (char *name
));
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
);
240 extern int generic_match_add (struct vty
*vty
,
241 struct route_map_index
*index
,
244 route_map_event_t type
);
246 extern int generic_match_delete (struct vty
*vty
,
247 struct route_map_index
*index
,
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
);
257 /* match interface */
258 extern void route_map_match_interface_hook (int (*func
) (struct vty
*vty
,
259 struct route_map_index
*index
,
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
,
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
,
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
,
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
,
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
,
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
,
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
,
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
,
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
,
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
,
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
,
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
,
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
,
340 route_map_event_t type
));
342 extern void route_map_match_metric_hook (int (*func
) (struct vty
*vty
,
343 struct route_map_index
*index
,
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
,
352 route_map_event_t type
));
354 extern void route_map_match_tag_hook (int (*func
) (struct vty
*vty
,
355 struct route_map_index
*index
,
358 route_map_event_t type
));
360 extern void route_map_no_match_tag_hook (int (*func
) (struct vty
*vty
,
361 struct route_map_index
*index
,
364 route_map_event_t type
));
366 extern void route_map_set_ip_nexthop_hook (int (*func
) (struct vty
*vty
,
367 struct route_map_index
*index
,
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
,
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
,
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
,
386 extern void route_map_set_metric_hook (int (*func
) (struct vty
*vty
,
387 struct route_map_index
*index
,
391 extern void route_map_no_set_metric_hook (int (*func
) (struct vty
*vty
,
392 struct route_map_index
*index
,
396 extern void route_map_set_tag_hook (int (*func
) (struct vty
*vty
,
397 struct route_map_index
*index
,
401 extern void route_map_no_set_tag_hook (int (*func
) (struct vty
*vty
,
402 struct route_map_index
*index
,
406 extern void *route_map_rule_tag_compile (const char *arg
);
407 extern void route_map_rule_tag_free (void *rule
);
409 #endif /* _ZEBRA_ROUTEMAP_H */