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
};
46 * Route-map match or set result "Eg: match evpn vni xx"
47 * route-map match cmd always returns match/nomatch/noop
48 * match--> found a match
49 * nomatch--> didnt find a match
50 * noop--> not applicable
51 * route-map set retuns okay/error
52 * okay --> set was successful
53 * error --> set was not successful
55 enum route_map_cmd_result_t
{
57 * route-map match cmd results
63 * route-map set cmd results
80 typedef enum { RMAP_EXIT
, RMAP_GOTO
, RMAP_NEXT
} route_map_end_t
;
84 RMAP_EVENT_SET_DELETED
,
85 RMAP_EVENT_SET_REPLACED
,
86 RMAP_EVENT_MATCH_ADDED
,
87 RMAP_EVENT_MATCH_DELETED
,
88 RMAP_EVENT_MATCH_REPLACED
,
89 RMAP_EVENT_INDEX_ADDED
,
90 RMAP_EVENT_INDEX_DELETED
,
91 RMAP_EVENT_CALL_ADDED
, /* call to another routemap added */
92 RMAP_EVENT_CALL_DELETED
,
93 RMAP_EVENT_PLIST_ADDED
,
94 RMAP_EVENT_PLIST_DELETED
,
95 RMAP_EVENT_CLIST_ADDED
,
96 RMAP_EVENT_CLIST_DELETED
,
97 RMAP_EVENT_ECLIST_ADDED
,
98 RMAP_EVENT_ECLIST_DELETED
,
99 RMAP_EVENT_LLIST_ADDED
,
100 RMAP_EVENT_LLIST_DELETED
,
101 RMAP_EVENT_ASLIST_ADDED
,
102 RMAP_EVENT_ASLIST_DELETED
,
103 RMAP_EVENT_FILTER_ADDED
,
104 RMAP_EVENT_FILTER_DELETED
,
107 /* Depth limit in RMAP recursion using RMAP_CALL. */
108 #define RMAP_RECURSION_LIMIT 10
110 /* Route map rule structure for matching and setting. */
111 struct route_map_rule_cmd
{
112 /* Route map rule name (e.g. as-path, metric) */
115 /* Function for value set or match. */
116 enum route_map_cmd_result_t (*func_apply
)(void *rule
,
117 const struct prefix
*prefix
,
118 route_map_object_t type
,
121 /* Compile argument and return result as void *. */
122 void *(*func_compile
)(const char *);
124 /* Free allocated value by func_compile (). */
125 void (*func_free
)(void *);
128 /* Route map apply error. */
130 RMAP_COMPILE_SUCCESS
,
132 /* Route map rule is missing. */
135 /* Route map rule can't compile */
138 /* Route map rule is duplicate */
142 /* Route map rule list. */
143 struct route_map_rule_list
{
144 struct route_map_rule
*head
;
145 struct route_map_rule
*tail
;
148 /* Route map index structure. */
149 struct route_map_index
{
150 struct route_map
*map
;
153 /* Preference of this route map rule. */
156 /* Route map type permit or deny. */
157 enum route_map_type type
;
159 /* Do we follow old rules, or hop forward? */
160 route_map_end_t exitpolicy
;
162 /* If we're using "GOTO", to where do we go? */
165 /* If we're using "CALL", to which route-map do ew go? */
168 /* Matching rule list. */
169 struct route_map_rule_list match_list
;
170 struct route_map_rule_list set_list
;
172 /* Make linked list. */
173 struct route_map_index
*next
;
174 struct route_map_index
*prev
;
176 /* Keep track how many times we've try to apply */
178 uint64_t applied_clear
;
182 DECLARE_QOBJ_TYPE(route_map_index
)
184 /* Route map list structure. */
186 /* Name of route map. */
189 /* Route map's rule. */
190 struct route_map_index
*head
;
191 struct route_map_index
*tail
;
193 /* Make linked list. */
194 struct route_map
*next
;
195 struct route_map
*prev
;
197 /* Maintain update info */
198 bool to_be_processed
; /* True if modification isn't acted on yet */
199 bool deleted
; /* If 1, then this node will be deleted */
201 /* How many times have we applied this route-map */
203 uint64_t applied_clear
;
205 /* Counter to track active usage of this route-map */
210 DECLARE_QOBJ_TYPE(route_map
)
213 extern void route_map_init(void);
216 * This should only be called on shutdown
217 * Additionally this function sets the hooks to NULL
218 * before any processing is done.
220 extern void route_map_finish(void);
222 /* Add match statement to route map. */
223 extern int route_map_add_match(struct route_map_index
*index
,
224 const char *match_name
, const char *match_arg
,
225 route_map_event_t type
);
227 /* Delete specified route match rule. */
228 extern int route_map_delete_match(struct route_map_index
*index
,
229 const char *match_name
,
230 const char *match_arg
);
232 extern const char *route_map_get_match_arg(struct route_map_index
*index
,
233 const char *match_name
);
235 /* Add route-map set statement to the route map. */
236 extern int route_map_add_set(struct route_map_index
*index
,
237 const char *set_name
, const char *set_arg
);
239 /* Delete route map set rule. */
240 extern int route_map_delete_set(struct route_map_index
*index
,
241 const char *set_name
, const char *set_arg
);
243 /* Install rule command to the match list. */
244 extern void route_map_install_match(struct route_map_rule_cmd
*cmd
);
247 * Install rule command to the set list.
249 * When installing a particular item, Allow a difference of handling
250 * of bad cli inputted(return NULL) -vs- this particular daemon cannot use
251 * this form of the command(return a pointer and handle it appropriately
252 * in the apply command). See 'set metric' command
253 * as it is handled in ripd/ripngd and ospfd.
255 extern void route_map_install_set(struct route_map_rule_cmd
*cmd
);
257 /* Lookup route map by name. */
258 extern struct route_map
*route_map_lookup_by_name(const char *name
);
260 /* Simple helper to warn if route-map does not exist. */
261 struct route_map
*route_map_lookup_warn_noexist(struct vty
*vty
, const char *name
);
263 /* Apply route map to the object. */
264 extern route_map_result_t
route_map_apply(struct route_map
*map
,
265 const struct prefix
*prefix
,
266 route_map_object_t object_type
,
269 extern void route_map_add_hook(void (*func
)(const char *));
270 extern void route_map_delete_hook(void (*func
)(const char *));
273 * This is the callback for when something has changed about a
274 * route-map. The interested parties can register to receive
277 * name - Is the name of the changed route-map
279 extern void route_map_event_hook(void (*func
)(const char *name
));
280 extern int route_map_mark_updated(const char *name
);
281 extern void route_map_walk_update_list(void (*update_fn
)(char *name
));
282 extern void route_map_upd8_dependency(route_map_event_t type
, const char *arg
,
283 const char *rmap_name
);
284 extern void route_map_notify_dependencies(const char *affected_name
,
285 route_map_event_t event
);
287 extern int generic_match_add(struct vty
*vty
, struct route_map_index
*index
,
288 const char *command
, const char *arg
,
289 route_map_event_t type
);
291 extern int generic_match_delete(struct vty
*vty
, struct route_map_index
*index
,
292 const char *command
, const char *arg
,
293 route_map_event_t type
);
294 extern int generic_set_add(struct vty
*vty
, struct route_map_index
*index
,
295 const char *command
, const char *arg
);
296 extern int generic_set_delete(struct vty
*vty
, struct route_map_index
*index
,
297 const char *command
, const char *arg
);
300 /* match interface */
301 extern void route_map_match_interface_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 interface */
305 extern void route_map_no_match_interface_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 address */
309 extern void route_map_match_ip_address_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 address */
313 extern void route_map_no_match_ip_address_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 address prefix list */
317 extern void route_map_match_ip_address_prefix_list_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 address prefix list */
321 extern void route_map_no_match_ip_address_prefix_list_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 ip next hop */
325 extern void route_map_match_ip_next_hop_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 ip next hop */
329 extern void route_map_no_match_ip_next_hop_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 ip next hop prefix list */
333 extern void route_map_match_ip_next_hop_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 ip next hop prefix list */
337 extern void route_map_no_match_ip_next_hop_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 ip next hop type */
341 extern void route_map_match_ip_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 ip next hop type */
345 extern void route_map_no_match_ip_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
));
348 /* match ipv6 address */
349 extern void route_map_match_ipv6_address_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 ipv6 address */
353 extern void route_map_no_match_ipv6_address_hook(int (*func
)(
354 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
355 const char *arg
, route_map_event_t type
));
356 /* match ipv6 address prefix list */
357 extern void route_map_match_ipv6_address_prefix_list_hook(int (*func
)(
358 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
359 const char *arg
, route_map_event_t type
));
360 /* no match ipv6 address prefix list */
361 extern void route_map_no_match_ipv6_address_prefix_list_hook(int (*func
)(
362 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
363 const char *arg
, route_map_event_t type
));
364 /* match ipv6 next-hop type */
365 extern void route_map_match_ipv6_next_hop_type_hook(int (*func
)(
366 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
367 const char *arg
, route_map_event_t type
));
368 /* no match ipv6 next-hop type */
369 extern void route_map_no_match_ipv6_next_hop_type_hook(int (*func
)(
370 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
371 const char *arg
, route_map_event_t type
));
373 extern void route_map_match_metric_hook(int (*func
)(
374 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
375 const char *arg
, route_map_event_t type
));
376 /* no match metric */
377 extern void route_map_no_match_metric_hook(int (*func
)(
378 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
379 const char *arg
, route_map_event_t type
));
381 extern void route_map_match_tag_hook(int (*func
)(
382 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
383 const char *arg
, route_map_event_t type
));
385 extern void route_map_no_match_tag_hook(int (*func
)(
386 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
387 const char *arg
, route_map_event_t type
));
389 extern void route_map_set_ip_nexthop_hook(
390 int (*func
)(struct vty
*vty
, struct route_map_index
*index
,
391 const char *command
, const char *arg
));
392 /* no set ip nexthop */
393 extern void route_map_no_set_ip_nexthop_hook(
394 int (*func
)(struct vty
*vty
, struct route_map_index
*index
,
395 const char *command
, const char *arg
));
396 /* set ipv6 nexthop local */
397 extern void route_map_set_ipv6_nexthop_local_hook(
398 int (*func
)(struct vty
*vty
, struct route_map_index
*index
,
399 const char *command
, const char *arg
));
400 /* no set ipv6 nexthop local */
401 extern void route_map_no_set_ipv6_nexthop_local_hook(
402 int (*func
)(struct vty
*vty
, struct route_map_index
*index
,
403 const char *command
, const char *arg
));
405 extern void route_map_set_metric_hook(int (*func
)(struct vty
*vty
,
406 struct route_map_index
*index
,
410 extern void route_map_no_set_metric_hook(
411 int (*func
)(struct vty
*vty
, struct route_map_index
*index
,
412 const char *command
, const char *arg
));
414 extern void route_map_set_tag_hook(int (*func
)(struct vty
*vty
,
415 struct route_map_index
*index
,
419 extern void route_map_no_set_tag_hook(int (*func
)(struct vty
*vty
,
420 struct route_map_index
*index
,
424 extern void *route_map_rule_tag_compile(const char *arg
);
425 extern void route_map_rule_tag_free(void *rule
);
427 /* Increment the route-map used counter */
428 extern void route_map_counter_increment(struct route_map
*map
);
430 /* Decrement the route-map used counter */
431 extern void route_map_counter_decrement(struct route_map
*map
);
437 #endif /* _ZEBRA_ROUTEMAP_H */