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 *rule
,
91 const struct prefix
*prefix
,
92 route_map_object_t type
,
95 /* Compile argument and return result as void *. */
96 void *(*func_compile
)(const char *);
98 /* Free allocated value by func_compile (). */
99 void (*func_free
)(void *);
102 /* Route map apply error. */
103 enum { RMAP_COMPILE_SUCCESS
,
105 /* Route map rule is missing. */
108 /* Route map rule can't compile */
109 RMAP_COMPILE_ERROR
};
111 /* Route map rule list. */
112 struct route_map_rule_list
{
113 struct route_map_rule
*head
;
114 struct route_map_rule
*tail
;
117 /* Route map index structure. */
118 struct route_map_index
{
119 struct route_map
*map
;
122 /* Preference of this route map rule. */
125 /* Route map type permit or deny. */
126 enum route_map_type type
;
128 /* Do we follow old rules, or hop forward? */
129 route_map_end_t exitpolicy
;
131 /* If we're using "GOTO", to where do we go? */
134 /* If we're using "CALL", to which route-map do ew go? */
137 /* Matching rule list. */
138 struct route_map_rule_list match_list
;
139 struct route_map_rule_list set_list
;
141 /* Make linked list. */
142 struct route_map_index
*next
;
143 struct route_map_index
*prev
;
147 DECLARE_QOBJ_TYPE(route_map_index
)
149 /* Route map list structure. */
151 /* Name of route map. */
154 /* Route map's rule. */
155 struct route_map_index
*head
;
156 struct route_map_index
*tail
;
158 /* Make linked list. */
159 struct route_map
*next
;
160 struct route_map
*prev
;
162 /* Maintain update info */
163 bool to_be_processed
; /* True if modification isn't acted on yet */
164 bool deleted
; /* If 1, then this node will be deleted */
168 DECLARE_QOBJ_TYPE(route_map
)
171 extern void route_map_init(void);
172 extern void route_map_finish(void);
174 /* Add match statement to route map. */
175 extern int route_map_add_match(struct route_map_index
*index
,
176 const char *match_name
, const char *match_arg
);
178 /* Delete specified route match rule. */
179 extern int route_map_delete_match(struct route_map_index
*index
,
180 const char *match_name
,
181 const char *match_arg
);
183 extern const char *route_map_get_match_arg(struct route_map_index
*index
,
184 const char *match_name
);
186 /* Add route-map set statement to the route map. */
187 extern int route_map_add_set(struct route_map_index
*index
,
188 const char *set_name
, const char *set_arg
);
190 /* Delete route map set rule. */
191 extern int route_map_delete_set(struct route_map_index
*index
,
192 const char *set_name
, const char *set_arg
);
194 /* Install rule command to the match list. */
195 extern void route_map_install_match(struct route_map_rule_cmd
*cmd
);
198 * Install rule command to the set list.
200 * When installing a particular item, Allow a difference of handling
201 * of bad cli inputted(return NULL) -vs- this particular daemon cannot use
202 * this form of the command(return a pointer and handle it appropriately
203 * in the apply command). See 'set metric' command
204 * as it is handled in ripd/ripngd and ospfd.
206 extern void route_map_install_set(struct route_map_rule_cmd
*cmd
);
208 /* Lookup route map by name. */
209 extern struct route_map
*route_map_lookup_by_name(const char *name
);
211 /* Apply route map to the object. */
212 extern route_map_result_t
route_map_apply(struct route_map
*map
,
213 const struct prefix
*prefix
,
214 route_map_object_t object_type
,
217 extern void route_map_add_hook(void (*func
)(const char *));
218 extern void route_map_delete_hook(void (*func
)(const char *));
219 extern void route_map_event_hook(void (*func
)(route_map_event_t
, const char *));
220 extern int route_map_mark_updated(const char *name
);
221 extern void route_map_walk_update_list(void (*update_fn
)(char *name
));
222 extern void route_map_upd8_dependency(route_map_event_t type
, const char *arg
,
223 const char *rmap_name
);
224 extern void route_map_notify_dependencies(const char *affected_name
,
225 route_map_event_t event
);
227 extern int generic_match_add(struct vty
*vty
, struct route_map_index
*index
,
228 const char *command
, const char *arg
,
229 route_map_event_t type
);
231 extern int generic_match_delete(struct vty
*vty
, struct route_map_index
*index
,
232 const char *command
, const char *arg
,
233 route_map_event_t type
);
234 extern int generic_set_add(struct vty
*vty
, struct route_map_index
*index
,
235 const char *command
, const char *arg
);
236 extern int generic_set_delete(struct vty
*vty
, struct route_map_index
*index
,
237 const char *command
, const char *arg
);
240 /* match interface */
241 extern void route_map_match_interface_hook(int (*func
)(
242 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
243 const char *arg
, route_map_event_t type
));
244 /* no match interface */
245 extern void route_map_no_match_interface_hook(int (*func
)(
246 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
247 const char *arg
, route_map_event_t type
));
248 /* match ip address */
249 extern void route_map_match_ip_address_hook(int (*func
)(
250 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
251 const char *arg
, route_map_event_t type
));
252 /* no match ip address */
253 extern void route_map_no_match_ip_address_hook(int (*func
)(
254 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
255 const char *arg
, route_map_event_t type
));
256 /* match ip address prefix list */
257 extern void route_map_match_ip_address_prefix_list_hook(int (*func
)(
258 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
259 const char *arg
, route_map_event_t type
));
260 /* no match ip address prefix list */
261 extern void route_map_no_match_ip_address_prefix_list_hook(int (*func
)(
262 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
263 const char *arg
, route_map_event_t type
));
264 /* match ip next hop */
265 extern void route_map_match_ip_next_hop_hook(int (*func
)(
266 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
267 const char *arg
, route_map_event_t type
));
268 /* no match ip next hop */
269 extern void route_map_no_match_ip_next_hop_hook(int (*func
)(
270 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
271 const char *arg
, route_map_event_t type
));
272 /* match ip next hop prefix list */
273 extern void route_map_match_ip_next_hop_prefix_list_hook(int (*func
)(
274 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
275 const char *arg
, route_map_event_t type
));
276 /* no match ip next hop prefix list */
277 extern void route_map_no_match_ip_next_hop_prefix_list_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 /* match ipv6 address */
281 extern void route_map_match_ipv6_address_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 /* no match ipv6 address */
285 extern void route_map_no_match_ipv6_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 /* match ipv6 address prefix list */
289 extern void route_map_match_ipv6_address_prefix_list_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 /* no match ipv6 address prefix list */
293 extern void route_map_no_match_ipv6_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
));
297 extern void route_map_match_metric_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 /* no match metric */
301 extern void route_map_no_match_metric_hook(int (*func
)(
302 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
303 const char *arg
, route_map_event_t type
));
305 extern void route_map_match_tag_hook(int (*func
)(
306 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
307 const char *arg
, route_map_event_t type
));
309 extern void route_map_no_match_tag_hook(int (*func
)(
310 struct vty
*vty
, struct route_map_index
*index
, const char *command
,
311 const char *arg
, route_map_event_t type
));
313 extern void route_map_set_ip_nexthop_hook(
314 int (*func
)(struct vty
*vty
, struct route_map_index
*index
,
315 const char *command
, const char *arg
));
316 /* no set ip nexthop */
317 extern void route_map_no_set_ip_nexthop_hook(
318 int (*func
)(struct vty
*vty
, struct route_map_index
*index
,
319 const char *command
, const char *arg
));
320 /* set ipv6 nexthop local */
321 extern void route_map_set_ipv6_nexthop_local_hook(
322 int (*func
)(struct vty
*vty
, struct route_map_index
*index
,
323 const char *command
, const char *arg
));
324 /* no set ipv6 nexthop local */
325 extern void route_map_no_set_ipv6_nexthop_local_hook(
326 int (*func
)(struct vty
*vty
, struct route_map_index
*index
,
327 const char *command
, const char *arg
));
329 extern void route_map_set_metric_hook(int (*func
)(struct vty
*vty
,
330 struct route_map_index
*index
,
334 extern void route_map_no_set_metric_hook(
335 int (*func
)(struct vty
*vty
, struct route_map_index
*index
,
336 const char *command
, const char *arg
));
338 extern void route_map_set_tag_hook(int (*func
)(struct vty
*vty
,
339 struct route_map_index
*index
,
343 extern void route_map_no_set_tag_hook(int (*func
)(struct vty
*vty
,
344 struct route_map_index
*index
,
348 extern void *route_map_rule_tag_compile(const char *arg
);
349 extern void route_map_rule_tag_free(void *rule
);
351 #endif /* _ZEBRA_ROUTEMAP_H */