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 if (metric
< 0 || metric
> RIPNG_METRIC_INFINITY
)
164 mod
= XMALLOC (MTYPE_ROUTE_MAP_COMPILED
,
165 sizeof (struct rip_metric_modifier
));
167 mod
->metric
= metric
;
173 route_set_metric_free (void *rule
)
175 XFREE (MTYPE_ROUTE_MAP_COMPILED
, rule
);
178 struct route_map_rule_cmd route_set_metric_cmd
=
182 route_set_metric_compile
,
183 route_set_metric_free
,
187 ripng_route_match_add (struct vty
*vty
, struct route_map_index
*index
,
188 char *command
, char *arg
)
192 ret
= route_map_add_match (index
, command
, arg
);
197 case RMAP_RULE_MISSING
:
198 vty_out (vty
, "Can't find rule.%s", VTY_NEWLINE
);
201 case RMAP_COMPILE_ERROR
:
202 vty_out (vty
, "Argument is malformed.%s", VTY_NEWLINE
);
211 ripng_route_match_delete (struct vty
*vty
, struct route_map_index
*index
,
212 char *command
, char *arg
)
216 ret
= route_map_delete_match (index
, command
, arg
);
221 case RMAP_RULE_MISSING
:
222 vty_out (vty
, "Can't find rule.%s", VTY_NEWLINE
);
225 case RMAP_COMPILE_ERROR
:
226 vty_out (vty
, "Argument is malformed.%s", VTY_NEWLINE
);
235 ripng_route_set_add (struct vty
*vty
, struct route_map_index
*index
,
236 char *command
, char *arg
)
240 ret
= route_map_add_set (index
, command
, arg
);
245 case RMAP_RULE_MISSING
:
246 vty_out (vty
, "Can't find rule.%s", VTY_NEWLINE
);
249 case RMAP_COMPILE_ERROR
:
250 vty_out (vty
, "Argument is malformed.%s", VTY_NEWLINE
);
259 ripng_route_set_delete (struct vty
*vty
, struct route_map_index
*index
,
260 char *command
, char *arg
)
264 ret
= route_map_delete_set (index
, command
, arg
);
269 case RMAP_RULE_MISSING
:
270 vty_out (vty
, "Can't find rule.%s", VTY_NEWLINE
);
273 case RMAP_COMPILE_ERROR
:
274 vty_out (vty
, "Argument is malformed.%s", VTY_NEWLINE
);
283 DEFUN (match_interface
,
285 "match interface WORD",
290 return ripng_route_match_add (vty
, vty
->index
, "interface", argv
[0]);
293 DEFUN (no_match_interface
,
294 no_match_interface_cmd
,
295 "no match interface WORD",
301 return ripng_route_match_delete (vty
, vty
->index
, "interface", argv
[0]);
307 "set metric <0-4294967295>",
312 return ripng_route_set_add (vty
, vty
->index
, "metric", argv
[0]);
315 DEFUN (no_set_metric
,
317 "no set metric <0-4294967295>",
323 return ripng_route_set_delete (vty
, vty
->index
, "metric", argv
[0]);
327 ripng_route_map_init ()
330 route_map_init_vty ();
332 /* route_map_install_match (&route_match_interface_cmd); */
333 route_map_install_set (&route_set_metric_cmd
);
336 install_element (RMAP_NODE, &match_interface_cmd);
337 install_element (RMAP_NODE, &no_match_interface_cmd);
340 install_element (RMAP_NODE
, &set_metric_cmd
);
341 install_element (RMAP_NODE
, &no_set_metric_cmd
);