/*
 * Copyright (C) 2003 Yasuhiro Ohara
 *
 * This file is part of GNU Zebra.
 *
 * GNU Zebra is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2, or (at your option) any
 * later version.
 *
 * GNU Zebra is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with GNU Zebra; see the file COPYING.  If not, write to the 
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 
 * Boston, MA 02111-1307, USA.  
 */

#include <zebra.h>

/* Include other stuffs */
#include "log.h"
#include "linklist.h"
#include "command.h"
#include "memory.h"
#include "thread.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_flood.h"

unsigned char conf_debug_ospf6_lsa = 0;

struct ospf6_lstype ospf6_lstype[OSPF6_LSTYPE_SIZE];

char *ospf6_lstype_str[OSPF6_LSTYPE_SIZE] =
  {"Unknown", "Router", "Network", "Inter-Prefix", "Inter-Router",
   "AS-External", "Group-Membership", "Type-7", "Link", "Intra-Prefix"};

char *
ospf6_lstype_name (u_int16_t type)
{
  static char buf[8];
  int index = ntohs (type) & OSPF6_LSTYPE_FCODE_MASK;

  if (index < OSPF6_LSTYPE_SIZE && ospf6_lstype_str[index])
    return ospf6_lstype_str[index];

  snprintf (buf, sizeof (buf), "0x%04hx", ntohs (type));
  return buf;
}

/* RFC2328: Section 13.2 */
int
ospf6_lsa_is_differ (struct ospf6_lsa *lsa1,
                     struct ospf6_lsa *lsa2)
{
  int len;

  assert (OSPF6_LSA_IS_SAME (lsa1, lsa2));

  /* XXX, Options ??? */

  ospf6_lsa_age_current (lsa1);
  ospf6_lsa_age_current (lsa2);
  if (ntohs (lsa1->header->age) == MAXAGE &&
      ntohs (lsa2->header->age) != MAXAGE)
    return 1;
  if (ntohs (lsa1->header->age) != MAXAGE &&
      ntohs (lsa2->header->age) == MAXAGE)
    return 1;

  /* compare body */
  if (ntohs (lsa1->header->length) != ntohs (lsa2->header->length))
    return 1;

  len = ntohs (lsa1->header->length) - sizeof (struct ospf6_lsa_header);
  return memcmp (lsa1->header + 1, lsa2->header + 1, len);
}

int
ospf6_lsa_is_changed (struct ospf6_lsa *lsa1,
                      struct ospf6_lsa *lsa2)
{
  int length;

  if (OSPF6_LSA_IS_MAXAGE (lsa1) ^ OSPF6_LSA_IS_MAXAGE (lsa2))
    return 1;
  if (ntohs (lsa1->header->length) != ntohs (lsa2->header->length))
    return 1;

  length = OSPF6_LSA_SIZE (lsa1->header) - sizeof (struct ospf6_lsa_header);
  assert (length > 0);

  return memcmp (OSPF6_LSA_HEADER_END (lsa1->header),
                 OSPF6_LSA_HEADER_END (lsa2->header), length);
}

/* ospf6 age functions */
/* calculate birth and set expire timer */
static void
ospf6_lsa_age_set (struct ospf6_lsa *lsa)
{
  struct timeval now;

  assert (lsa && lsa->header);

  if (gettimeofday (&now, (struct timezone *)NULL) < 0)
    zlog_warn ("LSA: gettimeofday failed, may fail LSA AGEs: %s",
               strerror (errno));

  lsa->birth.tv_sec = now.tv_sec - ntohs (lsa->header->age);
  lsa->birth.tv_usec = now.tv_usec;
  if (ntohs (lsa->header->age) != MAXAGE)
    lsa->expire = thread_add_timer (master, ospf6_lsa_expire, lsa,
                                    MAXAGE + lsa->birth.tv_sec
                                    - now.tv_sec);
  else
    lsa->expire = NULL;
  return;
}

/* this function calculates current age from its birth,
   then update age field of LSA header. return value is current age */
u_int16_t
ospf6_lsa_age_current (struct ospf6_lsa *lsa)
{
  struct timeval now;
  u_int32_t ulage;
  u_int16_t age;

  assert (lsa);
  assert (lsa->header);

  /* current time */
  if (gettimeofday (&now, (struct timezone *)NULL) < 0)
    zlog_warn ("LSA: gettimeofday failed, may fail LSA AGEs: %s",
               strerror (errno));

  /* calculate age */
  ulage = now.tv_sec - lsa->birth.tv_sec;

  /* if over MAXAGE, set to it */
  age = (ulage > MAXAGE ? MAXAGE : ulage);

  lsa->header->age = htons (age);
  return age;
}

/* update age field of LSA header with adding InfTransDelay */
void
ospf6_lsa_age_update_to_send (struct ospf6_lsa *lsa, u_int32_t transdelay)
{
  unsigned short age;

  age = ospf6_lsa_age_current (lsa) + transdelay;
  if (age > MAXAGE)
    age = MAXAGE;
  lsa->header->age = htons (age);
}

void
ospf6_lsa_premature_aging (struct ospf6_lsa *lsa)
{
  /* log */
  if (IS_OSPF6_DEBUG_LSA (ORIGINATE))
    zlog_info ("LSA: Premature aging: %s", lsa->name);

  THREAD_OFF (lsa->expire);
  THREAD_OFF (lsa->refresh);

  memset (&lsa->birth, 0, sizeof (struct timeval));
  thread_execute (master, ospf6_lsa_expire, lsa, 0);
}

/* check which is more recent. if a is more recent, return -1;
   if the same, return 0; otherwise(b is more recent), return 1 */
int
ospf6_lsa_compare (struct ospf6_lsa *a, struct ospf6_lsa *b)
{
  signed long seqnuma, seqnumb;
  u_int16_t cksuma, cksumb;
  u_int16_t agea, ageb;

  assert (a && a->header);
  assert (b && b->header);
  assert (OSPF6_LSA_IS_SAME (a, b));

  seqnuma = ((signed long) ntohl (a->header->seqnum))
             - (signed long) INITIAL_SEQUENCE_NUMBER;
  seqnumb = ((signed long) ntohl (b->header->seqnum))
             - (signed long) INITIAL_SEQUENCE_NUMBER;

  /* compare by sequence number */
  /* XXX, LS sequence number wrapping */
  if (seqnuma > seqnumb)
    return -1;
  else if (seqnuma < seqnumb)
    return 1;

  /* Checksum */
  cksuma = ntohs (a->header->checksum);
  cksumb = ntohs (b->header->checksum);
  if (cksuma > cksumb)
    return -1;
  if (cksuma < cksumb)
    return 0;

  /* Update Age */
  agea = ospf6_lsa_age_current (a);
  ageb = ospf6_lsa_age_current (b);

  /* MaxAge check */
  if (agea == MAXAGE && ageb != MAXAGE)
    return -1;
  else if (agea != MAXAGE && ageb == MAXAGE)
    return 1;

  /* Age check */
  if (agea > ageb && agea - ageb >= MAX_AGE_DIFF)
    return 1;
  else if (agea < ageb && ageb - agea >= MAX_AGE_DIFF)
    return -1;

  /* neither recent */
  return 0;
}

char *
ospf6_lsa_printbuf (struct ospf6_lsa *lsa, char *buf, int size)
{
  char id[16], adv_router[16];
  inet_ntop (AF_INET, &lsa->header->id, id, sizeof (id));
  inet_ntop (AF_INET, &lsa->header->adv_router, adv_router,
             sizeof (adv_router));
  snprintf (buf, size, "[%s Id:%s Adv:%s]",
            OSPF6_LSTYPE_NAME (lsa->header->type), id, adv_router);
  return buf;
}

void
ospf6_lsa_header_print_raw (struct ospf6_lsa_header *header)
{
  char id[16], adv_router[16];
  inet_ntop (AF_INET, &header->id, id, sizeof (id));
  inet_ntop (AF_INET, &header->adv_router, adv_router,
             sizeof (adv_router));
  zlog_info ("    [%s Id:%s Adv:%s]",
             OSPF6_LSTYPE_NAME (header->type), id, adv_router);
  zlog_info ("    Age: %4hu SeqNum: %#08lx Cksum: %04hx Len: %d",
             ntohs (header->age), (u_long) ntohl (header->seqnum),
             ntohs (header->checksum), ntohs (header->length));
}

void
ospf6_lsa_header_print (struct ospf6_lsa *lsa)
{
  ospf6_lsa_age_current (lsa);
  ospf6_lsa_header_print_raw (lsa->header);
}

void
ospf6_lsa_show (struct vty *vty, struct ospf6_lsa *lsa)
{
  char adv_router[64], id[64];
  int index;

  assert (lsa && lsa->header);

  inet_ntop (AF_INET, &lsa->header->id, id, sizeof (id));
  inet_ntop (AF_INET, &lsa->header->adv_router,
             adv_router, sizeof (adv_router));

  vty_out (vty, "%s", VTY_NEWLINE);
  vty_out (vty, "Age: %4hu Type: %s%s", ospf6_lsa_age_current (lsa),
           OSPF6_LSTYPE_NAME (lsa->header->type), VTY_NEWLINE);
  vty_out (vty, "Link State ID: %s%s", id, VTY_NEWLINE);
  vty_out (vty, "Advertising Router: %s%s", adv_router, VTY_NEWLINE);
  vty_out (vty, "LS Sequence Number: %#010lx%s",
           (u_long) ntohl (lsa->header->seqnum), VTY_NEWLINE);
  vty_out (vty, "CheckSum: %#06hx Length: %hu%s",
           ntohs (lsa->header->checksum),
           ntohs (lsa->header->length), VTY_NEWLINE);

  index = OSPF6_LSTYPE_INDEX (ntohs (lsa->header->type));
  if (ospf6_lstype[index].show)
    (*ospf6_lstype[index].show) (vty, lsa);
  else
    vty_out (vty, "%sUnknown LSA type ...%s", VTY_NEWLINE, VTY_NEWLINE);

  vty_out (vty, "%s", VTY_NEWLINE);
}

void
ospf6_lsa_show_summary_header (struct vty *vty)
{
  vty_out (vty, "%-12s %-15s %-15s %4s %8s %4s %4s %-8s%s",
           "Type", "LSId", "AdvRouter", "Age", "SeqNum",
           "Cksm", "Len", "Duration", VTY_NEWLINE);
}

void
ospf6_lsa_show_summary (struct vty *vty, struct ospf6_lsa *lsa)
{
  char adv_router[16], id[16];
  struct timeval now, res;
  char duration[16];

  assert (lsa);
  assert (lsa->header);

  inet_ntop (AF_INET, &lsa->header->id, id, sizeof (id));
  inet_ntop (AF_INET, &lsa->header->adv_router, adv_router,
             sizeof (adv_router));

  gettimeofday (&now, NULL);
  timersub (&now, &lsa->installed, &res);
  timerstring (&res, duration, sizeof (duration));

  vty_out (vty, "%-12s %-15s %-15s %4hu %8lx %04hx %4hu %8s%s",
           OSPF6_LSTYPE_NAME (lsa->header->type),
           id, adv_router, ospf6_lsa_age_current (lsa),
           (u_long) ntohl (lsa->header->seqnum),
           ntohs (lsa->header->checksum), ntohs (lsa->header->length),
           duration, VTY_NEWLINE);
}

void
ospf6_lsa_show_dump (struct vty *vty, struct ospf6_lsa *lsa)
{
  u_char *start, *end, *current;
  char byte[4];

  start = (char *) lsa->header;
  end = (char *) lsa->header + ntohs (lsa->header->length);

  vty_out (vty, "%s", VTY_NEWLINE);
  vty_out (vty, "%s:%s", lsa->name, VTY_NEWLINE);

  for (current = start; current < end; current ++)
    {
      if ((current - start) % 16 == 0)
        vty_out (vty, "%s        ", VTY_NEWLINE);
      else if ((current - start) % 4 == 0)
        vty_out (vty, " ");

      snprintf (byte, sizeof (byte), "%02x", *current);
      vty_out (vty, "%s", byte);
    }

  vty_out (vty, "%s%s", VTY_NEWLINE, VTY_NEWLINE);
}

void
ospf6_lsa_show_internal (struct vty *vty, struct ospf6_lsa *lsa)
{
  char adv_router[64], id[64];

  assert (lsa && lsa->header);

  inet_ntop (AF_INET, &lsa->header->id, id, sizeof (id));
  inet_ntop (AF_INET, &lsa->header->adv_router,
             adv_router, sizeof (adv_router));

  vty_out (vty, "%s", VTY_NEWLINE);
  vty_out (vty, "Age: %4hu Type: %s%s", ospf6_lsa_age_current (lsa),
           OSPF6_LSTYPE_NAME (lsa->header->type), VTY_NEWLINE);
  vty_out (vty, "Link State ID: %s%s", id, VTY_NEWLINE);
  vty_out (vty, "Advertising Router: %s%s", adv_router, VTY_NEWLINE);
  vty_out (vty, "LS Sequence Number: %#010lx%s",
           (u_long) ntohl (lsa->header->seqnum), VTY_NEWLINE);
  vty_out (vty, "CheckSum: %#06hx Length: %hu%s",
           ntohs (lsa->header->checksum),
           ntohs (lsa->header->length), VTY_NEWLINE);
  vty_out (vty, "    Prev: %p This: %p Next: %p%s",
           lsa->prev, lsa, lsa->next, VTY_NEWLINE);
  vty_out (vty, "    Reference count: %ld%s", lsa->refcnt, VTY_NEWLINE);
  vty_out (vty, "    Reference source: %s (%p) %s",
           (lsa->refsrc ? lsa->refsrc->name : "None"),
           lsa->refsrc, VTY_NEWLINE);
  vty_out (vty, "%s", VTY_NEWLINE);
}

/* OSPFv3 LSA creation/deletion function */

/* calculate LS sequence number for my new LSA.
   return value is network byte order */
u_int32_t
ospf6_lsa_new_seqnum (u_int16_t type, u_int32_t id, u_int32_t adv_router,
                      void *scope)
{
  struct ospf6_lsdb *lsdb = NULL;
  struct ospf6_lsa *lsa;
  signed long seqnum = 0;

  /* get current database copy */
  lsdb = ospf6_get_scoped_lsdb (type, scope);
  if (lsdb == NULL)
    {
      zlog_warn ("Can't decide scoped LSDB");
      return ((u_int32_t) htonl (INITIAL_SEQUENCE_NUMBER));
    }

  /* if current database copy not found, return InitialSequenceNumber */
  lsa = ospf6_lsdb_lookup (type, id, adv_router, lsdb);
  if (lsa == NULL)
    seqnum = INITIAL_SEQUENCE_NUMBER;
  else
    seqnum = (signed long) ntohl (lsa->header->seqnum) + 1;

  return ((u_int32_t) htonl (seqnum));
}

struct ospf6_lsa *
ospf6_lsa_create (struct ospf6_lsa_header *header)
{
  struct ospf6_lsa *lsa = NULL;
  struct ospf6_lsa_header *new_header = NULL;
  u_int16_t lsa_size = 0;

  /* size of the entire LSA */
  lsa_size = ntohs (header->length);   /* XXX vulnerable */

  /* allocate memory for this LSA */
  new_header = (struct ospf6_lsa_header *)
    XMALLOC (MTYPE_OSPF6_LSA, lsa_size);

  /* copy LSA from original header */
  memcpy (new_header, header, lsa_size);

  /* LSA information structure */
  /* allocate memory */
  lsa = (struct ospf6_lsa *)
    XMALLOC (MTYPE_OSPF6_LSA, sizeof (struct ospf6_lsa));
  memset (lsa, 0, sizeof (struct ospf6_lsa));

  lsa->header = (struct ospf6_lsa_header *) new_header;
  lsa->headeronly = 0; /* this is not header only */

  /* dump string */
  ospf6_lsa_printbuf (lsa, lsa->name, sizeof (lsa->name));

  /* calculate birth, expire and refresh of this lsa */
  ospf6_lsa_age_set (lsa);

  if (IS_OSPF6_DEBUG_LSA (MEMORY))
    zlog_info ("Create LSA Memory: %s (%p/%p)",
               lsa->name, lsa, lsa->header);

  return lsa;
}

struct ospf6_lsa *
ospf6_lsa_create_headeronly (struct ospf6_lsa_header *header)
{
  struct ospf6_lsa *lsa = NULL;
  struct ospf6_lsa_header *new_header = NULL;

  /* allocate memory for this LSA */
  new_header = (struct ospf6_lsa_header *)
    XMALLOC (MTYPE_OSPF6_LSA, sizeof (struct ospf6_lsa_header));

  /* copy LSA from original header */
  memcpy (new_header, header, sizeof (struct ospf6_lsa_header));

  /* LSA information structure */
  /* allocate memory */
  lsa = (struct ospf6_lsa *)
    XMALLOC (MTYPE_OSPF6_LSA, sizeof (struct ospf6_lsa));
  memset (lsa, 0, sizeof (struct ospf6_lsa));

  lsa->header = (struct ospf6_lsa_header *) new_header;
  lsa->headeronly = 1; /* this is header only */

  /* dump string */
  ospf6_lsa_printbuf (lsa, lsa->name, sizeof (lsa->name));

  /* calculate birth, expire and refresh of this lsa */
  ospf6_lsa_age_set (lsa);

  if (IS_OSPF6_DEBUG_LSA (MEMORY))
    zlog_info ("Create LSA (Header-only) Memory: %s (%p/%p)",
               lsa->name, lsa, lsa->header);

  return lsa;
}

void
ospf6_lsa_delete (struct ospf6_lsa *lsa)
{
  assert (lsa->lock == 0);

  /* cancel threads */
  THREAD_OFF (lsa->expire);
  THREAD_OFF (lsa->refresh);

  if (IS_OSPF6_DEBUG_LSA (MEMORY))
    zlog_info ("Delete LSA %s Memory: %s (%p/%p)",
               (lsa->headeronly ? "(Header-only) " : ""),
               lsa->name, lsa, lsa->header);

  /* do free */
  XFREE (MTYPE_OSPF6_LSA, lsa->header);
  XFREE (MTYPE_OSPF6_LSA, lsa);
}

struct ospf6_lsa *
ospf6_lsa_copy (struct ospf6_lsa *lsa)
{
  struct ospf6_lsa *copy = NULL;

  if (IS_OSPF6_DEBUG_LSA (MEMORY))
    zlog_info ("Create LSA Copy from %s", lsa->name);

  ospf6_lsa_age_current (lsa);
  if (lsa->headeronly)
    copy = ospf6_lsa_create_headeronly (lsa->header);
  else
    copy = ospf6_lsa_create (lsa->header);
  assert (copy->lock == 0);

  copy->installed = lsa->installed;
  copy->originated = lsa->originated;
  copy->scope = lsa->scope;

  copy->refsrc = lsa;
  copy->refsrc->refcnt++;

  return copy;
}

/* increment reference counter of struct ospf6_lsa */
void
ospf6_lsa_lock (struct ospf6_lsa *lsa)
{
  lsa->lock++;
  return;
}

/* decrement reference counter of struct ospf6_lsa */
void
ospf6_lsa_unlock (struct ospf6_lsa *lsa)
{
  /* decrement reference counter */
  assert (lsa->lock > 0);
  lsa->lock--;

  if (lsa->lock != 0)
    return;

  if (lsa->refsrc)
    lsa->refsrc->refcnt--;

  ospf6_lsa_delete (lsa);
}

void
ospf6_lsa_originate (struct ospf6_lsa *lsa)
{
  struct ospf6_lsa *old;
  struct ospf6_lsdb *lsdb = NULL;

  /* find previous LSA */
  lsdb = ospf6_get_scoped_lsdb (lsa->header->type, lsa->scope);
  if (lsdb == NULL)
    {
      zlog_warn ("Can't decide scoped LSDB");
      ospf6_lsa_delete (lsa);
      return;
    }

  old = ospf6_lsdb_lookup (lsa->header->type, lsa->header->id,
                           lsa->header->adv_router, lsdb);
  if (old)
    {
      /* If this origination is neither different instance nor refresh,
         suppress this origination */
      if (! CHECK_FLAG (old->flag, OSPF6_LSA_REFRESH) &&
          ! OSPF6_LSA_IS_DIFFER (lsa, old))
        {
          if (IS_OSPF6_DEBUG_LSA (ORIGINATE))
            zlog_info ("Suppress updating LSA: %s", lsa->name);
          ospf6_lsa_delete (lsa);
          return;
        }
    }

  lsa->refresh = thread_add_timer (master, ospf6_lsa_refresh, lsa,
                                   LS_REFRESH_TIME);

  if (IS_OSPF6_DEBUG_LSA (ORIGINATE))
    {
      zlog_info ("LSA Originate:");
      ospf6_lsa_header_print (lsa);
    }

  if (old)
    ospf6_flood_clear (old);
  ospf6_flood_lsa (lsa, NULL);
  ospf6_install_lsa (lsa, lsdb);
}

void
ospf6_lsa_re_originate (struct ospf6_lsa *lsa)
{
  u_int16_t index;

  if (IS_OSPF6_DEBUG_LSA (ORIGINATE))
    {
      zlog_info ("LSA Reoriginate:");
      ospf6_lsa_header_print (lsa);
    }

  index = OSPF6_LSTYPE_INDEX (ntohs (lsa->header->type));
  if (ospf6_lstype[index].reoriginate)
    (*ospf6_lstype[index].reoriginate) (lsa);
  else
    ospf6_lsa_premature_aging (lsa);
}


/* ospf6 lsa expiry */
int
ospf6_lsa_expire (struct thread *thread)
{
  struct ospf6_lsa *lsa;
  struct ospf6_lsdb *lsdb = NULL;

  lsa = (struct ospf6_lsa *) THREAD_ARG (thread);

  assert (lsa && lsa->header);
  assert (OSPF6_LSA_IS_MAXAGE (lsa));
  assert (! lsa->refresh);

  lsa->expire = (struct thread *) NULL;

  if (IS_OSPF6_DEBUG_LSA (TIMER))
    {
      zlog_info ("LSA Expire:");
      ospf6_lsa_header_print (lsa);
    }

  if (lsa->headeronly)
    return 0;    /* dbexchange will do something ... */

  /* reflood lsa */
  ospf6_flood_lsa (lsa, NULL);

  /* reinstall lsa */
  lsdb = ospf6_get_scoped_lsdb (lsa->header->type, lsa->scope);
  if (lsdb == NULL)
    {
      zlog_warn ("Can't decide scoped LSDB: %s", lsa->name);
      return 0;
    }
  if (IS_OSPF6_DEBUG_LSA (DATABASE))
    zlog_info ("Reinstall MaxAge %s", lsa->name);
  ospf6_lsdb_add (lsa, lsdb);

  /* schedule maxage remover */
  ospf6_maxage_remove (ospf6);

  return 0;
}

/* Below will become dummy thread.
   refresh function must be set individually per each LSAs */
int
ospf6_lsa_refresh (struct thread *thread)
{
  struct ospf6_lsa *lsa;

  assert (thread);
  lsa = (struct ospf6_lsa *) THREAD_ARG (thread);
  assert (lsa && lsa->header);

  lsa->refresh = (struct thread *) NULL;

  /* this will be used later to decide really originate or not */
  SET_FLAG (lsa->flag, OSPF6_LSA_REFRESH);

  if (IS_OSPF6_DEBUG_LSA (ORIGINATE))
    {
      zlog_info ("LSA Refresh:");
      ospf6_lsa_header_print (lsa);
    }

  ospf6_lsa_re_originate (lsa);
  return 0;
}



/* enhanced Fletcher checksum algorithm, RFC1008 7.2 */
#define MODX                4102
#define LSA_CHECKSUM_OFFSET   15

unsigned short
ospf6_lsa_checksum (struct ospf6_lsa_header *lsa_header)
{
  u_char *sp, *ep, *p, *q;
  int c0 = 0, c1 = 0;
  int x, y;
  u_int16_t length;

  lsa_header->checksum = 0;
  length = ntohs (lsa_header->length) - 2;
  sp = (char *) &lsa_header->type;

  for (ep = sp + length; sp < ep; sp = q)
    {
      q = sp + MODX;
      if (q > ep)
        q = ep;
      for (p = sp; p < q; p++)
        {
          c0 += *p;
          c1 += c0;
        }
      c0 %= 255;
      c1 %= 255;
    }

  /* r = (c1 << 8) + c0; */
  x = ((length - LSA_CHECKSUM_OFFSET) * c0 - c1) % 255;
  if (x <= 0)
    x += 255;
  y = 510 - c0 - x;
  if (y > 255)
    y -= 255;

  lsa_header->checksum = htons ((x << 8) + y);

  return (lsa_header->checksum);
}

int
ospf6_unknown_reoriginate (struct ospf6_lsa *lsa)
{
  ospf6_lsa_premature_aging (lsa);
  return 0;
}

int
ospf6_unknown_show (struct vty *vty, struct ospf6_lsa *lsa)
{
  u_char *start, *end, *current;
  char byte[4];

  start = (char *) lsa->header + sizeof (struct ospf6_lsa_header);
  end = (char *) lsa->header + ntohs (lsa->header->length);

  vty_out (vty, "        Unknown contents:%s", VTY_NEWLINE);
  for (current = start; current < end; current ++)
    {
      if ((current - start) % 16 == 0)
        vty_out (vty, "%s        ", VTY_NEWLINE);
      else if ((current - start) % 4 == 0)
        vty_out (vty, " ");

      snprintf (byte, sizeof (byte), "%02x", *current);
      vty_out (vty, "%s", byte);
    }

  vty_out (vty, "%s%s", VTY_NEWLINE, VTY_NEWLINE);
  return 0;
}

void
ospf6_lsa_init ()
{
  memset (ospf6_lstype, 0, sizeof (ospf6_lstype));

  ospf6_lstype[0].name = "Unknown";
  ospf6_lstype[0].reoriginate = ospf6_unknown_reoriginate;
  ospf6_lstype[0].show = ospf6_unknown_show;
}



DEFUN (debug_ospf6_lsa_sendrecv,
       debug_ospf6_lsa_sendrecv_cmd,
       "debug ospf6 lsa (send|recv|originate|timer|database|memory|all)",
       DEBUG_STR
       OSPF6_STR
       "Debug Link State Advertisements (LSAs)\n"
       "Debug Sending LSAs\n"
       "Debug Receiving LSAs\n"
       "Debug Originating LSAs\n"
       "Debug Timer Event of LSAs\n"
       "Debug LSA Database\n"
       "Debug Memory of LSAs\n"
       "Debug LSAs all\n"
      )
{
  unsigned char level = 0;

  if (argc)
    {
      if (! strncmp (argv[0], "s", 1))
        level = OSPF6_DEBUG_LSA_SEND;
      else if (! strncmp (argv[0], "r", 1))
        level = OSPF6_DEBUG_LSA_RECV;
      else if (! strncmp (argv[0], "o", 1))
        level = OSPF6_DEBUG_LSA_ORIGINATE;
      else if (! strncmp (argv[0], "t", 1))
        level = OSPF6_DEBUG_LSA_TIMER;
      else if (! strncmp (argv[0], "d", 1))
        level = OSPF6_DEBUG_LSA_DATABASE;
      else if (! strncmp (argv[0], "m", 1))
        level = OSPF6_DEBUG_LSA_MEMORY;
      else if (! strncmp (argv[0], "a", 1))
        {
          level = OSPF6_DEBUG_LSA_SEND | OSPF6_DEBUG_LSA_RECV |
                  OSPF6_DEBUG_LSA_ORIGINATE | OSPF6_DEBUG_LSA_TIMER |
                  OSPF6_DEBUG_LSA_DATABASE | OSPF6_DEBUG_LSA_MEMORY;
        }
    }
  else
    {
      level = OSPF6_DEBUG_LSA_SEND | OSPF6_DEBUG_LSA_RECV |
              OSPF6_DEBUG_LSA_ORIGINATE | OSPF6_DEBUG_LSA_TIMER;
    }

  OSPF6_DEBUG_LSA_ON (level);
  return CMD_SUCCESS;
}

ALIAS (debug_ospf6_lsa_sendrecv,
       debug_ospf6_lsa_cmd,
       "debug ospf6 lsa",
       NO_STR
       DEBUG_STR
       OSPF6_STR
       "Debug Link State Advertisements (LSAs)\n"
      );

DEFUN (no_debug_ospf6_lsa_sendrecv,
       no_debug_ospf6_lsa_sendrecv_cmd,
       "no debug ospf6 lsa (send|recv|originate|timer|database|memory|all)",
       NO_STR
       DEBUG_STR
       OSPF6_STR
       "Debug Link State Advertisements (LSAs)\n"
       "Debug Sending LSAs\n"
       "Debug Receiving LSAs\n"
       "Debug Originating LSAs\n"
       "Debug Timer Event of LSAs\n"
       "Debug LSA Database\n"
       "Debug Memory of LSAs\n"
       "Debug LSAs all\n"
      )
{
  unsigned char level = 0;

  if (argc)
    {
      if (! strncmp (argv[0], "s", 1))
        level = OSPF6_DEBUG_LSA_SEND;
      else if (! strncmp (argv[0], "r", 1))
        level = OSPF6_DEBUG_LSA_RECV;
      else if (! strncmp (argv[0], "o", 1))
        level = OSPF6_DEBUG_LSA_ORIGINATE;
      else if (! strncmp (argv[0], "t", 1))
        level = OSPF6_DEBUG_LSA_TIMER;
      else if (! strncmp (argv[0], "d", 1))
        level = OSPF6_DEBUG_LSA_DATABASE;
      else if (! strncmp (argv[0], "m", 1))
        level = OSPF6_DEBUG_LSA_MEMORY;
      else if (! strncmp (argv[0], "a", 1))
        {
          level = OSPF6_DEBUG_LSA_SEND | OSPF6_DEBUG_LSA_RECV |
                  OSPF6_DEBUG_LSA_ORIGINATE | OSPF6_DEBUG_LSA_TIMER |
                  OSPF6_DEBUG_LSA_DATABASE | OSPF6_DEBUG_LSA_MEMORY;
        }
    }
  else
    {
      level = OSPF6_DEBUG_LSA_SEND | OSPF6_DEBUG_LSA_RECV |
              OSPF6_DEBUG_LSA_ORIGINATE | OSPF6_DEBUG_LSA_TIMER;
    }

  OSPF6_DEBUG_LSA_OFF (level);
  return CMD_SUCCESS;
}

ALIAS (no_debug_ospf6_lsa_sendrecv,
       no_debug_ospf6_lsa_cmd,
       "no debug ospf6 lsa",
       NO_STR
       DEBUG_STR
       OSPF6_STR
       "Debug Link State Advertisements (LSAs)\n"
      );

int
config_write_ospf6_debug_lsa (struct vty *vty)
{
  if (conf_debug_ospf6_lsa == OSPF6_DEBUG_LSA_ALL)
    vty_out (vty, "debug ospf6 lsa all%s", VTY_NEWLINE);
  else
    {
      if (conf_debug_ospf6_lsa == OSPF6_DEBUG_LSA_DEFAULT)
        vty_out (vty, "debug ospf6 lsa%s", VTY_NEWLINE);
      else
        {
          if (IS_OSPF6_DEBUG_LSA (SEND))
            vty_out (vty, "debug ospf6 lsa send%s", VTY_NEWLINE);
          if (IS_OSPF6_DEBUG_LSA (RECV))
            vty_out (vty, "debug ospf6 lsa recv%s", VTY_NEWLINE);
          if (IS_OSPF6_DEBUG_LSA (ORIGINATE))
            vty_out (vty, "debug ospf6 lsa originate%s", VTY_NEWLINE);
          if (IS_OSPF6_DEBUG_LSA (TIMER))
            vty_out (vty, "debug ospf6 lsa timer%s", VTY_NEWLINE);
        }

      if (IS_OSPF6_DEBUG_LSA (DATABASE))
        vty_out (vty, "debug ospf6 lsa database%s", VTY_NEWLINE);
      if (IS_OSPF6_DEBUG_LSA (MEMORY))
        vty_out (vty, "debug ospf6 lsa memory%s", VTY_NEWLINE);
    }

  return 0;
}

void
install_element_ospf6_debug_lsa ()
{
  install_element (ENABLE_NODE, &debug_ospf6_lsa_cmd);
  install_element (ENABLE_NODE, &debug_ospf6_lsa_sendrecv_cmd);
  install_element (ENABLE_NODE, &no_debug_ospf6_lsa_cmd);
  install_element (ENABLE_NODE, &no_debug_ospf6_lsa_sendrecv_cmd);
  install_element (CONFIG_NODE, &debug_ospf6_lsa_cmd);
  install_element (CONFIG_NODE, &debug_ospf6_lsa_sendrecv_cmd);
  install_element (CONFIG_NODE, &no_debug_ospf6_lsa_cmd);
  install_element (CONFIG_NODE, &no_debug_ospf6_lsa_sendrecv_cmd);
}


