blob: 7980a643dbf299e9895c8be3f71b87ed196f90f5 [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 */
56void
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;
paul718e3742002-12-13 20:15:29 +000062
hasso508e53e2004-05-18 18:57:06 +000063 struct ospf6_as_external_lsa *as_external_lsa;
64 char buf[64];
65 caddr_t p;
paul718e3742002-12-13 20:15:29 +000066
hasso508e53e2004-05-18 18:57:06 +000067 /* find previous LSA */
68 old = ospf6_lsdb_lookup (htons (OSPF6_LSTYPE_AS_EXTERNAL),
hasso6452df02004-08-15 05:52:07 +000069 route->path.origin.id, ospf6->router_id,
hasso508e53e2004-05-18 18:57:06 +000070 ospf6->lsdb);
71
hasso1e058382004-09-01 21:36:14 +000072 if (IS_OSPF6_DEBUG_ASBR || IS_OSPF6_DEBUG_ORIGINATE (AS_EXTERNAL))
hasso508e53e2004-05-18 18:57:06 +000073 {
74 prefix2str (&route->prefix, buf, sizeof (buf));
hassoc6487d62004-12-24 06:00:11 +000075 zlog_debug ("Originate AS-External-LSA for %s", buf);
hasso508e53e2004-05-18 18:57:06 +000076 }
77
78 /* prepare buffer */
79 memset (buffer, 0, sizeof (buffer));
80 lsa_header = (struct ospf6_lsa_header *) buffer;
81 as_external_lsa = (struct ospf6_as_external_lsa *)
82 ((caddr_t) lsa_header + sizeof (struct ospf6_lsa_header));
83 p = (caddr_t)
84 ((caddr_t) as_external_lsa + sizeof (struct ospf6_as_external_lsa));
85
86 /* Fill AS-External-LSA */
87 /* Metric type */
88 if (route->path.metric_type == 2)
89 SET_FLAG (as_external_lsa->bits_metric, OSPF6_ASBR_BIT_E);
90 else
91 UNSET_FLAG (as_external_lsa->bits_metric, OSPF6_ASBR_BIT_E);
92
93 /* forwarding address */
hasso6452df02004-08-15 05:52:07 +000094 if (! IN6_IS_ADDR_UNSPECIFIED (&route->nexthop[0].address))
hasso508e53e2004-05-18 18:57:06 +000095 SET_FLAG (as_external_lsa->bits_metric, OSPF6_ASBR_BIT_F);
96 else
97 UNSET_FLAG (as_external_lsa->bits_metric, OSPF6_ASBR_BIT_F);
98
99 /* external route tag */
100 UNSET_FLAG (as_external_lsa->bits_metric, OSPF6_ASBR_BIT_T);
101
102 /* Set metric */
103 OSPF6_ASBR_METRIC_SET (as_external_lsa, route->path.cost);
104
105 /* prefixlen */
106 as_external_lsa->prefix.prefix_length = route->prefix.prefixlen;
107
108 /* PrefixOptions */
109 as_external_lsa->prefix.prefix_options = route->path.prefix_options;
110
111 /* don't use refer LS-type */
112 as_external_lsa->prefix.prefix_refer_lstype = htons (0);
113
114 /* set Prefix */
115 memcpy (p, &route->prefix.u.prefix6,
116 OSPF6_PREFIX_SPACE (route->prefix.prefixlen));
117 ospf6_prefix_apply_mask (&as_external_lsa->prefix);
118 p += OSPF6_PREFIX_SPACE (route->prefix.prefixlen);
119
120 /* Forwarding address */
121 if (CHECK_FLAG (as_external_lsa->bits_metric, OSPF6_ASBR_BIT_F))
122 {
hasso6452df02004-08-15 05:52:07 +0000123 memcpy (p, &route->nexthop[0].address, sizeof (struct in6_addr));
hasso508e53e2004-05-18 18:57:06 +0000124 p += sizeof (struct in6_addr);
125 }
126
127 /* External Route Tag */
128 if (CHECK_FLAG (as_external_lsa->bits_metric, OSPF6_ASBR_BIT_T))
129 {
130 /* xxx */
131 }
132
133 /* Fill LSA Header */
134 lsa_header->age = 0;
135 lsa_header->type = htons (OSPF6_LSTYPE_AS_EXTERNAL);
hasso6452df02004-08-15 05:52:07 +0000136 lsa_header->id = route->path.origin.id;
hasso508e53e2004-05-18 18:57:06 +0000137 lsa_header->adv_router = ospf6->router_id;
138 lsa_header->seqnum =
hasso049207c2004-08-04 20:02:13 +0000139 ospf6_new_ls_seqnum (lsa_header->type, lsa_header->id,
140 lsa_header->adv_router, ospf6->lsdb);
hasso508e53e2004-05-18 18:57:06 +0000141 lsa_header->length = htons ((caddr_t) p - (caddr_t) lsa_header);
142
143 /* LSA checksum */
144 ospf6_lsa_checksum (lsa_header);
145
146 /* create LSA */
147 lsa = ospf6_lsa_create (lsa_header);
hasso508e53e2004-05-18 18:57:06 +0000148
149 /* Originate */
hasso6452df02004-08-15 05:52:07 +0000150 ospf6_lsa_originate_process (lsa, ospf6);
hasso508e53e2004-05-18 18:57:06 +0000151}
152
hasso508e53e2004-05-18 18:57:06 +0000153
154void
155ospf6_asbr_lsa_add (struct ospf6_lsa *lsa)
156{
157 struct ospf6_as_external_lsa *external;
158 struct prefix asbr_id;
159 struct ospf6_route *asbr_entry, *route;
160 char buf[64];
161 int i;
162
163 external = (struct ospf6_as_external_lsa *)
164 OSPF6_LSA_HEADER_END (lsa->header);
165
hasso1e058382004-09-01 21:36:14 +0000166 if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL))
hassoc6487d62004-12-24 06:00:11 +0000167 zlog_debug ("Calculate AS-External route for %s", lsa->name);
hasso508e53e2004-05-18 18:57:06 +0000168
169 if (lsa->header->adv_router == ospf6->router_id)
170 {
hasso1e058382004-09-01 21:36:14 +0000171 if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL))
hassoc6487d62004-12-24 06:00:11 +0000172 zlog_debug ("Ignore self-originated AS-External-LSA");
hasso508e53e2004-05-18 18:57:06 +0000173 return;
174 }
175
176 if (OSPF6_ASBR_METRIC (external) == LS_INFINITY)
177 {
hasso1e058382004-09-01 21:36:14 +0000178 if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL))
hassoc6487d62004-12-24 06:00:11 +0000179 zlog_debug ("Ignore LSA with LSInfinity Metric");
hasso508e53e2004-05-18 18:57:06 +0000180 return;
181 }
182
hassoccb59b12004-08-25 09:10:37 +0000183 ospf6_linkstate_prefix (lsa->header->adv_router, htonl (0), &asbr_id);
hasso6452df02004-08-15 05:52:07 +0000184 asbr_entry = ospf6_route_lookup (&asbr_id, ospf6->brouter_table);
hasso63069ad2004-09-02 13:01:01 +0000185 if (asbr_entry == NULL ||
186 ! CHECK_FLAG (asbr_entry->path.router_bits, OSPF6_ROUTER_BIT_E))
hasso508e53e2004-05-18 18:57:06 +0000187 {
hasso1e058382004-09-01 21:36:14 +0000188 if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL))
hasso508e53e2004-05-18 18:57:06 +0000189 {
190 prefix2str (&asbr_id, buf, sizeof (buf));
hassoc6487d62004-12-24 06:00:11 +0000191 zlog_debug ("ASBR entry not found: %s", buf);
hasso508e53e2004-05-18 18:57:06 +0000192 }
193 return;
194 }
195
196 route = ospf6_route_create ();
197 route->type = OSPF6_DEST_TYPE_NETWORK;
198 route->prefix.family = AF_INET6;
199 route->prefix.prefixlen = external->prefix.prefix_length;
200 ospf6_prefix_in6_addr (&route->prefix.u.prefix6, &external->prefix);
201
202 route->path.area_id = asbr_entry->path.area_id;
203 route->path.origin.type = lsa->header->type;
204 route->path.origin.id = lsa->header->id;
205 route->path.origin.adv_router = lsa->header->adv_router;
206
207 route->path.prefix_options = external->prefix.prefix_options;
208 if (CHECK_FLAG (external->bits_metric, OSPF6_ASBR_BIT_E))
209 {
210 route->path.type = OSPF6_PATH_TYPE_EXTERNAL2;
211 route->path.metric_type = 2;
212 route->path.cost = asbr_entry->path.cost;
213 route->path.cost_e2 = OSPF6_ASBR_METRIC (external);
214 }
215 else
216 {
217 route->path.type = OSPF6_PATH_TYPE_EXTERNAL1;
218 route->path.metric_type = 1;
219 route->path.cost = asbr_entry->path.cost + OSPF6_ASBR_METRIC (external);
220 route->path.cost_e2 = 0;
221 }
222
223 for (i = 0; i < OSPF6_MULTI_PATH_LIMIT; i++)
224 ospf6_nexthop_copy (&route->nexthop[i], &asbr_entry->nexthop[i]);
225
hasso1e058382004-09-01 21:36:14 +0000226 if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL))
hasso508e53e2004-05-18 18:57:06 +0000227 {
228 prefix2str (&route->prefix, buf, sizeof (buf));
hassoc6487d62004-12-24 06:00:11 +0000229 zlog_debug ("AS-External route add: %s", buf);
hasso508e53e2004-05-18 18:57:06 +0000230 }
231
232 ospf6_route_add (route, ospf6->route_table);
233}
234
235void
236ospf6_asbr_lsa_remove (struct ospf6_lsa *lsa)
237{
238 struct ospf6_as_external_lsa *external;
239 struct prefix prefix;
240 struct ospf6_route *route;
241 char buf[64];
242
243 external = (struct ospf6_as_external_lsa *)
244 OSPF6_LSA_HEADER_END (lsa->header);
245
hasso1e058382004-09-01 21:36:14 +0000246 if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL))
hassoc6487d62004-12-24 06:00:11 +0000247 zlog_debug ("Withdraw AS-External route for %s", lsa->name);
hasso508e53e2004-05-18 18:57:06 +0000248
249 if (lsa->header->adv_router == ospf6->router_id)
250 {
hasso1e058382004-09-01 21:36:14 +0000251 if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL))
hassoc6487d62004-12-24 06:00:11 +0000252 zlog_debug ("Ignore self-originated AS-External-LSA");
hasso508e53e2004-05-18 18:57:06 +0000253 return;
254 }
255
256 memset (&prefix, 0, sizeof (struct prefix));
257 prefix.family = AF_INET6;
258 prefix.prefixlen = external->prefix.prefix_length;
259 ospf6_prefix_in6_addr (&prefix.u.prefix6, &external->prefix);
260
261 route = ospf6_route_lookup (&prefix, ospf6->route_table);
262 if (route == NULL)
263 {
hasso1e058382004-09-01 21:36:14 +0000264 if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL))
hasso508e53e2004-05-18 18:57:06 +0000265 {
266 prefix2str (&prefix, buf, sizeof (buf));
hassoc6487d62004-12-24 06:00:11 +0000267 zlog_debug ("AS-External route %s not found", buf);
hasso508e53e2004-05-18 18:57:06 +0000268 }
269 return;
270 }
271
272 for (ospf6_route_lock (route);
273 route && ospf6_route_is_prefix (&prefix, route);
274 route = ospf6_route_next (route))
275 {
276 if (route->type != OSPF6_DEST_TYPE_NETWORK)
277 continue;
278 if (route->path.origin.type != lsa->header->type)
279 continue;
280 if (route->path.origin.id != lsa->header->id)
281 continue;
282 if (route->path.origin.adv_router != lsa->header->adv_router)
283 continue;
284
hasso1e058382004-09-01 21:36:14 +0000285 if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL))
hasso508e53e2004-05-18 18:57:06 +0000286 {
287 prefix2str (&route->prefix, buf, sizeof (buf));
hassoc6487d62004-12-24 06:00:11 +0000288 zlog_debug ("AS-External route remove: %s", buf);
hasso508e53e2004-05-18 18:57:06 +0000289 }
290 ospf6_route_remove (route, ospf6->route_table);
291 }
292}
293
294void
295ospf6_asbr_lsentry_add (struct ospf6_route *asbr_entry)
296{
hasso508e53e2004-05-18 18:57:06 +0000297 struct ospf6_lsa *lsa;
298 u_int16_t type;
299 u_int32_t router;
300
Paul Jakmacb4b8842006-05-15 10:39:30 +0000301 if (! CHECK_FLAG (asbr_entry->flag, OSPF6_ROUTE_BEST))
hasso508e53e2004-05-18 18:57:06 +0000302 {
Paul Jakmacb4b8842006-05-15 10:39:30 +0000303 char buf[16];
304 inet_ntop (AF_INET, &ADV_ROUTER_IN_PREFIX (&asbr_entry->prefix),
305 buf, sizeof (buf));
306 zlog_info ("ignore non-best path: lsentry %s add", buf);
307 return;
hasso508e53e2004-05-18 18:57:06 +0000308 }
309
310 type = htons (OSPF6_LSTYPE_AS_EXTERNAL);
311 router = ospf6_linkstate_prefix_adv_router (&asbr_entry->prefix);
Paul Jakmacb4b8842006-05-15 10:39:30 +0000312 for (lsa = ospf6_lsdb_type_router_head (type, router, ospf6->lsdb); lsa;
313 lsa = ospf6_lsdb_type_router_next (type, router, lsa))
hasso508e53e2004-05-18 18:57:06 +0000314 {
315 if (! OSPF6_LSA_IS_MAXAGE (lsa))
316 ospf6_asbr_lsa_add (lsa);
317 }
hasso508e53e2004-05-18 18:57:06 +0000318}
319
320void
321ospf6_asbr_lsentry_remove (struct ospf6_route *asbr_entry)
322{
hasso508e53e2004-05-18 18:57:06 +0000323 struct ospf6_lsa *lsa;
324 u_int16_t type;
325 u_int32_t router;
326
Paul Jakmacb4b8842006-05-15 10:39:30 +0000327 if (! CHECK_FLAG (asbr_entry->flag, OSPF6_ROUTE_BEST))
hasso508e53e2004-05-18 18:57:06 +0000328 {
Paul Jakmacb4b8842006-05-15 10:39:30 +0000329 char buf[16];
330 inet_ntop (AF_INET, &ADV_ROUTER_IN_PREFIX (&asbr_entry->prefix),
331 buf, sizeof (buf));
332 zlog_info ("ignore non-best path: lsentry %s remove", buf);
333 return;
hasso508e53e2004-05-18 18:57:06 +0000334 }
335
336 type = htons (OSPF6_LSTYPE_AS_EXTERNAL);
337 router = ospf6_linkstate_prefix_adv_router (&asbr_entry->prefix);
338 for (lsa = ospf6_lsdb_type_router_head (type, router, ospf6->lsdb);
339 lsa; lsa = ospf6_lsdb_type_router_next (type, router, lsa))
340 ospf6_asbr_lsa_remove (lsa);
hasso508e53e2004-05-18 18:57:06 +0000341}
342
343
344
paul718e3742002-12-13 20:15:29 +0000345/* redistribute function */
hasso508e53e2004-05-18 18:57:06 +0000346
paul718e3742002-12-13 20:15:29 +0000347void
paul0c083ee2004-10-10 12:54:58 +0000348ospf6_asbr_routemap_set (int type, const char *mapname)
paul718e3742002-12-13 20:15:29 +0000349{
hasso508e53e2004-05-18 18:57:06 +0000350 if (ospf6->rmap[type].name)
351 free (ospf6->rmap[type].name);
352 ospf6->rmap[type].name = strdup (mapname);
353 ospf6->rmap[type].map = route_map_lookup_by_name (mapname);
paul718e3742002-12-13 20:15:29 +0000354}
355
356void
357ospf6_asbr_routemap_unset (int type)
358{
hasso508e53e2004-05-18 18:57:06 +0000359 if (ospf6->rmap[type].name)
360 free (ospf6->rmap[type].name);
361 ospf6->rmap[type].name = NULL;
362 ospf6->rmap[type].map = NULL;
paul718e3742002-12-13 20:15:29 +0000363}
364
365void
paul0c083ee2004-10-10 12:54:58 +0000366ospf6_asbr_routemap_update (const char *mapname)
paul718e3742002-12-13 20:15:29 +0000367{
hasso508e53e2004-05-18 18:57:06 +0000368 int type;
369
370 if (ospf6 == NULL)
371 return;
372
373 for (type = 0; type < ZEBRA_ROUTE_MAX; type++)
paul718e3742002-12-13 20:15:29 +0000374 {
hasso508e53e2004-05-18 18:57:06 +0000375 if (ospf6->rmap[type].name)
376 ospf6->rmap[type].map =
377 route_map_lookup_by_name (ospf6->rmap[type].name);
paul718e3742002-12-13 20:15:29 +0000378 else
hasso508e53e2004-05-18 18:57:06 +0000379 ospf6->rmap[type].map = NULL;
380 }
381}
382
383int
384ospf6_asbr_is_asbr (struct ospf6 *o)
385{
386 return o->external_table->count;
387}
388
389void
390ospf6_asbr_redistribute_set (int type)
391{
392 ospf6_zebra_redistribute (type);
393}
394
395void
396ospf6_asbr_redistribute_unset (int type)
397{
398 struct ospf6_route *route;
399 struct ospf6_external_info *info;
400
401 ospf6_zebra_no_redistribute (type);
402
403 for (route = ospf6_route_head (ospf6->external_table); route;
404 route = ospf6_route_next (route))
405 {
406 info = route->route_option;
407 if (info->type != type)
408 continue;
409
410 ospf6_asbr_redistribute_remove (info->type, route->nexthop[0].ifindex,
411 &route->prefix);
412 }
413}
414
415void
416ospf6_asbr_redistribute_add (int type, int ifindex, struct prefix *prefix,
417 u_int nexthop_num, struct in6_addr *nexthop)
418{
419 int ret;
420 struct ospf6_route troute;
421 struct ospf6_external_info tinfo;
422 struct ospf6_route *route, *match;
423 struct ospf6_external_info *info;
424 struct prefix prefix_id;
425 struct route_node *node;
426 char pbuf[64], ibuf[16];
paul1eb8ef22005-04-07 07:30:20 +0000427 struct listnode *lnode, *lnnode;
hasso508e53e2004-05-18 18:57:06 +0000428 struct ospf6_area *oa;
429
430 if (! ospf6_zebra_is_redistribute (type))
431 return;
432
433 if (IS_OSPF6_DEBUG_ASBR)
434 {
435 prefix2str (prefix, pbuf, sizeof (pbuf));
hassoc6487d62004-12-24 06:00:11 +0000436 zlog_debug ("Redistribute %s (%s)", pbuf, ZROUTE_NAME (type));
hasso508e53e2004-05-18 18:57:06 +0000437 }
438
439 /* if route-map was specified but not found, do not advertise */
440 if (ospf6->rmap[type].name)
441 {
442 if (ospf6->rmap[type].map == NULL)
hasso03d52f82004-09-29 00:26:19 +0000443 ospf6_asbr_routemap_update (NULL);
hasso508e53e2004-05-18 18:57:06 +0000444 if (ospf6->rmap[type].map == NULL)
445 {
446 zlog_warn ("route-map \"%s\" not found, suppress redistributing",
447 ospf6->rmap[type].name);
448 return;
449 }
450 }
451
452 /* apply route-map */
453 if (ospf6->rmap[type].map)
454 {
455 memset (&troute, 0, sizeof (troute));
456 memset (&tinfo, 0, sizeof (tinfo));
457 troute.route_option = &tinfo;
458
459 ret = route_map_apply (ospf6->rmap[type].map, prefix,
460 RMAP_OSPF6, &troute);
paul47828742005-08-10 15:46:11 +0000461 if (ret == RMAP_DENYMATCH)
hasso508e53e2004-05-18 18:57:06 +0000462 {
463 if (IS_OSPF6_DEBUG_ASBR)
hassoc6487d62004-12-24 06:00:11 +0000464 zlog_debug ("Denied by route-map \"%s\"", ospf6->rmap[type].name);
hasso508e53e2004-05-18 18:57:06 +0000465 return;
466 }
467 }
468
469 match = ospf6_route_lookup (prefix, ospf6->external_table);
470 if (match)
471 {
472 info = match->route_option;
473
474 /* copy result of route-map */
475 if (ospf6->rmap[type].map)
476 {
477 if (troute.path.metric_type)
478 match->path.metric_type = troute.path.metric_type;
479 if (troute.path.cost)
480 match->path.cost = troute.path.cost;
481 if (! IN6_IS_ADDR_UNSPECIFIED (&tinfo.forwarding))
482 memcpy (&info->forwarding, &tinfo.forwarding,
483 sizeof (struct in6_addr));
484 }
485
486 info->type = type;
487 match->nexthop[0].ifindex = ifindex;
488 if (nexthop_num && nexthop)
489 memcpy (&match->nexthop[0].address, nexthop, sizeof (struct in6_addr));
490
491 /* create/update binding in external_id_table */
492 prefix_id.family = AF_INET;
493 prefix_id.prefixlen = 32;
494 prefix_id.u.prefix4.s_addr = htonl (info->id);
495 node = route_node_get (ospf6->external_id_table, &prefix_id);
496 node->info = match;
497
498 if (IS_OSPF6_DEBUG_ASBR)
499 {
500 inet_ntop (AF_INET, &prefix_id.u.prefix4, ibuf, sizeof (ibuf));
hassoc6487d62004-12-24 06:00:11 +0000501 zlog_debug ("Advertise as AS-External Id:%s", ibuf);
hasso508e53e2004-05-18 18:57:06 +0000502 }
503
hasso3b687352004-08-19 06:56:53 +0000504 match->path.origin.id = htonl (info->id);
hasso6452df02004-08-15 05:52:07 +0000505 ospf6_as_external_lsa_originate (match);
hasso508e53e2004-05-18 18:57:06 +0000506 return;
507 }
508
509 /* create new entry */
510 route = ospf6_route_create ();
511 route->type = OSPF6_DEST_TYPE_NETWORK;
512 memcpy (&route->prefix, prefix, sizeof (struct prefix));
513
514 info = (struct ospf6_external_info *)
515 XMALLOC (MTYPE_OSPF6_EXTERNAL_INFO, sizeof (struct ospf6_external_info));
516 memset (info, 0, sizeof (struct ospf6_external_info));
517 route->route_option = info;
518 info->id = ospf6->external_id++;
519
520 /* copy result of route-map */
521 if (ospf6->rmap[type].map)
522 {
523 if (troute.path.metric_type)
524 route->path.metric_type = troute.path.metric_type;
525 if (troute.path.cost)
526 route->path.cost = troute.path.cost;
527 if (! IN6_IS_ADDR_UNSPECIFIED (&tinfo.forwarding))
528 memcpy (&info->forwarding, &tinfo.forwarding,
529 sizeof (struct in6_addr));
530 }
531
532 info->type = type;
533 route->nexthop[0].ifindex = ifindex;
534 if (nexthop_num && nexthop)
535 memcpy (&route->nexthop[0].address, nexthop, sizeof (struct in6_addr));
536
537 /* create/update binding in external_id_table */
538 prefix_id.family = AF_INET;
539 prefix_id.prefixlen = 32;
540 prefix_id.u.prefix4.s_addr = htonl (info->id);
541 node = route_node_get (ospf6->external_id_table, &prefix_id);
542 node->info = route;
543
544 route = ospf6_route_add (route, ospf6->external_table);
545 route->route_option = info;
546
547 if (IS_OSPF6_DEBUG_ASBR)
548 {
549 inet_ntop (AF_INET, &prefix_id.u.prefix4, ibuf, sizeof (ibuf));
hassoc6487d62004-12-24 06:00:11 +0000550 zlog_debug ("Advertise as AS-External Id:%s", ibuf);
hasso508e53e2004-05-18 18:57:06 +0000551 }
552
hasso3b687352004-08-19 06:56:53 +0000553 route->path.origin.id = htonl (info->id);
hasso6452df02004-08-15 05:52:07 +0000554 ospf6_as_external_lsa_originate (route);
hasso508e53e2004-05-18 18:57:06 +0000555
556 /* Router-Bit (ASBR Flag) may have to be updated */
paul1eb8ef22005-04-07 07:30:20 +0000557 for (ALL_LIST_ELEMENTS (ospf6->area_list, lnode, lnnode, oa))
558 OSPF6_ROUTER_LSA_SCHEDULE (oa);
hasso508e53e2004-05-18 18:57:06 +0000559}
560
561void
562ospf6_asbr_redistribute_remove (int type, int ifindex, struct prefix *prefix)
563{
564 struct ospf6_route *match;
565 struct ospf6_external_info *info = NULL;
566 struct route_node *node;
567 struct ospf6_lsa *lsa;
568 struct prefix prefix_id;
569 char pbuf[64], ibuf[16];
paul1eb8ef22005-04-07 07:30:20 +0000570 struct listnode *lnode, *lnnode;
hasso508e53e2004-05-18 18:57:06 +0000571 struct ospf6_area *oa;
572
573 match = ospf6_route_lookup (prefix, ospf6->external_table);
574 if (match == NULL)
575 {
576 if (IS_OSPF6_DEBUG_ASBR)
577 {
578 prefix2str (prefix, pbuf, sizeof (pbuf));
hassoc6487d62004-12-24 06:00:11 +0000579 zlog_debug ("No such route %s to withdraw", pbuf);
hasso508e53e2004-05-18 18:57:06 +0000580 }
581 return;
582 }
583
584 info = match->route_option;
585 assert (info);
586
587 if (info->type != type)
588 {
589 if (IS_OSPF6_DEBUG_ASBR)
590 {
591 prefix2str (prefix, pbuf, sizeof (pbuf));
hassoc6487d62004-12-24 06:00:11 +0000592 zlog_debug ("Original protocol mismatch: %s", pbuf);
hasso508e53e2004-05-18 18:57:06 +0000593 }
594 return;
595 }
596
597 if (IS_OSPF6_DEBUG_ASBR)
598 {
599 prefix2str (prefix, pbuf, sizeof (pbuf));
600 inet_ntop (AF_INET, &prefix_id.u.prefix4, ibuf, sizeof (ibuf));
hassoc6487d62004-12-24 06:00:11 +0000601 zlog_debug ("Withdraw %s (AS-External Id:%s)", pbuf, ibuf);
hasso508e53e2004-05-18 18:57:06 +0000602 }
603
604 lsa = ospf6_lsdb_lookup (htons (OSPF6_LSTYPE_AS_EXTERNAL),
605 htonl (info->id), ospf6->router_id, ospf6->lsdb);
606 if (lsa)
hasso6452df02004-08-15 05:52:07 +0000607 ospf6_lsa_purge (lsa);
hasso508e53e2004-05-18 18:57:06 +0000608
609 /* remove binding in external_id_table */
610 prefix_id.family = AF_INET;
611 prefix_id.prefixlen = 32;
612 prefix_id.u.prefix4.s_addr = htonl (info->id);
613 node = route_node_lookup (ospf6->external_id_table, &prefix_id);
614 assert (node);
615 node->info = NULL;
616 route_unlock_node (node);
617
618 ospf6_route_remove (match, ospf6->external_table);
619 XFREE (MTYPE_OSPF6_EXTERNAL_INFO, info);
620
621 /* Router-Bit (ASBR Flag) may have to be updated */
paul1eb8ef22005-04-07 07:30:20 +0000622 for (ALL_LIST_ELEMENTS (ospf6->area_list, lnode, lnnode, oa))
623 OSPF6_ROUTER_LSA_SCHEDULE (oa);
paul718e3742002-12-13 20:15:29 +0000624}
625
626DEFUN (ospf6_redistribute,
627 ospf6_redistribute_cmd,
628 "redistribute (static|kernel|connected|ripng|bgp)",
629 "Redistribute\n"
630 "Static route\n"
631 "Kernel route\n"
632 "Connected route\n"
633 "RIPng route\n"
634 "BGP route\n"
635 )
636{
637 int type = 0;
638
639 if (strncmp (argv[0], "sta", 3) == 0)
640 type = ZEBRA_ROUTE_STATIC;
641 else if (strncmp (argv[0], "ker", 3) == 0)
642 type = ZEBRA_ROUTE_KERNEL;
643 else if (strncmp (argv[0], "con", 3) == 0)
644 type = ZEBRA_ROUTE_CONNECT;
645 else if (strncmp (argv[0], "rip", 3) == 0)
646 type = ZEBRA_ROUTE_RIPNG;
647 else if (strncmp (argv[0], "bgp", 3) == 0)
648 type = ZEBRA_ROUTE_BGP;
649
hasso508e53e2004-05-18 18:57:06 +0000650 ospf6_asbr_redistribute_unset (type);
paul718e3742002-12-13 20:15:29 +0000651 ospf6_asbr_routemap_unset (type);
hasso508e53e2004-05-18 18:57:06 +0000652 ospf6_asbr_redistribute_set (type);
paul718e3742002-12-13 20:15:29 +0000653 return CMD_SUCCESS;
654}
655
656DEFUN (ospf6_redistribute_routemap,
657 ospf6_redistribute_routemap_cmd,
658 "redistribute (static|kernel|connected|ripng|bgp) route-map WORD",
659 "Redistribute\n"
660 "Static routes\n"
661 "Kernel route\n"
662 "Connected route\n"
663 "RIPng route\n"
664 "BGP route\n"
665 "Route map reference\n"
666 "Route map name\n"
667 )
668{
669 int type = 0;
670
671 if (strncmp (argv[0], "sta", 3) == 0)
672 type = ZEBRA_ROUTE_STATIC;
673 else if (strncmp (argv[0], "ker", 3) == 0)
674 type = ZEBRA_ROUTE_KERNEL;
675 else if (strncmp (argv[0], "con", 3) == 0)
676 type = ZEBRA_ROUTE_CONNECT;
677 else if (strncmp (argv[0], "rip", 3) == 0)
678 type = ZEBRA_ROUTE_RIPNG;
679 else if (strncmp (argv[0], "bgp", 3) == 0)
680 type = ZEBRA_ROUTE_BGP;
681
hasso508e53e2004-05-18 18:57:06 +0000682 ospf6_asbr_redistribute_unset (type);
paul718e3742002-12-13 20:15:29 +0000683 ospf6_asbr_routemap_set (type, argv[1]);
hasso508e53e2004-05-18 18:57:06 +0000684 ospf6_asbr_redistribute_set (type);
paul718e3742002-12-13 20:15:29 +0000685 return CMD_SUCCESS;
686}
687
688DEFUN (no_ospf6_redistribute,
689 no_ospf6_redistribute_cmd,
690 "no redistribute (static|kernel|connected|ripng|bgp)",
691 NO_STR
692 "Redistribute\n"
693 "Static route\n"
694 "Kernel route\n"
695 "Connected route\n"
696 "RIPng route\n"
697 "BGP route\n"
698 )
699{
700 int type = 0;
paul718e3742002-12-13 20:15:29 +0000701
702 if (strncmp (argv[0], "sta", 3) == 0)
703 type = ZEBRA_ROUTE_STATIC;
704 else if (strncmp (argv[0], "ker", 3) == 0)
705 type = ZEBRA_ROUTE_KERNEL;
706 else if (strncmp (argv[0], "con", 3) == 0)
707 type = ZEBRA_ROUTE_CONNECT;
708 else if (strncmp (argv[0], "rip", 3) == 0)
709 type = ZEBRA_ROUTE_RIPNG;
710 else if (strncmp (argv[0], "bgp", 3) == 0)
711 type = ZEBRA_ROUTE_BGP;
712
hasso508e53e2004-05-18 18:57:06 +0000713 ospf6_asbr_redistribute_unset (type);
paul718e3742002-12-13 20:15:29 +0000714 ospf6_asbr_routemap_unset (type);
715
paul718e3742002-12-13 20:15:29 +0000716 return CMD_SUCCESS;
717}
718
paul718e3742002-12-13 20:15:29 +0000719int
720ospf6_redistribute_config_write (struct vty *vty)
721{
hasso508e53e2004-05-18 18:57:06 +0000722 int type;
paul718e3742002-12-13 20:15:29 +0000723
hasso508e53e2004-05-18 18:57:06 +0000724 for (type = 0; type < ZEBRA_ROUTE_MAX; type++)
paul718e3742002-12-13 20:15:29 +0000725 {
hasso508e53e2004-05-18 18:57:06 +0000726 if (type == ZEBRA_ROUTE_OSPF6)
727 continue;
728 if (! ospf6_zebra_is_redistribute (type))
paul718e3742002-12-13 20:15:29 +0000729 continue;
730
hasso508e53e2004-05-18 18:57:06 +0000731 if (ospf6->rmap[type].name)
paul718e3742002-12-13 20:15:29 +0000732 vty_out (vty, " redistribute %s route-map %s%s",
hasso049207c2004-08-04 20:02:13 +0000733 ZROUTE_NAME (type), ospf6->rmap[type].name, VNL);
paul718e3742002-12-13 20:15:29 +0000734 else
735 vty_out (vty, " redistribute %s%s",
hasso049207c2004-08-04 20:02:13 +0000736 ZROUTE_NAME (type), VNL);
paul718e3742002-12-13 20:15:29 +0000737 }
738
739 return 0;
740}
741
742void
743ospf6_redistribute_show_config (struct vty *vty)
744{
hasso508e53e2004-05-18 18:57:06 +0000745 int type;
746 int nroute[ZEBRA_ROUTE_MAX];
747 int total;
748 struct ospf6_route *route;
paul718e3742002-12-13 20:15:29 +0000749 struct ospf6_external_info *info;
paul718e3742002-12-13 20:15:29 +0000750
hasso508e53e2004-05-18 18:57:06 +0000751 total = 0;
752 for (type = 0; type < ZEBRA_ROUTE_MAX; type++)
753 nroute[type] = 0;
754 for (route = ospf6_route_head (ospf6->external_table); route;
755 route = ospf6_route_next (route))
paul718e3742002-12-13 20:15:29 +0000756 {
hasso508e53e2004-05-18 18:57:06 +0000757 info = route->route_option;
758 nroute[info->type]++;
759 total++;
paul718e3742002-12-13 20:15:29 +0000760 }
761
hasso049207c2004-08-04 20:02:13 +0000762 vty_out (vty, "Redistributing External Routes from:%s", VNL);
hasso508e53e2004-05-18 18:57:06 +0000763 for (type = 0; type < ZEBRA_ROUTE_MAX; type++)
paul718e3742002-12-13 20:15:29 +0000764 {
hasso508e53e2004-05-18 18:57:06 +0000765 if (type == ZEBRA_ROUTE_OSPF6)
766 continue;
767 if (! ospf6_zebra_is_redistribute (type))
hassoe26bbeb2003-05-25 21:39:29 +0000768 continue;
769
hasso508e53e2004-05-18 18:57:06 +0000770 if (ospf6->rmap[type].name)
771 vty_out (vty, " %d: %s with route-map \"%s\"%s%s", nroute[type],
772 ZROUTE_NAME (type), ospf6->rmap[type].name,
773 (ospf6->rmap[type].map ? "" : " (not found !)"),
hasso049207c2004-08-04 20:02:13 +0000774 VNL);
paul718e3742002-12-13 20:15:29 +0000775 else
hasso508e53e2004-05-18 18:57:06 +0000776 vty_out (vty, " %d: %s%s", nroute[type],
hasso049207c2004-08-04 20:02:13 +0000777 ZROUTE_NAME (type), VNL);
paul718e3742002-12-13 20:15:29 +0000778 }
hasso049207c2004-08-04 20:02:13 +0000779 vty_out (vty, "Total %d routes%s", total, VNL);
hasso508e53e2004-05-18 18:57:06 +0000780}
paul718e3742002-12-13 20:15:29 +0000781
paul718e3742002-12-13 20:15:29 +0000782
hasso508e53e2004-05-18 18:57:06 +0000783
784/* Routemap Functions */
785route_map_result_t
786ospf6_routemap_rule_match_address_prefixlist (void *rule,
787 struct prefix *prefix,
788 route_map_object_t type,
789 void *object)
790{
791 struct prefix_list *plist;
paul718e3742002-12-13 20:15:29 +0000792
hasso508e53e2004-05-18 18:57:06 +0000793 if (type != RMAP_OSPF6)
794 return RMAP_NOMATCH;
paul718e3742002-12-13 20:15:29 +0000795
hasso508e53e2004-05-18 18:57:06 +0000796 plist = prefix_list_lookup (AFI_IP6, (char *) rule);
797 if (plist == NULL)
798 return RMAP_NOMATCH;
paul718e3742002-12-13 20:15:29 +0000799
hasso508e53e2004-05-18 18:57:06 +0000800 return (prefix_list_apply (plist, prefix) == PREFIX_DENY ?
801 RMAP_NOMATCH : RMAP_MATCH);
802}
paul718e3742002-12-13 20:15:29 +0000803
hasso508e53e2004-05-18 18:57:06 +0000804void *
paul0c083ee2004-10-10 12:54:58 +0000805ospf6_routemap_rule_match_address_prefixlist_compile (const char *arg)
hasso508e53e2004-05-18 18:57:06 +0000806{
807 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
paul718e3742002-12-13 20:15:29 +0000808}
809
810void
hasso508e53e2004-05-18 18:57:06 +0000811ospf6_routemap_rule_match_address_prefixlist_free (void *rule)
paul718e3742002-12-13 20:15:29 +0000812{
hasso508e53e2004-05-18 18:57:06 +0000813 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
814}
paul718e3742002-12-13 20:15:29 +0000815
hasso508e53e2004-05-18 18:57:06 +0000816struct route_map_rule_cmd
817ospf6_routemap_rule_match_address_prefixlist_cmd =
818{
819 "ipv6 address prefix-list",
820 ospf6_routemap_rule_match_address_prefixlist,
821 ospf6_routemap_rule_match_address_prefixlist_compile,
822 ospf6_routemap_rule_match_address_prefixlist_free,
823};
hassoe26bbeb2003-05-25 21:39:29 +0000824
hasso508e53e2004-05-18 18:57:06 +0000825route_map_result_t
826ospf6_routemap_rule_set_metric_type (void *rule, struct prefix *prefix,
827 route_map_object_t type, void *object)
828{
829 char *metric_type = rule;
830 struct ospf6_route *route = object;
hassoe26bbeb2003-05-25 21:39:29 +0000831
hasso508e53e2004-05-18 18:57:06 +0000832 if (type != RMAP_OSPF6)
833 return RMAP_OKAY;
paul718e3742002-12-13 20:15:29 +0000834
hasso508e53e2004-05-18 18:57:06 +0000835 if (strcmp (metric_type, "type-2") == 0)
836 route->path.metric_type = 2;
paul718e3742002-12-13 20:15:29 +0000837 else
hasso508e53e2004-05-18 18:57:06 +0000838 route->path.metric_type = 1;
paul718e3742002-12-13 20:15:29 +0000839
hasso508e53e2004-05-18 18:57:06 +0000840 return RMAP_OKAY;
841}
paul718e3742002-12-13 20:15:29 +0000842
hasso508e53e2004-05-18 18:57:06 +0000843void *
paul0c083ee2004-10-10 12:54:58 +0000844ospf6_routemap_rule_set_metric_type_compile (const char *arg)
hasso508e53e2004-05-18 18:57:06 +0000845{
846 if (strcmp (arg, "type-2") && strcmp (arg, "type-1"))
847 return NULL;
848 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
paul718e3742002-12-13 20:15:29 +0000849}
850
851void
hasso508e53e2004-05-18 18:57:06 +0000852ospf6_routemap_rule_set_metric_type_free (void *rule)
paul718e3742002-12-13 20:15:29 +0000853{
hasso508e53e2004-05-18 18:57:06 +0000854 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
855}
paul718e3742002-12-13 20:15:29 +0000856
hasso508e53e2004-05-18 18:57:06 +0000857struct route_map_rule_cmd
858ospf6_routemap_rule_set_metric_type_cmd =
859{
860 "metric-type",
861 ospf6_routemap_rule_set_metric_type,
862 ospf6_routemap_rule_set_metric_type_compile,
863 ospf6_routemap_rule_set_metric_type_free,
864};
paul718e3742002-12-13 20:15:29 +0000865
hasso508e53e2004-05-18 18:57:06 +0000866route_map_result_t
867ospf6_routemap_rule_set_metric (void *rule, struct prefix *prefix,
868 route_map_object_t type, void *object)
869{
870 char *metric = rule;
871 struct ospf6_route *route = object;
paul718e3742002-12-13 20:15:29 +0000872
hasso508e53e2004-05-18 18:57:06 +0000873 if (type != RMAP_OSPF6)
874 return RMAP_OKAY;
paul718e3742002-12-13 20:15:29 +0000875
hasso508e53e2004-05-18 18:57:06 +0000876 route->path.cost = atoi (metric);
877 return RMAP_OKAY;
878}
paul718e3742002-12-13 20:15:29 +0000879
hasso508e53e2004-05-18 18:57:06 +0000880void *
paul0c083ee2004-10-10 12:54:58 +0000881ospf6_routemap_rule_set_metric_compile (const char *arg)
hasso508e53e2004-05-18 18:57:06 +0000882{
883 u_int32_t metric;
884 char *endp;
885 metric = strtoul (arg, &endp, 0);
886 if (metric > LS_INFINITY || *endp != '\0')
887 return NULL;
888 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
paul718e3742002-12-13 20:15:29 +0000889}
890
891void
hasso508e53e2004-05-18 18:57:06 +0000892ospf6_routemap_rule_set_metric_free (void *rule)
paul718e3742002-12-13 20:15:29 +0000893{
hasso508e53e2004-05-18 18:57:06 +0000894 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
895}
896
897struct route_map_rule_cmd
898ospf6_routemap_rule_set_metric_cmd =
899{
900 "metric",
901 ospf6_routemap_rule_set_metric,
902 ospf6_routemap_rule_set_metric_compile,
903 ospf6_routemap_rule_set_metric_free,
904};
905
906route_map_result_t
907ospf6_routemap_rule_set_forwarding (void *rule, struct prefix *prefix,
908 route_map_object_t type, void *object)
909{
910 char *forwarding = rule;
911 struct ospf6_route *route = object;
912 struct ospf6_external_info *info = route->route_option;
913
914 if (type != RMAP_OSPF6)
915 return RMAP_OKAY;
916
917 if (inet_pton (AF_INET6, forwarding, &info->forwarding) != 1)
918 {
919 memset (&info->forwarding, 0, sizeof (struct in6_addr));
920 return RMAP_ERROR;
921 }
922
923 return RMAP_OKAY;
924}
925
926void *
paul0c083ee2004-10-10 12:54:58 +0000927ospf6_routemap_rule_set_forwarding_compile (const char *arg)
hasso508e53e2004-05-18 18:57:06 +0000928{
929 struct in6_addr a;
930 if (inet_pton (AF_INET6, arg, &a) != 1)
931 return NULL;
932 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
933}
934
935void
936ospf6_routemap_rule_set_forwarding_free (void *rule)
937{
938 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
939}
940
941struct route_map_rule_cmd
942ospf6_routemap_rule_set_forwarding_cmd =
943{
944 "forwarding-address",
945 ospf6_routemap_rule_set_forwarding,
946 ospf6_routemap_rule_set_forwarding_compile,
947 ospf6_routemap_rule_set_forwarding_free,
948};
949
950int
951route_map_command_status (struct vty *vty, int ret)
952{
953 if (! ret)
954 return CMD_SUCCESS;
955
956 switch (ret)
957 {
958 case RMAP_RULE_MISSING:
hasso049207c2004-08-04 20:02:13 +0000959 vty_out (vty, "Can't find rule.%s", VNL);
hasso508e53e2004-05-18 18:57:06 +0000960 break;
961 case RMAP_COMPILE_ERROR:
hasso049207c2004-08-04 20:02:13 +0000962 vty_out (vty, "Argument is malformed.%s", VNL);
hasso508e53e2004-05-18 18:57:06 +0000963 break;
964 default:
hasso049207c2004-08-04 20:02:13 +0000965 vty_out (vty, "route-map add set failed.%s", VNL);
hasso508e53e2004-05-18 18:57:06 +0000966 break;
967 }
968 return CMD_WARNING;
969}
970
971/* add "match address" */
972DEFUN (ospf6_routemap_match_address_prefixlist,
973 ospf6_routemap_match_address_prefixlist_cmd,
974 "match ipv6 address prefix-list WORD",
975 "Match values\n"
976 IPV6_STR
977 "Match address of route\n"
978 "Match entries of prefix-lists\n"
979 "IPv6 prefix-list name\n")
980{
981 int ret = route_map_add_match ((struct route_map_index *) vty->index,
982 "ipv6 address prefix-list", argv[0]);
983 return route_map_command_status (vty, ret);
984}
985
986/* delete "match address" */
987DEFUN (ospf6_routemap_no_match_address_prefixlist,
988 ospf6_routemap_no_match_address_prefixlist_cmd,
989 "no match ipv6 address prefix-list WORD",
990 NO_STR
991 "Match values\n"
992 IPV6_STR
993 "Match address of route\n"
994 "Match entries of prefix-lists\n"
995 "IPv6 prefix-list name\n")
996{
997 int ret = route_map_delete_match ((struct route_map_index *) vty->index,
998 "ipv6 address prefix-list", argv[0]);
999 return route_map_command_status (vty, ret);
1000}
1001
1002/* add "set metric-type" */
1003DEFUN (ospf6_routemap_set_metric_type,
1004 ospf6_routemap_set_metric_type_cmd,
1005 "set metric-type (type-1|type-2)",
1006 "Set value\n"
1007 "Type of metric\n"
1008 "OSPF6 external type 1 metric\n"
1009 "OSPF6 external type 2 metric\n")
1010{
1011 int ret = route_map_add_set ((struct route_map_index *) vty->index,
1012 "metric-type", argv[0]);
1013 return route_map_command_status (vty, ret);
1014}
1015
1016/* delete "set metric-type" */
1017DEFUN (ospf6_routemap_no_set_metric_type,
1018 ospf6_routemap_no_set_metric_type_cmd,
1019 "no set metric-type (type-1|type-2)",
1020 NO_STR
1021 "Set value\n"
1022 "Type of metric\n"
1023 "OSPF6 external type 1 metric\n"
1024 "OSPF6 external type 2 metric\n")
1025{
1026 int ret = route_map_delete_set ((struct route_map_index *) vty->index,
1027 "metric-type", argv[0]);
1028 return route_map_command_status (vty, ret);
1029}
1030
1031/* add "set metric" */
1032DEFUN (set_metric,
1033 set_metric_cmd,
1034 "set metric <0-4294967295>",
1035 "Set value\n"
1036 "Metric value\n"
1037 "Metric value\n")
1038{
1039 int ret = route_map_add_set ((struct route_map_index *) vty->index,
1040 "metric", argv[0]);
1041 return route_map_command_status (vty, ret);
1042}
1043
1044/* delete "set metric" */
1045DEFUN (no_set_metric,
1046 no_set_metric_cmd,
1047 "no set metric <0-4294967295>",
1048 NO_STR
1049 "Set value\n"
1050 "Metric\n"
1051 "METRIC value\n")
1052{
1053 int ret = route_map_delete_set ((struct route_map_index *) vty->index,
1054 "metric", argv[0]);
1055 return route_map_command_status (vty, ret);
1056}
1057
1058/* add "set forwarding-address" */
1059DEFUN (ospf6_routemap_set_forwarding,
1060 ospf6_routemap_set_forwarding_cmd,
1061 "set forwarding-address X:X::X:X",
1062 "Set value\n"
1063 "Forwarding Address\n"
1064 "IPv6 Address\n")
1065{
1066 int ret = route_map_add_set ((struct route_map_index *) vty->index,
1067 "forwarding-address", argv[0]);
1068 return route_map_command_status (vty, ret);
1069}
1070
1071/* delete "set forwarding-address" */
1072DEFUN (ospf6_routemap_no_set_forwarding,
1073 ospf6_routemap_no_set_forwarding_cmd,
1074 "no set forwarding-address X:X::X:X",
1075 NO_STR
1076 "Set value\n"
1077 "Forwarding Address\n"
1078 "IPv6 Address\n")
1079{
1080 int ret = route_map_delete_set ((struct route_map_index *) vty->index,
1081 "forwarding-address", argv[0]);
1082 return route_map_command_status (vty, ret);
1083}
1084
1085void
1086ospf6_routemap_init ()
1087{
1088 route_map_init ();
1089 route_map_init_vty ();
1090 route_map_add_hook (ospf6_asbr_routemap_update);
1091 route_map_delete_hook (ospf6_asbr_routemap_update);
1092
1093 route_map_install_match (&ospf6_routemap_rule_match_address_prefixlist_cmd);
1094 route_map_install_set (&ospf6_routemap_rule_set_metric_type_cmd);
1095 route_map_install_set (&ospf6_routemap_rule_set_metric_cmd);
1096 route_map_install_set (&ospf6_routemap_rule_set_forwarding_cmd);
1097
1098 /* Match address prefix-list */
1099 install_element (RMAP_NODE, &ospf6_routemap_match_address_prefixlist_cmd);
1100 install_element (RMAP_NODE, &ospf6_routemap_no_match_address_prefixlist_cmd);
1101
1102 /* ASE Metric Type (e.g. Type-1/Type-2) */
1103 install_element (RMAP_NODE, &ospf6_routemap_set_metric_type_cmd);
1104 install_element (RMAP_NODE, &ospf6_routemap_no_set_metric_type_cmd);
1105
1106 /* ASE Metric */
1107 install_element (RMAP_NODE, &set_metric_cmd);
1108 install_element (RMAP_NODE, &no_set_metric_cmd);
1109
1110 /* ASE Metric */
1111 install_element (RMAP_NODE, &ospf6_routemap_set_forwarding_cmd);
1112 install_element (RMAP_NODE, &ospf6_routemap_no_set_forwarding_cmd);
1113}
1114
1115
1116/* Display functions */
1117int
1118ospf6_as_external_lsa_show (struct vty *vty, struct ospf6_lsa *lsa)
1119{
1120 struct ospf6_as_external_lsa *external;
paul718e3742002-12-13 20:15:29 +00001121 char buf[64];
hasso508e53e2004-05-18 18:57:06 +00001122 struct in6_addr in6, *forwarding;
paul718e3742002-12-13 20:15:29 +00001123
1124 assert (lsa->header);
hasso508e53e2004-05-18 18:57:06 +00001125 external = (struct ospf6_as_external_lsa *)
1126 OSPF6_LSA_HEADER_END (lsa->header);
paul718e3742002-12-13 20:15:29 +00001127
1128 /* bits */
hasso508e53e2004-05-18 18:57:06 +00001129 snprintf (buf, sizeof (buf), "%c%c%c",
1130 (CHECK_FLAG (external->bits_metric, OSPF6_ASBR_BIT_E) ? 'E' : '-'),
1131 (CHECK_FLAG (external->bits_metric, OSPF6_ASBR_BIT_F) ? 'F' : '-'),
1132 (CHECK_FLAG (external->bits_metric, OSPF6_ASBR_BIT_T) ? 'T' : '-'));
paul718e3742002-12-13 20:15:29 +00001133
hasso049207c2004-08-04 20:02:13 +00001134 vty_out (vty, " Bits: %s%s", buf, VNL);
hasso508e53e2004-05-18 18:57:06 +00001135 vty_out (vty, " Metric: %5lu%s", (u_long) OSPF6_ASBR_METRIC (external),
hasso049207c2004-08-04 20:02:13 +00001136 VNL);
paul718e3742002-12-13 20:15:29 +00001137
hasso508e53e2004-05-18 18:57:06 +00001138 ospf6_prefix_options_printbuf (external->prefix.prefix_options,
1139 buf, sizeof (buf));
1140 vty_out (vty, " Prefix Options: %s%s", buf,
hasso049207c2004-08-04 20:02:13 +00001141 VNL);
paul718e3742002-12-13 20:15:29 +00001142
1143 vty_out (vty, " Referenced LSType: %d%s",
hasso508e53e2004-05-18 18:57:06 +00001144 ntohs (external->prefix.prefix_refer_lstype),
hasso049207c2004-08-04 20:02:13 +00001145 VNL);
paul718e3742002-12-13 20:15:29 +00001146
hasso508e53e2004-05-18 18:57:06 +00001147 ospf6_prefix_in6_addr (&in6, &external->prefix);
paul718e3742002-12-13 20:15:29 +00001148 inet_ntop (AF_INET6, &in6, buf, sizeof (buf));
hasso508e53e2004-05-18 18:57:06 +00001149 vty_out (vty, " Prefix: %s/%d%s", buf,
hasso049207c2004-08-04 20:02:13 +00001150 external->prefix.prefix_length, VNL);
paul718e3742002-12-13 20:15:29 +00001151
1152 /* Forwarding-Address */
1153 if (CHECK_FLAG (external->bits_metric, OSPF6_ASBR_BIT_F))
1154 {
hasso508e53e2004-05-18 18:57:06 +00001155 forwarding = (struct in6_addr *)
1156 ((caddr_t) external + sizeof (struct ospf6_as_external_lsa) +
1157 OSPF6_PREFIX_SPACE (external->prefix.prefix_length));
1158 inet_ntop (AF_INET6, forwarding, buf, sizeof (buf));
hasso049207c2004-08-04 20:02:13 +00001159 vty_out (vty, " Forwarding-Address: %s%s", buf, VNL);
paul718e3742002-12-13 20:15:29 +00001160 }
1161
1162 return 0;
1163}
1164
1165void
hasso508e53e2004-05-18 18:57:06 +00001166ospf6_asbr_external_route_show (struct vty *vty, struct ospf6_route *route)
paul718e3742002-12-13 20:15:29 +00001167{
hasso508e53e2004-05-18 18:57:06 +00001168 struct ospf6_external_info *info = route->route_option;
1169 char prefix[64], id[16], forwarding[64];
1170 u_int32_t tmp_id;
1171
1172 prefix2str (&route->prefix, prefix, sizeof (prefix));
1173 tmp_id = ntohl (info->id);
1174 inet_ntop (AF_INET, &tmp_id, id, sizeof (id));
1175 if (! IN6_IS_ADDR_UNSPECIFIED (&info->forwarding))
1176 inet_ntop (AF_INET6, &info->forwarding, forwarding, sizeof (forwarding));
1177 else
1178 snprintf (forwarding, sizeof (forwarding), ":: (ifindex %d)",
1179 route->nexthop[0].ifindex);
1180
ajsf52d13c2005-10-01 17:38:06 +00001181 vty_out (vty, "%c %-32s %-15s type-%d %5lu %s%s",
1182 zebra_route_char(info->type),
hasso508e53e2004-05-18 18:57:06 +00001183 prefix, id, route->path.metric_type,
1184 (u_long) (route->path.metric_type == 2 ?
1185 route->path.cost_e2 : route->path.cost),
hasso049207c2004-08-04 20:02:13 +00001186 forwarding, VNL);
paul718e3742002-12-13 20:15:29 +00001187}
1188
hasso508e53e2004-05-18 18:57:06 +00001189DEFUN (show_ipv6_ospf6_redistribute,
1190 show_ipv6_ospf6_redistribute_cmd,
1191 "show ipv6 ospf6 redistribute",
paul718e3742002-12-13 20:15:29 +00001192 SHOW_STR
1193 IP6_STR
paul718e3742002-12-13 20:15:29 +00001194 OSPF6_STR
1195 "redistributing External information\n"
1196 )
1197{
hasso508e53e2004-05-18 18:57:06 +00001198 struct ospf6_route *route;
paul718e3742002-12-13 20:15:29 +00001199
hasso508e53e2004-05-18 18:57:06 +00001200 ospf6_redistribute_show_config (vty);
1201
1202 for (route = ospf6_route_head (ospf6->external_table); route;
1203 route = ospf6_route_next (route))
1204 ospf6_asbr_external_route_show (vty, route);
1205
paul718e3742002-12-13 20:15:29 +00001206 return CMD_SUCCESS;
1207}
1208
hasso6452df02004-08-15 05:52:07 +00001209struct ospf6_lsa_handler as_external_handler =
hasso508e53e2004-05-18 18:57:06 +00001210{
hasso6452df02004-08-15 05:52:07 +00001211 OSPF6_LSTYPE_AS_EXTERNAL,
1212 "AS-External",
1213 ospf6_as_external_lsa_show
1214};
hasso508e53e2004-05-18 18:57:06 +00001215
paul718e3742002-12-13 20:15:29 +00001216void
1217ospf6_asbr_init ()
1218{
hasso508e53e2004-05-18 18:57:06 +00001219 ospf6_routemap_init ();
paul718e3742002-12-13 20:15:29 +00001220
hasso6452df02004-08-15 05:52:07 +00001221 ospf6_install_lsa_handler (&as_external_handler);
paul718e3742002-12-13 20:15:29 +00001222
hasso508e53e2004-05-18 18:57:06 +00001223 install_element (VIEW_NODE, &show_ipv6_ospf6_redistribute_cmd);
1224 install_element (ENABLE_NODE, &show_ipv6_ospf6_redistribute_cmd);
1225
paul718e3742002-12-13 20:15:29 +00001226 install_element (OSPF6_NODE, &ospf6_redistribute_cmd);
1227 install_element (OSPF6_NODE, &ospf6_redistribute_routemap_cmd);
1228 install_element (OSPF6_NODE, &no_ospf6_redistribute_cmd);
1229}
1230
1231
hasso508e53e2004-05-18 18:57:06 +00001232DEFUN (debug_ospf6_asbr,
1233 debug_ospf6_asbr_cmd,
1234 "debug ospf6 asbr",
1235 DEBUG_STR
1236 OSPF6_STR
1237 "Debug OSPFv3 ASBR function\n"
1238 )
1239{
1240 OSPF6_DEBUG_ASBR_ON ();
1241 return CMD_SUCCESS;
1242}
1243
1244DEFUN (no_debug_ospf6_asbr,
1245 no_debug_ospf6_asbr_cmd,
1246 "no debug ospf6 asbr",
1247 NO_STR
1248 DEBUG_STR
1249 OSPF6_STR
1250 "Debug OSPFv3 ASBR function\n"
1251 )
1252{
1253 OSPF6_DEBUG_ASBR_OFF ();
1254 return CMD_SUCCESS;
1255}
1256
1257int
1258config_write_ospf6_debug_asbr (struct vty *vty)
1259{
1260 if (IS_OSPF6_DEBUG_ASBR)
hasso049207c2004-08-04 20:02:13 +00001261 vty_out (vty, "debug ospf6 asbr%s", VNL);
hasso508e53e2004-05-18 18:57:06 +00001262 return 0;
1263}
1264
1265void
1266install_element_ospf6_debug_asbr ()
1267{
1268 install_element (ENABLE_NODE, &debug_ospf6_asbr_cmd);
1269 install_element (ENABLE_NODE, &no_debug_ospf6_asbr_cmd);
1270 install_element (CONFIG_NODE, &debug_ospf6_asbr_cmd);
1271 install_element (CONFIG_NODE, &no_debug_ospf6_asbr_cmd);
1272}
1273
1274