/*
 * 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) listgetdata (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);
}
