]> git.proxmox.com Git - mirror_frr.git/blame - lib/routemap.h
Merge branch 'stable/3.0' into tmp-3.0-master-merge
[mirror_frr.git] / lib / routemap.h
CommitLineData
718e3744 1/* Route map function.
2 * Copyright (C) 1998 Kunihiro Ishiguro
3 *
4 * This file is part of GNU Zebra.
5 *
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
9 * later version.
10 *
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.
15 *
896014f4
DL
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
718e3744 19 */
20
21#ifndef _ZEBRA_ROUTEMAP_H
22#define _ZEBRA_ROUTEMAP_H
23
24873f0c 24#include "prefix.h"
4a1ab8e4 25#include "memory.h"
e80e7cce 26#include "qobj.h"
0a538fc9
QY
27#include "vty.h"
28
4a1ab8e4
DL
29DECLARE_MTYPE(ROUTE_MAP_NAME)
30DECLARE_MTYPE(ROUTE_MAP_RULE)
31DECLARE_MTYPE(ROUTE_MAP_COMPILED)
24873f0c 32
718e3744 33/* Route map's type. */
d62a17ae 34enum route_map_type { RMAP_PERMIT, RMAP_DENY, RMAP_ANY };
35
36typedef enum {
37 RMAP_MATCH,
38 RMAP_DENYMATCH,
39 RMAP_NOMATCH,
40 RMAP_ERROR,
41 RMAP_OKAY
718e3744 42} route_map_result_t;
43
d62a17ae 44typedef enum {
45 RMAP_RIP,
46 RMAP_RIPNG,
47 RMAP_OSPF,
48 RMAP_OSPF6,
49 RMAP_BGP,
50 RMAP_ZEBRA,
51 RMAP_ISIS,
718e3744 52} route_map_object_t;
53
d62a17ae 54typedef enum { RMAP_EXIT, RMAP_GOTO, RMAP_NEXT } route_map_end_t;
55
56typedef enum {
57 RMAP_EVENT_SET_ADDED,
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,
718e3744 79} route_map_event_t;
80
fee0f4c6 81/* Depth limit in RMAP recursion using RMAP_CALL. */
82#define RMAP_RECURSION_LIMIT 10
83
718e3744 84/* Route map rule structure for matching and setting. */
d62a17ae 85struct route_map_rule_cmd {
86 /* Route map rule name (e.g. as-path, metric) */
87 const char *str;
718e3744 88
d62a17ae 89 /* Function for value set or match. */
90 route_map_result_t (*func_apply)(void *, struct prefix *,
91 route_map_object_t, void *);
718e3744 92
d62a17ae 93 /* Compile argument and return result as void *. */
94 void *(*func_compile)(const char *);
718e3744 95
d62a17ae 96 /* Free allocated value by func_compile (). */
97 void (*func_free)(void *);
718e3744 98};
99
100/* Route map apply error. */
d62a17ae 101enum {
102 /* Route map rule is missing. */
103 RMAP_RULE_MISSING = 1,
718e3744 104
d62a17ae 105 /* Route map rule can't compile */
106 RMAP_COMPILE_ERROR
718e3744 107};
108
109/* Route map rule list. */
d62a17ae 110struct route_map_rule_list {
111 struct route_map_rule *head;
112 struct route_map_rule *tail;
718e3744 113};
114
115/* Route map index structure. */
d62a17ae 116struct route_map_index {
117 struct route_map *map;
118 char *description;
718e3744 119
d62a17ae 120 /* Preference of this route map rule. */
121 int pref;
718e3744 122
d62a17ae 123 /* Route map type permit or deny. */
124 enum route_map_type type;
718e3744 125
d62a17ae 126 /* Do we follow old rules, or hop forward? */
127 route_map_end_t exitpolicy;
718e3744 128
d62a17ae 129 /* If we're using "GOTO", to where do we go? */
130 int nextpref;
718e3744 131
d62a17ae 132 /* If we're using "CALL", to which route-map do ew go? */
133 char *nextrm;
fee0f4c6 134
d62a17ae 135 /* Matching rule list. */
136 struct route_map_rule_list match_list;
137 struct route_map_rule_list set_list;
718e3744 138
d62a17ae 139 /* Make linked list. */
140 struct route_map_index *next;
141 struct route_map_index *prev;
e80e7cce 142
d62a17ae 143 QOBJ_FIELDS
718e3744 144};
e80e7cce 145DECLARE_QOBJ_TYPE(route_map_index)
718e3744 146
147/* Route map list structure. */
d62a17ae 148struct route_map {
149 /* Name of route map. */
150 char *name;
718e3744 151
d62a17ae 152 /* Route map's rule. */
153 struct route_map_index *head;
154 struct route_map_index *tail;
718e3744 155
d62a17ae 156 /* Make linked list. */
157 struct route_map *next;
158 struct route_map *prev;
518f0eb1 159
d62a17ae 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 */
e80e7cce 163
d62a17ae 164 QOBJ_FIELDS
718e3744 165};
e80e7cce 166DECLARE_QOBJ_TYPE(route_map)
718e3744 167
168/* Prototypes. */
d62a17ae 169extern void route_map_init(void);
170extern void route_map_finish(void);
718e3744 171
172/* Add match statement to route map. */
d62a17ae 173extern int route_map_add_match(struct route_map_index *index,
174 const char *match_name, const char *match_arg);
718e3744 175
176/* Delete specified route match rule. */
d62a17ae 177extern int route_map_delete_match(struct route_map_index *index,
178 const char *match_name,
179 const char *match_arg);
718e3744 180
d62a17ae 181extern const char *route_map_get_match_arg(struct route_map_index *index,
182 const char *match_name);
518f0eb1 183
718e3744 184/* Add route-map set statement to the route map. */
d62a17ae 185extern int route_map_add_set(struct route_map_index *index,
186 const char *set_name, const char *set_arg);
718e3744 187
188/* Delete route map set rule. */
d62a17ae 189extern int route_map_delete_set(struct route_map_index *index,
190 const char *set_name, const char *set_arg);
718e3744 191
192/* Install rule command to the match list. */
d62a17ae 193extern void route_map_install_match(struct route_map_rule_cmd *cmd);
718e3744 194
195/* Install rule command to the set list. */
d62a17ae 196extern void route_map_install_set(struct route_map_rule_cmd *cmd);
718e3744 197
198/* Lookup route map by name. */
d62a17ae 199extern struct route_map *route_map_lookup_by_name(const char *name);
718e3744 200
201/* Apply route map to the object. */
d62a17ae 202extern route_map_result_t route_map_apply(struct route_map *map,
203 struct prefix *,
204 route_map_object_t object_type,
205 void *object);
206
207extern void route_map_add_hook(void (*func)(const char *));
208extern void route_map_delete_hook(void (*func)(const char *));
209extern void route_map_event_hook(void (*func)(route_map_event_t, const char *));
210extern int route_map_mark_updated(const char *name, int deleted);
211extern int route_map_clear_updated(struct route_map *rmap);
212extern void route_map_walk_update_list(int (*update_fn)(char *name));
213extern void route_map_upd8_dependency(route_map_event_t type, const char *arg,
214 const char *rmap_name);
215extern void route_map_notify_dependencies(const char *affected_name,
216 route_map_event_t event);
217
218extern int generic_match_add(struct vty *vty, struct route_map_index *index,
219 const char *command, const char *arg,
220 route_map_event_t type);
221
222extern int generic_match_delete(struct vty *vty, struct route_map_index *index,
223 const char *command, const char *arg,
224 route_map_event_t type);
225extern int generic_set_add(struct vty *vty, struct route_map_index *index,
226 const char *command, const char *arg);
227extern int generic_set_delete(struct vty *vty, struct route_map_index *index,
228 const char *command, const char *arg);
82f97584
DW
229
230
231/* match interface */
d62a17ae 232extern void route_map_match_interface_hook(int (*func)(
233 struct vty *vty, struct route_map_index *index, const char *command,
234 const char *arg, route_map_event_t type));
82f97584 235/* no match interface */
d62a17ae 236extern void route_map_no_match_interface_hook(int (*func)(
237 struct vty *vty, struct route_map_index *index, const char *command,
238 const char *arg, route_map_event_t type));
82f97584 239/* match ip address */
d62a17ae 240extern void route_map_match_ip_address_hook(int (*func)(
241 struct vty *vty, struct route_map_index *index, const char *command,
242 const char *arg, route_map_event_t type));
82f97584 243/* no match ip address */
d62a17ae 244extern void route_map_no_match_ip_address_hook(int (*func)(
245 struct vty *vty, struct route_map_index *index, const char *command,
246 const char *arg, route_map_event_t type));
82f97584 247/* match ip address prefix list */
d62a17ae 248extern void route_map_match_ip_address_prefix_list_hook(int (*func)(
249 struct vty *vty, struct route_map_index *index, const char *command,
250 const char *arg, route_map_event_t type));
82f97584 251/* no match ip address prefix list */
d62a17ae 252extern void route_map_no_match_ip_address_prefix_list_hook(int (*func)(
253 struct vty *vty, struct route_map_index *index, const char *command,
254 const char *arg, route_map_event_t type));
82f97584 255/* match ip next hop */
d62a17ae 256extern void route_map_match_ip_next_hop_hook(int (*func)(
257 struct vty *vty, struct route_map_index *index, const char *command,
258 const char *arg, route_map_event_t type));
82f97584 259/* no match ip next hop */
d62a17ae 260extern void route_map_no_match_ip_next_hop_hook(int (*func)(
261 struct vty *vty, struct route_map_index *index, const char *command,
262 const char *arg, route_map_event_t type));
82f97584 263/* match ip next hop prefix list */
d62a17ae 264extern void route_map_match_ip_next_hop_prefix_list_hook(int (*func)(
265 struct vty *vty, struct route_map_index *index, const char *command,
266 const char *arg, route_map_event_t type));
82f97584 267/* no match ip next hop prefix list */
d62a17ae 268extern void route_map_no_match_ip_next_hop_prefix_list_hook(int (*func)(
269 struct vty *vty, struct route_map_index *index, const char *command,
270 const char *arg, route_map_event_t type));
82f97584 271/* match ipv6 address */
d62a17ae 272extern void route_map_match_ipv6_address_hook(int (*func)(
273 struct vty *vty, struct route_map_index *index, const char *command,
274 const char *arg, route_map_event_t type));
82f97584 275/* no match ipv6 address */
d62a17ae 276extern void route_map_no_match_ipv6_address_hook(int (*func)(
277 struct vty *vty, struct route_map_index *index, const char *command,
278 const char *arg, route_map_event_t type));
82f97584 279/* match ipv6 address prefix list */
d62a17ae 280extern void route_map_match_ipv6_address_prefix_list_hook(int (*func)(
281 struct vty *vty, struct route_map_index *index, const char *command,
282 const char *arg, route_map_event_t type));
82f97584 283/* no match ipv6 address prefix list */
d62a17ae 284extern void route_map_no_match_ipv6_address_prefix_list_hook(int (*func)(
285 struct vty *vty, struct route_map_index *index, const char *command,
286 const char *arg, route_map_event_t type));
82f97584 287/* match metric */
d62a17ae 288extern void route_map_match_metric_hook(int (*func)(
289 struct vty *vty, struct route_map_index *index, const char *command,
290 const char *arg, route_map_event_t type));
82f97584 291/* no match metric */
d62a17ae 292extern void route_map_no_match_metric_hook(int (*func)(
293 struct vty *vty, struct route_map_index *index, const char *command,
294 const char *arg, route_map_event_t type));
82f97584 295/* match tag */
d62a17ae 296extern void route_map_match_tag_hook(int (*func)(
297 struct vty *vty, struct route_map_index *index, const char *command,
298 const char *arg, route_map_event_t type));
82f97584 299/* no match tag */
d62a17ae 300extern void route_map_no_match_tag_hook(int (*func)(
301 struct vty *vty, struct route_map_index *index, const char *command,
302 const char *arg, route_map_event_t type));
82f97584 303/* set ip nexthop */
d62a17ae 304extern void route_map_set_ip_nexthop_hook(
305 int (*func)(struct vty *vty, struct route_map_index *index,
306 const char *command, const char *arg));
82f97584 307/* no set ip nexthop */
d62a17ae 308extern void route_map_no_set_ip_nexthop_hook(
309 int (*func)(struct vty *vty, struct route_map_index *index,
310 const char *command, const char *arg));
82f97584 311/* set ipv6 nexthop local */
d62a17ae 312extern void route_map_set_ipv6_nexthop_local_hook(
313 int (*func)(struct vty *vty, struct route_map_index *index,
314 const char *command, const char *arg));
82f97584 315/* no set ipv6 nexthop local */
d62a17ae 316extern void route_map_no_set_ipv6_nexthop_local_hook(
317 int (*func)(struct vty *vty, struct route_map_index *index,
318 const char *command, const char *arg));
82f97584 319/* set metric */
d62a17ae 320extern void route_map_set_metric_hook(int (*func)(struct vty *vty,
321 struct route_map_index *index,
322 const char *command,
323 const char *arg));
82f97584 324/* no set metric */
d62a17ae 325extern void route_map_no_set_metric_hook(
326 int (*func)(struct vty *vty, struct route_map_index *index,
327 const char *command, const char *arg));
82f97584 328/* set tag */
d62a17ae 329extern void route_map_set_tag_hook(int (*func)(struct vty *vty,
330 struct route_map_index *index,
331 const char *command,
332 const char *arg));
82f97584 333/* no set tag */
d62a17ae 334extern void route_map_no_set_tag_hook(int (*func)(struct vty *vty,
335 struct route_map_index *index,
336 const char *command,
337 const char *arg));
e52702f2 338
d62a17ae 339extern void *route_map_rule_tag_compile(const char *arg);
340extern void route_map_rule_tag_free(void *rule);
dc9ffce8 341
718e3744 342#endif /* _ZEBRA_ROUTEMAP_H */