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

pkg/tinydtls: Adjust defaults #19331

Merged
merged 3 commits into from
Mar 2, 2023
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
1 change: 1 addition & 0 deletions pkg/tinydtls/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ config DTLS_CONTEXT_MAX

config DTLS_PEER_MAX
int "Max number of peers"
default 2 if KCONFIG_USEMODULE_GCOAP_DTLS
default 1
help
The maximum number of DTLS peers.
Expand Down
20 changes: 20 additions & 0 deletions pkg/tinydtls/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,23 @@ all:
ifeq (llvm,$(TOOLCHAIN))
CFLAGS += -Wno-format-nonliteral
endif

ifneq (,$(filter gcoap,$(USEMODULE)))
# Configuring the buffer large enough that a full Gcoap packet can be
# encrypted or decrypted.

# This is the default in gcoap.h, which we don't have access to, so it is copied over.
CONFIG_GCOAP_PDU_BUF_SIZE := $(or $(CONFIG_GCOAP_PDU_BUF_SIZE),128)

# If there were another way to set up DTLS_MAX_BUF, we'd need to set the
# maximum of these here.
#
# 29 bytes are the overhead measured with Wireshark on packets exchanged in
# default configuration; adding some to be safe against variable size fields.
CFLAGS += "-DDTLS_MAX_BUF=($(CONFIG_GCOAP_PDU_BUF_SIZE) + 36)"
endif

# TinyDTLS emits several messages during connection establishment at the info
# level; this is way more verbose than common in RIOT.
TINYDTLS_LOG_LEVEL ?= LOG_WARNING
CFLAGS += -DLOG_LEVEL=$(TINYDTLS_LOG_LEVEL)
6 changes: 6 additions & 0 deletions pkg/tinydtls/Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ endif
PEER_MAX := $(or $(CONFIG_DTLS_PEER_MAX),$(patsubst -DCONFIG_DTLS_PEER_MAX=%,%,$(filter -DCONFIG_DTLS_PEER_MAX=%,$(CFLAGS))))
ifneq (,$(PEER_MAX))
CFLAGS += -DDTLS_PEER_MAX=$(PEER_MAX)
else ifneq (,$(filter gcoap_dtls,$(USEMODULE)))
# The default value in sys/include/net/dtls.h for CONFIG_DTLS_PEER_MAX is 2
# when gcoap_dtls is active, otherwise 1. As the default in tinydtls is 1,
# we need to set it explicitly if the dtls.h default value deviates from
# the tinydtls default.
CFLAGS += -DDTLS_PEER_MAX=2
endif

HANDSHAKE_MAX := $(or $(CONFIG_DTLS_HANDSHAKE_MAX),$(patsubst -DCONFIG_DTLS_HANDSHAKE_MAX=%,%,$(filter -DCONFIG_DTLS_HANDSHAKE_MAX=%,$(CFLAGS))))
Expand Down
6 changes: 6 additions & 0 deletions sys/include/net/dtls.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
#ifndef NET_DTLS_H
#define NET_DTLS_H

#include "modules.h"

#ifdef __cplusplus
extern "C" {
#endif
Expand All @@ -44,8 +46,12 @@ extern "C" {
* @brief The maximum number DTLS peers (i.e. sessions)
*/
#ifndef CONFIG_DTLS_PEER_MAX
#if IS_USED(MODULE_GCOAP_DTLS)
#define CONFIG_DTLS_PEER_MAX (2)
benpicco marked this conversation as resolved.
Show resolved Hide resolved
#else
#define CONFIG_DTLS_PEER_MAX (1)
#endif
#endif

#ifdef __cplusplus
}
Expand Down