-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
156 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
pkg/tinydtls/patches/0003-RIOT-OS-Add-support-for-IPv4.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
From e8a60987d0b0b2c0d5d7f1e44302049904789ec7 Mon Sep 17 00:00:00 2001 | ||
From: HendrikVE <hendrik1995@msn.com> | ||
Date: Sun, 6 Mar 2022 00:17:12 +0100 | ||
Subject: [PATCH] RIOT OS: Add support for IPv4 | ||
|
||
--- | ||
session.c | 38 +++++++++++++++++++++++++++++++++----- | ||
session.h | 16 ++++++++++++++-- | ||
2 files changed, 47 insertions(+), 7 deletions(-) | ||
|
||
diff --git a/session.c b/session.c | ||
index 8e9f544..dea8990 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) | ||
-#define _dtls_address_equals_impl(A,B) \ | ||
- ((A)->size == (B)->size \ | ||
- && (A)->port == (B)->port \ | ||
- && ipv6_addr_equal(&((A)->addr),&((B)->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)->port == (B)->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)->port == (B)->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 8ba5fa2..b90b269 100644 | ||
--- a/session.h | ||
+++ b/session.h | ||
@@ -32,12 +32,24 @@ typedef struct { | ||
} session_t; | ||
/* TODO: Add support for RIOT over sockets */ | ||
#elif defined(WITH_RIOT) | ||
+#include "net/ipv4/addr.h" | ||
#include "net/ipv6/addr.h" | ||
typedef struct { | ||
unsigned char size; | ||
- ipv6_addr_t addr; | ||
- unsigned short port; | ||
int ifindex; | ||
+ int addr_family; | ||
+ union { | ||
+ #ifdef SOCK_HAS_IPV4 | ||
+ ipv4_addr_t ipv4; | ||
+ #endif | ||
+ #ifdef SOCK_HAS_IPV6 | ||
+ ipv6_addr_t ipv6; | ||
+ #endif | ||
+ } addr; | ||
+ /* Note: Member "port" MUST follow directly after the member "addr"! dtls_hmac_update in | ||
+ * dtls.c gets "session->size" as length input which is set to e.g. | ||
+ * "sizeof(ipv6_addr_t) + sizeof(unsigned short)" = (addr + port) in sock_dtls.c */ | ||
+ unsigned short port; | ||
} session_t; | ||
#else /* ! WITH_CONTIKI && ! WITH_RIOT */ | ||
|
||
-- | ||
2.25.1 | ||
|