From ece4c22ef6fe9926c1ad11cb3760416008d38442 Mon Sep 17 00:00:00 2001 From: Hongquan Li Date: Tue, 10 Dec 2024 21:35:30 +0800 Subject: [PATCH] Subsys: mgmt: mcumgr: Fix mcumgr assertion error In the case of IPV6 not enabled, when NET_SOCKETS_PACKET is enabled, the sizeof(struct sockarr) will change to 20, the value of MCUMGR_TRANSPORT_NETBUF_MIN_USER_DATA_SIZE is 8, which is not able to pass the compilation, so I change its default value to 20. Fixes #82757 Signed-off-by: Hongquan Li --- subsys/mgmt/mcumgr/transport/Kconfig | 1 + subsys/mgmt/mcumgr/transport/src/smp_udp.c | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/subsys/mgmt/mcumgr/transport/Kconfig b/subsys/mgmt/mcumgr/transport/Kconfig index a892caee8d6b69..90bd158ed161ea 100644 --- a/subsys/mgmt/mcumgr/transport/Kconfig +++ b/subsys/mgmt/mcumgr/transport/Kconfig @@ -51,6 +51,7 @@ config MCUMGR_TRANSPORT_NETBUF_SIZE config MCUMGR_TRANSPORT_NETBUF_MIN_USER_DATA_SIZE int default 24 if MCUMGR_TRANSPORT_UDP && NET_IPV6 + default 20 if MCUMGR_TRANSPORT_UDP && MCUMGR_TRANSPORT_UDP_IPV4 && NET_SOCKETS_PACKET default 8 if MCUMGR_TRANSPORT_UDP && MCUMGR_TRANSPORT_UDP_IPV4 default 8 if MCUMGR_TRANSPORT_BT default 4 diff --git a/subsys/mgmt/mcumgr/transport/src/smp_udp.c b/subsys/mgmt/mcumgr/transport/src/smp_udp.c index 77734889ac86a1..60ed9816ed26d1 100644 --- a/subsys/mgmt/mcumgr/transport/src/smp_udp.c +++ b/subsys/mgmt/mcumgr/transport/src/smp_udp.c @@ -164,6 +164,7 @@ static int create_socket(enum proto_type proto, int *sock) int tmp_sock; int err; struct sockaddr *addr; + socklen_t addr_len = 0; #ifdef CONFIG_MCUMGR_TRANSPORT_UDP_IPV4 struct sockaddr_in addr4; @@ -175,6 +176,7 @@ static int create_socket(enum proto_type proto, int *sock) #ifdef CONFIG_MCUMGR_TRANSPORT_UDP_IPV4 if (proto == PROTOCOL_IPV4) { + addr_len = sizeof(struct sockaddr_in); memset(&addr4, 0, sizeof(addr4)); addr4.sin_family = AF_INET; addr4.sin_port = htons(CONFIG_MCUMGR_TRANSPORT_UDP_PORT); @@ -185,6 +187,7 @@ static int create_socket(enum proto_type proto, int *sock) #ifdef CONFIG_MCUMGR_TRANSPORT_UDP_IPV6 if (proto == PROTOCOL_IPV6) { + addr_len = sizeof(struct sockaddr_in6); memset(&addr6, 0, sizeof(addr6)); addr6.sin6_family = AF_INET6; addr6.sin6_port = htons(CONFIG_MCUMGR_TRANSPORT_UDP_PORT); @@ -203,7 +206,7 @@ static int create_socket(enum proto_type proto, int *sock) return -err; } - if (zsock_bind(tmp_sock, addr, sizeof(*addr)) < 0) { + if (zsock_bind(tmp_sock, addr, addr_len) < 0) { err = errno; LOG_ERR("Could not bind to receive socket (%s), err: %i", smp_udp_proto_to_name(proto), err);