stun/turn: added DTLS transport
This commit is contained in:
parent
0bb0ec6592
commit
8277f5ff0f
6 changed files with 60 additions and 1 deletions
|
@ -24,6 +24,13 @@ enum stun_af {
|
|||
STUN_AF_IPv6 = 0x02 /**< IPv6 Address Family */
|
||||
};
|
||||
|
||||
/** STUN Transport */
|
||||
enum stun_transp {
|
||||
STUN_TRANSP_UDP = IPPROTO_UDP, /**< UDP-transport (struct udp_sock) */
|
||||
STUN_TRANSP_TCP = IPPROTO_TCP, /**< TCP-transport (struct tcp_conn) */
|
||||
STUN_TRANSP_DTLS, /**< DTLS-transport (struct tls_conn) */
|
||||
};
|
||||
|
||||
/** STUN Methods */
|
||||
enum stun_method {
|
||||
STUN_METHOD_BINDING = 0x001,
|
||||
|
|
|
@ -69,3 +69,5 @@ int dtls_accept(struct tls_conn **ptc, struct tls *tls,
|
|||
dtls_estab_h *estabh, dtls_recv_h *recvh,
|
||||
dtls_close_h *closeh, void *arg);
|
||||
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);
|
||||
|
|
|
@ -11,6 +11,8 @@
|
|||
#include <re_sa.h>
|
||||
#include <re_udp.h>
|
||||
#include <re_tcp.h>
|
||||
#include <re_srtp.h>
|
||||
#include <re_tls.h>
|
||||
#include <re_list.h>
|
||||
#include <re_tmr.h>
|
||||
#include <re_md5.h>
|
||||
|
@ -85,7 +87,8 @@ static void timeout_handler(void *arg)
|
|||
goto error;
|
||||
|
||||
ct->mb->pos = ct->pos;
|
||||
err = udp_send(ct->sock, &ct->dst, ct->mb);
|
||||
|
||||
err = stun_send(ct->proto, ct->sock, &ct->dst, ct->mb);
|
||||
if (err)
|
||||
goto error;
|
||||
|
||||
|
@ -292,6 +295,19 @@ int stun_ctrans_request(struct stun_ctrans **ctp, struct stun *stun, int proto,
|
|||
tcp_close_handler, ct);
|
||||
break;
|
||||
|
||||
case STUN_TRANSP_DTLS:
|
||||
if (!sock) {
|
||||
err = EINVAL;
|
||||
break;
|
||||
}
|
||||
|
||||
ct->ival = stun_conf(stun)->rto;
|
||||
tmr_start(&ct->tmr, ct->ival, timeout_handler, ct);
|
||||
|
||||
ct->txc = 1;
|
||||
err = dtls_send(ct->sock, mb);
|
||||
break;
|
||||
|
||||
default:
|
||||
err = EPROTONOSUPPORT;
|
||||
break;
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
#include <re_sa.h>
|
||||
#include <re_udp.h>
|
||||
#include <re_tcp.h>
|
||||
#include <re_srtp.h>
|
||||
#include <re_tls.h>
|
||||
#include <re_sys.h>
|
||||
#include <re_list.h>
|
||||
#include <re_stun.h>
|
||||
|
@ -108,6 +110,10 @@ int stun_send(int proto, void *sock, const struct sa *dst, struct mbuf *mb)
|
|||
err = tcp_send(sock, mb);
|
||||
break;
|
||||
|
||||
case STUN_TRANSP_DTLS:
|
||||
err = dtls_send(sock, mb);
|
||||
break;
|
||||
|
||||
default:
|
||||
err = EPROTONOSUPPORT;
|
||||
break;
|
||||
|
|
|
@ -577,6 +577,28 @@ int dtls_send(struct tls_conn *tc, struct mbuf *mb)
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set handlers on a DTLS Connection
|
||||
*
|
||||
* @param tc DTLS Connection
|
||||
* @param estabh DTLS Connection Established handler
|
||||
* @param recvh DTLS Connection Receive data handler
|
||||
* @param closeh DTLS Connection Close handler
|
||||
* @param arg Handler argument
|
||||
*/
|
||||
void dtls_set_handlers(struct tls_conn *tc, dtls_estab_h *estabh,
|
||||
dtls_recv_h *recvh, dtls_close_h *closeh, void *arg)
|
||||
{
|
||||
if (!tc)
|
||||
return;
|
||||
|
||||
tc->estabh = estabh;
|
||||
tc->recvh = recvh;
|
||||
tc->closeh = closeh;
|
||||
tc->arg = arg;
|
||||
}
|
||||
|
||||
|
||||
static void sock_destructor(void *arg)
|
||||
{
|
||||
struct dtls_sock *sock = arg;
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#include <re_sa.h>
|
||||
#include <re_udp.h>
|
||||
#include <re_tcp.h>
|
||||
#include <re_srtp.h>
|
||||
#include <re_tls.h>
|
||||
#include <re_stun.h>
|
||||
#include <re_turn.h>
|
||||
#include "turnc.h"
|
||||
|
@ -535,6 +537,10 @@ int turnc_send(struct turnc *turnc, const struct sa *dst, struct mbuf *mb)
|
|||
err = tcp_send(turnc->sock, mb);
|
||||
break;
|
||||
|
||||
case STUN_TRANSP_DTLS:
|
||||
err = dtls_send(turnc->sock, mb);
|
||||
break;
|
||||
|
||||
default:
|
||||
err = EPROTONOSUPPORT;
|
||||
break;
|
||||
|
|
Loading…
Add table
Reference in a new issue