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
30 #include "ripngd/ripngd.h"
33 /* `match interface IFNAME' */
35 route_match_interface (void *rule
, struct prefix
*prefix
,
36 route_map_object_t type
, void *object
)
38 struct ripng_info
*rinfo
;
39 struct interface
*ifp
;
42 if (type
== ROUTE_MAP_RIPNG
)
45 ifp
= if_lookup_by_name(ifname
);
52 if (rinfo
->ifindex
== ifp
->ifindex
)
61 route_match_interface_compile (char *arg
)
63 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED
, arg
);
67 route_match_interface_free (void *rule
)
69 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
72 struct route_map_rule_cmd route_match_interface_cmd
=
75 route_match_interface
,
76 route_match_interface_compile
,
77 route_match_interface_free
81 struct rip_metric_modifier
94 route_set_metric (void *rule
, struct prefix
*prefix
,
95 route_map_object_t type
, void *object
)
97 if (type
== RMAP_RIPNG
)
99 struct rip_metric_modifier
*mod
;
100 struct ripng_info
*rinfo
;
105 if (mod
->type
== metric_increment
)
106 rinfo
->metric
+= mod
->metric
;
107 else if (mod
->type
== metric_decrement
)
108 rinfo
->metric
-= mod
->metric
;
109 else if (mod
->type
== metric_absolute
)
110 rinfo
->metric
= mod
->metric
;
112 if (rinfo
->metric
< 1)
114 if (rinfo
->metric
> RIPNG_METRIC_INFINITY
)
115 rinfo
->metric
= RIPNG_METRIC_INFINITY
;
117 rinfo
->metric_set
= 1;
123 route_set_metric_compile (char *arg
)
130 struct rip_metric_modifier
*mod
;
138 /* Examine first character. */
141 type
= metric_increment
;
144 else if (arg
[0] == '-')
146 type
= metric_decrement
;
150 type
= metric_absolute
;
152 /* Check beginning with digit string. */
153 if (*pnt
< '0' || *pnt
> '9')
156 /* Convert string to integer. */
157 metric
= strtol (pnt
, &endptr
, 10);
159 if (metric
== LONG_MAX
|| *endptr
!= '\0')
161 /* Commented out by Hasso Tepper, to avoid problems in vtysh. */
162 /* if (metric < 0 || metric > RIPNG_METRIC_INFINITY) */
166 mod
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
,
167 sizeof (struct rip_metric_modifier
));
169 mod
->metric
= metric
;
175 route_set_metric_free (void *rule
)
177 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
180 struct route_map_rule_cmd route_set_metric_cmd
=
184 route_set_metric_compile
,
185 route_set_metric_free
,
189 ripng_route_match_add (struct vty
*vty
, struct route_map_index
*index
,
190 char *command
, char *arg
)
194 ret
= route_map_add_match (index
, command
, arg
);
199 case RMAP_RULE_MISSING
:
200 vty_out (vty
, "Can't find rule.%s", VTY_NEWLINE
);
203 case RMAP_COMPILE_ERROR
:
204 vty_out (vty
, "Argument is malformed.%s", VTY_NEWLINE
);
213 ripng_route_match_delete (struct vty
*vty
, struct route_map_index
*index
,
214 char *command
, char *arg
)
218 ret
= route_map_delete_match (index
, command
, arg
);
223 case RMAP_RULE_MISSING
:
224 vty_out (vty
, "Can't find rule.%s", VTY_NEWLINE
);
227 case RMAP_COMPILE_ERROR
:
228 vty_out (vty
, "Argument is malformed.%s", VTY_NEWLINE
);
237 ripng_route_set_add (struct vty
*vty
, struct route_map_index
*index
,
238 char *command
, char *arg
)
242 ret
= route_map_add_set (index
, command
, arg
);
247 case RMAP_RULE_MISSING
:
248 vty_out (vty
, "Can't find rule.%s", VTY_NEWLINE
);
251 case RMAP_COMPILE_ERROR
:
252 vty_out (vty
, "Argument is malformed.%s", VTY_NEWLINE
);
261 ripng_route_set_delete (struct vty
*vty
, struct route_map_index
*index
,
262 char *command
, char *arg
)
266 ret
= route_map_delete_set (index
, command
, arg
);
271 case RMAP_RULE_MISSING
:
272 vty_out (vty
, "Can't find rule.%s", VTY_NEWLINE
);
275 case RMAP_COMPILE_ERROR
:
276 vty_out (vty
, "Argument is malformed.%s", VTY_NEWLINE
);
285 DEFUN (match_interface
,
287 "match interface WORD",
292 return ripng_route_match_add (vty
, vty
->index
, "interface", argv
[0]);
295 DEFUN (no_match_interface
,
296 no_match_interface_cmd
,
297 "no match interface WORD",
303 return ripng_route_match_delete (vty
, vty
->index
, "interface", argv
[0]);
309 "set metric <0-4294967295>",
314 return ripng_route_set_add (vty
, vty
->index
, "metric", argv
[0]);
317 DEFUN (no_set_metric
,
322 "Metric value for destination routing protocol\n")
325 return ripng_route_set_delete (vty
, vty
->index
, "metric", NULL
);
327 return ripng_route_set_delete (vty
, vty
->index
, "metric", argv
[0]);
330 ALIAS (no_set_metric
,
331 no_set_metric_val_cmd
,
332 "no set metric <0-4294967295>",
335 "Metric value for destination routing protocol\n"
339 ripng_route_map_init ()
342 route_map_init_vty ();
344 /* route_map_install_match (&route_match_interface_cmd); */
345 route_map_install_set (&route_set_metric_cmd
);
348 install_element (RMAP_NODE, &match_interface_cmd);
349 install_element (RMAP_NODE, &no_match_interface_cmd);
352 install_element (RMAP_NODE
, &set_metric_cmd
);
353 install_element (RMAP_NODE
, &no_set_metric_cmd
);