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