blob: 321e1927aa64a8bf09f8cb75f8abf81db412c6c0 [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/* 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
25/* Route map's type. */
26enum route_map_type
27{
28 RMAP_PERMIT,
29 RMAP_DENY,
30 RMAP_ANY
31};
32
33typedef enum
34{
35 RMAP_MATCH,
36 RMAP_DENYMATCH,
37 RMAP_NOMATCH,
38 RMAP_ERROR,
39 RMAP_OKAY
40} route_map_result_t;
41
42typedef enum
43{
44 RMAP_RIP,
45 RMAP_RIPNG,
46 RMAP_OSPF,
47 RMAP_OSPF6,
Paul Jakma7514fb72007-05-02 16:05:35 +000048 RMAP_BGP,
49 RMAP_ZEBRA
paul718e3742002-12-13 20:15:29 +000050} route_map_object_t;
51
52typedef enum
53{
54 RMAP_EXIT,
55 RMAP_GOTO,
56 RMAP_NEXT
57} route_map_end_t;
58
59typedef enum
60{
61 RMAP_EVENT_SET_ADDED,
62 RMAP_EVENT_SET_DELETED,
63 RMAP_EVENT_SET_REPLACED,
64 RMAP_EVENT_MATCH_ADDED,
65 RMAP_EVENT_MATCH_DELETED,
66 RMAP_EVENT_MATCH_REPLACED,
67 RMAP_EVENT_INDEX_ADDED,
68 RMAP_EVENT_INDEX_DELETED
69} route_map_event_t;
70
paulfee0f4c2004-09-13 05:12:46 +000071/* Depth limit in RMAP recursion using RMAP_CALL. */
72#define RMAP_RECURSION_LIMIT 10
73
paul718e3742002-12-13 20:15:29 +000074/* Route map rule structure for matching and setting. */
75struct route_map_rule_cmd
76{
77 /* Route map rule name (e.g. as-path, metric) */
hasso27a43a82004-10-08 06:29:12 +000078 const char *str;
paul718e3742002-12-13 20:15:29 +000079
80 /* Function for value set or match. */
81 route_map_result_t (*func_apply)(void *, struct prefix *,
82 route_map_object_t, void *);
83
84 /* Compile argument and return result as void *. */
paulc9eca012004-10-11 11:28:44 +000085 void *(*func_compile)(const char *);
paul718e3742002-12-13 20:15:29 +000086
87 /* Free allocated value by func_compile (). */
88 void (*func_free)(void *);
89};
90
91/* Route map apply error. */
92enum
93{
94 /* Route map rule is missing. */
95 RMAP_RULE_MISSING = 1,
96
97 /* Route map rule can't compile */
98 RMAP_COMPILE_ERROR
99};
100
101/* Route map rule list. */
102struct route_map_rule_list
103{
104 struct route_map_rule *head;
105 struct route_map_rule *tail;
106};
107
108/* Route map index structure. */
109struct route_map_index
110{
111 struct route_map *map;
hasso4a8164e2005-04-08 14:20:18 +0000112 char *description;
paul718e3742002-12-13 20:15:29 +0000113
114 /* Preference of this route map rule. */
115 int pref;
116
117 /* Route map type permit or deny. */
118 enum route_map_type type;
119
120 /* Do we follow old rules, or hop forward? */
121 route_map_end_t exitpolicy;
122
123 /* If we're using "GOTO", to where do we go? */
124 int nextpref;
125
paulfee0f4c2004-09-13 05:12:46 +0000126 /* If we're using "CALL", to which route-map do ew go? */
127 char *nextrm;
128
paul718e3742002-12-13 20:15:29 +0000129 /* Matching rule list. */
130 struct route_map_rule_list match_list;
131 struct route_map_rule_list set_list;
132
133 /* Make linked list. */
134 struct route_map_index *next;
135 struct route_map_index *prev;
136};
137
138/* Route map list structure. */
139struct route_map
140{
141 /* Name of route map. */
142 char *name;
143
144 /* Route map's rule. */
145 struct route_map_index *head;
146 struct route_map_index *tail;
147
148 /* Make linked list. */
149 struct route_map *next;
150 struct route_map *prev;
151};
152
153/* Prototypes. */
paul8cc41982005-05-06 21:25:49 +0000154extern void route_map_init (void);
155extern void route_map_init_vty (void);
paul718e3742002-12-13 20:15:29 +0000156
157/* Add match statement to route map. */
paul8cc41982005-05-06 21:25:49 +0000158extern int route_map_add_match (struct route_map_index *index,
159 const char *match_name,
160 const char *match_arg);
paul718e3742002-12-13 20:15:29 +0000161
162/* Delete specified route match rule. */
paul8cc41982005-05-06 21:25:49 +0000163extern int route_map_delete_match (struct route_map_index *index,
164 const char *match_name,
165 const char *match_arg);
paul718e3742002-12-13 20:15:29 +0000166
167/* Add route-map set statement to the route map. */
paul8cc41982005-05-06 21:25:49 +0000168extern int route_map_add_set (struct route_map_index *index,
169 const char *set_name,
170 const char *set_arg);
paul718e3742002-12-13 20:15:29 +0000171
172/* Delete route map set rule. */
paul8cc41982005-05-06 21:25:49 +0000173extern int route_map_delete_set (struct route_map_index *index,
174 const char *set_name,
175 const char *set_arg);
paul718e3742002-12-13 20:15:29 +0000176
177/* Install rule command to the match list. */
paul8cc41982005-05-06 21:25:49 +0000178extern void route_map_install_match (struct route_map_rule_cmd *cmd);
paul718e3742002-12-13 20:15:29 +0000179
180/* Install rule command to the set list. */
paul8cc41982005-05-06 21:25:49 +0000181extern void route_map_install_set (struct route_map_rule_cmd *cmd);
paul718e3742002-12-13 20:15:29 +0000182
183/* Lookup route map by name. */
paul8cc41982005-05-06 21:25:49 +0000184extern struct route_map * route_map_lookup_by_name (const char *name);
paul718e3742002-12-13 20:15:29 +0000185
186/* Apply route map to the object. */
paul8cc41982005-05-06 21:25:49 +0000187extern route_map_result_t route_map_apply (struct route_map *map,
188 struct prefix *,
189 route_map_object_t object_type,
190 void *object);
paul718e3742002-12-13 20:15:29 +0000191
paul8cc41982005-05-06 21:25:49 +0000192extern void route_map_add_hook (void (*func) (const char *));
193extern void route_map_delete_hook (void (*func) (const char *));
194extern void route_map_event_hook (void (*func) (route_map_event_t, const char *));
paul718e3742002-12-13 20:15:29 +0000195
196#endif /* _ZEBRA_ROUTEMAP_H */