blob: d6c1517e3dc84dea01906636cf2114e736972cab [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/*
hasso508e53e2004-05-18 18:57:06 +00002 * Copyright (C) 2003 Yasuhiro Ohara
paul718e3742002-12-13 20:15:29 +00003 *
4 * This file is part of GNU Zebra.
5 *
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
9 * later version.
10 *
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.
15 *
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
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
20 */
21
22#include <zebra.h>
23
24#include "log.h"
25#include "memory.h"
26#include "prefix.h"
27#include "command.h"
28#include "vty.h"
29#include "routemap.h"
30#include "table.h"
31#include "plist.h"
32#include "thread.h"
hasso508e53e2004-05-18 18:57:06 +000033#include "linklist.h"
paul718e3742002-12-13 20:15:29 +000034
paul718e3742002-12-13 20:15:29 +000035#include "ospf6_proto.h"
hasso508e53e2004-05-18 18:57:06 +000036#include "ospf6_lsa.h"
37#include "ospf6_lsdb.h"
38#include "ospf6_route.h"
39#include "ospf6_zebra.h"
hasso6452df02004-08-15 05:52:07 +000040#include "ospf6_message.h"
41
hasso508e53e2004-05-18 18:57:06 +000042#include "ospf6_top.h"
43#include "ospf6_area.h"
hasso6452df02004-08-15 05:52:07 +000044#include "ospf6_interface.h"
45#include "ospf6_neighbor.h"
hasso508e53e2004-05-18 18:57:06 +000046#include "ospf6_asbr.h"
47#include "ospf6_intra.h"
hasso6452df02004-08-15 05:52:07 +000048#include "ospf6_flood.h"
hasso049207c2004-08-04 20:02:13 +000049#include "ospf6d.h"
paul718e3742002-12-13 20:15:29 +000050
hasso508e53e2004-05-18 18:57:06 +000051unsigned char conf_debug_ospf6_asbr = 0;
paul718e3742002-12-13 20:15:29 +000052
ajsf52d13c2005-10-01 17:38:06 +000053#define ZROUTE_NAME(x) zebra_route_string(x)
hasso508e53e2004-05-18 18:57:06 +000054
55/* AS External LSA origination */
Paul Jakma6ac29a52008-08-15 13:45:30 +010056static void
hasso6452df02004-08-15 05:52:07 +000057ospf6_as_external_lsa_originate (struct ospf6_route *route)
paul718e3742002-12-13 20:15:29 +000058{
hasso508e53e2004-05-18 18:57:06 +000059 char buffer[OSPF6_MAX_LSASIZE];
60 struct ospf6_lsa_header *lsa_header;
61 struct ospf6_lsa *old, *lsa;
Paul Jakma0b26f812006-05-15 10:47:53 +000062 struct ospf6_external_info *info = route->route_option;
paul718e3742002-12-13 20:15:29 +000063
hasso508e53e2004-05-18 18:57:06 +000064 struct ospf6_as_external_lsa *as_external_lsa;
65 char buf[64];
66 caddr_t p;
paul718e3742002-12-13 20:15:29 +000067
hasso508e53e2004-05-18 18:57:06 +000068 /* find previous LSA */
69 old = ospf6_lsdb_lookup (htons (OSPF6_LSTYPE_AS_EXTERNAL),
hasso6452df02004-08-15 05:52:07 +000070 route->path.origin.id, ospf6->router_id,
hasso508e53e2004-05-18 18:57:06 +000071 ospf6->lsdb);
72
hasso1e058382004-09-01 21:36:14 +000073 if (IS_OSPF6_DEBUG_ASBR || IS_OSPF6_DEBUG_ORIGINATE (AS_EXTERNAL))
hasso508e53e2004-05-18 18:57:06 +000074 {
75 prefix2str (&route->prefix, buf, sizeof (buf));
hassoc6487d62004-12-24 06:00:11 +000076 zlog_debug ("Originate AS-External-LSA for %s", buf);
hasso508e53e2004-05-18 18:57:06 +000077 }
78
79 /* prepare buffer */
80 memset (buffer, 0, sizeof (buffer));
81 lsa_header = (struct ospf6_lsa_header *) buffer;
82 as_external_lsa = (struct ospf6_as_external_lsa *)
83 ((caddr_t) lsa_header + sizeof (struct ospf6_lsa_header));
84 p = (caddr_t)
85 ((caddr_t) as_external_lsa + sizeof (struct ospf6_as_external_lsa));
86
87 /* Fill AS-External-LSA */
88 /* Metric type */
89 if (route->path.metric_type == 2)
90 SET_FLAG (as_external_lsa->bits_metric, OSPF6_ASBR_BIT_E);
91 else
92 UNSET_FLAG (as_external_lsa->bits_metric, OSPF6_ASBR_BIT_E);
93
94 /* forwarding address */
Paul Jakma0b26f812006-05-15 10:47:53 +000095 if (! IN6_IS_ADDR_UNSPECIFIED (&info->forwarding))
hasso508e53e2004-05-18 18:57:06 +000096 SET_FLAG (as_external_lsa->bits_metric, OSPF6_ASBR_BIT_F);
97 else
98 UNSET_FLAG (as_external_lsa->bits_metric, OSPF6_ASBR_BIT_F);
99
100 /* external route tag */
101 UNSET_FLAG (as_external_lsa->bits_metric, OSPF6_ASBR_BIT_T);
102
103 /* Set metric */
104 OSPF6_ASBR_METRIC_SET (as_external_lsa, route->path.cost);
105
106 /* prefixlen */
107 as_external_lsa->prefix.prefix_length = route->prefix.prefixlen;
108
109 /* PrefixOptions */
110 as_external_lsa->prefix.prefix_options = route->path.prefix_options;
111
112 /* don't use refer LS-type */
113 as_external_lsa->prefix.prefix_refer_lstype = htons (0);
114
115 /* set Prefix */
116 memcpy (p, &route->prefix.u.prefix6,
117 OSPF6_PREFIX_SPACE (route->prefix.prefixlen));
118 ospf6_prefix_apply_mask (&as_external_lsa->prefix);
119 p += OSPF6_PREFIX_SPACE (route->prefix.prefixlen);
120
121 /* Forwarding address */
122 if (CHECK_FLAG (as_external_lsa->bits_metric, OSPF6_ASBR_BIT_F))
123 {
Paul Jakma0b26f812006-05-15 10:47:53 +0000124 memcpy (p, &info->forwarding, sizeof (struct in6_addr));
hasso508e53e2004-05-18 18:57:06 +0000125 p += sizeof (struct in6_addr);
126 }
127
128 /* External Route Tag */
129 if (CHECK_FLAG (as_external_lsa->bits_metric, OSPF6_ASBR_BIT_T))
130 {
131 /* xxx */
132 }
133
134 /* Fill LSA Header */
135 lsa_header->age = 0;
136 lsa_header->type = htons (OSPF6_LSTYPE_AS_EXTERNAL);
hasso6452df02004-08-15 05:52:07 +0000137 lsa_header->id = route->path.origin.id;
hasso508e53e2004-05-18 18:57:06 +0000138 lsa_header->adv_router = ospf6->router_id;
139 lsa_header->seqnum =
hasso049207c2004-08-04 20:02:13 +0000140 ospf6_new_ls_seqnum (lsa_header->type, lsa_header->id,
141 lsa_header->adv_router, ospf6->lsdb);
hasso508e53e2004-05-18 18:57:06 +0000142 lsa_header->length = htons ((caddr_t) p - (caddr_t) lsa_header);
143
144 /* LSA checksum */
145 ospf6_lsa_checksum (lsa_header);
146
147 /* create LSA */
148 lsa = ospf6_lsa_create (lsa_header);
hasso508e53e2004-05-18 18:57:06 +0000149
150 /* Originate */
hasso6452df02004-08-15 05:52:07 +0000151 ospf6_lsa_originate_process (lsa, ospf6);
hasso508e53e2004-05-18 18:57:06 +0000152}
153
hasso508e53e2004-05-18 18:57:06 +0000154
155void
156ospf6_asbr_lsa_add (struct ospf6_lsa *lsa)
157{
158 struct ospf6_as_external_lsa *external;
159 struct prefix asbr_id;
160 struct ospf6_route *asbr_entry, *route;
161 char buf[64];
162 int i;
163
164 external = (struct ospf6_as_external_lsa *)
165 OSPF6_LSA_HEADER_END (lsa->header);
166
hasso1e058382004-09-01 21:36:14 +0000167 if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL))
hassoc6487d62004-12-24 06:00:11 +0000168 zlog_debug ("Calculate AS-External route for %s", lsa->name);
hasso508e53e2004-05-18 18:57:06 +0000169
170 if (lsa->header->adv_router == ospf6->router_id)
171 {
hasso1e058382004-09-01 21:36:14 +0000172 if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL))
hassoc6487d62004-12-24 06:00:11 +0000173 zlog_debug ("Ignore self-originated AS-External-LSA");
hasso508e53e2004-05-18 18:57:06 +0000174 return;
175 }
176
177 if (OSPF6_ASBR_METRIC (external) == LS_INFINITY)
178 {
hasso1e058382004-09-01 21:36:14 +0000179 if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL))
hassoc6487d62004-12-24 06:00:11 +0000180 zlog_debug ("Ignore LSA with LSInfinity Metric");
hasso508e53e2004-05-18 18:57:06 +0000181 return;
182 }
183
hassoccb59b12004-08-25 09:10:37 +0000184 ospf6_linkstate_prefix (lsa->header->adv_router, htonl (0), &asbr_id);
hasso6452df02004-08-15 05:52:07 +0000185 asbr_entry = ospf6_route_lookup (&asbr_id, ospf6->brouter_table);
hasso63069ad2004-09-02 13:01:01 +0000186 if (asbr_entry == NULL ||
187 ! CHECK_FLAG (asbr_entry->path.router_bits, OSPF6_ROUTER_BIT_E))
hasso508e53e2004-05-18 18:57:06 +0000188 {
hasso1e058382004-09-01 21:36:14 +0000189 if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL))
hasso508e53e2004-05-18 18:57:06 +0000190 {
191 prefix2str (&asbr_id, buf, sizeof (buf));
hassoc6487d62004-12-24 06:00:11 +0000192 zlog_debug ("ASBR entry not found: %s", buf);
hasso508e53e2004-05-18 18:57:06 +0000193 }
194 return;
195 }
196
197 route = ospf6_route_create ();
198 route->type = OSPF6_DEST_TYPE_NETWORK;
199 route->prefix.family = AF_INET6;
200 route->prefix.prefixlen = external->prefix.prefix_length;
201 ospf6_prefix_in6_addr (&route->prefix.u.prefix6, &external->prefix);
202
203 route->path.area_id = asbr_entry->path.area_id;
204 route->path.origin.type = lsa->header->type;
205 route->path.origin.id = lsa->header->id;
206 route->path.origin.adv_router = lsa->header->adv_router;
207
208 route->path.prefix_options = external->prefix.prefix_options;
209 if (CHECK_FLAG (external->bits_metric, OSPF6_ASBR_BIT_E))
210 {
211 route->path.type = OSPF6_PATH_TYPE_EXTERNAL2;
212 route->path.metric_type = 2;
213 route->path.cost = asbr_entry->path.cost;
214 route->path.cost_e2 = OSPF6_ASBR_METRIC (external);
215 }
216 else
217 {
218 route->path.type = OSPF6_PATH_TYPE_EXTERNAL1;
219 route->path.metric_type = 1;
220 route->path.cost = asbr_entry->path.cost + OSPF6_ASBR_METRIC (external);
221 route->path.cost_e2 = 0;
222 }
223
224 for (i = 0; i < OSPF6_MULTI_PATH_LIMIT; i++)
225 ospf6_nexthop_copy (&route->nexthop[i], &asbr_entry->nexthop[i]);
226
hasso1e058382004-09-01 21:36:14 +0000227 if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL))
hasso508e53e2004-05-18 18:57:06 +0000228 {
229 prefix2str (&route->prefix, buf, sizeof (buf));
hassoc6487d62004-12-24 06:00:11 +0000230 zlog_debug ("AS-External route add: %s", buf);
hasso508e53e2004-05-18 18:57:06 +0000231 }
232
233 ospf6_route_add (route, ospf6->route_table);
234}
235
236void
237ospf6_asbr_lsa_remove (struct ospf6_lsa *lsa)
238{
239 struct ospf6_as_external_lsa *external;
240 struct prefix prefix;
241 struct ospf6_route *route;
242 char buf[64];
243
244 external = (struct ospf6_as_external_lsa *)
245 OSPF6_LSA_HEADER_END (lsa->header);
246
hasso1e058382004-09-01 21:36:14 +0000247 if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL))
hassoc6487d62004-12-24 06:00:11 +0000248 zlog_debug ("Withdraw AS-External route for %s", lsa->name);
hasso508e53e2004-05-18 18:57:06 +0000249
250 if (lsa->header->adv_router == ospf6->router_id)
251 {
hasso1e058382004-09-01 21:36:14 +0000252 if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL))
hassoc6487d62004-12-24 06:00:11 +0000253 zlog_debug ("Ignore self-originated AS-External-LSA");
hasso508e53e2004-05-18 18:57:06 +0000254 return;
255 }
256
257 memset (&prefix, 0, sizeof (struct prefix));
258 prefix.family = AF_INET6;
259 prefix.prefixlen = external->prefix.prefix_length;
260 ospf6_prefix_in6_addr (&prefix.u.prefix6, &external->prefix);
261
262 route = ospf6_route_lookup (&prefix, ospf6->route_table);
263 if (route == NULL)
264 {
hasso1e058382004-09-01 21:36:14 +0000265 if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL))
hasso508e53e2004-05-18 18:57:06 +0000266 {
267 prefix2str (&prefix, buf, sizeof (buf));
hassoc6487d62004-12-24 06:00:11 +0000268 zlog_debug ("AS-External route %s not found", buf);
hasso508e53e2004-05-18 18:57:06 +0000269 }
270 return;
271 }
272
273 for (ospf6_route_lock (route);
274 route && ospf6_route_is_prefix (&prefix, route);
275 route = ospf6_route_next (route))
276 {
277 if (route->type != OSPF6_DEST_TYPE_NETWORK)
278 continue;
279 if (route->path.origin.type != lsa->header->type)
280 continue;
281 if (route->path.origin.id != lsa->header->id)
282 continue;
283 if (route->path.origin.adv_router != lsa->header->adv_router)
284 continue;
285
hasso1e058382004-09-01 21:36:14 +0000286 if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL))
hasso508e53e2004-05-18 18:57:06 +0000287 {
288 prefix2str (&route->prefix, buf, sizeof (buf));
hassoc6487d62004-12-24 06:00:11 +0000289 zlog_debug ("AS-External route remove: %s", buf);
hasso508e53e2004-05-18 18:57:06 +0000290 }
291 ospf6_route_remove (route, ospf6->route_table);
292 }
293}
294
295void
296ospf6_asbr_lsentry_add (struct ospf6_route *asbr_entry)
297{
hasso508e53e2004-05-18 18:57:06 +0000298 struct ospf6_lsa *lsa;
299 u_int16_t type;
300 u_int32_t router;
301
Paul Jakmacb4b8842006-05-15 10:39:30 +0000302 if (! CHECK_FLAG (asbr_entry->flag, OSPF6_ROUTE_BEST))
hasso508e53e2004-05-18 18:57:06 +0000303 {
Paul Jakmacb4b8842006-05-15 10:39:30 +0000304 char buf[16];
305 inet_ntop (AF_INET, &ADV_ROUTER_IN_PREFIX (&asbr_entry->prefix),
306 buf, sizeof (buf));
307 zlog_info ("ignore non-best path: lsentry %s add", buf);
308 return;
hasso508e53e2004-05-18 18:57:06 +0000309 }
310
311 type = htons (OSPF6_LSTYPE_AS_EXTERNAL);
312 router = ospf6_linkstate_prefix_adv_router (&asbr_entry->prefix);
Paul Jakmacb4b8842006-05-15 10:39:30 +0000313 for (lsa = ospf6_lsdb_type_router_head (type, router, ospf6->lsdb); lsa;
314 lsa = ospf6_lsdb_type_router_next (type, router, lsa))
hasso508e53e2004-05-18 18:57:06 +0000315 {
316 if (! OSPF6_LSA_IS_MAXAGE (lsa))
317 ospf6_asbr_lsa_add (lsa);
318 }
hasso508e53e2004-05-18 18:57:06 +0000319}
320
321void
322ospf6_asbr_lsentry_remove (struct ospf6_route *asbr_entry)
323{
hasso508e53e2004-05-18 18:57:06 +0000324 struct ospf6_lsa *lsa;
325 u_int16_t type;
326 u_int32_t router;
327
hasso508e53e2004-05-18 18:57:06 +0000328 type = htons (OSPF6_LSTYPE_AS_EXTERNAL);
329 router = ospf6_linkstate_prefix_adv_router (&asbr_entry->prefix);
330 for (lsa = ospf6_lsdb_type_router_head (type, router, ospf6->lsdb);
331 lsa; lsa = ospf6_lsdb_type_router_next (type, router, lsa))
332 ospf6_asbr_lsa_remove (lsa);
hasso508e53e2004-05-18 18:57:06 +0000333}
334
335
336
paul718e3742002-12-13 20:15:29 +0000337/* redistribute function */
hasso508e53e2004-05-18 18:57:06 +0000338
Paul Jakma6ac29a52008-08-15 13:45:30 +0100339static void
paul0c083ee2004-10-10 12:54:58 +0000340ospf6_asbr_routemap_set (int type, const char *mapname)
paul718e3742002-12-13 20:15:29 +0000341{
hasso508e53e2004-05-18 18:57:06 +0000342 if (ospf6->rmap[type].name)
343 free (ospf6->rmap[type].name);
344 ospf6->rmap[type].name = strdup (mapname);
345 ospf6->rmap[type].map = route_map_lookup_by_name (mapname);
paul718e3742002-12-13 20:15:29 +0000346}
347
Paul Jakma6ac29a52008-08-15 13:45:30 +0100348static void
paul718e3742002-12-13 20:15:29 +0000349ospf6_asbr_routemap_unset (int type)
350{
hasso508e53e2004-05-18 18:57:06 +0000351 if (ospf6->rmap[type].name)
352 free (ospf6->rmap[type].name);
353 ospf6->rmap[type].name = NULL;
354 ospf6->rmap[type].map = NULL;
paul718e3742002-12-13 20:15:29 +0000355}
356
Paul Jakma6ac29a52008-08-15 13:45:30 +0100357static void
paul0c083ee2004-10-10 12:54:58 +0000358ospf6_asbr_routemap_update (const char *mapname)
paul718e3742002-12-13 20:15:29 +0000359{
hasso508e53e2004-05-18 18:57:06 +0000360 int type;
361
362 if (ospf6 == NULL)
363 return;
364
365 for (type = 0; type < ZEBRA_ROUTE_MAX; type++)
paul718e3742002-12-13 20:15:29 +0000366 {
hasso508e53e2004-05-18 18:57:06 +0000367 if (ospf6->rmap[type].name)
368 ospf6->rmap[type].map =
369 route_map_lookup_by_name (ospf6->rmap[type].name);
paul718e3742002-12-13 20:15:29 +0000370 else
hasso508e53e2004-05-18 18:57:06 +0000371 ospf6->rmap[type].map = NULL;
372 }
373}
374
375int
376ospf6_asbr_is_asbr (struct ospf6 *o)
377{
378 return o->external_table->count;
379}
380
Paul Jakma6ac29a52008-08-15 13:45:30 +0100381static void
hasso508e53e2004-05-18 18:57:06 +0000382ospf6_asbr_redistribute_set (int type)
383{
384 ospf6_zebra_redistribute (type);
385}
386
Paul Jakma6ac29a52008-08-15 13:45:30 +0100387static void
hasso508e53e2004-05-18 18:57:06 +0000388ospf6_asbr_redistribute_unset (int type)
389{
390 struct ospf6_route *route;
391 struct ospf6_external_info *info;
392
393 ospf6_zebra_no_redistribute (type);
394
395 for (route = ospf6_route_head (ospf6->external_table); route;
396 route = ospf6_route_next (route))
397 {
398 info = route->route_option;
399 if (info->type != type)
400 continue;
401
402 ospf6_asbr_redistribute_remove (info->type, route->nexthop[0].ifindex,
403 &route->prefix);
404 }
405}
406
407void
408ospf6_asbr_redistribute_add (int type, int ifindex, struct prefix *prefix,
409 u_int nexthop_num, struct in6_addr *nexthop)
410{
411 int ret;
412 struct ospf6_route troute;
413 struct ospf6_external_info tinfo;
414 struct ospf6_route *route, *match;
415 struct ospf6_external_info *info;
416 struct prefix prefix_id;
417 struct route_node *node;
418 char pbuf[64], ibuf[16];
paul1eb8ef22005-04-07 07:30:20 +0000419 struct listnode *lnode, *lnnode;
hasso508e53e2004-05-18 18:57:06 +0000420 struct ospf6_area *oa;
421
422 if (! ospf6_zebra_is_redistribute (type))
423 return;
424
425 if (IS_OSPF6_DEBUG_ASBR)
426 {
427 prefix2str (prefix, pbuf, sizeof (pbuf));
hassoc6487d62004-12-24 06:00:11 +0000428 zlog_debug ("Redistribute %s (%s)", pbuf, ZROUTE_NAME (type));
hasso508e53e2004-05-18 18:57:06 +0000429 }
430
431 /* if route-map was specified but not found, do not advertise */
432 if (ospf6->rmap[type].name)
433 {
434 if (ospf6->rmap[type].map == NULL)
hasso03d52f82004-09-29 00:26:19 +0000435 ospf6_asbr_routemap_update (NULL);
hasso508e53e2004-05-18 18:57:06 +0000436 if (ospf6->rmap[type].map == NULL)
437 {
438 zlog_warn ("route-map \"%s\" not found, suppress redistributing",
439 ospf6->rmap[type].name);
440 return;
441 }
442 }
443
444 /* apply route-map */
445 if (ospf6->rmap[type].map)
446 {
447 memset (&troute, 0, sizeof (troute));
448 memset (&tinfo, 0, sizeof (tinfo));
449 troute.route_option = &tinfo;
450
451 ret = route_map_apply (ospf6->rmap[type].map, prefix,
452 RMAP_OSPF6, &troute);
paul47828742005-08-10 15:46:11 +0000453 if (ret == RMAP_DENYMATCH)
hasso508e53e2004-05-18 18:57:06 +0000454 {
455 if (IS_OSPF6_DEBUG_ASBR)
hassoc6487d62004-12-24 06:00:11 +0000456 zlog_debug ("Denied by route-map \"%s\"", ospf6->rmap[type].name);
hasso508e53e2004-05-18 18:57:06 +0000457 return;
458 }
459 }
460
461 match = ospf6_route_lookup (prefix, ospf6->external_table);
462 if (match)
463 {
464 info = match->route_option;
465
466 /* copy result of route-map */
467 if (ospf6->rmap[type].map)
468 {
469 if (troute.path.metric_type)
470 match->path.metric_type = troute.path.metric_type;
471 if (troute.path.cost)
472 match->path.cost = troute.path.cost;
473 if (! IN6_IS_ADDR_UNSPECIFIED (&tinfo.forwarding))
474 memcpy (&info->forwarding, &tinfo.forwarding,
475 sizeof (struct in6_addr));
476 }
477
478 info->type = type;
479 match->nexthop[0].ifindex = ifindex;
480 if (nexthop_num && nexthop)
481 memcpy (&match->nexthop[0].address, nexthop, sizeof (struct in6_addr));
482
483 /* create/update binding in external_id_table */
484 prefix_id.family = AF_INET;
485 prefix_id.prefixlen = 32;
486 prefix_id.u.prefix4.s_addr = htonl (info->id);
487 node = route_node_get (ospf6->external_id_table, &prefix_id);
488 node->info = match;
489
490 if (IS_OSPF6_DEBUG_ASBR)
491 {
492 inet_ntop (AF_INET, &prefix_id.u.prefix4, ibuf, sizeof (ibuf));
hassoc6487d62004-12-24 06:00:11 +0000493 zlog_debug ("Advertise as AS-External Id:%s", ibuf);
hasso508e53e2004-05-18 18:57:06 +0000494 }
495
hasso3b687352004-08-19 06:56:53 +0000496 match->path.origin.id = htonl (info->id);
hasso6452df02004-08-15 05:52:07 +0000497 ospf6_as_external_lsa_originate (match);
hasso508e53e2004-05-18 18:57:06 +0000498 return;
499 }
500
501 /* create new entry */
502 route = ospf6_route_create ();
503 route->type = OSPF6_DEST_TYPE_NETWORK;
504 memcpy (&route->prefix, prefix, sizeof (struct prefix));
505
506 info = (struct ospf6_external_info *)
Stephen Hemminger393deb92008-08-18 14:13:29 -0700507 XCALLOC (MTYPE_OSPF6_EXTERNAL_INFO, sizeof (struct ospf6_external_info));
hasso508e53e2004-05-18 18:57:06 +0000508 route->route_option = info;
509 info->id = ospf6->external_id++;
510
511 /* copy result of route-map */
512 if (ospf6->rmap[type].map)
513 {
514 if (troute.path.metric_type)
515 route->path.metric_type = troute.path.metric_type;
516 if (troute.path.cost)
517 route->path.cost = troute.path.cost;
518 if (! IN6_IS_ADDR_UNSPECIFIED (&tinfo.forwarding))
519 memcpy (&info->forwarding, &tinfo.forwarding,
520 sizeof (struct in6_addr));
521 }
522
523 info->type = type;
524 route->nexthop[0].ifindex = ifindex;
525 if (nexthop_num && nexthop)
526 memcpy (&route->nexthop[0].address, nexthop, sizeof (struct in6_addr));
527
528 /* create/update binding in external_id_table */
529 prefix_id.family = AF_INET;
530 prefix_id.prefixlen = 32;
531 prefix_id.u.prefix4.s_addr = htonl (info->id);
532 node = route_node_get (ospf6->external_id_table, &prefix_id);
533 node->info = route;
534
535 route = ospf6_route_add (route, ospf6->external_table);
536 route->route_option = info;
537
538 if (IS_OSPF6_DEBUG_ASBR)
539 {
540 inet_ntop (AF_INET, &prefix_id.u.prefix4, ibuf, sizeof (ibuf));
hassoc6487d62004-12-24 06:00:11 +0000541 zlog_debug ("Advertise as AS-External Id:%s", ibuf);
hasso508e53e2004-05-18 18:57:06 +0000542 }
543
hasso3b687352004-08-19 06:56:53 +0000544 route->path.origin.id = htonl (info->id);
hasso6452df02004-08-15 05:52:07 +0000545 ospf6_as_external_lsa_originate (route);
hasso508e53e2004-05-18 18:57:06 +0000546
547 /* Router-Bit (ASBR Flag) may have to be updated */
paul1eb8ef22005-04-07 07:30:20 +0000548 for (ALL_LIST_ELEMENTS (ospf6->area_list, lnode, lnnode, oa))
549 OSPF6_ROUTER_LSA_SCHEDULE (oa);
hasso508e53e2004-05-18 18:57:06 +0000550}
551
552void
553ospf6_asbr_redistribute_remove (int type, int ifindex, struct prefix *prefix)
554{
555 struct ospf6_route *match;
556 struct ospf6_external_info *info = NULL;
557 struct route_node *node;
558 struct ospf6_lsa *lsa;
559 struct prefix prefix_id;
560 char pbuf[64], ibuf[16];
paul1eb8ef22005-04-07 07:30:20 +0000561 struct listnode *lnode, *lnnode;
hasso508e53e2004-05-18 18:57:06 +0000562 struct ospf6_area *oa;
563
564 match = ospf6_route_lookup (prefix, ospf6->external_table);
565 if (match == NULL)
566 {
567 if (IS_OSPF6_DEBUG_ASBR)
568 {
569 prefix2str (prefix, pbuf, sizeof (pbuf));
hassoc6487d62004-12-24 06:00:11 +0000570 zlog_debug ("No such route %s to withdraw", pbuf);
hasso508e53e2004-05-18 18:57:06 +0000571 }
572 return;
573 }
574
575 info = match->route_option;
576 assert (info);
577
578 if (info->type != type)
579 {
580 if (IS_OSPF6_DEBUG_ASBR)
581 {
582 prefix2str (prefix, pbuf, sizeof (pbuf));
hassoc6487d62004-12-24 06:00:11 +0000583 zlog_debug ("Original protocol mismatch: %s", pbuf);
hasso508e53e2004-05-18 18:57:06 +0000584 }
585 return;
586 }
587
588 if (IS_OSPF6_DEBUG_ASBR)
589 {
590 prefix2str (prefix, pbuf, sizeof (pbuf));
591 inet_ntop (AF_INET, &prefix_id.u.prefix4, ibuf, sizeof (ibuf));
hassoc6487d62004-12-24 06:00:11 +0000592 zlog_debug ("Withdraw %s (AS-External Id:%s)", pbuf, ibuf);
hasso508e53e2004-05-18 18:57:06 +0000593 }
594
595 lsa = ospf6_lsdb_lookup (htons (OSPF6_LSTYPE_AS_EXTERNAL),
596 htonl (info->id), ospf6->router_id, ospf6->lsdb);
597 if (lsa)
hasso6452df02004-08-15 05:52:07 +0000598 ospf6_lsa_purge (lsa);
hasso508e53e2004-05-18 18:57:06 +0000599
600 /* remove binding in external_id_table */
601 prefix_id.family = AF_INET;
602 prefix_id.prefixlen = 32;
603 prefix_id.u.prefix4.s_addr = htonl (info->id);
604 node = route_node_lookup (ospf6->external_id_table, &prefix_id);
605 assert (node);
606 node->info = NULL;
607 route_unlock_node (node);
608
609 ospf6_route_remove (match, ospf6->external_table);
610 XFREE (MTYPE_OSPF6_EXTERNAL_INFO, info);
611
612 /* Router-Bit (ASBR Flag) may have to be updated */
paul1eb8ef22005-04-07 07:30:20 +0000613 for (ALL_LIST_ELEMENTS (ospf6->area_list, lnode, lnnode, oa))
614 OSPF6_ROUTER_LSA_SCHEDULE (oa);
paul718e3742002-12-13 20:15:29 +0000615}
616
617DEFUN (ospf6_redistribute,
618 ospf6_redistribute_cmd,
David Lamparterdaca2cf2009-09-16 01:52:42 +0200619 "redistribute " QUAGGA_REDIST_STR_OSPF6D,
paul718e3742002-12-13 20:15:29 +0000620 "Redistribute\n"
David Lamparterdaca2cf2009-09-16 01:52:42 +0200621 QUAGGA_REDIST_HELP_STR_OSPF6D
paul718e3742002-12-13 20:15:29 +0000622 )
623{
David Lamparterdaca2cf2009-09-16 01:52:42 +0200624 int type;
paul718e3742002-12-13 20:15:29 +0000625
David Lamparterdaca2cf2009-09-16 01:52:42 +0200626 type = proto_redistnum(AFI_IP6, argv[0]);
627 if (type < 0 || type == ZEBRA_ROUTE_OSPF6)
628 return CMD_WARNING;
paul718e3742002-12-13 20:15:29 +0000629
hasso508e53e2004-05-18 18:57:06 +0000630 ospf6_asbr_redistribute_unset (type);
paul718e3742002-12-13 20:15:29 +0000631 ospf6_asbr_routemap_unset (type);
hasso508e53e2004-05-18 18:57:06 +0000632 ospf6_asbr_redistribute_set (type);
paul718e3742002-12-13 20:15:29 +0000633 return CMD_SUCCESS;
634}
635
636DEFUN (ospf6_redistribute_routemap,
637 ospf6_redistribute_routemap_cmd,
David Lamparterdaca2cf2009-09-16 01:52:42 +0200638 "redistribute " QUAGGA_REDIST_STR_OSPF6D " route-map WORD",
paul718e3742002-12-13 20:15:29 +0000639 "Redistribute\n"
David Lamparterdaca2cf2009-09-16 01:52:42 +0200640 QUAGGA_REDIST_HELP_STR_OSPF6D
paul718e3742002-12-13 20:15:29 +0000641 "Route map reference\n"
642 "Route map name\n"
643 )
644{
David Lamparterdaca2cf2009-09-16 01:52:42 +0200645 int type;
paul718e3742002-12-13 20:15:29 +0000646
David Lamparterdaca2cf2009-09-16 01:52:42 +0200647 type = proto_redistnum(AFI_IP6, argv[0]);
648 if (type < 0 || type == ZEBRA_ROUTE_OSPF6)
649 return CMD_WARNING;
paul718e3742002-12-13 20:15:29 +0000650
hasso508e53e2004-05-18 18:57:06 +0000651 ospf6_asbr_redistribute_unset (type);
paul718e3742002-12-13 20:15:29 +0000652 ospf6_asbr_routemap_set (type, argv[1]);
hasso508e53e2004-05-18 18:57:06 +0000653 ospf6_asbr_redistribute_set (type);
paul718e3742002-12-13 20:15:29 +0000654 return CMD_SUCCESS;
655}
656
657DEFUN (no_ospf6_redistribute,
658 no_ospf6_redistribute_cmd,
David Lamparterdaca2cf2009-09-16 01:52:42 +0200659 "no redistribute " QUAGGA_REDIST_STR_OSPF6D,
paul718e3742002-12-13 20:15:29 +0000660 NO_STR
661 "Redistribute\n"
David Lamparterdaca2cf2009-09-16 01:52:42 +0200662 QUAGGA_REDIST_HELP_STR_OSPF6D
paul718e3742002-12-13 20:15:29 +0000663 )
664{
David Lamparterdaca2cf2009-09-16 01:52:42 +0200665 int type;
paul718e3742002-12-13 20:15:29 +0000666
David Lamparterdaca2cf2009-09-16 01:52:42 +0200667 type = proto_redistnum(AFI_IP6, argv[0]);
668 if (type < 0 || type == ZEBRA_ROUTE_OSPF6)
669 return CMD_WARNING;
paul718e3742002-12-13 20:15:29 +0000670
hasso508e53e2004-05-18 18:57:06 +0000671 ospf6_asbr_redistribute_unset (type);
paul718e3742002-12-13 20:15:29 +0000672 ospf6_asbr_routemap_unset (type);
673
paul718e3742002-12-13 20:15:29 +0000674 return CMD_SUCCESS;
675}
676
paul718e3742002-12-13 20:15:29 +0000677int
678ospf6_redistribute_config_write (struct vty *vty)
679{
hasso508e53e2004-05-18 18:57:06 +0000680 int type;
paul718e3742002-12-13 20:15:29 +0000681
hasso508e53e2004-05-18 18:57:06 +0000682 for (type = 0; type < ZEBRA_ROUTE_MAX; type++)
paul718e3742002-12-13 20:15:29 +0000683 {
hasso508e53e2004-05-18 18:57:06 +0000684 if (type == ZEBRA_ROUTE_OSPF6)
685 continue;
686 if (! ospf6_zebra_is_redistribute (type))
paul718e3742002-12-13 20:15:29 +0000687 continue;
688
hasso508e53e2004-05-18 18:57:06 +0000689 if (ospf6->rmap[type].name)
paul718e3742002-12-13 20:15:29 +0000690 vty_out (vty, " redistribute %s route-map %s%s",
hasso049207c2004-08-04 20:02:13 +0000691 ZROUTE_NAME (type), ospf6->rmap[type].name, VNL);
paul718e3742002-12-13 20:15:29 +0000692 else
693 vty_out (vty, " redistribute %s%s",
hasso049207c2004-08-04 20:02:13 +0000694 ZROUTE_NAME (type), VNL);
paul718e3742002-12-13 20:15:29 +0000695 }
696
697 return 0;
698}
699
Paul Jakma6ac29a52008-08-15 13:45:30 +0100700static void
paul718e3742002-12-13 20:15:29 +0000701ospf6_redistribute_show_config (struct vty *vty)
702{
hasso508e53e2004-05-18 18:57:06 +0000703 int type;
704 int nroute[ZEBRA_ROUTE_MAX];
705 int total;
706 struct ospf6_route *route;
paul718e3742002-12-13 20:15:29 +0000707 struct ospf6_external_info *info;
paul718e3742002-12-13 20:15:29 +0000708
hasso508e53e2004-05-18 18:57:06 +0000709 total = 0;
710 for (type = 0; type < ZEBRA_ROUTE_MAX; type++)
711 nroute[type] = 0;
712 for (route = ospf6_route_head (ospf6->external_table); route;
713 route = ospf6_route_next (route))
paul718e3742002-12-13 20:15:29 +0000714 {
hasso508e53e2004-05-18 18:57:06 +0000715 info = route->route_option;
716 nroute[info->type]++;
717 total++;
paul718e3742002-12-13 20:15:29 +0000718 }
719
hasso049207c2004-08-04 20:02:13 +0000720 vty_out (vty, "Redistributing External Routes from:%s", VNL);
hasso508e53e2004-05-18 18:57:06 +0000721 for (type = 0; type < ZEBRA_ROUTE_MAX; type++)
paul718e3742002-12-13 20:15:29 +0000722 {
hasso508e53e2004-05-18 18:57:06 +0000723 if (type == ZEBRA_ROUTE_OSPF6)
724 continue;
725 if (! ospf6_zebra_is_redistribute (type))
hassoe26bbeb2003-05-25 21:39:29 +0000726 continue;
727
hasso508e53e2004-05-18 18:57:06 +0000728 if (ospf6->rmap[type].name)
729 vty_out (vty, " %d: %s with route-map \"%s\"%s%s", nroute[type],
730 ZROUTE_NAME (type), ospf6->rmap[type].name,
731 (ospf6->rmap[type].map ? "" : " (not found !)"),
hasso049207c2004-08-04 20:02:13 +0000732 VNL);
paul718e3742002-12-13 20:15:29 +0000733 else
hasso508e53e2004-05-18 18:57:06 +0000734 vty_out (vty, " %d: %s%s", nroute[type],
hasso049207c2004-08-04 20:02:13 +0000735 ZROUTE_NAME (type), VNL);
paul718e3742002-12-13 20:15:29 +0000736 }
hasso049207c2004-08-04 20:02:13 +0000737 vty_out (vty, "Total %d routes%s", total, VNL);
hasso508e53e2004-05-18 18:57:06 +0000738}
paul718e3742002-12-13 20:15:29 +0000739
paul718e3742002-12-13 20:15:29 +0000740
hasso508e53e2004-05-18 18:57:06 +0000741
742/* Routemap Functions */
Paul Jakma6ac29a52008-08-15 13:45:30 +0100743static route_map_result_t
hasso508e53e2004-05-18 18:57:06 +0000744ospf6_routemap_rule_match_address_prefixlist (void *rule,
745 struct prefix *prefix,
746 route_map_object_t type,
747 void *object)
748{
749 struct prefix_list *plist;
paul718e3742002-12-13 20:15:29 +0000750
hasso508e53e2004-05-18 18:57:06 +0000751 if (type != RMAP_OSPF6)
752 return RMAP_NOMATCH;
paul718e3742002-12-13 20:15:29 +0000753
hasso508e53e2004-05-18 18:57:06 +0000754 plist = prefix_list_lookup (AFI_IP6, (char *) rule);
755 if (plist == NULL)
756 return RMAP_NOMATCH;
paul718e3742002-12-13 20:15:29 +0000757
hasso508e53e2004-05-18 18:57:06 +0000758 return (prefix_list_apply (plist, prefix) == PREFIX_DENY ?
759 RMAP_NOMATCH : RMAP_MATCH);
760}
paul718e3742002-12-13 20:15:29 +0000761
Paul Jakma6ac29a52008-08-15 13:45:30 +0100762static void *
paul0c083ee2004-10-10 12:54:58 +0000763ospf6_routemap_rule_match_address_prefixlist_compile (const char *arg)
hasso508e53e2004-05-18 18:57:06 +0000764{
765 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
paul718e3742002-12-13 20:15:29 +0000766}
767
Paul Jakma6ac29a52008-08-15 13:45:30 +0100768static void
hasso508e53e2004-05-18 18:57:06 +0000769ospf6_routemap_rule_match_address_prefixlist_free (void *rule)
paul718e3742002-12-13 20:15:29 +0000770{
hasso508e53e2004-05-18 18:57:06 +0000771 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
772}
paul718e3742002-12-13 20:15:29 +0000773
hasso508e53e2004-05-18 18:57:06 +0000774struct route_map_rule_cmd
775ospf6_routemap_rule_match_address_prefixlist_cmd =
776{
777 "ipv6 address prefix-list",
778 ospf6_routemap_rule_match_address_prefixlist,
779 ospf6_routemap_rule_match_address_prefixlist_compile,
780 ospf6_routemap_rule_match_address_prefixlist_free,
781};
hassoe26bbeb2003-05-25 21:39:29 +0000782
Paul Jakma6ac29a52008-08-15 13:45:30 +0100783static route_map_result_t
hasso508e53e2004-05-18 18:57:06 +0000784ospf6_routemap_rule_set_metric_type (void *rule, struct prefix *prefix,
785 route_map_object_t type, void *object)
786{
787 char *metric_type = rule;
788 struct ospf6_route *route = object;
hassoe26bbeb2003-05-25 21:39:29 +0000789
hasso508e53e2004-05-18 18:57:06 +0000790 if (type != RMAP_OSPF6)
791 return RMAP_OKAY;
paul718e3742002-12-13 20:15:29 +0000792
hasso508e53e2004-05-18 18:57:06 +0000793 if (strcmp (metric_type, "type-2") == 0)
794 route->path.metric_type = 2;
paul718e3742002-12-13 20:15:29 +0000795 else
hasso508e53e2004-05-18 18:57:06 +0000796 route->path.metric_type = 1;
paul718e3742002-12-13 20:15:29 +0000797
hasso508e53e2004-05-18 18:57:06 +0000798 return RMAP_OKAY;
799}
paul718e3742002-12-13 20:15:29 +0000800
Paul Jakma6ac29a52008-08-15 13:45:30 +0100801static void *
paul0c083ee2004-10-10 12:54:58 +0000802ospf6_routemap_rule_set_metric_type_compile (const char *arg)
hasso508e53e2004-05-18 18:57:06 +0000803{
804 if (strcmp (arg, "type-2") && strcmp (arg, "type-1"))
805 return NULL;
806 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
paul718e3742002-12-13 20:15:29 +0000807}
808
Paul Jakma6ac29a52008-08-15 13:45:30 +0100809static void
hasso508e53e2004-05-18 18:57:06 +0000810ospf6_routemap_rule_set_metric_type_free (void *rule)
paul718e3742002-12-13 20:15:29 +0000811{
hasso508e53e2004-05-18 18:57:06 +0000812 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
813}
paul718e3742002-12-13 20:15:29 +0000814
hasso508e53e2004-05-18 18:57:06 +0000815struct route_map_rule_cmd
816ospf6_routemap_rule_set_metric_type_cmd =
817{
818 "metric-type",
819 ospf6_routemap_rule_set_metric_type,
820 ospf6_routemap_rule_set_metric_type_compile,
821 ospf6_routemap_rule_set_metric_type_free,
822};
paul718e3742002-12-13 20:15:29 +0000823
Paul Jakma6ac29a52008-08-15 13:45:30 +0100824static route_map_result_t
hasso508e53e2004-05-18 18:57:06 +0000825ospf6_routemap_rule_set_metric (void *rule, struct prefix *prefix,
826 route_map_object_t type, void *object)
827{
828 char *metric = rule;
829 struct ospf6_route *route = object;
paul718e3742002-12-13 20:15:29 +0000830
hasso508e53e2004-05-18 18:57:06 +0000831 if (type != RMAP_OSPF6)
832 return RMAP_OKAY;
paul718e3742002-12-13 20:15:29 +0000833
hasso508e53e2004-05-18 18:57:06 +0000834 route->path.cost = atoi (metric);
835 return RMAP_OKAY;
836}
paul718e3742002-12-13 20:15:29 +0000837
Paul Jakma6ac29a52008-08-15 13:45:30 +0100838static void *
paul0c083ee2004-10-10 12:54:58 +0000839ospf6_routemap_rule_set_metric_compile (const char *arg)
hasso508e53e2004-05-18 18:57:06 +0000840{
841 u_int32_t metric;
842 char *endp;
843 metric = strtoul (arg, &endp, 0);
844 if (metric > LS_INFINITY || *endp != '\0')
845 return NULL;
846 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
paul718e3742002-12-13 20:15:29 +0000847}
848
Paul Jakma6ac29a52008-08-15 13:45:30 +0100849static void
hasso508e53e2004-05-18 18:57:06 +0000850ospf6_routemap_rule_set_metric_free (void *rule)
paul718e3742002-12-13 20:15:29 +0000851{
hasso508e53e2004-05-18 18:57:06 +0000852 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
853}
854
855struct route_map_rule_cmd
856ospf6_routemap_rule_set_metric_cmd =
857{
858 "metric",
859 ospf6_routemap_rule_set_metric,
860 ospf6_routemap_rule_set_metric_compile,
861 ospf6_routemap_rule_set_metric_free,
862};
863
Paul Jakma6ac29a52008-08-15 13:45:30 +0100864static route_map_result_t
hasso508e53e2004-05-18 18:57:06 +0000865ospf6_routemap_rule_set_forwarding (void *rule, struct prefix *prefix,
866 route_map_object_t type, void *object)
867{
868 char *forwarding = rule;
869 struct ospf6_route *route = object;
870 struct ospf6_external_info *info = route->route_option;
871
872 if (type != RMAP_OSPF6)
873 return RMAP_OKAY;
874
875 if (inet_pton (AF_INET6, forwarding, &info->forwarding) != 1)
876 {
877 memset (&info->forwarding, 0, sizeof (struct in6_addr));
878 return RMAP_ERROR;
879 }
880
881 return RMAP_OKAY;
882}
883
Paul Jakma6ac29a52008-08-15 13:45:30 +0100884static void *
paul0c083ee2004-10-10 12:54:58 +0000885ospf6_routemap_rule_set_forwarding_compile (const char *arg)
hasso508e53e2004-05-18 18:57:06 +0000886{
887 struct in6_addr a;
888 if (inet_pton (AF_INET6, arg, &a) != 1)
889 return NULL;
890 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
891}
892
Paul Jakma6ac29a52008-08-15 13:45:30 +0100893static void
hasso508e53e2004-05-18 18:57:06 +0000894ospf6_routemap_rule_set_forwarding_free (void *rule)
895{
896 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
897}
898
899struct route_map_rule_cmd
900ospf6_routemap_rule_set_forwarding_cmd =
901{
902 "forwarding-address",
903 ospf6_routemap_rule_set_forwarding,
904 ospf6_routemap_rule_set_forwarding_compile,
905 ospf6_routemap_rule_set_forwarding_free,
906};
907
Paul Jakma6ac29a52008-08-15 13:45:30 +0100908static int
hasso508e53e2004-05-18 18:57:06 +0000909route_map_command_status (struct vty *vty, int ret)
910{
911 if (! ret)
912 return CMD_SUCCESS;
913
914 switch (ret)
915 {
916 case RMAP_RULE_MISSING:
hasso049207c2004-08-04 20:02:13 +0000917 vty_out (vty, "Can't find rule.%s", VNL);
hasso508e53e2004-05-18 18:57:06 +0000918 break;
919 case RMAP_COMPILE_ERROR:
hasso049207c2004-08-04 20:02:13 +0000920 vty_out (vty, "Argument is malformed.%s", VNL);
hasso508e53e2004-05-18 18:57:06 +0000921 break;
922 default:
hasso049207c2004-08-04 20:02:13 +0000923 vty_out (vty, "route-map add set failed.%s", VNL);
hasso508e53e2004-05-18 18:57:06 +0000924 break;
925 }
926 return CMD_WARNING;
927}
928
929/* add "match address" */
930DEFUN (ospf6_routemap_match_address_prefixlist,
931 ospf6_routemap_match_address_prefixlist_cmd,
932 "match ipv6 address prefix-list WORD",
933 "Match values\n"
934 IPV6_STR
935 "Match address of route\n"
936 "Match entries of prefix-lists\n"
937 "IPv6 prefix-list name\n")
938{
939 int ret = route_map_add_match ((struct route_map_index *) vty->index,
940 "ipv6 address prefix-list", argv[0]);
941 return route_map_command_status (vty, ret);
942}
943
944/* delete "match address" */
945DEFUN (ospf6_routemap_no_match_address_prefixlist,
946 ospf6_routemap_no_match_address_prefixlist_cmd,
947 "no match ipv6 address prefix-list WORD",
948 NO_STR
949 "Match values\n"
950 IPV6_STR
951 "Match address of route\n"
952 "Match entries of prefix-lists\n"
953 "IPv6 prefix-list name\n")
954{
955 int ret = route_map_delete_match ((struct route_map_index *) vty->index,
956 "ipv6 address prefix-list", argv[0]);
957 return route_map_command_status (vty, ret);
958}
959
960/* add "set metric-type" */
961DEFUN (ospf6_routemap_set_metric_type,
962 ospf6_routemap_set_metric_type_cmd,
963 "set metric-type (type-1|type-2)",
964 "Set value\n"
965 "Type of metric\n"
966 "OSPF6 external type 1 metric\n"
967 "OSPF6 external type 2 metric\n")
968{
969 int ret = route_map_add_set ((struct route_map_index *) vty->index,
970 "metric-type", argv[0]);
971 return route_map_command_status (vty, ret);
972}
973
974/* delete "set metric-type" */
975DEFUN (ospf6_routemap_no_set_metric_type,
976 ospf6_routemap_no_set_metric_type_cmd,
977 "no set metric-type (type-1|type-2)",
978 NO_STR
979 "Set value\n"
980 "Type of metric\n"
981 "OSPF6 external type 1 metric\n"
982 "OSPF6 external type 2 metric\n")
983{
984 int ret = route_map_delete_set ((struct route_map_index *) vty->index,
985 "metric-type", argv[0]);
986 return route_map_command_status (vty, ret);
987}
988
989/* add "set metric" */
990DEFUN (set_metric,
991 set_metric_cmd,
992 "set metric <0-4294967295>",
993 "Set value\n"
994 "Metric value\n"
995 "Metric value\n")
996{
997 int ret = route_map_add_set ((struct route_map_index *) vty->index,
998 "metric", argv[0]);
999 return route_map_command_status (vty, ret);
1000}
1001
1002/* delete "set metric" */
1003DEFUN (no_set_metric,
1004 no_set_metric_cmd,
1005 "no set metric <0-4294967295>",
1006 NO_STR
1007 "Set value\n"
1008 "Metric\n"
1009 "METRIC value\n")
1010{
1011 int ret = route_map_delete_set ((struct route_map_index *) vty->index,
1012 "metric", argv[0]);
1013 return route_map_command_status (vty, ret);
1014}
1015
1016/* add "set forwarding-address" */
1017DEFUN (ospf6_routemap_set_forwarding,
1018 ospf6_routemap_set_forwarding_cmd,
1019 "set forwarding-address X:X::X:X",
1020 "Set value\n"
1021 "Forwarding Address\n"
1022 "IPv6 Address\n")
1023{
1024 int ret = route_map_add_set ((struct route_map_index *) vty->index,
1025 "forwarding-address", argv[0]);
1026 return route_map_command_status (vty, ret);
1027}
1028
1029/* delete "set forwarding-address" */
1030DEFUN (ospf6_routemap_no_set_forwarding,
1031 ospf6_routemap_no_set_forwarding_cmd,
1032 "no set forwarding-address X:X::X:X",
1033 NO_STR
1034 "Set value\n"
1035 "Forwarding Address\n"
1036 "IPv6 Address\n")
1037{
1038 int ret = route_map_delete_set ((struct route_map_index *) vty->index,
1039 "forwarding-address", argv[0]);
1040 return route_map_command_status (vty, ret);
1041}
1042
Paul Jakma6ac29a52008-08-15 13:45:30 +01001043static void
1044ospf6_routemap_init (void)
hasso508e53e2004-05-18 18:57:06 +00001045{
1046 route_map_init ();
1047 route_map_init_vty ();
1048 route_map_add_hook (ospf6_asbr_routemap_update);
1049 route_map_delete_hook (ospf6_asbr_routemap_update);
1050
1051 route_map_install_match (&ospf6_routemap_rule_match_address_prefixlist_cmd);
1052 route_map_install_set (&ospf6_routemap_rule_set_metric_type_cmd);
1053 route_map_install_set (&ospf6_routemap_rule_set_metric_cmd);
1054 route_map_install_set (&ospf6_routemap_rule_set_forwarding_cmd);
1055
1056 /* Match address prefix-list */
1057 install_element (RMAP_NODE, &ospf6_routemap_match_address_prefixlist_cmd);
1058 install_element (RMAP_NODE, &ospf6_routemap_no_match_address_prefixlist_cmd);
1059
1060 /* ASE Metric Type (e.g. Type-1/Type-2) */
1061 install_element (RMAP_NODE, &ospf6_routemap_set_metric_type_cmd);
1062 install_element (RMAP_NODE, &ospf6_routemap_no_set_metric_type_cmd);
1063
1064 /* ASE Metric */
1065 install_element (RMAP_NODE, &set_metric_cmd);
1066 install_element (RMAP_NODE, &no_set_metric_cmd);
1067
1068 /* ASE Metric */
1069 install_element (RMAP_NODE, &ospf6_routemap_set_forwarding_cmd);
1070 install_element (RMAP_NODE, &ospf6_routemap_no_set_forwarding_cmd);
1071}
1072
1073
1074/* Display functions */
Paul Jakma6ac29a52008-08-15 13:45:30 +01001075static int
hasso508e53e2004-05-18 18:57:06 +00001076ospf6_as_external_lsa_show (struct vty *vty, struct ospf6_lsa *lsa)
1077{
1078 struct ospf6_as_external_lsa *external;
paul718e3742002-12-13 20:15:29 +00001079 char buf[64];
hasso508e53e2004-05-18 18:57:06 +00001080 struct in6_addr in6, *forwarding;
paul718e3742002-12-13 20:15:29 +00001081
1082 assert (lsa->header);
hasso508e53e2004-05-18 18:57:06 +00001083 external = (struct ospf6_as_external_lsa *)
1084 OSPF6_LSA_HEADER_END (lsa->header);
paul718e3742002-12-13 20:15:29 +00001085
1086 /* bits */
hasso508e53e2004-05-18 18:57:06 +00001087 snprintf (buf, sizeof (buf), "%c%c%c",
1088 (CHECK_FLAG (external->bits_metric, OSPF6_ASBR_BIT_E) ? 'E' : '-'),
1089 (CHECK_FLAG (external->bits_metric, OSPF6_ASBR_BIT_F) ? 'F' : '-'),
1090 (CHECK_FLAG (external->bits_metric, OSPF6_ASBR_BIT_T) ? 'T' : '-'));
paul718e3742002-12-13 20:15:29 +00001091
hasso049207c2004-08-04 20:02:13 +00001092 vty_out (vty, " Bits: %s%s", buf, VNL);
hasso508e53e2004-05-18 18:57:06 +00001093 vty_out (vty, " Metric: %5lu%s", (u_long) OSPF6_ASBR_METRIC (external),
hasso049207c2004-08-04 20:02:13 +00001094 VNL);
paul718e3742002-12-13 20:15:29 +00001095
hasso508e53e2004-05-18 18:57:06 +00001096 ospf6_prefix_options_printbuf (external->prefix.prefix_options,
1097 buf, sizeof (buf));
1098 vty_out (vty, " Prefix Options: %s%s", buf,
hasso049207c2004-08-04 20:02:13 +00001099 VNL);
paul718e3742002-12-13 20:15:29 +00001100
1101 vty_out (vty, " Referenced LSType: %d%s",
hasso508e53e2004-05-18 18:57:06 +00001102 ntohs (external->prefix.prefix_refer_lstype),
hasso049207c2004-08-04 20:02:13 +00001103 VNL);
paul718e3742002-12-13 20:15:29 +00001104
hasso508e53e2004-05-18 18:57:06 +00001105 ospf6_prefix_in6_addr (&in6, &external->prefix);
paul718e3742002-12-13 20:15:29 +00001106 inet_ntop (AF_INET6, &in6, buf, sizeof (buf));
hasso508e53e2004-05-18 18:57:06 +00001107 vty_out (vty, " Prefix: %s/%d%s", buf,
hasso049207c2004-08-04 20:02:13 +00001108 external->prefix.prefix_length, VNL);
paul718e3742002-12-13 20:15:29 +00001109
1110 /* Forwarding-Address */
1111 if (CHECK_FLAG (external->bits_metric, OSPF6_ASBR_BIT_F))
1112 {
hasso508e53e2004-05-18 18:57:06 +00001113 forwarding = (struct in6_addr *)
1114 ((caddr_t) external + sizeof (struct ospf6_as_external_lsa) +
1115 OSPF6_PREFIX_SPACE (external->prefix.prefix_length));
1116 inet_ntop (AF_INET6, forwarding, buf, sizeof (buf));
hasso049207c2004-08-04 20:02:13 +00001117 vty_out (vty, " Forwarding-Address: %s%s", buf, VNL);
paul718e3742002-12-13 20:15:29 +00001118 }
1119
1120 return 0;
1121}
1122
Paul Jakma6ac29a52008-08-15 13:45:30 +01001123static void
hasso508e53e2004-05-18 18:57:06 +00001124ospf6_asbr_external_route_show (struct vty *vty, struct ospf6_route *route)
paul718e3742002-12-13 20:15:29 +00001125{
hasso508e53e2004-05-18 18:57:06 +00001126 struct ospf6_external_info *info = route->route_option;
1127 char prefix[64], id[16], forwarding[64];
1128 u_int32_t tmp_id;
1129
1130 prefix2str (&route->prefix, prefix, sizeof (prefix));
1131 tmp_id = ntohl (info->id);
1132 inet_ntop (AF_INET, &tmp_id, id, sizeof (id));
1133 if (! IN6_IS_ADDR_UNSPECIFIED (&info->forwarding))
1134 inet_ntop (AF_INET6, &info->forwarding, forwarding, sizeof (forwarding));
1135 else
1136 snprintf (forwarding, sizeof (forwarding), ":: (ifindex %d)",
1137 route->nexthop[0].ifindex);
1138
ajsf52d13c2005-10-01 17:38:06 +00001139 vty_out (vty, "%c %-32s %-15s type-%d %5lu %s%s",
1140 zebra_route_char(info->type),
hasso508e53e2004-05-18 18:57:06 +00001141 prefix, id, route->path.metric_type,
1142 (u_long) (route->path.metric_type == 2 ?
1143 route->path.cost_e2 : route->path.cost),
hasso049207c2004-08-04 20:02:13 +00001144 forwarding, VNL);
paul718e3742002-12-13 20:15:29 +00001145}
1146
hasso508e53e2004-05-18 18:57:06 +00001147DEFUN (show_ipv6_ospf6_redistribute,
1148 show_ipv6_ospf6_redistribute_cmd,
1149 "show ipv6 ospf6 redistribute",
paul718e3742002-12-13 20:15:29 +00001150 SHOW_STR
1151 IP6_STR
paul718e3742002-12-13 20:15:29 +00001152 OSPF6_STR
1153 "redistributing External information\n"
1154 )
1155{
hasso508e53e2004-05-18 18:57:06 +00001156 struct ospf6_route *route;
paul718e3742002-12-13 20:15:29 +00001157
hasso508e53e2004-05-18 18:57:06 +00001158 ospf6_redistribute_show_config (vty);
1159
1160 for (route = ospf6_route_head (ospf6->external_table); route;
1161 route = ospf6_route_next (route))
1162 ospf6_asbr_external_route_show (vty, route);
1163
paul718e3742002-12-13 20:15:29 +00001164 return CMD_SUCCESS;
1165}
1166
hasso6452df02004-08-15 05:52:07 +00001167struct ospf6_lsa_handler as_external_handler =
hasso508e53e2004-05-18 18:57:06 +00001168{
hasso6452df02004-08-15 05:52:07 +00001169 OSPF6_LSTYPE_AS_EXTERNAL,
1170 "AS-External",
1171 ospf6_as_external_lsa_show
1172};
hasso508e53e2004-05-18 18:57:06 +00001173
paul718e3742002-12-13 20:15:29 +00001174void
Paul Jakma6ac29a52008-08-15 13:45:30 +01001175ospf6_asbr_init (void)
paul718e3742002-12-13 20:15:29 +00001176{
hasso508e53e2004-05-18 18:57:06 +00001177 ospf6_routemap_init ();
paul718e3742002-12-13 20:15:29 +00001178
hasso6452df02004-08-15 05:52:07 +00001179 ospf6_install_lsa_handler (&as_external_handler);
paul718e3742002-12-13 20:15:29 +00001180
hasso508e53e2004-05-18 18:57:06 +00001181 install_element (VIEW_NODE, &show_ipv6_ospf6_redistribute_cmd);
1182 install_element (ENABLE_NODE, &show_ipv6_ospf6_redistribute_cmd);
1183
paul718e3742002-12-13 20:15:29 +00001184 install_element (OSPF6_NODE, &ospf6_redistribute_cmd);
1185 install_element (OSPF6_NODE, &ospf6_redistribute_routemap_cmd);
1186 install_element (OSPF6_NODE, &no_ospf6_redistribute_cmd);
1187}
1188
1189
hasso508e53e2004-05-18 18:57:06 +00001190DEFUN (debug_ospf6_asbr,
1191 debug_ospf6_asbr_cmd,
1192 "debug ospf6 asbr",
1193 DEBUG_STR
1194 OSPF6_STR
1195 "Debug OSPFv3 ASBR function\n"
1196 )
1197{
1198 OSPF6_DEBUG_ASBR_ON ();
1199 return CMD_SUCCESS;
1200}
1201
1202DEFUN (no_debug_ospf6_asbr,
1203 no_debug_ospf6_asbr_cmd,
1204 "no debug ospf6 asbr",
1205 NO_STR
1206 DEBUG_STR
1207 OSPF6_STR
1208 "Debug OSPFv3 ASBR function\n"
1209 )
1210{
1211 OSPF6_DEBUG_ASBR_OFF ();
1212 return CMD_SUCCESS;
1213}
1214
1215int
1216config_write_ospf6_debug_asbr (struct vty *vty)
1217{
1218 if (IS_OSPF6_DEBUG_ASBR)
hasso049207c2004-08-04 20:02:13 +00001219 vty_out (vty, "debug ospf6 asbr%s", VNL);
hasso508e53e2004-05-18 18:57:06 +00001220 return 0;
1221}
1222
1223void
1224install_element_ospf6_debug_asbr ()
1225{
1226 install_element (ENABLE_NODE, &debug_ospf6_asbr_cmd);
1227 install_element (ENABLE_NODE, &no_debug_ospf6_asbr_cmd);
1228 install_element (CONFIG_NODE, &debug_ospf6_asbr_cmd);
1229 install_element (CONFIG_NODE, &no_debug_ospf6_asbr_cmd);
1230}
1231
1232