]> git.proxmox.com Git - mirror_frr.git/blame - isisd/isis_routemap.c
all: removed all DEFUN command stomps
[mirror_frr.git] / isisd / isis_routemap.c
CommitLineData
eb5d44eb 1/*
f3ccedaa 2 * IS-IS Rout(e)ing protocol - isis_routemap.c
eb5d44eb 3 *
f3ccedaa 4 * Copyright (C) 2013-2015 Christian Franke <chris@opensourcerouting.org>
eb5d44eb 5 *
6 * This program is free software; you can redistribute it and/or modify it
f3ccedaa 7 * under the terms of the GNU General Public License as published by the Free
eb5d44eb 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; if not, write to the Free Software Foundation, Inc.,
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
f3ccedaa 20
eb5d44eb 21#include <zebra.h>
eb5d44eb 22
f3ccedaa
CF
23#include "command.h"
24#include "filter.h"
25#include "hash.h"
26#include "if.h"
eb5d44eb 27#include "linklist.h"
eb5d44eb 28#include "log.h"
29#include "memory.h"
30#include "prefix.h"
f3ccedaa 31#include "plist.h"
eb5d44eb 32#include "routemap.h"
f3ccedaa
CF
33#include "table.h"
34#include "thread.h"
35#include "vty.h"
eb5d44eb 36
37#include "isis_constants.h"
38#include "isis_common.h"
3f045a08 39#include "isis_flags.h"
eb5d44eb 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_tlv.h"
46#include "isis_pdu.h"
47#include "isis_lsp.h"
48#include "isis_spf.h"
49#include "isis_route.h"
50#include "isis_zebra.h"
f3ccedaa 51#include "isis_routemap.h"
eb5d44eb 52
f3ccedaa
CF
53static route_map_result_t
54route_match_ip_address(void *rule, struct prefix *prefix,
55 route_map_object_t type, void *object)
56{
57 struct access_list *alist;
eb5d44eb 58
f3ccedaa
CF
59 if (type != RMAP_ISIS)
60 return RMAP_NOMATCH;
41b36e90 61
f3ccedaa
CF
62 alist = access_list_lookup(AFI_IP, (char*)rule);
63 if (access_list_apply(alist, prefix) != FILTER_DENY)
64 return RMAP_MATCH;
41b36e90 65
f3ccedaa
CF
66 return RMAP_NOMATCH;
67}
68
69static void *
70route_match_ip_address_compile(const char *arg)
71{
72 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg);
73}
74
75static void
76route_match_ip_address_free(void *rule)
77{
78 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
79}
80
81static struct route_map_rule_cmd route_match_ip_address_cmd =
82{
83 "ip address",
84 route_match_ip_address,
85 route_match_ip_address_compile,
86 route_match_ip_address_free
87};
88
89/* ------------------------------------------------------------*/
90
91static route_map_result_t
92route_match_ip_address_prefix_list(void *rule, struct prefix *prefix,
93 route_map_object_t type, void *object)
94{
95 struct prefix_list *plist;
96
97 if (type != RMAP_ISIS)
98 return RMAP_NOMATCH;
99
100 plist = prefix_list_lookup(AFI_IP, (char*)rule);
101 if (prefix_list_apply(plist, prefix) != PREFIX_DENY)
102 return RMAP_MATCH;
103
104 return RMAP_NOMATCH;
105}
106
107static void *
108route_match_ip_address_prefix_list_compile(const char *arg)
109{
110 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
111}
112
113static void
114route_match_ip_address_prefix_list_free (void *rule)
115{
116 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
117}
118
119struct route_map_rule_cmd route_match_ip_address_prefix_list_cmd =
120{
121 "ip address prefix-list",
122 route_match_ip_address_prefix_list,
123 route_match_ip_address_prefix_list_compile,
124 route_match_ip_address_prefix_list_free
125};
126
127/* ------------------------------------------------------------*/
128
129static route_map_result_t
130route_match_ipv6_address(void *rule, struct prefix *prefix,
131 route_map_object_t type, void *object)
eb5d44eb 132{
f3ccedaa 133 struct access_list *alist;
f390d2c7 134
f3ccedaa
CF
135 if (type != RMAP_ISIS)
136 return RMAP_NOMATCH;
137
138 alist = access_list_lookup(AFI_IP6, (char*)rule);
139 if (access_list_apply(alist, prefix) != FILTER_DENY)
140 return RMAP_MATCH;
141
142 return RMAP_NOMATCH;
143}
144
145static void *
146route_match_ipv6_address_compile(const char *arg)
147{
148 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg);
149}
150
151static void
152route_match_ipv6_address_free(void *rule)
153{
154 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
155}
156
157static struct route_map_rule_cmd route_match_ipv6_address_cmd =
158{
159 "ipv6 address",
160 route_match_ipv6_address,
161 route_match_ipv6_address_compile,
162 route_match_ipv6_address_free
163};
164
165/* ------------------------------------------------------------*/
166
167static route_map_result_t
168route_match_ipv6_address_prefix_list(void *rule, struct prefix *prefix,
169 route_map_object_t type, void *object)
170{
171 struct prefix_list *plist;
f390d2c7 172
f3ccedaa
CF
173 if (type != RMAP_ISIS)
174 return RMAP_NOMATCH;
175
176 plist = prefix_list_lookup(AFI_IP6, (char*)rule);
177 if (prefix_list_apply(plist, prefix) != PREFIX_DENY)
178 return RMAP_MATCH;
179
180 return RMAP_NOMATCH;
181}
182
183static void *
184route_match_ipv6_address_prefix_list_compile(const char *arg)
185{
186 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
187}
188
189static void
190route_match_ipv6_address_prefix_list_free (void *rule)
191{
192 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
193}
194
195struct route_map_rule_cmd route_match_ipv6_address_prefix_list_cmd =
196{
197 "ipv6 address prefix-list",
198 route_match_ipv6_address_prefix_list,
199 route_match_ipv6_address_prefix_list_compile,
200 route_match_ipv6_address_prefix_list_free
201};
202
203/* ------------------------------------------------------------*/
204
205static route_map_result_t
206route_set_metric(void *rule, struct prefix *prefix,
207 route_map_object_t type, void *object)
208{
209 uint32_t *metric;
210 struct isis_ext_info *info;
211
212 if (type == RMAP_ISIS)
f390d2c7 213 {
f3ccedaa
CF
214 metric = rule;
215 info = object;
216
217 info->metric = *metric;
f390d2c7 218 }
f3ccedaa 219 return RMAP_OKAY;
eb5d44eb 220}
221
f3ccedaa
CF
222static void *
223route_set_metric_compile(const char *arg)
224{
225 unsigned long metric;
226 char *endp;
227 uint32_t *ret;
228
229 metric = strtoul(arg, &endp, 10);
230 if (arg[0] == '\0' || *endp != '\0' || metric > MAX_WIDE_PATH_METRIC)
231 return NULL;
232
233 ret = XCALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(ret));
234 *ret = metric;
235
236 return ret;
237}
238
239static void
240route_set_metric_free(void *rule)
eb5d44eb 241{
f3ccedaa
CF
242 XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
243}
244
245static struct route_map_rule_cmd route_set_metric_cmd =
246{
247 "metric",
248 route_set_metric,
249 route_set_metric_compile,
250 route_set_metric_free
251};
eb5d44eb 252
82f97584
DW
253void
254isis_route_map_init(void)
f3ccedaa 255{
82f97584
DW
256 route_map_init();
257 route_map_init_vty();
f3ccedaa 258
82f97584
DW
259 route_map_match_ip_address_hook (generic_match_add);
260 route_map_no_match_ip_address_hook (generic_match_delete);
f3ccedaa 261
82f97584
DW
262 route_map_match_ip_address_prefix_list_hook (generic_match_add);
263 route_map_no_match_ip_address_prefix_list_hook (generic_match_delete);
f3ccedaa 264
82f97584
DW
265 route_map_match_ipv6_address_hook (generic_match_add);
266 route_map_no_match_ipv6_address_hook (generic_match_delete);
f3ccedaa 267
82f97584
DW
268 route_map_match_ipv6_address_prefix_list_hook (generic_match_add);
269 route_map_no_match_ipv6_address_prefix_list_hook (generic_match_delete);
f3ccedaa 270
82f97584
DW
271 route_map_set_metric_hook (generic_set_add);
272 route_map_no_set_metric_hook (generic_set_delete);
f3ccedaa
CF
273
274 route_map_install_match(&route_match_ip_address_cmd);
f3ccedaa 275 route_map_install_match(&route_match_ip_address_prefix_list_cmd);
f3ccedaa 276 route_map_install_match(&route_match_ipv6_address_cmd);
f3ccedaa 277 route_map_install_match(&route_match_ipv6_address_prefix_list_cmd);
f3ccedaa 278 route_map_install_set(&route_set_metric_cmd);
eb5d44eb 279}