blob: 14df7940cba40b80c0069b0ad7357542d8163c01 [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/*
2 * OSPFv3 Route-Map
3 * Copyright (C) 1999 Yasuhiro Ohara
4 *
5 * This file is part of GNU Zebra.
6 *
7 * GNU Zebra is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
10 * later version.
11 *
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Zebra; see the file COPYING. If not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
21 */
22
23#include <zebra.h>
24
25#include "log.h"
26#include "memory.h"
27#include "linklist.h"
28#include "prefix.h"
29#include "command.h"
30#include "vty.h"
31#include "routemap.h"
32#include "table.h"
33#include "plist.h"
34
35#include "ospf6_route.h"
36#include "ospf6_prefix.h"
37#include "ospf6_lsa.h"
38#include "ospf6_asbr.h"
39
40route_map_result_t
41ospf6_routemap_rule_match_address_prefixlist (void *rule,
42 struct prefix *prefix,
43 route_map_object_t type,
44 void *object)
45{
46 struct prefix_list *plist;
47
48 if (type != RMAP_OSPF6)
49 return RMAP_NOMATCH;
50
51 plist = prefix_list_lookup (AFI_IP6, (char *) rule);
52
53 if (plist == NULL)
54 return RMAP_NOMATCH;
55
56 return (prefix_list_apply (plist, prefix) == PREFIX_DENY ?
57 RMAP_NOMATCH : RMAP_MATCH);
58}
59
60void *
61ospf6_routemap_rule_match_address_prefixlist_compile (char *arg)
62{
63 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
64}
65
66void
67ospf6_routemap_rule_match_address_prefixlist_free (void *rule)
68{
69 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
70}
71
72struct route_map_rule_cmd
73ospf6_routemap_rule_match_address_prefixlist_cmd =
74{
75 "ipv6 address prefix-list",
76 ospf6_routemap_rule_match_address_prefixlist,
77 ospf6_routemap_rule_match_address_prefixlist_compile,
78 ospf6_routemap_rule_match_address_prefixlist_free,
79};
80
81route_map_result_t
82ospf6_routemap_rule_set_metric_type (void *rule, struct prefix *prefix,
83 route_map_object_t type, void *object)
84{
85 char *metric_type = rule;
86 struct ospf6_external_info *info = object;
87
88 if (type != RMAP_OSPF6)
89 return RMAP_OKAY;
90
91 if (strcmp (metric_type, "type-2") == 0)
92 info->metric_type = 2;
93 else
94 info->metric_type = 1;
95
96 return RMAP_OKAY;
97}
98
99void *
100ospf6_routemap_rule_set_metric_type_compile (char *arg)
101{
102 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
103}
104
105void
106ospf6_routemap_rule_set_metric_type_free (void *rule)
107{
108 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
109}
110
111struct route_map_rule_cmd
112ospf6_routemap_rule_set_metric_type_cmd =
113{
114 "metric-type",
115 ospf6_routemap_rule_set_metric_type,
116 ospf6_routemap_rule_set_metric_type_compile,
117 ospf6_routemap_rule_set_metric_type_free,
118};
119
120route_map_result_t
121ospf6_routemap_rule_set_metric (void *rule, struct prefix *prefix,
122 route_map_object_t type, void *object)
123{
124 char *metric = rule;
125 struct ospf6_external_info *info = object;
126
127 if (type != RMAP_OSPF6)
128 return RMAP_OKAY;
129
130 info->metric = atoi (metric);
131 return RMAP_OKAY;
132}
133
134void *
135ospf6_routemap_rule_set_metric_compile (char *arg)
136{
137 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
138}
139
140void
141ospf6_routemap_rule_set_metric_free (void *rule)
142{
143 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
144}
145
146struct route_map_rule_cmd
147ospf6_routemap_rule_set_metric_cmd =
148{
149 "metric",
150 ospf6_routemap_rule_set_metric,
151 ospf6_routemap_rule_set_metric_compile,
152 ospf6_routemap_rule_set_metric_free,
153};
154
155route_map_result_t
156ospf6_routemap_rule_set_forwarding (void *rule, struct prefix *prefix,
157 route_map_object_t type, void *object)
158{
159 char *forwarding = rule;
160 struct ospf6_external_info *info = object;
161
162 if (type != RMAP_OSPF6)
163 return RMAP_OKAY;
164
165 if (inet_pton (AF_INET6, forwarding, &info->forwarding) != 1)
166 {
167 memset (&info->forwarding, 0, sizeof (struct in6_addr));
168 return RMAP_ERROR;
169 }
170
171 return RMAP_OKAY;
172}
173
174void *
175ospf6_routemap_rule_set_forwarding_compile (char *arg)
176{
177 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
178}
179
180void
181ospf6_routemap_rule_set_forwarding_free (void *rule)
182{
183 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
184}
185
186struct route_map_rule_cmd
187ospf6_routemap_rule_set_forwarding_cmd =
188{
189 "forwarding-address",
190 ospf6_routemap_rule_set_forwarding,
191 ospf6_routemap_rule_set_forwarding_compile,
192 ospf6_routemap_rule_set_forwarding_free,
193};
194
195int
196route_map_command_status (struct vty *vty, int ret)
197{
198 if (! ret)
199 return CMD_SUCCESS;
200
201 switch (ret)
202 {
203 case RMAP_RULE_MISSING:
204 vty_out (vty, "Can't find rule.%s", VTY_NEWLINE);
205 break;
206 case RMAP_COMPILE_ERROR:
207 vty_out (vty, "Argument is malformed.%s", VTY_NEWLINE);
208 break;
209 default:
210 vty_out (vty, "route-map add set failed.%s", VTY_NEWLINE);
211 break;
212 }
213 return CMD_WARNING;
214}
215
216/* add "match address" */
217DEFUN (ospf6_routemap_match_address_prefixlist,
218 ospf6_routemap_match_address_prefixlist_cmd,
219 "match ipv6 address prefix-list WORD",
220 "Match values\n"
221 IPV6_STR
222 "Match address of route\n"
223 "Match entries of prefix-lists\n"
224 "IPv6 prefix-list name\n")
225{
226 int ret = route_map_add_match ((struct route_map_index *) vty->index,
227 "ipv6 address prefix-list", argv[0]);
228 return route_map_command_status (vty, ret);
229}
230
231/* delete "match address" */
232DEFUN (ospf6_routemap_no_match_address_prefixlist,
233 ospf6_routemap_no_match_address_prefixlist_cmd,
234 "no match ipv6 address prefix-list WORD",
235 NO_STR
236 "Match values\n"
237 IPV6_STR
238 "Match address of route\n"
239 "Match entries of prefix-lists\n"
240 "IPv6 prefix-list name\n")
241{
242 int ret = route_map_delete_match ((struct route_map_index *) vty->index,
243 "ipv6 address prefix-list", argv[0]);
244 return route_map_command_status (vty, ret);
245}
246
247/* add "set metric-type" */
248DEFUN (ospf6_routemap_set_metric_type,
249 ospf6_routemap_set_metric_type_cmd,
250 "set metric-type (type-1|type-2)",
251 "Set value\n"
252 "Type of metric\n"
253 "OSPF6 external type 1 metric\n"
254 "OSPF6 external type 2 metric\n")
255{
256 int ret = route_map_add_set ((struct route_map_index *) vty->index,
257 "metric-type", argv[0]);
258 return route_map_command_status (vty, ret);
259}
260
261/* delete "set metric-type" */
262DEFUN (ospf6_routemap_no_set_metric_type,
263 ospf6_routemap_no_set_metric_type_cmd,
264 "no set metric-type (type-1|type-2)",
265 NO_STR
266 "Set value\n"
267 "Type of metric\n"
268 "OSPF6 external type 1 metric\n"
269 "OSPF6 external type 2 metric\n")
270{
271 int ret = route_map_delete_set ((struct route_map_index *) vty->index,
272 "metric-type", argv[0]);
273 return route_map_command_status (vty, ret);
274}
275
276/* add "set metric" */
277DEFUN (set_metric,
278 set_metric_cmd,
279 "set metric <0-4294967295>",
280 "Set value\n"
281 "Metric value\n"
282 "Metric value\n")
283{
284 int ret = route_map_add_set ((struct route_map_index *) vty->index,
285 "metric", argv[0]);
286 return route_map_command_status (vty, ret);
287}
288
289/* delete "set metric" */
290DEFUN (no_set_metric,
291 no_set_metric_cmd,
292 "no set metric <0-4294967295>",
293 NO_STR
294 "Set value\n"
295 "Metric\n"
296 "METRIC value\n")
297{
298 int ret = route_map_delete_set ((struct route_map_index *) vty->index,
299 "metric", argv[0]);
300 return route_map_command_status (vty, ret);
301}
302
303/* add "set forwarding-address" */
304DEFUN (ospf6_routemap_set_forwarding,
305 ospf6_routemap_set_forwarding_cmd,
306 "set forwarding-address X:X::X:X",
307 "Set value\n"
308 "Forwarding Address\n"
309 "IPv6 Address\n")
310{
311 int ret = route_map_add_set ((struct route_map_index *) vty->index,
312 "forwarding-address", argv[0]);
313 return route_map_command_status (vty, ret);
314}
315
316/* delete "set forwarding-address" */
317DEFUN (ospf6_routemap_no_set_forwarding,
318 ospf6_routemap_no_set_forwarding_cmd,
319 "no set forwarding-address X:X::X:X",
320 NO_STR
321 "Set value\n"
322 "Forwarding Address\n"
323 "IPv6 Address\n")
324{
325 int ret = route_map_delete_set ((struct route_map_index *) vty->index,
326 "forwarding-address", argv[0]);
327 return route_map_command_status (vty, ret);
328}
329
330void
331ospf6_routemap_init ()
332{
333 route_map_init ();
334 route_map_init_vty ();
335 route_map_add_hook (ospf6_asbr_routemap_update);
336 route_map_delete_hook (ospf6_asbr_routemap_update);
337
338 route_map_install_match (&ospf6_routemap_rule_match_address_prefixlist_cmd);
339 route_map_install_set (&ospf6_routemap_rule_set_metric_type_cmd);
340 route_map_install_set (&ospf6_routemap_rule_set_metric_cmd);
341 route_map_install_set (&ospf6_routemap_rule_set_forwarding_cmd);
342
343 /* Match address prefix-list */
344 install_element (RMAP_NODE, &ospf6_routemap_match_address_prefixlist_cmd);
345 install_element (RMAP_NODE, &ospf6_routemap_no_match_address_prefixlist_cmd);
346
347 /* ASE Metric Type (e.g. Type-1/Type-2) */
348 install_element (RMAP_NODE, &ospf6_routemap_set_metric_type_cmd);
349 install_element (RMAP_NODE, &ospf6_routemap_no_set_metric_type_cmd);
350
351 /* ASE Metric */
352 install_element (RMAP_NODE, &set_metric_cmd);
353 install_element (RMAP_NODE, &no_set_metric_cmd);
354
355 /* ASE Metric */
356 install_element (RMAP_NODE, &ospf6_routemap_set_forwarding_cmd);
357 install_element (RMAP_NODE, &ospf6_routemap_no_set_forwarding_cmd);
358}
359