Skip to content

Commit bda1e76

Browse files
hongquan-progkartben
authored andcommitted
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 <[email protected]>
1 parent cc620a3 commit bda1e76

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

subsys/mgmt/mcumgr/transport/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ config MCUMGR_TRANSPORT_NETBUF_SIZE
5151
config MCUMGR_TRANSPORT_NETBUF_MIN_USER_DATA_SIZE
5252
int
5353
default 24 if MCUMGR_TRANSPORT_UDP && NET_IPV6
54+
default 20 if MCUMGR_TRANSPORT_UDP && MCUMGR_TRANSPORT_UDP_IPV4 && NET_SOCKETS_PACKET
5455
default 8 if MCUMGR_TRANSPORT_UDP && MCUMGR_TRANSPORT_UDP_IPV4
5556
default 8 if MCUMGR_TRANSPORT_BT
5657
default 4

subsys/mgmt/mcumgr/transport/src/smp_udp.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ static int create_socket(enum proto_type proto, int *sock)
164164
int tmp_sock;
165165
int err;
166166
struct sockaddr *addr;
167+
socklen_t addr_len = 0;
167168

168169
#ifdef CONFIG_MCUMGR_TRANSPORT_UDP_IPV4
169170
struct sockaddr_in addr4;
@@ -175,6 +176,7 @@ static int create_socket(enum proto_type proto, int *sock)
175176

176177
#ifdef CONFIG_MCUMGR_TRANSPORT_UDP_IPV4
177178
if (proto == PROTOCOL_IPV4) {
179+
addr_len = sizeof(struct sockaddr_in);
178180
memset(&addr4, 0, sizeof(addr4));
179181
addr4.sin_family = AF_INET;
180182
addr4.sin_port = htons(CONFIG_MCUMGR_TRANSPORT_UDP_PORT);
@@ -185,6 +187,7 @@ static int create_socket(enum proto_type proto, int *sock)
185187

186188
#ifdef CONFIG_MCUMGR_TRANSPORT_UDP_IPV6
187189
if (proto == PROTOCOL_IPV6) {
190+
addr_len = sizeof(struct sockaddr_in6);
188191
memset(&addr6, 0, sizeof(addr6));
189192
addr6.sin6_family = AF_INET6;
190193
addr6.sin6_port = htons(CONFIG_MCUMGR_TRANSPORT_UDP_PORT);
@@ -203,7 +206,7 @@ static int create_socket(enum proto_type proto, int *sock)
203206
return -err;
204207
}
205208

206-
if (zsock_bind(tmp_sock, addr, sizeof(*addr)) < 0) {
209+
if (zsock_bind(tmp_sock, addr, addr_len) < 0) {
207210
err = errno;
208211
LOG_ERR("Could not bind to receive socket (%s), err: %i",
209212
smp_udp_proto_to_name(proto), err);

0 commit comments

Comments
 (0)