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. */
129 enum rmap_compile_rets
{
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 enum rmap_compile_rets
route_map_add_match(struct route_map_index
*index
,
224 const char *match_name
,
225 const char *match_arg
,
226 route_map_event_t type
);
228 /* Delete specified route match rule. */
229 extern enum rmap_compile_rets
230 route_map_delete_match(struct route_map_index
*index
,
231 const char *match_name
, const char *match_arg
);
233 extern const char *route_map_get_match_arg(struct route_map_index
*index
,
234 const char *match_name
);
236 /* Add route-map set statement to the route map. */
237 extern enum rmap_compile_rets
route_map_add_set(struct route_map_index
*index
,
238 const char *set_name
,
239 const char *set_arg
);
241 /* Delete route map set rule. */
242 extern enum rmap_compile_rets
243 route_map_delete_set(struct route_map_index
*index
,
244 const char *set_name
, const char *set_arg
);
246 /* Install rule command to the match list. */
247 extern void route_map_install_match(struct route_map_rule_cmd
*cmd
);
250 * Install rule command to the set list.
252 * When installing a particular item, Allow a difference of handling
253 * of bad cli inputted(return NULL) -vs- this particular daemon cannot use
254 * this form of the command(return a pointer and handle it appropriately
255 * in the apply command). See 'set metric' command
256 * as it is handled in ripd/ripngd and ospfd.
258 extern void route_map_install_set(struct route_map_rule_cmd
*cmd
);
260 /* Lookup route map by name. */
261 extern struct route_map
*route_map_lookup_by_name(const char *name
);
263 /* Simple helper to warn if route-map does not exist. */
264 struct route_map
*route_map_lookup_warn_noexist(struct vty
*vty
, const char *name
);
266 /* Apply route map to the object. */
267 extern route_map_result_t
route_map_apply(struct route_map
*map
,
268 const struct prefix
*prefix
,
269 route_map_object_t object_type
,
272 extern void route_map_add_hook(void (*func
)(const char *));
273 extern void route_map_delete_hook(void (*func
)(const char *));
276 * This is the callback for when something has changed about a
277 * route-map. The interested parties can register to receive
280 * name - Is the name of the changed route-map
282 extern void route_map_event_hook(void (*func
)(const char *name
));
283 extern int route_map_mark_updated(const char *name
);
284 extern void route_map_walk_update_list(void (*update_fn
)(char *name
));
285 extern void route_map_upd8_dependency(route_map_event_t type
, const char *arg
,
286 const char *rmap_name
);
287 extern void route_map_notify_dependencies(const char *affected_name
,
288 route_map_event_t event
);
290 extern int generic_match_add(struct vty
*vty
, struct route_map_index
*index
,
291 const char *command
, const char *arg
,
292 route_map_event_t type
);
294 extern int generic_match_delete(struct vty
*vty
, struct route_map_index
*index
,
295 const char *command
, const char *arg
,
296 route_map_event_t type
);
297 extern int generic_set_add(struct vty
*vty
, struct route_map_index
*index
,
298 const char *command
, const char *arg
);
299 extern int generic_set_delete(struct vty
*vty
, struct route_map_index
*index
,
300 const char *command
, const char *arg
);
303 /* match interface */
304 extern void route_map_match_interface_hook(int (*func
)(
305 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
306 const char *arg
, route_map_event_t type
));
307 /* no match interface */
308 extern void route_map_no_match_interface_hook(int (*func
)(
309 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
310 const char *arg
, route_map_event_t type
));
311 /* match ip address */
312 extern void route_map_match_ip_address_hook(int (*func
)(
313 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
314 const char *arg
, route_map_event_t type
));
315 /* no match ip address */
316 extern void route_map_no_match_ip_address_hook(int (*func
)(
317 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
318 const char *arg
, route_map_event_t type
));
319 /* match ip address prefix list */
320 extern void route_map_match_ip_address_prefix_list_hook(int (*func
)(
321 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
322 const char *arg
, route_map_event_t type
));
323 /* no match ip address prefix list */
324 extern void route_map_no_match_ip_address_prefix_list_hook(int (*func
)(
325 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
326 const char *arg
, route_map_event_t type
));
327 /* match ip next hop */
328 extern void route_map_match_ip_next_hop_hook(int (*func
)(
329 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
330 const char *arg
, route_map_event_t type
));
331 /* no match ip next hop */
332 extern void route_map_no_match_ip_next_hop_hook(int (*func
)(
333 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
334 const char *arg
, route_map_event_t type
));
335 /* match ip next hop prefix list */
336 extern void route_map_match_ip_next_hop_prefix_list_hook(int (*func
)(
337 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
338 const char *arg
, route_map_event_t type
));
339 /* no match ip next hop prefix list */
340 extern void route_map_no_match_ip_next_hop_prefix_list_hook(int (*func
)(
341 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
342 const char *arg
, route_map_event_t type
));
343 /* match ip next hop type */
344 extern void route_map_match_ip_next_hop_type_hook(int (*func
)(
345 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
346 const char *arg
, route_map_event_t type
));
347 /* no match ip next hop type */
348 extern void route_map_no_match_ip_next_hop_type_hook(int (*func
)(
349 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
350 const char *arg
, route_map_event_t type
));
351 /* match ipv6 address */
352 extern void route_map_match_ipv6_address_hook(int (*func
)(
353 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
354 const char *arg
, route_map_event_t type
));
355 /* no match ipv6 address */
356 extern void route_map_no_match_ipv6_address_hook(int (*func
)(
357 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
358 const char *arg
, route_map_event_t type
));
359 /* match ipv6 address prefix list */
360 extern void route_map_match_ipv6_address_prefix_list_hook(int (*func
)(
361 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
362 const char *arg
, route_map_event_t type
));
363 /* no match ipv6 address prefix list */
364 extern void route_map_no_match_ipv6_address_prefix_list_hook(int (*func
)(
365 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
366 const char *arg
, route_map_event_t type
));
367 /* match ipv6 next-hop type */
368 extern void route_map_match_ipv6_next_hop_type_hook(int (*func
)(
369 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
370 const char *arg
, route_map_event_t type
));
371 /* no match ipv6 next-hop type */
372 extern void route_map_no_match_ipv6_next_hop_type_hook(int (*func
)(
373 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
374 const char *arg
, route_map_event_t type
));
376 extern void route_map_match_metric_hook(int (*func
)(
377 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
378 const char *arg
, route_map_event_t type
));
379 /* no match metric */
380 extern void route_map_no_match_metric_hook(int (*func
)(
381 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
382 const char *arg
, route_map_event_t type
));
384 extern void route_map_match_tag_hook(int (*func
)(
385 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
386 const char *arg
, route_map_event_t type
));
388 extern void route_map_no_match_tag_hook(int (*func
)(
389 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
390 const char *arg
, route_map_event_t type
));
392 extern void route_map_set_ip_nexthop_hook(
393 int (*func
)(struct vty
*vty
, struct route_map_index
*index
,
394 const char *command
, const char *arg
));
395 /* no set ip nexthop */
396 extern void route_map_no_set_ip_nexthop_hook(
397 int (*func
)(struct vty
*vty
, struct route_map_index
*index
,
398 const char *command
, const char *arg
));
399 /* set ipv6 nexthop local */
400 extern void route_map_set_ipv6_nexthop_local_hook(
401 int (*func
)(struct vty
*vty
, struct route_map_index
*index
,
402 const char *command
, const char *arg
));
403 /* no set ipv6 nexthop local */
404 extern void route_map_no_set_ipv6_nexthop_local_hook(
405 int (*func
)(struct vty
*vty
, struct route_map_index
*index
,
406 const char *command
, const char *arg
));
408 extern void route_map_set_metric_hook(int (*func
)(struct vty
*vty
,
409 struct route_map_index
*index
,
413 extern void route_map_no_set_metric_hook(
414 int (*func
)(struct vty
*vty
, struct route_map_index
*index
,
415 const char *command
, const char *arg
));
417 extern void route_map_set_tag_hook(int (*func
)(struct vty
*vty
,
418 struct route_map_index
*index
,
422 extern void route_map_no_set_tag_hook(int (*func
)(struct vty
*vty
,
423 struct route_map_index
*index
,
427 extern void *route_map_rule_tag_compile(const char *arg
);
428 extern void route_map_rule_tag_free(void *rule
);
430 /* Increment the route-map used counter */
431 extern void route_map_counter_increment(struct route_map
*map
);
433 /* Decrement the route-map used counter */
434 extern void route_map_counter_decrement(struct route_map
*map
);
440 #endif /* _ZEBRA_ROUTEMAP_H */