From 7d2f414476a3da2c5a5a3da804b08b45f5b60b4a Mon Sep 17 00:00:00 2001 From: Oleg Hahm Date: Tue, 18 Aug 2015 19:13:16 +0200 Subject: [PATCH 1/2] universal_address: make size dependent on FIB size --- sys/include/universal_address.h | 1 + sys/universal_address/universal_address.c | 18 +++++++++++++++++- tests/unittests/tests-fib/Makefile.include | 2 +- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/sys/include/universal_address.h b/sys/include/universal_address.h index ebc600fa3..a7be5337b 100644 --- a/sys/include/universal_address.h +++ b/sys/include/universal_address.h @@ -27,6 +27,7 @@ extern "C" { #include #include +#include "net/ipv6/addr.h" #define UNIVERSAL_ADDRESS_SIZE (16) /**< size of the used addresses in bytes */ diff --git a/sys/universal_address/universal_address.c b/sys/universal_address/universal_address.c index 6e0808169..ef0e0cf17 100644 --- a/sys/universal_address/universal_address.c +++ b/sys/universal_address/universal_address.c @@ -19,6 +19,12 @@ #include #include #include +#ifdef MODULE_FIB +#include "net/fib.h" +#ifdef MODULE_GNRC_IPV6 +#include "net/gnrc/ipv6.h" +#endif +#endif #include "mutex.h" #define ENABLE_DEBUG (0) @@ -28,7 +34,17 @@ /** * @brief Maximum number of entries handled */ -#define UNIVERSAL_ADDRESS_MAX_ENTRIES (40) +/* determine the maximum numer of entries */ +#ifndef UNIVERSAL_ADDRESS_MAX_ENTRIES +/* all potential users of universal addresses have to add their requirements here */ +# if defined(MODULE_FIB) && defined(MODULE_GNRC_IPV6) +# define UA_ADD0 (2 * GNRC_IPV6_FIB_TABLE_SIZE) +# else +# define UA_ADD0 (0) +# endif + +# define UNIVERSAL_ADDRESS_MAX_ENTRIES (UA_ADD0) +#endif /** * @brief counter indicating the number of entries allocated diff --git a/tests/unittests/tests-fib/Makefile.include b/tests/unittests/tests-fib/Makefile.include index 2c46289f2..75e2535a5 100644 --- a/tests/unittests/tests-fib/Makefile.include +++ b/tests/unittests/tests-fib/Makefile.include @@ -1,3 +1,3 @@ -CFLAGS += -DFIB_DEVEL_HELPER +CFLAGS += -DFIB_DEVEL_HELPER -DUNIVERSAL_ADDRESS_SIZE=16 -DUNIVERSAL_ADDRESS_MAX_ENTRIES=40 USEMODULE += fib From 23a60e62707725c79ccb0e724839562577994261 Mon Sep 17 00:00:00 2001 From: Oleg Hahm Date: Tue, 18 Aug 2015 19:31:49 +0200 Subject: [PATCH 2/2] universal_address: determine biggest address size --- sys/include/universal_address.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/sys/include/universal_address.h b/sys/include/universal_address.h index a7be5337b..86525f4aa 100644 --- a/sys/include/universal_address.h +++ b/sys/include/universal_address.h @@ -29,7 +29,18 @@ extern "C" { #include #include "net/ipv6/addr.h" -#define UNIVERSAL_ADDRESS_SIZE (16) /**< size of the used addresses in bytes */ +/** @brief size of the used addresses in bytes */ +/* determine the widest possible address type */ +#ifndef UNIVERSAL_ADDRESS_SIZE +#define UNIVERSAL_ADDRESS_SIZE (0) /* rather senseless default, should + trigger warnings */ +#endif + +/* IPv6 address has 128 bit -> 16 bytes */ +#if defined(MODULE_IPV6_ADDR) && ((IPV6_ADDR_BIT_LEN >> 3) > UNIVERSAL_ADDRESS_SIZE) +#undef UNIVERSAL_ADDRESS_SIZE +#define UNIVERSAL_ADDRESS_SIZE (IPV6_ADDR_BIT_LEN >> 3) +#endif /** * @brief The container descriptor used to identify a universal address entry