net: lwm2m: Fix address length at connect
If NET_IPV4 and NET_SOCKETS_PACKET is enabled, NET_SOCKADDR_MAX_SIZE will be bigger than the ipv4 address length. This is a problem when DTLS is used as the address comparison will fail because of the different length of the received and the stored address. This is also a problem if NET_IPV6 and NET_IPV4 is enabled and the remote address is a ipv4 address Signed-off-by: Benjamin Bigler <benjamin.bigler@securiton.ch>
This commit is contained in:
parent
7a042377f4
commit
493b940248
1 changed files with 10 additions and 1 deletions
|
@ -5589,6 +5589,7 @@ static int load_tls_credential(struct lwm2m_ctx *client_ctx, uint16_t res_id,
|
|||
|
||||
int lwm2m_socket_start(struct lwm2m_ctx *client_ctx)
|
||||
{
|
||||
socklen_t addr_len;
|
||||
int flags;
|
||||
#if defined(CONFIG_LWM2M_DTLS_SUPPORT)
|
||||
int ret;
|
||||
|
@ -5661,9 +5662,17 @@ int lwm2m_socket_start(struct lwm2m_ctx *client_ctx)
|
|||
}
|
||||
}
|
||||
#endif /* CONFIG_LWM2M_DTLS_SUPPORT */
|
||||
if ((client_ctx->remote_addr).sa_family == AF_INET) {
|
||||
addr_len = sizeof(struct sockaddr_in);
|
||||
} else if ((client_ctx->remote_addr).sa_family == AF_INET6) {
|
||||
addr_len = sizeof(struct sockaddr_in6);
|
||||
} else {
|
||||
lwm2m_engine_context_close(client_ctx);
|
||||
return -EPROTONOSUPPORT;
|
||||
}
|
||||
|
||||
if (connect(client_ctx->sock_fd, &client_ctx->remote_addr,
|
||||
NET_SOCKADDR_MAX_SIZE) < 0) {
|
||||
addr_len) < 0) {
|
||||
LOG_ERR("Cannot connect UDP (-%d)", errno);
|
||||
lwm2m_engine_context_close(client_ctx);
|
||||
return -errno;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue