Ospf6d merge from Zebra repository with added privs stuff and merged
zclient changes.
diff --git a/ospf6d/ospf6_neighbor.c b/ospf6d/ospf6_neighbor.c
index 72735d5..acfd1a4 100644
--- a/ospf6d/ospf6_neighbor.c
+++ b/ospf6d/ospf6_neighbor.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 1999 Yasuhiro Ohara
+ * Copyright (C) 2003 Yasuhiro Ohara
  *
  * This file is part of GNU Zebra.
  *
@@ -19,321 +19,581 @@
  * Boston, MA 02111-1307, USA.  
  */
 
-#include "ospf6d.h"
-
 #include <zebra.h>
 
 #include "log.h"
+#include "memory.h"
 #include "thread.h"
 #include "linklist.h"
 #include "vty.h"
 #include "command.h"
 
-#include "ospf6_lsa.h"
-#include "ospf6_message.h"
-#include "ospf6_neighbor.h"
-#include "ospf6_nsm.h"
+#include "ospf6d.h"
+#include "ospf6_proto.h"
 #include "ospf6_lsa.h"
 #include "ospf6_lsdb.h"
+#include "ospf6_message.h"
+#include "ospf6_top.h"
+#include "ospf6_area.h"
+#include "ospf6_interface.h"
+#include "ospf6_neighbor.h"
+#include "ospf6_intra.h"
 
-char *ospf6_neighbor_state_string[] =
-{
-  "None", "Down", "Attempt", "Init", "Twoway",
-  "ExStart", "ExChange", "Loading", "Full", NULL
-};
+unsigned char conf_debug_ospf6_neighbor = 0;
+
+char *ospf6_neighbor_state_str[] =
+{ "None", "Down", "Attempt", "Init", "Twoway", "ExStart", "ExChange",
+  "Loading", "Full", NULL };
 
 int
-ospf6_neighbor_last_dbdesc_release (struct thread *thread)
+ospf6_neighbor_cmp (void *va, void *vb)
 {
-  struct ospf6_neighbor *o6n;
-
-  o6n = (struct ospf6_neighbor *) THREAD_ARG (thread);
-  assert (o6n);
-  memset (&o6n->last_dd, 0, sizeof (struct ospf6_dbdesc));
-  return 0;
+  struct ospf6_neighbor *ona = (struct ospf6_neighbor *) va;
+  struct ospf6_neighbor *onb = (struct ospf6_neighbor *) vb;
+  return (ntohl (ona->router_id) - ntohl (onb->router_id));
 }
 
-
-
-void
-ospf6_neighbor_thread_cancel_all (struct ospf6_neighbor *o6n)
+struct ospf6_neighbor *
+ospf6_neighbor_lookup (u_int32_t router_id,
+                       struct ospf6_interface *oi)
 {
-  if (o6n->inactivity_timer)
-    thread_cancel (o6n->inactivity_timer);
-  o6n->inactivity_timer = (struct thread *) NULL;
+  listnode n;
+  struct ospf6_neighbor *on;
 
-  if (o6n->send_update)
-    thread_cancel (o6n->send_update);
-  o6n->send_update = (struct thread *) NULL;
-
-  if (o6n->thread_send_dbdesc)
-    thread_cancel (o6n->thread_send_dbdesc);
-  o6n->thread_send_dbdesc = (struct thread *) NULL;
-  if (o6n->thread_rxmt_dbdesc)
-    thread_cancel (o6n->thread_rxmt_dbdesc);
-  o6n->thread_rxmt_dbdesc = (struct thread *) NULL;
-
-  if (o6n->thread_rxmt_lsreq)
-    thread_cancel (o6n->thread_rxmt_lsreq);
-  o6n->thread_rxmt_lsreq = (struct thread *) NULL;
-}
-
-void
-ospf6_neighbor_lslist_clear (struct ospf6_neighbor *nei)
-{
-  ospf6_lsdb_remove_all (nei->summary_list);
-  ospf6_lsdb_remove_all (nei->request_list);
-  ospf6_lsdb_remove_all (nei->retrans_list);
-  ospf6_lsdb_remove_all (nei->dbdesc_list);
-}
-
-void
-ospf6_neighbor_summary_add (struct ospf6_lsa *lsa,
-                            struct ospf6_neighbor *nei)
-{
-  struct ospf6_lsa *summary;
-
-  if (IS_OSPF6_DUMP_NEIGHBOR)
+  for (n = listhead (oi->neighbor_list); n; nextnode (n))
     {
-      zlog_info ("Neighbor %s summary-list:", nei->str);
-      zlog_info ("    Add %s", lsa->str);
+      on = (struct ospf6_neighbor *) getdata (n);
+      if (on->router_id == router_id)
+        return on;
     }
-
-  ospf6_lsa_age_current (lsa);
-  summary = ospf6_lsa_summary_create (lsa->header);
-  ospf6_lsdb_add (summary, nei->summary_list);
-}
-
-void
-ospf6_neighbor_summary_remove (struct ospf6_lsa *lsa,
-                               struct ospf6_neighbor *nei)
-{
-  struct ospf6_lsa *summary;
-
-  if (IS_OSPF6_DUMP_NEIGHBOR)
-    {
-      zlog_info ("Neighbor %s summary-list:", nei->str);
-      zlog_info ("    Remove %s", lsa->str);
-    }
-
-  summary = ospf6_lsdb_lookup_lsdb (lsa->header->type, lsa->header->id,
-                                    lsa->header->adv_router, nei->summary_list);
-  ospf6_lsdb_remove (summary, nei->summary_list);
-}
-
-void
-ospf6_neighbor_request_add (struct ospf6_lsa *lsa,
-                            struct ospf6_neighbor *nei)
-{
-  struct ospf6_lsa *summary;
-
-  if (IS_OSPF6_DUMP_NEIGHBOR)
-    {
-      zlog_info ("Neighbor %s request-list:", nei->str);
-      zlog_info ("    Add %s", lsa->str);
-    }
-
-  ospf6_lsa_age_current (lsa);
-  summary = ospf6_lsa_summary_create (lsa->header);
-  ospf6_lsdb_add (summary, nei->request_list);
-}
-
-void
-ospf6_neighbor_request_remove (struct ospf6_lsa *lsa,
-                               struct ospf6_neighbor *nei)
-{
-  struct ospf6_lsa *summary;
-
-  if (IS_OSPF6_DUMP_NEIGHBOR)
-    {
-      zlog_info ("Neighbor %s request-list:", nei->str);
-      zlog_info ("    Remove %s", lsa->str);
-    }
-
-  summary = ospf6_lsdb_lookup_lsdb (lsa->header->type, lsa->header->id,
-                                    lsa->header->adv_router, nei->request_list);
-  ospf6_lsdb_remove (summary, nei->request_list);
-}
-
-void
-ospf6_neighbor_retrans_add (struct ospf6_lsa *lsa,
-                            struct ospf6_neighbor *nei)
-{
-  if (IS_OSPF6_DUMP_NEIGHBOR)
-    {
-      zlog_info ("Neighbor %s retrans-list:", nei->str);
-      zlog_info ("    Add %s", lsa->str);
-    }
-
-  ospf6_lsdb_add (lsa, nei->retrans_list);
-}
-
-void
-ospf6_neighbor_retrans_remove (struct ospf6_lsa *lsa,
-                               struct ospf6_neighbor *nei)
-{
-  if (IS_OSPF6_DUMP_NEIGHBOR)
-    {
-      zlog_info ("Neighbor %s retrans-list:", nei->str);
-      zlog_info ("    Remove %s", lsa->str);
-    }
-
-  ospf6_lsdb_remove (lsa, nei->retrans_list);
-
-  if (nei->retrans_list->count == 0)
-    {
-      if (nei->send_update)
-        thread_cancel (nei->send_update);
-      nei->send_update = NULL;
-    }
-}
-
-void
-ospf6_neighbor_dbdesc_add (struct ospf6_lsa *lsa,
-                           struct ospf6_neighbor *nei)
-{
-  if (IS_OSPF6_DUMP_NEIGHBOR)
-    {
-      zlog_info ("Neighbor %s dbdesc-list:", nei->str);
-      zlog_info ("    Add %s", lsa->str);
-    }
-
-  ospf6_lsdb_add (lsa, nei->dbdesc_list);
-}
-
-void
-ospf6_neighbor_dbdesc_remove (struct ospf6_lsa *lsa,
-                              struct ospf6_neighbor *nei)
-{
-  if (IS_OSPF6_DUMP_NEIGHBOR)
-    {
-      zlog_info ("Neighbor %s dbdesc-list:", nei->str);
-      zlog_info ("    Remove %s", lsa->str);
-    }
-
-  ospf6_lsdb_remove (lsa, nei->dbdesc_list);
-}
-
-
-/* prepare summary-list of his neighbor structure */
-void
-ospf6_neighbor_dbex_init (struct ospf6_neighbor *nei)
-{
-  struct ospf6_lsdb_node node;
-
-  /* clear ls-list */
-  ospf6_neighbor_lslist_clear (nei);
-
-  /* AS scope LSAs */
-  for (ospf6_lsdb_head (&node, nei->ospf6_interface->area->ospf6->lsdb);
-       ! ospf6_lsdb_is_end (&node); ospf6_lsdb_next (&node))
-    {
-      if (IS_LSA_MAXAGE (node.lsa))
-        ospf6_neighbor_retrans_add (node.lsa, nei);
-      else
-        ospf6_neighbor_summary_add (node.lsa, nei);
-    }
-
-  /* AREA scope LSAs */
-  for (ospf6_lsdb_head (&node, nei->ospf6_interface->area->lsdb);
-       ! ospf6_lsdb_is_end (&node); ospf6_lsdb_next (&node))
-    {
-      if (IS_LSA_MAXAGE (node.lsa))
-        ospf6_neighbor_retrans_add (node.lsa, nei);
-      else
-        ospf6_neighbor_summary_add (node.lsa, nei);
-    }
-
-  /* INTERFACE scope LSAs */
-  for (ospf6_lsdb_head (&node, nei->ospf6_interface->lsdb);
-       ! ospf6_lsdb_is_end (&node); ospf6_lsdb_next (&node))
-    {
-      if (IS_LSA_MAXAGE (node.lsa))
-        ospf6_neighbor_retrans_add (node.lsa, nei);
-      else
-        ospf6_neighbor_summary_add (node.lsa, nei);
-    }
+  return (struct ospf6_neighbor *) NULL;
 }
 
 /* create ospf6_neighbor */
 struct ospf6_neighbor *
-ospf6_neighbor_create (u_int32_t router_id, struct ospf6_interface *o6i)
+ospf6_neighbor_create (u_int32_t router_id, struct ospf6_interface *oi)
 {
-  struct ospf6_neighbor *new;
-  char buf[32];
+  struct ospf6_neighbor *on;
+  char buf[16];
 
-  new = (struct ospf6_neighbor *)
+  on = (struct ospf6_neighbor *)
     XMALLOC (MTYPE_OSPF6_NEIGHBOR, sizeof (struct ospf6_neighbor));
-  if (new == NULL)
+  if (on == NULL)
     {
       zlog_warn ("neighbor: malloc failed");
       return NULL;
     }
 
-  memset (new, 0, sizeof (struct ospf6_neighbor));
-
-  new->state = OSPF6_NEIGHBOR_STATE_DOWN;
-
-  new->router_id = router_id;
+  memset (on, 0, sizeof (struct ospf6_neighbor));
   inet_ntop (AF_INET, &router_id, buf, sizeof (buf));
-  snprintf (new->str, sizeof (new->str), "%s%%%s", buf, o6i->interface->name);
-  new->inactivity_timer = (struct thread *) NULL;
+  snprintf (on->name, sizeof (on->name), "%s%%%s",
+            buf, oi->interface->name);
+  on->ospf6_if = oi;
+  on->state = OSPF6_NEIGHBOR_DOWN;
+  gettimeofday (&on->last_changed, (struct timezone *) NULL);
+  on->router_id = router_id;
 
-  new->summary_list = ospf6_lsdb_create ();
-  new->request_list = ospf6_lsdb_create ();
-  new->retrans_list = ospf6_lsdb_create ();
-  new->dbdesc_list = ospf6_lsdb_create ();
+  on->summary_list = ospf6_lsdb_create ();
+  on->request_list = ospf6_lsdb_create ();
+  on->retrans_list = ospf6_lsdb_create ();
 
-  listnode_add (o6i->neighbor_list, new);
-  new->ospf6_interface = o6i;
+  on->dbdesc_list = ospf6_lsdb_create ();
+  on->lsreq_list = ospf6_lsdb_create ();
+  on->lsupdate_list = ospf6_lsdb_create ();
+  on->lsack_list = ospf6_lsdb_create ();
 
-  CALL_ADD_HOOK (&neighbor_hook, new);
-
-  return new;
+  listnode_add_sort (oi->neighbor_list, on);
+  return on;
 }
 
 void
-ospf6_neighbor_delete (struct ospf6_neighbor *o6n)
+ospf6_neighbor_delete (struct ospf6_neighbor *on)
 {
-  CALL_REMOVE_HOOK (&neighbor_hook, o6n);
+  ospf6_lsdb_remove_all (on->summary_list);
+  ospf6_lsdb_remove_all (on->request_list);
+  ospf6_lsdb_remove_all (on->retrans_list);
 
-  ospf6_neighbor_thread_cancel_all (o6n);
-  ospf6_neighbor_lslist_clear (o6n);
+  ospf6_lsdb_remove_all (on->dbdesc_list);
+  ospf6_lsdb_remove_all (on->lsreq_list);
+  ospf6_lsdb_remove_all (on->lsupdate_list);
+  ospf6_lsdb_remove_all (on->lsack_list);
 
-  list_free (o6n->dbdesc_lsa);
+  ospf6_lsdb_delete (on->summary_list);
+  ospf6_lsdb_delete (on->request_list);
+  ospf6_lsdb_delete (on->retrans_list);
 
-  ospf6_lsdb_delete (o6n->summary_list);
-  ospf6_lsdb_delete (o6n->request_list);
-  ospf6_lsdb_delete (o6n->retrans_list);
-  ospf6_lsdb_delete (o6n->dbdesc_list);
+  ospf6_lsdb_delete (on->dbdesc_list);
+  ospf6_lsdb_delete (on->lsreq_list);
+  ospf6_lsdb_delete (on->lsupdate_list);
+  ospf6_lsdb_delete (on->lsack_list);
 
-  XFREE (MTYPE_OSPF6_NEIGHBOR, o6n);
+  THREAD_OFF (on->inactivity_timer);
+
+  THREAD_OFF (on->thread_send_dbdesc);
+  THREAD_OFF (on->thread_send_lsreq);
+  THREAD_OFF (on->thread_send_lsupdate);
+  THREAD_OFF (on->thread_send_lsack);
+
+  XFREE (MTYPE_OSPF6_NEIGHBOR, on);
 }
 
-struct ospf6_neighbor *
-ospf6_neighbor_lookup (u_int32_t router_id,
-                       struct ospf6_interface *o6i)
+static void
+ospf6_neighbor_state_change (u_char next_state, struct ospf6_neighbor *on)
 {
-  listnode n;
-  struct ospf6_neighbor *o6n;
+  u_char prev_state;
 
-  for (n = listhead (o6i->neighbor_list); n; nextnode (n))
+  prev_state = on->state;
+  on->state = next_state;
+
+  if (prev_state == next_state)
+    return;
+
+  gettimeofday (&on->last_changed, (struct timezone *) NULL);
+
+  /* log */
+  if (IS_OSPF6_DEBUG_NEIGHBOR (STATE))
     {
-      o6n = (struct ospf6_neighbor *) getdata (n);
-      if (o6n->router_id == router_id)
-        return o6n;
+      zlog_info ("Neighbor state change %s: [%s]->[%s]", on->name,
+                 ospf6_neighbor_state_str[prev_state],
+                 ospf6_neighbor_state_str[next_state]);
     }
-  return (struct ospf6_neighbor *) NULL;
+
+  if (prev_state == OSPF6_NEIGHBOR_FULL || next_state == OSPF6_NEIGHBOR_FULL)
+    {
+      OSPF6_ROUTER_LSA_SCHEDULE (on->ospf6_if->area);
+      if (on->ospf6_if->state == OSPF6_INTERFACE_DR)
+        {
+          OSPF6_NETWORK_LSA_SCHEDULE (on->ospf6_if);
+          OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT (on->ospf6_if);
+          OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB (on->ospf6_if->area);
+        }
+    }
+
+#ifdef XXX
+  if (prev_state == NBS_FULL || next_state == NBS_FULL)
+    nbs_full_change (on->ospf6_interface);
+
+  /* check for LSAs that already reached MaxAge */
+  if ((prev_state == OSPF6_NEIGHBOR_EXCHANGE ||
+       prev_state == OSPF6_NEIGHBOR_LOADING) &&
+      (next_state != OSPF6_NEIGHBOR_EXCHANGE &&
+       next_state != OSPF6_NEIGHBOR_LOADING))
+    {
+      ospf6_maxage_remover ();
+    }
+#endif /*XXX*/
+
 }
 
+/* RFC2328 section 10.4 */
+int
+need_adjacency (struct ospf6_neighbor *on)
+{
+  if (on->ospf6_if->state == OSPF6_INTERFACE_POINTTOPOINT ||
+      on->ospf6_if->state == OSPF6_INTERFACE_DR ||
+      on->ospf6_if->state == OSPF6_INTERFACE_BDR)
+    return 1;
+
+  if (on->ospf6_if->drouter == on->router_id ||
+      on->ospf6_if->bdrouter == on->router_id)
+    return 1;
+
+  return 0;
+}
+
+int
+hello_received (struct thread *thread)
+{
+  struct ospf6_neighbor *on;
+
+  on = (struct ospf6_neighbor *) THREAD_ARG (thread);
+  assert (on);
+
+  if (IS_OSPF6_DEBUG_NEIGHBOR (EVENT))
+    zlog_info ("Neighbor Event %s: *HelloReceived*", on->name);
+
+  /* reset Inactivity Timer */
+  THREAD_OFF (on->inactivity_timer);
+  on->inactivity_timer = thread_add_timer (master, inactivity_timer, on,
+                                           on->ospf6_if->dead_interval);
+
+  if (on->state <= OSPF6_NEIGHBOR_DOWN)
+    ospf6_neighbor_state_change (OSPF6_NEIGHBOR_INIT, on);
+
+  return 0;
+}
+
+int
+twoway_received (struct thread *thread)
+{
+  struct ospf6_neighbor *on;
+
+  on = (struct ospf6_neighbor *) THREAD_ARG (thread);
+  assert (on);
+
+  if (on->state > OSPF6_NEIGHBOR_INIT)
+    return 0;
+
+  if (IS_OSPF6_DEBUG_NEIGHBOR (EVENT))
+    zlog_info ("Neighbor Event %s: *2Way-Received*", on->name);
+
+  thread_add_event (master, neighbor_change, on->ospf6_if, 0);
+
+  if (! need_adjacency (on))
+    {
+      ospf6_neighbor_state_change (OSPF6_NEIGHBOR_TWOWAY, on);
+      return 0;
+    }
+
+  ospf6_neighbor_state_change (OSPF6_NEIGHBOR_EXSTART, on);
+  SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MSBIT);
+  SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MBIT);
+  SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_IBIT);
+
+  THREAD_OFF (on->thread_send_dbdesc);
+  on->thread_send_dbdesc =
+    thread_add_event (master, ospf6_dbdesc_send, on, 0);
+
+  return 0;
+}
+
+int
+negotiation_done (struct thread *thread)
+{
+  struct ospf6_neighbor *on;
+  struct ospf6_lsa *lsa;
+
+  on = (struct ospf6_neighbor *) THREAD_ARG (thread);
+  assert (on);
+
+  if (on->state != OSPF6_NEIGHBOR_EXSTART)
+    return 0;
+
+  if (IS_OSPF6_DEBUG_NEIGHBOR (EVENT))
+    zlog_info ("Neighbor Event %s: *NegotiationDone*", on->name);
+
+  /* clear ls-list */
+  ospf6_lsdb_remove_all (on->summary_list);
+  ospf6_lsdb_remove_all (on->request_list);
+  ospf6_lsdb_remove_all (on->retrans_list);
+
+  /* Interface scoped LSAs */
+  for (lsa = ospf6_lsdb_head (on->ospf6_if->lsdb); lsa;
+       lsa = ospf6_lsdb_next (lsa))
+    {
+      if (IS_OSPF6_DEBUG_LSA (DATABASE))
+        zlog_info ("Add copy of %s to %s of %s", lsa->name,
+                   (OSPF6_LSA_IS_MAXAGE (lsa) ? "retrans_list" :
+                    "summary_list"), on->name);
+      if (OSPF6_LSA_IS_MAXAGE (lsa))
+        ospf6_lsdb_add (ospf6_lsa_copy (lsa), on->retrans_list);
+      else
+        ospf6_lsdb_add (ospf6_lsa_copy (lsa), on->summary_list);
+    }
+
+  /* Area scoped LSAs */
+  for (lsa = ospf6_lsdb_head (on->ospf6_if->area->lsdb); lsa;
+       lsa = ospf6_lsdb_next (lsa))
+    {
+      if (IS_OSPF6_DEBUG_LSA (DATABASE))
+        zlog_info ("Add copy of %s to %s of %s", lsa->name,
+                   (OSPF6_LSA_IS_MAXAGE (lsa) ? "retrans_list" :
+                    "summary_list"), on->name);
+      if (OSPF6_LSA_IS_MAXAGE (lsa))
+        ospf6_lsdb_add (ospf6_lsa_copy (lsa), on->retrans_list);
+      else
+        ospf6_lsdb_add (ospf6_lsa_copy (lsa), on->summary_list);
+    }
+
+  /* AS scoped LSAs */
+  for (lsa = ospf6_lsdb_head (on->ospf6_if->area->ospf6->lsdb); lsa;
+       lsa = ospf6_lsdb_next (lsa))
+    {
+      if (IS_OSPF6_DEBUG_LSA (DATABASE))
+        zlog_info ("Add copy of %s to %s of %s", lsa->name,
+                   (OSPF6_LSA_IS_MAXAGE (lsa) ? "retrans_list" :
+                    "summary_list"), on->name);
+      if (OSPF6_LSA_IS_MAXAGE (lsa))
+        ospf6_lsdb_add (ospf6_lsa_copy (lsa), on->retrans_list);
+      else
+        ospf6_lsdb_add (ospf6_lsa_copy (lsa), on->summary_list);
+    }
+
+  UNSET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_IBIT);
+  ospf6_neighbor_state_change (OSPF6_NEIGHBOR_EXCHANGE, on);
+
+  return 0;
+}
+
+int
+exchange_done (struct thread *thread)
+{
+  struct ospf6_neighbor *on;
+
+  on = (struct ospf6_neighbor *) THREAD_ARG (thread);
+  assert (on);
+
+  if (on->state != OSPF6_NEIGHBOR_EXCHANGE)
+    return 0;
+
+  if (IS_OSPF6_DEBUG_NEIGHBOR (EVENT))
+    zlog_info ("Neighbor Event %s: *ExchangeDone*", on->name);
+
+  THREAD_OFF (on->thread_send_dbdesc);
+  ospf6_lsdb_remove_all (on->dbdesc_list);
+
+/* XXX
+  thread_add_timer (master, ospf6_neighbor_last_dbdesc_release, on,
+                    on->ospf6_if->dead_interval);
+*/
+
+  if (on->request_list->count == 0)
+    ospf6_neighbor_state_change (OSPF6_NEIGHBOR_FULL, on);
+  else
+    ospf6_neighbor_state_change (OSPF6_NEIGHBOR_LOADING, on);
+
+  return 0;
+}
+
+int
+loading_done (struct thread *thread)
+{
+  struct ospf6_neighbor *on;
+
+  on = (struct ospf6_neighbor *) THREAD_ARG (thread);
+  assert (on);
+
+  if (on->state != OSPF6_NEIGHBOR_LOADING)
+    return 0;
+
+  if (IS_OSPF6_DEBUG_NEIGHBOR (EVENT))
+    zlog_info ("Neighbor Event %s: *LoadingDone*", on->name);
+
+  assert (on->request_list->count == 0);
+
+  ospf6_neighbor_state_change (OSPF6_NEIGHBOR_FULL, on);
+
+  return 0;
+}
+
+int
+adj_ok (struct thread *thread)
+{
+  struct ospf6_neighbor *on;
+
+  on = (struct ospf6_neighbor *) THREAD_ARG (thread);
+  assert (on);
+
+  if (IS_OSPF6_DEBUG_NEIGHBOR (EVENT))
+    zlog_info ("Neighbor Event %s: *AdjOK?*", on->name);
+
+  if (on->state == OSPF6_NEIGHBOR_TWOWAY && need_adjacency (on))
+    {
+      ospf6_neighbor_state_change (OSPF6_NEIGHBOR_EXSTART, on);
+      SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MSBIT);
+      SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MBIT);
+      SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_IBIT);
+
+      THREAD_OFF (on->thread_send_dbdesc);
+      on->thread_send_dbdesc =
+        thread_add_event (master, ospf6_dbdesc_send, on, 0);
+
+    }
+  else if (on->state >= OSPF6_NEIGHBOR_EXSTART &&
+           ! need_adjacency (on))
+    {
+      ospf6_neighbor_state_change (OSPF6_NEIGHBOR_TWOWAY, on);
+      ospf6_lsdb_remove_all (on->summary_list);
+      ospf6_lsdb_remove_all (on->request_list);
+      ospf6_lsdb_remove_all (on->retrans_list);
+    }
+
+  return 0;
+}
+
+int
+seqnumber_mismatch (struct thread *thread)
+{
+  struct ospf6_neighbor *on;
+
+  on = (struct ospf6_neighbor *) THREAD_ARG (thread);
+  assert (on);
+
+  if (on->state < OSPF6_NEIGHBOR_EXCHANGE)
+    return 0;
+
+  if (IS_OSPF6_DEBUG_NEIGHBOR (EVENT))
+    zlog_info ("Neighbor Event %s: *SeqNumberMismatch*", on->name);
+
+  ospf6_neighbor_state_change (OSPF6_NEIGHBOR_EXSTART, on);
+  SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MSBIT);
+  SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MBIT);
+  SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_IBIT);
+
+  ospf6_lsdb_remove_all (on->summary_list);
+  ospf6_lsdb_remove_all (on->request_list);
+  ospf6_lsdb_remove_all (on->retrans_list);
+
+  THREAD_OFF (on->thread_send_dbdesc);
+  on->thread_send_dbdesc =
+    thread_add_event (master, ospf6_dbdesc_send, on, 0);
+
+  return 0;
+}
+
+int
+bad_lsreq (struct thread *thread)
+{
+  struct ospf6_neighbor *on;
+
+  on = (struct ospf6_neighbor *) THREAD_ARG (thread);
+  assert (on);
+
+  if (on->state < OSPF6_NEIGHBOR_EXCHANGE)
+    return 0;
+
+  if (IS_OSPF6_DEBUG_NEIGHBOR (EVENT))
+    zlog_info ("Neighbor Event %s: *BadLSReq*", on->name);
+
+  ospf6_neighbor_state_change (OSPF6_NEIGHBOR_EXSTART, on);
+  SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MSBIT);
+  SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MBIT);
+  SET_FLAG (on->dbdesc_bits, OSPF6_DBDESC_IBIT);
+
+  ospf6_lsdb_remove_all (on->summary_list);
+  ospf6_lsdb_remove_all (on->request_list);
+  ospf6_lsdb_remove_all (on->retrans_list);
+
+  THREAD_OFF (on->thread_send_dbdesc);
+  on->thread_send_dbdesc =
+    thread_add_event (master, ospf6_dbdesc_send, on, 0);
+
+  return 0;
+}
+
+int
+oneway_received (struct thread *thread)
+{
+  struct ospf6_neighbor *on;
+
+  on = (struct ospf6_neighbor *) THREAD_ARG (thread);
+  assert (on);
+
+  if (on->state < OSPF6_NEIGHBOR_TWOWAY)
+    return 0;
+
+  if (IS_OSPF6_DEBUG_NEIGHBOR (EVENT))
+    zlog_info ("Neighbor Event %s: *1Way-Received*", on->name);
+
+  ospf6_neighbor_state_change (OSPF6_NEIGHBOR_INIT, on);
+  thread_add_event (master, neighbor_change, on->ospf6_if, 0);
+
+  ospf6_lsdb_remove_all (on->summary_list);
+  ospf6_lsdb_remove_all (on->request_list);
+  ospf6_lsdb_remove_all (on->retrans_list);
+
+  THREAD_OFF (on->thread_send_dbdesc);
+  THREAD_OFF (on->thread_send_lsreq);
+  THREAD_OFF (on->thread_send_lsupdate);
+  THREAD_OFF (on->thread_send_lsack);
+
+  return 0;
+}
+
+int
+inactivity_timer (struct thread *thread)
+{
+  struct ospf6_neighbor *on;
+
+  on = (struct ospf6_neighbor *) THREAD_ARG (thread);
+  assert (on);
+
+  if (IS_OSPF6_DEBUG_NEIGHBOR (EVENT))
+    zlog_info ("Neighbor Event %s: *InactivityTimer*", on->name);
+
+  on->inactivity_timer = NULL;
+  on->drouter = on->prev_drouter = 0;
+  on->bdrouter = on->prev_bdrouter = 0;
+
+  ospf6_neighbor_state_change (OSPF6_NEIGHBOR_DOWN, on);
+  thread_add_event (master, neighbor_change, on->ospf6_if, 0);
+
+  listnode_delete (on->ospf6_if->neighbor_list, on);
+  ospf6_neighbor_delete (on);
+
+  return 0;
+}
+
+
 
 /* vty functions */
 /* show neighbor structure */
 void
-ospf6_neighbor_show_summary (struct vty *vty, struct ospf6_neighbor *o6n)
+ospf6_neighbor_show (struct vty *vty, struct ospf6_neighbor *on)
 {
   char router_id[16];
-  char dr[16], bdr[16];
+  char duration[16];
+  struct timeval now, res;
+  char nstate[16];
+  char deadtime[16];
+  long h, m, s;
+
+  /* Router-ID (Name) */
+  inet_ntop (AF_INET, &on->router_id, router_id, sizeof (router_id));
+#ifdef HAVE_GETNAMEINFO
+  {
+  }
+#endif /*HAVE_GETNAMEINFO*/
+
+  gettimeofday (&now, NULL);
+
+  /* Dead time */
+  h = m = s = 0;
+  if (on->inactivity_timer)
+    {
+      s = on->inactivity_timer->u.sands.tv_sec - now.tv_sec;
+      h = s / 3600;
+      s -= h * 3600;
+      m = s / 60;
+      s -= m * 60;
+    }
+  snprintf (deadtime, sizeof (deadtime), "%02ld:%02ld:%02ld", h, m, s);
+
+  /* Neighbor State */
+  if (if_is_pointopoint (on->ospf6_if->interface))
+    snprintf (nstate, sizeof (nstate), "PointToPoint");
+  else
+    {
+      if (on->router_id == on->drouter)
+        snprintf (nstate, sizeof (nstate), "DR");
+      else if (on->router_id == on->bdrouter)
+        snprintf (nstate, sizeof (nstate), "BDR");
+      else
+        snprintf (nstate, sizeof (nstate), "DROther");
+    }
+
+  /* Duration */
+  timersub (&now, &on->last_changed, &res);
+  timerstring (&res, duration, sizeof (duration));
+
+  /*
+  vty_out (vty, "%-15s %3d %11s %6s/%-12s %11s %s[%s]%s",
+           "Neighbor ID", "Pri", "DeadTime", "State", "", "Duration",
+           "I/F", "State", VTY_NEWLINE);
+  */
+
+  vty_out (vty, "%-15s %3d %11s %6s/%-12s %11s %s[%s]%s",
+           router_id, on->priority, deadtime,
+           ospf6_neighbor_state_str[on->state], nstate, duration,
+           on->ospf6_if->interface->name,
+           ospf6_interface_state_str[on->ospf6_if->state], VTY_NEWLINE);
+}
+
+void
+ospf6_neighbor_show_drchoice (struct vty *vty, struct ospf6_neighbor *on)
+{
+  char router_id[16];
+  char drouter[16], bdrouter[16];
   char duration[16];
   struct timeval now, res;
 
@@ -343,247 +603,232 @@
              "State", VTY_NEWLINE);
 */
 
-  inet_ntop (AF_INET, &o6n->router_id, router_id, sizeof (router_id));
-  inet_ntop (AF_INET, &o6n->dr, dr, sizeof (dr));
-  inet_ntop (AF_INET, &o6n->bdr, bdr, sizeof (bdr));
+  inet_ntop (AF_INET, &on->router_id, router_id, sizeof (router_id));
+  inet_ntop (AF_INET, &on->drouter, drouter, sizeof (drouter));
+  inet_ntop (AF_INET, &on->bdrouter, bdrouter, sizeof (bdrouter));
 
   gettimeofday (&now, NULL);
-  ospf6_timeval_sub (&now, &o6n->last_changed, &res);
-  ospf6_timeval_string_summary (&res, duration, sizeof (duration));
+  timersub (&now, &on->last_changed, &res);
+  timerstring (&res, duration, sizeof (duration));
 
   vty_out (vty, "%-15s %6s/%-11s %-15s %-15s %s[%s]%s",
-           router_id, ospf6_neighbor_state_string[o6n->state],
-           duration, dr, bdr, o6n->ospf6_interface->interface->name,
-           ospf6_interface_state_string[o6n->ospf6_interface->state],
+           router_id, ospf6_neighbor_state_str[on->state],
+           duration, drouter, bdrouter, on->ospf6_if->interface->name,
+           ospf6_interface_state_str[on->ospf6_if->state],
            VTY_NEWLINE);
 }
 
 void
-ospf6_neighbor_show (struct vty *vty, struct ospf6_neighbor *o6n)
+ospf6_neighbor_show_detail (struct vty *vty, struct ospf6_neighbor *on)
 {
-  char hisaddr[64], timestring[32];
+  char drouter[16], bdrouter[16];
+  char linklocal_addr[64], duration[32];
   struct timeval now, res;
+  struct ospf6_lsa *lsa;
 
-  inet_ntop (AF_INET6, &o6n->hisaddr, hisaddr, sizeof (hisaddr));
-  vty_out (vty, " Neighbor %s, interface address %s%s",
-           o6n->str, hisaddr, VTY_NEWLINE);
-  vty_out (vty, "    Area %s via interface %s (ifindex %d)%s",
-           o6n->ospf6_interface->area->str,
-           o6n->ospf6_interface->interface->name,
-           o6n->ospf6_interface->interface->ifindex,
-           VTY_NEWLINE);
-  vty_out (vty, "    Priority: %d, State: %s, %d state changes%s",
-           o6n->priority, ospf6_neighbor_state_string[o6n->state],
-           o6n->ospf6_stat_state_changed, VTY_NEWLINE);
+  inet_ntop (AF_INET6, &on->linklocal_addr, linklocal_addr,
+             sizeof (linklocal_addr));
+  inet_ntop (AF_INET, &on->drouter, drouter, sizeof (drouter));
+  inet_ntop (AF_INET, &on->bdrouter, bdrouter, sizeof (bdrouter));
 
   gettimeofday (&now, NULL);
-  ospf6_timeval_sub (&now, &o6n->last_changed, &res);
-  ospf6_timeval_string_summary (&res, timestring, sizeof (timestring));
-  vty_out (vty, "    Last state changed: %s ago%s", timestring, VTY_NEWLINE);
-}
+  timersub (&now, &on->last_changed, &res);
+  timerstring (&res, duration, sizeof (duration));
 
-void
-ospf6_neighbor_show_detail (struct vty *vty, struct ospf6_neighbor *o6n)
-{
-  char hisdr[16], hisbdr[16];
-
-  ospf6_neighbor_show (vty, o6n);
-
-  inet_ntop (AF_INET, &o6n->dr, hisdr, sizeof (hisdr));
-  inet_ntop (AF_INET, &o6n->bdr, hisbdr, sizeof (hisbdr));
-
-  vty_out (vty, "    His Ifindex of myside: %d%s",
-                o6n->ifid, VTY_NEWLINE);
-  vty_out (vty, "    His DR Election: DR %s, BDR %s%s",
-                hisdr, hisbdr, VTY_NEWLINE);
-
-  vty_out (vty, "    Last received DbDesc: opt:%s"
-                " ifmtu:%hu bit:%s%s%s seqnum:%ld%s",
-                "xxx", ntohs (o6n->last_dd.ifmtu),
-                (DD_IS_IBIT_SET (o6n->last_dd.bits) ? "I" : "-"),
-                (DD_IS_MBIT_SET (o6n->last_dd.bits) ? "M" : "-"),
-                (DD_IS_MSBIT_SET (o6n->last_dd.bits) ? "m" : "s"),
-                (u_long)ntohl (o6n->last_dd.seqnum), VTY_NEWLINE);
-  vty_out (vty, "    My DbDesc bit for this neighbor: %s%s%s%s",
-           (DD_IS_IBIT_SET (o6n->dbdesc_bits) ? "I" : "-"),
-           (DD_IS_MBIT_SET (o6n->dbdesc_bits) ? "M" : "-"),
-           (DD_IS_MSBIT_SET (o6n->dbdesc_bits) ? "m" : "s"),
+  vty_out (vty, " Neighbor %s%s", on->name,
+           VTY_NEWLINE);
+  vty_out (vty, "    Area %s via interface %s (ifindex %d)%s",
+           on->ospf6_if->area->name,
+           on->ospf6_if->interface->name,
+           on->ospf6_if->interface->ifindex,
+           VTY_NEWLINE);
+  vty_out (vty, "    His IfIndex: %d Link-local address: %s%s",
+           on->ifindex, linklocal_addr,
+           VTY_NEWLINE);
+  vty_out (vty, "    State %s for a duration of %s%s",
+           ospf6_neighbor_state_str[on->state], duration,
+           VTY_NEWLINE);
+  vty_out (vty, "    His choice of DR/BDR %s/%s, Priority %d%s",
+           drouter, bdrouter, on->priority,
+           VTY_NEWLINE);
+  vty_out (vty, "    DbDesc status: %s%s%s SeqNum: %#lx%s",
+           (CHECK_FLAG (on->dbdesc_bits, OSPF6_DBDESC_IBIT) ? "Initial " : ""),
+           (CHECK_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MBIT) ? "More " : ""),
+           (CHECK_FLAG (on->dbdesc_bits, OSPF6_DBDESC_MSBIT) ?
+            "Master" : "Slave"), (u_long) ntohl (on->dbdesc_seqnum),
            VTY_NEWLINE);
 
-  vty_out (vty, "    %-16s %5d times, %-16s %5d times%s",
-                "SeqnumMismatch", o6n->ospf6_stat_seqnum_mismatch,
-                "BadLSReq", o6n->ospf6_stat_bad_lsreq, VTY_NEWLINE);
-  vty_out (vty, "    %-16s %5d times, %-16s %5d times%s",
-                "OnewayReceived", o6n->ospf6_stat_oneway_received,
-                "InactivityTimer", o6n->ospf6_stat_inactivity_timer,
-                VTY_NEWLINE);
-  vty_out (vty, "    %-16s %5d times, %-16s %5d times%s",
-                "DbDescRetrans", o6n->ospf6_stat_retrans_dbdesc,
-                "LSReqRetrans", o6n->ospf6_stat_retrans_lsreq,
-                VTY_NEWLINE);
-  vty_out (vty, "    %-16s %5d times%s",
-                "LSUpdateRetrans", o6n->ospf6_stat_retrans_lsupdate,
-                VTY_NEWLINE);
-  vty_out (vty, "    %-16s %5d times, %-16s %5d times%s",
-                "LSAReceived", o6n->ospf6_stat_received_lsa,
-                "LSUpdateReceived", o6n->ospf6_stat_received_lsupdate,
-                VTY_NEWLINE);
+  vty_out (vty, "    Summary-List: %d LSAs%s", on->summary_list->count,
+           VTY_NEWLINE);
+  for (lsa = ospf6_lsdb_head (on->summary_list); lsa;
+       lsa = ospf6_lsdb_next (lsa))
+    vty_out (vty, "      %s%s", lsa->name, VTY_NEWLINE);
 
-  vty_out (vty, "    %-12s %-12s %-12s%s",
-           "Message", "DbDesc", "LSReq", VTY_NEWLINE);
-  vty_out (vty, "    %-12s %12d %12d%s", "LSA Send",
-           o6n->lsa_send[OSPF6_MESSAGE_TYPE_DBDESC],
-           o6n->lsa_send[OSPF6_MESSAGE_TYPE_LSREQ], VTY_NEWLINE);
-  vty_out (vty, "    %-12s %12d %12d%s", "LSA Receive",
-           o6n->lsa_receive[OSPF6_MESSAGE_TYPE_DBDESC],
-           o6n->lsa_receive[OSPF6_MESSAGE_TYPE_LSREQ], VTY_NEWLINE);
-  vty_out (vty, "%s", VTY_NEWLINE);
+  vty_out (vty, "    Request-List: %d LSAs%s", on->request_list->count,
+           VTY_NEWLINE);
+  for (lsa = ospf6_lsdb_head (on->request_list); lsa;
+       lsa = ospf6_lsdb_next (lsa))
+    vty_out (vty, "      %s%s", lsa->name, VTY_NEWLINE);
+
+  vty_out (vty, "    Retrans-List: %d LSAs%s", on->retrans_list->count,
+           VTY_NEWLINE);
+  for (lsa = ospf6_lsdb_head (on->retrans_list); lsa;
+       lsa = ospf6_lsdb_next (lsa))
+    vty_out (vty, "      %s%s", lsa->name, VTY_NEWLINE);
+
+  timerclear (&res);
+  if (on->thread_send_dbdesc)
+    timersub (&on->thread_send_dbdesc->u.sands, &now, &res);
+  timerstring (&res, duration, sizeof (duration));
+  vty_out (vty, "    %d Pending LSAs for DbDesc in Time %s [thread %s]%s",
+           on->dbdesc_list->count, duration,
+           (on->thread_send_dbdesc ? "on" : "off"),
+           VTY_NEWLINE);
+  for (lsa = ospf6_lsdb_head (on->dbdesc_list); lsa;
+       lsa = ospf6_lsdb_next (lsa))
+    vty_out (vty, "      %s%s", lsa->name, VTY_NEWLINE);
+
+  timerclear (&res);
+  if (on->thread_send_lsreq)
+    timersub (&on->thread_send_lsreq->u.sands, &now, &res);
+  timerstring (&res, duration, sizeof (duration));
+  vty_out (vty, "    %d Pending LSAs for LSReq in Time %s [thread %s]%s",
+           on->lsreq_list->count, duration,
+           (on->thread_send_lsreq ? "on" : "off"),
+           VTY_NEWLINE);
+  for (lsa = ospf6_lsdb_head (on->lsreq_list); lsa;
+       lsa = ospf6_lsdb_next (lsa))
+    vty_out (vty, "      %s%s", lsa->name, VTY_NEWLINE);
+
+  timerclear (&res);
+  if (on->thread_send_lsupdate)
+    timersub (&on->thread_send_lsupdate->u.sands, &now, &res);
+  timerstring (&res, duration, sizeof (duration));
+  vty_out (vty, "    %d Pending LSAs for LSUpdate in Time %s [thread %s]%s",
+           on->lsupdate_list->count, duration,
+           (on->thread_send_lsupdate ? "on" : "off"),
+           VTY_NEWLINE);
+  for (lsa = ospf6_lsdb_head (on->lsupdate_list); lsa;
+       lsa = ospf6_lsdb_next (lsa))
+    vty_out (vty, "      %s%s", lsa->name, VTY_NEWLINE);
+
+  timerclear (&res);
+  if (on->thread_send_lsack)
+    timersub (&on->thread_send_lsack->u.sands, &now, &res);
+  timerstring (&res, duration, sizeof (duration));
+  vty_out (vty, "    %d Pending LSAs for LSAck in Time %s [thread %s]%s",
+           on->lsack_list->count, duration,
+           (on->thread_send_lsack ? "on" : "off"),
+           VTY_NEWLINE);
+  for (lsa = ospf6_lsdb_head (on->lsack_list); lsa;
+       lsa = ospf6_lsdb_next (lsa))
+    vty_out (vty, "      %s%s", lsa->name, VTY_NEWLINE);
+
 }
 
-void
-ospf6_neighbor_timestamp_hello (struct ospf6_neighbor *o6n)
-{
-  struct timeval now, interval;
-  gettimeofday (&now, (struct timezone *) NULL);
-  if (o6n->tv_last_hello_received.tv_sec)
-    {
-      ospf6_timeval_sub (&now, &o6n->tv_last_hello_received, &interval);
-      zlog_info ("Hello Interval %s : %ld msec",
-                  o6n->str, interval.tv_sec * 1000 + interval.tv_usec % 1000);
-    }
-  o6n->tv_last_hello_received.tv_sec = now.tv_sec;
-  o6n->tv_last_hello_received.tv_usec = now.tv_usec;
-}
-
-DEFUN (show_ipv6_ospf6_neighbor_routerid,
-       show_ipv6_ospf6_neighbor_routerid_cmd,
-       "show ipv6 ospf6 neighbor A.B.C.D",
-       SHOW_STR
-       IP6_STR
-       OSPF6_STR
-       "Neighbor list\n"
-       "OSPF6 neighbor Router ID in IP address format\n"
-       )
-{
-  u_int32_t router_id;
-  struct ospf6_neighbor *o6n;
-  struct ospf6_interface *o6i;
-  struct ospf6_area *o6a;
-  listnode nodei, nodej, nodek;
-
-  OSPF6_CMD_CHECK_RUNNING ();
-
-  if (argc == 0)
-    vty_out (vty, "%-15s %6s/%-11s %-15s %-15s %s[%s]%s",
-             "RouterID", "State", "Duration", "DR", "BDR", "I/F",
-             "State", VTY_NEWLINE);
-  else if (inet_pton (AF_INET, argv[0], &router_id) != 1)
-    {
-      vty_out (vty, "Malformed Router-ID: %s%s", argv[0], VTY_NEWLINE);
-      return CMD_SUCCESS;
-    }
-
-  for (nodei = listhead (ospf6->area_list); nodei; nextnode (nodei))
-    {
-      o6a = getdata (nodei);
-      for (nodej = listhead (o6a->if_list); nodej; nextnode (nodej))
-        {
-          o6i = getdata (nodej);
-          for (nodek = listhead (o6i->neighbor_list); nodek; nextnode (nodek))
-            {
-              o6n = getdata (nodek);
-              if (argc == 0)
-                ospf6_neighbor_show_summary (vty, o6n);
-              else if (o6n->router_id == router_id)
-                ospf6_neighbor_show_detail (vty, o6n);
-            }
-        }
-    }
-  return CMD_SUCCESS;
-}
-
-ALIAS (show_ipv6_ospf6_neighbor_routerid,
+DEFUN (show_ipv6_ospf6_neighbor,
        show_ipv6_ospf6_neighbor_cmd,
        "show ipv6 ospf6 neighbor",
        SHOW_STR
        IP6_STR
        OSPF6_STR
        "Neighbor list\n"
-       )
-
-DEFUN (show_ipv6_ospf6_neighborlist,
-       show_ipv6_ospf6_neighborlist_cmd,
-       "show ipv6 ospf6 (summary-list|request-list|retrans-list|dbdesc-list)",
-       SHOW_STR
-       IP6_STR
-       OSPF6_STR
-       "Link State summary list\n"
-       "Link State request list\n"
-       "Link State retransmission list\n"
-       "Link State Description list (Used to retrans DbDesc)\n"
-       )
+      )
 {
-  struct ospf6_area *o6a;
-  struct ospf6_interface *o6i;
-  struct ospf6_neighbor *o6n;
-  listnode i, j, k, l;
-  struct ospf6_lsa *lsa;
-  struct ospf6_lsdb *lsdb = NULL;
-  char type[16], id[16], adv_router[16];
-  struct ospf6_lsdb_node node;
-  u_int16_t age, cksum, len;
-  u_int32_t seqnum;
+  struct ospf6_neighbor *on;
+  struct ospf6_interface *oi;
+  struct ospf6_area *oa;
+  listnode i, j, k;
+  void (*showfunc) (struct vty *, struct ospf6_neighbor *);
 
   OSPF6_CMD_CHECK_RUNNING ();
-  i = j = k = l = NULL;
+  showfunc = ospf6_neighbor_show;
+
+  if (argc)
+    {
+      if (! strncmp (argv[0], "de", 2))
+        showfunc = ospf6_neighbor_show_detail;
+      else if (! strncmp (argv[0], "dr", 2))
+        showfunc = ospf6_neighbor_show_drchoice;
+    }
+
+  if (showfunc == ospf6_neighbor_show)
+    vty_out (vty, "%-15s %3s %11s %6s/%-12s %11s %s[%s]%s",
+             "Neighbor ID", "Pri", "DeadTime", "State", "IfState", "Duration",
+             "I/F", "State", VTY_NEWLINE);
+  else if (showfunc == ospf6_neighbor_show_drchoice)
+    vty_out (vty, "%-15s %6s/%-11s %-15s %-15s %s[%s]%s",
+             "RouterID", "State", "Duration", "DR", "BDR", "I/F",
+             "State", VTY_NEWLINE);
 
   for (i = listhead (ospf6->area_list); i; nextnode (i))
     {
-      o6a = (struct ospf6_area *) getdata (i);
-      for (j = listhead (o6a->if_list); j; nextnode (j))
+      oa = (struct ospf6_area *) getdata (i);
+      for (j = listhead (oa->if_list); j; nextnode (j))
         {
-          o6i = (struct ospf6_interface *) getdata (j);
-          for (k = listhead (o6i->neighbor_list); k; nextnode (k))
+          oi = (struct ospf6_interface *) getdata (j);
+          for (k = listhead (oi->neighbor_list); k; nextnode (k))
             {
-              o6n = (struct ospf6_neighbor *) getdata (k);
-
-              if (strncmp (argv[0], "sum", 3) == 0)
-                lsdb = o6n->summary_list;
-              else if (strncmp (argv[0], "req", 3) == 0)
-                lsdb = o6n->request_list;
-              else if (strncmp (argv[0], "ret", 3) == 0)
-                lsdb = o6n->retrans_list;
-              else if (strncmp (argv[0], "dbd", 3) == 0)
-                lsdb = o6n->dbdesc_list;
-
-              vty_out (vty, "neighbor %s on interface %s: %d%s", o6n->str,
-                       o6i->interface->name, lsdb->count,
-                       VTY_NEWLINE);
-              for (ospf6_lsdb_head (&node, lsdb); ! ospf6_lsdb_is_end (&node);
-                   ospf6_lsdb_next (&node))
-                {
-                  lsa = node.lsa;
-                  ospf6_lsa_age_current (lsa);
-
-                  ospf6_lsa_type_string (lsa->header->type, type,
-                                         sizeof (type));
-                  inet_ntop (AF_INET, &lsa->header->id, id, sizeof (id));
-                  inet_ntop (AF_INET, &lsa->header->adv_router, adv_router,
-                             sizeof (adv_router));
-                  age = ntohs (lsa->header->age);
-                  seqnum = ntohl (lsa->header->seqnum);
-                  cksum = ntohs (lsa->header->checksum);
-                  len = ntohs (lsa->header->length);
-
-                  vty_out (vty, "  %s-LSA ID=%s Adv=%s%s",
-                           type, id, adv_router, VTY_NEWLINE);
-                  vty_out (vty, "  Age: %hu SeqNum: %#x Cksum: %hx Len: %hu%s",
-                           age, seqnum, cksum, len, VTY_NEWLINE);
-                }
+              on = (struct ospf6_neighbor *) getdata (k);
+              (*showfunc) (vty, on);
             }
         }
     }
+  return CMD_SUCCESS;
+}
 
+ALIAS (show_ipv6_ospf6_neighbor,
+       show_ipv6_ospf6_neighbor_detail_cmd,
+       "show ipv6 ospf6 neighbor (detail|drchoice)",
+       SHOW_STR
+       IP6_STR
+       OSPF6_STR
+       "Neighbor list\n"
+       "Display details\n"
+       "Display DR choices\n"
+      );
+
+DEFUN (show_ipv6_ospf6_neighbor_one,
+       show_ipv6_ospf6_neighbor_one_cmd,
+       "show ipv6 ospf6 neighbor A.B.C.D",
+       SHOW_STR
+       IP6_STR
+       OSPF6_STR
+       "Neighbor list\n"
+       "Specify Router-ID as IPv4 address notation\n"
+      )
+{
+  struct ospf6_neighbor *on;
+  struct ospf6_interface *oi;
+  struct ospf6_area *oa;
+  listnode i, j, k;
+  void (*showfunc) (struct vty *, struct ospf6_neighbor *);
+  u_int32_t router_id;
+
+  OSPF6_CMD_CHECK_RUNNING ();
+  showfunc = ospf6_neighbor_show_detail;
+
+  if ((inet_pton (AF_INET, argv[0], &router_id)) != 1)
+    {
+      vty_out (vty, "Router-ID is not parsable: %s%s", argv[0],
+               VTY_NEWLINE);
+      return CMD_SUCCESS;
+    }
+
+  for (i = listhead (ospf6->area_list); i; nextnode (i))
+    {
+      oa = (struct ospf6_area *) getdata (i);
+      for (j = listhead (oa->if_list); j; nextnode (j))
+        {
+          oi = (struct ospf6_interface *) getdata (j);
+          for (k = listhead (oi->neighbor_list); k; nextnode (k))
+            {
+              on = (struct ospf6_neighbor *) getdata (k);
+              if (on->router_id == router_id)
+                (*showfunc) (vty, on);
+            }
+        }
+    }
   return CMD_SUCCESS;
 }
 
@@ -591,12 +836,104 @@
 ospf6_neighbor_init ()
 {
   install_element (VIEW_NODE, &show_ipv6_ospf6_neighbor_cmd);
-  install_element (VIEW_NODE, &show_ipv6_ospf6_neighbor_routerid_cmd);
-  install_element (VIEW_NODE, &show_ipv6_ospf6_neighborlist_cmd);
-
+  install_element (VIEW_NODE, &show_ipv6_ospf6_neighbor_detail_cmd);
   install_element (ENABLE_NODE, &show_ipv6_ospf6_neighbor_cmd);
-  install_element (ENABLE_NODE, &show_ipv6_ospf6_neighbor_routerid_cmd);
-  install_element (ENABLE_NODE, &show_ipv6_ospf6_neighborlist_cmd);
+  install_element (ENABLE_NODE, &show_ipv6_ospf6_neighbor_detail_cmd);
 }
 
+DEFUN (debug_ospf6_neighbor,
+       debug_ospf6_neighbor_cmd,
+       "debug ospf6 neighbor",
+       DEBUG_STR
+       OSPF6_STR
+       "Debug OSPFv3 Neighbor\n"
+      )
+{
+  unsigned char level = 0;
+  if (argc)
+    {
+      if (! strncmp (argv[0], "s", 1))
+        level = OSPF6_DEBUG_NEIGHBOR_STATE;
+      if (! strncmp (argv[0], "e", 1))
+        level = OSPF6_DEBUG_NEIGHBOR_EVENT;
+    }
+  else
+    level = OSPF6_DEBUG_NEIGHBOR_STATE | OSPF6_DEBUG_NEIGHBOR_EVENT;
+
+  OSPF6_DEBUG_NEIGHBOR_ON (level);
+  return CMD_SUCCESS;
+}
+
+ALIAS (debug_ospf6_neighbor,
+       debug_ospf6_neighbor_detail_cmd,
+       "debug ospf6 neighbor (state|event)",
+       DEBUG_STR
+       OSPF6_STR
+       "Debug OSPFv3 Neighbor\n"
+       "Debug OSPFv3 Neighbor State Change\n"
+       "Debug OSPFv3 Neighbor Event\n"
+      );
+
+DEFUN (no_debug_ospf6_neighbor,
+       no_debug_ospf6_neighbor_cmd,
+       "no debug ospf6 neighbor",
+       NO_STR
+       DEBUG_STR
+       OSPF6_STR
+       "Debug OSPFv3 Neighbor\n"
+      )
+{
+  unsigned char level = 0;
+  if (argc)
+    {
+      if (! strncmp (argv[0], "s", 1))
+        level = OSPF6_DEBUG_NEIGHBOR_STATE;
+      if (! strncmp (argv[0], "e", 1))
+        level = OSPF6_DEBUG_NEIGHBOR_EVENT;
+    }
+  else
+    level = OSPF6_DEBUG_NEIGHBOR_STATE | OSPF6_DEBUG_NEIGHBOR_EVENT;
+
+  OSPF6_DEBUG_NEIGHBOR_OFF (level);
+  return CMD_SUCCESS;
+}
+
+ALIAS (no_debug_ospf6_neighbor,
+       no_debug_ospf6_neighbor_detail_cmd,
+       "no debug ospf6 neighbor (state|event)",
+       NO_STR
+       DEBUG_STR
+       OSPF6_STR
+       "Debug OSPFv3 Neighbor\n"
+       "Debug OSPFv3 Neighbor State Change\n"
+       "Debug OSPFv3 Neighbor Event\n"
+      );
+
+int
+config_write_ospf6_debug_neighbor (struct vty *vty)
+{
+  if (IS_OSPF6_DEBUG_NEIGHBOR (STATE) &&
+      IS_OSPF6_DEBUG_NEIGHBOR (EVENT))
+    vty_out (vty, "debug ospf6 neighbor%s", VTY_NEWLINE);
+  else if (IS_OSPF6_DEBUG_NEIGHBOR (STATE))
+    vty_out (vty, "debug ospf6 neighbor state%s", VTY_NEWLINE);
+  else if (IS_OSPF6_DEBUG_NEIGHBOR (EVENT))
+    vty_out (vty, "debug ospf6 neighbor event%s", VTY_NEWLINE);
+  return 0;
+}
+
+void
+install_element_ospf6_debug_neighbor ()
+{
+  install_element (ENABLE_NODE, &debug_ospf6_neighbor_cmd);
+  install_element (ENABLE_NODE, &debug_ospf6_neighbor_detail_cmd);
+  install_element (ENABLE_NODE, &no_debug_ospf6_neighbor_cmd);
+  install_element (ENABLE_NODE, &no_debug_ospf6_neighbor_detail_cmd);
+  install_element (CONFIG_NODE, &debug_ospf6_neighbor_cmd);
+  install_element (CONFIG_NODE, &debug_ospf6_neighbor_detail_cmd);
+  install_element (CONFIG_NODE, &no_debug_ospf6_neighbor_cmd);
+  install_element (CONFIG_NODE, &no_debug_ospf6_neighbor_detail_cmd);
+}
+
+