]> git.proxmox.com Git - mirror_frr.git/blame - ospfd/ospf_routemap.c
redhat: Fix missing packages in requirements section of README
[mirror_frr.git] / ospfd / ospf_routemap.c
CommitLineData
718e3744 1/*
2 * Route map function of ospfd.
3 * Copyright (C) 2000 IP Infusion Inc.
4 *
5 * Written by Toshiaki Takada.
6 *
7 * This file is part of GNU Zebra.
8 *
9 * GNU Zebra is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2, or (at your option) any
12 * later version.
13 *
14 * GNU Zebra is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with GNU Zebra; see the file COPYING. If not, write to the Free
21 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22 * 02111-1307, USA.
23 */
24
25#include <zebra.h>
26
27#include "memory.h"
28#include "prefix.h"
29#include "table.h"
30#include "routemap.h"
31#include "command.h"
32#include "log.h"
33#include "plist.h"
34
35#include "ospfd/ospfd.h"
36#include "ospfd/ospf_asbr.h"
37#include "ospfd/ospf_interface.h"
38#include "ospfd/ospf_lsa.h"
39#include "ospfd/ospf_route.h"
40#include "ospfd/ospf_zebra.h"
41
42/* Hook function for updating route_map assignment. */
4dadc291 43static void
6c835671 44ospf_route_map_update (const char *name)
718e3744 45{
73ffb25b 46 struct ospf *ospf;
718e3744 47 int type;
48
49 /* If OSPF instatnce does not exist, return right now. */
73ffb25b 50 ospf = ospf_lookup ();
51 if (ospf == NULL)
718e3744 52 return;
53
54 /* Update route-map */
55 for (type = 0; type <= ZEBRA_ROUTE_MAX; type++)
56 {
7c8ff89e
DS
57 struct list *red_list;
58 struct listnode *node;
59 struct ospf_redist *red;
60
61 red_list = ospf->redist[type];
62 if (!red_list)
63 continue;
64
65 for (ALL_LIST_ELEMENTS_RO(red_list, node, red))
66 {
67 if (ROUTEMAP_NAME (red)
68 && strcmp (ROUTEMAP_NAME (red), name) == 0)
69 {
70 /* Keep old route-map. */
71 struct route_map *old = ROUTEMAP (red);
72
73 /* Update route-map. */
74 ROUTEMAP (red) =
75 route_map_lookup_by_name (ROUTEMAP_NAME (red));
76
77 /* No update for this distribute type. */
78 if (old == NULL && ROUTEMAP (red) == NULL)
79 continue;
80
81 ospf_distribute_list_update (ospf, type, red->instance);
82 }
83 }
718e3744 84 }
85}
86
4dadc291 87static void
6c835671 88ospf_route_map_event (route_map_event_t event, const char *name)
718e3744 89{
73ffb25b 90 struct ospf *ospf;
718e3744 91 int type;
92
93 /* If OSPF instatnce does not exist, return right now. */
73ffb25b 94 ospf = ospf_lookup ();
95 if (ospf == NULL)
718e3744 96 return;
97
718e3744 98 for (type = 0; type <= ZEBRA_ROUTE_MAX; type++)
99 {
7c8ff89e
DS
100 struct list *red_list;
101 struct listnode *node;
102 struct ospf_redist *red;
103
104 red_list = ospf->redist[type];
105 if (!red_list)
106 continue;
107
108 for (ALL_LIST_ELEMENTS_RO(red_list, node, red))
718e3744 109 {
7c8ff89e
DS
110 if (ROUTEMAP_NAME (red) && ROUTEMAP (red)
111 && !strcmp (ROUTEMAP_NAME (red), name))
112 {
113 ospf_distribute_list_update (ospf, type, red->instance);
114 }
718e3744 115 }
116 }
117}
118
119/* Delete rip route map rule. */
4dadc291 120static int
718e3744 121ospf_route_match_delete (struct vty *vty, struct route_map_index *index,
6c835671 122 const char *command, const char *arg)
718e3744 123{
124 int ret;
125
126 ret = route_map_delete_match (index, command, arg);
127 if (ret)
128 {
129 switch (ret)
130 {
131 case RMAP_RULE_MISSING:
5e3edbf5 132 vty_out (vty, "%% OSPF Can't find rule.%s", VTY_NEWLINE);
718e3744 133 return CMD_WARNING;
718e3744 134 case RMAP_COMPILE_ERROR:
5e3edbf5 135 vty_out (vty, "%% OSPF Argument is malformed.%s", VTY_NEWLINE);
718e3744 136 return CMD_WARNING;
718e3744 137 }
138 }
139
140 return CMD_SUCCESS;
141}
142
4dadc291 143static int
718e3744 144ospf_route_match_add (struct vty *vty, struct route_map_index *index,
6c835671 145 const char *command, const char *arg)
718e3744 146{
147 int ret;
148
149 ret = route_map_add_match (index, command, arg);
150 if (ret)
151 {
152 switch (ret)
153 {
154 case RMAP_RULE_MISSING:
5e3edbf5 155 vty_out (vty, "%% OSPF Can't find rule.%s", VTY_NEWLINE);
718e3744 156 return CMD_WARNING;
718e3744 157 case RMAP_COMPILE_ERROR:
5e3edbf5 158 vty_out (vty, "%% OSPF Argument is malformed.%s", VTY_NEWLINE);
718e3744 159 return CMD_WARNING;
718e3744 160 }
161 }
162
163 return CMD_SUCCESS;
164}
165
4dadc291 166static int
718e3744 167ospf_route_set_add (struct vty *vty, struct route_map_index *index,
6c835671 168 const char *command, const char *arg)
718e3744 169{
170 int ret;
171
172 ret = route_map_add_set (index, command, arg);
173 if (ret)
174 {
175 switch (ret)
176 {
177 case RMAP_RULE_MISSING:
5e3edbf5 178 vty_out (vty, "%% OSPF Can't find rule.%s", VTY_NEWLINE);
718e3744 179 return CMD_WARNING;
718e3744 180 case RMAP_COMPILE_ERROR:
5e3edbf5 181 vty_out (vty, "%% OSPF Argument is malformed.%s", VTY_NEWLINE);
718e3744 182 return CMD_WARNING;
718e3744 183 }
184 }
185
186 return CMD_SUCCESS;
187}
188
189/* Delete rip route map rule. */
4dadc291 190static int
718e3744 191ospf_route_set_delete (struct vty *vty, struct route_map_index *index,
6c835671 192 const char *command, const char *arg)
718e3744 193{
194 int ret;
195
196 ret = route_map_delete_set (index, command, arg);
197 if (ret)
198 {
199 switch (ret)
200 {
201 case RMAP_RULE_MISSING:
5e3edbf5 202 vty_out (vty, "%% OSPF Can't find rule.%s", VTY_NEWLINE);
718e3744 203 return CMD_WARNING;
718e3744 204 case RMAP_COMPILE_ERROR:
5e3edbf5 205 vty_out (vty, "%% OSPF Argument is malformed.%s", VTY_NEWLINE);
718e3744 206 return CMD_WARNING;
718e3744 207 }
208 }
209
210 return CMD_SUCCESS;
211}
212
213/* `match ip netxthop ' */
214/* Match function return 1 if match is success else return zero. */
4dadc291 215static route_map_result_t
718e3744 216route_match_ip_nexthop (void *rule, struct prefix *prefix,
217 route_map_object_t type, void *object)
218{
219 struct access_list *alist;
220 struct external_info *ei = object;
221 struct prefix_ipv4 p;
222
223 if (type == RMAP_OSPF)
224 {
225 p.family = AF_INET;
226 p.prefix = ei->nexthop;
227 p.prefixlen = IPV4_MAX_BITLEN;
228
229 alist = access_list_lookup (AFI_IP, (char *) rule);
230 if (alist == NULL)
231 return RMAP_NOMATCH;
232
233 return (access_list_apply (alist, &p) == FILTER_DENY ?
234 RMAP_NOMATCH : RMAP_MATCH);
235 }
236 return RMAP_NOMATCH;
237}
238
239/* Route map `ip next-hop' match statement. `arg' should be
240 access-list name. */
4dadc291 241static void *
6c835671 242route_match_ip_nexthop_compile (const char *arg)
718e3744 243{
244 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
245}
246
247/* Free route map's compiled `ip address' value. */
4dadc291 248static void
718e3744 249route_match_ip_nexthop_free (void *rule)
250{
251 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
252}
253
254/* Route map commands for metric matching. */
255struct route_map_rule_cmd route_match_ip_nexthop_cmd =
256{
257 "ip next-hop",
258 route_match_ip_nexthop,
259 route_match_ip_nexthop_compile,
260 route_match_ip_nexthop_free
261};
262
263/* `match ip next-hop prefix-list PREFIX_LIST' */
264
4dadc291 265static route_map_result_t
718e3744 266route_match_ip_next_hop_prefix_list (void *rule, struct prefix *prefix,
267 route_map_object_t type, void *object)
268{
269 struct prefix_list *plist;
270 struct external_info *ei = object;
271 struct prefix_ipv4 p;
272
273 if (type == RMAP_OSPF)
274 {
275 p.family = AF_INET;
276 p.prefix = ei->nexthop;
277 p.prefixlen = IPV4_MAX_BITLEN;
278
279 plist = prefix_list_lookup (AFI_IP, (char *) rule);
280 if (plist == NULL)
281 return RMAP_NOMATCH;
282
283 return (prefix_list_apply (plist, &p) == PREFIX_DENY ?
284 RMAP_NOMATCH : RMAP_MATCH);
285 }
286 return RMAP_NOMATCH;
287}
288
4dadc291 289static void *
6c835671 290route_match_ip_next_hop_prefix_list_compile (const char *arg)
718e3744 291{
292 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
293}
294
4dadc291 295static void
718e3744 296route_match_ip_next_hop_prefix_list_free (void *rule)
297{
298 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
299}
300
301struct route_map_rule_cmd route_match_ip_next_hop_prefix_list_cmd =
302{
303 "ip next-hop prefix-list",
304 route_match_ip_next_hop_prefix_list,
305 route_match_ip_next_hop_prefix_list_compile,
306 route_match_ip_next_hop_prefix_list_free
307};
308
309/* `match ip address IP_ACCESS_LIST' */
310/* Match function should return 1 if match is success else return
311 zero. */
4dadc291 312static route_map_result_t
718e3744 313route_match_ip_address (void *rule, struct prefix *prefix,
314 route_map_object_t type, void *object)
315{
316 struct access_list *alist;
317 /* struct prefix_ipv4 match; */
318
319 if (type == RMAP_OSPF)
320 {
321 alist = access_list_lookup (AFI_IP, (char *) rule);
322 if (alist == NULL)
323 return RMAP_NOMATCH;
324
325 return (access_list_apply (alist, prefix) == FILTER_DENY ?
326 RMAP_NOMATCH : RMAP_MATCH);
327 }
328 return RMAP_NOMATCH;
329}
330
331/* Route map `ip address' match statement. `arg' should be
332 access-list name. */
4dadc291 333static void *
6c835671 334route_match_ip_address_compile (const char *arg)
718e3744 335{
336 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
337}
338
339/* Free route map's compiled `ip address' value. */
4dadc291 340static void
718e3744 341route_match_ip_address_free (void *rule)
342{
343 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
344}
345
346/* Route map commands for ip address matching. */
347struct route_map_rule_cmd route_match_ip_address_cmd =
348{
349 "ip address",
350 route_match_ip_address,
351 route_match_ip_address_compile,
352 route_match_ip_address_free
353};
354
355/* `match ip address prefix-list PREFIX_LIST' */
4dadc291 356static route_map_result_t
718e3744 357route_match_ip_address_prefix_list (void *rule, struct prefix *prefix,
358 route_map_object_t type, void *object)
359{
360 struct prefix_list *plist;
361
362 if (type == RMAP_OSPF)
363 {
364 plist = prefix_list_lookup (AFI_IP, (char *) rule);
365 if (plist == NULL)
366 return RMAP_NOMATCH;
367
368 return (prefix_list_apply (plist, prefix) == PREFIX_DENY ?
369 RMAP_NOMATCH : RMAP_MATCH);
370 }
371 return RMAP_NOMATCH;
372}
373
4dadc291 374static void *
6c835671 375route_match_ip_address_prefix_list_compile (const char *arg)
718e3744 376{
377 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
378}
379
4dadc291 380static void
718e3744 381route_match_ip_address_prefix_list_free (void *rule)
382{
383 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
384}
385
386struct route_map_rule_cmd route_match_ip_address_prefix_list_cmd =
387{
388 "ip address prefix-list",
389 route_match_ip_address_prefix_list,
390 route_match_ip_address_prefix_list_compile,
391 route_match_ip_address_prefix_list_free
392};
393
394/* `match interface IFNAME' */
395/* Match function should return 1 if match is success else return
396 zero. */
4dadc291 397static route_map_result_t
718e3744 398route_match_interface (void *rule, struct prefix *prefix,
399 route_map_object_t type, void *object)
400{
401 struct interface *ifp;
402 struct external_info *ei;
403
404 if (type == RMAP_OSPF)
405 {
406 ei = object;
407 ifp = if_lookup_by_name ((char *)rule);
408
409 if (ifp == NULL || ifp->ifindex != ei->ifindex)
410 return RMAP_NOMATCH;
411
412 return RMAP_MATCH;
413 }
414 return RMAP_NOMATCH;
415}
416
417/* Route map `interface' match statement. `arg' should be
418 interface name. */
4dadc291 419static void *
6c835671 420route_match_interface_compile (const char *arg)
718e3744 421{
422 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
423}
424
425/* Free route map's compiled `interface' value. */
4dadc291 426static void
718e3744 427route_match_interface_free (void *rule)
428{
429 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
430}
431
432/* Route map commands for ip address matching. */
433struct route_map_rule_cmd route_match_interface_cmd =
434{
435 "interface",
436 route_match_interface,
437 route_match_interface_compile,
438 route_match_interface_free
439};
440
0d9551dc
DS
441/* Match function return 1 if match is success else return zero. */
442static route_map_result_t
443route_match_tag (void *rule, struct prefix *prefix,
444 route_map_object_t type, void *object)
445{
dc9ffce8 446 route_tag_t *tag;
0d9551dc
DS
447 struct external_info *ei;
448
449 if (type == RMAP_OSPF)
450 {
451 tag = rule;
452 ei = object;
453
454 return ((ei->tag == *tag)? RMAP_MATCH : RMAP_NOMATCH);
455 }
456
457 return RMAP_NOMATCH;
458}
459
0d9551dc 460/* Route map commands for tag matching. */
dc9ffce8 461static struct route_map_rule_cmd route_match_tag_cmd =
0d9551dc
DS
462{
463 "tag",
464 route_match_tag,
dc9ffce8
CF
465 route_map_rule_tag_compile,
466 route_map_rule_tag_free,
0d9551dc
DS
467};
468
469
718e3744 470/* `set metric METRIC' */
471/* Set metric to attribute. */
4dadc291 472static route_map_result_t
718e3744 473route_set_metric (void *rule, struct prefix *prefix,
474 route_map_object_t type, void *object)
475{
476 u_int32_t *metric;
477 struct external_info *ei;
478
479 if (type == RMAP_OSPF)
480 {
481 /* Fetch routemap's rule information. */
482 metric = rule;
483 ei = object;
484
485 /* Set metric out value. */
486 ei->route_map_set.metric = *metric;
487 }
488 return RMAP_OKAY;
489}
490
491/* set metric compilation. */
4dadc291 492static void *
6c835671 493route_set_metric_compile (const char *arg)
718e3744 494{
495 u_int32_t *metric;
fbc043a8 496 int32_t ret;
718e3744 497
5e3edbf5
DS
498 /* OSPF doesn't support the +/- in
499 set metric <+/-metric> check
500 Ignore the +/- component */
501 if (! all_digit (arg))
ed2eb093
DS
502 {
503 if ((strncmp (arg, "+", 1) == 0 || strncmp (arg, "-", 1) == 0) &&
504 all_digit (arg+1))
505 {
506 zlog_warn ("OSPF does not support 'set metric +/-'");
507 arg++;
508 }
509 else
510 {
511 return NULL;
512 }
513 }
718e3744 514 metric = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_int32_t));
fbc043a8 515 ret = atoi (arg);
718e3744 516
fbc043a8
AC
517 if (ret >= 0)
518 {
519 *metric = (u_int32_t)ret;
520 return metric;
521 }
718e3744 522
523 XFREE (MTYPE_ROUTE_MAP_COMPILED, metric);
524 return NULL;
525}
526
527/* Free route map's compiled `set metric' value. */
4dadc291 528static void
718e3744 529route_set_metric_free (void *rule)
530{
531 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
532}
533
534/* Set metric rule structure. */
535struct route_map_rule_cmd route_set_metric_cmd =
536{
537 "metric",
538 route_set_metric,
539 route_set_metric_compile,
540 route_set_metric_free,
541};
542
543/* `set metric-type TYPE' */
544/* Set metric-type to attribute. */
4dadc291 545static route_map_result_t
718e3744 546route_set_metric_type (void *rule, struct prefix *prefix,
547 route_map_object_t type, void *object)
548{
549 u_int32_t *metric_type;
550 struct external_info *ei;
551
552 if (type == RMAP_OSPF)
553 {
554 /* Fetch routemap's rule information. */
555 metric_type = rule;
556 ei = object;
557
558 /* Set metric out value. */
559 ei->route_map_set.metric_type = *metric_type;
560 }
561 return RMAP_OKAY;
562}
563
564/* set metric-type compilation. */
4dadc291 565static void *
6c835671 566route_set_metric_type_compile (const char *arg)
718e3744 567{
568 u_int32_t *metric_type;
569
570 metric_type = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_int32_t));
571 if (strcmp (arg, "type-1") == 0)
572 *metric_type = EXTERNAL_METRIC_TYPE_1;
573 else if (strcmp (arg, "type-2") == 0)
574 *metric_type = EXTERNAL_METRIC_TYPE_2;
575
576 if (*metric_type == EXTERNAL_METRIC_TYPE_1 ||
577 *metric_type == EXTERNAL_METRIC_TYPE_2)
578 return metric_type;
579
580 XFREE (MTYPE_ROUTE_MAP_COMPILED, metric_type);
581 return NULL;
582}
583
584/* Free route map's compiled `set metric-type' value. */
4dadc291 585static void
718e3744 586route_set_metric_type_free (void *rule)
587{
588 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
589}
590
591/* Set metric rule structure. */
592struct route_map_rule_cmd route_set_metric_type_cmd =
593{
594 "metric-type",
595 route_set_metric_type,
596 route_set_metric_type_compile,
597 route_set_metric_type_free,
598};
599
0d9551dc
DS
600static route_map_result_t
601route_set_tag (void *rule, struct prefix *prefix,
602 route_map_object_t type, void *object)
603{
dc9ffce8 604 route_tag_t *tag;
0d9551dc
DS
605 struct external_info *ei;
606
607 if (type == RMAP_OSPF)
608 {
609 tag = rule;
610 ei = object;
611
612 /* Set tag value */
613 ei->tag=*tag;
614 }
615
616 return RMAP_OKAY;
617}
618
0d9551dc 619/* Route map commands for tag set. */
dc9ffce8 620static struct route_map_rule_cmd route_set_tag_cmd =
0d9551dc
DS
621{
622 "tag",
623 route_set_tag,
dc9ffce8
CF
624 route_map_rule_tag_compile,
625 route_map_rule_tag_free,
0d9551dc
DS
626};
627
718e3744 628DEFUN (match_ip_nexthop,
629 match_ip_nexthop_cmd,
630 "match ip next-hop (<1-199>|<1300-2699>|WORD)",
631 MATCH_STR
632 IP_STR
633 "Match next-hop address of route\n"
634 "IP access-list number\n"
635 "IP access-list number (expanded range)\n"
636 "IP access-list name\n")
637{
638 return ospf_route_match_add (vty, vty->index, "ip next-hop", argv[0]);
639}
640
641DEFUN (no_match_ip_nexthop,
642 no_match_ip_nexthop_cmd,
643 "no match ip next-hop",
644 NO_STR
645 MATCH_STR
646 IP_STR
647 "Match next-hop address of route\n")
648{
649 if (argc == 0)
650 return ospf_route_match_delete (vty, vty->index, "ip next-hop", NULL);
651
652 return ospf_route_match_delete (vty, vty->index, "ip next-hop", argv[0]);
653}
654
655ALIAS (no_match_ip_nexthop,
656 no_match_ip_nexthop_val_cmd,
657 "no match ip next-hop (<1-199>|<1300-2699>|WORD)",
658 NO_STR
659 MATCH_STR
660 IP_STR
661 "Match next-hop address of route\n"
662 "IP access-list number\n"
663 "IP access-list number (expanded range)\n"
664 "IP access-list name\n")
665
666DEFUN (match_ip_next_hop_prefix_list,
667 match_ip_next_hop_prefix_list_cmd,
668 "match ip next-hop prefix-list WORD",
669 MATCH_STR
670 IP_STR
671 "Match next-hop address of route\n"
672 "Match entries of prefix-lists\n"
673 "IP prefix-list name\n")
674{
675 return ospf_route_match_add (vty, vty->index, "ip next-hop prefix-list",
676 argv[0]);
677}
678
679DEFUN (no_match_ip_next_hop_prefix_list,
680 no_match_ip_next_hop_prefix_list_cmd,
681 "no match ip next-hop prefix-list",
682 NO_STR
683 MATCH_STR
684 IP_STR
685 "Match next-hop address of route\n"
686 "Match entries of prefix-lists\n")
687{
688 if (argc == 0)
689 return ospf_route_match_delete (vty, vty->index, "ip next-hop prefix-list",
690 NULL);
691 return ospf_route_match_delete (vty, vty->index, "ip next-hop prefix-list",
692 argv[0]);
693}
694
695ALIAS (no_match_ip_next_hop_prefix_list,
696 no_match_ip_next_hop_prefix_list_val_cmd,
697 "no match ip next-hop prefix-list WORD",
698 NO_STR
699 MATCH_STR
700 IP_STR
701 "Match next-hop address of route\n"
702 "Match entries of prefix-lists\n"
703 "IP prefix-list name\n")
704
705DEFUN (match_ip_address,
706 match_ip_address_cmd,
707 "match ip address (<1-199>|<1300-2699>|WORD)",
708 MATCH_STR
709 IP_STR
710 "Match address of route\n"
711 "IP access-list number\n"
712 "IP access-list number (expanded range)\n"
713 "IP access-list name\n")
714{
715 return ospf_route_match_add (vty, vty->index, "ip address", argv[0]);
716}
717
718DEFUN (no_match_ip_address,
719 no_match_ip_address_cmd,
720 "no match ip address",
721 NO_STR
722 MATCH_STR
723 IP_STR
724 "Match address of route\n")
725{
726 if (argc == 0)
727 return ospf_route_match_delete (vty, vty->index, "ip address", NULL);
728
729 return ospf_route_match_delete (vty, vty->index, "ip address", argv[0]);
730}
731
732ALIAS (no_match_ip_address,
733 no_match_ip_address_val_cmd,
734 "no match ip address (<1-199>|<1300-2699>|WORD)",
735 NO_STR
736 MATCH_STR
737 IP_STR
738 "Match address of route\n"
739 "IP access-list number\n"
740 "IP access-list number (expanded range)\n"
741 "IP access-list name\n")
742
743DEFUN (match_ip_address_prefix_list,
744 match_ip_address_prefix_list_cmd,
745 "match ip address prefix-list WORD",
746 MATCH_STR
747 IP_STR
748 "Match address of route\n"
749 "Match entries of prefix-lists\n"
750 "IP prefix-list name\n")
751{
752 return ospf_route_match_add (vty, vty->index, "ip address prefix-list",
753 argv[0]);
754}
755
756DEFUN (no_match_ip_address_prefix_list,
757 no_match_ip_address_prefix_list_cmd,
758 "no match ip address prefix-list",
759 NO_STR
760 MATCH_STR
761 IP_STR
762 "Match address of route\n"
763 "Match entries of prefix-lists\n")
764{
765 if (argc == 0)
766 return ospf_route_match_delete (vty, vty->index, "ip address prefix-list",
767 NULL);
768 return ospf_route_match_delete (vty, vty->index, "ip address prefix-list",
769 argv[0]);
770}
771
772ALIAS (no_match_ip_address_prefix_list,
773 no_match_ip_address_prefix_list_val_cmd,
774 "no match ip address prefix-list WORD",
775 NO_STR
776 MATCH_STR
777 IP_STR
778 "Match address of route\n"
779 "Match entries of prefix-lists\n"
780 "IP prefix-list name\n")
781
782DEFUN (match_interface,
783 match_interface_cmd,
784 "match interface WORD",
785 MATCH_STR
786 "Match first hop interface of route\n"
787 "Interface name\n")
788{
789 return ospf_route_match_add (vty, vty->index, "interface", argv[0]);
790}
791
792DEFUN (no_match_interface,
793 no_match_interface_cmd,
794 "no match interface",
795 NO_STR
796 MATCH_STR
797 "Match first hop interface of route\n")
798{
799 if (argc == 0)
800 return ospf_route_match_delete (vty, vty->index, "interface", NULL);
801
802 return ospf_route_match_delete (vty, vty->index, "interface", argv[0]);
803}
804
805ALIAS (no_match_interface,
806 no_match_interface_val_cmd,
807 "no match interface WORD",
808 NO_STR
809 MATCH_STR
810 "Match first hop interface of route\n"
811 "Interface name\n")
812
0d9551dc
DS
813DEFUN (match_tag,
814 match_tag_cmd,
dc9ffce8 815 "match tag <1-4294967295>",
0d9551dc
DS
816 MATCH_STR
817 "Match tag of route\n"
818 "Tag value\n")
819{
820 return ospf_route_match_add (vty, vty->index, "tag", argv[0]);
821}
822
823DEFUN (no_match_tag,
824 no_match_tag_cmd,
825 "no match tag",
826 NO_STR
827 MATCH_STR
828 "Match tag of route\n")
829{
830 if (argc == 0)
831 return ospf_route_match_delete (vty, vty->index, "tag", NULL);
832
833 return ospf_route_match_delete (vty, vty->index, "tag", argv[0]);
834}
835
836ALIAS (no_match_tag,
837 no_match_tag_val_cmd,
dc9ffce8 838 "no match tag <1-4294967295>",
0d9551dc
DS
839 NO_STR
840 MATCH_STR
841 "Match tag of route\n"
842 "Tag value\n")
843
718e3744 844DEFUN (set_metric,
845 set_metric_cmd,
846 "set metric <0-4294967295>",
847 SET_STR
848 "Metric value for destination routing protocol\n"
849 "Metric value\n")
850{
851 return ospf_route_set_add (vty, vty->index, "metric", argv[0]);
852}
853
854DEFUN (no_set_metric,
855 no_set_metric_cmd,
856 "no set metric",
857 NO_STR
858 SET_STR
859 "Metric value for destination routing protocol\n")
860{
861 if (argc == 0)
862 return ospf_route_set_delete (vty, vty->index, "metric", NULL);
863
864 return ospf_route_set_delete (vty, vty->index, "metric", argv[0]);
865}
866
867ALIAS (no_set_metric,
868 no_set_metric_val_cmd,
869 "no set metric <0-4294967295>",
870 NO_STR
871 SET_STR
872 "Metric value for destination routing protocol\n"
873 "Metric value\n")
874
875DEFUN (set_metric_type,
876 set_metric_type_cmd,
877 "set metric-type (type-1|type-2)",
878 SET_STR
879 "Type of metric for destination routing protocol\n"
73ffb25b 880 "OSPF[6] external type 1 metric\n"
881 "OSPF[6] external type 2 metric\n")
718e3744 882{
883 if (strcmp (argv[0], "1") == 0)
4dadc291 884 return ospf_route_set_add (vty, vty->index, "metric-type", "type-1");
718e3744 885 if (strcmp (argv[0], "2") == 0)
4dadc291 886 return ospf_route_set_add (vty, vty->index, "metric-type", "type-2");
718e3744 887
888 return ospf_route_set_add (vty, vty->index, "metric-type", argv[0]);
889}
890
891DEFUN (no_set_metric_type,
892 no_set_metric_type_cmd,
893 "no set metric-type",
894 NO_STR
895 SET_STR
896 "Type of metric for destination routing protocol\n")
897{
898 if (argc == 0)
899 return ospf_route_set_delete (vty, vty->index, "metric-type", NULL);
900
901 return ospf_route_set_delete (vty, vty->index, "metric-type", argv[0]);
902}
903
904ALIAS (no_set_metric_type,
905 no_set_metric_type_val_cmd,
906 "no set metric-type (type-1|type-2)",
907 NO_STR
908 SET_STR
909 "Type of metric for destination routing protocol\n"
73ffb25b 910 "OSPF[6] external type 1 metric\n"
911 "OSPF[6] external type 2 metric\n")
718e3744 912
0d9551dc
DS
913DEFUN (set_tag,
914 set_tag_cmd,
dc9ffce8 915 "set tag <1-4294967295>",
0d9551dc
DS
916 SET_STR
917 "Tag value for routing protocol\n"
918 "Tag value\n")
919{
920 return ospf_route_set_add (vty, vty->index, "tag", argv[0]);
921}
922
923DEFUN (no_set_tag,
924 no_set_tag_cmd,
925 "no set tag",
926 NO_STR
927 SET_STR
928 "Tag value for routing protocol\n")
929{
930 if (argc == 0)
931 ospf_route_set_delete(vty, vty->index, "tag", NULL);
932
933 return ospf_route_set_delete (vty, vty->index, "tag", argv[0]);
934}
935
936ALIAS (no_set_tag,
937 no_set_tag_val_cmd,
dc9ffce8 938 "no set tag <1-4294967295>",
0d9551dc
DS
939 NO_STR
940 SET_STR
941 "Tag value for routing protocol\n"
942 "Tag value\n")
943
718e3744 944/* Route-map init */
945void
946ospf_route_map_init (void)
947{
948 route_map_init ();
718e3744 949
950 route_map_add_hook (ospf_route_map_update);
951 route_map_delete_hook (ospf_route_map_update);
952 route_map_event_hook (ospf_route_map_event);
953
954 route_map_install_match (&route_match_ip_nexthop_cmd);
955 route_map_install_match (&route_match_ip_next_hop_prefix_list_cmd);
956 route_map_install_match (&route_match_ip_address_cmd);
957 route_map_install_match (&route_match_ip_address_prefix_list_cmd);
958 route_map_install_match (&route_match_interface_cmd);
0d9551dc 959 route_map_install_match (&route_match_tag_cmd);
718e3744 960
961 route_map_install_set (&route_set_metric_cmd);
962 route_map_install_set (&route_set_metric_type_cmd);
0d9551dc 963 route_map_install_set (&route_set_tag_cmd);
718e3744 964
965 install_element (RMAP_NODE, &match_ip_nexthop_cmd);
966 install_element (RMAP_NODE, &no_match_ip_nexthop_cmd);
967 install_element (RMAP_NODE, &no_match_ip_nexthop_val_cmd);
968 install_element (RMAP_NODE, &match_ip_next_hop_prefix_list_cmd);
969 install_element (RMAP_NODE, &no_match_ip_next_hop_prefix_list_cmd);
970 install_element (RMAP_NODE, &no_match_ip_next_hop_prefix_list_val_cmd);
971 install_element (RMAP_NODE, &match_ip_address_cmd);
972 install_element (RMAP_NODE, &no_match_ip_address_cmd);
973 install_element (RMAP_NODE, &no_match_ip_address_val_cmd);
974 install_element (RMAP_NODE, &match_ip_address_prefix_list_cmd);
975 install_element (RMAP_NODE, &no_match_ip_address_prefix_list_cmd);
976 install_element (RMAP_NODE, &no_match_ip_address_prefix_list_val_cmd);
977 install_element (RMAP_NODE, &match_interface_cmd);
978 install_element (RMAP_NODE, &no_match_interface_cmd);
979 install_element (RMAP_NODE, &no_match_interface_val_cmd);
0d9551dc
DS
980 install_element (RMAP_NODE, &match_tag_cmd);
981 install_element (RMAP_NODE, &no_match_tag_cmd);
982 install_element (RMAP_NODE, &no_match_tag_val_cmd);
718e3744 983
984 install_element (RMAP_NODE, &set_metric_cmd);
985 install_element (RMAP_NODE, &no_set_metric_cmd);
986 install_element (RMAP_NODE, &no_set_metric_val_cmd);
987 install_element (RMAP_NODE, &set_metric_type_cmd);
988 install_element (RMAP_NODE, &no_set_metric_type_cmd);
989 install_element (RMAP_NODE, &no_set_metric_type_val_cmd);
0d9551dc
DS
990 install_element (RMAP_NODE, &set_tag_cmd);
991 install_element (RMAP_NODE, &no_set_tag_cmd);
992 install_element (RMAP_NODE, &no_set_tag_val_cmd);
718e3744 993}