Skip to content

Commit 808d4cf

Browse files
committed
net: mqtt_sn: document address size and add checks for UDP
Add guidelines in Kconfig explaining the minimum required MQTT_SN_LIB_MAX_ADDR_SIZE for UDP transport and IPv4 and or IPv6. Also explain when this value might need to be changed. In addition, introduce BUILD_ASSERT checks in the UDP transport implementation to ensure the configured maximum address size is large enough for the enabled IP families. Signed-off-by: Aurelien Jarno <[email protected]>
1 parent 61a8648 commit 808d4cf

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

subsys/net/lib/mqtt_sn/Kconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ config MQTT_SN_LIB_MAX_ADDR_SIZE
4545
needs to know how long your addresses are. Set this to the maximum
4646
length in bytes of the address data structure for your implemented transport.
4747

48+
A UDP transport requires at least 8 bytes on IPv4 and 21 bytes on
49+
IPv6, corresponding to the sizes of the sockaddr_in and sockaddr_in6
50+
structs. For an out-of-tree transport, you may need to adjust this
51+
value.
52+
4853
config MQTT_SN_LIB_BROADCAST_RADIUS
4954
int "Radius for broadcast messages"
5055
default 1

subsys/net/lib/mqtt_sn/mqtt_sn_transport_udp.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919
#include <zephyr/logging/log.h>
2020
LOG_MODULE_DECLARE(net_mqtt_sn, CONFIG_MQTT_SN_LOG_LEVEL);
2121

22+
BUILD_ASSERT(CONFIG_MQTT_SN_LIB_MAX_ADDR_SIZE >= sizeof(struct net_sockaddr_in) ||
23+
!IS_ENABLED(CONFIG_NET_IPV4));
24+
25+
BUILD_ASSERT(CONFIG_MQTT_SN_LIB_MAX_ADDR_SIZE >= sizeof(struct net_sockaddr_in6) ||
26+
!IS_ENABLED(CONFIG_NET_IPV6));
27+
2228
static char *get_ip_str(const struct net_sockaddr *sa, char *s, size_t maxlen)
2329
{
2430
switch (sa->sa_family) {

0 commit comments

Comments
 (0)