+// SPDX-License-Identifier: GPL-2.0-or-later
/*
* FRR ID Number Allocator
* Copyright (C) 2018 Amazon.com, Inc. or its affiliates
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 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; see the file COPYING; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
#include "id_alloc.h"
#include "log.h"
#include <inttypes.h>
-DEFINE_MTYPE_STATIC(LIB, IDALLOC_ALLOCATOR, "ID Number Allocator")
-DEFINE_MTYPE_STATIC(LIB, IDALLOC_ALLOCATOR_NAME, "ID Number Allocator Name")
-DEFINE_MTYPE_STATIC(LIB, IDALLOC_DIRECTORY, "ID Number Allocator Directory")
+DEFINE_MTYPE_STATIC(LIB, IDALLOC_ALLOCATOR, "ID Number Allocator");
+DEFINE_MTYPE_STATIC(LIB, IDALLOC_ALLOCATOR_NAME, "ID Number Allocator Name");
+DEFINE_MTYPE_STATIC(LIB, IDALLOC_DIRECTORY, "ID Number Allocator Directory");
DEFINE_MTYPE_STATIC(LIB, IDALLOC_SUBDIRECTORY,
- "ID Number Allocator Subdirectory")
-DEFINE_MTYPE_STATIC(LIB, IDALLOC_PAGE, "ID Number Allocator Page")
-DEFINE_MTYPE_STATIC(LIB, IDALLOC_POOL, "ID Number temporary holding pool entry")
+ "ID Number Allocator Subdirectory");
+DEFINE_MTYPE_STATIC(LIB, IDALLOC_PAGE, "ID Number Allocator Page");
+DEFINE_MTYPE_STATIC(LIB, IDALLOC_POOL,
+ "ID Number temporary holding pool entry");
#if UINT_MAX >= UINT32_MAX
#define FFS32(x) ffs(x)
#define DIR_MASK ((1<<IDALLOC_DIR_BITS)-1)
#define SUBDIR_MASK ((1<<IDALLOC_SUBDIR_BITS)-1)
-#define PAGE_MASK ((1<<IDALLOC_PAGE_BITS)-1)
+#define FRR_ID_PAGE_MASK ((1<<IDALLOC_PAGE_BITS)-1)
#define WORD_MASK ((1<<IDALLOC_WORD_BITS)-1)
#define OFFSET_MASK ((1<<IDALLOC_OFFSET_BITS)-1)
IDALLOC_PAGE_BITS + IDALLOC_SUBDIR_BITS)
#define SUBDIR_SHIFT (IDALLOC_OFFSET_BITS + IDALLOC_WORD_BITS + \
IDALLOC_PAGE_BITS)
-#define PAGE_SHIFT (IDALLOC_OFFSET_BITS + IDALLOC_WORD_BITS)
+#define FRR_ID_PAGE_SHIFT (IDALLOC_OFFSET_BITS + IDALLOC_WORD_BITS)
#define WORD_SHIFT (IDALLOC_OFFSET_BITS)
#define OFFSET_SHIFT (0)
#define ID_DIR(id) ((id >> DIR_SHIFT) & DIR_MASK)
#define ID_SUBDIR(id) ((id >> SUBDIR_SHIFT) & SUBDIR_MASK)
-#define ID_PAGE(id) ((id >> PAGE_SHIFT) & PAGE_MASK)
+#define ID_PAGE(id) ((id >> FRR_ID_PAGE_SHIFT) & FRR_ID_PAGE_MASK)
#define ID_WORD(id) ((id >> WORD_SHIFT) & WORD_MASK)
#define ID_OFFSET(id) ((id >> OFFSET_SHIFT) & OFFSET_MASK)
page->base_value = id;
subdir->sublevels[ID_PAGE(id)] = page;
- alloc->capacity += 1 << PAGE_SHIFT;
+ alloc->capacity += 1 << FRR_ID_PAGE_SHIFT;
page->next_has_free = alloc->has_free;
alloc->has_free = page;
} else if (page != NULL && create) {
flog_err(
EC_LIB_ID_CONSISTENCY,
- "ID Allocator %s attempt to re-create page at %" PRIu32,
+ "ID Allocator %s attempt to re-create page at %u",
alloc->name, id);
}
page = find_or_create_page(alloc, id, 0);
if (!page) {
flog_err(EC_LIB_ID_CONSISTENCY,
- "ID Allocator %s cannot free #%" PRIu32
- ". ID Block does not exist.",
+ "ID Allocator %s cannot free #%u. ID Block does not exist.",
alloc->name, id);
return;
}
if ((page->allocated_mask[word] & (1 << offset)) == 0) {
flog_err(EC_LIB_ID_CONSISTENCY,
- "ID Allocator %s cannot free #%" PRIu32
- ". ID was not allocated at the time of free.",
+ "ID Allocator %s cannot free #%u. ID was not allocated at the time of free.",
alloc->name, id);
return;
}
if (page->allocated_mask[word] & (((uint32_t)1) << offset)) {
flog_err(EC_LIB_ID_CONSISTENCY,
- "ID Allocator %s could not reserve %" PRIu32
- " because it is already allocated.",
+ "ID Allocator %s could not reserve %u because it is already allocated.",
alloc->name, id);
return IDALLOC_INVALID;
}