Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add IPv4 support for RIOT OS #129

Merged
merged 1 commit into from
Jun 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 33 additions & 5 deletions session.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,23 @@
&& uip_ipaddr_cmp(&((A)->addr),&((B)->addr)) \
&& (A)->ifindex == (B)->ifindex)
#elif defined(WITH_RIOT_SOCK)
#define _dtls_address_equals_impl(A,B) \
((A)->size == (B)->size \
&& (A)->addr.port == (B)->addr.port \
&& ipv6_addr_equal(&((A)->addr.addr6),&((B)->addr.addr6)) \
&& (A)->ifindex == (B)->ifindex)
#include "net/af.h"
#ifdef SOCK_HAS_IPV4
#define _dtls_ipv4_address_equals_impl(A,B) \
((A)->size == (B)->size \
&& (A)->addr.port == (B)->addr.port \
&& (A)->ifindex == (B)->ifindex) \
&& (A)->addr.family == (B)->addr.family \
&& ipv4_addr_equal(&((A)->addr.ipv4),&((B)->addr.ipv4))
#endif
#ifdef SOCK_HAS_IPV6
#define _dtls_ipv6_address_equals_impl(A,B) \
((A)->size == (B)->size \
&& (A)->addr.port == (B)->addr.port \
&& (A)->ifindex == (B)->ifindex) \
&& (A)->addr.family == (B)->addr.family \
&& ipv6_addr_equal(&((A)->addr.ipv6),&((B)->addr.ipv6))
#endif
#else /* WITH_CONTIKI */

static inline int
Expand Down Expand Up @@ -120,5 +132,21 @@ dtls_session_addr(session_t *sess, socklen_t *addrlen) {
int
dtls_session_equals(const session_t *a, const session_t *b) {
assert(a); assert(b);
#ifdef RIOT_VERSION
switch (a->addr.family) {
#ifdef SOCK_HAS_IPV4
case AF_INET:
return _dtls_ipv4_address_equals_impl(a, b);
#endif
#ifdef SOCK_HAS_IPV6
case AF_INET6:
return _dtls_ipv6_address_equals_impl(a, b);
#endif
default:
assert(0);
return false;
}
#else
return _dtls_address_equals_impl(a, b);
#endif /* RIOT_VERSION */
}
19 changes: 14 additions & 5 deletions session.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,23 @@ typedef struct {
} session_t;
/* TODO: Add support for RIOT over sockets */
#elif defined(WITH_RIOT_SOCK)
#include "net/ipv4/addr.h"
#include "net/ipv6/addr.h"
typedef struct {
unsigned char size; /**< size of session_t::addr */
unsigned char size; /**< size of session_t::addr */
struct {
unsigned short port; /**< transport layer port */
ipv6_addr_t addr6; /**< IPv6 address */
} addr; /**< session IP address and port */
int ifindex; /**< network interface index */
unsigned short family; /**< IP address family */
unsigned short port; /**< transport layer port */
union {
#ifdef SOCK_HAS_IPV4
ipv4_addr_t ipv4; /**< IPv4 address */
#endif
#ifdef SOCK_HAS_IPV6
ipv6_addr_t ipv6; /**< IPv6 address */
#endif
};
obgm marked this conversation as resolved.
Show resolved Hide resolved
} addr; /**< session IP address and port */
int ifindex; /**< network interface index */
} session_t;
#else /* ! WITH_CONTIKI && ! WITH_RIOT_SOCK */

Expand Down