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. */
34 enum route_map_type
{ RMAP_PERMIT
, RMAP_DENY
, RMAP_ANY
};
54 typedef enum { RMAP_EXIT
, RMAP_GOTO
, RMAP_NEXT
} route_map_end_t
;
58 RMAP_EVENT_SET_DELETED
,
59 RMAP_EVENT_SET_REPLACED
,
60 RMAP_EVENT_MATCH_ADDED
,
61 RMAP_EVENT_MATCH_DELETED
,
62 RMAP_EVENT_MATCH_REPLACED
,
63 RMAP_EVENT_INDEX_ADDED
,
64 RMAP_EVENT_INDEX_DELETED
,
65 RMAP_EVENT_CALL_ADDED
, /* call to another routemap added */
66 RMAP_EVENT_CALL_DELETED
,
67 RMAP_EVENT_PLIST_ADDED
,
68 RMAP_EVENT_PLIST_DELETED
,
69 RMAP_EVENT_CLIST_ADDED
,
70 RMAP_EVENT_CLIST_DELETED
,
71 RMAP_EVENT_ECLIST_ADDED
,
72 RMAP_EVENT_ECLIST_DELETED
,
73 RMAP_EVENT_LLIST_ADDED
,
74 RMAP_EVENT_LLIST_DELETED
,
75 RMAP_EVENT_ASLIST_ADDED
,
76 RMAP_EVENT_ASLIST_DELETED
,
77 RMAP_EVENT_FILTER_ADDED
,
78 RMAP_EVENT_FILTER_DELETED
,
81 /* Depth limit in RMAP recursion using RMAP_CALL. */
82 #define RMAP_RECURSION_LIMIT 10
84 /* Route map rule structure for matching and setting. */
85 struct route_map_rule_cmd
{
86 /* Route map rule name (e.g. as-path, metric) */
89 /* Function for value set or match. */
90 route_map_result_t (*func_apply
)(void *, struct prefix
*,
91 route_map_object_t
, void *);
93 /* Compile argument and return result as void *. */
94 void *(*func_compile
)(const char *);
96 /* Free allocated value by func_compile (). */
97 void (*func_free
)(void *);
100 /* Route map apply error. */
101 enum { RMAP_COMPILE_SUCCESS
,
103 /* Route map rule is missing. */
106 /* Route map rule can't compile */
107 RMAP_COMPILE_ERROR
};
109 /* Route map rule list. */
110 struct route_map_rule_list
{
111 struct route_map_rule
*head
;
112 struct route_map_rule
*tail
;
115 /* Route map index structure. */
116 struct route_map_index
{
117 struct route_map
*map
;
120 /* Preference of this route map rule. */
123 /* Route map type permit or deny. */
124 enum route_map_type type
;
126 /* Do we follow old rules, or hop forward? */
127 route_map_end_t exitpolicy
;
129 /* If we're using "GOTO", to where do we go? */
132 /* If we're using "CALL", to which route-map do ew go? */
135 /* Matching rule list. */
136 struct route_map_rule_list match_list
;
137 struct route_map_rule_list set_list
;
139 /* Make linked list. */
140 struct route_map_index
*next
;
141 struct route_map_index
*prev
;
145 DECLARE_QOBJ_TYPE(route_map_index
)
147 /* Route map list structure. */
149 /* Name of route map. */
152 /* Route map's rule. */
153 struct route_map_index
*head
;
154 struct route_map_index
*tail
;
156 /* Make linked list. */
157 struct route_map
*next
;
158 struct route_map
*prev
;
160 /* Maintain update info */
161 int to_be_processed
; /* True if modification isn't acted on yet */
162 int deleted
; /* If 1, then this node will be deleted */
166 DECLARE_QOBJ_TYPE(route_map
)
169 extern void route_map_init(void);
170 extern void route_map_finish(void);
172 /* Add match statement to route map. */
173 extern int route_map_add_match(struct route_map_index
*index
,
174 const char *match_name
, const char *match_arg
);
176 /* Delete specified route match rule. */
177 extern int route_map_delete_match(struct route_map_index
*index
,
178 const char *match_name
,
179 const char *match_arg
);
181 extern const char *route_map_get_match_arg(struct route_map_index
*index
,
182 const char *match_name
);
184 /* Add route-map set statement to the route map. */
185 extern int route_map_add_set(struct route_map_index
*index
,
186 const char *set_name
, const char *set_arg
);
188 /* Delete route map set rule. */
189 extern int route_map_delete_set(struct route_map_index
*index
,
190 const char *set_name
, const char *set_arg
);
192 /* Install rule command to the match list. */
193 extern void route_map_install_match(struct route_map_rule_cmd
*cmd
);
196 * Install rule command to the set list.
198 * When installing a particular item, Allow a difference of handling
199 * of bad cli inputted(return NULL) -vs- this particular daemon cannot use
200 * this form of the command(return a pointer and handle it appropriately
201 * in the apply command). See 'set metric' command
202 * as it is handled in ripd/ripngd and ospfd.
204 extern void route_map_install_set(struct route_map_rule_cmd
*cmd
);
206 /* Lookup route map by name. */
207 extern struct route_map
*route_map_lookup_by_name(const char *name
);
209 /* Apply route map to the object. */
210 extern route_map_result_t
route_map_apply(struct route_map
*map
,
212 route_map_object_t object_type
,
215 extern void route_map_add_hook(void (*func
)(const char *));
216 extern void route_map_delete_hook(void (*func
)(const char *));
217 extern void route_map_event_hook(void (*func
)(route_map_event_t
, const char *));
218 extern int route_map_mark_updated(const char *name
, int deleted
);
219 extern int route_map_clear_updated(struct route_map
*rmap
);
220 extern void route_map_walk_update_list(int (*update_fn
)(char *name
));
221 extern void route_map_upd8_dependency(route_map_event_t type
, const char *arg
,
222 const char *rmap_name
);
223 extern void route_map_notify_dependencies(const char *affected_name
,
224 route_map_event_t event
);
226 extern int generic_match_add(struct vty
*vty
, struct route_map_index
*index
,
227 const char *command
, const char *arg
,
228 route_map_event_t type
);
230 extern int generic_match_delete(struct vty
*vty
, struct route_map_index
*index
,
231 const char *command
, const char *arg
,
232 route_map_event_t type
);
233 extern int generic_set_add(struct vty
*vty
, struct route_map_index
*index
,
234 const char *command
, const char *arg
);
235 extern int generic_set_delete(struct vty
*vty
, struct route_map_index
*index
,
236 const char *command
, const char *arg
);
239 /* match interface */
240 extern void route_map_match_interface_hook(int (*func
)(
241 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
242 const char *arg
, route_map_event_t type
));
243 /* no match interface */
244 extern void route_map_no_match_interface_hook(int (*func
)(
245 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
246 const char *arg
, route_map_event_t type
));
247 /* match ip address */
248 extern void route_map_match_ip_address_hook(int (*func
)(
249 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
250 const char *arg
, route_map_event_t type
));
251 /* no match ip address */
252 extern void route_map_no_match_ip_address_hook(int (*func
)(
253 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
254 const char *arg
, route_map_event_t type
));
255 /* match ip address prefix list */
256 extern void route_map_match_ip_address_prefix_list_hook(int (*func
)(
257 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
258 const char *arg
, route_map_event_t type
));
259 /* no match ip address prefix list */
260 extern void route_map_no_match_ip_address_prefix_list_hook(int (*func
)(
261 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
262 const char *arg
, route_map_event_t type
));
263 /* match ip next hop */
264 extern void route_map_match_ip_next_hop_hook(int (*func
)(
265 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
266 const char *arg
, route_map_event_t type
));
267 /* no match ip next hop */
268 extern void route_map_no_match_ip_next_hop_hook(int (*func
)(
269 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
270 const char *arg
, route_map_event_t type
));
271 /* match ip next hop prefix list */
272 extern void route_map_match_ip_next_hop_prefix_list_hook(int (*func
)(
273 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
274 const char *arg
, route_map_event_t type
));
275 /* no match ip next hop prefix list */
276 extern void route_map_no_match_ip_next_hop_prefix_list_hook(int (*func
)(
277 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
278 const char *arg
, route_map_event_t type
));
279 /* match ipv6 address */
280 extern void route_map_match_ipv6_address_hook(int (*func
)(
281 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
282 const char *arg
, route_map_event_t type
));
283 /* no match ipv6 address */
284 extern void route_map_no_match_ipv6_address_hook(int (*func
)(
285 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
286 const char *arg
, route_map_event_t type
));
287 /* match ipv6 address prefix list */
288 extern void route_map_match_ipv6_address_prefix_list_hook(int (*func
)(
289 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
290 const char *arg
, route_map_event_t type
));
291 /* no match ipv6 address prefix list */
292 extern void route_map_no_match_ipv6_address_prefix_list_hook(int (*func
)(
293 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
294 const char *arg
, route_map_event_t type
));
296 extern void route_map_match_metric_hook(int (*func
)(
297 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
298 const char *arg
, route_map_event_t type
));
299 /* no match metric */
300 extern void route_map_no_match_metric_hook(int (*func
)(
301 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
302 const char *arg
, route_map_event_t type
));
304 extern void route_map_match_tag_hook(int (*func
)(
305 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
306 const char *arg
, route_map_event_t type
));
308 extern void route_map_no_match_tag_hook(int (*func
)(
309 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
310 const char *arg
, route_map_event_t type
));
312 extern void route_map_set_ip_nexthop_hook(
313 int (*func
)(struct vty
*vty
, struct route_map_index
*index
,
314 const char *command
, const char *arg
));
315 /* no set ip nexthop */
316 extern void route_map_no_set_ip_nexthop_hook(
317 int (*func
)(struct vty
*vty
, struct route_map_index
*index
,
318 const char *command
, const char *arg
));
319 /* set ipv6 nexthop local */
320 extern void route_map_set_ipv6_nexthop_local_hook(
321 int (*func
)(struct vty
*vty
, struct route_map_index
*index
,
322 const char *command
, const char *arg
));
323 /* no set ipv6 nexthop local */
324 extern void route_map_no_set_ipv6_nexthop_local_hook(
325 int (*func
)(struct vty
*vty
, struct route_map_index
*index
,
326 const char *command
, const char *arg
));
328 extern void route_map_set_metric_hook(int (*func
)(struct vty
*vty
,
329 struct route_map_index
*index
,
333 extern void route_map_no_set_metric_hook(
334 int (*func
)(struct vty
*vty
, struct route_map_index
*index
,
335 const char *command
, const char *arg
));
337 extern void route_map_set_tag_hook(int (*func
)(struct vty
*vty
,
338 struct route_map_index
*index
,
342 extern void route_map_no_set_tag_hook(int (*func
)(struct vty
*vty
,
343 struct route_map_index
*index
,
347 extern void *route_map_rule_tag_compile(const char *arg
);
348 extern void route_map_rule_tag_free(void *rule
);
350 #endif /* _ZEBRA_ROUTEMAP_H */