blob: 68129e1d96c61b876ac57ed668a1c794f6d9445f [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
Paul Jakma23426d22017-01-23 10:55:55 +000025#include "prefix.h"
26
paul718e3742002-12-13 20:15:29 +000027/* 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,
Paul Jakma57345092011-12-25 17:52:09 +010048 RMAP_BABEL,
paul718e3742002-12-13 20:15:29 +000049 RMAP_OSPF,
50 RMAP_OSPF6,
Paul Jakma7514fb72007-05-02 16:05:35 +000051 RMAP_BGP,
Christian Frankeacf98652015-11-12 14:24:22 +010052 RMAP_ZEBRA,
53 RMAP_ISIS,
paul718e3742002-12-13 20:15:29 +000054} route_map_object_t;
55
56typedef enum
57{
58 RMAP_EXIT,
59 RMAP_GOTO,
60 RMAP_NEXT
61} route_map_end_t;
62
63typedef enum
64{
65 RMAP_EVENT_SET_ADDED,
66 RMAP_EVENT_SET_DELETED,
67 RMAP_EVENT_SET_REPLACED,
68 RMAP_EVENT_MATCH_ADDED,
69 RMAP_EVENT_MATCH_DELETED,
70 RMAP_EVENT_MATCH_REPLACED,
71 RMAP_EVENT_INDEX_ADDED,
72 RMAP_EVENT_INDEX_DELETED
73} route_map_event_t;
74
paulfee0f4c2004-09-13 05:12:46 +000075/* Depth limit in RMAP recursion using RMAP_CALL. */
76#define RMAP_RECURSION_LIMIT 10
77
paul718e3742002-12-13 20:15:29 +000078/* Route map rule structure for matching and setting. */
79struct route_map_rule_cmd
80{
81 /* Route map rule name (e.g. as-path, metric) */
hasso27a43a82004-10-08 06:29:12 +000082 const char *str;
paul718e3742002-12-13 20:15:29 +000083
84 /* Function for value set or match. */
85 route_map_result_t (*func_apply)(void *, struct prefix *,
86 route_map_object_t, void *);
87
88 /* Compile argument and return result as void *. */
paulc9eca012004-10-11 11:28:44 +000089 void *(*func_compile)(const char *);
paul718e3742002-12-13 20:15:29 +000090
91 /* Free allocated value by func_compile (). */
92 void (*func_free)(void *);
93};
94
95/* Route map apply error. */
96enum
97{
98 /* Route map rule is missing. */
99 RMAP_RULE_MISSING = 1,
100
101 /* Route map rule can't compile */
102 RMAP_COMPILE_ERROR
103};
104
105/* Route map rule list. */
106struct route_map_rule_list
107{
108 struct route_map_rule *head;
109 struct route_map_rule *tail;
110};
111
112/* Route map index structure. */
113struct route_map_index
114{
115 struct route_map *map;
hasso4a8164e2005-04-08 14:20:18 +0000116 char *description;
paul718e3742002-12-13 20:15:29 +0000117
118 /* Preference of this route map rule. */
119 int pref;
120
121 /* Route map type permit or deny. */
122 enum route_map_type type;
123
124 /* Do we follow old rules, or hop forward? */
125 route_map_end_t exitpolicy;
126
127 /* If we're using "GOTO", to where do we go? */
128 int nextpref;
129
paulfee0f4c2004-09-13 05:12:46 +0000130 /* If we're using "CALL", to which route-map do ew go? */
131 char *nextrm;
132
paul718e3742002-12-13 20:15:29 +0000133 /* Matching rule list. */
134 struct route_map_rule_list match_list;
135 struct route_map_rule_list set_list;
136
137 /* Make linked list. */
138 struct route_map_index *next;
139 struct route_map_index *prev;
140};
141
142/* Route map list structure. */
143struct route_map
144{
145 /* Name of route map. */
146 char *name;
147
148 /* Route map's rule. */
149 struct route_map_index *head;
150 struct route_map_index *tail;
151
152 /* Make linked list. */
153 struct route_map *next;
154 struct route_map *prev;
155};
156
157/* Prototypes. */
paul8cc41982005-05-06 21:25:49 +0000158extern void route_map_init (void);
159extern void route_map_init_vty (void);
Chris Caputo228da422009-07-18 05:44:03 +0000160extern void route_map_finish (void);
paul718e3742002-12-13 20:15:29 +0000161
162/* Add match statement to route map. */
paul8cc41982005-05-06 21:25:49 +0000163extern int route_map_add_match (struct route_map_index *index,
164 const char *match_name,
165 const char *match_arg);
paul718e3742002-12-13 20:15:29 +0000166
167/* Delete specified route match rule. */
paul8cc41982005-05-06 21:25:49 +0000168extern int route_map_delete_match (struct route_map_index *index,
169 const char *match_name,
170 const char *match_arg);
paul718e3742002-12-13 20:15:29 +0000171
172/* Add route-map set statement to the route map. */
paul8cc41982005-05-06 21:25:49 +0000173extern int route_map_add_set (struct route_map_index *index,
174 const char *set_name,
175 const char *set_arg);
paul718e3742002-12-13 20:15:29 +0000176
177/* Delete route map set rule. */
paul8cc41982005-05-06 21:25:49 +0000178extern int route_map_delete_set (struct route_map_index *index,
179 const char *set_name,
180 const char *set_arg);
paul718e3742002-12-13 20:15:29 +0000181
182/* Install rule command to the match list. */
paul8cc41982005-05-06 21:25:49 +0000183extern void route_map_install_match (struct route_map_rule_cmd *cmd);
paul718e3742002-12-13 20:15:29 +0000184
185/* Install rule command to the set list. */
paul8cc41982005-05-06 21:25:49 +0000186extern void route_map_install_set (struct route_map_rule_cmd *cmd);
paul718e3742002-12-13 20:15:29 +0000187
188/* Lookup route map by name. */
paul8cc41982005-05-06 21:25:49 +0000189extern struct route_map * route_map_lookup_by_name (const char *name);
paul718e3742002-12-13 20:15:29 +0000190
191/* Apply route map to the object. */
paul8cc41982005-05-06 21:25:49 +0000192extern route_map_result_t route_map_apply (struct route_map *map,
193 struct prefix *,
194 route_map_object_t object_type,
195 void *object);
paul718e3742002-12-13 20:15:29 +0000196
paul8cc41982005-05-06 21:25:49 +0000197extern void route_map_add_hook (void (*func) (const char *));
198extern void route_map_delete_hook (void (*func) (const char *));
199extern void route_map_event_hook (void (*func) (route_map_event_t, const char *));
paul718e3742002-12-13 20:15:29 +0000200
Christian Frankeddc160c2016-10-01 20:42:34 +0200201extern void *route_map_rule_tag_compile (const char *arg);
202extern void route_map_rule_tag_free (void *rule);
203
paul718e3742002-12-13 20:15:29 +0000204#endif /* _ZEBRA_ROUTEMAP_H */