Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kconfig: Expose gnrc/ipv6/whitelist configurations #12893

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ mainmenu "RIOT Configuration"
# For now, get used modules as macros from this file (see kconfig.mk)
osource "$(KCONFIG_GENERATED_DEPENDENCIES)"

rsource "sys/Kconfig"

# The application may declare new symbols as well
osource "$(APPDIR)/Kconfig"

Expand Down
11 changes: 11 additions & 0 deletions sys/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright (c) 2019 HAW Hamburg
#
# This file is subject to the terms and conditions of the GNU Lesser
# General Public License v2.1. See the file LICENSE in the top level
# directory for more details.
#
menu "System"

rsource "net/Kconfig"

endmenu # System
4 changes: 2 additions & 2 deletions sys/include/net/gnrc/ipv6/whitelist.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ extern "C" {
/**
* Maximum size of the whitelist.
*/
#ifndef GNRC_IPV6_WHITELIST_SIZE
#define GNRC_IPV6_WHITELIST_SIZE (8)
#ifndef CONFIG_GNRC_IPV6_WHITELIST_SIZE
#define CONFIG_GNRC_IPV6_WHITELIST_SIZE (8)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have to rename all config macros to be usable with kconfig?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, Kconfig generates the .config and .h files appending the CONFIG_ symbol. Regardless of that, I think it's good to have configuration macros under a single namespace.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, were just wondering for future integrations.

#endif
/** @} */

Expand Down
11 changes: 11 additions & 0 deletions sys/net/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright (c) 2019 HAW Hamburg
#
# This file is subject to the terms and conditions of the GNU Lesser
# General Public License v2.1. See the file LICENSE in the top level
# directory for more details.
#
menu "Networking"

rsource "gnrc/Kconfig"

endmenu # Networking
12 changes: 12 additions & 0 deletions sys/net/gnrc/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright (c) 2019 HAW Hamburg
#
# This file is subject to the terms and conditions of the GNU Lesser
# General Public License v2.1. See the file LICENSE in the top level
# directory for more details.
#
menu "GNRC Network stack"
depends on MODULE_GNRC

rsource "network_layer/ipv6/whitelist/Kconfig"

endmenu # GNRC Network Stack
19 changes: 19 additions & 0 deletions sys/net/gnrc/network_layer/ipv6/whitelist/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright (c) 2019 HAW Hamburg
#
# This file is subject to the terms and conditions of the GNU Lesser
# General Public License v2.1. See the file LICENSE in the top level
# directory for more details.
#
menuconfig KCONFIG_MODULE_GNRC_IPV6_WHITELIST
bool "Configure GNRC IPv6 Whitelisting"
depends on MODULE_GNRC_IPV6_WHITELIST
help
Configure GNRC IPv6 Whitelisting module using Kconfig.

if KCONFIG_MODULE_GNRC_IPV6_WHITELIST

config GNRC_IPV6_WHITELIST_SIZE
int "Maximum size of the whitelist"
default 8

endif # KCONFIG_MODULE_GNRC_IPV6_WHITELIST
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
#define ENABLE_DEBUG (0)
#include "debug.h"

ipv6_addr_t gnrc_ipv6_whitelist[GNRC_IPV6_WHITELIST_SIZE];
BITFIELD(gnrc_ipv6_whitelist_set, GNRC_IPV6_WHITELIST_SIZE);
ipv6_addr_t gnrc_ipv6_whitelist[CONFIG_GNRC_IPV6_WHITELIST_SIZE];
BITFIELD(gnrc_ipv6_whitelist_set, CONFIG_GNRC_IPV6_WHITELIST_SIZE);

static char addr_str[IPV6_ADDR_MAX_STR_LEN];

int gnrc_ipv6_whitelist_add(const ipv6_addr_t *addr)
{
for (int i = 0; i < GNRC_IPV6_WHITELIST_SIZE; i++) {
for (int i = 0; i < CONFIG_GNRC_IPV6_WHITELIST_SIZE; i++) {
if (!bf_isset(gnrc_ipv6_whitelist_set, i)) {
bf_set(gnrc_ipv6_whitelist_set, i);
memcpy(&gnrc_ipv6_whitelist[i], addr, sizeof(*addr));
Expand All @@ -42,7 +42,7 @@ int gnrc_ipv6_whitelist_add(const ipv6_addr_t *addr)

void gnrc_ipv6_whitelist_del(const ipv6_addr_t *addr)
{
for (int i = 0; i < GNRC_IPV6_WHITELIST_SIZE; i++) {
for (int i = 0; i < CONFIG_GNRC_IPV6_WHITELIST_SIZE; i++) {
if (ipv6_addr_equal(addr, &gnrc_ipv6_whitelist[i])) {
bf_unset(gnrc_ipv6_whitelist_set, i);
DEBUG("IPv6 whitelist: unwhitelisted %s\n",
Expand All @@ -53,7 +53,7 @@ void gnrc_ipv6_whitelist_del(const ipv6_addr_t *addr)

bool gnrc_ipv6_whitelisted(const ipv6_addr_t *addr)
{
for (int i = 0; i < GNRC_IPV6_WHITELIST_SIZE; i++) {
for (int i = 0; i < CONFIG_GNRC_IPV6_WHITELIST_SIZE; i++) {
if (bf_isset(gnrc_ipv6_whitelist_set, i) &&
ipv6_addr_equal(addr, &gnrc_ipv6_whitelist[i])) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@

#include "net/gnrc/ipv6/whitelist.h"

extern ipv6_addr_t gnrc_ipv6_whitelist[GNRC_IPV6_WHITELIST_SIZE];
extern BITFIELD(gnrc_ipv6_whitelist_set, GNRC_IPV6_WHITELIST_SIZE);
extern ipv6_addr_t gnrc_ipv6_whitelist[CONFIG_GNRC_IPV6_WHITELIST_SIZE];
extern BITFIELD(gnrc_ipv6_whitelist_set, CONFIG_GNRC_IPV6_WHITELIST_SIZE);

void gnrc_ipv6_whitelist_print(void)
{
char addr_str[IPV6_ADDR_MAX_STR_LEN];
for (int i = 0; i < GNRC_IPV6_WHITELIST_SIZE; i++) {
for (int i = 0; i < CONFIG_GNRC_IPV6_WHITELIST_SIZE; i++) {
if (bf_isset(gnrc_ipv6_whitelist_set, i)) {
puts(ipv6_addr_to_str(addr_str, &gnrc_ipv6_whitelist[i], sizeof(addr_str)));
}
Expand Down