/*
 * IS-IS Rout(e)ing protocol - isis_flags.c
 *                             Routines for manipulation of SSN and SRM flags
 *
 * 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 <zebra.h>
#include "log.h"
#include "linklist.h"

#include "isisd/isis_constants.h"
#include "isisd/isis_common.h"
#include "isisd/isis_flags.h"

int
flags_get_index (struct flags *flags) 
{
  struct listnode *node;
  int index;

  if (flags->free_idcs == NULL || flags->free_idcs->count == 0) {
    flags->maxindex++;
    index = flags->maxindex;
  } else {
    node = listhead (flags->free_idcs);
    index = (int) getdata (node);
    listnode_delete (flags->free_idcs, (void *)index);
  }
  
  return index;
}

void 
flags_free_index (struct flags *flags, int index) 
{
  if (flags->free_idcs == NULL) {
    flags->free_idcs = list_new ();
  }
  
  listnode_add (flags->free_idcs, (void *)index);
  
  return;
}

int  
flags_any_set (u_int32_t *flags)
{

  u_int32_t zero[ISIS_MAX_CIRCUITS]; 
  memset (zero, 0x00, ISIS_MAX_CIRCUITS*4); 

  return bcmp(flags, zero, ISIS_MAX_CIRCUITS*4);
}
