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; if not, write to the Free Software Foundation, Inc.,
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
37 #include "isis_constants.h"
38 #include "isis_common.h"
39 #include "isis_flags.h"
42 #include "isis_misc.h"
43 #include "isis_adjacency.h"
44 #include "isis_circuit.h"
49 #include "isis_route.h"
50 #include "isis_zebra.h"
51 #include "isis_routemap.h"
53 static route_map_result_t
route_match_ip_address(void *rule
,
54 struct prefix
*prefix
,
55 route_map_object_t type
,
58 struct access_list
*alist
;
60 if (type
!= RMAP_ISIS
)
63 alist
= access_list_lookup(AFI_IP
, (char *)rule
);
64 if (access_list_apply(alist
, prefix
) != FILTER_DENY
)
70 static void *route_match_ip_address_compile(const char *arg
)
72 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
75 static void route_match_ip_address_free(void *rule
)
77 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
80 static struct route_map_rule_cmd route_match_ip_address_cmd
= {
81 "ip address", route_match_ip_address
, route_match_ip_address_compile
,
82 route_match_ip_address_free
};
84 /* ------------------------------------------------------------*/
86 static route_map_result_t
87 route_match_ip_address_prefix_list(void *rule
, struct prefix
*prefix
,
88 route_map_object_t type
, void *object
)
90 struct prefix_list
*plist
;
92 if (type
!= RMAP_ISIS
)
95 plist
= prefix_list_lookup(AFI_IP
, (char *)rule
);
96 if (prefix_list_apply(plist
, prefix
) != PREFIX_DENY
)
102 static void *route_match_ip_address_prefix_list_compile(const char *arg
)
104 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
107 static void route_match_ip_address_prefix_list_free(void *rule
)
109 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
112 struct route_map_rule_cmd route_match_ip_address_prefix_list_cmd
= {
113 "ip address prefix-list", route_match_ip_address_prefix_list
,
114 route_match_ip_address_prefix_list_compile
,
115 route_match_ip_address_prefix_list_free
};
117 /* ------------------------------------------------------------*/
119 static route_map_result_t
route_match_ipv6_address(void *rule
,
120 struct prefix
*prefix
,
121 route_map_object_t type
,
124 struct access_list
*alist
;
126 if (type
!= RMAP_ISIS
)
129 alist
= access_list_lookup(AFI_IP6
, (char *)rule
);
130 if (access_list_apply(alist
, prefix
) != FILTER_DENY
)
136 static void *route_match_ipv6_address_compile(const char *arg
)
138 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
141 static void route_match_ipv6_address_free(void *rule
)
143 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
146 static struct route_map_rule_cmd route_match_ipv6_address_cmd
= {
147 "ipv6 address", route_match_ipv6_address
,
148 route_match_ipv6_address_compile
, route_match_ipv6_address_free
};
150 /* ------------------------------------------------------------*/
152 static route_map_result_t
153 route_match_ipv6_address_prefix_list(void *rule
, struct prefix
*prefix
,
154 route_map_object_t type
, void *object
)
156 struct prefix_list
*plist
;
158 if (type
!= RMAP_ISIS
)
161 plist
= prefix_list_lookup(AFI_IP6
, (char *)rule
);
162 if (prefix_list_apply(plist
, prefix
) != PREFIX_DENY
)
168 static void *route_match_ipv6_address_prefix_list_compile(const char *arg
)
170 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
173 static void route_match_ipv6_address_prefix_list_free(void *rule
)
175 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
178 struct route_map_rule_cmd route_match_ipv6_address_prefix_list_cmd
= {
179 "ipv6 address prefix-list", route_match_ipv6_address_prefix_list
,
180 route_match_ipv6_address_prefix_list_compile
,
181 route_match_ipv6_address_prefix_list_free
};
183 /* ------------------------------------------------------------*/
185 static route_map_result_t
route_set_metric(void *rule
, struct prefix
*prefix
,
186 route_map_object_t type
,
190 struct isis_ext_info
*info
;
192 if (type
== RMAP_ISIS
) {
196 info
->metric
= *metric
;
201 static void *route_set_metric_compile(const char *arg
)
203 unsigned long metric
;
207 metric
= strtoul(arg
, &endp
, 10);
208 if (arg
[0] == '\0' || *endp
!= '\0' || metric
> MAX_WIDE_PATH_METRIC
)
211 ret
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(*ret
));
217 static void route_set_metric_free(void *rule
)
219 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
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
};
226 void isis_route_map_init(void)
230 route_map_match_ip_address_hook(generic_match_add
);
231 route_map_no_match_ip_address_hook(generic_match_delete
);
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
);
236 route_map_match_ipv6_address_hook(generic_match_add
);
237 route_map_no_match_ipv6_address_hook(generic_match_delete
);
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
);
242 route_map_set_metric_hook(generic_set_add
);
243 route_map_no_set_metric_hook(generic_set_delete
);
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
);