]> git.proxmox.com Git - mirror_frr.git/blob - isisd/isis_routemap.c
lib: enforce vrf_name_to_id by returning default_vrf when name is null
[mirror_frr.git] / isisd / isis_routemap.c
1 /*
2 * IS-IS Rout(e)ing protocol - isis_routemap.c
3 *
4 * Copyright (C) 2013-2015 Christian Franke <chris@opensourcerouting.org>
5 *
6 * This program 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 Free
8 * Software Foundation; either version 2 of the License, or (at your option)
9 * any later version.
10 *
11 * This program is distributed in the hope that it will be useful,but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include <zebra.h>
22
23 #include "command.h"
24 #include "filter.h"
25 #include "hash.h"
26 #include "if.h"
27 #include "linklist.h"
28 #include "log.h"
29 #include "memory.h"
30 #include "prefix.h"
31 #include "plist.h"
32 #include "routemap.h"
33 #include "table.h"
34 #include "thread.h"
35 #include "vty.h"
36
37 #include "isis_constants.h"
38 #include "isis_common.h"
39 #include "isis_flags.h"
40 #include "dict.h"
41 #include "isisd.h"
42 #include "isis_misc.h"
43 #include "isis_adjacency.h"
44 #include "isis_circuit.h"
45 #include "isis_pdu.h"
46 #include "isis_lsp.h"
47 #include "isis_spf.h"
48 #include "isis_route.h"
49 #include "isis_zebra.h"
50 #include "isis_routemap.h"
51
52 static route_map_result_t route_match_ip_address(void *rule,
53 const struct prefix *prefix,
54 route_map_object_t type,
55 void *object)
56 {
57 struct access_list *alist;
58
59 if (type != RMAP_ISIS)
60 return RMAP_NOMATCH;
61
62 alist = access_list_lookup(AFI_IP, (char *)rule);
63 if (access_list_apply(alist, prefix) != FILTER_DENY)
64 return RMAP_MATCH;
65
66 return RMAP_NOMATCH;
67 }
68
69 static void *route_match_ip_address_compile(const char *arg)
70 {
71 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg);
72 }
73
74 static void route_match_ip_address_free(void *rule)
75 {
76 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
77 }
78
79 static struct route_map_rule_cmd route_match_ip_address_cmd = {
80 "ip address", route_match_ip_address, route_match_ip_address_compile,
81 route_match_ip_address_free};
82
83 /* ------------------------------------------------------------*/
84
85 static route_map_result_t
86 route_match_ip_address_prefix_list(void *rule, const struct prefix *prefix,
87 route_map_object_t type, void *object)
88 {
89 struct prefix_list *plist;
90
91 if (type != RMAP_ISIS)
92 return RMAP_NOMATCH;
93
94 plist = prefix_list_lookup(AFI_IP, (char *)rule);
95 if (prefix_list_apply(plist, prefix) != PREFIX_DENY)
96 return RMAP_MATCH;
97
98 return RMAP_NOMATCH;
99 }
100
101 static void *route_match_ip_address_prefix_list_compile(const char *arg)
102 {
103 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg);
104 }
105
106 static void route_match_ip_address_prefix_list_free(void *rule)
107 {
108 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
109 }
110
111 struct route_map_rule_cmd route_match_ip_address_prefix_list_cmd = {
112 "ip address prefix-list", route_match_ip_address_prefix_list,
113 route_match_ip_address_prefix_list_compile,
114 route_match_ip_address_prefix_list_free};
115
116 /* ------------------------------------------------------------*/
117
118 static route_map_result_t route_match_ipv6_address(void *rule,
119 const struct prefix *prefix,
120 route_map_object_t type,
121 void *object)
122 {
123 struct access_list *alist;
124
125 if (type != RMAP_ISIS)
126 return RMAP_NOMATCH;
127
128 alist = access_list_lookup(AFI_IP6, (char *)rule);
129 if (access_list_apply(alist, prefix) != FILTER_DENY)
130 return RMAP_MATCH;
131
132 return RMAP_NOMATCH;
133 }
134
135 static void *route_match_ipv6_address_compile(const char *arg)
136 {
137 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg);
138 }
139
140 static void route_match_ipv6_address_free(void *rule)
141 {
142 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
143 }
144
145 static struct route_map_rule_cmd route_match_ipv6_address_cmd = {
146 "ipv6 address", route_match_ipv6_address,
147 route_match_ipv6_address_compile, route_match_ipv6_address_free};
148
149 /* ------------------------------------------------------------*/
150
151 static route_map_result_t
152 route_match_ipv6_address_prefix_list(void *rule, const struct prefix *prefix,
153 route_map_object_t type, void *object)
154 {
155 struct prefix_list *plist;
156
157 if (type != RMAP_ISIS)
158 return RMAP_NOMATCH;
159
160 plist = prefix_list_lookup(AFI_IP6, (char *)rule);
161 if (prefix_list_apply(plist, prefix) != PREFIX_DENY)
162 return RMAP_MATCH;
163
164 return RMAP_NOMATCH;
165 }
166
167 static void *route_match_ipv6_address_prefix_list_compile(const char *arg)
168 {
169 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg);
170 }
171
172 static void route_match_ipv6_address_prefix_list_free(void *rule)
173 {
174 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
175 }
176
177 struct route_map_rule_cmd route_match_ipv6_address_prefix_list_cmd = {
178 "ipv6 address prefix-list", route_match_ipv6_address_prefix_list,
179 route_match_ipv6_address_prefix_list_compile,
180 route_match_ipv6_address_prefix_list_free};
181
182 /* ------------------------------------------------------------*/
183
184 static route_map_result_t route_set_metric(void *rule,
185 const struct prefix *prefix,
186 route_map_object_t type,
187 void *object)
188 {
189 uint32_t *metric;
190 struct isis_ext_info *info;
191
192 if (type == RMAP_ISIS) {
193 metric = rule;
194 info = object;
195
196 info->metric = *metric;
197 }
198 return RMAP_OKAY;
199 }
200
201 static void *route_set_metric_compile(const char *arg)
202 {
203 unsigned long metric;
204 char *endp;
205 uint32_t *ret;
206
207 metric = strtoul(arg, &endp, 10);
208 if (arg[0] == '\0' || *endp != '\0' || metric > MAX_WIDE_PATH_METRIC)
209 return NULL;
210
211 ret = XCALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(*ret));
212 *ret = metric;
213
214 return ret;
215 }
216
217 static void route_set_metric_free(void *rule)
218 {
219 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
220 }
221
222 static struct route_map_rule_cmd route_set_metric_cmd = {
223 "metric", route_set_metric, route_set_metric_compile,
224 route_set_metric_free};
225
226 void isis_route_map_init(void)
227 {
228 route_map_init();
229
230 route_map_match_ip_address_hook(generic_match_add);
231 route_map_no_match_ip_address_hook(generic_match_delete);
232
233 route_map_match_ip_address_prefix_list_hook(generic_match_add);
234 route_map_no_match_ip_address_prefix_list_hook(generic_match_delete);
235
236 route_map_match_ipv6_address_hook(generic_match_add);
237 route_map_no_match_ipv6_address_hook(generic_match_delete);
238
239 route_map_match_ipv6_address_prefix_list_hook(generic_match_add);
240 route_map_no_match_ipv6_address_prefix_list_hook(generic_match_delete);
241
242 route_map_set_metric_hook(generic_set_add);
243 route_map_no_set_metric_hook(generic_set_delete);
244
245 route_map_install_match(&route_match_ip_address_cmd);
246 route_map_install_match(&route_match_ip_address_prefix_list_cmd);
247 route_map_install_match(&route_match_ipv6_address_cmd);
248 route_map_install_match(&route_match_ipv6_address_prefix_list_cmd);
249 route_map_install_set(&route_set_metric_cmd);
250 }