bfcp: add support for DTLS transport

This commit is contained in:
Richard Aas 2013-04-03 07:58:39 +00:00
parent baee4163be
commit c0e30047d8
3 changed files with 22 additions and 2 deletions

View file

@ -101,6 +101,7 @@ enum bfcp_priority {
/** BFCP Transport */
enum bfcp_transp {
BFCP_UDP,
BFCP_DTLS,
};
/** BFCP Request Status */
@ -178,6 +179,7 @@ struct bfcp_msg {
struct list attrl;
};
struct tls;
struct bfcp_conn;
@ -259,7 +261,7 @@ const char *bfcp_prim_name(enum bfcp_prim prim);
/* conn */
int bfcp_listen(struct bfcp_conn **bcp, enum bfcp_transp tp, struct sa *laddr,
bfcp_recv_h *recvh, void *arg);
struct tls *tls, bfcp_recv_h *recvh, void *arg);
void *bfcp_sock(const struct bfcp_conn *bc);

View file

@ -17,6 +17,7 @@ struct bfcp_conn {
struct tmr tmr1;
struct tmr tmr2;
struct udp_sock *us;
struct tls_sock *ss;
struct mbuf *mb;
bfcp_recv_h *recvh;
void *arg;

View file

@ -11,6 +11,7 @@
#include <re_list.h>
#include <re_sa.h>
#include <re_udp.h>
#include <re_tls.h>
#include <re_tmr.h>
#include <re_bfcp.h>
#include "bfcp.h"
@ -23,6 +24,7 @@ static void destructor(void *arg)
list_flush(&bc->ctransl);
tmr_cancel(&bc->tmr1);
tmr_cancel(&bc->tmr2);
mem_deref(bc->ss);
mem_deref(bc->us);
mem_deref(bc->mb);
}
@ -81,13 +83,14 @@ out:
* @param bcp Pointer to BFCP connection
* @param tp BFCP Transport type
* @param laddr Optional listening address/port
* @param tls TLS Context (optional)
* @param recvh Receive handler
* @param arg Receive handler argument
*
* @return 0 if success, otherwise errorcode
*/
int bfcp_listen(struct bfcp_conn **bcp, enum bfcp_transp tp, struct sa *laddr,
bfcp_recv_h *recvh, void *arg)
struct tls *tls, bfcp_recv_h *recvh, void *arg)
{
struct bfcp_conn *bc;
int err;
@ -106,6 +109,7 @@ int bfcp_listen(struct bfcp_conn **bcp, enum bfcp_transp tp, struct sa *laddr,
switch (bc->tp) {
case BFCP_UDP:
case BFCP_DTLS:
err = udp_listen(&bc->us, laddr, udp_recv_handler, bc);
if (err)
goto out;
@ -122,6 +126,18 @@ int bfcp_listen(struct bfcp_conn **bcp, enum bfcp_transp tp, struct sa *laddr,
goto out;
}
if (bc->tp == BFCP_DTLS) {
#ifdef USE_OPENSSL_DTLS
err = tls_start_udp(&bc->ss, tls, bc->us, 0, 4);
#else
(void)tls;
err = ENOSYS;
#endif
if (err)
goto out;
}
out:
if (err)
mem_deref(bc);
@ -140,6 +156,7 @@ int bfcp_send(struct bfcp_conn *bc, const struct sa *dst, struct mbuf *mb)
switch (bc->tp) {
case BFCP_UDP:
case BFCP_DTLS:
return udp_send(bc->us, dst, mb);
default: