]> git.proxmox.com Git - mirror_frr.git/blame - lib/routemap.h
lib: migrate to new memory-type handling
[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 *
16 * You should have received a copy of the GNU General Public License
17 * along with GNU Zebra; see the file COPYING. If not, write to the Free
18 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 * 02111-1307, USA.
20 */
21
22#ifndef _ZEBRA_ROUTEMAP_H
23#define _ZEBRA_ROUTEMAP_H
24
24873f0c
DS
25#include "prefix.h"
26
718e3744 27/* Route map's type. */
28enum route_map_type
29{
30 RMAP_PERMIT,
31 RMAP_DENY,
32 RMAP_ANY
33};
34
35typedef enum
36{
37 RMAP_MATCH,
38 RMAP_DENYMATCH,
39 RMAP_NOMATCH,
40 RMAP_ERROR,
41 RMAP_OKAY
42} route_map_result_t;
43
44typedef enum
45{
46 RMAP_RIP,
47 RMAP_RIPNG,
48 RMAP_OSPF,
49 RMAP_OSPF6,
7514fb77 50 RMAP_BGP,
f3ccedaa
CF
51 RMAP_ZEBRA,
52 RMAP_ISIS,
718e3744 53} route_map_object_t;
54
55typedef enum
56{
57 RMAP_EXIT,
58 RMAP_GOTO,
59 RMAP_NEXT
60} route_map_end_t;
61
62typedef enum
63{
64 RMAP_EVENT_SET_ADDED,
65 RMAP_EVENT_SET_DELETED,
66 RMAP_EVENT_SET_REPLACED,
67 RMAP_EVENT_MATCH_ADDED,
68 RMAP_EVENT_MATCH_DELETED,
69 RMAP_EVENT_MATCH_REPLACED,
70 RMAP_EVENT_INDEX_ADDED,
518f0eb1
DS
71 RMAP_EVENT_INDEX_DELETED,
72 RMAP_EVENT_CALL_ADDED, /* call to another routemap added */
73 RMAP_EVENT_CALL_DELETED,
74 RMAP_EVENT_PLIST_ADDED,
75 RMAP_EVENT_PLIST_DELETED,
76 RMAP_EVENT_CLIST_ADDED,
77 RMAP_EVENT_CLIST_DELETED,
78 RMAP_EVENT_ECLIST_ADDED,
79 RMAP_EVENT_ECLIST_DELETED,
80 RMAP_EVENT_ASLIST_ADDED,
81 RMAP_EVENT_ASLIST_DELETED,
82 RMAP_EVENT_FILTER_ADDED,
83 RMAP_EVENT_FILTER_DELETED,
718e3744 84} route_map_event_t;
85
fee0f4c6 86/* Depth limit in RMAP recursion using RMAP_CALL. */
87#define RMAP_RECURSION_LIMIT 10
88
718e3744 89/* Route map rule structure for matching and setting. */
90struct route_map_rule_cmd
91{
92 /* Route map rule name (e.g. as-path, metric) */
27a43a81 93 const char *str;
718e3744 94
95 /* Function for value set or match. */
96 route_map_result_t (*func_apply)(void *, struct prefix *,
97 route_map_object_t, void *);
98
99 /* Compile argument and return result as void *. */
c9eca01b 100 void *(*func_compile)(const char *);
718e3744 101
102 /* Free allocated value by func_compile (). */
103 void (*func_free)(void *);
104};
105
106/* Route map apply error. */
107enum
108{
109 /* Route map rule is missing. */
110 RMAP_RULE_MISSING = 1,
111
112 /* Route map rule can't compile */
113 RMAP_COMPILE_ERROR
114};
115
116/* Route map rule list. */
117struct route_map_rule_list
118{
119 struct route_map_rule *head;
120 struct route_map_rule *tail;
121};
122
123/* Route map index structure. */
124struct route_map_index
125{
126 struct route_map *map;
4a8164e5 127 char *description;
718e3744 128
129 /* Preference of this route map rule. */
130 int pref;
131
132 /* Route map type permit or deny. */
133 enum route_map_type type;
134
135 /* Do we follow old rules, or hop forward? */
136 route_map_end_t exitpolicy;
137
138 /* If we're using "GOTO", to where do we go? */
139 int nextpref;
140
fee0f4c6 141 /* If we're using "CALL", to which route-map do ew go? */
142 char *nextrm;
143
718e3744 144 /* Matching rule list. */
145 struct route_map_rule_list match_list;
146 struct route_map_rule_list set_list;
147
148 /* Make linked list. */
149 struct route_map_index *next;
150 struct route_map_index *prev;
151};
152
153/* Route map list structure. */
154struct route_map
155{
156 /* Name of route map. */
157 char *name;
158
159 /* Route map's rule. */
160 struct route_map_index *head;
161 struct route_map_index *tail;
162
163 /* Make linked list. */
164 struct route_map *next;
165 struct route_map *prev;
518f0eb1
DS
166
167 /* Maintain update info */
168 int to_be_processed; /* True if modification isn't acted on yet */
169 int deleted; /* If 1, then this node will be deleted */
718e3744 170};
171
172/* Prototypes. */
8cc4198f 173extern void route_map_init (void);
174extern void route_map_init_vty (void);
228da428 175extern void route_map_finish (void);
718e3744 176
177/* Add match statement to route map. */
8cc4198f 178extern int route_map_add_match (struct route_map_index *index,
179 const char *match_name,
180 const char *match_arg);
718e3744 181
182/* Delete specified route match rule. */
8cc4198f 183extern int route_map_delete_match (struct route_map_index *index,
184 const char *match_name,
185 const char *match_arg);
718e3744 186
518f0eb1
DS
187extern const char *route_map_get_match_arg (struct route_map_index *index,
188 const char *match_name);
189
718e3744 190/* Add route-map set statement to the route map. */
8cc4198f 191extern int route_map_add_set (struct route_map_index *index,
192 const char *set_name,
193 const char *set_arg);
718e3744 194
195/* Delete route map set rule. */
8cc4198f 196extern int route_map_delete_set (struct route_map_index *index,
197 const char *set_name,
198 const char *set_arg);
718e3744 199
200/* Install rule command to the match list. */
8cc4198f 201extern void route_map_install_match (struct route_map_rule_cmd *cmd);
718e3744 202
203/* Install rule command to the set list. */
8cc4198f 204extern void route_map_install_set (struct route_map_rule_cmd *cmd);
718e3744 205
206/* Lookup route map by name. */
8cc4198f 207extern struct route_map * route_map_lookup_by_name (const char *name);
718e3744 208
209/* Apply route map to the object. */
8cc4198f 210extern route_map_result_t route_map_apply (struct route_map *map,
211 struct prefix *,
212 route_map_object_t object_type,
213 void *object);
214
215extern void route_map_add_hook (void (*func) (const char *));
216extern void route_map_delete_hook (void (*func) (const char *));
518f0eb1
DS
217extern void route_map_event_hook (void (*func) (route_map_event_t,
218 const char *));
219extern int route_map_mark_updated (const char *name, int deleted);
220extern int route_map_clear_updated (struct route_map *rmap);
5fe9f963 221extern void route_map_walk_update_list (int (*update_fn) (char *name));
518f0eb1
DS
222extern void route_map_upd8_dependency (route_map_event_t type, const char *arg,
223 const char *rmap_name);
224extern void route_map_notify_dependencies (const char *affected_name,
225 route_map_event_t event);
718e3744 226
227#endif /* _ZEBRA_ROUTEMAP_H */