2 * IS-IS Rout(e)ing protocol - isis_routemap.c
4 * Copyright (C) 2013-2015 Christian Franke <chris@opensourcerouting.org>
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)
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
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
37 #include "isis_constants.h"
38 #include "isis_common.h"
39 #include "isis_flags.h"
41 #include "isis_misc.h"
42 #include "isis_adjacency.h"
43 #include "isis_circuit.h"
47 #include "isis_route.h"
48 #include "isis_zebra.h"
49 #include "isis_routemap.h"
51 static enum route_map_cmd_result_t
52 route_match_ip_address(void *rule
, const struct prefix
*prefix
, void *object
)
54 struct access_list
*alist
;
56 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
57 if (access_list_apply(alist
, prefix
) != FILTER_DENY
)
63 static void *route_match_ip_address_compile(const char *arg
)
65 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
68 static void route_match_ip_address_free(void *rule
)
70 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
73 static const struct route_map_rule_cmd route_match_ip_address_cmd
= {
75 route_match_ip_address
,
76 route_match_ip_address_compile
,
77 route_match_ip_address_free
80 /* ------------------------------------------------------------*/
82 static enum route_map_cmd_result_t
83 route_match_ip_address_prefix_list(void *rule
, const struct prefix
*prefix
,
86 struct prefix_list
*plist
;
88 plist
= prefix_list_lookup(AFI_IP
, (char *)rule
);
89 if (prefix_list_apply(plist
, prefix
) != PREFIX_DENY
)
95 static void *route_match_ip_address_prefix_list_compile(const char *arg
)
97 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
100 static void route_match_ip_address_prefix_list_free(void *rule
)
102 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
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
113 /* ------------------------------------------------------------*/
115 /* `match tag TAG' */
116 /* Match function return 1 if match is success else return zero. */
117 static enum route_map_cmd_result_t
118 route_match_tag(void *rule
, const struct prefix
*p
, void *object
)
121 struct isis_ext_info
*info
;
122 route_tag_t info_tag
;
127 info_tag
= info
->tag
;
128 if (info_tag
== *tag
)
134 /* Route map commands for tag matching. */
135 static const struct route_map_rule_cmd route_match_tag_cmd
= {
138 route_map_rule_tag_compile
,
139 route_map_rule_tag_free
,
142 /* ------------------------------------------------------------*/
144 static enum route_map_cmd_result_t
145 route_match_ipv6_address(void *rule
, const struct prefix
*prefix
, void *object
)
147 struct access_list
*alist
;
149 alist
= access_list_lookup(AFI_IP6
, (char *)rule
);
150 if (access_list_apply(alist
, prefix
) != FILTER_DENY
)
156 static void *route_match_ipv6_address_compile(const char *arg
)
158 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
161 static void route_match_ipv6_address_free(void *rule
)
163 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
166 static const struct route_map_rule_cmd route_match_ipv6_address_cmd
= {
168 route_match_ipv6_address
,
169 route_match_ipv6_address_compile
,
170 route_match_ipv6_address_free
173 /* ------------------------------------------------------------*/
175 static enum route_map_cmd_result_t
176 route_match_ipv6_address_prefix_list(void *rule
, const struct prefix
*prefix
,
179 struct prefix_list
*plist
;
181 plist
= prefix_list_lookup(AFI_IP6
, (char *)rule
);
182 if (prefix_list_apply(plist
, prefix
) != PREFIX_DENY
)
188 static void *route_match_ipv6_address_prefix_list_compile(const char *arg
)
190 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
193 static void route_match_ipv6_address_prefix_list_free(void *rule
)
195 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
198 static const struct route_map_rule_cmd
199 route_match_ipv6_address_prefix_list_cmd
= {
200 "ipv6 address prefix-list",
201 route_match_ipv6_address_prefix_list
,
202 route_match_ipv6_address_prefix_list_compile
,
203 route_match_ipv6_address_prefix_list_free
206 /* ------------------------------------------------------------*/
208 static enum route_map_cmd_result_t
209 route_set_metric(void *rule
, const struct prefix
*prefix
, void *object
)
212 struct isis_ext_info
*info
;
217 info
->metric
= *metric
;
222 static void *route_set_metric_compile(const char *arg
)
224 unsigned long metric
;
228 metric
= strtoul(arg
, &endp
, 10);
229 if (arg
[0] == '\0' || *endp
!= '\0' || metric
> MAX_WIDE_PATH_METRIC
)
232 ret
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(*ret
));
238 static void route_set_metric_free(void *rule
)
240 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
243 static const struct route_map_rule_cmd route_set_metric_cmd
= {
246 route_set_metric_compile
,
247 route_set_metric_free
250 void isis_route_map_init(void)
254 route_map_match_ip_address_hook(generic_match_add
);
255 route_map_no_match_ip_address_hook(generic_match_delete
);
257 route_map_match_ip_address_prefix_list_hook(generic_match_add
);
258 route_map_no_match_ip_address_prefix_list_hook(generic_match_delete
);
260 route_map_match_ipv6_address_hook(generic_match_add
);
261 route_map_no_match_ipv6_address_hook(generic_match_delete
);
263 route_map_match_ipv6_address_prefix_list_hook(generic_match_add
);
264 route_map_no_match_ipv6_address_prefix_list_hook(generic_match_delete
);
266 route_map_match_tag_hook(generic_match_add
);
267 route_map_no_match_tag_hook(generic_match_delete
);
269 route_map_set_metric_hook(generic_set_add
);
270 route_map_no_set_metric_hook(generic_set_delete
);
272 route_map_install_match(&route_match_ip_address_cmd
);
273 route_map_install_match(&route_match_ip_address_prefix_list_cmd
);
274 route_map_install_match(&route_match_ipv6_address_cmd
);
275 route_map_install_match(&route_match_ipv6_address_prefix_list_cmd
);
276 route_map_install_match(&route_match_tag_cmd
);
277 route_map_install_set(&route_set_metric_cmd
);