Пример #1
0
static struct ospf6_area *
ospf6_area_get (u_int32_t area_id, struct ospf6 *o)
{
  struct ospf6_area *oa;
  oa = ospf6_area_lookup (area_id, o);
  if (oa == NULL)
    oa = ospf6_area_create (area_id, o);
  return oa;
}
Пример #2
0
void
ospf6_abr_originate_summary (struct ospf6_route *route)
{
  struct listnode *node, *nnode;
  struct ospf6_area *oa;
  struct ospf6_route *range = NULL;

  if (route->type == OSPF6_DEST_TYPE_NETWORK)
    {
      oa = ospf6_area_lookup (route->path.area_id, ospf6);
      range = ospf6_route_lookup_bestmatch (&route->prefix, oa->range_table);
      if (range)
        ospf6_abr_range_update (range);
    }

  for (ALL_LIST_ELEMENTS (ospf6->area_list, node, nnode, oa))
    ospf6_abr_originate_summary_to_area (route, oa);
}
Пример #3
0
void sibling_ctrl_add_ctrl_client(unsigned int hostnum, char * ifname, char * area)
{
  struct ctrl_client * ctrl_client;
  struct interface * ifp;
  struct ospf6_interface * oi;
  struct ospf6_area * oa;

  u_int32_t area_id;

  ctrl_client = ctrl_client_new();
  ctrl_client->hostnum = hostnum;
  ctrl_client->inter_con = NULL;

  list_push_back(&ctrl_clients, &ctrl_client->node);

  /* find/create ospf6 interface */
  ifp = if_get_by_name(ctrl_client->if_list, ifname);
  oi = (struct ospf6_interface *) ifp->info;
  if(oi == NULL)
  {
    oi = ospf6_interface_create(ifp);
  }

  /* parse Area-ID */
  if (inet_pton (AF_INET, area, &area_id) != 1)  
  {
    printf("Invalid Area-ID: %s\n", area);
  }
  
  /* find/create ospf6 area */
  oa = ospf6_area_lookup (area_id, ospf6); 
  if(oa == NULL)
    oa = ospf6_area_create(area_id, ospf6); 
 
  /* attach interface to area */
  list_push_back(&oa->if_list, &oi->node);
  oi->area = oa;

  /* start up */
  thread_add_event(master, interface_up, oi, 0); 
}
Пример #4
0
void
ospf6_abr_originate_summary (struct ospf6_route *route)
{
  listnode node;
  struct ospf6_area *oa;
  struct ospf6_route *range = NULL;

  if (route->type == OSPF6_DEST_TYPE_NETWORK)
    {
      oa = ospf6_area_lookup (route->path.area_id, ospf6);
      range = ospf6_route_lookup_bestmatch (&route->prefix, oa->range_table);
      if (range)
        ospf6_abr_range_update (range);
    }

  for (node = listhead (ospf6->area_list); node; nextnode (node))
    {
      oa = (struct ospf6_area *) getdata (node);
      ospf6_abr_originate_summary_to_area (route, oa);
    }
}
Пример #5
0
static u_char *
ospfv3AreaLsdbEntry (struct variable *v, oid *name, size_t *length,
                     int exact, size_t *var_len, WriteMethod **write_method)
{
  struct ospf6_lsa *lsa = NULL;
  struct in_addr area_id;
  u_int16_t type;
  struct in_addr id;
  struct in_addr adv_router;
  int len;
  oid *offset;
  int offsetlen;
  char a[16], b[16], c[16];
  struct ospf6_area *oa;
  struct listnode *node;

  memset (&area_id, 0, sizeof (struct in_addr));
  type = 0;
  memset (&id, 0, sizeof (struct in_addr));
  memset (&adv_router, 0, sizeof (struct in_addr));

  /* Check OSPFv3 instance. */
  if (ospf6 == NULL)
    return NULL;

  /* Get variable length. */
  offset = name + v->namelen;
  offsetlen = *length - v->namelen;

#define OSPFV3_AREA_LSDB_ENTRY_EXACT_OFFSET \
  (IN_ADDR_SIZE + 1 + IN_ADDR_SIZE + IN_ADDR_SIZE)

  if (exact && offsetlen != OSPFV3_AREA_LSDB_ENTRY_EXACT_OFFSET)
    return NULL;

  /* Parse area-id */
  len = (offsetlen < IN_ADDR_SIZE ? offsetlen : IN_ADDR_SIZE);
  if (len)
    oid2in_addr (offset, len, &area_id);
  offset += len;
  offsetlen -= len;

  /* Parse type */
  len = (offsetlen < 1 ? offsetlen : 1);
  if (len)
    type = htons (*offset);
  offset += len;
  offsetlen -= len;

  /* Parse Router-ID */
  len = (offsetlen < IN_ADDR_SIZE ? offsetlen : IN_ADDR_SIZE);
  if (len)
    oid2in_addr (offset, len, &adv_router);
  offset += len;
  offsetlen -= len;

  /* Parse LS-ID */
  len = (offsetlen < IN_ADDR_SIZE ? offsetlen : IN_ADDR_SIZE);
  if (len)
    oid2in_addr (offset, len, &id);
  offset += len;
  offsetlen -= len;

  ospf6_id2str (area_id.s_addr, a, sizeof (a));
  ospf6_id2str (adv_router.s_addr, b, sizeof (b));
  ospf6_id2str (id.s_addr, c, sizeof (c));
  zlog_debug ("SNMP access by lsdb: area=%s exact=%d length=%lu magic=%d"
	      " type=%#x adv_router=%s id=%s",
	      a, exact, (u_long)*length, v->magic, ntohs (type), b, c);

  if (exact)
    {
      oa = ospf6_area_lookup (area_id.s_addr, ospf6);
      lsa = ospf6_lsdb_lookup (type, id.s_addr, adv_router.s_addr, oa->lsdb);
    }
  else
    {
      for (ALL_LIST_ELEMENTS_RO (ospf6->area_list, node, oa))
        {
          if (lsa)
            continue;
          if (ntohl (oa->area_id) < ntohl (area_id.s_addr))
            continue;

          lsa = ospf6_lsdb_lookup_next (type, id.s_addr, adv_router.s_addr,
                                        oa->lsdb);
          if (! lsa)
            {
              type = 0;
              memset (&id, 0, sizeof (struct in_addr));
              memset (&adv_router, 0, sizeof (struct in_addr));
            }
        }
    }

  if (! lsa)
    {
      zlog_debug ("SNMP respond: No LSA to return");
      return NULL;
    }
  oa = OSPF6_AREA (lsa->lsdb->data);

  zlog_debug ("SNMP respond: area: %s lsa: %s", oa->name, lsa->name);

  /* Add Index (AreaId, Type, RouterId, Lsid) */
  *length = v->namelen + OSPFV3_AREA_LSDB_ENTRY_EXACT_OFFSET;
  offset = name + v->namelen;
  oid_copy_addr (offset, (struct in_addr *) &oa->area_id, IN_ADDR_SIZE);
  offset += IN_ADDR_SIZE;
  *offset = ntohs (lsa->header->type);
  offset++;
  oid_copy_addr (offset, (struct in_addr *) &lsa->header->adv_router,
                 IN_ADDR_SIZE);
  offset += IN_ADDR_SIZE;
  oid_copy_addr (offset, (struct in_addr *) &lsa->header->id, IN_ADDR_SIZE);
  offset += IN_ADDR_SIZE;

  /* Return the current value of the variable */
  switch (v->magic)
    {
    case OSPFv3AREALSDBAREAID:        /* 1 */
      area_id.s_addr = OSPF6_AREA (lsa->lsdb->data)->area_id;
      return SNMP_IPADDRESS (area_id);
      break;
    case OSPFv3AREALSDBTYPE:          /* 2 */
      return SNMP_INTEGER (ntohs (lsa->header->type));
      break;
    case OSPFv3AREALSDBROUTERID:      /* 3 */
      adv_router.s_addr = lsa->header->adv_router;
      return SNMP_IPADDRESS (adv_router);
      break;
    case OSPFv3AREALSDBLSID:          /* 4 */
      id.s_addr = lsa->header->id;
      return SNMP_IPADDRESS (id);
      break;
    case OSPFv3AREALSDBSEQUENCE:      /* 5 */
      return SNMP_INTEGER (lsa->header->seqnum);
      break;
    case OSPFv3AREALSDBAGE:           /* 6 */
      ospf6_lsa_age_current (lsa);
      return SNMP_INTEGER (lsa->header->age);
      break;
    case OSPFv3AREALSDBCHECKSUM:      /* 7 */
      return SNMP_INTEGER (lsa->header->checksum);
      break;
    case OSPFv3AREALSDBADVERTISEMENT: /* 8 */
      *var_len = ntohs (lsa->header->length);
      return (u_char *) lsa->header;
      break;
    case OSPFv3AREALSDBTYPEKNOWN:     /* 9 */
      return SNMP_INTEGER (OSPF6_LSA_IS_KNOWN (lsa->header->type) ?
                           SNMP_TRUE : SNMP_FALSE);
      break;
    default:
      return NULL;
      break;
    }
  return NULL;
}
Пример #6
0
/* RFC 2328 12.4.3. Summary-LSAs */
void
ospf6_abr_originate_summary_to_area (struct ospf6_route *route,
                                     struct ospf6_area *area)
{
  struct ospf6_lsa *lsa, *old = NULL;
  struct ospf6_interface *oi;
  struct ospf6_route *summary, *range = NULL;
  struct ospf6_area *route_area;
  char buffer[OSPF6_MAX_LSASIZE];
  struct ospf6_lsa_header *lsa_header;
  caddr_t p;
  struct ospf6_inter_prefix_lsa *prefix_lsa;
  struct ospf6_inter_router_lsa *router_lsa;
  struct ospf6_route_table *summary_table = NULL;
  u_int16_t type;
  char buf[64];
  int is_debug = 0;

  if (route->type == OSPF6_DEST_TYPE_ROUTER)
    {
      if (IS_OSPF6_DEBUG_ABR || IS_OSPF6_DEBUG_ORIGINATE (INTER_ROUTER))
        {
          is_debug++;
          inet_ntop (AF_INET, &(ADV_ROUTER_IN_PREFIX (&route->prefix)),
                     buf, sizeof (buf));
          zlog_debug ("Originating summary in area %s for ASBR %s",
		      area->name, buf);
        }
      summary_table = area->summary_router;
    }
  else
    {
      if (IS_OSPF6_DEBUG_ABR || IS_OSPF6_DEBUG_ORIGINATE (INTER_PREFIX))
        {
          is_debug++;
          prefix2str (&route->prefix, buf, sizeof (buf));
          zlog_debug ("Originating summary in area %s for %s",
		      area->name, buf);
        }
      summary_table = area->summary_prefix;
    }

  summary = ospf6_route_lookup (&route->prefix, summary_table);
  if (summary)
    old = ospf6_lsdb_lookup (summary->path.origin.type,
                             summary->path.origin.id,
                             area->ospf6->router_id, area->lsdb);

  /* if this route has just removed, remove corresponding LSA */
  if (CHECK_FLAG (route->flag, OSPF6_ROUTE_REMOVE))
    {
      if (is_debug)
        zlog_debug ("The route has just removed, purge previous LSA");
      if (summary)
        ospf6_route_remove (summary, summary_table);
      if (old)
        ospf6_lsa_purge (old);
      return;
    }

  /* Only destination type network, range or ASBR are considered */
  if (route->type != OSPF6_DEST_TYPE_NETWORK &&
      route->type != OSPF6_DEST_TYPE_RANGE &&
      (route->type != OSPF6_DEST_TYPE_ROUTER ||
       ! CHECK_FLAG (route->path.router_bits, OSPF6_ROUTER_BIT_E)))
    {
      if (is_debug)
        zlog_debug ("Route type is none of network, range nor ASBR, withdraw");
      if (summary)
        ospf6_route_remove (summary, summary_table);
      if (old)
        ospf6_lsa_purge (old);
      return;
    }

  /* AS External routes are never considered */
  if (route->path.type == OSPF6_PATH_TYPE_EXTERNAL1 ||
      route->path.type == OSPF6_PATH_TYPE_EXTERNAL2)
    {
      if (is_debug)
        zlog_debug ("Path type is external, withdraw");
      if (summary)
        ospf6_route_remove (summary, summary_table);
      if (old)
        ospf6_lsa_purge (old);
      return;
    }

  /* do not generate if the path's area is the same as target area */
  if (route->path.area_id == area->area_id)
    {
      if (is_debug)
        zlog_debug ("The route is in the area itself, ignore");
      if (summary)
        ospf6_route_remove (summary, summary_table);
      if (old)
        ospf6_lsa_purge (old);
      return;
    }

  /* do not generate if the nexthops belongs to the target area */
  oi = ospf6_interface_lookup_by_ifindex (route->nexthop[0].ifindex);
  if (oi && oi->area && oi->area == area)
    {
      if (is_debug)
        zlog_debug ("The route's nexthop is in the same area, ignore");
      if (summary)
        ospf6_route_remove (summary, summary_table);
      if (old)
        ospf6_lsa_purge (old);
      return;
    }

  /* do not generate if the route cost is greater or equal to LSInfinity */
  if (route->path.cost >= OSPF_LS_INFINITY)
    {
      if (is_debug)
        zlog_debug ("The cost exceeds LSInfinity, withdraw");
      if (summary)
        ospf6_route_remove (summary, summary_table);
      if (old)
        ospf6_lsa_purge (old);
      return;
    }

  /* if this is a route to ASBR */
  if (route->type == OSPF6_DEST_TYPE_ROUTER)
    {
      /* Only the prefered best path is considered */
      if (! CHECK_FLAG (route->flag, OSPF6_ROUTE_BEST))
        {
          if (is_debug)
            zlog_debug ("This is the secondary path to the ASBR, ignore");
          if (summary)
            ospf6_route_remove (summary, summary_table);
          if (old)
            ospf6_lsa_purge (old);
          return;
        }

      /* Do not generate if the area is stub */
      /* XXX */
    }

  /* if this is an intra-area route, this may be suppressed by aggregation */
  if (route->type == OSPF6_DEST_TYPE_NETWORK &&
      route->path.type == OSPF6_PATH_TYPE_INTRA)
    {
      /* search for configured address range for the route's area */
      route_area = ospf6_area_lookup (route->path.area_id, area->ospf6);
      assert (route_area);
      range = ospf6_route_lookup_bestmatch (&route->prefix,
                                            route_area->range_table);

      /* ranges are ignored when originate backbone routes to transit area.
         Otherwise, if ranges are configured, the route is suppressed. */
      if (range && ! CHECK_FLAG (range->flag, OSPF6_ROUTE_REMOVE) &&
          (route->path.area_id != OSPF_AREA_BACKBONE ||
           ! IS_AREA_TRANSIT (area)))
        {
          if (is_debug)
            {
              prefix2str (&range->prefix, buf, sizeof (buf));
              zlog_debug ("Suppressed by range %s of area %s",
                         buf, route_area->name);
            }

          if (summary)
            ospf6_route_remove (summary, summary_table);
          if (old)
            ospf6_lsa_purge (old);
          return;
        }
    }

  /* If this is a configured address range */
  if (route->type == OSPF6_DEST_TYPE_RANGE)
    {
      /* If DoNotAdvertise is set */
      if (CHECK_FLAG (route->flag, OSPF6_ROUTE_DO_NOT_ADVERTISE))
        {
          if (is_debug)
            zlog_debug ("This is the range with DoNotAdvertise set. ignore");
          if (summary)
            ospf6_route_remove (summary, summary_table);
          if (old)
            ospf6_lsa_purge (old);
          return;
        }

      /* Whether the route have active longer prefix */
      if (! CHECK_FLAG (route->flag, OSPF6_ROUTE_ACTIVE_SUMMARY))
        {
          if (is_debug)
            zlog_debug ("The range is not active. withdraw");
          if (summary)
            ospf6_route_remove (summary, summary_table);
          if (old)
            ospf6_lsa_purge (old);
          return;
        }
    }

  /* Check export list */
  if (EXPORT_NAME (area))
    {
      if (EXPORT_LIST (area) == NULL)
        EXPORT_LIST (area) =
          access_list_lookup (AFI_IP6, EXPORT_NAME (area));

      if (EXPORT_LIST (area))
        if (access_list_apply (EXPORT_LIST (area),
                               &route->prefix) == FILTER_DENY)
          {
            if (is_debug)
              {
                inet_ntop (AF_INET, &(ADV_ROUTER_IN_PREFIX (&route->prefix)),
                           buf, sizeof(buf));
                zlog_debug ("prefix %s was denied by export list", buf);
              }
            return;
          }
    }

  /* Check filter-list */
  if (PREFIX_NAME_OUT (area))
    {
      if (PREFIX_LIST_OUT (area) == NULL)
        PREFIX_LIST_OUT (area) =
          prefix_list_lookup(AFI_IP6, PREFIX_NAME_OUT (area));

      if (PREFIX_LIST_OUT (area))
         if (prefix_list_apply (PREFIX_LIST_OUT (area), 
                                &route->prefix) != PREFIX_PERMIT) 
           {
             if (is_debug)
               {
                 inet_ntop (AF_INET, &(ADV_ROUTER_IN_PREFIX (&route->prefix)),
                            buf, sizeof (buf));
                 zlog_debug ("prefix %s was denied by filter-list out", buf);
               }
             return;
           }
    }

  /* the route is going to be originated. store it in area's summary_table */
  if (summary == NULL)
    {
      summary = ospf6_route_copy (route);
      if (route->type == OSPF6_DEST_TYPE_NETWORK ||
          route->type == OSPF6_DEST_TYPE_RANGE)
        summary->path.origin.type = htons (OSPF6_LSTYPE_INTER_PREFIX);
      else
        summary->path.origin.type = htons (OSPF6_LSTYPE_INTER_ROUTER);
      summary->path.origin.adv_router = area->ospf6->router_id;
      summary->path.origin.id =
        ospf6_new_ls_id (summary->path.origin.type,
                         summary->path.origin.adv_router, area->lsdb);
      summary = ospf6_route_add (summary, summary_table);
    }
  else
    {
      summary->type = route->type;
      quagga_gettime (QUAGGA_CLK_MONOTONIC, &summary->changed);
    }

  summary->path.router_bits = route->path.router_bits;
  summary->path.options[0] = route->path.options[0];
  summary->path.options[1] = route->path.options[1];
  summary->path.options[2] = route->path.options[2];
  summary->path.prefix_options = route->path.prefix_options;
  summary->path.area_id = area->area_id;
  summary->path.type = OSPF6_PATH_TYPE_INTER;
  summary->path.cost = route->path.cost;
  summary->nexthop[0] = route->nexthop[0];

  /* prepare buffer */
  memset (buffer, 0, sizeof (buffer));
  lsa_header = (struct ospf6_lsa_header *) buffer;

  if (route->type == OSPF6_DEST_TYPE_ROUTER)
    {
      router_lsa = (struct ospf6_inter_router_lsa *)
        ((caddr_t) lsa_header + sizeof (struct ospf6_lsa_header));
      p = (caddr_t) router_lsa + sizeof (struct ospf6_inter_router_lsa);

      /* Fill Inter-Area-Router-LSA */
      router_lsa->options[0] = route->path.options[0];
      router_lsa->options[1] = route->path.options[1];
      router_lsa->options[2] = route->path.options[2];
      OSPF6_ABR_SUMMARY_METRIC_SET (router_lsa, route->path.cost);
      router_lsa->router_id = ADV_ROUTER_IN_PREFIX (&route->prefix);
      type = htons (OSPF6_LSTYPE_INTER_ROUTER);
    }
  else
    {
      prefix_lsa = (struct ospf6_inter_prefix_lsa *)
        ((caddr_t) lsa_header + sizeof (struct ospf6_lsa_header));
      p = (caddr_t) prefix_lsa + sizeof (struct ospf6_inter_prefix_lsa);

      /* Fill Inter-Area-Prefix-LSA */
      OSPF6_ABR_SUMMARY_METRIC_SET (prefix_lsa, route->path.cost);
      prefix_lsa->prefix.prefix_length = route->prefix.prefixlen;
      prefix_lsa->prefix.prefix_options = route->path.prefix_options;

      /* set Prefix */
      memcpy (p, &route->prefix.u.prefix6,
              OSPF6_PREFIX_SPACE (route->prefix.prefixlen));
      ospf6_prefix_apply_mask (&prefix_lsa->prefix);
      p += OSPF6_PREFIX_SPACE (route->prefix.prefixlen);
      type = htons (OSPF6_LSTYPE_INTER_PREFIX);
    }

  /* Fill LSA Header */
  lsa_header->age = 0;
  lsa_header->type = type;
  lsa_header->id = summary->path.origin.id;
  lsa_header->adv_router = area->ospf6->router_id;
  lsa_header->seqnum =
    ospf6_new_ls_seqnum (lsa_header->type, lsa_header->id,
                         lsa_header->adv_router, area->lsdb);
  lsa_header->length = htons ((caddr_t) p - (caddr_t) lsa_header);

  /* LSA checksum */
  ospf6_lsa_checksum (lsa_header);

  /* create LSA */
  lsa = ospf6_lsa_create (lsa_header);

  /* Originate */
  ospf6_lsa_originate_area (lsa, area);
}
       "show ipv6 ospf6 area A.B.C.D route",
       SHOW_STR
       IP6_STR
       OSPF6_STR
       OSPF6_AREA_STR
       OSPF6_AREA_ID_STR
       ROUTE_STR
       )
{
  struct ospf6_area *o6a;
  u_int32_t area_id;

  OSPF6_CMD_CHECK_RUNNING ();

  inet_pton (AF_INET, argv[0], &area_id);
  o6a = ospf6_area_lookup (area_id, ospf6);

  if (! o6a)
    return CMD_SUCCESS;

  argc -= 1;
  argv += 1;

  return ospf6_route_table_show (vty, argc, argv, o6a->route_table);
}

ALIAS (show_ipv6_ospf6_area_route,
       show_ipv6_ospf6_area_route_prefix_cmd,
       "show ipv6 ospf6 area A.B.C.D route (X::X|detail)",
       SHOW_STR
       IP6_STR
Пример #8
0
static u_char *
ospfv3WwLsdbEntry (struct variable *v, oid *name, size_t *length,
                     int exact, size_t *var_len, WriteMethod **write_method)
{
  struct ospf6_lsa *lsa = NULL;
  u_int32_t ifindex, area_id, id, instid, adv_router;
  u_int16_t type;
  int len;
  oid *offset;
  int offsetlen;
  char a[16], b[16], c[16];
  struct ospf6_area *oa;
  struct listnode *node;
  struct interface *iif;
  struct ospf6_interface *oi = NULL;
  struct list *ifslist;

  if (smux_header_table(v, name, length, exact, var_len, write_method)
      == MATCH_FAILED)
    return NULL;

  instid = ifindex = area_id = type = id = adv_router = 0;

  /* Check OSPFv3 instance. */
  if (ospf6 == NULL)
    return NULL;

  /* Get variable length. */
  offset = name + v->namelen;
  offsetlen = *length - v->namelen;

  if (exact && (v->magic & OSPFv3WWASTABLE) && offsetlen != 3)
    return NULL;
  if (exact && (v->magic & OSPFv3WWAREATABLE) && offsetlen != 4)
    return NULL;
  if (exact && (v->magic & OSPFv3WWLINKTABLE) && offsetlen != 5)
    return NULL;

  if (v->magic & OSPFv3WWLINKTABLE)
    {
      /* Parse ifindex */
      len = (offsetlen < 1 ? 0 : 1);
      if (len)
        ifindex = *offset;
      offset += len;
      offsetlen -= len;

      /* Parse instance ID */
      len = (offsetlen < 1 ? 0 : 1);
      if (len)
        instid = *offset;
      offset += len;
      offsetlen -= len;
    }
  else if (v->magic & OSPFv3WWAREATABLE)
    {
      /* Parse area-id */
      len = (offsetlen < 1 ? 0 : 1);
      if (len)
        area_id = htonl (*offset);
      offset += len;
      offsetlen -= len;
    }

  /* Parse type */
  len = (offsetlen < 1 ? 0 : 1);
  if (len)
    type = htons (*offset);
  offset += len;
  offsetlen -= len;

  /* Parse Router-ID */
  len = (offsetlen < 1 ? 0 : 1);
  if (len)
    adv_router = htonl (*offset);
  offset += len;
  offsetlen -= len;

  /* Parse LS-ID */
  len = (offsetlen < 1 ? 0 : 1);
  if (len)
    id = htonl (*offset);
  offset += len;
  offsetlen -= len;

  if (exact)
    {
      if (v->magic & OSPFv3WWASTABLE)
        {
          lsa = ospf6_lsdb_lookup (type, id, adv_router, ospf6->lsdb);
        }
      else if (v->magic & OSPFv3WWAREATABLE)
        {
          oa = ospf6_area_lookup (area_id, ospf6);
          if (!oa) return NULL;
          lsa = ospf6_lsdb_lookup (type, id, adv_router, oa->lsdb);
        }
      else if (v->magic & OSPFv3WWLINKTABLE)
        {
          oi = ospf6_interface_lookup_by_ifindex (ifindex);
          if (!oi || oi->instance_id != instid) return NULL;
          lsa = ospf6_lsdb_lookup (type, id, adv_router, oi->lsdb);
        }
    }
  else
    {
      if (v->magic & OSPFv3WWASTABLE)
	{
	  if (ospf6->lsdb->count)
	    lsa = ospf6_lsdb_lookup_next (type, id, adv_router,
					  ospf6->lsdb);
	}
      else if (v->magic & OSPFv3WWAREATABLE)
	for (ALL_LIST_ELEMENTS_RO (ospf6->area_list, node, oa))
          {
            if (oa->area_id < area_id)
              continue;

            if (oa->lsdb->count)
              lsa = ospf6_lsdb_lookup_next (type, id, adv_router,
                                            oa->lsdb);
            if (lsa) break;
            type = 0;
            id = 0;
            adv_router = 0;
          }
      else if (v->magic & OSPFv3WWLINKTABLE)
        {
          /* We build a sorted list of interfaces */
          ifslist = list_new ();
          if (!ifslist) return NULL;
          ifslist->cmp = (int (*)(void *, void *))if_icmp_func;
          for (ALL_LIST_ELEMENTS_RO (iflist, node, iif))
            listnode_add_sort (ifslist, iif);
          
          for (ALL_LIST_ELEMENTS_RO (ifslist, node, iif))
            {
              if (!iif->ifindex) continue;
              oi = ospf6_interface_lookup_by_ifindex (iif->ifindex);
              if (!oi) continue;
              if (iif->ifindex < ifindex) continue;
              if (oi->instance_id < instid) continue;
              
              if (oi->lsdb->count)
                lsa = ospf6_lsdb_lookup_next (type, id, adv_router,
                                            oi->lsdb);
              if (lsa) break;
              type = 0;
              id = 0;
              adv_router = 0;
              oi = NULL;
            }

          list_delete_all_node (ifslist);
        }