blob: 074a2deabc634a781f0184edc3cf896a4f95907b [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/*
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. */
43void
paul6c835672004-10-11 11:00:30 +000044ospf_route_map_update (const char *name)
paul718e3742002-12-13 20:15:29 +000045{
paul73ffb252003-04-19 15:49:49 +000046 struct ospf *ospf;
paul718e3742002-12-13 20:15:29 +000047 int type;
48
49 /* If OSPF instatnce does not exist, return right now. */
paul73ffb252003-04-19 15:49:49 +000050 ospf = ospf_lookup ();
51 if (ospf == NULL)
paul718e3742002-12-13 20:15:29 +000052 return;
53
54 /* Update route-map */
55 for (type = 0; type <= ZEBRA_ROUTE_MAX; type++)
56 {
paul73ffb252003-04-19 15:49:49 +000057 if (ROUTEMAP_NAME (ospf, type)
58 && strcmp (ROUTEMAP_NAME (ospf, type), name) == 0)
paul718e3742002-12-13 20:15:29 +000059 {
60 /* Keep old route-map. */
paul73ffb252003-04-19 15:49:49 +000061 struct route_map *old = ROUTEMAP (ospf, type);
paul718e3742002-12-13 20:15:29 +000062
63 /* Update route-map. */
paul73ffb252003-04-19 15:49:49 +000064 ROUTEMAP (ospf, type) =
65 route_map_lookup_by_name (ROUTEMAP_NAME (ospf, type));
paul718e3742002-12-13 20:15:29 +000066
67 /* No update for this distribute type. */
paul73ffb252003-04-19 15:49:49 +000068 if (old == NULL && ROUTEMAP (ospf, type) == NULL)
paul718e3742002-12-13 20:15:29 +000069 continue;
70
paul73ffb252003-04-19 15:49:49 +000071 ospf_distribute_list_update (ospf, type);
paul718e3742002-12-13 20:15:29 +000072 }
73 }
74}
75
76void
paul6c835672004-10-11 11:00:30 +000077ospf_route_map_event (route_map_event_t event, const char *name)
paul718e3742002-12-13 20:15:29 +000078{
paul73ffb252003-04-19 15:49:49 +000079 struct ospf *ospf;
paul718e3742002-12-13 20:15:29 +000080 int type;
81
82 /* If OSPF instatnce does not exist, return right now. */
paul73ffb252003-04-19 15:49:49 +000083 ospf = ospf_lookup ();
84 if (ospf == NULL)
paul718e3742002-12-13 20:15:29 +000085 return;
86
87 /* Update route-map. */
88 for (type = 0; type <= ZEBRA_ROUTE_MAX; type++)
89 {
paul73ffb252003-04-19 15:49:49 +000090 if (ROUTEMAP_NAME (ospf, type) && ROUTEMAP (ospf, type)
91 && !strcmp (ROUTEMAP_NAME (ospf, type), name))
paul718e3742002-12-13 20:15:29 +000092 {
paul73ffb252003-04-19 15:49:49 +000093 ospf_distribute_list_update (ospf, type);
paul718e3742002-12-13 20:15:29 +000094 }
95 }
96}
97
98/* Delete rip route map rule. */
99int
100ospf_route_match_delete (struct vty *vty, struct route_map_index *index,
paul6c835672004-10-11 11:00:30 +0000101 const char *command, const char *arg)
paul718e3742002-12-13 20:15:29 +0000102{
103 int ret;
104
105 ret = route_map_delete_match (index, command, arg);
106 if (ret)
107 {
108 switch (ret)
109 {
110 case RMAP_RULE_MISSING:
111 vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);
112 return CMD_WARNING;
113 break;
114 case RMAP_COMPILE_ERROR:
115 vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);
116 return CMD_WARNING;
117 break;
118 }
119 }
120
121 return CMD_SUCCESS;
122}
123
124int
125ospf_route_match_add (struct vty *vty, struct route_map_index *index,
paul6c835672004-10-11 11:00:30 +0000126 const char *command, const char *arg)
paul718e3742002-12-13 20:15:29 +0000127{
128 int ret;
129
130 ret = route_map_add_match (index, command, arg);
131 if (ret)
132 {
133 switch (ret)
134 {
135 case RMAP_RULE_MISSING:
136 vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);
137 return CMD_WARNING;
138 break;
139 case RMAP_COMPILE_ERROR:
140 vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);
141 return CMD_WARNING;
142 break;
143 }
144 }
145
146 return CMD_SUCCESS;
147}
148
149int
150ospf_route_set_add (struct vty *vty, struct route_map_index *index,
paul6c835672004-10-11 11:00:30 +0000151 const char *command, const char *arg)
paul718e3742002-12-13 20:15:29 +0000152{
153 int ret;
154
155 ret = route_map_add_set (index, command, arg);
156 if (ret)
157 {
158 switch (ret)
159 {
160 case RMAP_RULE_MISSING:
161 vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);
162 return CMD_WARNING;
163 break;
164 case RMAP_COMPILE_ERROR:
165 vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);
166 return CMD_WARNING;
167 break;
168 }
169 }
170
171 return CMD_SUCCESS;
172}
173
174/* Delete rip route map rule. */
175int
176ospf_route_set_delete (struct vty *vty, struct route_map_index *index,
paul6c835672004-10-11 11:00:30 +0000177 const char *command, const char *arg)
paul718e3742002-12-13 20:15:29 +0000178{
179 int ret;
180
181 ret = route_map_delete_set (index, command, arg);
182 if (ret)
183 {
184 switch (ret)
185 {
186 case RMAP_RULE_MISSING:
187 vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);
188 return CMD_WARNING;
189 break;
190 case RMAP_COMPILE_ERROR:
191 vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);
192 return CMD_WARNING;
193 break;
194 }
195 }
196
197 return CMD_SUCCESS;
198}
199
200/* `match ip netxthop ' */
201/* Match function return 1 if match is success else return zero. */
202route_map_result_t
203route_match_ip_nexthop (void *rule, struct prefix *prefix,
204 route_map_object_t type, void *object)
205{
206 struct access_list *alist;
207 struct external_info *ei = object;
208 struct prefix_ipv4 p;
209
210 if (type == RMAP_OSPF)
211 {
212 p.family = AF_INET;
213 p.prefix = ei->nexthop;
214 p.prefixlen = IPV4_MAX_BITLEN;
215
216 alist = access_list_lookup (AFI_IP, (char *) rule);
217 if (alist == NULL)
218 return RMAP_NOMATCH;
219
220 return (access_list_apply (alist, &p) == FILTER_DENY ?
221 RMAP_NOMATCH : RMAP_MATCH);
222 }
223 return RMAP_NOMATCH;
224}
225
226/* Route map `ip next-hop' match statement. `arg' should be
227 access-list name. */
228void *
paul6c835672004-10-11 11:00:30 +0000229route_match_ip_nexthop_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +0000230{
231 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
232}
233
234/* Free route map's compiled `ip address' value. */
235void
236route_match_ip_nexthop_free (void *rule)
237{
238 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
239}
240
241/* Route map commands for metric matching. */
242struct route_map_rule_cmd route_match_ip_nexthop_cmd =
243{
244 "ip next-hop",
245 route_match_ip_nexthop,
246 route_match_ip_nexthop_compile,
247 route_match_ip_nexthop_free
248};
249
250/* `match ip next-hop prefix-list PREFIX_LIST' */
251
252route_map_result_t
253route_match_ip_next_hop_prefix_list (void *rule, struct prefix *prefix,
254 route_map_object_t type, void *object)
255{
256 struct prefix_list *plist;
257 struct external_info *ei = object;
258 struct prefix_ipv4 p;
259
260 if (type == RMAP_OSPF)
261 {
262 p.family = AF_INET;
263 p.prefix = ei->nexthop;
264 p.prefixlen = IPV4_MAX_BITLEN;
265
266 plist = prefix_list_lookup (AFI_IP, (char *) rule);
267 if (plist == NULL)
268 return RMAP_NOMATCH;
269
270 return (prefix_list_apply (plist, &p) == PREFIX_DENY ?
271 RMAP_NOMATCH : RMAP_MATCH);
272 }
273 return RMAP_NOMATCH;
274}
275
276void *
paul6c835672004-10-11 11:00:30 +0000277route_match_ip_next_hop_prefix_list_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +0000278{
279 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
280}
281
282void
283route_match_ip_next_hop_prefix_list_free (void *rule)
284{
285 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
286}
287
288struct route_map_rule_cmd route_match_ip_next_hop_prefix_list_cmd =
289{
290 "ip next-hop prefix-list",
291 route_match_ip_next_hop_prefix_list,
292 route_match_ip_next_hop_prefix_list_compile,
293 route_match_ip_next_hop_prefix_list_free
294};
295
296/* `match ip address IP_ACCESS_LIST' */
297/* Match function should return 1 if match is success else return
298 zero. */
299route_map_result_t
300route_match_ip_address (void *rule, struct prefix *prefix,
301 route_map_object_t type, void *object)
302{
303 struct access_list *alist;
304 /* struct prefix_ipv4 match; */
305
306 if (type == RMAP_OSPF)
307 {
308 alist = access_list_lookup (AFI_IP, (char *) rule);
309 if (alist == NULL)
310 return RMAP_NOMATCH;
311
312 return (access_list_apply (alist, prefix) == FILTER_DENY ?
313 RMAP_NOMATCH : RMAP_MATCH);
314 }
315 return RMAP_NOMATCH;
316}
317
318/* Route map `ip address' match statement. `arg' should be
319 access-list name. */
320void *
paul6c835672004-10-11 11:00:30 +0000321route_match_ip_address_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +0000322{
323 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
324}
325
326/* Free route map's compiled `ip address' value. */
327void
328route_match_ip_address_free (void *rule)
329{
330 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
331}
332
333/* Route map commands for ip address matching. */
334struct route_map_rule_cmd route_match_ip_address_cmd =
335{
336 "ip address",
337 route_match_ip_address,
338 route_match_ip_address_compile,
339 route_match_ip_address_free
340};
341
342/* `match ip address prefix-list PREFIX_LIST' */
343route_map_result_t
344route_match_ip_address_prefix_list (void *rule, struct prefix *prefix,
345 route_map_object_t type, void *object)
346{
347 struct prefix_list *plist;
348
349 if (type == RMAP_OSPF)
350 {
351 plist = prefix_list_lookup (AFI_IP, (char *) rule);
352 if (plist == NULL)
353 return RMAP_NOMATCH;
354
355 return (prefix_list_apply (plist, prefix) == PREFIX_DENY ?
356 RMAP_NOMATCH : RMAP_MATCH);
357 }
358 return RMAP_NOMATCH;
359}
360
361void *
paul6c835672004-10-11 11:00:30 +0000362route_match_ip_address_prefix_list_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +0000363{
364 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
365}
366
367void
368route_match_ip_address_prefix_list_free (void *rule)
369{
370 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
371}
372
373struct route_map_rule_cmd route_match_ip_address_prefix_list_cmd =
374{
375 "ip address prefix-list",
376 route_match_ip_address_prefix_list,
377 route_match_ip_address_prefix_list_compile,
378 route_match_ip_address_prefix_list_free
379};
380
381/* `match interface IFNAME' */
382/* Match function should return 1 if match is success else return
383 zero. */
384route_map_result_t
385route_match_interface (void *rule, struct prefix *prefix,
386 route_map_object_t type, void *object)
387{
388 struct interface *ifp;
389 struct external_info *ei;
390
391 if (type == RMAP_OSPF)
392 {
393 ei = object;
394 ifp = if_lookup_by_name ((char *)rule);
395
396 if (ifp == NULL || ifp->ifindex != ei->ifindex)
397 return RMAP_NOMATCH;
398
399 return RMAP_MATCH;
400 }
401 return RMAP_NOMATCH;
402}
403
404/* Route map `interface' match statement. `arg' should be
405 interface name. */
406void *
paul6c835672004-10-11 11:00:30 +0000407route_match_interface_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +0000408{
409 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
410}
411
412/* Free route map's compiled `interface' value. */
413void
414route_match_interface_free (void *rule)
415{
416 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
417}
418
419/* Route map commands for ip address matching. */
420struct route_map_rule_cmd route_match_interface_cmd =
421{
422 "interface",
423 route_match_interface,
424 route_match_interface_compile,
425 route_match_interface_free
426};
427
428/* `set metric METRIC' */
429/* Set metric to attribute. */
430route_map_result_t
431route_set_metric (void *rule, struct prefix *prefix,
432 route_map_object_t type, void *object)
433{
434 u_int32_t *metric;
435 struct external_info *ei;
436
437 if (type == RMAP_OSPF)
438 {
439 /* Fetch routemap's rule information. */
440 metric = rule;
441 ei = object;
442
443 /* Set metric out value. */
444 ei->route_map_set.metric = *metric;
445 }
446 return RMAP_OKAY;
447}
448
449/* set metric compilation. */
450void *
paul6c835672004-10-11 11:00:30 +0000451route_set_metric_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +0000452{
453 u_int32_t *metric;
454
455 metric = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_int32_t));
456 *metric = atoi (arg);
457
458 if (*metric >= 0)
459 return metric;
460
461 XFREE (MTYPE_ROUTE_MAP_COMPILED, metric);
462 return NULL;
463}
464
465/* Free route map's compiled `set metric' value. */
466void
467route_set_metric_free (void *rule)
468{
469 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
470}
471
472/* Set metric rule structure. */
473struct route_map_rule_cmd route_set_metric_cmd =
474{
475 "metric",
476 route_set_metric,
477 route_set_metric_compile,
478 route_set_metric_free,
479};
480
481/* `set metric-type TYPE' */
482/* Set metric-type to attribute. */
483route_map_result_t
484route_set_metric_type (void *rule, struct prefix *prefix,
485 route_map_object_t type, void *object)
486{
487 u_int32_t *metric_type;
488 struct external_info *ei;
489
490 if (type == RMAP_OSPF)
491 {
492 /* Fetch routemap's rule information. */
493 metric_type = rule;
494 ei = object;
495
496 /* Set metric out value. */
497 ei->route_map_set.metric_type = *metric_type;
498 }
499 return RMAP_OKAY;
500}
501
502/* set metric-type compilation. */
503void *
paul6c835672004-10-11 11:00:30 +0000504route_set_metric_type_compile (const char *arg)
paul718e3742002-12-13 20:15:29 +0000505{
506 u_int32_t *metric_type;
507
508 metric_type = XCALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_int32_t));
509 if (strcmp (arg, "type-1") == 0)
510 *metric_type = EXTERNAL_METRIC_TYPE_1;
511 else if (strcmp (arg, "type-2") == 0)
512 *metric_type = EXTERNAL_METRIC_TYPE_2;
513
514 if (*metric_type == EXTERNAL_METRIC_TYPE_1 ||
515 *metric_type == EXTERNAL_METRIC_TYPE_2)
516 return metric_type;
517
518 XFREE (MTYPE_ROUTE_MAP_COMPILED, metric_type);
519 return NULL;
520}
521
522/* Free route map's compiled `set metric-type' value. */
523void
524route_set_metric_type_free (void *rule)
525{
526 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
527}
528
529/* Set metric rule structure. */
530struct route_map_rule_cmd route_set_metric_type_cmd =
531{
532 "metric-type",
533 route_set_metric_type,
534 route_set_metric_type_compile,
535 route_set_metric_type_free,
536};
537
538DEFUN (match_ip_nexthop,
539 match_ip_nexthop_cmd,
540 "match ip next-hop (<1-199>|<1300-2699>|WORD)",
541 MATCH_STR
542 IP_STR
543 "Match next-hop address of route\n"
544 "IP access-list number\n"
545 "IP access-list number (expanded range)\n"
546 "IP access-list name\n")
547{
548 return ospf_route_match_add (vty, vty->index, "ip next-hop", argv[0]);
549}
550
551DEFUN (no_match_ip_nexthop,
552 no_match_ip_nexthop_cmd,
553 "no match ip next-hop",
554 NO_STR
555 MATCH_STR
556 IP_STR
557 "Match next-hop address of route\n")
558{
559 if (argc == 0)
560 return ospf_route_match_delete (vty, vty->index, "ip next-hop", NULL);
561
562 return ospf_route_match_delete (vty, vty->index, "ip next-hop", argv[0]);
563}
564
565ALIAS (no_match_ip_nexthop,
566 no_match_ip_nexthop_val_cmd,
567 "no match ip next-hop (<1-199>|<1300-2699>|WORD)",
568 NO_STR
569 MATCH_STR
570 IP_STR
571 "Match next-hop address of route\n"
572 "IP access-list number\n"
573 "IP access-list number (expanded range)\n"
574 "IP access-list name\n")
575
576DEFUN (match_ip_next_hop_prefix_list,
577 match_ip_next_hop_prefix_list_cmd,
578 "match ip next-hop prefix-list WORD",
579 MATCH_STR
580 IP_STR
581 "Match next-hop address of route\n"
582 "Match entries of prefix-lists\n"
583 "IP prefix-list name\n")
584{
585 return ospf_route_match_add (vty, vty->index, "ip next-hop prefix-list",
586 argv[0]);
587}
588
589DEFUN (no_match_ip_next_hop_prefix_list,
590 no_match_ip_next_hop_prefix_list_cmd,
591 "no match ip next-hop prefix-list",
592 NO_STR
593 MATCH_STR
594 IP_STR
595 "Match next-hop address of route\n"
596 "Match entries of prefix-lists\n")
597{
598 if (argc == 0)
599 return ospf_route_match_delete (vty, vty->index, "ip next-hop prefix-list",
600 NULL);
601 return ospf_route_match_delete (vty, vty->index, "ip next-hop prefix-list",
602 argv[0]);
603}
604
605ALIAS (no_match_ip_next_hop_prefix_list,
606 no_match_ip_next_hop_prefix_list_val_cmd,
607 "no match ip next-hop prefix-list WORD",
608 NO_STR
609 MATCH_STR
610 IP_STR
611 "Match next-hop address of route\n"
612 "Match entries of prefix-lists\n"
613 "IP prefix-list name\n")
614
615DEFUN (match_ip_address,
616 match_ip_address_cmd,
617 "match ip address (<1-199>|<1300-2699>|WORD)",
618 MATCH_STR
619 IP_STR
620 "Match address of route\n"
621 "IP access-list number\n"
622 "IP access-list number (expanded range)\n"
623 "IP access-list name\n")
624{
625 return ospf_route_match_add (vty, vty->index, "ip address", argv[0]);
626}
627
628DEFUN (no_match_ip_address,
629 no_match_ip_address_cmd,
630 "no match ip address",
631 NO_STR
632 MATCH_STR
633 IP_STR
634 "Match address of route\n")
635{
636 if (argc == 0)
637 return ospf_route_match_delete (vty, vty->index, "ip address", NULL);
638
639 return ospf_route_match_delete (vty, vty->index, "ip address", argv[0]);
640}
641
642ALIAS (no_match_ip_address,
643 no_match_ip_address_val_cmd,
644 "no match ip address (<1-199>|<1300-2699>|WORD)",
645 NO_STR
646 MATCH_STR
647 IP_STR
648 "Match address of route\n"
649 "IP access-list number\n"
650 "IP access-list number (expanded range)\n"
651 "IP access-list name\n")
652
653DEFUN (match_ip_address_prefix_list,
654 match_ip_address_prefix_list_cmd,
655 "match ip address prefix-list WORD",
656 MATCH_STR
657 IP_STR
658 "Match address of route\n"
659 "Match entries of prefix-lists\n"
660 "IP prefix-list name\n")
661{
662 return ospf_route_match_add (vty, vty->index, "ip address prefix-list",
663 argv[0]);
664}
665
666DEFUN (no_match_ip_address_prefix_list,
667 no_match_ip_address_prefix_list_cmd,
668 "no match ip address prefix-list",
669 NO_STR
670 MATCH_STR
671 IP_STR
672 "Match address of route\n"
673 "Match entries of prefix-lists\n")
674{
675 if (argc == 0)
676 return ospf_route_match_delete (vty, vty->index, "ip address prefix-list",
677 NULL);
678 return ospf_route_match_delete (vty, vty->index, "ip address prefix-list",
679 argv[0]);
680}
681
682ALIAS (no_match_ip_address_prefix_list,
683 no_match_ip_address_prefix_list_val_cmd,
684 "no match ip address prefix-list WORD",
685 NO_STR
686 MATCH_STR
687 IP_STR
688 "Match address of route\n"
689 "Match entries of prefix-lists\n"
690 "IP prefix-list name\n")
691
692DEFUN (match_interface,
693 match_interface_cmd,
694 "match interface WORD",
695 MATCH_STR
696 "Match first hop interface of route\n"
697 "Interface name\n")
698{
699 return ospf_route_match_add (vty, vty->index, "interface", argv[0]);
700}
701
702DEFUN (no_match_interface,
703 no_match_interface_cmd,
704 "no match interface",
705 NO_STR
706 MATCH_STR
707 "Match first hop interface of route\n")
708{
709 if (argc == 0)
710 return ospf_route_match_delete (vty, vty->index, "interface", NULL);
711
712 return ospf_route_match_delete (vty, vty->index, "interface", argv[0]);
713}
714
715ALIAS (no_match_interface,
716 no_match_interface_val_cmd,
717 "no match interface WORD",
718 NO_STR
719 MATCH_STR
720 "Match first hop interface of route\n"
721 "Interface name\n")
722
723DEFUN (set_metric,
724 set_metric_cmd,
725 "set metric <0-4294967295>",
726 SET_STR
727 "Metric value for destination routing protocol\n"
728 "Metric value\n")
729{
730 return ospf_route_set_add (vty, vty->index, "metric", argv[0]);
731}
732
733DEFUN (no_set_metric,
734 no_set_metric_cmd,
735 "no set metric",
736 NO_STR
737 SET_STR
738 "Metric value for destination routing protocol\n")
739{
740 if (argc == 0)
741 return ospf_route_set_delete (vty, vty->index, "metric", NULL);
742
743 return ospf_route_set_delete (vty, vty->index, "metric", argv[0]);
744}
745
746ALIAS (no_set_metric,
747 no_set_metric_val_cmd,
748 "no set metric <0-4294967295>",
749 NO_STR
750 SET_STR
751 "Metric value for destination routing protocol\n"
752 "Metric value\n")
753
754DEFUN (set_metric_type,
755 set_metric_type_cmd,
756 "set metric-type (type-1|type-2)",
757 SET_STR
758 "Type of metric for destination routing protocol\n"
paul73ffb252003-04-19 15:49:49 +0000759 "OSPF[6] external type 1 metric\n"
760 "OSPF[6] external type 2 metric\n")
paul718e3742002-12-13 20:15:29 +0000761{
762 if (strcmp (argv[0], "1") == 0)
hassoeb1ce602004-10-08 08:17:22 +0000763 return ospf_route_set_add (vty, vty->index, "metric-type",
764 (char *) "type-1");
paul718e3742002-12-13 20:15:29 +0000765 if (strcmp (argv[0], "2") == 0)
hassoeb1ce602004-10-08 08:17:22 +0000766 return ospf_route_set_add (vty, vty->index, "metric-type",
767 (char *) "type-2");
paul718e3742002-12-13 20:15:29 +0000768
769 return ospf_route_set_add (vty, vty->index, "metric-type", argv[0]);
770}
771
772DEFUN (no_set_metric_type,
773 no_set_metric_type_cmd,
774 "no set metric-type",
775 NO_STR
776 SET_STR
777 "Type of metric for destination routing protocol\n")
778{
779 if (argc == 0)
780 return ospf_route_set_delete (vty, vty->index, "metric-type", NULL);
781
782 return ospf_route_set_delete (vty, vty->index, "metric-type", argv[0]);
783}
784
785ALIAS (no_set_metric_type,
786 no_set_metric_type_val_cmd,
787 "no set metric-type (type-1|type-2)",
788 NO_STR
789 SET_STR
790 "Type of metric for destination routing protocol\n"
paul73ffb252003-04-19 15:49:49 +0000791 "OSPF[6] external type 1 metric\n"
792 "OSPF[6] external type 2 metric\n")
paul718e3742002-12-13 20:15:29 +0000793
794/* Route-map init */
795void
796ospf_route_map_init (void)
797{
798 route_map_init ();
799 route_map_init_vty ();
800
801 route_map_add_hook (ospf_route_map_update);
802 route_map_delete_hook (ospf_route_map_update);
803 route_map_event_hook (ospf_route_map_event);
804
805 route_map_install_match (&route_match_ip_nexthop_cmd);
806 route_map_install_match (&route_match_ip_next_hop_prefix_list_cmd);
807 route_map_install_match (&route_match_ip_address_cmd);
808 route_map_install_match (&route_match_ip_address_prefix_list_cmd);
809 route_map_install_match (&route_match_interface_cmd);
810
811 route_map_install_set (&route_set_metric_cmd);
812 route_map_install_set (&route_set_metric_type_cmd);
813
814 install_element (RMAP_NODE, &match_ip_nexthop_cmd);
815 install_element (RMAP_NODE, &no_match_ip_nexthop_cmd);
816 install_element (RMAP_NODE, &no_match_ip_nexthop_val_cmd);
817 install_element (RMAP_NODE, &match_ip_next_hop_prefix_list_cmd);
818 install_element (RMAP_NODE, &no_match_ip_next_hop_prefix_list_cmd);
819 install_element (RMAP_NODE, &no_match_ip_next_hop_prefix_list_val_cmd);
820 install_element (RMAP_NODE, &match_ip_address_cmd);
821 install_element (RMAP_NODE, &no_match_ip_address_cmd);
822 install_element (RMAP_NODE, &no_match_ip_address_val_cmd);
823 install_element (RMAP_NODE, &match_ip_address_prefix_list_cmd);
824 install_element (RMAP_NODE, &no_match_ip_address_prefix_list_cmd);
825 install_element (RMAP_NODE, &no_match_ip_address_prefix_list_val_cmd);
826 install_element (RMAP_NODE, &match_interface_cmd);
827 install_element (RMAP_NODE, &no_match_interface_cmd);
828 install_element (RMAP_NODE, &no_match_interface_val_cmd);
829
830 install_element (RMAP_NODE, &set_metric_cmd);
831 install_element (RMAP_NODE, &no_set_metric_cmd);
832 install_element (RMAP_NODE, &no_set_metric_val_cmd);
833 install_element (RMAP_NODE, &set_metric_type_cmd);
834 install_element (RMAP_NODE, &no_set_metric_type_cmd);
835 install_element (RMAP_NODE, &no_set_metric_type_val_cmd);
836}