From a627951aebfece958c54132a77d32761dfc626a8 Mon Sep 17 00:00:00 2001 From: Lennart Grahl Date: Wed, 2 Nov 2016 13:56:30 +0100 Subject: [PATCH] Change DTLS connection's remote peer address (#24) * Make it possible to change the DTLS connection's remote peer address. Add `dtls_set_peer` function * Add `dtls_peer` getter function Change `dtls_set_peer` signature, leave comparison of the remote address up to the user application * Fix typo in docstring --- include/re_tls.h | 2 ++ src/tls/openssl/tls_udp.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/include/re_tls.h b/include/re_tls.h index 42ff35f..c1feda0 100644 --- a/include/re_tls.h +++ b/include/re_tls.h @@ -78,3 +78,5 @@ int dtls_accept(struct tls_conn **ptc, struct tls *tls, int dtls_send(struct tls_conn *tc, struct mbuf *mb); void dtls_set_handlers(struct tls_conn *tc, dtls_estab_h *estabh, dtls_recv_h *recvh, dtls_close_h *closeh, void *arg); +const struct sa *dtls_peer(const struct tls_conn *tc); +void dtls_set_peer(struct tls_conn *tc, const struct sa *peer); diff --git a/src/tls/openssl/tls_udp.c b/src/tls/openssl/tls_udp.c index a073b33..e04cd87 100644 --- a/src/tls/openssl/tls_udp.c +++ b/src/tls/openssl/tls_udp.c @@ -651,6 +651,37 @@ void dtls_set_handlers(struct tls_conn *tc, dtls_estab_h *estabh, } +/** + * Get the remote peer of a DTLS Connection + * + * @param tc DTLS Connection + * + * @return Remote peer + */ +const struct sa *dtls_peer(const struct tls_conn *tc) +{ + return tc ? &tc->peer : NULL; +} + + +/** + * Set the remote peer of a DTLS Connection + * + * @param tc DTLS Connection + * @param peer Peer address + */ +void dtls_set_peer(struct tls_conn *tc, const struct sa *peer) +{ + if (!tc || !peer) + return; + + hash_unlink(&tc->he); + hash_append(tc->sock->ht, sa_hash(peer, SA_ALL), &tc->he, tc); + + tc->peer = *peer; +} + + static void sock_destructor(void *arg) { struct dtls_sock *sock = arg;