/*
 * IS-IS Rout(e)ing protocol - isis_lsp.c
 *                             LSP processing
 *
 * Copyright (C) 2001,2002   Sampo Saaristo
 *                           Tampere University of Technology      
 *                           Institute of Communications Engineering
 *
 * This program is free software; you can redistribute it and/or modify it 
 * under the terms of the GNU General Public Licenseas published by the Free 
 * Software Foundation; either version 2 of the License, or (at your option) 
 * any later version.
 *
 * This program 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 this program; if not, write to the Free Software Foundation, Inc., 
 * 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
#include <stdlib.h>
#include <stdio.h>
#include <zebra.h>
#include <net/ethernet.h>

#include "linklist.h"
#include "thread.h"
#include "vty.h"
#include "stream.h"
#include "memory.h"
#include "log.h"
#include "prefix.h"
#include "command.h"
#include "hash.h"
#include "if.h"

#include "isisd/dict.h"
#include "isisd/isis_constants.h"
#include "isisd/isis_common.h"
#include "isisd/isis_circuit.h"
#include "isisd/isisd.h"
#include "isisd/isis_tlv.h"
#include "isisd/isis_lsp.h"
#include "isisd/isis_pdu.h"
#include "isisd/isis_dynhn.h"
#include "isisd/isis_misc.h"
#include "isisd/isis_flags.h"
#include "isisd/iso_checksum.h"
#include "isisd/isis_csm.h"
#include "isisd/isis_adjacency.h"
#include "isisd/isis_spf.h"

#ifdef TOPOLOGY_GENERATE
#include "spgrid.h"
#endif

#define LSP_MEMORY_PREASSIGN 

extern struct isis *isis;
extern struct thread_master *master;

int 
lsp_id_cmp (u_char *id1, u_char *id2)
{  
  return memcmp (id1, id2, ISIS_SYS_ID_LEN + 2);
}

dict_t *
lsp_db_init (void) 
{
  dict_t *dict;
  
  dict = dict_create (DICTCOUNT_T_MAX, (dict_comp_t)lsp_id_cmp);
  
  return dict;
}

struct isis_lsp *
lsp_search (u_char *id, dict_t *lspdb)
{
  dnode_t *node;

#ifdef EXTREME_DEBUG 
  dnode_t *dn;

  zlog_warn("searching db");
  for (dn = dict_first(lspdb); dn; dn = dict_next(lspdb, dn)) {
    zlog_warn("%s\t%pX", rawlspid_print((char *) dnode_getkey(dn)), 
              dnode_get(dn));
  }
#endif /* EXTREME DEBUG */

  node = dict_lookup (lspdb, id);
  
  if (node)
    return (struct isis_lsp *)dnode_get (node);

  return NULL;
}

void
lsp_clear_data (struct isis_lsp *lsp)
{
  if (!lsp)
    return;
 
  if (lsp->own_lsp) {
    if (lsp->tlv_data.nlpids)
      XFREE (MTYPE_ISIS_TLV, lsp->tlv_data.nlpids);
    if (lsp->tlv_data.hostname)
      XFREE (MTYPE_ISIS_TLV, lsp->tlv_data.hostname);
  }
  if (lsp->tlv_data.is_neighs)
    list_delete (lsp->tlv_data.is_neighs);
  if (lsp->tlv_data.area_addrs)
    list_delete (lsp->tlv_data.area_addrs);
  if (lsp->tlv_data.es_neighs)
    list_delete (lsp->tlv_data.es_neighs);
  if (lsp->tlv_data.ipv4_addrs)
    list_delete (lsp->tlv_data.ipv4_addrs);
  if (lsp->tlv_data.ipv4_int_reachs)
    list_delete (lsp->tlv_data.ipv4_int_reachs);
  if (lsp->tlv_data.ipv4_ext_reachs)
    list_delete (lsp->tlv_data.ipv4_ext_reachs);
#ifdef HAVE_IPV6
  if (lsp->tlv_data.ipv6_addrs)
    list_delete (lsp->tlv_data.ipv6_addrs);
  if (lsp->tlv_data.ipv6_reachs)
    list_delete (lsp->tlv_data.ipv6_reachs);
#endif /* HAVE_IPV6 */

  memset (&lsp->tlv_data, 0, sizeof (struct tlvs));

  return;
}

void
lsp_destroy (struct isis_lsp *lsp)
{
  if (!lsp)
    return;
  
  lsp_clear_data (lsp);
  
  if (LSP_FRAGMENT (lsp->lsp_header->lsp_id) == 0 && lsp->lspu.frags) {
      list_delete (lsp->lspu.frags);
  }
  
  if (lsp->pdu)
    stream_free (lsp->pdu);
  XFREE (MTYPE_ISIS_LSP, lsp);
}

void 
lsp_db_destroy (dict_t *lspdb)
{
  dnode_t *dnode, *next;
  struct isis_lsp *lsp;
  
  dnode = dict_first (lspdb);
  while (dnode) {
    next = dict_next (lspdb, dnode);
    lsp = dnode_get (dnode);
    lsp_destroy (lsp);
    dict_delete_free (lspdb, dnode);
    dnode = next;
  }
  
  dict_free (lspdb);
  
  return;
}

/*
 * Remove all the frags belonging to the given lsp
 */
void
lsp_remove_frags (struct list *frags, dict_t *lspdb)
{
  dnode_t *dnode;
  struct listnode *lnode;
  struct isis_lsp *lsp;

  for (lnode = listhead (frags); lnode; nextnode (lnode)) {
    lsp = getdata (lnode);
    dnode = dict_lookup (lspdb, lsp->lsp_header->lsp_id);
    lsp_destroy (lsp);
    dnode_destroy (dict_delete(lspdb, dnode));
  }
  
  list_delete_all_node (frags);
  
  return;
}

void
lsp_search_and_destroy (u_char *id, dict_t *lspdb)
{
  dnode_t *node;
  struct isis_lsp *lsp;

  node = dict_lookup (lspdb, id);
  if (node) {
    node = dict_delete (lspdb, node);
    lsp = dnode_get (node);
    /*
     * If this is a zero lsp, remove all the frags now 
     */
    if (LSP_FRAGMENT(lsp->lsp_header->lsp_id) == 0) {
      if (lsp->lspu.frags)
        lsp_remove_frags (lsp->lspu.frags, lspdb);
    } else {
    /* 
     * else just remove this frag, from the zero lsps' frag list
     */
      if (lsp->lspu.zero_lsp && lsp->lspu.zero_lsp->lspu.frags)
        listnode_delete (lsp->lspu.zero_lsp->lspu.frags, lsp);
    }
    lsp_destroy (lsp);
    dnode_destroy (node);
  }
}

/*
 * Compares a LSP to given values
 * Params are given in net order
 */
int 
lsp_compare (char *areatag, struct isis_lsp *lsp, u_int32_t seq_num, 
	     u_int16_t checksum, u_int16_t rem_lifetime)
{
      /* no point in double ntohl on seqnum */
  if (lsp->lsp_header->seq_num == seq_num && 
      lsp->lsp_header->checksum == checksum &&
      /*comparing with 0, no need to do ntohl */
      ((lsp->lsp_header->rem_lifetime == 0 && rem_lifetime == 0) ||
       (lsp->lsp_header->rem_lifetime != 0 && rem_lifetime != 0))) { 
    if (isis->debugs & DEBUG_SNP_PACKETS) {
      zlog_info ("ISIS-Snp (%s): LSP %s seq 0x%08x, cksum 0x%04x,"
                 " lifetime %us",
                 areatag,
                 rawlspid_print (lsp->lsp_header->lsp_id),
                 ntohl(lsp->lsp_header->seq_num),
                 ntohs(lsp->lsp_header->checksum),
                 ntohs(lsp->lsp_header->rem_lifetime) );
      zlog_info ("ISIS-Snp (%s):         is equal to ours seq 0x%08x,"
                 " cksum 0x%04x, lifetime %us",
                 areatag,
                 ntohl(seq_num),
                 ntohs(checksum),
                 ntohs(rem_lifetime));
    }
    return LSP_EQUAL;
  }

  if (ntohl(seq_num) >= ntohl(lsp->lsp_header->seq_num)) {
    if (isis->debugs & DEBUG_SNP_PACKETS) {
      zlog_info ("ISIS-Snp (%s): LSP %s seq 0x%08x, cksum 0x%04x,"
                 " lifetime %us",
                 areatag,
                 rawlspid_print (lsp->lsp_header->lsp_id),
                 ntohl(seq_num),
                 ntohs(checksum),
                 ntohs(rem_lifetime ));
      zlog_info ("ISIS-Snp (%s):       is newer than ours seq 0x%08x, "
                 "cksum 0x%04x, lifetime %us",
                 areatag,
                 ntohl(lsp->lsp_header->seq_num),
                 ntohs(lsp->lsp_header->checksum),
                 ntohs(lsp->lsp_header->rem_lifetime) );
    }
    return LSP_NEWER;
  }
  if (isis->debugs & DEBUG_SNP_PACKETS) {
    zlog_info ("ISIS-Snp (%s): LSP %s seq 0x%08x, cksum 0x%04x, lifetime %us",
	       areatag,
	       rawlspid_print (lsp->lsp_header->lsp_id),
	       ntohl(seq_num),
	       ntohs(checksum),
	       ntohs(rem_lifetime ));
    zlog_info ("ISIS-Snp (%s):       is older than ours seq 0x%08x,"
               " cksum 0x%04x, lifetime %us",
	       areatag,
	       ntohl(lsp->lsp_header->seq_num),
	       ntohs(lsp->lsp_header->checksum),
	       ntohs(lsp->lsp_header->rem_lifetime) );
  }

  return LSP_OLDER;
}

void 
lsp_inc_seqnum (struct isis_lsp *lsp, u_int32_t seq_num)
{
  u_int32_t newseq;
  
  if (seq_num == 0 || ntohl (lsp->lsp_header->seq_num) > seq_num)
    newseq = ntohl (lsp->lsp_header->seq_num) + 1;
  else
    newseq = seq_num ++;
  
  lsp->lsp_header->seq_num = htonl (newseq);
  iso_csum_create (STREAM_DATA (lsp->pdu) + 12, 
                   ntohs(lsp->lsp_header->pdu_len) - 12, 12);

  return;
}

/*
 * Genetates checksum for LSP and its frags
 */
void
lsp_seqnum_update (struct isis_lsp *lsp0)
{
  struct isis_lsp *lsp;
  struct listnode *node;
  
  lsp_inc_seqnum (lsp0, 0);

  if (!lsp0->lspu.frags)
    return;

  for (node = listhead (lsp0->lspu.frags); node; nextnode (node)) {
    lsp = getdata (node);
    lsp_inc_seqnum(lsp, 0);
  }
  
  return;
}

int 
isis_lsp_authinfo_check (struct stream *stream, struct isis_area *area,
			 int  pdulen, struct isis_passwd *passwd)
{
  uint32_t expected = 0, found;
  struct tlvs tlvs;
  int retval = 0;

  expected |= TLVFLAG_AUTH_INFO;
  retval = parse_tlvs (area->area_tag, stream->data +
                       ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN,
                       pdulen - ISIS_FIXED_HDR_LEN 
                       - ISIS_LSP_HDR_LEN, 
		       &expected, &found, &tlvs);
  if (retval || !(found & TLVFLAG_AUTH_INFO))
    return 1; /* Auth fail (parsing failed or no auth-tlv)*/

  return authentication_check (passwd, &tlvs.auth_info);
}

void
lsp_update_data (struct isis_lsp *lsp, struct stream *stream, 
                 struct isis_area *area)
{
  uint32_t expected = 0,found;
  int retval;
  
  /* copying only the relevant part of our stream */
  lsp->pdu = stream_new (stream->endp);
  lsp->pdu->putp = stream->putp;
  lsp->pdu->getp = stream->getp;
  lsp->pdu->endp = stream->endp;
  memcpy (lsp->pdu->data, stream->data, stream->endp);

  /* setting pointers to the correct place */
  lsp->isis_header = (struct isis_fixed_hdr *)(STREAM_DATA(lsp->pdu));
  lsp->lsp_header = (struct isis_link_state_hdr *)(STREAM_DATA(lsp->pdu) + 
						   ISIS_FIXED_HDR_LEN);
  lsp->age_out = ZERO_AGE_LIFETIME;
  lsp->installed = time(NULL);
  /*
   * Get LSP data i.e. TLVs
   */
  expected |= TLVFLAG_AUTH_INFO;
  expected |= TLVFLAG_AREA_ADDRS;
  expected |= TLVFLAG_IS_NEIGHS;
  if ((lsp->lsp_header->lsp_bits & 3) == 3) /* a level 2 LSP */
    expected |= TLVFLAG_PARTITION_DESIG_LEVEL2_IS;
  expected |= TLVFLAG_NLPID;
  if (area->dynhostname)
    expected |= TLVFLAG_DYN_HOSTNAME;
  if (area->newmetric) {
    expected |= TLVFLAG_TE_IS_NEIGHS;
    expected |= TLVFLAG_TE_IPV4_REACHABILITY;
    expected |= TLVFLAG_TE_ROUTER_ID;
  }
  expected |= TLVFLAG_IPV4_ADDR;
  expected |= TLVFLAG_IPV4_INT_REACHABILITY;
  expected |= TLVFLAG_IPV4_EXT_REACHABILITY;
#ifdef HAVE_IPV6
  expected |= TLVFLAG_IPV6_ADDR;
  expected |= TLVFLAG_IPV6_REACHABILITY;
#endif /* HAVE_IPV6 */

  retval = parse_tlvs (area->area_tag, lsp->pdu->data +
                       ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN,
                       ntohs(lsp->lsp_header->pdu_len) - ISIS_FIXED_HDR_LEN 
                       - ISIS_LSP_HDR_LEN, &expected, &found, &lsp->tlv_data);

  if (found & TLVFLAG_DYN_HOSTNAME) {
    if (area->dynhostname)
      isis_dynhn_insert (lsp->lsp_header->lsp_id, lsp->tlv_data.hostname,
                         (lsp->lsp_header->lsp_bits & LSPBIT_IST) == 
                         IS_LEVEL_1_AND_2 ? IS_LEVEL_2 : 
                         (lsp->lsp_header->lsp_bits & LSPBIT_IST));
  }

}

void
lsp_update (struct isis_lsp *lsp, struct isis_link_state_hdr *lsp_hdr,
            struct stream *stream, struct isis_area *area)
{

  /* free the old lsp data*/
  XFREE (MTYPE_STREAM_DATA, lsp->pdu);
  lsp_clear_data (lsp);

  /* rebuild the lsp data */
  lsp_update_data (lsp, stream, area);

  /* set the new values for lsp header */ 
  memcpy (lsp->lsp_header, lsp_hdr, ISIS_LSP_HDR_LEN);

}


/* creation of LSP directly from what we received */
struct isis_lsp *
lsp_new_from_stream_ptr (struct stream *stream, 
                         u_int16_t pdu_len, struct isis_lsp *lsp0,
                         struct isis_area *area)
{
  struct isis_lsp *lsp;

  lsp = XMALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp));
  memset (lsp, 0, sizeof (struct isis_lsp));
  
  lsp_update_data (lsp, stream, area);
  
  if (lsp0 == NULL) {
    /*
     * zero lsp -> create the list for fragments
     */
    lsp->lspu.frags = list_new ();
  } else {
    /*
     * a fragment -> set the backpointer and add this to zero lsps frag list
     */
    lsp->lspu.zero_lsp = lsp0;
    listnode_add (lsp0->lspu.frags, lsp);
  }
  
  return lsp;
}

struct isis_lsp *
lsp_new (u_char *lsp_id, u_int16_t rem_lifetime, u_int32_t seq_num, 
         u_int8_t lsp_bits, u_int16_t checksum, int level)
{
  struct isis_lsp *lsp;

  lsp = XMALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp));
  if (!lsp) {
    /* FIXME: set lspdbol bit */
    zlog_warn ("lsp_new(): out of memory");
    return NULL;
  }
  memset (lsp, 0, sizeof (struct isis_lsp));
#ifdef LSP_MEMORY_PREASSIGN
  lsp->pdu = stream_new (1514); /*Should be minimal mtu? yup...*/
#else
  /* We need to do realloc on TLVs additions*/
  lsp->pdu = malloc (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN); 
#endif /* LSP_MEMORY_PREASSIGN */
  if (LSP_FRAGMENT (lsp_id) == 0)
    lsp->lspu.frags = list_new ();
  lsp->isis_header = (struct isis_fixed_hdr*)(STREAM_DATA(lsp->pdu));
  lsp->lsp_header = (struct isis_link_state_hdr*)
                    (STREAM_DATA(lsp->pdu) + ISIS_FIXED_HDR_LEN);
  
  /* at first we fill the FIXED HEADER */
  (level == 1) ? fill_fixed_hdr (lsp->isis_header, L1_LINK_STATE):
                 fill_fixed_hdr (lsp->isis_header, L2_LINK_STATE);
  
  /* now for the LSP HEADER */
  /* Minimal LSP PDU size */
  lsp->lsp_header->pdu_len = htons (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN); 
  memcpy (lsp->lsp_header->lsp_id, lsp_id, ISIS_SYS_ID_LEN + 2);
  lsp->lsp_header->checksum = checksum; /* Provided in network order */
  lsp->lsp_header->seq_num = htonl (seq_num);
  lsp->lsp_header->rem_lifetime = htons (rem_lifetime);
  lsp->lsp_header->lsp_bits = lsp_bits;
  lsp->level = level;
  lsp->age_out = ZERO_AGE_LIFETIME;

  stream_set_putp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);

  /* #ifdef EXTREME_DEBUG */
  /* logging */
  zlog_info ("New LSP with ID %s-%02x-%02x seqnum %08x", sysid_print (lsp_id),
             LSP_PSEUDO_ID (lsp->lsp_header->lsp_id),
             LSP_FRAGMENT (lsp->lsp_header->lsp_id),
             ntohl (lsp->lsp_header->seq_num));
  /* #endif  EXTREME DEBUG */

  return lsp;
}

void
lsp_insert (struct isis_lsp *lsp, dict_t *lspdb)
{
  dict_alloc_insert (lspdb, lsp->lsp_header->lsp_id, lsp);
}

/*
 * Build a list of LSPs with non-zero ht bounded by start and stop ids
 */
void 
lsp_build_list_nonzero_ht (u_char *start_id, u_char *stop_id, 
                           struct list *list, dict_t *lspdb)
{
  dnode_t *first, *last, *curr;

  first = dict_lower_bound (lspdb, start_id);
  if (!first)
    return;
  
  last = dict_upper_bound (lspdb, stop_id);
  
  curr = first;
  
  if (((struct isis_lsp *)(curr->dict_data))->lsp_header->rem_lifetime)
    listnode_add (list, first->dict_data);

  while (curr) {
    curr = dict_next (lspdb, curr);
    if (curr && 
        ((struct isis_lsp *)(curr->dict_data))->lsp_header->rem_lifetime)
      listnode_add (list, curr->dict_data);
    if (curr == last)
      break;
  }
  
  return;
}

/*
 * Build a list of all LSPs bounded by start and stop ids
 */
void 
lsp_build_list (u_char *start_id, u_char *stop_id, 
                struct list *list, dict_t *lspdb)
{
  dnode_t *first, *last, *curr;

  first = dict_lower_bound (lspdb, start_id);
  if (!first)
    return;
  
  last = dict_upper_bound (lspdb, stop_id);
  
  curr = first;
  
  listnode_add (list, first->dict_data);

  while (curr) {
    curr = dict_next (lspdb, curr);
    if (curr)
      listnode_add (list, curr->dict_data);
    if (curr == last)
      break;
  }
  
  return;
}

/*
 * Build a list of LSPs with SSN flag set for the given circuit
 */
void
lsp_build_list_ssn (struct isis_circuit *circuit, struct list *list, 
                    dict_t *lspdb)
{
  dnode_t *dnode, *next;
  struct isis_lsp *lsp;
  
  dnode = dict_first (lspdb);
  while (dnode != NULL) {
    next = dict_next (lspdb, dnode);
    lsp = dnode_get (dnode);
    if (ISIS_CHECK_FLAG (lsp->SSNflags, circuit))
      listnode_add (list, lsp);
    dnode = next;
  }
  
  return;
}

void
lsp_set_time (struct isis_lsp *lsp)
{
  assert (lsp);
  
  if (lsp->lsp_header->rem_lifetime == 0) {
    if (lsp->age_out != 0) lsp->age_out--;
    return;
  }

  /* If we are turning 0 */
  /* ISO 10589 - 7.3.16.4 first paragraph */

  if (ntohs (lsp->lsp_header->rem_lifetime) == 1) {
    /* 7.3.16.4 a) set SRM flags on all */
    ISIS_FLAGS_SET_ALL (lsp->SRMflags);
    /* 7.3.16.4 b) retain only the header FIXME  */
    /* 7.3.16.4 c) record the time to purge FIXME (other way to do it)*/
  }

  lsp->lsp_header->rem_lifetime = 
    htons (ntohs (lsp->lsp_header->rem_lifetime) - 1);
}

void
lspid_print (u_char *lsp_id, u_char *trg, char dynhost, char frag)
{
  struct isis_dynhn *dyn = NULL;
  u_char id [SYSID_STRLEN];

  if (dynhost)
    dyn = dynhn_find_by_id (lsp_id);
  else
    dyn = NULL;

  if (dyn)
    sprintf (id, "%.14s", dyn->name.name);
  else if (!memcmp (isis->sysid, lsp_id, ISIS_SYS_ID_LEN) & dynhost)
    sprintf (id, "%.14s", unix_hostname());
   else {
    memcpy(id, sysid_print (lsp_id), 15);
  }
  if (frag)
    sprintf (trg, "%s.%02x-%02x", id, LSP_PSEUDO_ID(lsp_id), 
             LSP_FRAGMENT(lsp_id));
  else
    sprintf (trg, "%s.%02x", id, LSP_PSEUDO_ID(lsp_id));
}

/* Convert the lsp attribute bits to attribute string */ 
char * 
lsp_bits2string (u_char *lsp_bits) {

  char *pos = lsp_bits_string; 

  if(!*lsp_bits)
    return " none";

  /* we only focus on the default metric */
  pos += sprintf (pos, "%d/",
           ISIS_MASK_LSP_ATT_DEFAULT_BIT(*lsp_bits) ?
           1 : 0);

  pos += sprintf (pos, "%d/",
           ISIS_MASK_LSP_PARTITION_BIT(*lsp_bits) ?
           1 : 0);

  pos += sprintf (pos, "%d",
           ISIS_MASK_LSP_OL_BIT(*lsp_bits) ?
           1 : 0);
  
  *(pos) = '\0';
  
  return lsp_bits_string;

}

/* this function prints the lsp on show isis database */
void
lsp_print (dnode_t *node, struct vty *vty, char dynhost)
{
  struct isis_lsp *lsp = dnode_get(node);
  u_char LSPid[255];

  lspid_print (lsp->lsp_header->lsp_id, LSPid, dynhost, 1);
  vty_out (vty, "%-21s%c   ", LSPid,lsp->own_lsp?'*':' ');
  vty_out (vty, "0x%08x   ", ntohl(lsp->lsp_header->seq_num));
  vty_out (vty, "0x%04x      ", ntohs(lsp->lsp_header->checksum));

  if (ntohs(lsp->lsp_header->rem_lifetime) == 0)
    vty_out (vty, " (%2u)",lsp->age_out);
  else
    vty_out (vty, "%5u", ntohs(lsp->lsp_header->rem_lifetime));

  vty_out (vty, "         %s%s",
    lsp_bits2string(&lsp->lsp_header->lsp_bits),	   
    VTY_NEWLINE);
}

void
lsp_print_detail (dnode_t *node, struct vty *vty, char dynhost)
{
  struct isis_lsp *lsp = dnode_get (node);
  struct area_addr *area_addr;
  char   nlpidstr[2];
  int    i;
  struct listnode *lnode;
  struct is_neigh *is_neigh;
  struct te_is_neigh *te_is_neigh;
  struct ipv4_reachability *ipv4_reach;
  struct in_addr *ipv4_addr;
  struct te_ipv4_reachability *te_ipv4_reach;
#ifdef HAVE_IPV6
  struct ipv6_reachability *ipv6_reach;
  struct in6_addr in6;
#endif
  u_char LSPid[255];
  u_char hostname[255];
  u_char buff[BUFSIZ];
  u_int32_t now,helper;
  u_char ipv4_reach_prefix[20];
  u_char ipv4_reach_mask[20];
  u_char ipv4_address[20];

  lspid_print (lsp->lsp_header->lsp_id, LSPid, dynhost, 1);
  lsp_print(node, vty, dynhost);

  /* for all area address */
  if (lsp->tlv_data.area_addrs) {
    LIST_LOOP (lsp->tlv_data.area_addrs, area_addr, lnode) {
    vty_out (vty, "  Area Address:  %s%s", 
		   isonet_print (area_addr->area_addr, area_addr->addr_len), 
		   VTY_NEWLINE);
    }
  }

  /* for the nlpid tlv */
  if (lsp->tlv_data.nlpids) {
    for (i = 0; i < lsp->tlv_data.nlpids->count; i++) {
      switch (lsp->tlv_data.nlpids->nlpids[i]) {
      case NLPID_IP:
      case NLPID_IPV6:
        vty_out (vty, "  NLPID:         0x%X%s",
               lsp->tlv_data.nlpids->nlpids[i],
               VTY_NEWLINE);
        break;
      default:
        vty_out (vty, "  NLPID:         %s%s",
               "unknown",
               VTY_NEWLINE);
        break;
      }
    } 
  }

  /* for the hostname tlv */
  if (lsp->tlv_data.hostname) {
    bzero (hostname, sizeof (hostname));
    memcpy (hostname, lsp->tlv_data.hostname->name,
            lsp->tlv_data.hostname->namelen);
    vty_out (vty, "  Hostname: %s%s", hostname, VTY_NEWLINE);
  }

  if (lsp->tlv_data.ipv4_addrs) {
    LIST_LOOP(lsp->tlv_data.ipv4_addrs, ipv4_addr, lnode) {
      memcpy (ipv4_address, inet_ntoa (*ipv4_addr), sizeof (ipv4_addr));
      vty_out (vty, "  IP:        %s%s",
               ipv4_address,
               VTY_NEWLINE);
    }
  }
  
  /* for the internal reachable tlv */
  if (lsp->tlv_data.ipv4_int_reachs)
    LIST_LOOP(lsp->tlv_data.ipv4_int_reachs, ipv4_reach, lnode) {
      memcpy (ipv4_reach_prefix, inet_ntoa (ipv4_reach->prefix), sizeof (ipv4_reach_prefix));
      memcpy (ipv4_reach_mask, inet_ntoa (ipv4_reach->mask), sizeof (ipv4_reach_mask));
      vty_out (vty, "  Matric: %d IP %s %s%s",
             ipv4_reach->metrics.metric_default,
             ipv4_reach_prefix,
             ipv4_reach_mask,
             VTY_NEWLINE);
  }

  /* for the IS neighbor tlv */
  if (lsp->tlv_data.is_neighs) {
    LIST_LOOP(lsp->tlv_data.is_neighs,is_neigh,lnode) {
      lspid_print (is_neigh->neigh_id, LSPid, dynhost, 0);
      vty_out (vty, "  Metric: %d IS %s%s",
              is_neigh->metrics.metric_default,
              LSPid,
              VTY_NEWLINE);
    }
  }

/* FIXME: Other tlvs such as te or external tlv will be added later */
#if 0  
  vty_out (vty, "%s  %s %c%s",
	   VTY_NEWLINE,
	   LSPid,
	   lsp->own_lsp ? '*' : ' ',
	   VTY_NEWLINE);

  vty_out (vty, "    Sequence: 0x%08x Checksum: 0x%04x Lifetime: ",
	   ntohl (lsp->lsp_header->seq_num),
	   ntohs (lsp->lsp_header->checksum));

  if (ntohs (lsp->lsp_header->rem_lifetime) == 0)
    vty_out (vty, " (%2u) ", lsp->age_out);
  else
    vty_out (vty, "%5u ", ntohs (lsp->lsp_header->rem_lifetime));

  vty_out (vty, "%s    Attributes:%s",
	   VTY_NEWLINE,
	   lsp_bits2string (&lsp->lsp_header->lsp_bits));

  /* if this is a self originated LSP then print
   * the generation time plus when we sent it last
   * if it is a non self-originated LSP then print the
   * time when the LSP has been installed
   */

  if (lsp->own_lsp) {

    now = time (NULL);
    helper = now - lsp->last_generated;
    if (!lsp->last_generated)
      helper = 0;

    vty_out (vty, ", Generated: %s ago",
	     time2string (helper));

    now = time (NULL);
    helper = now - lsp->last_sent;
    if (!lsp->last_sent)
      helper = 0;

    vty_out (vty, ", Last sent: %s ago",
	     time2string (helper));
  } else {
    now = time (NULL);
    helper = now - lsp->installed;
    if (!lsp->installed)
      helper = 0;

    vty_out (vty, ", Installed: %s ago",
	     time2string (helper));

  }

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

  if (lsp->tlv_data.nlpids)  {
    vty_out (vty, "    Speaks: %s%s", nlpid2string (lsp->tlv_data.nlpids), 
             VTY_NEWLINE);
  }

  if (lsp->tlv_data.router_id)  {
    vty_out (vty, "     Router ID: %s%s", 
             inet_ntoa (lsp->tlv_data.router_id->id), VTY_NEWLINE);
  }

  if (lsp->tlv_data.is_neighs)
  LIST_LOOP(lsp->tlv_data.is_neighs,is_neigh,lnode) {
    lspid_print (is_neigh->neigh_id, LSPid, dynhost, 0);
    vty_out (vty, "     IS      %s, Metric: %d%s",
             LSPid,
	     is_neigh->metrics.metric_default,
	     VTY_NEWLINE);
  }

  if (lsp->tlv_data.te_is_neighs)
    LIST_LOOP(lsp->tlv_data.te_is_neighs,te_is_neigh,lnode) {
    /* FIXME: metric display is wrong */
    lspid_print (te_is_neigh->neigh_id, LSPid, dynhost, 0);
    vty_out (vty, "     extd-IS %s, Metric: %d%s",
             LSPid,	     
	     te_is_neigh->te_metric[0],
	     VTY_NEWLINE);
  }

  if (lsp->tlv_data.ipv4_int_reachs)
    LIST_LOOP(lsp->tlv_data.ipv4_int_reachs, ipv4_reach, lnode) {
    vty_out (vty, "     int-IP  %s/%d, Metric: %d%s",
             inet_ntoa (ipv4_reach->prefix),
	     ip_masklen (ipv4_reach->mask),
	     ipv4_reach->metrics.metric_default,
	     VTY_NEWLINE);
  }

  if (lsp->tlv_data.ipv4_ext_reachs)
    LIST_LOOP(lsp->tlv_data.ipv4_ext_reachs,ipv4_reach,lnode) {
    vty_out (vty, "     ext-IP  %s/%d, Metric: %d%s",
             inet_ntoa(ipv4_reach->prefix),
	     ip_masklen(ipv4_reach->mask),
	     ipv4_reach->metrics.metric_default,
	     VTY_NEWLINE);
  }

  if (lsp->tlv_data.te_ipv4_reachs)
    LIST_LOOP(lsp->tlv_data.te_ipv4_reachs,te_ipv4_reach,lnode) {
    vty_out (vty, "     extd-IP %s/%d, Metric: %d%s",
             inet_ntoa ( newprefix2inaddr (&te_ipv4_reach->prefix_start, 
                                           te_ipv4_reach->control)),
             te_ipv4_reach->control & 0x3F,
	     ntohl (te_ipv4_reach->te_metric),
	     VTY_NEWLINE);
  }

#ifdef HAVE_IPV6
  if (lsp->tlv_data.ipv6_reachs)
    LIST_LOOP(lsp->tlv_data.ipv6_reachs, ipv6_reach, lnode) {
    memcpy (in6.s6_addr, ipv6_reach->prefix, 16);
    inet_ntop (AF_INET6, &in6, buff, BUFSIZ);
    if ((ipv6_reach->control_info &&  
        CTRL_INFO_DISTRIBUTION) == DISTRIBUTION_INTERNAL)
      vty_out (vty, "     int-IPv6 %s/%d, Metric: %d%s",
               buff,
               ipv6_reach->prefix_len,
               ntohl (ipv6_reach->metric),
               VTY_NEWLINE);
    else
      vty_out (vty, "     ext-IPv6 %s/%d, Metric: %d%s",
               buff,
               ipv6_reach->prefix_len,
               ntohl (ipv6_reach->metric),
               VTY_NEWLINE);
    
  }
#endif
  if (lsp->tlv_data.hostname) {
    memset (hostname, 0, sizeof (hostname));
    memcpy (hostname, lsp->tlv_data.hostname->name,
            lsp->tlv_data.hostname->namelen);
    vty_out (vty, "    Hostname: %s%s", hostname, VTY_NEWLINE);
  }
#endif
 return;
}

/* print all the lsps info in the local lspdb */
int 
lsp_print_all (struct vty *vty, dict_t *lspdb, char detail, char dynhost)
{

  dnode_t *node = dict_first(lspdb), *next;
  int lsp_count = 0;

  /* print the title, for both modes */
  vty_out (vty, "LSP ID                   LSP Seq Num  LSP Checksum "
             "LSP Holdtime ATT/P/OL%s", VTY_NEWLINE);
             
  if (detail == ISIS_UI_LEVEL_BRIEF) {
    while (node != NULL) {
      /* dict_contains (lspdb, node); */ /* I think it is unnecessary, so I comment it out */
      next = dict_next (lspdb, node);
      lsp_print (node, vty, dynhost);
      node = next;
      lsp_count++;
    }
  } else if (detail == ISIS_UI_LEVEL_DETAIL) {
    while (node != NULL) {
      next = dict_next (lspdb, node);
      lsp_print_detail (node, vty, dynhost);
      node = next;
      lsp_count++;
    }
  }

  return lsp_count;
}

/* this function reallocate memory to an lsp pdu, with an additional
 * size of memory, it scans the lsp and moves all pointers the
 * way they should */
u_char *
lsppdu_realloc (struct isis_lsp *lsp, int memorytype, int size)
{
  u_char *retval;
  
  retval = STREAM_DATA(lsp->pdu) + ntohs(lsp->lsp_header->pdu_len);
#ifdef   LSP_MEMORY_PREASSIGN
  lsp->lsp_header->pdu_len = htons(ntohs(lsp->lsp_header->pdu_len) + size);
  return retval;
#else    /* otherwise we have to move all pointers */
  u_char *newpdu;
  newpdu = stream_new (ntohs (lsp->lsp_header->pdu_len) + size);
  memcpy (STREAM_DATA (newpdu), STREAM_DATA(lsp->pdu), 
          ntohs (lsp->lsp_header->pdu_len));
  XFREE (memorytype, lsp->pdu);
  lsp->pdu = newpdu;
  lsp->isis_header = (struct isis_fixed_hdr*)STREAM_DATA(lsp->pdu);
  lsp->lsp_header = (struct isis_link_state_hdr*)
                    (STREAM_DATA(lsp->pdu) + ISIS_FIXED_HDR_LEN);
  htons (ntohs (lsp->lsp_header->pdu_len) += size);
  return STREAM_DATA(lsp->pdu) + (lsp->lsp_header->pdu_len - size);
#endif /* LSP_MEMORY_PREASSIGN */
}


#if 0 /* Saving the old one just in case :) */
/*
 * Builds the lsp->tlv_data
 * and writes the tlvs into lsp->pdu 
 */
void
lsp_build_nonpseudo (struct isis_lsp *lsp, struct isis_area *area)
{
  struct is_neigh *is_neigh;
  struct listnode *node, *ipnode;
  int level = lsp->level;
  struct isis_circuit *circuit;
  struct prefix_ipv4 *ipv4;
  struct ipv4_reachability *ipreach;
  struct isis_adjacency *nei;
#ifdef HAVE_IPV6
  struct prefix_ipv6 *ipv6;
  struct ipv6_reachability *ip6reach;
#endif /* HAVE_IPV6 */
  
  /*
   * First add the tlvs related to area
   */
  
  /* Area addresses */
  if (lsp->tlv_data.area_addrs == NULL)
    lsp->tlv_data.area_addrs = list_new ();
  list_add_list (lsp->tlv_data.area_addrs, area->area_addrs);
  /* Protocols Supported */
  if (area->ip_circuits > 0 
#ifdef HAVE_IPV6
      || area->ipv6_circuits > 0
#endif /* HAVE_IPV6 */
      )
    {
      lsp->tlv_data.nlpids = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct nlpids));
      lsp->tlv_data.nlpids->count = 0;
      if (area->ip_circuits > 0) { 
        lsp->tlv_data.nlpids->count++;
        lsp->tlv_data.nlpids->nlpids[0] = NLPID_IP;
      }  
#ifdef HAVE_IPV6
      if (area->ipv6_circuits > 0) {  
        lsp->tlv_data.nlpids->count++;
        lsp->tlv_data.nlpids->nlpids[lsp->tlv_data.nlpids->count - 1] = 
        NLPID_IPV6;
      } 
#endif /* HAVE_IPV6 */
    }
  /* Dynamic Hostname */
  if (area->dynhostname) {
    lsp->tlv_data.hostname = XMALLOC (MTYPE_ISIS_TLV, 
                                      sizeof (struct hostname));
    memcpy (&lsp->tlv_data.hostname->name, unix_hostname(),
            strlen(unix_hostname()));
    lsp->tlv_data.hostname->namelen = strlen (unix_hostname());
  }
#ifdef TOPOLOGY_GENERATE
  /*
   * If we have a topology in this area, we need to connect this lsp to
   * the first topology lsp
   */
  if ((area->topology) && (level == 1)) {
    if (lsp->tlv_data.is_neighs == NULL)
      lsp->tlv_data.is_neighs = list_new ();
    is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
    memset (is_neigh, 0, sizeof (struct is_neigh));
    memcpy (&is_neigh->neigh_id, area->topology_baseis, ISIS_SYS_ID_LEN);
    /* connected to the first */
    is_neigh->neigh_id[ISIS_SYS_ID_LEN-1] = (0x01); 
    /* this is actually the same system, why mess the SPT */
    is_neigh->metrics.metric_default = 0; 
    is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
    is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
    is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
    listnode_add (lsp->tlv_data.is_neighs, is_neigh);

  }
#endif

  /*
   * Then add tlvs related to circuits
   */
  for (node = listhead (area->circuit_list); node; nextnode (node)) {
    circuit = getdata (node);
    if (circuit->state != C_STATE_UP)
      continue;
    
    /*
     * Add IPv4 internal reachability of this circuit
     */
    if (circuit->ip_router && circuit->ip_addrs && 
        circuit->ip_addrs->count > 0) {
      if (lsp->tlv_data.ipv4_int_reachs == NULL) { 
        lsp->tlv_data.ipv4_int_reachs = list_new ();
        lsp->tlv_data.ipv4_int_reachs->del = free_tlv;
      }
      for (ipnode = listhead (circuit->ip_addrs); ipnode; nextnode (ipnode)) {
        ipv4 = getdata (ipnode);
        ipreach = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv4_reachability));
        ipreach->metrics = circuit->metrics[level - 1];
        ipreach->prefix = ipv4->prefix;
        masklen2ip (ipv4->prefixlen, &ipreach->mask); 
        listnode_add (lsp->tlv_data.ipv4_int_reachs, ipreach);
      }
    }
#ifdef HAVE_IPV6
    /*
     * Add IPv6 reachability of this circuit
     */
    if (circuit->ipv6_router && circuit->ipv6_non_link && 
        circuit->ipv6_non_link->count > 0) {
        if (lsp->tlv_data.ipv6_reachs == NULL) {
            lsp->tlv_data.ipv6_reachs = list_new ();
            lsp->tlv_data.ipv6_reachs->del = free_tlv;
        }
      for (ipnode = listhead (circuit->ipv6_non_link); ipnode; 
           nextnode (ipnode)) {
        ipv6 = getdata (ipnode);
        ip6reach = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv6_reachability));
        memset (ip6reach, 0, sizeof (struct ipv6_reachability));
        ip6reach->metric = htonl(circuit->metrics[level - 1].metric_default);
        ip6reach->control_info = 0;
        ip6reach->prefix_len = ipv6->prefixlen;
        memcpy (&ip6reach->prefix, ipv6->prefix.s6_addr, 
                (ipv6->prefixlen + 7) / 8);
        listnode_add (lsp->tlv_data.ipv6_reachs, ip6reach);
      }
    }
#endif /* HAVE_IPV6 */
    
    switch (circuit->circ_type) {
    case CIRCUIT_T_BROADCAST:
      if (level & circuit->circuit_is_type) {
        if (lsp->tlv_data.is_neighs == NULL) {
          lsp->tlv_data.is_neighs = list_new ();
          lsp->tlv_data.is_neighs->del = free_tlv;
        }
        is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
        memset (is_neigh, 0, sizeof (struct is_neigh));
        if (level == 1)
          memcpy (&is_neigh->neigh_id, 
                  circuit->u.bc.l1_desig_is, ISIS_SYS_ID_LEN + 1);
        else
          memcpy (&is_neigh->neigh_id, 
                  circuit->u.bc.l2_desig_is, ISIS_SYS_ID_LEN + 1);
            is_neigh->metrics = circuit->metrics[level - 1];
        listnode_add (lsp->tlv_data.is_neighs, is_neigh);
      }
      break;
    case CIRCUIT_T_P2P:
      nei = circuit->u.p2p.neighbor; 
        if (nei && (level & nei->circuit_t)) {
          if (lsp->tlv_data.is_neighs == NULL) {
            lsp->tlv_data.is_neighs = list_new ();
            lsp->tlv_data.is_neighs->del = free_tlv;
          }
          is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
          memset (is_neigh, 0, sizeof (struct is_neigh));
          memcpy (&is_neigh->neigh_id, nei->sysid, ISIS_SYS_ID_LEN);
          is_neigh->metrics = circuit->metrics[level - 1];
          listnode_add (lsp->tlv_data.is_neighs, is_neigh);
      }
      break;
    case  CIRCUIT_T_STATIC_IN:
      zlog_warn ("lsp_area_create: unsupported circuit type");
      break;
    case  CIRCUIT_T_STATIC_OUT:
      zlog_warn ("lsp_area_create: unsupported circuit type");
      break;
    case CIRCUIT_T_DA:
      zlog_warn ("lsp_area_create: unsupported circuit type");
      break;
    default:
      zlog_warn ("lsp_area_create: unknown circuit type");
    }
  }
  
  stream_set_putp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
  
  if (lsp->tlv_data.nlpids)
    tlv_add_nlpid (lsp->tlv_data.nlpids, lsp->pdu);
  if (lsp->tlv_data.hostname)
    tlv_add_dynamic_hostname (lsp->tlv_data.hostname, lsp->pdu);
  if (lsp->tlv_data.area_addrs && listcount (lsp->tlv_data.area_addrs) > 0 )
    tlv_add_area_addrs (lsp->tlv_data.area_addrs, lsp->pdu);
  if (lsp->tlv_data.is_neighs && listcount (lsp->tlv_data.is_neighs) > 0)
    tlv_add_is_neighs (lsp->tlv_data.is_neighs, lsp->pdu);
  if (lsp->tlv_data.ipv4_int_reachs  && 
      listcount (lsp->tlv_data.ipv4_int_reachs) > 0)
    tlv_add_ipv4_reachs (lsp->tlv_data.ipv4_int_reachs, lsp->pdu);
#ifdef  HAVE_IPV6 
  if (lsp->tlv_data.ipv6_reachs && 
      listcount (lsp->tlv_data.ipv6_reachs) > 0)
    tlv_add_ipv6_reachs (lsp->tlv_data.ipv6_reachs, lsp->pdu);
#endif /* HAVE_IPV6 */

  lsp->lsp_header->pdu_len = htons (stream_get_putp (lsp->pdu));

  return;
}
#endif

#define FRAG_THOLD(S,T) \
((STREAM_SIZE(S)*T)/100)

/* stream*, area->lsp_frag_threshold, increment */
#define FRAG_NEEDED(S,T,I) \
  (STREAM_SIZE(S)-STREAM_REMAIN(S)+(I) > FRAG_THOLD(S,T))

void
lsp_tlv_fit (struct isis_lsp *lsp, struct list **from, struct list **to,
             int tlvsize, int frag_thold, 
             int tlv_build_func(struct list *, struct stream *))
{
  int count, i;
  
  /* can we fit all ? */
  if (!FRAG_NEEDED(lsp->pdu, frag_thold,
                   listcount(*from) * tlvsize + 2)) {
    tlv_build_func (*from, lsp->pdu);
    *to = *from;
    *from = NULL;
  } else if (!FRAG_NEEDED(lsp->pdu, frag_thold, tlvsize + 2)) {
    /* fit all we can */
    count = FRAG_THOLD(lsp->pdu,frag_thold) - 2 - 
      (STREAM_SIZE(lsp->pdu) - STREAM_REMAIN(lsp->pdu));
    if (count)
      count = count / tlvsize;
    for (i = 0; i < count; i++) {
      listnode_add (*to, getdata(listhead(*from)));
      listnode_delete(*from, getdata(listhead(*from)));
    }
    tlv_build_func (*to, lsp->pdu);
  }
  lsp->lsp_header->pdu_len = htons (stream_get_putp (lsp->pdu));  
  return;
}

struct isis_lsp  *
lsp_next_frag (u_char frag_num, struct isis_lsp *lsp0, struct isis_area *area, 
               int level )
{
  struct isis_lsp *lsp;
  u_char frag_id[ISIS_SYS_ID_LEN + 2]; 
  
  memcpy (frag_id, lsp0->lsp_header->lsp_id, ISIS_SYS_ID_LEN + 1);
  LSP_FRAGMENT (frag_id) = frag_num;
  lsp = lsp_search (frag_id, area->lspdb[level - 1]);
  if (lsp) {
    /*
     * Clear the TLVs, but inherit the authinfo
     */
    lsp_clear_data (lsp);
    if (lsp0->tlv_data.auth_info.type) {
      memcpy (&lsp->tlv_data.auth_info, &lsp->tlv_data.auth_info, 
	      sizeof (struct isis_passwd));
      tlv_add_authinfo (lsp->tlv_data.auth_info.type, 
			lsp->tlv_data.auth_info.len, 
		      lsp->tlv_data.auth_info.passwd, lsp->pdu);
    }
    return lsp;
  } 
  lsp = lsp_new (frag_id, area->max_lsp_lifetime[level - 1], 0, area->is_type,
                 0, level);
  lsp->own_lsp = 1;
  lsp_insert (lsp, area->lspdb[level-1]);
  listnode_add (lsp0->lspu.frags, lsp);
  lsp->lspu.zero_lsp = lsp0;
  /*
   * Copy the authinfo from zero LSP
   */
  if (lsp0->tlv_data.auth_info.type) {
    memcpy (&lsp->tlv_data.auth_info, &lsp->tlv_data.auth_info, 
	    sizeof (struct isis_passwd));
    tlv_add_authinfo (lsp->tlv_data.auth_info.type, 
		      lsp->tlv_data.auth_info.len, 
		      lsp->tlv_data.auth_info.passwd, lsp->pdu);
  }
  return lsp;
}

/*
 * Builds the LSP data part. This func creates a new frag whenever 
 * area->lsp_frag_threshold is exceeded.
 */
#if 1
void
lsp_build_nonpseudo (struct isis_lsp *lsp, struct isis_area *area)
{
  struct is_neigh *is_neigh;
  struct listnode *node, *ipnode;
  int level = lsp->level;
  struct isis_circuit *circuit;
  struct prefix_ipv4 *ipv4;
  struct ipv4_reachability *ipreach;
  struct isis_adjacency *nei;
#ifdef HAVE_IPV6
  struct prefix_ipv6 *ipv6;
  struct ipv6_reachability *ip6reach;
#endif /* HAVE_IPV6 */
  struct tlvs tlv_data;
  struct isis_lsp *lsp0 = lsp;
  struct isis_passwd *passwd;

  /*
   * First add the tlvs related to area
   */
  
  /* Area addresses */
  if (lsp->tlv_data.area_addrs == NULL)
    lsp->tlv_data.area_addrs = list_new ();
  list_add_list (lsp->tlv_data.area_addrs, area->area_addrs);
  /* Protocols Supported */
  if (area->ip_circuits > 0 
#ifdef HAVE_IPV6
      || area->ipv6_circuits > 0
#endif /* HAVE_IPV6 */
      )
    {
      lsp->tlv_data.nlpids = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct nlpids));
      lsp->tlv_data.nlpids->count = 0;
      if (area->ip_circuits > 0) { 
        lsp->tlv_data.nlpids->count++;
        lsp->tlv_data.nlpids->nlpids[0] = NLPID_IP;
      }  
#ifdef HAVE_IPV6
      if (area->ipv6_circuits > 0) {  
        lsp->tlv_data.nlpids->count++;
        lsp->tlv_data.nlpids->nlpids[lsp->tlv_data.nlpids->count - 1] = 
        NLPID_IPV6;
      } 
#endif /* HAVE_IPV6 */
    }
  /* Dynamic Hostname */
  if (area->dynhostname) {
    lsp->tlv_data.hostname = XMALLOC (MTYPE_ISIS_TLV, 
                                      sizeof (struct hostname));

    memcpy (lsp->tlv_data.hostname->name, unix_hostname(),
            strlen (unix_hostname()));
    lsp->tlv_data.hostname->namelen = strlen (unix_hostname());
  }

  /*
   * Building the zero lsp
   */
  stream_set_putp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);  
  /*
   * Add the authentication info if its present
   */
  (level == 1) ? (passwd = &area->area_passwd) : 
                 (passwd = &area->domain_passwd);
  if (passwd->type) {
    memcpy (&lsp->tlv_data.auth_info, passwd, sizeof (struct isis_passwd));
    tlv_add_authinfo (passwd->type, passwd->len,
		      passwd->passwd, lsp->pdu);
  }
  if (lsp->tlv_data.nlpids)
    tlv_add_nlpid (lsp->tlv_data.nlpids, lsp->pdu);
  if (lsp->tlv_data.hostname)
    tlv_add_dynamic_hostname (lsp->tlv_data.hostname, lsp->pdu);
  if (lsp->tlv_data.area_addrs && listcount (lsp->tlv_data.area_addrs) > 0 )
    tlv_add_area_addrs (lsp->tlv_data.area_addrs, lsp->pdu);
 
  memset (&tlv_data, 0, sizeof (struct tlvs));
  /*
   * Then build lists of tlvs related to circuits
   */
  for (node = listhead (area->circuit_list); node; nextnode (node)) {
    circuit = getdata (node);
    if (circuit->state != C_STATE_UP)
      continue;
    
    /*
     * Add IPv4 internal reachability of this circuit
     */
    if (circuit->ip_router && circuit->ip_addrs && 
        circuit->ip_addrs->count > 0) {
      if (tlv_data.ipv4_int_reachs == NULL) { 
        tlv_data.ipv4_int_reachs = list_new ();
      }
      for (ipnode = listhead (circuit->ip_addrs); ipnode; nextnode (ipnode)) {
        ipv4 = getdata (ipnode);
        ipreach = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv4_reachability));
        ipreach->metrics = circuit->metrics[level - 1];
        ipreach->prefix = ipv4->prefix;
        masklen2ip (ipv4->prefixlen, &ipreach->mask); 
        listnode_add (tlv_data.ipv4_int_reachs, ipreach);
      }

    }
#ifdef HAVE_IPV6
    /*
     * Add IPv6 reachability of this circuit
     */
    if (circuit->ipv6_router && circuit->ipv6_non_link && 
        circuit->ipv6_non_link->count > 0) {
      
      if (tlv_data.ipv6_reachs == NULL) {
        tlv_data.ipv6_reachs = list_new ();
      }
      for (ipnode = listhead (circuit->ipv6_non_link); ipnode; 
           nextnode (ipnode)) {
        ipv6 = getdata (ipnode);
        ip6reach = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv6_reachability));
        memset (ip6reach, 0, sizeof (struct ipv6_reachability));
        ip6reach->metric = htonl(circuit->metrics[level - 1].metric_default);
        ip6reach->control_info = 0;
        ip6reach->prefix_len = ipv6->prefixlen;
        memcpy (ip6reach->prefix, ipv6->prefix.s6_addr, 
                (ipv6->prefixlen + 7) / 8);
        listnode_add (tlv_data.ipv6_reachs, ip6reach);
      }
    }
#endif /* HAVE_IPV6 */
    
    switch (circuit->circ_type) {
    case CIRCUIT_T_BROADCAST:
      if (level & circuit->circuit_is_type) {
        if (tlv_data.is_neighs == NULL) {
          tlv_data.is_neighs = list_new ();
        }
        is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
        memset (is_neigh, 0, sizeof (struct is_neigh));
        if (level == 1)
          memcpy (is_neigh->neigh_id, 
                  circuit->u.bc.l1_desig_is, ISIS_SYS_ID_LEN + 1);
        else
          memcpy (is_neigh->neigh_id, 
                  circuit->u.bc.l2_desig_is, ISIS_SYS_ID_LEN + 1);
            is_neigh->metrics = circuit->metrics[level - 1];
        listnode_add (tlv_data.is_neighs, is_neigh);
      }
      break;
    case CIRCUIT_T_P2P:
      nei = circuit->u.p2p.neighbor; 
        if (nei && (level & nei->circuit_t)) {
          if (tlv_data.is_neighs == NULL) {
            tlv_data.is_neighs = list_new ();
            tlv_data.is_neighs->del = free_tlv;
          }
          is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
          memset (is_neigh, 0, sizeof (struct is_neigh));
          memcpy (is_neigh->neigh_id, nei->sysid, ISIS_SYS_ID_LEN);
          is_neigh->metrics = circuit->metrics[level - 1];
          listnode_add (tlv_data.is_neighs, is_neigh);
      }
      break;
    case  CIRCUIT_T_STATIC_IN:
      zlog_warn ("lsp_area_create: unsupported circuit type");
      break;
    case  CIRCUIT_T_STATIC_OUT:
      zlog_warn ("lsp_area_create: unsupported circuit type");
      break;
    case CIRCUIT_T_DA:
      zlog_warn ("lsp_area_create: unsupported circuit type");
      break;
    default:
      zlog_warn ("lsp_area_create: unknown circuit type");
    }
  }
  
  while (tlv_data.ipv4_int_reachs && listcount(tlv_data.ipv4_int_reachs)) {
    if (lsp->tlv_data.ipv4_int_reachs == NULL)
      lsp->tlv_data.ipv4_int_reachs = list_new ();
    lsp_tlv_fit (lsp, &tlv_data.ipv4_int_reachs, 
                 &lsp->tlv_data.ipv4_int_reachs,
                 IPV4_REACH_LEN, area->lsp_frag_threshold, 
                 tlv_add_ipv4_reachs);
    if (tlv_data.ipv4_int_reachs && listcount(tlv_data.ipv4_int_reachs))
      lsp = lsp_next_frag (LSP_FRAGMENT(lsp->lsp_header->lsp_id) + 1, 
                           lsp0, area, level);
  }

#ifdef  HAVE_IPV6   
  while (tlv_data.ipv6_reachs && listcount(tlv_data.ipv6_reachs)) {
    if (lsp->tlv_data.ipv6_reachs == NULL)
      lsp->tlv_data.ipv6_reachs = list_new ();
    lsp_tlv_fit (lsp, &tlv_data.ipv6_reachs, 
                 &lsp->tlv_data.ipv6_reachs,
                 IPV6_REACH_LEN, area->lsp_frag_threshold, 
                 tlv_add_ipv6_reachs);
    if (tlv_data.ipv6_reachs && listcount(tlv_data.ipv6_reachs))
      lsp = lsp_next_frag (LSP_FRAGMENT(lsp->lsp_header->lsp_id) +  1, 
                           lsp0, area, level);
  }
#endif /* HAVE_IPV6 */   

  while (tlv_data.is_neighs && listcount(tlv_data.is_neighs)) {
    if (lsp->tlv_data.is_neighs == NULL)
      lsp->tlv_data.is_neighs = list_new ();
    lsp_tlv_fit (lsp, &tlv_data.is_neighs, 
                 &lsp->tlv_data.is_neighs,
                 IS_NEIGHBOURS_LEN, area->lsp_frag_threshold, 
                 tlv_add_is_neighs);
    if (tlv_data.is_neighs && listcount(tlv_data.is_neighs))
      lsp = lsp_next_frag (LSP_FRAGMENT(lsp->lsp_header->lsp_id) + 1, 
                           lsp0, area, level);
  }
  
  
  return;
}
#endif

void
build_lsp_data (struct isis_lsp *lsp, struct isis_area *area)
{
  struct list *circuit_list = area->circuit_list;
  struct isis_circuit *circuit;
  u_char *tlv_ptr;
  struct is_neigh *is_neigh;

   
  /* add our nlpids */
  /* the 2 is for the TL plus 1 for the nlpid*/
  tlv_ptr = lsppdu_realloc (lsp,MTYPE_ISIS_TLV, 3);
  *tlv_ptr = PROTOCOLS_SUPPORTED; /* Type */
  *(tlv_ptr+1) = 1; /* one protocol */
#ifdef HAVE_IPV6 /*dunno if its right*/
  *(tlv_ptr+2) =  NLPID_IPV6;
#else
  *(tlv_ptr+2) =  NLPID_IP;
#endif /* HAVE_IPV6 */

  /* we should add our areas here
   * FIXME: we need to figure out which should be added? Adj? All? First? */

  /* first, lets add ourselves to the IS neighbours info */
  /* the 2 is for the TL plus 1 for the virtual field*/
  tlv_ptr = lsppdu_realloc(lsp,MTYPE_ISIS_TLV, 3);
  *tlv_ptr = IS_NEIGHBOURS; /* Type */
  *(tlv_ptr+2) = 0; /* virtual is zero */
  lsp->tlv_data.is_neighs = list_new (); /* new list of is_neighbours */
  /* assign space for the is_neigh at the pdu end */
  is_neigh = (struct is_neigh*) lsppdu_realloc(lsp,MTYPE_ISIS_TLV, 
					       sizeof(struct is_neigh)); 
  /* add this node to our list */
  listnode_add (lsp->tlv_data.is_neighs, is_neigh); 
  /* FIXME: Do we need our designated address here? */
  memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN + 1); 
  /* FIXME: Where should we really get our own LSPs metrics from? */
  circuit = (struct isis_circuit*)listhead(circuit_list);
  /* is_neigh->metrics = circuit->metrics[lsp->level -1];*/
  /* Length */
  *(tlv_ptr+1)=(lsp->tlv_data.is_neighs->count * sizeof(struct is_neigh) +1); 

  /* FIXME: scan for adjencecies and add them */

  /* FIXME: add reachability info */

  /* adding dynamic hostname if needed*/
  if (area->dynhostname) {
    tlv_ptr = lsppdu_realloc (lsp,MTYPE_ISIS_TLV, 2); /* the 2 is for the TL */
    *tlv_ptr = DYNAMIC_HOSTNAME; /* Type */
    *(tlv_ptr+1) = strlen (unix_hostname()); /* Length */
    lsp->tlv_data.hostname = (struct hostname *)
      (lsppdu_realloc(lsp,
		      MTYPE_ISIS_TLV,
		      /* the -1 is to fit the length in the struct */
		      strlen (unix_hostname())) - 1); 
    memcpy (lsp->tlv_data.hostname->name, unix_hostname(),
            strlen(unix_hostname()));
  }

}

/*
 * 7.3.7 Generation on non-pseudonode LSPs
 */
int
lsp_generate_non_pseudo (struct isis_area *area, int level) {

  struct isis_lsp *oldlsp, *newlsp;
  u_int32_t seq_num = 0;
  u_char lspid[ISIS_SYS_ID_LEN + 2];

  memset (&lspid, 0, ISIS_SYS_ID_LEN + 2);
  memcpy (&lspid, isis->sysid, ISIS_SYS_ID_LEN);

  /* only builds the lsp if the area shares the level */
  if ((area->is_type & level) == level) { 
    oldlsp = lsp_search (lspid, area->lspdb[level-1]);
    if (oldlsp) {
      seq_num = ntohl (oldlsp->lsp_header->seq_num);
      lsp_search_and_destroy (oldlsp->lsp_header->lsp_id, 
                              area->lspdb[level-1]);
      /* FIXME: we should actually initiate a purge */
    }
    newlsp = lsp_new (lspid, area->max_lsp_lifetime[level-1], seq_num, 
                      area->is_type, 0, level);
    newlsp->own_lsp = 1;
    
    lsp_insert (newlsp, area->lspdb[level-1]);
    /* build_lsp_data (newlsp, area); */
    lsp_build_nonpseudo (newlsp, area);
    /* time to calculate our checksum */
    lsp_seqnum_update (newlsp);
  }


  /* DEBUG_ADJ_PACKETS */
  if (isis->debugs & DEBUG_ADJ_PACKETS) {
    /* FIXME: is this place right? fix missing info */
    zlog_info ("ISIS-Upd (%s): Building L%d LSP",
               area->area_tag, level);
  }

  return ISIS_OK;
}

/*
 * 7.3.9 Generation of level 1 LSPs (non-pseudonode)
 */
int
lsp_l1_generate (struct isis_area *area)
{
  
  area->t_lsp_refresh[0] = thread_add_timer (master, lsp_refresh_l1, area, 
                                             MAX_LSP_GEN_INTERVAL);

  return lsp_generate_non_pseudo (area, 1);
}


/*
 * 7.3.9 Generation of level 2 LSPs (non-pseudonode)
 */
int
lsp_l2_generate (struct isis_area *area)
{
  
  area->t_lsp_refresh[1] = thread_add_timer (master, lsp_refresh_l2, area, 
                                             MAX_LSP_GEN_INTERVAL);

  return lsp_generate_non_pseudo (area, 2);
}

int
lsp_non_pseudo_regenerate (struct isis_area *area, int level)
{
  dict_t *lspdb = area->lspdb[level - 1];
  struct isis_lsp *lsp, *frag;
  struct listnode *node;
  u_char lspid[ISIS_SYS_ID_LEN + 2];

  memset (lspid, 0, ISIS_SYS_ID_LEN + 2);
  memcpy (lspid, isis->sysid, ISIS_SYS_ID_LEN);
  
  lsp = lsp_search (lspid, lspdb);
  
  if (!lsp) {
    zlog_err ("ISIS-Upd (%s): lsp_non_pseudo_regenerate(): no L%d LSP found!",
              area->area_tag,	      
	      level);

    return ISIS_ERROR;
  }

  lsp_clear_data (lsp);  
  lsp_build_nonpseudo (lsp, area);
  lsp->lsp_header->rem_lifetime = htons (isis_jitter 
                                         (area->max_lsp_lifetime[level-1],
                                          MAX_AGE_JITTER));
  lsp_seqnum_update (lsp);
    
  if (isis->debugs & DEBUG_UPDATE_PACKETS) {
    zlog_info ("ISIS-Upd (%s): refreshing our L%d LSP %s, "
	       "seq 0x%08x, cksum 0x%04x lifetime %us",
	       area->area_tag,
	       level,
               rawlspid_print (lsp->lsp_header->lsp_id),
	       ntohl(lsp->lsp_header->seq_num),
	       ntohs(lsp->lsp_header->checksum),
	       ntohs(lsp->lsp_header->rem_lifetime)); 
  }

  lsp->last_generated = time (NULL);
  area->lsp_regenerate_pending[level - 1] = 0;
  ISIS_FLAGS_SET_ALL (lsp->SRMflags);
  for (node = listhead (lsp->lspu.frags); node; nextnode(node)) {
    frag = getdata (node);
    frag->lsp_header->rem_lifetime = htons (isis_jitter 
                                         (area->max_lsp_lifetime[level-1],
                                          MAX_AGE_JITTER));
    ISIS_FLAGS_SET_ALL (frag->SRMflags);
  }

  if (area->ip_circuits)
    isis_spf_schedule (area, level);
#ifdef HAVE_IPV6
  if (area->ipv6_circuits)
    isis_spf_schedule6 (area, level);
#endif
  return ISIS_OK;
}


/*
 * Done at least every MAX_LSP_GEN_INTERVAL. Search own LSPs, update holding
 * time and set SRM
 */
int 
lsp_refresh_l1 (struct thread *thread)
{
  struct isis_area *area;
  unsigned long ref_time;

  area = THREAD_ARG (thread);
  assert (area);
  
  area->t_lsp_refresh[0] = NULL;
  if (area->is_type & IS_LEVEL_1) 
    lsp_non_pseudo_regenerate (area, 1);
  
  ref_time =  area->lsp_refresh[0] > MAX_LSP_GEN_INTERVAL ? 
    MAX_LSP_GEN_INTERVAL : area->lsp_refresh[0];

  area->t_lsp_refresh[0] = thread_add_timer (master, lsp_refresh_l1, area,
                                          isis_jitter (ref_time, 
                                                       MAX_AGE_JITTER));
  return ISIS_OK;
}

int 
lsp_refresh_l2 (struct thread *thread)
{
  struct isis_area *area;
  unsigned long ref_time;

  area = THREAD_ARG (thread);
  assert (area);
  
  area->t_lsp_refresh[1] = NULL;
  if (area->is_type & IS_LEVEL_2) 
    lsp_non_pseudo_regenerate (area, 2);

  ref_time =  area->lsp_refresh[1] > MAX_LSP_GEN_INTERVAL ? 
    MAX_LSP_GEN_INTERVAL : area->lsp_refresh[1];


  area->t_lsp_refresh[1] = thread_add_timer (master, lsp_refresh_l2, area,
                                          isis_jitter (ref_time, 
                                                       MAX_AGE_JITTER));
  return ISIS_OK;
}


/*
 * Something has changed -> regenerate LSP
 */

int
lsp_l1_regenerate (struct thread *thread)
{
  struct isis_area *area;

  area = THREAD_ARG (thread);
  area->lsp_regenerate_pending[0] = 0;

  return lsp_non_pseudo_regenerate (area, 1);
}

int
lsp_l2_regenerate (struct thread *thread)
{
  struct isis_area *area;

  area = THREAD_ARG (thread);
  area->lsp_regenerate_pending[1] = 0;
  
  return lsp_non_pseudo_regenerate (area, 2);
}

int 
lsp_regenerate_schedule (struct isis_area *area)
{
  struct isis_lsp *lsp;
  u_char id[ISIS_SYS_ID_LEN + 2];
  time_t now, diff;
  memcpy(id, isis->sysid, ISIS_SYS_ID_LEN);
  LSP_PSEUDO_ID(id) = LSP_FRAGMENT(id) = 0;
  now = time (NULL);
  /*
   * First level 1
   */
  if (area->is_type & IS_LEVEL_1) {
    lsp = lsp_search (id, area->lspdb[0]);
    if (!lsp || area->lsp_regenerate_pending[0])
      goto L2;
    /*
     * Throttle avoidance
     */
    diff = now - lsp->last_generated;
    if (diff < MIN_LSP_GEN_INTERVAL) {
      area->lsp_regenerate_pending[0] = 1;
      thread_add_timer (master, lsp_l1_regenerate, area, 
                        MIN_LSP_GEN_INTERVAL - diff);
      return ISIS_OK;
    } else
      lsp_non_pseudo_regenerate (area, 1);
  }
  /*
   * then 2
   */
 L2:
  if (area->is_type & IS_LEVEL_2) {
    lsp = lsp_search (id, area->lspdb[1]);
    if (!lsp || area->lsp_regenerate_pending[1])
      return ISIS_OK;
    /*
     * Throttle avoidance
     */
    diff = now - lsp->last_generated;
    if (diff < MIN_LSP_GEN_INTERVAL) {
      area->lsp_regenerate_pending[1] = 1;
      thread_add_timer (master, lsp_l2_regenerate, area, 
                        MIN_LSP_GEN_INTERVAL - diff);
      return ISIS_OK;
    } else
      lsp_non_pseudo_regenerate (area, 2); 
  }
    
  return ISIS_OK; 
}

/*
 * Funcs for pseudonode LSPs
 */

/*
 * 7.3.8 and 7.3.10 Generation of level 1 and 2 pseudonode LSPs 
 */
void
lsp_build_pseudo (struct isis_lsp *lsp, struct isis_circuit *circuit, 
                  int level)
{
  struct isis_adjacency *adj;
  struct is_neigh *is_neigh;
  struct es_neigh *es_neigh;
  struct list *adj_list;
  struct listnode *node;
  struct isis_passwd *passwd;

  assert (circuit);
  assert (circuit->circ_type == CIRCUIT_T_BROADCAST);
  
  if (!circuit->u.bc.is_dr[level - 1])
    return; /* we are not DIS on this circuit */
  
  lsp->level = level;
  if (level == 1)
    lsp->lsp_header->lsp_bits |= IS_LEVEL_1;
  else
    lsp->lsp_header->lsp_bits |= IS_LEVEL_2;

  /*
   * add self to IS neighbours 
   */
  if (lsp->tlv_data.is_neighs == NULL) {
    lsp->tlv_data.is_neighs = list_new ();
    lsp->tlv_data.is_neighs->del = free_tlv;
  }
  is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
  memset (is_neigh, 0, sizeof (struct is_neigh));
  memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN);
  listnode_add (lsp->tlv_data.is_neighs, is_neigh);
  
  adj_list = list_new();
  isis_adj_build_up_list (circuit->u.bc.adjdb[level-1], adj_list);
  
  for (node = listhead (adj_list); node; nextnode (node)){
    adj = getdata (node);
    if (adj->circuit_t & level) {
      if ((level == 1 && adj->sys_type == ISIS_SYSTYPE_L1_IS) ||
          (level == 1 && adj->sys_type == ISIS_SYSTYPE_L2_IS &&
           adj->adj_usage == ISIS_ADJ_LEVEL1AND2) ||
          (level == 2 && adj->sys_type == ISIS_SYSTYPE_L2_IS)) {
        /* an IS neighbour -> add it */
        is_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct is_neigh));
        memset (is_neigh, 0, sizeof (struct is_neigh));
        memcpy (&is_neigh->neigh_id, adj->sysid, ISIS_SYS_ID_LEN);
        listnode_add (lsp->tlv_data.is_neighs, is_neigh);
      } else if (level == 1 && adj->sys_type == ISIS_SYSTYPE_ES) {
        /* an ES neigbour add it, if we are building level 1 LSP */
        /* FIXME: the tlv-format is hard to use here */
        if (lsp->tlv_data.es_neighs == NULL) {
          lsp->tlv_data.es_neighs = list_new ();
          lsp->tlv_data.es_neighs->del = free_tlv;
        }
        es_neigh = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct es_neigh));
        memset (es_neigh, 0, sizeof (struct es_neigh));
        memcpy (&es_neigh->first_es_neigh, adj->sysid, ISIS_SYS_ID_LEN);
        listnode_add (lsp->tlv_data.es_neighs, is_neigh);
      }
    }
  }
  
  stream_set_putp (lsp->pdu, ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
  /*
   * Add the authentication info if it's present
   */
  (level == 1) ? (passwd = &circuit->area->area_passwd) : 
                 (passwd = &circuit->area->domain_passwd);
  if (passwd->type) {
    memcpy (&lsp->tlv_data.auth_info, passwd, sizeof (struct isis_passwd));
    tlv_add_authinfo (passwd->type, passwd->len,
		      passwd->passwd, lsp->pdu);
  }

  if (lsp->tlv_data.is_neighs && listcount (lsp->tlv_data.is_neighs) > 0)
    tlv_add_is_neighs (lsp->tlv_data.is_neighs, lsp->pdu);

  if (lsp->tlv_data.es_neighs && listcount (lsp->tlv_data.es_neighs) > 0)
    tlv_add_is_neighs (lsp->tlv_data.es_neighs, lsp->pdu);

  lsp->lsp_header->pdu_len = htons (stream_get_putp (lsp->pdu));
  iso_csum_create (STREAM_DATA (lsp->pdu) + 12, 
                   ntohs(lsp->lsp_header->pdu_len) - 12, 12);
  
  list_delete (adj_list);

  return;
}

int
lsp_pseudo_regenerate (struct isis_circuit *circuit, int level)
{
  dict_t *lspdb = circuit->area->lspdb[level - 1];
  struct isis_lsp *lsp;
  u_char lsp_id[ISIS_SYS_ID_LEN + 2];
  
  memcpy (lsp_id, isis->sysid, ISIS_SYS_ID_LEN);
  LSP_PSEUDO_ID(lsp_id) = circuit->circuit_id;
  LSP_FRAGMENT(lsp_id) = 0;
  
  lsp = lsp_search (lsp_id, lspdb);
  
  if (!lsp) {
    zlog_err ("lsp_pseudo_regenerate(): no l%d LSP %s found!", level,
              rawlspid_print(lsp_id));
    return ISIS_ERROR;
  }
  lsp_clear_data (lsp);  

  lsp_build_pseudo (lsp, circuit, level);

  lsp->lsp_header->rem_lifetime = 
    htons (isis_jitter (circuit->area->max_lsp_lifetime[level - 1],
                        MAX_AGE_JITTER));

  lsp_inc_seqnum (lsp, 0);
    
  if (isis->debugs & DEBUG_UPDATE_PACKETS) {
    zlog_info ("ISIS-Upd (%s): refreshing pseudo LSP L%d %s", 
               circuit->area->area_tag, level,
               rawlspid_print (lsp->lsp_header->lsp_id)); 
  }

  lsp->last_generated = time (NULL);
  ISIS_FLAGS_SET_ALL (lsp->SRMflags);
    
  return ISIS_OK;
}


int
lsp_l1_refresh_pseudo (struct thread *thread)
{
  struct isis_circuit *circuit;
  int retval;
  unsigned long ref_time;

  circuit = THREAD_ARG(thread);
  
  if (!circuit->u.bc.is_dr[0])
    return ISIS_ERROR; /* FIXME: purge and such */
  
  retval = lsp_pseudo_regenerate (circuit, 1);
  
  ref_time =  circuit->area->lsp_refresh[0] > MAX_LSP_GEN_INTERVAL ? 
    MAX_LSP_GEN_INTERVAL : circuit->area->lsp_refresh[0];

  circuit->u.bc.t_refresh_pseudo_lsp[0] = 
    thread_add_timer (master, lsp_l1_refresh_pseudo, circuit, 
                      isis_jitter (ref_time,
                                   MAX_AGE_JITTER));
  return retval;
}

int 
lsp_l1_pseudo_generate (struct isis_circuit *circuit)
{
  struct isis_lsp *lsp;
  u_char id[ISIS_SYS_ID_LEN + 2];
  unsigned long ref_time;

  memcpy(id, isis->sysid, ISIS_SYS_ID_LEN);
  LSP_FRAGMENT(id) = 0;
  LSP_PSEUDO_ID(id) = circuit->circuit_id;

  /*
   * If for some reason have a pseudo LSP in the db already -> regenerate
   */
  if (lsp_search (id, circuit->area->lspdb[0]))
    return lsp_pseudo_regenerate (circuit, 1);
  lsp = lsp_new (id, circuit->area->max_lsp_lifetime[0],
                 1, circuit->area->is_type, 0, 1);
  
  lsp_build_pseudo (lsp, circuit, 1);
  
  lsp->own_lsp = 1;
  lsp_insert (lsp, circuit->area->lspdb[0]);
  ISIS_FLAGS_SET_ALL (lsp->SRMflags);

  ref_time =  circuit->area->lsp_refresh[0] > MAX_LSP_GEN_INTERVAL ? 
    MAX_LSP_GEN_INTERVAL : circuit->area->lsp_refresh[0];

  
  circuit->u.bc.t_refresh_pseudo_lsp[0] = 
    thread_add_timer (master, lsp_l1_refresh_pseudo, circuit, 
                      isis_jitter (ref_time,
                                   MAX_AGE_JITTER));

  return lsp_regenerate_schedule (circuit->area);
}

int
lsp_l2_refresh_pseudo (struct thread *thread)
{
  struct isis_circuit *circuit;
  int retval;
  unsigned long ref_time;
  circuit = THREAD_ARG(thread);
  
  if (!circuit->u.bc.is_dr[1])
    return ISIS_ERROR; /* FIXME: purge and such */
  
  retval = lsp_pseudo_regenerate (circuit, 2);

  ref_time =  circuit->area->lsp_refresh[1] > MAX_LSP_GEN_INTERVAL ? 
    MAX_LSP_GEN_INTERVAL : circuit->area->lsp_refresh[1];


  circuit->u.bc.t_refresh_pseudo_lsp[1] = 
    thread_add_timer (master, lsp_l2_refresh_pseudo, circuit, 
                      isis_jitter (ref_time,
                                   MAX_AGE_JITTER));
  return retval;
}


int 
lsp_l2_pseudo_generate (struct isis_circuit *circuit)
{
  struct isis_lsp *lsp;
  u_char id[ISIS_SYS_ID_LEN + 2];
  unsigned long ref_time;

  memcpy(id, isis->sysid, ISIS_SYS_ID_LEN);
  LSP_FRAGMENT(id) = 0;
  LSP_PSEUDO_ID(id) = circuit->circuit_id;

  if (lsp_search (id, circuit->area->lspdb[1]))
    return lsp_pseudo_regenerate (circuit, 2);

  lsp = lsp_new (id, circuit->area->max_lsp_lifetime[1],
                 1, circuit->area->is_type, 0, 2);

  lsp_build_pseudo (lsp, circuit, 2);
  
  ref_time =  circuit->area->lsp_refresh[1] > MAX_LSP_GEN_INTERVAL ? 
    MAX_LSP_GEN_INTERVAL : circuit->area->lsp_refresh[1];


  lsp->own_lsp = 1;
  lsp_insert (lsp, circuit->area->lspdb[1]);
  ISIS_FLAGS_SET_ALL (lsp->SRMflags);
      
  circuit->u.bc.t_refresh_pseudo_lsp[1] = 
    thread_add_timer (master, lsp_l2_refresh_pseudo, circuit, 
                      isis_jitter (ref_time,
                                   MAX_AGE_JITTER));
  
  return lsp_regenerate_schedule (circuit->area);
}



/*
 * Walk through LSPs for an area
 *  - set remaining lifetime
 *  - set LSPs with SRMflag set for sending
 */
int 
lsp_tick (struct thread *thread)
{
  struct isis_area *area;
  struct isis_circuit *circuit;
  struct isis_lsp *lsp;
  struct list *lsp_list;
  struct listnode *lspnode, *cnode;
  dnode_t *dnode, *dnode_next;
  int level;

  lsp_list = list_new ();
  
  area = THREAD_ARG (thread);
  assert (area);
  area->t_tick = thread_add_timer (master, lsp_tick, area, 1);

  /*
   * Build a list of LSPs with (any) SRMflag set
   * and removed the ones that have aged out
   */
  for (level = 0; level < ISIS_LEVELS; level++) {
    if (area->lspdb[level] && dict_count (area->lspdb[level]) > 0) {
      dnode = dict_first (area->lspdb[level]);
      while (dnode != NULL) {
        dnode_next = dict_next (area->lspdb[level], dnode);
        lsp = dnode_get (dnode);
        lsp_set_time (lsp);
        if (lsp->age_out == 0) {

          zlog_info ("ISIS-Upd (%s): L%u LSP %s seq 0x%08x aged out",
		     area->area_tag,
		     lsp->level,
		     rawlspid_print (lsp->lsp_header->lsp_id),
		     ntohl(lsp->lsp_header->seq_num));

          lsp_destroy (lsp);
          dict_delete (area->lspdb[level], dnode);
        } else if (flags_any_set (lsp->SRMflags))
          listnode_add (lsp_list, lsp);
        dnode = dnode_next;
      }

      /*
       * Send LSPs on circuits indicated by the SRMflags
       */
      if (listcount (lsp_list) > 0) {
        for (cnode = listhead (area->circuit_list); cnode; nextnode (cnode)) {
          circuit = getdata (cnode);
          for (lspnode = listhead (lsp_list); lspnode; nextnode (lspnode)) {
            lsp = getdata (lspnode);
            if (ISIS_CHECK_FLAG (lsp->SRMflags, circuit)) {
							/* FIXME: if same or elder lsp is already in lsp queue */
							listnode_add (circuit->lsp_queue, lsp);			
              thread_add_event (master, send_lsp, circuit, 0);
            }
          }
        }
      }
      list_delete_all_node (lsp_list);
    }
  }

  list_delete (lsp_list);

  return ISIS_OK;
}


void
lsp_purge_dr (u_char *id, struct isis_circuit *circuit, int level)
{
  struct isis_lsp *lsp;
  
  lsp = lsp_search (id, circuit->area->lspdb[level - 1]);
  
  if (lsp && lsp->purged == 0) {
    lsp->lsp_header->rem_lifetime = htons (0);
    lsp->lsp_header->pdu_len = htons (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
    lsp->purged = 0;
    iso_csum_create (STREAM_DATA (lsp->pdu) + 12, 
                     ntohs(lsp->lsp_header->pdu_len) - 12, 12);
    ISIS_FLAGS_SET_ALL(lsp->SRMflags);
  } 
    
    
  return;
}

/*
 * Purge own LSP that is received and we don't have. 
 * -> Do as in 7.3.16.4
 */
void
lsp_purge_non_exist (struct isis_link_state_hdr *lsp_hdr, 
                     struct isis_area *area)
{
  struct isis_lsp *lsp;

  /*
   * We need to create the LSP to be purged 
   */
  zlog_info ("LSP PURGE NON EXIST");
  lsp = XMALLOC (MTYPE_ISIS_LSP, sizeof (struct isis_lsp));
  memset (lsp, 0, sizeof (struct isis_lsp));
  /*FIXME: BUG BUG BUG! the lsp doesn't exist here!*/
  /*did smt here, maybe good probably not*/
  lsp->level = ((lsp_hdr->lsp_bits & LSPBIT_IST) == IS_LEVEL_1) ? 1 : 2;
  lsp->pdu = stream_new (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
  lsp->isis_header = (struct isis_fixed_hdr*)STREAM_DATA(lsp->pdu);
  fill_fixed_hdr (lsp->isis_header, (lsp->level == 1) ? L1_LINK_STATE
                  : L2_LINK_STATE);
  lsp->lsp_header = (struct isis_link_state_hdr*)(STREAM_DATA(lsp->pdu) +
                                                  ISIS_FIXED_HDR_LEN);  
  memcpy (lsp->lsp_header, lsp_hdr, ISIS_LSP_HDR_LEN);
  
  /*
   * Retain only LSP header
   */
  lsp->lsp_header->pdu_len = htons (ISIS_FIXED_HDR_LEN + ISIS_LSP_HDR_LEN);
  /*
   * Set the remaining lifetime to 0
   */
  lsp->lsp_header->rem_lifetime = 0;
  /*
   * Put the lsp into LSPdb
   */
  lsp_insert (lsp, area->lspdb[lsp->level-1]);

  /*
   * Send in to whole area
   */
  ISIS_FLAGS_SET_ALL (lsp->SRMflags);
  
  return;
}

#ifdef TOPOLOGY_GENERATE
int
top_lsp_refresh (struct thread *thread)
{
  struct isis_lsp  *lsp;

  lsp = THREAD_ARG (thread);
  assert (lsp);

  lsp->t_lsp_top_ref = NULL;

  lsp->lsp_header->rem_lifetime = htons (isis_jitter(MAX_AGE,MAX_AGE_JITTER));
  lsp->lsp_header->seq_num = htonl(ntohl(lsp->lsp_header->seq_num) +1);

  ISIS_FLAGS_SET_ALL (lsp->SRMflags);
  if (isis->debugs & DEBUG_UPDATE_PACKETS) {
    zlog_info ("ISIS-Upd (): refreshing Topology L1 %s", 
               rawlspid_print (lsp->lsp_header->lsp_id));
  }

  /* time to calculate our checksum */
  iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
                   ntohs(lsp->lsp_header->pdu_len) - 12, 12);

  lsp->t_lsp_top_ref = thread_add_timer (master, top_lsp_refresh, lsp,
                                         isis_jitter (MAX_LSP_GEN_INTERVAL,
                                                      MAX_LSP_GEN_JITTER));

  return ISIS_OK;
}

void
generate_topology_lsps (struct isis_area *area)
{
  struct listnode *node;
  int i, max = 0;
  struct arc *arc;
  u_char lspid[ISIS_SYS_ID_LEN + 2];
  struct isis_lsp *lsp;

  /* first we find the maximal node */
  LIST_LOOP (area->topology, arc, node) {
    if (arc->from_node > max) max = arc->from_node;
    if (arc->to_node > max) max = arc->to_node;
  }


  for (i = 1; i < (max+1); i++) {
    memcpy (lspid,area->topology_baseis,ISIS_SYS_ID_LEN);
    LSP_PSEUDO_ID (lspid) = 0x00;
    LSP_FRAGMENT (lspid) = 0x00;
    lspid[ISIS_SYS_ID_LEN-1] = (i & 0xFF);
    lspid[ISIS_SYS_ID_LEN-2] = ((i >> 8) & 0xFF);

    lsp = lsp_new (lspid, isis_jitter (area->max_lsp_lifetime[0],
				       MAX_AGE_JITTER), 1, IS_LEVEL_1, 0, 1);
    lsp->from_topology = 1;
    /* creating data based on topology */
    build_topology_lsp_data (lsp,area,i);
    /* time to calculate our checksum */
    iso_csum_create (STREAM_DATA (lsp->pdu) + 12,
		     ntohs(lsp->lsp_header->pdu_len) - 12, 12);
    lsp->t_lsp_top_ref = thread_add_timer (master, top_lsp_refresh, lsp,
					   isis_jitter(MAX_LSP_GEN_INTERVAL,
						       MAX_LSP_GEN_JITTER));

    ISIS_FLAGS_SET_ALL(lsp->SRMflags);
    lsp_insert (lsp,area->lspdb[0]);

  }
}

void
remove_topology_lsps (struct isis_area *area)
{
  struct isis_lsp *lsp;
  dnode_t *dnode, *dnode_next;

  dnode = dict_first (area->lspdb[0]);
  while (dnode != NULL) {
    dnode_next = dict_next (area->lspdb[0], dnode);
    lsp = dnode_get (dnode);
    if (lsp->from_topology) {
      thread_cancel(lsp->t_lsp_top_ref);
      lsp_destroy (lsp);
      dict_delete (area->lspdb[0], dnode);
    }
    dnode = dnode_next;
  }
}

void
build_topology_lsp_data (struct isis_lsp *lsp, struct isis_area *area, 
			 int lsp_top_num)
{
  struct listnode *node;
  struct arc *arc;
  u_char *tlv_ptr;
  struct is_neigh *is_neigh;
  int to_lsp = 0;
  char buff[200];

  /* add our nlpids */
  /* the 2 is for the TL plus 1 for the nlpid*/
  tlv_ptr = lsppdu_realloc (lsp,MTYPE_ISIS_TLV, 3); 
  *tlv_ptr = PROTOCOLS_SUPPORTED; /* Type */
  *(tlv_ptr+1) = 1; /* one protocol */
  *(tlv_ptr+2) =  NLPID_IP;
  lsp->tlv_data.nlpids = (struct nlpids*)(tlv_ptr+1); 

  /* first, lets add the tops */
  /* the 2 is for the TL plus 1 for the virtual field*/
  tlv_ptr = lsppdu_realloc (lsp ,MTYPE_ISIS_TLV, 3);
  *tlv_ptr = IS_NEIGHBOURS; /* Type */
  *(tlv_ptr+1) = 1; /* this is the virtual char len*/
  *(tlv_ptr+2) = 0; /* virtual is zero */
  lsp->tlv_data.is_neighs = list_new (); /* new list of is_neighbours */

  /* add reachability for this IS for simulated 1 */
  if (lsp_top_num == 1) {
    /* assign space for the is_neigh at the pdu end */
    is_neigh = (struct is_neigh*) lsppdu_realloc(lsp, MTYPE_ISIS_TLV, 
						 sizeof(struct is_neigh)); 
    /* add this node to our list */
    listnode_add (lsp->tlv_data.is_neighs, is_neigh); 
    memcpy (&is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN);
    LSP_PSEUDO_ID (is_neigh->neigh_id) = 0x00;
    is_neigh->metrics.metric_default = 0x00; /* no special reason */
    is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
    is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
    is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
    /* don't forget the length */
    *(tlv_ptr+1) += IS_NEIGHBOURS_LEN; /* the -1 is the virtual */
    /* no need to check for fragging here, it is a lonely is_reach */
  }

  /* addding is reachabilities */
  LIST_LOOP (area->topology, arc, node) {
    if ((arc->from_node == lsp_top_num) ||
        (arc->to_node   == lsp_top_num)) {
      if (arc->to_node   == lsp_top_num) to_lsp = arc->from_node;
      if (arc->from_node == lsp_top_num) to_lsp = arc->to_node;

      /* if the length here is about to cross the FF limit, we reTLV */
      if (*(tlv_ptr+1) >= (0xFF - IS_NEIGHBOURS_LEN)) {
        /* retlv */
	/* the 2 is for the TL plus 1 for the virtual field*/
        tlv_ptr = lsppdu_realloc(lsp,MTYPE_ISIS_TLV, 3); 
        *tlv_ptr = IS_NEIGHBOURS; /* Type */
        *(tlv_ptr+1) = 1; /* this is the virtual char len*/
        *(tlv_ptr+2) = 0; /* virtual is zero */
      }
      /* doing this here assures us that we won't add an "empty" tlv */
      /* assign space for the is_neigh at the pdu end */
      is_neigh = (struct is_neigh*) lsppdu_realloc (lsp, MTYPE_ISIS_TLV, 
						    sizeof(struct is_neigh));
      /* add this node to our list */
      listnode_add (lsp->tlv_data.is_neighs, is_neigh); 
      memcpy (&is_neigh->neigh_id, area->topology_baseis, ISIS_SYS_ID_LEN);
      LSP_PSEUDO_ID (is_neigh->neigh_id) = 0x00;
      is_neigh->neigh_id[ISIS_SYS_ID_LEN-1] = (to_lsp & 0xFF);
      is_neigh->neigh_id[ISIS_SYS_ID_LEN-2] = ((to_lsp >> 8) & 0xFF);
      is_neigh->metrics.metric_default = arc->distance;
      is_neigh->metrics.metric_delay = METRICS_UNSUPPORTED;
      is_neigh->metrics.metric_expense = METRICS_UNSUPPORTED;
      is_neigh->metrics.metric_error = METRICS_UNSUPPORTED;
      /* don't forget the length */
      *(tlv_ptr+1) += IS_NEIGHBOURS_LEN; /* the -1 is the virtual */
    }
  }

  /* adding dynamic hostname if needed*/
  if (area->dynhostname) {
    memset (buff,0x00,200);
    sprintf (buff,"feedme%d",lsp_top_num);
    tlv_ptr = lsppdu_realloc (lsp,MTYPE_ISIS_TLV, 2); /* the 2 is for the TL */
    *tlv_ptr = DYNAMIC_HOSTNAME; /* Type */
    *(tlv_ptr+1) = strlen (buff); /* Length */
    /* the -1 is to fit the length in the struct */
    lsp->tlv_data.hostname = (struct hostname *)
      (lsppdu_realloc (lsp, MTYPE_ISIS_TLV, strlen(buff)) - 1);
    memcpy (lsp->tlv_data.hostname->name, buff, strlen(buff));
  }

  /* thanks to hannes, another bug bites the dust */
  lsp->pdu->putp = ntohs(lsp->lsp_header->pdu_len);
  lsp->pdu->endp = ntohs(lsp->lsp_header->pdu_len);
}
#endif /* TOPOLOGY_GENERATE */
