]> git.proxmox.com Git - mirror_frr.git/blob - isisd/isis_routemap.c
Merge pull request #7518 from donaldsharp/asic_offload_more
[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 "isisd.h"
41 #include "isis_misc.h"
42 #include "isis_adjacency.h"
43 #include "isis_circuit.h"
44 #include "isis_pdu.h"
45 #include "isis_lsp.h"
46 #include "isis_spf.h"
47 #include "isis_route.h"
48 #include "isis_zebra.h"
49 #include "isis_routemap.h"
50
51 static enum route_map_cmd_result_t
52 route_match_ip_address(void *rule, const struct prefix *prefix, void *object)
53 {
54 struct access_list *alist;
55
56 alist = access_list_lookup(AFI_IP, (char *)rule);
57 if (access_list_apply(alist, prefix) != FILTER_DENY)
58 return RMAP_MATCH;
59
60 return RMAP_NOMATCH;
61 }
62
63 static void *route_match_ip_address_compile(const char *arg)
64 {
65 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg);
66 }
67
68 static void route_match_ip_address_free(void *rule)
69 {
70 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
71 }
72
73 static const struct route_map_rule_cmd route_match_ip_address_cmd = {
74 "ip address",
75 route_match_ip_address,
76 route_match_ip_address_compile,
77 route_match_ip_address_free
78 };
79
80 /* ------------------------------------------------------------*/
81
82 static enum route_map_cmd_result_t
83 route_match_ip_address_prefix_list(void *rule, const struct prefix *prefix,
84 void *object)
85 {
86 struct prefix_list *plist;
87
88 plist = prefix_list_lookup(AFI_IP, (char *)rule);
89 if (prefix_list_apply(plist, prefix) != PREFIX_DENY)
90 return RMAP_MATCH;
91
92 return RMAP_NOMATCH;
93 }
94
95 static void *route_match_ip_address_prefix_list_compile(const char *arg)
96 {
97 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg);
98 }
99
100 static void route_match_ip_address_prefix_list_free(void *rule)
101 {
102 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
103 }
104
105 static const struct route_map_rule_cmd
106 route_match_ip_address_prefix_list_cmd = {
107 "ip address prefix-list",
108 route_match_ip_address_prefix_list,
109 route_match_ip_address_prefix_list_compile,
110 route_match_ip_address_prefix_list_free
111 };
112
113 /* ------------------------------------------------------------*/
114
115 static enum route_map_cmd_result_t
116 route_match_ipv6_address(void *rule, const struct prefix *prefix, void *object)
117 {
118 struct access_list *alist;
119
120 alist = access_list_lookup(AFI_IP6, (char *)rule);
121 if (access_list_apply(alist, prefix) != FILTER_DENY)
122 return RMAP_MATCH;
123
124 return RMAP_NOMATCH;
125 }
126
127 static void *route_match_ipv6_address_compile(const char *arg)
128 {
129 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg);
130 }
131
132 static void route_match_ipv6_address_free(void *rule)
133 {
134 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
135 }
136
137 static const struct route_map_rule_cmd route_match_ipv6_address_cmd = {
138 "ipv6 address",
139 route_match_ipv6_address,
140 route_match_ipv6_address_compile,
141 route_match_ipv6_address_free
142 };
143
144 /* ------------------------------------------------------------*/
145
146 static enum route_map_cmd_result_t
147 route_match_ipv6_address_prefix_list(void *rule, const struct prefix *prefix,
148 void *object)
149 {
150 struct prefix_list *plist;
151
152 plist = prefix_list_lookup(AFI_IP6, (char *)rule);
153 if (prefix_list_apply(plist, prefix) != PREFIX_DENY)
154 return RMAP_MATCH;
155
156 return RMAP_NOMATCH;
157 }
158
159 static void *route_match_ipv6_address_prefix_list_compile(const char *arg)
160 {
161 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg);
162 }
163
164 static void route_match_ipv6_address_prefix_list_free(void *rule)
165 {
166 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
167 }
168
169 static const struct route_map_rule_cmd
170 route_match_ipv6_address_prefix_list_cmd = {
171 "ipv6 address prefix-list",
172 route_match_ipv6_address_prefix_list,
173 route_match_ipv6_address_prefix_list_compile,
174 route_match_ipv6_address_prefix_list_free
175 };
176
177 /* ------------------------------------------------------------*/
178
179 static enum route_map_cmd_result_t
180 route_set_metric(void *rule, const struct prefix *prefix, void *object)
181 {
182 uint32_t *metric;
183 struct isis_ext_info *info;
184
185 metric = rule;
186 info = object;
187
188 info->metric = *metric;
189
190 return RMAP_OKAY;
191 }
192
193 static void *route_set_metric_compile(const char *arg)
194 {
195 unsigned long metric;
196 char *endp;
197 uint32_t *ret;
198
199 metric = strtoul(arg, &endp, 10);
200 if (arg[0] == '\0' || *endp != '\0' || metric > MAX_WIDE_PATH_METRIC)
201 return NULL;
202
203 ret = XCALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(*ret));
204 *ret = metric;
205
206 return ret;
207 }
208
209 static void route_set_metric_free(void *rule)
210 {
211 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
212 }
213
214 static const struct route_map_rule_cmd route_set_metric_cmd = {
215 "metric",
216 route_set_metric,
217 route_set_metric_compile,
218 route_set_metric_free
219 };
220
221 void isis_route_map_init(void)
222 {
223 route_map_init();
224
225 route_map_match_ip_address_hook(generic_match_add);
226 route_map_no_match_ip_address_hook(generic_match_delete);
227
228 route_map_match_ip_address_prefix_list_hook(generic_match_add);
229 route_map_no_match_ip_address_prefix_list_hook(generic_match_delete);
230
231 route_map_match_ipv6_address_hook(generic_match_add);
232 route_map_no_match_ipv6_address_hook(generic_match_delete);
233
234 route_map_match_ipv6_address_prefix_list_hook(generic_match_add);
235 route_map_no_match_ipv6_address_prefix_list_hook(generic_match_delete);
236
237 route_map_set_metric_hook(generic_set_add);
238 route_map_no_set_metric_hook(generic_set_delete);
239
240 route_map_install_match(&route_match_ip_address_cmd);
241 route_map_install_match(&route_match_ip_address_prefix_list_cmd);
242 route_map_install_match(&route_match_ipv6_address_cmd);
243 route_map_install_match(&route_match_ipv6_address_prefix_list_cmd);
244 route_map_install_set(&route_set_metric_cmd);
245 }