]> git.proxmox.com Git - mirror_frr.git/blame - ospf6d/ospf6_asbr.c
ospf6d: add "auto-cost reference-bandwidth" command
[mirror_frr.git] / ospf6d / ospf6_asbr.c
CommitLineData
718e3744 1/*
508e53e2 2 * Copyright (C) 2003 Yasuhiro Ohara
718e3744 3 *
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"
508e53e2 33#include "linklist.h"
718e3744 34
508e53e2 35#include "ospf6_proto.h"
36#include "ospf6_lsa.h"
37#include "ospf6_lsdb.h"
38#include "ospf6_route.h"
718e3744 39#include "ospf6_zebra.h"
6452df09 40#include "ospf6_message.h"
41
718e3744 42#include "ospf6_top.h"
508e53e2 43#include "ospf6_area.h"
6452df09 44#include "ospf6_interface.h"
45#include "ospf6_neighbor.h"
508e53e2 46#include "ospf6_asbr.h"
47#include "ospf6_intra.h"
6452df09 48#include "ospf6_flood.h"
049207c3 49#include "ospf6d.h"
718e3744 50
508e53e2 51unsigned char conf_debug_ospf6_asbr = 0;
718e3744 52
f52d13cb 53#define ZROUTE_NAME(x) zebra_route_string(x)
508e53e2 54
55/* AS External LSA origination */
6ac29a51 56static void
6452df09 57ospf6_as_external_lsa_originate (struct ospf6_route *route)
718e3744 58{
508e53e2 59 char buffer[OSPF6_MAX_LSASIZE];
60 struct ospf6_lsa_header *lsa_header;
61 struct ospf6_lsa *old, *lsa;
0b26f81b 62 struct ospf6_external_info *info = route->route_option;
718e3744 63
508e53e2 64 struct ospf6_as_external_lsa *as_external_lsa;
65 char buf[64];
66 caddr_t p;
718e3744 67
508e53e2 68 /* find previous LSA */
69 old = ospf6_lsdb_lookup (htons (OSPF6_LSTYPE_AS_EXTERNAL),
6452df09 70 route->path.origin.id, ospf6->router_id,
508e53e2 71 ospf6->lsdb);
718e3744 72
1e05838a 73 if (IS_OSPF6_DEBUG_ASBR || IS_OSPF6_DEBUG_ORIGINATE (AS_EXTERNAL))
508e53e2 74 {
75 prefix2str (&route->prefix, buf, sizeof (buf));
c6487d61 76 zlog_debug ("Originate AS-External-LSA for %s", buf);
508e53e2 77 }
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 */
0b26f81b 95 if (! IN6_IS_ADDR_UNSPECIFIED (&info->forwarding))
508e53e2 96 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);
718e3744 99
508e53e2 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 {
0b26f81b 124 memcpy (p, &info->forwarding, sizeof (struct in6_addr));
508e53e2 125 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);
6452df09 137 lsa_header->id = route->path.origin.id;
508e53e2 138 lsa_header->adv_router = ospf6->router_id;
139 lsa_header->seqnum =
049207c3 140 ospf6_new_ls_seqnum (lsa_header->type, lsa_header->id,
141 lsa_header->adv_router, ospf6->lsdb);
508e53e2 142 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);
508e53e2 149
150 /* Originate */
6452df09 151 ospf6_lsa_originate_process (lsa, ospf6);
718e3744 152}
153
508e53e2 154\f
718e3744 155void
508e53e2 156ospf6_asbr_lsa_add (struct ospf6_lsa *lsa)
718e3744 157{
508e53e2 158 struct ospf6_as_external_lsa *external;
159 struct prefix asbr_id;
160 struct ospf6_route *asbr_entry, *route;
161 char buf[64];
718e3744 162 int i;
508e53e2 163
164 external = (struct ospf6_as_external_lsa *)
165 OSPF6_LSA_HEADER_END (lsa->header);
166
1e05838a 167 if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL))
c6487d61 168 zlog_debug ("Calculate AS-External route for %s", lsa->name);
508e53e2 169
170 if (lsa->header->adv_router == ospf6->router_id)
718e3744 171 {
1e05838a 172 if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL))
c6487d61 173 zlog_debug ("Ignore self-originated AS-External-LSA");
508e53e2 174 return;
718e3744 175 }
718e3744 176
8551e6da 177 if (OSPF6_ASBR_METRIC (external) == OSPF_LS_INFINITY)
508e53e2 178 {
1e05838a 179 if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL))
c6487d61 180 zlog_debug ("Ignore LSA with LSInfinity Metric");
508e53e2 181 return;
182 }
718e3744 183
01879114
DD
184 if (CHECK_FLAG(external->prefix.prefix_options, OSPF6_PREFIX_OPTION_NU))
185 {
186 if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL))
187 zlog_debug ("Ignore LSA with NU bit set Metric");
188 return;
189 }
190
ccb59b11 191 ospf6_linkstate_prefix (lsa->header->adv_router, htonl (0), &asbr_id);
6452df09 192 asbr_entry = ospf6_route_lookup (&asbr_id, ospf6->brouter_table);
63069ad6 193 if (asbr_entry == NULL ||
194 ! CHECK_FLAG (asbr_entry->path.router_bits, OSPF6_ROUTER_BIT_E))
508e53e2 195 {
1e05838a 196 if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL))
508e53e2 197 {
198 prefix2str (&asbr_id, buf, sizeof (buf));
c6487d61 199 zlog_debug ("ASBR entry not found: %s", buf);
508e53e2 200 }
201 return;
202 }
718e3744 203
508e53e2 204 route = ospf6_route_create ();
205 route->type = OSPF6_DEST_TYPE_NETWORK;
206 route->prefix.family = AF_INET6;
207 route->prefix.prefixlen = external->prefix.prefix_length;
208 ospf6_prefix_in6_addr (&route->prefix.u.prefix6, &external->prefix);
718e3744 209
508e53e2 210 route->path.area_id = asbr_entry->path.area_id;
211 route->path.origin.type = lsa->header->type;
212 route->path.origin.id = lsa->header->id;
213 route->path.origin.adv_router = lsa->header->adv_router;
718e3744 214
508e53e2 215 route->path.prefix_options = external->prefix.prefix_options;
216 if (CHECK_FLAG (external->bits_metric, OSPF6_ASBR_BIT_E))
217 {
218 route->path.type = OSPF6_PATH_TYPE_EXTERNAL2;
219 route->path.metric_type = 2;
220 route->path.cost = asbr_entry->path.cost;
221 route->path.cost_e2 = OSPF6_ASBR_METRIC (external);
222 }
223 else
224 {
225 route->path.type = OSPF6_PATH_TYPE_EXTERNAL1;
226 route->path.metric_type = 1;
227 route->path.cost = asbr_entry->path.cost + OSPF6_ASBR_METRIC (external);
228 route->path.cost_e2 = 0;
229 }
230
231 for (i = 0; i < OSPF6_MULTI_PATH_LIMIT; i++)
232 ospf6_nexthop_copy (&route->nexthop[i], &asbr_entry->nexthop[i]);
233
1e05838a 234 if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL))
508e53e2 235 {
236 prefix2str (&route->prefix, buf, sizeof (buf));
c6487d61 237 zlog_debug ("AS-External route add: %s", buf);
508e53e2 238 }
239
240 ospf6_route_add (route, ospf6->route_table);
718e3744 241}
242
508e53e2 243void
244ospf6_asbr_lsa_remove (struct ospf6_lsa *lsa)
718e3744 245{
508e53e2 246 struct ospf6_as_external_lsa *external;
247 struct prefix prefix;
248 struct ospf6_route *route;
249 char buf[64];
718e3744 250
508e53e2 251 external = (struct ospf6_as_external_lsa *)
252 OSPF6_LSA_HEADER_END (lsa->header);
718e3744 253
1e05838a 254 if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL))
c6487d61 255 zlog_debug ("Withdraw AS-External route for %s", lsa->name);
718e3744 256
508e53e2 257 if (lsa->header->adv_router == ospf6->router_id)
718e3744 258 {
1e05838a 259 if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL))
c6487d61 260 zlog_debug ("Ignore self-originated AS-External-LSA");
508e53e2 261 return;
262 }
263
264 memset (&prefix, 0, sizeof (struct prefix));
265 prefix.family = AF_INET6;
266 prefix.prefixlen = external->prefix.prefix_length;
267 ospf6_prefix_in6_addr (&prefix.u.prefix6, &external->prefix);
268
269 route = ospf6_route_lookup (&prefix, ospf6->route_table);
270 if (route == NULL)
271 {
1e05838a 272 if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL))
718e3744 273 {
508e53e2 274 prefix2str (&prefix, buf, sizeof (buf));
c6487d61 275 zlog_debug ("AS-External route %s not found", buf);
718e3744 276 }
508e53e2 277 return;
718e3744 278 }
279
508e53e2 280 for (ospf6_route_lock (route);
281 route && ospf6_route_is_prefix (&prefix, route);
282 route = ospf6_route_next (route))
283 {
284 if (route->type != OSPF6_DEST_TYPE_NETWORK)
285 continue;
286 if (route->path.origin.type != lsa->header->type)
287 continue;
288 if (route->path.origin.id != lsa->header->id)
289 continue;
290 if (route->path.origin.adv_router != lsa->header->adv_router)
291 continue;
292
1e05838a 293 if (IS_OSPF6_DEBUG_EXAMIN (AS_EXTERNAL))
508e53e2 294 {
295 prefix2str (&route->prefix, buf, sizeof (buf));
c6487d61 296 zlog_debug ("AS-External route remove: %s", buf);
508e53e2 297 }
298 ospf6_route_remove (route, ospf6->route_table);
299 }
718e3744 300}
301
508e53e2 302void
303ospf6_asbr_lsentry_add (struct ospf6_route *asbr_entry)
304{
508e53e2 305 struct ospf6_lsa *lsa;
306 u_int16_t type;
307 u_int32_t router;
308
cb4b8845 309 if (! CHECK_FLAG (asbr_entry->flag, OSPF6_ROUTE_BEST))
508e53e2 310 {
cb4b8845
PJ
311 char buf[16];
312 inet_ntop (AF_INET, &ADV_ROUTER_IN_PREFIX (&asbr_entry->prefix),
313 buf, sizeof (buf));
314 zlog_info ("ignore non-best path: lsentry %s add", buf);
315 return;
508e53e2 316 }
718e3744 317
508e53e2 318 type = htons (OSPF6_LSTYPE_AS_EXTERNAL);
319 router = ospf6_linkstate_prefix_adv_router (&asbr_entry->prefix);
cb4b8845
PJ
320 for (lsa = ospf6_lsdb_type_router_head (type, router, ospf6->lsdb); lsa;
321 lsa = ospf6_lsdb_type_router_next (type, router, lsa))
508e53e2 322 {
323 if (! OSPF6_LSA_IS_MAXAGE (lsa))
324 ospf6_asbr_lsa_add (lsa);
325 }
508e53e2 326}
327
328void
329ospf6_asbr_lsentry_remove (struct ospf6_route *asbr_entry)
718e3744 330{
508e53e2 331 struct ospf6_lsa *lsa;
332 u_int16_t type;
333 u_int32_t router;
718e3744 334
508e53e2 335 type = htons (OSPF6_LSTYPE_AS_EXTERNAL);
336 router = ospf6_linkstate_prefix_adv_router (&asbr_entry->prefix);
337 for (lsa = ospf6_lsdb_type_router_head (type, router, ospf6->lsdb);
338 lsa; lsa = ospf6_lsdb_type_router_next (type, router, lsa))
339 ospf6_asbr_lsa_remove (lsa);
508e53e2 340}
718e3744 341
508e53e2 342
343\f
344/* redistribute function */
345
6ac29a51 346static void
0c083ee9 347ospf6_asbr_routemap_set (int type, const char *mapname)
508e53e2 348{
349 if (ospf6->rmap[type].name)
350 free (ospf6->rmap[type].name);
351 ospf6->rmap[type].name = strdup (mapname);
352 ospf6->rmap[type].map = route_map_lookup_by_name (mapname);
718e3744 353}
354
6ac29a51 355static void
508e53e2 356ospf6_asbr_routemap_unset (int type)
718e3744 357{
508e53e2 358 if (ospf6->rmap[type].name)
359 free (ospf6->rmap[type].name);
360 ospf6->rmap[type].name = NULL;
361 ospf6->rmap[type].map = NULL;
362}
363
6ac29a51 364static void
0c083ee9 365ospf6_asbr_routemap_update (const char *mapname)
508e53e2 366{
367 int type;
718e3744 368
508e53e2 369 if (ospf6 == NULL)
718e3744 370 return;
371
508e53e2 372 for (type = 0; type < ZEBRA_ROUTE_MAX; type++)
718e3744 373 {
508e53e2 374 if (ospf6->rmap[type].name)
375 ospf6->rmap[type].map =
376 route_map_lookup_by_name (ospf6->rmap[type].name);
718e3744 377 else
508e53e2 378 ospf6->rmap[type].map = NULL;
718e3744 379 }
380}
381
718e3744 382int
508e53e2 383ospf6_asbr_is_asbr (struct ospf6 *o)
384{
385 return o->external_table->count;
386}
387
6ac29a51 388static void
508e53e2 389ospf6_asbr_redistribute_set (int type)
718e3744 390{
508e53e2 391 ospf6_zebra_redistribute (type);
392}
393
6ac29a51 394static void
508e53e2 395ospf6_asbr_redistribute_unset (int type)
396{
397 struct ospf6_route *route;
718e3744 398 struct ospf6_external_info *info;
718e3744 399
508e53e2 400 ospf6_zebra_no_redistribute (type);
401
402 for (route = ospf6_route_head (ospf6->external_table); route;
403 route = ospf6_route_next (route))
404 {
405 info = route->route_option;
406 if (info->type != type)
407 continue;
718e3744 408
508e53e2 409 ospf6_asbr_redistribute_remove (info->type, route->nexthop[0].ifindex,
410 &route->prefix);
411 }
d9628728
CF
412
413 ospf6_asbr_routemap_unset (type);
508e53e2 414}
718e3744 415
508e53e2 416void
417ospf6_asbr_redistribute_add (int type, int ifindex, struct prefix *prefix,
418 u_int nexthop_num, struct in6_addr *nexthop)
419{
420 int ret;
421 struct ospf6_route troute;
422 struct ospf6_external_info tinfo;
423 struct ospf6_route *route, *match;
424 struct ospf6_external_info *info;
425 struct prefix prefix_id;
426 struct route_node *node;
427 char pbuf[64], ibuf[16];
1eb8ef25 428 struct listnode *lnode, *lnnode;
508e53e2 429 struct ospf6_area *oa;
430
431 if (! ospf6_zebra_is_redistribute (type))
432 return;
433
434 if (IS_OSPF6_DEBUG_ASBR)
435 {
436 prefix2str (prefix, pbuf, sizeof (pbuf));
c6487d61 437 zlog_debug ("Redistribute %s (%s)", pbuf, ZROUTE_NAME (type));
508e53e2 438 }
439
440 /* if route-map was specified but not found, do not advertise */
441 if (ospf6->rmap[type].name)
718e3744 442 {
508e53e2 443 if (ospf6->rmap[type].map == NULL)
03d52f8d 444 ospf6_asbr_routemap_update (NULL);
508e53e2 445 if (ospf6->rmap[type].map == NULL)
718e3744 446 {
508e53e2 447 zlog_warn ("route-map \"%s\" not found, suppress redistributing",
448 ospf6->rmap[type].name);
449 return;
718e3744 450 }
718e3744 451 }
452
508e53e2 453 /* apply route-map */
454 if (ospf6->rmap[type].map)
455 {
456 memset (&troute, 0, sizeof (troute));
457 memset (&tinfo, 0, sizeof (tinfo));
458 troute.route_option = &tinfo;
42a7debf 459 tinfo.ifindex = ifindex;
718e3744 460
508e53e2 461 ret = route_map_apply (ospf6->rmap[type].map, prefix,
462 RMAP_OSPF6, &troute);
47828747 463 if (ret == RMAP_DENYMATCH)
508e53e2 464 {
465 if (IS_OSPF6_DEBUG_ASBR)
c6487d61 466 zlog_debug ("Denied by route-map \"%s\"", ospf6->rmap[type].name);
508e53e2 467 return;
468 }
469 }
718e3744 470
508e53e2 471 match = ospf6_route_lookup (prefix, ospf6->external_table);
472 if (match)
473 {
474 info = match->route_option;
718e3744 475
508e53e2 476 /* copy result of route-map */
477 if (ospf6->rmap[type].map)
478 {
479 if (troute.path.metric_type)
480 match->path.metric_type = troute.path.metric_type;
481 if (troute.path.cost)
482 match->path.cost = troute.path.cost;
483 if (! IN6_IS_ADDR_UNSPECIFIED (&tinfo.forwarding))
484 memcpy (&info->forwarding, &tinfo.forwarding,
485 sizeof (struct in6_addr));
486 }
718e3744 487
508e53e2 488 info->type = type;
489 match->nexthop[0].ifindex = ifindex;
490 if (nexthop_num && nexthop)
491 memcpy (&match->nexthop[0].address, nexthop, sizeof (struct in6_addr));
718e3744 492
508e53e2 493 /* create/update binding in external_id_table */
494 prefix_id.family = AF_INET;
495 prefix_id.prefixlen = 32;
496 prefix_id.u.prefix4.s_addr = htonl (info->id);
497 node = route_node_get (ospf6->external_id_table, &prefix_id);
498 node->info = match;
718e3744 499
508e53e2 500 if (IS_OSPF6_DEBUG_ASBR)
501 {
502 inet_ntop (AF_INET, &prefix_id.u.prefix4, ibuf, sizeof (ibuf));
c6487d61 503 zlog_debug ("Advertise as AS-External Id:%s", ibuf);
508e53e2 504 }
718e3744 505
3b68735f 506 match->path.origin.id = htonl (info->id);
6452df09 507 ospf6_as_external_lsa_originate (match);
508e53e2 508 return;
509 }
718e3744 510
508e53e2 511 /* create new entry */
512 route = ospf6_route_create ();
513 route->type = OSPF6_DEST_TYPE_NETWORK;
514 memcpy (&route->prefix, prefix, sizeof (struct prefix));
718e3744 515
508e53e2 516 info = (struct ospf6_external_info *)
393deb9b 517 XCALLOC (MTYPE_OSPF6_EXTERNAL_INFO, sizeof (struct ospf6_external_info));
508e53e2 518 route->route_option = info;
519 info->id = ospf6->external_id++;
520
521 /* copy result of route-map */
522 if (ospf6->rmap[type].map)
718e3744 523 {
508e53e2 524 if (troute.path.metric_type)
525 route->path.metric_type = troute.path.metric_type;
526 if (troute.path.cost)
527 route->path.cost = troute.path.cost;
528 if (! IN6_IS_ADDR_UNSPECIFIED (&tinfo.forwarding))
529 memcpy (&info->forwarding, &tinfo.forwarding,
530 sizeof (struct in6_addr));
718e3744 531 }
532
508e53e2 533 info->type = type;
534 route->nexthop[0].ifindex = ifindex;
535 if (nexthop_num && nexthop)
536 memcpy (&route->nexthop[0].address, nexthop, sizeof (struct in6_addr));
537
538 /* create/update binding in external_id_table */
539 prefix_id.family = AF_INET;
540 prefix_id.prefixlen = 32;
541 prefix_id.u.prefix4.s_addr = htonl (info->id);
542 node = route_node_get (ospf6->external_id_table, &prefix_id);
543 node->info = route;
544
545 route = ospf6_route_add (route, ospf6->external_table);
546 route->route_option = info;
547
548 if (IS_OSPF6_DEBUG_ASBR)
718e3744 549 {
508e53e2 550 inet_ntop (AF_INET, &prefix_id.u.prefix4, ibuf, sizeof (ibuf));
c6487d61 551 zlog_debug ("Advertise as AS-External Id:%s", ibuf);
718e3744 552 }
553
3b68735f 554 route->path.origin.id = htonl (info->id);
6452df09 555 ospf6_as_external_lsa_originate (route);
508e53e2 556
557 /* Router-Bit (ASBR Flag) may have to be updated */
1eb8ef25 558 for (ALL_LIST_ELEMENTS (ospf6->area_list, lnode, lnnode, oa))
559 OSPF6_ROUTER_LSA_SCHEDULE (oa);
718e3744 560}
561
508e53e2 562void
563ospf6_asbr_redistribute_remove (int type, int ifindex, struct prefix *prefix)
718e3744 564{
508e53e2 565 struct ospf6_route *match;
566 struct ospf6_external_info *info = NULL;
567 struct route_node *node;
568 struct ospf6_lsa *lsa;
569 struct prefix prefix_id;
570 char pbuf[64], ibuf[16];
1eb8ef25 571 struct listnode *lnode, *lnnode;
508e53e2 572 struct ospf6_area *oa;
718e3744 573
508e53e2 574 match = ospf6_route_lookup (prefix, ospf6->external_table);
575 if (match == NULL)
718e3744 576 {
508e53e2 577 if (IS_OSPF6_DEBUG_ASBR)
718e3744 578 {
508e53e2 579 prefix2str (prefix, pbuf, sizeof (pbuf));
c6487d61 580 zlog_debug ("No such route %s to withdraw", pbuf);
718e3744 581 }
508e53e2 582 return;
718e3744 583 }
584
508e53e2 585 info = match->route_option;
586 assert (info);
718e3744 587
508e53e2 588 if (info->type != type)
718e3744 589 {
508e53e2 590 if (IS_OSPF6_DEBUG_ASBR)
591 {
592 prefix2str (prefix, pbuf, sizeof (pbuf));
c6487d61 593 zlog_debug ("Original protocol mismatch: %s", pbuf);
508e53e2 594 }
595 return;
718e3744 596 }
597
508e53e2 598 if (IS_OSPF6_DEBUG_ASBR)
599 {
600 prefix2str (prefix, pbuf, sizeof (pbuf));
601 inet_ntop (AF_INET, &prefix_id.u.prefix4, ibuf, sizeof (ibuf));
c6487d61 602 zlog_debug ("Withdraw %s (AS-External Id:%s)", pbuf, ibuf);
508e53e2 603 }
718e3744 604
508e53e2 605 lsa = ospf6_lsdb_lookup (htons (OSPF6_LSTYPE_AS_EXTERNAL),
606 htonl (info->id), ospf6->router_id, ospf6->lsdb);
718e3744 607 if (lsa)
6452df09 608 ospf6_lsa_purge (lsa);
508e53e2 609
610 /* remove binding in external_id_table */
611 prefix_id.family = AF_INET;
612 prefix_id.prefixlen = 32;
613 prefix_id.u.prefix4.s_addr = htonl (info->id);
614 node = route_node_lookup (ospf6->external_id_table, &prefix_id);
615 assert (node);
616 node->info = NULL;
617 route_unlock_node (node);
618
619 ospf6_route_remove (match, ospf6->external_table);
620 XFREE (MTYPE_OSPF6_EXTERNAL_INFO, info);
621
622 /* Router-Bit (ASBR Flag) may have to be updated */
1eb8ef25 623 for (ALL_LIST_ELEMENTS (ospf6->area_list, lnode, lnnode, oa))
624 OSPF6_ROUTER_LSA_SCHEDULE (oa);
718e3744 625}
626
508e53e2 627DEFUN (ospf6_redistribute,
628 ospf6_redistribute_cmd,
e0ca5fde 629 "redistribute " QUAGGA_REDIST_STR_OSPF6D,
508e53e2 630 "Redistribute\n"
e0ca5fde 631 QUAGGA_REDIST_HELP_STR_OSPF6D
508e53e2 632 )
718e3744 633{
e0ca5fde
DL
634 int type;
635
636 type = proto_redistnum(AFI_IP6, argv[0]);
637 if (type < 0 || type == ZEBRA_ROUTE_OSPF6)
638 return CMD_WARNING;
718e3744 639
508e53e2 640 ospf6_asbr_redistribute_unset (type);
508e53e2 641 ospf6_asbr_redistribute_set (type);
642 return CMD_SUCCESS;
643}
718e3744 644
508e53e2 645DEFUN (ospf6_redistribute_routemap,
646 ospf6_redistribute_routemap_cmd,
e0ca5fde 647 "redistribute " QUAGGA_REDIST_STR_OSPF6D " route-map WORD",
508e53e2 648 "Redistribute\n"
e0ca5fde 649 QUAGGA_REDIST_HELP_STR_OSPF6D
508e53e2 650 "Route map reference\n"
651 "Route map name\n"
652 )
653{
e0ca5fde
DL
654 int type;
655
656 type = proto_redistnum(AFI_IP6, argv[0]);
657 if (type < 0 || type == ZEBRA_ROUTE_OSPF6)
658 return CMD_WARNING;
e26bbeba 659
508e53e2 660 ospf6_asbr_redistribute_unset (type);
661 ospf6_asbr_routemap_set (type, argv[1]);
662 ospf6_asbr_redistribute_set (type);
663 return CMD_SUCCESS;
664}
665
666DEFUN (no_ospf6_redistribute,
667 no_ospf6_redistribute_cmd,
e0ca5fde 668 "no redistribute " QUAGGA_REDIST_STR_OSPF6D,
508e53e2 669 NO_STR
670 "Redistribute\n"
e0ca5fde 671 QUAGGA_REDIST_HELP_STR_OSPF6D
508e53e2 672 )
673{
e0ca5fde
DL
674 int type;
675
676 type = proto_redistnum(AFI_IP6, argv[0]);
677 if (type < 0 || type == ZEBRA_ROUTE_OSPF6)
678 return CMD_WARNING;
e26bbeba 679
508e53e2 680 ospf6_asbr_redistribute_unset (type);
e26bbeba 681
508e53e2 682 return CMD_SUCCESS;
683}
718e3744 684
508e53e2 685int
686ospf6_redistribute_config_write (struct vty *vty)
687{
688 int type;
718e3744 689
508e53e2 690 for (type = 0; type < ZEBRA_ROUTE_MAX; type++)
718e3744 691 {
508e53e2 692 if (type == ZEBRA_ROUTE_OSPF6)
693 continue;
694 if (! ospf6_zebra_is_redistribute (type))
695 continue;
718e3744 696
508e53e2 697 if (ospf6->rmap[type].name)
698 vty_out (vty, " redistribute %s route-map %s%s",
049207c3 699 ZROUTE_NAME (type), ospf6->rmap[type].name, VNL);
508e53e2 700 else
701 vty_out (vty, " redistribute %s%s",
049207c3 702 ZROUTE_NAME (type), VNL);
508e53e2 703 }
718e3744 704
705 return 0;
706}
707
6ac29a51 708static void
508e53e2 709ospf6_redistribute_show_config (struct vty *vty)
718e3744 710{
508e53e2 711 int type;
712 int nroute[ZEBRA_ROUTE_MAX];
713 int total;
714 struct ospf6_route *route;
715 struct ospf6_external_info *info;
718e3744 716
508e53e2 717 total = 0;
718 for (type = 0; type < ZEBRA_ROUTE_MAX; type++)
719 nroute[type] = 0;
720 for (route = ospf6_route_head (ospf6->external_table); route;
721 route = ospf6_route_next (route))
718e3744 722 {
508e53e2 723 info = route->route_option;
724 nroute[info->type]++;
725 total++;
718e3744 726 }
727
049207c3 728 vty_out (vty, "Redistributing External Routes from:%s", VNL);
508e53e2 729 for (type = 0; type < ZEBRA_ROUTE_MAX; type++)
718e3744 730 {
508e53e2 731 if (type == ZEBRA_ROUTE_OSPF6)
732 continue;
733 if (! ospf6_zebra_is_redistribute (type))
734 continue;
718e3744 735
508e53e2 736 if (ospf6->rmap[type].name)
737 vty_out (vty, " %d: %s with route-map \"%s\"%s%s", nroute[type],
738 ZROUTE_NAME (type), ospf6->rmap[type].name,
739 (ospf6->rmap[type].map ? "" : " (not found !)"),
049207c3 740 VNL);
718e3744 741 else
508e53e2 742 vty_out (vty, " %d: %s%s", nroute[type],
049207c3 743 ZROUTE_NAME (type), VNL);
718e3744 744 }
049207c3 745 vty_out (vty, "Total %d routes%s", total, VNL);
508e53e2 746}
718e3744 747
718e3744 748
508e53e2 749\f
750/* Routemap Functions */
6ac29a51 751static route_map_result_t
508e53e2 752ospf6_routemap_rule_match_address_prefixlist (void *rule,
753 struct prefix *prefix,
754 route_map_object_t type,
755 void *object)
756{
757 struct prefix_list *plist;
718e3744 758
508e53e2 759 if (type != RMAP_OSPF6)
760 return RMAP_NOMATCH;
718e3744 761
508e53e2 762 plist = prefix_list_lookup (AFI_IP6, (char *) rule);
763 if (plist == NULL)
764 return RMAP_NOMATCH;
718e3744 765
508e53e2 766 return (prefix_list_apply (plist, prefix) == PREFIX_DENY ?
767 RMAP_NOMATCH : RMAP_MATCH);
768}
718e3744 769
6ac29a51 770static void *
0c083ee9 771ospf6_routemap_rule_match_address_prefixlist_compile (const char *arg)
508e53e2 772{
773 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
718e3744 774}
775
6ac29a51 776static void
508e53e2 777ospf6_routemap_rule_match_address_prefixlist_free (void *rule)
718e3744 778{
508e53e2 779 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
780}
718e3744 781
508e53e2 782struct route_map_rule_cmd
783ospf6_routemap_rule_match_address_prefixlist_cmd =
784{
785 "ipv6 address prefix-list",
786 ospf6_routemap_rule_match_address_prefixlist,
787 ospf6_routemap_rule_match_address_prefixlist_compile,
788 ospf6_routemap_rule_match_address_prefixlist_free,
789};
718e3744 790
42a7debf
VT
791/* `match interface IFNAME' */
792/* Match function should return 1 if match is success else return
793 zero. */
794static route_map_result_t
795ospf6_routemap_rule_match_interface (void *rule, struct prefix *prefix,
796 route_map_object_t type, void *object)
797{
798 struct interface *ifp;
799 struct ospf6_external_info *ei;
800
801 if (type == RMAP_OSPF6)
802 {
803 ei = ((struct ospf6_route *) object)->route_option;
804 ifp = if_lookup_by_name ((char *)rule);
805
806 if (ifp != NULL
807 && ei->ifindex == ifp->ifindex)
808 return RMAP_MATCH;
809 }
810
811 return RMAP_NOMATCH;
812}
813
814/* Route map `interface' match statement. `arg' should be
815 interface name. */
816static void *
817ospf6_routemap_rule_match_interface_compile (const char *arg)
818{
819 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
820}
821
822/* Free route map's compiled `interface' value. */
823static void
824ospf6_routemap_rule_match_interface_free (void *rule)
825{
826 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
827}
828
829/* Route map commands for interface matching. */
830struct route_map_rule_cmd
831ospf6_routemap_rule_match_interface_cmd =
832{
833 "interface",
834 ospf6_routemap_rule_match_interface,
835 ospf6_routemap_rule_match_interface_compile,
836 ospf6_routemap_rule_match_interface_free
837};
838
6ac29a51 839static route_map_result_t
508e53e2 840ospf6_routemap_rule_set_metric_type (void *rule, struct prefix *prefix,
841 route_map_object_t type, void *object)
842{
843 char *metric_type = rule;
844 struct ospf6_route *route = object;
718e3744 845
508e53e2 846 if (type != RMAP_OSPF6)
847 return RMAP_OKAY;
718e3744 848
508e53e2 849 if (strcmp (metric_type, "type-2") == 0)
850 route->path.metric_type = 2;
718e3744 851 else
508e53e2 852 route->path.metric_type = 1;
718e3744 853
508e53e2 854 return RMAP_OKAY;
855}
718e3744 856
6ac29a51 857static void *
0c083ee9 858ospf6_routemap_rule_set_metric_type_compile (const char *arg)
508e53e2 859{
860 if (strcmp (arg, "type-2") && strcmp (arg, "type-1"))
861 return NULL;
862 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
718e3744 863}
864
6ac29a51 865static void
508e53e2 866ospf6_routemap_rule_set_metric_type_free (void *rule)
718e3744 867{
508e53e2 868 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
869}
718e3744 870
508e53e2 871struct route_map_rule_cmd
872ospf6_routemap_rule_set_metric_type_cmd =
873{
874 "metric-type",
875 ospf6_routemap_rule_set_metric_type,
876 ospf6_routemap_rule_set_metric_type_compile,
877 ospf6_routemap_rule_set_metric_type_free,
878};
718e3744 879
6ac29a51 880static route_map_result_t
508e53e2 881ospf6_routemap_rule_set_metric (void *rule, struct prefix *prefix,
882 route_map_object_t type, void *object)
883{
884 char *metric = rule;
885 struct ospf6_route *route = object;
718e3744 886
508e53e2 887 if (type != RMAP_OSPF6)
888 return RMAP_OKAY;
718e3744 889
508e53e2 890 route->path.cost = atoi (metric);
891 return RMAP_OKAY;
892}
718e3744 893
6ac29a51 894static void *
0c083ee9 895ospf6_routemap_rule_set_metric_compile (const char *arg)
508e53e2 896{
897 u_int32_t metric;
898 char *endp;
899 metric = strtoul (arg, &endp, 0);
8551e6da 900 if (metric > OSPF_LS_INFINITY || *endp != '\0')
508e53e2 901 return NULL;
902 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
718e3744 903}
904
6ac29a51 905static void
508e53e2 906ospf6_routemap_rule_set_metric_free (void *rule)
718e3744 907{
508e53e2 908 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
909}
718e3744 910
508e53e2 911struct route_map_rule_cmd
912ospf6_routemap_rule_set_metric_cmd =
913{
914 "metric",
915 ospf6_routemap_rule_set_metric,
916 ospf6_routemap_rule_set_metric_compile,
917 ospf6_routemap_rule_set_metric_free,
918};
718e3744 919
6ac29a51 920static route_map_result_t
508e53e2 921ospf6_routemap_rule_set_forwarding (void *rule, struct prefix *prefix,
922 route_map_object_t type, void *object)
923{
924 char *forwarding = rule;
925 struct ospf6_route *route = object;
926 struct ospf6_external_info *info = route->route_option;
718e3744 927
508e53e2 928 if (type != RMAP_OSPF6)
929 return RMAP_OKAY;
718e3744 930
508e53e2 931 if (inet_pton (AF_INET6, forwarding, &info->forwarding) != 1)
718e3744 932 {
508e53e2 933 memset (&info->forwarding, 0, sizeof (struct in6_addr));
934 return RMAP_ERROR;
718e3744 935 }
718e3744 936
508e53e2 937 return RMAP_OKAY;
718e3744 938}
939
6ac29a51 940static void *
0c083ee9 941ospf6_routemap_rule_set_forwarding_compile (const char *arg)
718e3744 942{
508e53e2 943 struct in6_addr a;
944 if (inet_pton (AF_INET6, arg, &a) != 1)
945 return NULL;
946 return XSTRDUP (MTYPE_ROUTE_MAP_COMPILED, arg);
718e3744 947}
948
6ac29a51 949static void
508e53e2 950ospf6_routemap_rule_set_forwarding_free (void *rule)
718e3744 951{
508e53e2 952 XFREE (MTYPE_ROUTE_MAP_COMPILED, rule);
953}
718e3744 954
508e53e2 955struct route_map_rule_cmd
956ospf6_routemap_rule_set_forwarding_cmd =
957{
958 "forwarding-address",
959 ospf6_routemap_rule_set_forwarding,
960 ospf6_routemap_rule_set_forwarding_compile,
961 ospf6_routemap_rule_set_forwarding_free,
962};
718e3744 963
6ac29a51 964static int
508e53e2 965route_map_command_status (struct vty *vty, int ret)
966{
967 if (! ret)
968 return CMD_SUCCESS;
718e3744 969
508e53e2 970 switch (ret)
718e3744 971 {
508e53e2 972 case RMAP_RULE_MISSING:
049207c3 973 vty_out (vty, "Can't find rule.%s", VNL);
508e53e2 974 break;
975 case RMAP_COMPILE_ERROR:
049207c3 976 vty_out (vty, "Argument is malformed.%s", VNL);
508e53e2 977 break;
978 default:
049207c3 979 vty_out (vty, "route-map add set failed.%s", VNL);
508e53e2 980 break;
718e3744 981 }
508e53e2 982 return CMD_WARNING;
983}
718e3744 984
508e53e2 985/* add "match address" */
986DEFUN (ospf6_routemap_match_address_prefixlist,
987 ospf6_routemap_match_address_prefixlist_cmd,
988 "match ipv6 address prefix-list WORD",
989 "Match values\n"
990 IPV6_STR
991 "Match address of route\n"
992 "Match entries of prefix-lists\n"
993 "IPv6 prefix-list name\n")
994{
995 int ret = route_map_add_match ((struct route_map_index *) vty->index,
996 "ipv6 address prefix-list", argv[0]);
997 return route_map_command_status (vty, ret);
998}
999
1000/* delete "match address" */
1001DEFUN (ospf6_routemap_no_match_address_prefixlist,
1002 ospf6_routemap_no_match_address_prefixlist_cmd,
1003 "no match ipv6 address prefix-list WORD",
1004 NO_STR
1005 "Match values\n"
1006 IPV6_STR
1007 "Match address of route\n"
1008 "Match entries of prefix-lists\n"
1009 "IPv6 prefix-list name\n")
1010{
1011 int ret = route_map_delete_match ((struct route_map_index *) vty->index,
1012 "ipv6 address prefix-list", argv[0]);
1013 return route_map_command_status (vty, ret);
1014}
718e3744 1015
42a7debf
VT
1016/* "match interface" */
1017DEFUN (ospf6_routemap_match_interface,
1018 ospf6_routemap_match_interface_cmd,
1019 "match interface WORD",
1020 MATCH_STR
1021 "Match first hop interface of route\n"
1022 "Interface name\n")
1023{
1024 return route_map_add_match ((struct route_map_index *) vty->index,
1025 "interface", argv[0]);
1026}
1027
1028/* "no match interface WORD" */
1029DEFUN (ospf6_routemap_no_match_interface,
1030 ospf6_routemap_no_match_interface_cmd,
1031 "no match interface",
1032 MATCH_STR
1033 NO_STR
1034 "Match first hop interface of route\n")
1035{
1036 int ret = route_map_delete_match ((struct route_map_index *) vty->index,
1037 "interface", (argc == 0) ? NULL : argv[0]);
1038 return route_map_command_status (vty, ret);
1039}
1040
1041ALIAS (ospf6_routemap_no_match_interface,
1042 ospf6_routemap_no_match_interface_val_cmd,
1043 "no match interface WORD",
1044 MATCH_STR
1045 NO_STR
1046 "Match first hop interface of route\n"
1047 "Interface name\n")
1048
508e53e2 1049/* add "set metric-type" */
1050DEFUN (ospf6_routemap_set_metric_type,
1051 ospf6_routemap_set_metric_type_cmd,
1052 "set metric-type (type-1|type-2)",
1053 "Set value\n"
1054 "Type of metric\n"
1055 "OSPF6 external type 1 metric\n"
1056 "OSPF6 external type 2 metric\n")
1057{
1058 int ret = route_map_add_set ((struct route_map_index *) vty->index,
1059 "metric-type", argv[0]);
1060 return route_map_command_status (vty, ret);
718e3744 1061}
1062
508e53e2 1063/* delete "set metric-type" */
1064DEFUN (ospf6_routemap_no_set_metric_type,
1065 ospf6_routemap_no_set_metric_type_cmd,
1066 "no set metric-type (type-1|type-2)",
1067 NO_STR
1068 "Set value\n"
1069 "Type of metric\n"
1070 "OSPF6 external type 1 metric\n"
1071 "OSPF6 external type 2 metric\n")
718e3744 1072{
508e53e2 1073 int ret = route_map_delete_set ((struct route_map_index *) vty->index,
1074 "metric-type", argv[0]);
1075 return route_map_command_status (vty, ret);
1076}
718e3744 1077
508e53e2 1078/* add "set metric" */
1079DEFUN (set_metric,
1080 set_metric_cmd,
1081 "set metric <0-4294967295>",
1082 "Set value\n"
1083 "Metric value\n"
1084 "Metric value\n")
1085{
1086 int ret = route_map_add_set ((struct route_map_index *) vty->index,
1087 "metric", argv[0]);
1088 return route_map_command_status (vty, ret);
1089}
718e3744 1090
508e53e2 1091/* delete "set metric" */
1092DEFUN (no_set_metric,
1093 no_set_metric_cmd,
1094 "no set metric <0-4294967295>",
1095 NO_STR
1096 "Set value\n"
1097 "Metric\n"
1098 "METRIC value\n")
1099{
1100 int ret = route_map_delete_set ((struct route_map_index *) vty->index,
1101 "metric", argv[0]);
1102 return route_map_command_status (vty, ret);
1103}
718e3744 1104
508e53e2 1105/* add "set forwarding-address" */
1106DEFUN (ospf6_routemap_set_forwarding,
1107 ospf6_routemap_set_forwarding_cmd,
1108 "set forwarding-address X:X::X:X",
1109 "Set value\n"
1110 "Forwarding Address\n"
1111 "IPv6 Address\n")
1112{
1113 int ret = route_map_add_set ((struct route_map_index *) vty->index,
1114 "forwarding-address", argv[0]);
1115 return route_map_command_status (vty, ret);
1116}
718e3744 1117
508e53e2 1118/* delete "set forwarding-address" */
1119DEFUN (ospf6_routemap_no_set_forwarding,
1120 ospf6_routemap_no_set_forwarding_cmd,
1121 "no set forwarding-address X:X::X:X",
1122 NO_STR
1123 "Set value\n"
1124 "Forwarding Address\n"
1125 "IPv6 Address\n")
1126{
1127 int ret = route_map_delete_set ((struct route_map_index *) vty->index,
1128 "forwarding-address", argv[0]);
1129 return route_map_command_status (vty, ret);
1130}
718e3744 1131
6ac29a51
PJ
1132static void
1133ospf6_routemap_init (void)
508e53e2 1134{
1135 route_map_init ();
1136 route_map_init_vty ();
1137 route_map_add_hook (ospf6_asbr_routemap_update);
1138 route_map_delete_hook (ospf6_asbr_routemap_update);
1139
1140 route_map_install_match (&ospf6_routemap_rule_match_address_prefixlist_cmd);
42a7debf
VT
1141 route_map_install_match (&ospf6_routemap_rule_match_interface_cmd);
1142
508e53e2 1143 route_map_install_set (&ospf6_routemap_rule_set_metric_type_cmd);
1144 route_map_install_set (&ospf6_routemap_rule_set_metric_cmd);
1145 route_map_install_set (&ospf6_routemap_rule_set_forwarding_cmd);
1146
1147 /* Match address prefix-list */
1148 install_element (RMAP_NODE, &ospf6_routemap_match_address_prefixlist_cmd);
1149 install_element (RMAP_NODE, &ospf6_routemap_no_match_address_prefixlist_cmd);
1150
42a7debf
VT
1151 /* Match interface */
1152 install_element (RMAP_NODE, &ospf6_routemap_match_interface_cmd);
1153 install_element (RMAP_NODE, &ospf6_routemap_no_match_interface_cmd);
1154 install_element (RMAP_NODE, &ospf6_routemap_no_match_interface_val_cmd);
1155
508e53e2 1156 /* ASE Metric Type (e.g. Type-1/Type-2) */
1157 install_element (RMAP_NODE, &ospf6_routemap_set_metric_type_cmd);
1158 install_element (RMAP_NODE, &ospf6_routemap_no_set_metric_type_cmd);
1159
1160 /* ASE Metric */
1161 install_element (RMAP_NODE, &set_metric_cmd);
1162 install_element (RMAP_NODE, &no_set_metric_cmd);
1163
1164 /* ASE Metric */
1165 install_element (RMAP_NODE, &ospf6_routemap_set_forwarding_cmd);
1166 install_element (RMAP_NODE, &ospf6_routemap_no_set_forwarding_cmd);
718e3744 1167}
1168
508e53e2 1169\f
1170/* Display functions */
e68a6767
DD
1171static char *
1172ospf6_as_external_lsa_get_prefix_str (struct ospf6_lsa *lsa, char *buf,
1173 int buflen, int pos)
1174{
1175 struct ospf6_as_external_lsa *external;
1176 struct in6_addr in6;
1177 int prefix_length = 0;
1178
1179 if (lsa)
1180 {
1181 external = (struct ospf6_as_external_lsa *)
1182 OSPF6_LSA_HEADER_END (lsa->header);
1183
1184 if (pos == 0)
1185 {
1186 ospf6_prefix_in6_addr (&in6, &external->prefix);
1187 prefix_length = external->prefix.prefix_length;
1188 }
1189 else {
1190 in6 = *((struct in6_addr *)
1191 ((caddr_t) external + sizeof (struct ospf6_as_external_lsa) +
1192 OSPF6_PREFIX_SPACE (external->prefix.prefix_length)));
1193 }
1194 if (buf)
1195 {
1196 inet_ntop (AF_INET6, &in6, buf, buflen);
1197 if (prefix_length)
1198 sprintf (&buf[strlen(buf)], "/%d", prefix_length);
1199 }
1200 }
1201 return (buf);
1202}
1203
6ac29a51 1204static int
508e53e2 1205ospf6_as_external_lsa_show (struct vty *vty, struct ospf6_lsa *lsa)
718e3744 1206{
508e53e2 1207 struct ospf6_as_external_lsa *external;
1208 char buf[64];
718e3744 1209
1210 assert (lsa->header);
508e53e2 1211 external = (struct ospf6_as_external_lsa *)
1212 OSPF6_LSA_HEADER_END (lsa->header);
718e3744 1213
1214 /* bits */
508e53e2 1215 snprintf (buf, sizeof (buf), "%c%c%c",
1216 (CHECK_FLAG (external->bits_metric, OSPF6_ASBR_BIT_E) ? 'E' : '-'),
1217 (CHECK_FLAG (external->bits_metric, OSPF6_ASBR_BIT_F) ? 'F' : '-'),
1218 (CHECK_FLAG (external->bits_metric, OSPF6_ASBR_BIT_T) ? 'T' : '-'));
718e3744 1219
049207c3 1220 vty_out (vty, " Bits: %s%s", buf, VNL);
508e53e2 1221 vty_out (vty, " Metric: %5lu%s", (u_long) OSPF6_ASBR_METRIC (external),
049207c3 1222 VNL);
718e3744 1223
508e53e2 1224 ospf6_prefix_options_printbuf (external->prefix.prefix_options,
1225 buf, sizeof (buf));
1226 vty_out (vty, " Prefix Options: %s%s", buf,
049207c3 1227 VNL);
718e3744 1228
1229 vty_out (vty, " Referenced LSType: %d%s",
508e53e2 1230 ntohs (external->prefix.prefix_refer_lstype),
049207c3 1231 VNL);
718e3744 1232
e68a6767
DD
1233 vty_out (vty, " Prefix: %s%s",
1234 ospf6_as_external_lsa_get_prefix_str (lsa, buf, sizeof(buf), 0), VNL);
718e3744 1235
1236 /* Forwarding-Address */
1237 if (CHECK_FLAG (external->bits_metric, OSPF6_ASBR_BIT_F))
1238 {
e68a6767
DD
1239 vty_out (vty, " Forwarding-Address: %s%s",
1240 ospf6_as_external_lsa_get_prefix_str (lsa, buf, sizeof(buf), 1),
1241 VNL);
718e3744 1242 }
1243
1244 return 0;
1245}
1246
6ac29a51 1247static void
508e53e2 1248ospf6_asbr_external_route_show (struct vty *vty, struct ospf6_route *route)
718e3744 1249{
508e53e2 1250 struct ospf6_external_info *info = route->route_option;
1251 char prefix[64], id[16], forwarding[64];
1252 u_int32_t tmp_id;
718e3744 1253
508e53e2 1254 prefix2str (&route->prefix, prefix, sizeof (prefix));
1255 tmp_id = ntohl (info->id);
1256 inet_ntop (AF_INET, &tmp_id, id, sizeof (id));
1257 if (! IN6_IS_ADDR_UNSPECIFIED (&info->forwarding))
1258 inet_ntop (AF_INET6, &info->forwarding, forwarding, sizeof (forwarding));
1259 else
1260 snprintf (forwarding, sizeof (forwarding), ":: (ifindex %d)",
1261 route->nexthop[0].ifindex);
1262
f52d13cb 1263 vty_out (vty, "%c %-32s %-15s type-%d %5lu %s%s",
1264 zebra_route_char(info->type),
508e53e2 1265 prefix, id, route->path.metric_type,
1266 (u_long) (route->path.metric_type == 2 ?
1267 route->path.cost_e2 : route->path.cost),
049207c3 1268 forwarding, VNL);
718e3744 1269}
1270
508e53e2 1271DEFUN (show_ipv6_ospf6_redistribute,
1272 show_ipv6_ospf6_redistribute_cmd,
1273 "show ipv6 ospf6 redistribute",
1274 SHOW_STR
1275 IP6_STR
1276 OSPF6_STR
1277 "redistributing External information\n"
1278 )
718e3744 1279{
508e53e2 1280 struct ospf6_route *route;
718e3744 1281
508e53e2 1282 ospf6_redistribute_show_config (vty);
718e3744 1283
508e53e2 1284 for (route = ospf6_route_head (ospf6->external_table); route;
1285 route = ospf6_route_next (route))
1286 ospf6_asbr_external_route_show (vty, route);
1287
1288 return CMD_SUCCESS;
718e3744 1289}
1290
6452df09 1291struct ospf6_lsa_handler as_external_handler =
718e3744 1292{
6452df09 1293 OSPF6_LSTYPE_AS_EXTERNAL,
1294 "AS-External",
e68a6767
DD
1295 "ASE",
1296 ospf6_as_external_lsa_show,
1297 ospf6_as_external_lsa_get_prefix_str
6452df09 1298};
508e53e2 1299
718e3744 1300void
6ac29a51 1301ospf6_asbr_init (void)
718e3744 1302{
508e53e2 1303 ospf6_routemap_init ();
1304
6452df09 1305 ospf6_install_lsa_handler (&as_external_handler);
718e3744 1306
508e53e2 1307 install_element (VIEW_NODE, &show_ipv6_ospf6_redistribute_cmd);
1308 install_element (ENABLE_NODE, &show_ipv6_ospf6_redistribute_cmd);
1309
718e3744 1310 install_element (OSPF6_NODE, &ospf6_redistribute_cmd);
1311 install_element (OSPF6_NODE, &ospf6_redistribute_routemap_cmd);
1312 install_element (OSPF6_NODE, &no_ospf6_redistribute_cmd);
1313}
1314
d9628728
CF
1315void
1316ospf6_asbr_redistribute_reset (void)
1317{
1318 int type;
1319
1320 for (type = 0; type < ZEBRA_ROUTE_MAX; type++)
1321 {
1322 if (type == ZEBRA_ROUTE_OSPF6)
1323 continue;
1324 if (ospf6_zebra_is_redistribute (type))
1325 ospf6_asbr_redistribute_unset(type);
1326 }
1327}
1328
ae2254aa
TG
1329void
1330ospf6_asbr_terminate (void)
1331{
1332 route_map_finish ();
1333}
718e3744 1334
508e53e2 1335DEFUN (debug_ospf6_asbr,
1336 debug_ospf6_asbr_cmd,
1337 "debug ospf6 asbr",
1338 DEBUG_STR
1339 OSPF6_STR
1340 "Debug OSPFv3 ASBR function\n"
1341 )
1342{
1343 OSPF6_DEBUG_ASBR_ON ();
1344 return CMD_SUCCESS;
1345}
1346
1347DEFUN (no_debug_ospf6_asbr,
1348 no_debug_ospf6_asbr_cmd,
1349 "no debug ospf6 asbr",
1350 NO_STR
1351 DEBUG_STR
1352 OSPF6_STR
1353 "Debug OSPFv3 ASBR function\n"
1354 )
1355{
1356 OSPF6_DEBUG_ASBR_OFF ();
1357 return CMD_SUCCESS;
1358}
1359
1360int
1361config_write_ospf6_debug_asbr (struct vty *vty)
1362{
1363 if (IS_OSPF6_DEBUG_ASBR)
049207c3 1364 vty_out (vty, "debug ospf6 asbr%s", VNL);
508e53e2 1365 return 0;
1366}
1367
1368void
1369install_element_ospf6_debug_asbr ()
1370{
1371 install_element (ENABLE_NODE, &debug_ospf6_asbr_cmd);
1372 install_element (ENABLE_NODE, &no_debug_ospf6_asbr_cmd);
1373 install_element (CONFIG_NODE, &debug_ospf6_asbr_cmd);
1374 install_element (CONFIG_NODE, &no_debug_ospf6_asbr_cmd);
1375}
1376
1377