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
54 route_match_ip_address(void *rule
, struct prefix
*prefix
,
55 route_map_object_t type
, void *object
)
57 struct access_list
*alist
;
59 if (type
!= RMAP_ISIS
)
62 alist
= access_list_lookup(AFI_IP
, (char*)rule
);
63 if (access_list_apply(alist
, prefix
) != FILTER_DENY
)
70 route_match_ip_address_compile(const char *arg
)
72 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
76 route_match_ip_address_free(void *rule
)
78 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
81 static struct route_map_rule_cmd route_match_ip_address_cmd
=
84 route_match_ip_address
,
85 route_match_ip_address_compile
,
86 route_match_ip_address_free
89 /* ------------------------------------------------------------*/
91 static route_map_result_t
92 route_match_ip_address_prefix_list(void *rule
, struct prefix
*prefix
,
93 route_map_object_t type
, void *object
)
95 struct prefix_list
*plist
;
97 if (type
!= RMAP_ISIS
)
100 plist
= prefix_list_lookup(AFI_IP
, (char*)rule
);
101 if (prefix_list_apply(plist
, prefix
) != PREFIX_DENY
)
108 route_match_ip_address_prefix_list_compile(const char *arg
)
110 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
114 route_match_ip_address_prefix_list_free (void *rule
)
116 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
119 struct route_map_rule_cmd route_match_ip_address_prefix_list_cmd
=
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
127 /* ------------------------------------------------------------*/
129 static route_map_result_t
130 route_match_ipv6_address(void *rule
, struct prefix
*prefix
,
131 route_map_object_t type
, void *object
)
133 struct access_list
*alist
;
135 if (type
!= RMAP_ISIS
)
138 alist
= access_list_lookup(AFI_IP6
, (char*)rule
);
139 if (access_list_apply(alist
, prefix
) != FILTER_DENY
)
146 route_match_ipv6_address_compile(const char *arg
)
148 return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED
, arg
);
152 route_match_ipv6_address_free(void *rule
)
154 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
157 static struct route_map_rule_cmd route_match_ipv6_address_cmd
=
160 route_match_ipv6_address
,
161 route_match_ipv6_address_compile
,
162 route_match_ipv6_address_free
165 /* ------------------------------------------------------------*/
167 static route_map_result_t
168 route_match_ipv6_address_prefix_list(void *rule
, struct prefix
*prefix
,
169 route_map_object_t type
, void *object
)
171 struct prefix_list
*plist
;
173 if (type
!= RMAP_ISIS
)
176 plist
= prefix_list_lookup(AFI_IP6
, (char*)rule
);
177 if (prefix_list_apply(plist
, prefix
) != PREFIX_DENY
)
184 route_match_ipv6_address_prefix_list_compile(const char *arg
)
186 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
190 route_match_ipv6_address_prefix_list_free (void *rule
)
192 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
195 struct route_map_rule_cmd route_match_ipv6_address_prefix_list_cmd
=
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
203 /* ------------------------------------------------------------*/
205 static route_map_result_t
206 route_set_metric(void *rule
, struct prefix
*prefix
,
207 route_map_object_t type
, void *object
)
210 struct isis_ext_info
*info
;
212 if (type
== RMAP_ISIS
)
217 info
->metric
= *metric
;
223 route_set_metric_compile(const char *arg
)
225 unsigned long metric
;
229 metric
= strtoul(arg
, &endp
, 10);
230 if (arg
[0] == '\0' || *endp
!= '\0' || metric
> MAX_WIDE_PATH_METRIC
)
233 ret
= XCALLOC(MTYPE_ROUTE_MAP_COMPILED
, sizeof(ret
));
240 route_set_metric_free(void *rule
)
242 XFREE(MTYPE_ROUTE_MAP_COMPILED
, rule
);
245 static struct route_map_rule_cmd route_set_metric_cmd
=
249 route_set_metric_compile
,
250 route_set_metric_free
253 /* ------------------------------------------------------------*/
256 isis_route_match_add(struct vty
*vty
, struct route_map_index
*index
,
257 const char *command
, const char *arg
)
261 ret
= route_map_add_match (index
, command
, arg
);
266 case RMAP_RULE_MISSING
:
267 vty_out (vty
, "%% Can't find rule.%s", VTY_NEWLINE
);
269 case RMAP_COMPILE_ERROR
:
270 vty_out (vty
, "%% Argument is malformed.%s", VTY_NEWLINE
);
278 isis_route_match_delete(struct vty
*vty
, struct route_map_index
*index
,
279 const char *command
, const char *arg
)
283 ret
= route_map_delete_match (index
, command
, arg
);
288 case RMAP_RULE_MISSING
:
289 vty_out (vty
, "%% Can't find rule.%s", VTY_NEWLINE
);
291 case RMAP_COMPILE_ERROR
:
292 vty_out (vty
, "%% Argument is malformed.%s", VTY_NEWLINE
);
300 isis_route_set_add(struct vty
*vty
, struct route_map_index
*index
,
301 const char *command
, const char *arg
)
305 ret
= route_map_add_set(index
, command
, arg
);
310 case RMAP_RULE_MISSING
:
311 vty_out (vty
, "%% Can't find rule.%s", VTY_NEWLINE
);
313 case RMAP_COMPILE_ERROR
:
314 vty_out (vty
, "%% Argument is malformed.%s", VTY_NEWLINE
);
323 isis_route_set_delete (struct vty
*vty
, struct route_map_index
*index
,
324 const char *command
, const char *arg
)
328 ret
= route_map_delete_set (index
, command
, arg
);
333 case RMAP_RULE_MISSING
:
334 vty_out (vty
, "%% Can't find rule.%s", VTY_NEWLINE
);
336 case RMAP_COMPILE_ERROR
:
337 vty_out (vty
, "%% Argument is malformed.%s", VTY_NEWLINE
);
345 /* ------------------------------------------------------------*/
347 DEFUN (match_ip_address
,
348 match_ip_address_cmd
,
349 "match ip address (<1-199>|<1300-2699>|WORD)",
352 "Match address of route\n"
353 "IP access-list number\n"
354 "IP access-list number (expanded range)\n"
355 "IP Access-list name\n")
357 return isis_route_match_add(vty
, vty
->index
, "ip address", argv
[0]->arg
);
360 DEFUN (no_match_ip_address
,
361 no_match_ip_address_val_cmd
,
362 "no match ip address (<1-199>|<1300-2699>|WORD)",
366 "Match address of route\n"
367 "IP access-list number\n"
368 "IP access-list number (expanded range)\n"
369 "IP Access-list name\n")
372 return isis_route_match_delete(vty
, vty
->index
, "ip address", NULL
);
373 return isis_route_match_delete(vty
, vty
->index
, "ip address", argv
[0]->arg
);
376 ALIAS (no_match_ip_address
,
377 no_match_ip_address_cmd
,
378 "no match ip address",
382 "Match address of route\n")
384 /* ------------------------------------------------------------*/
386 DEFUN (match_ip_address_prefix_list
,
387 match_ip_address_prefix_list_cmd
,
388 "match ip address prefix-list WORD",
391 "Match address of route\n"
392 "Match entries of prefix-lists\n"
393 "IP prefix-list name\n")
395 return isis_route_match_add(vty
, vty
->index
, "ip address prefix-list", argv
[0]->arg
);
398 DEFUN (no_match_ip_address_prefix_list
,
399 no_match_ip_address_prefix_list_cmd
,
400 "no match ip address prefix-list",
404 "Match address of route\n"
405 "Match entries of prefix-lists\n")
408 return isis_route_match_delete (vty
, vty
->index
, "ip address prefix-list", NULL
);
409 return isis_route_match_delete (vty
, vty
->index
, "ip address prefix-list", argv
[0]->arg
);
412 ALIAS (no_match_ip_address_prefix_list
,
413 no_match_ip_address_prefix_list_val_cmd
,
414 "no match ip address prefix-list WORD",
418 "Match address of route\n"
419 "Match entries of prefix-lists\n"
420 "IP prefix-list name\n")
422 /* ------------------------------------------------------------*/
424 DEFUN (match_ipv6_address
,
425 match_ipv6_address_cmd
,
426 "match ipv6 address WORD",
429 "Match IPv6 address of route\n"
430 "IPv6 access-list name\n")
432 return isis_route_match_add(vty
, vty
->index
, "ipv6 address", argv
[0]->arg
);
435 DEFUN (no_match_ipv6_address
,
436 no_match_ipv6_address_val_cmd
,
437 "no match ipv6 address WORD",
441 "Match IPv6 address of route\n"
442 "IPv6 access-list name\n")
445 return isis_route_match_delete(vty
, vty
->index
, "ipv6 address", NULL
);
446 return isis_route_match_delete(vty
, vty
->index
, "ipv6 address", argv
[0]->arg
);
449 ALIAS (no_match_ipv6_address
,
450 no_match_ipv6_address_cmd
,
451 "no match ipv6 address",
455 "Match IPv6 address of route\n")
457 /* ------------------------------------------------------------*/
459 DEFUN (match_ipv6_address_prefix_list
,
460 match_ipv6_address_prefix_list_cmd
,
461 "match ipv6 address prefix-list WORD",
464 "Match address of route\n"
465 "Match entries of prefix-lists\n"
466 "IP prefix-list name\n")
468 return isis_route_match_add(vty
, vty
->index
, "ipv6 address prefix-list", argv
[0]->arg
);
471 DEFUN (no_match_ipv6_address_prefix_list
,
472 no_match_ipv6_address_prefix_list_cmd
,
473 "no match ipv6 address prefix-list",
477 "Match address of route\n"
478 "Match entries of prefix-lists\n")
481 return isis_route_match_delete (vty
, vty
->index
, "ipv6 address prefix-list", NULL
);
482 return isis_route_match_delete (vty
, vty
->index
, "ipv6 address prefix-list", argv
[0]->arg
);
485 ALIAS (no_match_ipv6_address_prefix_list
,
486 no_match_ipv6_address_prefix_list_val_cmd
,
487 "no match ipv6 address prefix-list WORD",
491 "Match address of route\n"
492 "Match entries of prefix-lists\n"
493 "IP prefix-list name\n")
495 /* ------------------------------------------------------------*/
497 /* set metric already exists e.g. in the ospf routemap. vtysh doesn't cope well with different
498 * commands at the same node, therefore add set metric with the same 32-bit range as ospf and
499 * verify that the input is a valid isis metric */
502 "set metric <0-4294967295>",
504 "Metric vale for destination routing protocol\n"
507 return isis_route_set_add(vty
, vty
->index
, "metric", argv
[0]->arg
);
510 DEFUN (no_set_metric
,
511 no_set_metric_val_cmd
,
512 "no set metric <0-4294967295>",
515 "Metric value for destination routing protocol\n"
519 return isis_route_set_delete(vty
, vty
->index
, "metric", NULL
);
520 return isis_route_set_delete(vty
, vty
->index
, "metric", argv
[0]->arg
);
523 ALIAS (no_set_metric
,
528 "Metric vale for destination routing protocol\n");
531 isis_route_map_init(void)
534 route_map_init_vty();
536 route_map_install_match(&route_match_ip_address_cmd
);
537 install_element(RMAP_NODE
, &match_ip_address_cmd
);
538 install_element(RMAP_NODE
, &no_match_ip_address_val_cmd
);
539 install_element(RMAP_NODE
, &no_match_ip_address_cmd
);
541 route_map_install_match(&route_match_ip_address_prefix_list_cmd
);
542 install_element(RMAP_NODE
, &match_ip_address_prefix_list_cmd
);
543 install_element(RMAP_NODE
, &no_match_ip_address_prefix_list_val_cmd
);
544 install_element(RMAP_NODE
, &no_match_ip_address_prefix_list_cmd
);
546 route_map_install_match(&route_match_ipv6_address_cmd
);
547 install_element(RMAP_NODE
, &match_ipv6_address_cmd
);
548 install_element(RMAP_NODE
, &no_match_ipv6_address_val_cmd
);
549 install_element(RMAP_NODE
, &no_match_ipv6_address_cmd
);
551 route_map_install_match(&route_match_ipv6_address_prefix_list_cmd
);
552 install_element(RMAP_NODE
, &match_ipv6_address_prefix_list_cmd
);
553 install_element(RMAP_NODE
, &no_match_ipv6_address_prefix_list_val_cmd
);
554 install_element(RMAP_NODE
, &no_match_ipv6_address_prefix_list_cmd
);
556 route_map_install_set(&route_set_metric_cmd
);
557 install_element(RMAP_NODE
, &set_metric_cmd
);
558 install_element(RMAP_NODE
, &no_set_metric_val_cmd
);
559 install_element(RMAP_NODE
, &no_set_metric_cmd
);