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 *);
127 /** To get the rule key after Compilation **/
128 void *(*func_get_rmap_rule_key
)(void *val
);
131 /* Route map apply error. */
132 enum rmap_compile_rets
{
133 RMAP_COMPILE_SUCCESS
,
135 /* Route map rule is missing. */
138 /* Route map rule can't compile */
143 /* Route map rule list. */
144 struct route_map_rule_list
{
145 struct route_map_rule
*head
;
146 struct route_map_rule
*tail
;
149 /* Route map index structure. */
150 struct route_map_index
{
151 struct route_map
*map
;
154 /* Preference of this route map rule. */
157 /* Route map type permit or deny. */
158 enum route_map_type type
;
160 /* Do we follow old rules, or hop forward? */
161 route_map_end_t exitpolicy
;
163 /* If we're using "GOTO", to where do we go? */
166 /* If we're using "CALL", to which route-map do ew go? */
169 /* Matching rule list. */
170 struct route_map_rule_list match_list
;
171 struct route_map_rule_list set_list
;
173 /* Make linked list. */
174 struct route_map_index
*next
;
175 struct route_map_index
*prev
;
177 /* Keep track how many times we've try to apply */
179 uint64_t applied_clear
;
183 DECLARE_QOBJ_TYPE(route_map_index
)
185 /* Route map list structure. */
187 /* Name of route map. */
190 /* Route map's rule. */
191 struct route_map_index
*head
;
192 struct route_map_index
*tail
;
194 /* Make linked list. */
195 struct route_map
*next
;
196 struct route_map
*prev
;
198 /* Maintain update info */
199 bool to_be_processed
; /* True if modification isn't acted on yet */
200 bool deleted
; /* If 1, then this node will be deleted */
202 /* How many times have we applied this route-map */
204 uint64_t applied_clear
;
206 /* Counter to track active usage of this route-map */
211 DECLARE_QOBJ_TYPE(route_map
)
214 extern void route_map_init(void);
217 * This should only be called on shutdown
218 * Additionally this function sets the hooks to NULL
219 * before any processing is done.
221 extern void route_map_finish(void);
223 /* Add match statement to route map. */
224 extern enum rmap_compile_rets
route_map_add_match(struct route_map_index
*index
,
225 const char *match_name
,
226 const char *match_arg
,
227 route_map_event_t type
);
229 /* Delete specified route match rule. */
230 extern enum rmap_compile_rets
231 route_map_delete_match(struct route_map_index
*index
,
232 const char *match_name
, const char *match_arg
,
233 route_map_event_t type
);
235 extern const char *route_map_get_match_arg(struct route_map_index
*index
,
236 const char *match_name
);
238 /* Add route-map set statement to the route map. */
239 extern enum rmap_compile_rets
route_map_add_set(struct route_map_index
*index
,
240 const char *set_name
,
241 const char *set_arg
);
243 /* Delete route map set rule. */
244 extern enum rmap_compile_rets
245 route_map_delete_set(struct route_map_index
*index
,
246 const char *set_name
, const char *set_arg
);
248 /* Install rule command to the match list. */
249 extern void route_map_install_match(const struct route_map_rule_cmd
*cmd
);
252 * Install rule command to the set list.
254 * When installing a particular item, Allow a difference of handling
255 * of bad cli inputted(return NULL) -vs- this particular daemon cannot use
256 * this form of the command(return a pointer and handle it appropriately
257 * in the apply command). See 'set metric' command
258 * as it is handled in ripd/ripngd and ospfd.
260 extern void route_map_install_set(const struct route_map_rule_cmd
*cmd
);
262 /* Lookup route map by name. */
263 extern struct route_map
*route_map_lookup_by_name(const char *name
);
265 /* Simple helper to warn if route-map does not exist. */
266 struct route_map
*route_map_lookup_warn_noexist(struct vty
*vty
, const char *name
);
268 /* Apply route map to the object. */
269 extern route_map_result_t
route_map_apply(struct route_map
*map
,
270 const struct prefix
*prefix
,
271 route_map_object_t object_type
,
274 extern void route_map_add_hook(void (*func
)(const char *));
275 extern void route_map_delete_hook(void (*func
)(const char *));
278 * This is the callback for when something has changed about a
279 * route-map. The interested parties can register to receive
282 * name - Is the name of the changed route-map
284 extern void route_map_event_hook(void (*func
)(const char *name
));
285 extern int route_map_mark_updated(const char *name
);
286 extern void route_map_walk_update_list(void (*update_fn
)(char *name
));
287 extern void route_map_upd8_dependency(route_map_event_t type
, const char *arg
,
288 const char *rmap_name
);
289 extern void route_map_notify_dependencies(const char *affected_name
,
290 route_map_event_t event
);
292 extern int generic_match_add(struct vty
*vty
, struct route_map_index
*index
,
293 const char *command
, const char *arg
,
294 route_map_event_t type
);
296 extern int generic_match_delete(struct vty
*vty
, struct route_map_index
*index
,
297 const char *command
, const char *arg
,
298 route_map_event_t type
);
299 extern int generic_set_add(struct vty
*vty
, struct route_map_index
*index
,
300 const char *command
, const char *arg
);
301 extern int generic_set_delete(struct vty
*vty
, struct route_map_index
*index
,
302 const char *command
, const char *arg
);
305 /* match interface */
306 extern void route_map_match_interface_hook(int (*func
)(
307 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
308 const char *arg
, route_map_event_t type
));
309 /* no match interface */
310 extern void route_map_no_match_interface_hook(int (*func
)(
311 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
312 const char *arg
, route_map_event_t type
));
313 /* match ip address */
314 extern void route_map_match_ip_address_hook(int (*func
)(
315 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
316 const char *arg
, route_map_event_t type
));
317 /* no match ip address */
318 extern void route_map_no_match_ip_address_hook(int (*func
)(
319 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
320 const char *arg
, route_map_event_t type
));
321 /* match ip address prefix list */
322 extern void route_map_match_ip_address_prefix_list_hook(int (*func
)(
323 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
324 const char *arg
, route_map_event_t type
));
325 /* no match ip address prefix list */
326 extern void route_map_no_match_ip_address_prefix_list_hook(int (*func
)(
327 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
328 const char *arg
, route_map_event_t type
));
329 /* match ip next hop */
330 extern void route_map_match_ip_next_hop_hook(int (*func
)(
331 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
332 const char *arg
, route_map_event_t type
));
333 /* no match ip next hop */
334 extern void route_map_no_match_ip_next_hop_hook(int (*func
)(
335 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
336 const char *arg
, route_map_event_t type
));
337 /* match ip next hop prefix list */
338 extern void route_map_match_ip_next_hop_prefix_list_hook(int (*func
)(
339 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
340 const char *arg
, route_map_event_t type
));
341 /* no match ip next hop prefix list */
342 extern void route_map_no_match_ip_next_hop_prefix_list_hook(int (*func
)(
343 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
344 const char *arg
, route_map_event_t type
));
345 /* match ip next hop type */
346 extern void route_map_match_ip_next_hop_type_hook(int (*func
)(
347 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
348 const char *arg
, route_map_event_t type
));
349 /* no match ip next hop type */
350 extern void route_map_no_match_ip_next_hop_type_hook(int (*func
)(
351 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
352 const char *arg
, route_map_event_t type
));
353 /* match ipv6 address */
354 extern void route_map_match_ipv6_address_hook(int (*func
)(
355 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
356 const char *arg
, route_map_event_t type
));
357 /* no match ipv6 address */
358 extern void route_map_no_match_ipv6_address_hook(int (*func
)(
359 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
360 const char *arg
, route_map_event_t type
));
361 /* match ipv6 address prefix list */
362 extern void route_map_match_ipv6_address_prefix_list_hook(int (*func
)(
363 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
364 const char *arg
, route_map_event_t type
));
365 /* no match ipv6 address prefix list */
366 extern void route_map_no_match_ipv6_address_prefix_list_hook(int (*func
)(
367 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
368 const char *arg
, route_map_event_t type
));
369 /* match ipv6 next-hop type */
370 extern void route_map_match_ipv6_next_hop_type_hook(int (*func
)(
371 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
372 const char *arg
, route_map_event_t type
));
373 /* no match ipv6 next-hop type */
374 extern void route_map_no_match_ipv6_next_hop_type_hook(int (*func
)(
375 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
376 const char *arg
, route_map_event_t type
));
378 extern void route_map_match_metric_hook(int (*func
)(
379 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
380 const char *arg
, route_map_event_t type
));
381 /* no match metric */
382 extern void route_map_no_match_metric_hook(int (*func
)(
383 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
384 const char *arg
, route_map_event_t type
));
386 extern void route_map_match_tag_hook(int (*func
)(
387 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
388 const char *arg
, route_map_event_t type
));
390 extern void route_map_no_match_tag_hook(int (*func
)(
391 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
392 const char *arg
, route_map_event_t type
));
394 extern void route_map_set_ip_nexthop_hook(
395 int (*func
)(struct vty
*vty
, struct route_map_index
*index
,
396 const char *command
, const char *arg
));
397 /* no set ip nexthop */
398 extern void route_map_no_set_ip_nexthop_hook(
399 int (*func
)(struct vty
*vty
, struct route_map_index
*index
,
400 const char *command
, const char *arg
));
401 /* set ipv6 nexthop local */
402 extern void route_map_set_ipv6_nexthop_local_hook(
403 int (*func
)(struct vty
*vty
, struct route_map_index
*index
,
404 const char *command
, const char *arg
));
405 /* no set ipv6 nexthop local */
406 extern void route_map_no_set_ipv6_nexthop_local_hook(
407 int (*func
)(struct vty
*vty
, struct route_map_index
*index
,
408 const char *command
, const char *arg
));
410 extern void route_map_set_metric_hook(int (*func
)(struct vty
*vty
,
411 struct route_map_index
*index
,
415 extern void route_map_no_set_metric_hook(
416 int (*func
)(struct vty
*vty
, struct route_map_index
*index
,
417 const char *command
, const char *arg
));
419 extern void route_map_set_tag_hook(int (*func
)(struct vty
*vty
,
420 struct route_map_index
*index
,
424 extern void route_map_no_set_tag_hook(int (*func
)(struct vty
*vty
,
425 struct route_map_index
*index
,
429 extern void *route_map_rule_tag_compile(const char *arg
);
430 extern void route_map_rule_tag_free(void *rule
);
432 /* Increment the route-map used counter */
433 extern void route_map_counter_increment(struct route_map
*map
);
435 /* Decrement the route-map used counter */
436 extern void route_map_counter_decrement(struct route_map
*map
);
442 #endif /* _ZEBRA_ROUTEMAP_H */