]> git.proxmox.com Git - mirror_frr.git/blame - lib/routemap.h
2004-09-13 Paul Jakma <paul@dishone.st>
[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
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,
48 RMAP_BGP
49} route_map_object_t;
50
51typedef enum
52{
53 RMAP_EXIT,
54 RMAP_GOTO,
55 RMAP_NEXT
56} route_map_end_t;
57
58typedef enum
59{
60 RMAP_EVENT_SET_ADDED,
61 RMAP_EVENT_SET_DELETED,
62 RMAP_EVENT_SET_REPLACED,
63 RMAP_EVENT_MATCH_ADDED,
64 RMAP_EVENT_MATCH_DELETED,
65 RMAP_EVENT_MATCH_REPLACED,
66 RMAP_EVENT_INDEX_ADDED,
67 RMAP_EVENT_INDEX_DELETED
68} route_map_event_t;
69
70/* Route map rule structure for matching and setting. */
71struct route_map_rule_cmd
72{
73 /* Route map rule name (e.g. as-path, metric) */
74 char *str;
75
76 /* Function for value set or match. */
77 route_map_result_t (*func_apply)(void *, struct prefix *,
78 route_map_object_t, void *);
79
80 /* Compile argument and return result as void *. */
81 void *(*func_compile)(char *);
82
83 /* Free allocated value by func_compile (). */
84 void (*func_free)(void *);
85};
86
87/* Route map apply error. */
88enum
89{
90 /* Route map rule is missing. */
91 RMAP_RULE_MISSING = 1,
92
93 /* Route map rule can't compile */
94 RMAP_COMPILE_ERROR
95};
96
97/* Route map rule list. */
98struct route_map_rule_list
99{
100 struct route_map_rule *head;
101 struct route_map_rule *tail;
102};
103
104/* Route map index structure. */
105struct route_map_index
106{
107 struct route_map *map;
108
109 /* Preference of this route map rule. */
110 int pref;
111
112 /* Route map type permit or deny. */
113 enum route_map_type type;
114
115 /* Do we follow old rules, or hop forward? */
116 route_map_end_t exitpolicy;
117
118 /* If we're using "GOTO", to where do we go? */
119 int nextpref;
120
121 /* Matching rule list. */
122 struct route_map_rule_list match_list;
123 struct route_map_rule_list set_list;
124
125 /* Make linked list. */
126 struct route_map_index *next;
127 struct route_map_index *prev;
128};
129
130/* Route map list structure. */
131struct route_map
132{
133 /* Name of route map. */
134 char *name;
135
136 /* Route map's rule. */
137 struct route_map_index *head;
138 struct route_map_index *tail;
139
140 /* Make linked list. */
141 struct route_map *next;
142 struct route_map *prev;
143};
144
145/* Prototypes. */
146void route_map_init ();
147void route_map_init_vty ();
148
149/* Add match statement to route map. */
150int
151route_map_add_match (struct route_map_index *index,
152 char *match_name,
153 char *match_arg);
154
155/* Delete specified route match rule. */
156int
157route_map_delete_match (struct route_map_index *index,
158 char *match_name,
159 char *match_arg);
160
161/* Add route-map set statement to the route map. */
162int
163route_map_add_set (struct route_map_index *index,
164 char *set_name,
165 char *set_arg);
166
167/* Delete route map set rule. */
168int
169route_map_delete_set (struct route_map_index *index, char *set_name,
170 char *set_arg);
171
172/* Install rule command to the match list. */
173void
174route_map_install_match (struct route_map_rule_cmd *cmd);
175
176/* Install rule command to the set list. */
177void
178route_map_install_set (struct route_map_rule_cmd *cmd);
179
180/* Lookup route map by name. */
181struct route_map *
182route_map_lookup_by_name (char *name);
183
184/* Apply route map to the object. */
185route_map_result_t
186route_map_apply (struct route_map *map, struct prefix *,
187 route_map_object_t object_type, void *object);
188
189void route_map_add_hook (void (*func) (char *));
190void route_map_delete_hook (void (*func) (char *));
191void route_map_event_hook (void (*func) (route_map_event_t, char *));
192
193
194#endif /* _ZEBRA_ROUTEMAP_H */