1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 12:52:44 +01:00
RIOT/pkg/tinydtls/patches/0004-session-Add-support-for-IPv4-on-RIOT-OS.patch
2022-03-25 17:19:47 +01:00

95 lines
2.9 KiB
Diff

From 5e044288ff5f15a71aa89c8c17fab4ba0d40a86d Mon Sep 17 00:00:00 2001
From: HendrikVE <hendrik1995@msn.com>
Date: Fri, 25 Mar 2022 14:04:02 +0100
Subject: [PATCH 4/4] session: Add support for IPv4 on RIOT OS
---
session.c | 38 +++++++++++++++++++++++++++++++++-----
session.h | 11 ++++++++++-
2 files changed, 43 insertions(+), 6 deletions(-)
diff --git a/session.c b/session.c
index 7615188..bdd845a 100644
--- a/session.c
+++ b/session.c
@@ -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.addr),&((B)->addr.addr)) \
- && (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
@@ -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 */
}
diff --git a/session.h b/session.h
index 9d7041a..6ae5a82 100644
--- a/session.h
+++ b/session.h
@@ -32,11 +32,20 @@ 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;
struct {
- ipv6_addr_t addr;
+ int family;
+ union {
+#ifdef SOCK_HAS_IPV4
+ ipv4_addr_t ipv4;
+#endif
+#ifdef SOCK_HAS_IPV6
+ ipv6_addr_t ipv6;
+#endif
+ };
unsigned short port;
} addr;
int ifindex;
--
2.25.1