Skip to content

Commit c0e3004

Browse files
author
Richard Aas
committed
bfcp: add support for DTLS transport
1 parent baee416 commit c0e3004

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

include/re_bfcp.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ enum bfcp_priority {
101101
/** BFCP Transport */
102102
enum bfcp_transp {
103103
BFCP_UDP,
104+
BFCP_DTLS,
104105
};
105106

106107
/** BFCP Request Status */
@@ -178,6 +179,7 @@ struct bfcp_msg {
178179
struct list attrl;
179180
};
180181

182+
struct tls;
181183
struct bfcp_conn;
182184

183185

@@ -259,7 +261,7 @@ const char *bfcp_prim_name(enum bfcp_prim prim);
259261

260262
/* conn */
261263
int bfcp_listen(struct bfcp_conn **bcp, enum bfcp_transp tp, struct sa *laddr,
262-
bfcp_recv_h *recvh, void *arg);
264+
struct tls *tls, bfcp_recv_h *recvh, void *arg);
263265
void *bfcp_sock(const struct bfcp_conn *bc);
264266

265267

src/bfcp/bfcp.h

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ struct bfcp_conn {
1717
struct tmr tmr1;
1818
struct tmr tmr2;
1919
struct udp_sock *us;
20+
struct tls_sock *ss;
2021
struct mbuf *mb;
2122
bfcp_recv_h *recvh;
2223
void *arg;

src/bfcp/conn.c

+18-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <re_list.h>
1212
#include <re_sa.h>
1313
#include <re_udp.h>
14+
#include <re_tls.h>
1415
#include <re_tmr.h>
1516
#include <re_bfcp.h>
1617
#include "bfcp.h"
@@ -23,6 +24,7 @@ static void destructor(void *arg)
2324
list_flush(&bc->ctransl);
2425
tmr_cancel(&bc->tmr1);
2526
tmr_cancel(&bc->tmr2);
27+
mem_deref(bc->ss);
2628
mem_deref(bc->us);
2729
mem_deref(bc->mb);
2830
}
@@ -81,13 +83,14 @@ static void udp_recv_handler(const struct sa *src, struct mbuf *mb, void *arg)
8183
* @param bcp Pointer to BFCP connection
8284
* @param tp BFCP Transport type
8385
* @param laddr Optional listening address/port
86+
* @param tls TLS Context (optional)
8487
* @param recvh Receive handler
8588
* @param arg Receive handler argument
8689
*
8790
* @return 0 if success, otherwise errorcode
8891
*/
8992
int bfcp_listen(struct bfcp_conn **bcp, enum bfcp_transp tp, struct sa *laddr,
90-
bfcp_recv_h *recvh, void *arg)
93+
struct tls *tls, bfcp_recv_h *recvh, void *arg)
9194
{
9295
struct bfcp_conn *bc;
9396
int err;
@@ -106,6 +109,7 @@ int bfcp_listen(struct bfcp_conn **bcp, enum bfcp_transp tp, struct sa *laddr,
106109
switch (bc->tp) {
107110

108111
case BFCP_UDP:
112+
case BFCP_DTLS:
109113
err = udp_listen(&bc->us, laddr, udp_recv_handler, bc);
110114
if (err)
111115
goto out;
@@ -122,6 +126,18 @@ int bfcp_listen(struct bfcp_conn **bcp, enum bfcp_transp tp, struct sa *laddr,
122126
goto out;
123127
}
124128

129+
if (bc->tp == BFCP_DTLS) {
130+
131+
#ifdef USE_OPENSSL_DTLS
132+
err = tls_start_udp(&bc->ss, tls, bc->us, 0, 4);
133+
#else
134+
(void)tls;
135+
err = ENOSYS;
136+
#endif
137+
if (err)
138+
goto out;
139+
}
140+
125141
out:
126142
if (err)
127143
mem_deref(bc);
@@ -140,6 +156,7 @@ int bfcp_send(struct bfcp_conn *bc, const struct sa *dst, struct mbuf *mb)
140156
switch (bc->tp) {
141157

142158
case BFCP_UDP:
159+
case BFCP_DTLS:
143160
return udp_send(bc->us, dst, mb);
144161

145162
default:

0 commit comments

Comments
 (0)