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
33 DECLARE_MTYPE(ROUTE_MAP_NAME
)
34 DECLARE_MTYPE(ROUTE_MAP_RULE
)
35 DECLARE_MTYPE(ROUTE_MAP_COMPILED
)
37 /* Route map's type. */
38 enum route_map_type
{ RMAP_PERMIT
, RMAP_DENY
, RMAP_ANY
};
58 typedef enum { RMAP_EXIT
, RMAP_GOTO
, RMAP_NEXT
} route_map_end_t
;
62 RMAP_EVENT_SET_DELETED
,
63 RMAP_EVENT_SET_REPLACED
,
64 RMAP_EVENT_MATCH_ADDED
,
65 RMAP_EVENT_MATCH_DELETED
,
66 RMAP_EVENT_MATCH_REPLACED
,
67 RMAP_EVENT_INDEX_ADDED
,
68 RMAP_EVENT_INDEX_DELETED
,
69 RMAP_EVENT_CALL_ADDED
, /* call to another routemap added */
70 RMAP_EVENT_CALL_DELETED
,
71 RMAP_EVENT_PLIST_ADDED
,
72 RMAP_EVENT_PLIST_DELETED
,
73 RMAP_EVENT_CLIST_ADDED
,
74 RMAP_EVENT_CLIST_DELETED
,
75 RMAP_EVENT_ECLIST_ADDED
,
76 RMAP_EVENT_ECLIST_DELETED
,
77 RMAP_EVENT_LLIST_ADDED
,
78 RMAP_EVENT_LLIST_DELETED
,
79 RMAP_EVENT_ASLIST_ADDED
,
80 RMAP_EVENT_ASLIST_DELETED
,
81 RMAP_EVENT_FILTER_ADDED
,
82 RMAP_EVENT_FILTER_DELETED
,
85 /* Depth limit in RMAP recursion using RMAP_CALL. */
86 #define RMAP_RECURSION_LIMIT 10
88 /* Route map rule structure for matching and setting. */
89 struct route_map_rule_cmd
{
90 /* Route map rule name (e.g. as-path, metric) */
93 /* Function for value set or match. */
94 route_map_result_t (*func_apply
)(void *rule
,
95 const struct prefix
*prefix
,
96 route_map_object_t type
,
99 /* Compile argument and return result as void *. */
100 void *(*func_compile
)(const char *);
102 /* Free allocated value by func_compile (). */
103 void (*func_free
)(void *);
106 /* Route map apply error. */
108 RMAP_COMPILE_SUCCESS
,
110 /* Route map rule is missing. */
113 /* Route map rule can't compile */
116 /* Route map rule is duplicate */
120 /* Route map rule list. */
121 struct route_map_rule_list
{
122 struct route_map_rule
*head
;
123 struct route_map_rule
*tail
;
126 /* Route map index structure. */
127 struct route_map_index
{
128 struct route_map
*map
;
131 /* Preference of this route map rule. */
134 /* Route map type permit or deny. */
135 enum route_map_type type
;
137 /* Do we follow old rules, or hop forward? */
138 route_map_end_t exitpolicy
;
140 /* If we're using "GOTO", to where do we go? */
143 /* If we're using "CALL", to which route-map do ew go? */
146 /* Matching rule list. */
147 struct route_map_rule_list match_list
;
148 struct route_map_rule_list set_list
;
150 /* Make linked list. */
151 struct route_map_index
*next
;
152 struct route_map_index
*prev
;
154 /* Keep track how many times we've try to apply */
159 DECLARE_QOBJ_TYPE(route_map_index
)
161 /* Route map list structure. */
163 /* Name of route map. */
166 /* Route map's rule. */
167 struct route_map_index
*head
;
168 struct route_map_index
*tail
;
170 /* Make linked list. */
171 struct route_map
*next
;
172 struct route_map
*prev
;
174 /* Maintain update info */
175 bool to_be_processed
; /* True if modification isn't acted on yet */
176 bool deleted
; /* If 1, then this node will be deleted */
178 /* How many times have we applied this route-map */
181 /* Counter to track active usage of this route-map */
186 DECLARE_QOBJ_TYPE(route_map
)
189 extern void route_map_init(void);
192 * This should only be called on shutdown
193 * Additionally this function sets the hooks to NULL
194 * before any processing is done.
196 extern void route_map_finish(void);
198 /* Add match statement to route map. */
199 extern int route_map_add_match(struct route_map_index
*index
,
200 const char *match_name
, const char *match_arg
,
201 route_map_event_t type
);
203 /* Delete specified route match rule. */
204 extern int route_map_delete_match(struct route_map_index
*index
,
205 const char *match_name
,
206 const char *match_arg
);
208 extern const char *route_map_get_match_arg(struct route_map_index
*index
,
209 const char *match_name
);
211 /* Add route-map set statement to the route map. */
212 extern int route_map_add_set(struct route_map_index
*index
,
213 const char *set_name
, const char *set_arg
);
215 /* Delete route map set rule. */
216 extern int route_map_delete_set(struct route_map_index
*index
,
217 const char *set_name
, const char *set_arg
);
219 /* Install rule command to the match list. */
220 extern void route_map_install_match(struct route_map_rule_cmd
*cmd
);
223 * Install rule command to the set list.
225 * When installing a particular item, Allow a difference of handling
226 * of bad cli inputted(return NULL) -vs- this particular daemon cannot use
227 * this form of the command(return a pointer and handle it appropriately
228 * in the apply command). See 'set metric' command
229 * as it is handled in ripd/ripngd and ospfd.
231 extern void route_map_install_set(struct route_map_rule_cmd
*cmd
);
233 /* Lookup route map by name. */
234 extern struct route_map
*route_map_lookup_by_name(const char *name
);
236 /* Simple helper to warn if route-map does not exist. */
237 struct route_map
*route_map_lookup_warn_noexist(struct vty
*vty
, const char *name
);
239 /* Apply route map to the object. */
240 extern route_map_result_t
route_map_apply(struct route_map
*map
,
241 const struct prefix
*prefix
,
242 route_map_object_t object_type
,
245 extern void route_map_add_hook(void (*func
)(const char *));
246 extern void route_map_delete_hook(void (*func
)(const char *));
249 * This is the callback for when something has changed about a
250 * route-map. The interested parties can register to receive
253 * name - Is the name of the changed route-map
255 extern void route_map_event_hook(void (*func
)(const char *name
));
256 extern int route_map_mark_updated(const char *name
);
257 extern void route_map_walk_update_list(void (*update_fn
)(char *name
));
258 extern void route_map_upd8_dependency(route_map_event_t type
, const char *arg
,
259 const char *rmap_name
);
260 extern void route_map_notify_dependencies(const char *affected_name
,
261 route_map_event_t event
);
263 extern int generic_match_add(struct vty
*vty
, struct route_map_index
*index
,
264 const char *command
, const char *arg
,
265 route_map_event_t type
);
267 extern int generic_match_delete(struct vty
*vty
, struct route_map_index
*index
,
268 const char *command
, const char *arg
,
269 route_map_event_t type
);
270 extern int generic_set_add(struct vty
*vty
, struct route_map_index
*index
,
271 const char *command
, const char *arg
);
272 extern int generic_set_delete(struct vty
*vty
, struct route_map_index
*index
,
273 const char *command
, const char *arg
);
276 /* match interface */
277 extern void route_map_match_interface_hook(int (*func
)(
278 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
279 const char *arg
, route_map_event_t type
));
280 /* no match interface */
281 extern void route_map_no_match_interface_hook(int (*func
)(
282 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
283 const char *arg
, route_map_event_t type
));
284 /* match ip address */
285 extern void route_map_match_ip_address_hook(int (*func
)(
286 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
287 const char *arg
, route_map_event_t type
));
288 /* no match ip address */
289 extern void route_map_no_match_ip_address_hook(int (*func
)(
290 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
291 const char *arg
, route_map_event_t type
));
292 /* match ip address prefix list */
293 extern void route_map_match_ip_address_prefix_list_hook(int (*func
)(
294 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
295 const char *arg
, route_map_event_t type
));
296 /* no match ip address prefix list */
297 extern void route_map_no_match_ip_address_prefix_list_hook(int (*func
)(
298 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
299 const char *arg
, route_map_event_t type
));
300 /* match ip next hop */
301 extern void route_map_match_ip_next_hop_hook(int (*func
)(
302 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
303 const char *arg
, route_map_event_t type
));
304 /* no match ip next hop */
305 extern void route_map_no_match_ip_next_hop_hook(int (*func
)(
306 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
307 const char *arg
, route_map_event_t type
));
308 /* match ip next hop prefix list */
309 extern void route_map_match_ip_next_hop_prefix_list_hook(int (*func
)(
310 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
311 const char *arg
, route_map_event_t type
));
312 /* no match ip next hop prefix list */
313 extern void route_map_no_match_ip_next_hop_prefix_list_hook(int (*func
)(
314 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
315 const char *arg
, route_map_event_t type
));
316 /* match ip next hop type */
317 extern void route_map_match_ip_next_hop_type_hook(int (*func
)(
318 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
319 const char *arg
, route_map_event_t type
));
320 /* no match ip next hop type */
321 extern void route_map_no_match_ip_next_hop_type_hook(int (*func
)(
322 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
323 const char *arg
, route_map_event_t type
));
324 /* match ipv6 address */
325 extern void route_map_match_ipv6_address_hook(int (*func
)(
326 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
327 const char *arg
, route_map_event_t type
));
328 /* no match ipv6 address */
329 extern void route_map_no_match_ipv6_address_hook(int (*func
)(
330 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
331 const char *arg
, route_map_event_t type
));
332 /* match ipv6 address prefix list */
333 extern void route_map_match_ipv6_address_prefix_list_hook(int (*func
)(
334 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
335 const char *arg
, route_map_event_t type
));
336 /* no match ipv6 address prefix list */
337 extern void route_map_no_match_ipv6_address_prefix_list_hook(int (*func
)(
338 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
339 const char *arg
, route_map_event_t type
));
340 /* match ipv6 next-hop type */
341 extern void route_map_match_ipv6_next_hop_type_hook(int (*func
)(
342 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
343 const char *arg
, route_map_event_t type
));
344 /* no match ipv6 next-hop type */
345 extern void route_map_no_match_ipv6_next_hop_type_hook(int (*func
)(
346 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
347 const char *arg
, route_map_event_t type
));
349 extern void route_map_match_metric_hook(int (*func
)(
350 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
351 const char *arg
, route_map_event_t type
));
352 /* no match metric */
353 extern void route_map_no_match_metric_hook(int (*func
)(
354 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
355 const char *arg
, route_map_event_t type
));
357 extern void route_map_match_tag_hook(int (*func
)(
358 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
359 const char *arg
, route_map_event_t type
));
361 extern void route_map_no_match_tag_hook(int (*func
)(
362 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
363 const char *arg
, route_map_event_t type
));
365 extern void route_map_set_ip_nexthop_hook(
366 int (*func
)(struct vty
*vty
, struct route_map_index
*index
,
367 const char *command
, const char *arg
));
368 /* no set ip nexthop */
369 extern void route_map_no_set_ip_nexthop_hook(
370 int (*func
)(struct vty
*vty
, struct route_map_index
*index
,
371 const char *command
, const char *arg
));
372 /* set ipv6 nexthop local */
373 extern void route_map_set_ipv6_nexthop_local_hook(
374 int (*func
)(struct vty
*vty
, struct route_map_index
*index
,
375 const char *command
, const char *arg
));
376 /* no set ipv6 nexthop local */
377 extern void route_map_no_set_ipv6_nexthop_local_hook(
378 int (*func
)(struct vty
*vty
, struct route_map_index
*index
,
379 const char *command
, const char *arg
));
381 extern void route_map_set_metric_hook(int (*func
)(struct vty
*vty
,
382 struct route_map_index
*index
,
386 extern void route_map_no_set_metric_hook(
387 int (*func
)(struct vty
*vty
, struct route_map_index
*index
,
388 const char *command
, const char *arg
));
390 extern void route_map_set_tag_hook(int (*func
)(struct vty
*vty
,
391 struct route_map_index
*index
,
395 extern void route_map_no_set_tag_hook(int (*func
)(struct vty
*vty
,
396 struct route_map_index
*index
,
400 extern void *route_map_rule_tag_compile(const char *arg
);
401 extern void route_map_rule_tag_free(void *rule
);
403 /* Increment the route-map used counter */
404 extern void route_map_counter_increment(struct route_map
*map
);
406 /* Decrement the route-map used counter */
407 extern void route_map_counter_decrement(struct route_map
*map
);
413 #endif /* _ZEBRA_ROUTEMAP_H */