1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

pkg/tinydtls: join IPv6 address and port in addr member

This commit is contained in:
Leandro Lanzieri 2022-03-24 12:18:43 +01:00
parent 530e699de1
commit 05db36a3d0
No known key found for this signature in database
GPG Key ID: F4E9A721761C7593
4 changed files with 18 additions and 18 deletions

View File

@ -119,9 +119,8 @@ static int dtls_handle_read(dtls_context_t *ctx)
return 0; return 0;
} }
/* session requires the remote socket (IPv6:UDP) address and netif */ dtls_session_init(&session);
session.size = sizeof(uint8_t) * 16 + sizeof(unsigned short); session.addr.port = remote.port;
session.port = remote.port;
if (remote.netif == SOCK_ADDR_ANY_NETIF) { if (remote.netif == SOCK_ADDR_ANY_NETIF) {
session.ifindex = SOCK_ADDR_ANY_NETIF; session.ifindex = SOCK_ADDR_ANY_NETIF;
} }
@ -129,11 +128,11 @@ static int dtls_handle_read(dtls_context_t *ctx)
session.ifindex = remote.netif; session.ifindex = remote.netif;
} }
memcpy(&session.addr, &remote.addr.ipv6, sizeof(session.addr)); memcpy(&session.addr.addr, &remote.addr.ipv6, sizeof(session.addr.addr));
if (IS_ACTIVE(ENABLE_DEBUG)) { if (IS_ACTIVE(ENABLE_DEBUG)) {
DEBUG("DBG-Client: Msg received from \n\t Addr Src: ["); DEBUG("DBG-Client: Msg received from \n\t Addr Src: [");
ipv6_addr_print(&session.addr); ipv6_addr_print(&session.addr.addr);
DEBUG("]:%u\n", remote.port); DEBUG("]:%u\n", remote.port);
} }
@ -325,6 +324,8 @@ dtls_context_t *_init_dtls(sock_udp_t *sock, sock_udp_ep_t *local,
dtls_set_log_level(TINYDTLS_LOG_LVL); dtls_set_log_level(TINYDTLS_LOG_LVL);
#endif #endif
dtls_session_init(dst);
/* First, we prepare the UDP Sock */ /* First, we prepare the UDP Sock */
local->port = (unsigned short) CLIENT_PORT; local->port = (unsigned short) CLIENT_PORT;
remote->port = (unsigned short) DTLS_DEFAULT_PORT; remote->port = (unsigned short) DTLS_DEFAULT_PORT;
@ -358,11 +359,10 @@ dtls_context_t *_init_dtls(sock_udp_t *sock, sock_udp_ep_t *local,
} }
/* Second: We prepare the DTLS Session by means of ctx->app */ /* Second: We prepare the DTLS Session by means of ctx->app */
dst->size = sizeof(uint8_t) * 16 + sizeof(unsigned short); dst->addr.port = remote->port;
dst->port = remote->port;
/* NOTE: remote.addr.ipv6 and dst->addr are different structures. */ /* NOTE: remote.addr.ipv6 and dst->addr.addr are different structures. */
if (ipv6_addr_from_str(&dst->addr, addr_str) == NULL) { if (ipv6_addr_from_str(&dst->addr.addr, addr_str) == NULL) {
puts("ERROR: init_dtls was unable to load the IPv6 addresses!"); puts("ERROR: init_dtls was unable to load the IPv6 addresses!");
return new_context; return new_context;
} }

View File

@ -114,8 +114,8 @@ static int dtls_handle_read(dtls_context_t *ctx)
DEBUG("DBG-Server: Record Rcvd\n"); DEBUG("DBG-Server: Record Rcvd\n");
/* (DTLS) session requires the remote peer address (IPv6:Port) and netif */ /* (DTLS) session requires the remote peer address (IPv6:Port) and netif */
session.size = sizeof(uint8_t) * 16 + sizeof(unsigned short); dtls_session_init(&session);
session.port = remote_peer->remote->port; session.addr.port = remote_peer->remote->port;
if (remote_peer->remote->netif == SOCK_ADDR_ANY_NETIF) { if (remote_peer->remote->netif == SOCK_ADDR_ANY_NETIF) {
session.ifindex = SOCK_ADDR_ANY_NETIF; session.ifindex = SOCK_ADDR_ANY_NETIF;
} }
@ -123,7 +123,7 @@ static int dtls_handle_read(dtls_context_t *ctx)
session.ifindex = remote_peer->remote->netif; session.ifindex = remote_peer->remote->netif;
} }
memcpy(&session.addr, &remote_peer->remote->addr.ipv6, sizeof(session.addr)); memcpy(&session.addr.addr, &remote_peer->remote->addr.ipv6, sizeof(session.addr.addr));
return dtls_handle_message(ctx, &session, packet_rcvd, res); return dtls_handle_message(ctx, &session, packet_rcvd, res);
} }

View File

@ -817,9 +817,9 @@ void sock_dtls_init(void)
static void _ep_to_session(const sock_udp_ep_t *ep, session_t *session) static void _ep_to_session(const sock_udp_ep_t *ep, session_t *session)
{ {
session->port = ep->port; dtls_session_init(session);
session->size = sizeof(ipv6_addr_t) + /* addr */ session->addr.port = ep->port;
sizeof(unsigned short); /* port */
if (ipv6_addr_is_link_local((ipv6_addr_t *)ep->addr.ipv6)) { if (ipv6_addr_is_link_local((ipv6_addr_t *)ep->addr.ipv6)) {
/* set ifindex for link-local addresses */ /* set ifindex for link-local addresses */
session->ifindex = ep->netif; session->ifindex = ep->netif;
@ -827,15 +827,15 @@ static void _ep_to_session(const sock_udp_ep_t *ep, session_t *session)
else { else {
session->ifindex = SOCK_ADDR_ANY_NETIF; session->ifindex = SOCK_ADDR_ANY_NETIF;
} }
memcpy(&session->addr, &ep->addr.ipv6, sizeof(ipv6_addr_t)); memcpy(&session->addr.addr, &ep->addr.ipv6, sizeof(session->addr.addr));
} }
static void _session_to_ep(const session_t *session, sock_udp_ep_t *ep) static void _session_to_ep(const session_t *session, sock_udp_ep_t *ep)
{ {
ep->port = session->port; ep->port = session->addr.port;
ep->netif = session->ifindex; ep->netif = session->ifindex;
ep->family = AF_INET6; ep->family = AF_INET6;
memcpy(&ep->addr.ipv6, &session->addr, sizeof(ipv6_addr_t)); memcpy(&ep->addr.ipv6, &session->addr.addr, sizeof(ep->addr.ipv6));
} }
static inline uint32_t _update_timeout(uint32_t start, uint32_t timeout) static inline uint32_t _update_timeout(uint32_t start, uint32_t timeout)