/*
 * 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_address));
      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, "  Metric: %d IP %s %s%s",
             ipv4_reach->metrics.metric_default,
             ipv4_reach_prefix,
             ipv4_reach_mask,
             VTY_NEWLINE);
  }

  /* for the external reachable tlv */
  if (lsp->tlv_data.ipv4_ext_reachs)
    LIST_LOOP(lsp->tlv_data.ipv4_ext_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, "  Metric: %d IP-External %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);
    }
  }

  /* IPv6 tlv */
#ifdef HAVE_IPV6
  if (lsp->tlv_data.ipv6_reachs)
    LIST_LOOP(lsp->tlv_data.ipv6_reachs, ipv6_reach, lnode) {
      memset(&in6, 0, sizeof(in6));
      memcpy (in6.s6_addr, ipv6_reach->prefix, PSIZE(ipv6_reach->prefix_len));
      inet_ntop (AF_INET6, &in6, buff, BUFSIZ);
      if ((ipv6_reach->control_info &&
            CTRL_INFO_DISTRIBUTION) == DISTRIBUTION_INTERNAL)
        vty_out (vty, "  Metric: %d IPv6-Intern %s/%d%s",
               ntohl (ipv6_reach->metric),
               buff,
               ipv6_reach->prefix_len,
               VTY_NEWLINE);
      else
        vty_out (vty, "  Metric: %d IPv6-Extern %s/%d%s",
               ntohl (ipv6_reach->metric),
               buff,
               ipv6_reach->prefix_len,
               VTY_NEWLINE);
    }
#endif

/* 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 */
