2
* Copyright (C) 1999 Kunihiro Ishiguro
4
* This file is part of GNU Zebra.
6
* GNU Zebra 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
8
* Free Software Foundation; either version 2, or (at your option) any
11
* GNU Zebra is distributed in the hope that it will be useful, but
12
* WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
* General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with GNU Zebra; see the file COPYING. If not, write to the Free
18
* Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
29
#include "sockunion.h"
31
#include "ripngd/ripngd.h"
33
struct rip_metric_modifier
47
ripng_route_match_add (struct vty *vty, struct route_map_index *index,
48
char *command, char *arg)
52
ret = route_map_add_match (index, command, arg);
57
case RMAP_RULE_MISSING:
58
vty_out (vty, "Can't find rule.%s", VTY_NEWLINE);
61
case RMAP_COMPILE_ERROR:
62
vty_out (vty, "Argument is malformed.%s", VTY_NEWLINE);
71
ripng_route_match_delete (struct vty *vty, struct route_map_index *index,
72
char *command, char *arg)
76
ret = route_map_delete_match (index, command, arg);
81
case RMAP_RULE_MISSING:
82
vty_out (vty, "Can't find rule.%s", VTY_NEWLINE);
85
case RMAP_COMPILE_ERROR:
86
vty_out (vty, "Argument is malformed.%s", VTY_NEWLINE);
95
ripng_route_set_add (struct vty *vty, struct route_map_index *index,
96
char *command, char *arg)
100
ret = route_map_add_set (index, command, arg);
105
case RMAP_RULE_MISSING:
106
vty_out (vty, "Can't find rule.%s", VTY_NEWLINE);
109
case RMAP_COMPILE_ERROR:
110
vty_out (vty, "Argument is malformed.%s", VTY_NEWLINE);
119
ripng_route_set_delete (struct vty *vty, struct route_map_index *index,
120
char *command, char *arg)
124
ret = route_map_delete_set (index, command, arg);
129
case RMAP_RULE_MISSING:
130
vty_out (vty, "Can't find rule.%s", VTY_NEWLINE);
133
case RMAP_COMPILE_ERROR:
134
vty_out (vty, "Argument is malformed.%s", VTY_NEWLINE);
142
/* `match metric METRIC' */
143
/* Match function return 1 if match is success else return zero. */
145
route_match_metric (void *rule, struct prefix *prefix,
146
route_map_object_t type, void *object)
149
struct ripng_info *rinfo;
151
if (type == RMAP_RIPNG)
156
if (rinfo->metric == *metric)
164
/* Route map `match metric' match statement. `arg' is METRIC value */
166
route_match_metric_compile (char *arg)
170
metric = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_int32_t));
171
*metric = atoi (arg);
176
XFREE (MTYPE_ROUTE_MAP_COMPILED, metric);
180
/* Free route map's compiled `match metric' value. */
182
route_match_metric_free (void *rule)
184
XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
187
/* Route map commands for metric matching. */
188
struct route_map_rule_cmd route_match_metric_cmd =
192
route_match_metric_compile,
193
route_match_metric_free
196
/* `match interface IFNAME' */
197
/* Match function return 1 if match is success else return zero. */
199
route_match_interface (void *rule, struct prefix *prefix,
200
route_map_object_t type, void *object)
202
struct ripng_info *rinfo;
203
struct interface *ifp;
206
if (type == RMAP_RIPNG)
209
ifp = if_lookup_by_name(ifname);
216
if (rinfo->ifindex == ifp->ifindex)
224
/* Route map `match interface' match statement. `arg' is IFNAME value */
226
route_match_interface_compile (char *arg)
228
return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
232
route_match_interface_free (void *rule)
234
XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
237
struct route_map_rule_cmd route_match_interface_cmd =
240
route_match_interface,
241
route_match_interface_compile,
242
route_match_interface_free
245
/* `match tag TAG' */
246
/* Match function return 1 if match is success else return zero. */
248
route_match_tag (void *rule, struct prefix *prefix,
249
route_map_object_t type, void *object)
252
struct ripng_info *rinfo;
254
if (type == RMAP_RIPNG)
259
/* The information stored by rinfo is host ordered. */
260
if (rinfo->tag == *tag)
268
/* Route map `match tag' match statement. `arg' is TAG value */
270
route_match_tag_compile (char *arg)
274
tag = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_short));
280
/* Free route map's compiled `match tag' value. */
282
route_match_tag_free (void *rule)
284
XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
287
/* Route map commands for tag matching. */
288
struct route_map_rule_cmd route_match_tag_cmd =
292
route_match_tag_compile,
296
/* `set metric METRIC' */
298
/* Set metric to attribute. */
300
route_set_metric (void *rule, struct prefix *prefix,
301
route_map_object_t type, void *object)
303
if (type == RMAP_RIPNG)
305
struct rip_metric_modifier *mod;
306
struct ripng_info *rinfo;
311
if (mod->type == metric_increment)
312
rinfo->metric_out += mod->metric;
313
else if (mod->type == metric_decrement)
314
rinfo->metric_out-= mod->metric;
315
else if (mod->type == metric_absolute)
316
rinfo->metric_out = mod->metric;
318
if (rinfo->metric_out < 1)
319
rinfo->metric_out = 1;
320
if (rinfo->metric_out > RIPNG_METRIC_INFINITY)
321
rinfo->metric_out = RIPNG_METRIC_INFINITY;
323
rinfo->metric_set = 1;
328
/* set metric compilation. */
330
route_set_metric_compile (char *arg)
337
struct rip_metric_modifier *mod;
345
/* Examine first character. */
348
type = metric_increment;
351
else if (arg[0] == '-')
353
type = metric_decrement;
357
type = metric_absolute;
359
/* Check beginning with digit string. */
360
if (*pnt < '0' || *pnt > '9')
363
/* Convert string to integer. */
364
metric = strtol (pnt, &endptr, 10);
366
if (metric == LONG_MAX || *endptr != '\0')
368
/* Commented out by Hasso Tepper, to avoid problems in vtysh. */
369
/* if (metric < 0 || metric > RIPNG_METRIC_INFINITY) */
373
mod = XMALLOC (MTYPE_ROUTE_MAP_COMPILED,
374
sizeof (struct rip_metric_modifier));
376
mod->metric = metric;
381
/* Free route map's compiled `set metric' value. */
383
route_set_metric_free (void *rule)
385
XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
388
struct route_map_rule_cmd route_set_metric_cmd =
392
route_set_metric_compile,
393
route_set_metric_free,
396
/* `set ipv6 next-hop local IP_ADDRESS' */
398
/* Set nexthop to object. ojbect must be pointer to struct attr. */
400
route_set_ipv6_nexthop_local (void *rule, struct prefix *prefix,
401
route_map_object_t type, void *object)
403
struct in6_addr *address;
404
struct ripng_info *rinfo;
406
if(type == RMAP_RIPNG)
408
/* Fetch routemap's rule information. */
412
/* Set next hop value. */
413
rinfo->nexthop_out = *address;
419
/* Route map `ipv6 nexthop local' compile function. Given string is converted
420
to struct in6_addr structure. */
422
route_set_ipv6_nexthop_local_compile (char *arg)
425
struct in6_addr *address;
427
address = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (struct in_addr));
429
ret = inet_pton (AF_INET6, arg, address);
433
XFREE (MTYPE_ROUTE_MAP_COMPILED, address);
440
/* Free route map's compiled `ipv6 nexthop local' value. */
442
route_set_ipv6_nexthop_local_free (void *rule)
444
XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
447
/* Route map commands for ipv6 nexthop local set. */
448
struct route_map_rule_cmd route_set_ipv6_nexthop_local_cmd =
450
"ipv6 next-hop local",
451
route_set_ipv6_nexthop_local,
452
route_set_ipv6_nexthop_local_compile,
453
route_set_ipv6_nexthop_local_free
458
/* Set tag to object. ojbect must be pointer to struct attr. */
460
route_set_tag (void *rule, struct prefix *prefix,
461
route_map_object_t type, void *object)
464
struct ripng_info *rinfo;
466
if(type == RMAP_RIPNG)
468
/* Fetch routemap's rule information. */
472
/* Set next hop value. */
473
rinfo->tag_out = *tag;
479
/* Route map `tag' compile function. Given string is converted
482
route_set_tag_compile (char *arg)
486
tag = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_short));
492
/* Free route map's compiled `ip nexthop' value. */
494
route_set_tag_free (void *rule)
496
XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
499
/* Route map commands for tag set. */
500
struct route_map_rule_cmd route_set_tag_cmd =
504
route_set_tag_compile,
508
#define MATCH_STR "Match values from routing table\n"
509
#define SET_STR "Set values in destination routing protocol\n"
513
"match metric <0-4294967295>",
515
"Match metric of route\n"
518
return ripng_route_match_add (vty, vty->index, "metric", argv[0]);
521
DEFUN (no_match_metric,
526
"Match metric of route\n")
529
return ripng_route_match_delete (vty, vty->index, "metric", NULL);
531
return ripng_route_match_delete (vty, vty->index, "metric", argv[0]);
534
ALIAS (no_match_metric,
535
no_match_metric_val_cmd,
536
"no match metric <0-4294967295>",
539
"Match metric of route\n"
542
DEFUN (match_interface,
544
"match interface WORD",
546
"Match first hop interface of route\n"
549
return ripng_route_match_add (vty, vty->index, "interface", argv[0]);
552
DEFUN (no_match_interface,
553
no_match_interface_cmd,
554
"no match interface",
557
"Match first hop interface of route\n")
560
return ripng_route_match_delete (vty, vty->index, "interface", NULL);
562
return ripng_route_match_delete (vty, vty->index, "interface", argv[0]);
565
ALIAS (no_match_interface,
566
no_match_interface_val_cmd,
567
"no match interface WORD",
570
"Match first hop interface of route\n"
575
"match tag <0-65535>",
577
"Match tag of route\n"
580
return ripng_route_match_add (vty, vty->index, "tag", argv[0]);
588
"Match tag of route\n")
591
return ripng_route_match_delete (vty, vty->index, "tag", NULL);
593
return ripng_route_match_delete (vty, vty->index, "tag", argv[0]);
597
no_match_tag_val_cmd,
598
"no match tag <0-65535>",
601
"Match tag of route\n"
608
"set metric <0-4294967295>",
610
"Metric value for destination routing protocol\n"
613
return ripng_route_set_add (vty, vty->index, "metric", argv[0]);
616
DEFUN (no_set_metric,
621
"Metric value for destination routing protocol\n")
624
return ripng_route_set_delete (vty, vty->index, "metric", NULL);
626
return ripng_route_set_delete (vty, vty->index, "metric", argv[0]);
629
ALIAS (no_set_metric,
630
no_set_metric_val_cmd,
631
"no set metric <0-4294967295>",
634
"Metric value for destination routing protocol\n"
637
DEFUN (set_ipv6_nexthop_local,
638
set_ipv6_nexthop_local_cmd,
639
"set ipv6 next-hop local X:X::X:X",
642
"IPv6 next-hop address\n"
643
"IPv6 local address\n"
644
"IPv6 address of next hop\n")
649
ret = str2sockunion (argv[0], &su);
652
vty_out (vty, "%% Malformed next-hop local address%s", VTY_NEWLINE);
656
return ripng_route_set_add (vty, vty->index, "ipv6 next-hop local", argv[0]);
659
DEFUN (no_set_ipv6_nexthop_local,
660
no_set_ipv6_nexthop_local_cmd,
661
"no set ipv6 next-hop local",
665
"IPv6 next-hop address\n"
666
"IPv6 local address\n")
669
return ripng_route_set_delete (vty, vty->index, "ipv6 next-hop local", NULL);
671
return ripng_route_set_delete (vty, vty->index, "ipv6 next-hop local", argv[0]);
674
ALIAS (no_set_ipv6_nexthop_local,
675
no_set_ipv6_nexthop_local_val_cmd,
676
"no set ipv6 next-hop local X:X::X:X",
680
"IPv6 next-hop address\n"
681
"IPv6 local address\n"
682
"IPv6 address of next hop\n")
688
"Tag value for routing protocol\n"
691
return ripng_route_set_add (vty, vty->index, "tag", argv[0]);
699
"Tag value for routing protocol\n")
702
return ripng_route_set_delete (vty, vty->index, "tag", NULL);
704
return ripng_route_set_delete (vty, vty->index, "tag", argv[0]);
709
"no set tag <0-65535>",
712
"Tag value for routing protocol\n"
716
ripng_route_map_reset ()
723
ripng_route_map_init ()
726
route_map_init_vty ();
728
route_map_install_match (&route_match_metric_cmd);
729
route_map_install_match (&route_match_interface_cmd);
730
route_map_install_match (&route_match_tag_cmd);
732
route_map_install_set (&route_set_metric_cmd);
733
route_map_install_set (&route_set_ipv6_nexthop_local_cmd);
734
route_map_install_set (&route_set_tag_cmd);
736
install_element (RMAP_NODE, &match_metric_cmd);
737
install_element (RMAP_NODE, &no_match_metric_cmd);
738
install_element (RMAP_NODE, &no_match_metric_val_cmd);
739
install_element (RMAP_NODE, &match_interface_cmd);
740
install_element (RMAP_NODE, &no_match_interface_cmd);
741
install_element (RMAP_NODE, &no_match_interface_val_cmd);
742
install_element (RMAP_NODE, &match_tag_cmd);
743
install_element (RMAP_NODE, &no_match_tag_cmd);
744
install_element (RMAP_NODE, &no_match_tag_val_cmd);
746
install_element (RMAP_NODE, &set_metric_cmd);
747
install_element (RMAP_NODE, &no_set_metric_cmd);
748
install_element (RMAP_NODE, &no_set_metric_val_cmd);
749
install_element (RMAP_NODE, &set_ipv6_nexthop_local_cmd);
750
install_element (RMAP_NODE, &no_set_ipv6_nexthop_local_cmd);
751
install_element (RMAP_NODE, &no_set_ipv6_nexthop_local_val_cmd);
752
install_element (RMAP_NODE, &set_tag_cmd);
753
install_element (RMAP_NODE, &no_set_tag_cmd);
754
install_element (RMAP_NODE, &no_set_tag_val_cmd);