From 3173150ef76fb125341a215b17ed78d194bd5297 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Tue, 14 Feb 2023 17:45:19 +0100 Subject: [PATCH 1/4] gnrc_dhcpv6_client_simple_pd: select upstream based on type/index --- .../net/gnrc/dhcpv6/client/simple_pd.h | 19 +++++++++++++++++++ .../dhcpv6/client_simple_pd.c | 6 ++++++ 2 files changed, 25 insertions(+) diff --git a/sys/include/net/gnrc/dhcpv6/client/simple_pd.h b/sys/include/net/gnrc/dhcpv6/client/simple_pd.h index 9f36780afa5e..b1a2a784e876 100644 --- a/sys/include/net/gnrc/dhcpv6/client/simple_pd.h +++ b/sys/include/net/gnrc/dhcpv6/client/simple_pd.h @@ -36,6 +36,25 @@ extern "C" { #define CONFIG_GNRC_DHCPV6_CLIENT_6LBR_UPSTREAM (0) #endif +/** + * @brief Interface type of the upstream interface + * + * See @ref netdev_type_t for possible values + */ +#ifndef CONFIG_GNRC_DHCPV6_CLIENT_6LBR_UPSTREAM_TYPE +#define CONFIG_GNRC_DHCPV6_CLIENT_6LBR_UPSTREAM_TYPE NETDEV_ANY +#endif + +/** + * @brief Interface index of the upstream interface + * + * If there are multiple interfaces of the same type, set this to select + * which one to use for the upstream. + */ +#ifndef CONFIG_GNRC_DHCPV6_CLIENT_6LBR_UPSTREAM_IDX +#define CONFIG_GNRC_DHCPV6_CLIENT_6LBR_UPSTREAM_IDX (0) +#endif + /** * @brief 6LoWPAN compression context lifetime for configured prefixes in * minutes diff --git a/sys/net/gnrc/application_layer/dhcpv6/client_simple_pd.c b/sys/net/gnrc/application_layer/dhcpv6/client_simple_pd.c index da1a98759be7..349dab922be6 100644 --- a/sys/net/gnrc/application_layer/dhcpv6/client_simple_pd.c +++ b/sys/net/gnrc/application_layer/dhcpv6/client_simple_pd.c @@ -48,6 +48,12 @@ static gnrc_netif_t *_find_upstream_netif(void) if (CONFIG_GNRC_DHCPV6_CLIENT_6LBR_UPSTREAM) { return gnrc_netif_get_by_pid(CONFIG_GNRC_DHCPV6_CLIENT_6LBR_UPSTREAM); } + + if (CONFIG_GNRC_DHCPV6_CLIENT_6LBR_UPSTREAM_TYPE != NETDEV_ANY) { + return gnrc_netif_get_by_type(CONFIG_GNRC_DHCPV6_CLIENT_6LBR_UPSTREAM_TYPE, + CONFIG_GNRC_DHCPV6_CLIENT_6LBR_UPSTREAM_IDX); + } + while ((netif = gnrc_netif_iter(netif))) { if (!gnrc_netif_is_6lo(netif)) { LOG_WARNING("DHCPv6: Selecting interface %d as upstream\n", From 28289a13cbdc4c7f8f5433d68367c522df59cf8d Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Sat, 18 Feb 2023 23:57:43 +0100 Subject: [PATCH 2/4] gnrc_dhcpv6_client_simple_pd: check result of _find_upstream_netif() --- sys/net/gnrc/application_layer/dhcpv6/client_simple_pd.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/sys/net/gnrc/application_layer/dhcpv6/client_simple_pd.c b/sys/net/gnrc/application_layer/dhcpv6/client_simple_pd.c index 349dab922be6..a1ee5691c731 100644 --- a/sys/net/gnrc/application_layer/dhcpv6/client_simple_pd.c +++ b/sys/net/gnrc/application_layer/dhcpv6/client_simple_pd.c @@ -99,9 +99,16 @@ static void _configure_dhcpv6_client(void) { gnrc_netif_t *netif = NULL; gnrc_netif_t *upstream = _find_upstream_netif(); + + if (upstream == NULL) { + LOG_ERROR("DHCPv6: No upstream interface found!\n"); + return; + } + if (IS_ACTIVE(MODULE_DHCPV6_CLIENT_IA_NA)) { upstream->ipv6.aac_mode |= GNRC_NETIF_AAC_DHCP; } + while ((netif = gnrc_netif_iter(netif))) { if (IS_USED(MODULE_GNRC_DHCPV6_CLIENT_6LBR) && !gnrc_netif_is_6lo(netif)) { From 2285961810046956ea1b632973f0d8fa6525cc83 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Mon, 20 Feb 2023 18:22:00 +0100 Subject: [PATCH 3/4] sys/crypto: make AES_KEY struct private --- sys/crypto/aes.c | 24 ++++++++++++++++-------- sys/include/crypto/aes.h | 15 --------------- 2 files changed, 16 insertions(+), 23 deletions(-) diff --git a/sys/crypto/aes.c b/sys/crypto/aes.c index 22f3adb8c52b..a54072c11abf 100644 --- a/sys/crypto/aes.c +++ b/sys/crypto/aes.c @@ -32,8 +32,6 @@ * @} */ -#include -#include #include #include #include @@ -62,6 +60,16 @@ # define AES_KEY_SIZE(ctx) ctx->key_size #endif +/** + * @brief AES key + * @see cipher_context_t + */ +typedef struct { + /** @cond INTERNAL */ + uint32_t rd_key[4 * (AES_MAXNR + 1)]; + int rounds; + /** @endcond */ +} aes_key_t; /** * Interface to the aes cipher */ @@ -860,7 +868,7 @@ int aes_init(cipher_context_t *context, const uint8_t *key, uint8_t keySize) * Expand the cipher key into the encryption key schedule. */ static int aes_set_encrypt_key(const unsigned char *userKey, const int bits, - AES_KEY *key) + aes_key_t *key) { u32 *rk; int i = 0; @@ -979,7 +987,7 @@ static int aes_set_encrypt_key(const unsigned char *userKey, const int bits, * Expand the cipher key into the decryption key schedule. */ static int aes_set_decrypt_key(const unsigned char *userKey, const int bits, - AES_KEY *key) + aes_key_t *key) { u32 *rk; int i, j; @@ -1062,8 +1070,8 @@ int aes_encrypt(const cipher_context_t *context, const uint8_t *plainBlock, { /* setup AES_KEY */ int res; - AES_KEY aeskey; - const AES_KEY *key = &aeskey; + aes_key_t aeskey; + const aes_key_t *key = &aeskey; res = aes_set_encrypt_key((unsigned char *)context->context, AES_KEY_SIZE(context) * 8, &aeskey); @@ -1331,8 +1339,8 @@ int aes_decrypt(const cipher_context_t *context, const uint8_t *cipherBlock, { /* setup AES_KEY */ int res; - AES_KEY aeskey; - const AES_KEY *key = &aeskey; + aes_key_t aeskey; + const aes_key_t *key = &aeskey; res = aes_set_decrypt_key((unsigned char *)context->context, AES_KEY_SIZE(context) * 8, &aeskey); diff --git a/sys/include/crypto/aes.h b/sys/include/crypto/aes.h index 2055dbb76aba..73496ea0f17b 100644 --- a/sys/include/crypto/aes.h +++ b/sys/include/crypto/aes.h @@ -30,10 +30,6 @@ #ifndef CRYPTO_AES_H #define CRYPTO_AES_H -#include -#include -#include -#include #include #include "crypto/ciphers.h" @@ -64,17 +60,6 @@ typedef uint8_t u8; #define AES_KEY_SIZE_256 32 /** @} */ -/** - * @brief AES key - * @see cipher_context_t - */ -typedef struct aes_key_st { - /** @cond INTERNAL */ - uint32_t rd_key[4 * (AES_MAXNR + 1)]; - int rounds; - /** @endcond */ -} AES_KEY; - /** * @brief the cipher_context_t-struct adapted for AES */ From d6e2499ab7789caa935d7de57c70816c55488fae Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Mon, 20 Feb 2023 18:31:23 +0100 Subject: [PATCH 4/4] tests/sys_crypto: add missing include --- tests/sys_crypto/tests-crypto-aes.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/sys_crypto/tests-crypto-aes.c b/tests/sys_crypto/tests-crypto-aes.c index fb67fed73cad..38f46c9b99fe 100644 --- a/tests/sys_crypto/tests-crypto-aes.c +++ b/tests/sys_crypto/tests-crypto-aes.c @@ -6,6 +6,7 @@ * directory for more details. */ +#include #include #include "embUnit.h"