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