Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions modules/dtls_gw/rtpp_dtls_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,11 @@ rtpp_dtls_conn_dtls_recv(struct rtpp_dtls_conn *self,
#define SRTCP_PROTECT(a, b, c) srtp_protect_rtcp(a, b, c)
#endif

/* libsrtp2 < 2.6.0 only documents it as SRTP_MAX_TRAILER_LEN+4 */
#if !defined(SRTP_MAX_SRTCP_TRAILER_LEN)
#define SRTP_MAX_SRTCP_TRAILER_LEN (SRTP_MAX_TRAILER_LEN + 4)
#endif

static struct res_loc
rtpp_dtls_conn_rtp_send(struct rtpp_dtls_conn *self, struct pkt_proc_ctx *pktxp)
{
Expand All @@ -489,6 +494,15 @@ rtpp_dtls_conn_rtp_send(struct rtpp_dtls_conn *self, struct pkt_proc_ctx *pktxp)
return (RES_HERE(-1));
}

/*
* srtp_protect() and srtp_protect_rtcp() append the trailer in place,
* make sure it fits in data.buf (the SRTCP one is the larger of the two).
*/
if (pktxp->pktp->size > sizeof(pktxp->pktp->data.buf) -
SRTP_MAX_SRTCP_TRAILER_LEN) {
return (RES_HERE(-1));
}

if (pktxp->flags & PPROC_FLAG_COW) {
struct rtp_packet *p = rtp_packet_alloc();
if (p == NULL)
Expand Down
2 changes: 1 addition & 1 deletion tests/dtls_gw/basic
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ rm -f dtls_gw.?.rlog
-D DSO="${TOP_BUILDDIR}/modules/dtls_gw/.libs/rtpp_dtls_gw_debug.so" \
-D RECORD_DIR="${RECORD_DIR}" -D RECORD_SPL_DIR="${RECORD_SPL_DIR}" \
-D SCENARIO="${RPTL_DIR}/examples/dtls.scenario.rptl" \
-D PROMPT_NAME="${BUILDDIR}/dtls_gw.prompt" \
-D PROMPT_NAME="${BUILDDIR}/dtls_gw.prompt" -D PYINT="${PYINT}" \
2>&1 > dtls_gw.vars
echo ${?} > dtls_gw.rptl.rc
} | tee dtls_gw.rlog
Expand Down
1 change: 1 addition & 0 deletions tests/dtls_gw/basic.rptl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ socket fwd: stdio: %%RTPPROXY_ARGS%% -i -> dtls_gw.f.creplies
socket geno: stdio: %%RTPPROXY_ARGS%% -P -r %%RECORD_DIR%% -S %%RECORD_SPL_DIR%% -> dtls_gw.o.creplies
.echo: OK: rtpproxy GenO started
.include: %%SCENARIO%%
.include: oversize.rptl
.close: geno
.echo: OK: wait for rtpproxy GenO shutdown
.close: fwd
Expand Down
2 changes: 2 additions & 0 deletions tests/dtls_gw/oversize.check.rptl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fwd: Qv %%OS_CALLID%% from_tag_1 to_tag_1 npkts_ina nrelayed ndropped -> OS_STATS
.eval: %%OS_STATS%% -> str_equal(OS_EXPECTED, OS_DONE)
16 changes: 16 additions & 0 deletions tests/dtls_gw/oversize.rptl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# A plain RTP datagram that fills the whole receive buffer leaves no room
# for the SRTP trailer: Fwd has to drop it instead of protecting it in place.
.eval: dtls_gw_oversize -> OS_CALLID
fwd: U %%OS_CALLID%% 0.0.0.0 0 from_tag_1 && M4:1 S -> str_split(&&, OS_PORT1, DTLS_PARAMS)
.eval: %%DTLS_PARAMS%% -> str_split( , DTLS_MODE, DTLS_DIGALG, DTLS_DIGSUM)
geno: U %%OS_CALLID%% 127.0.0.1 %%OS_PORT1%% from_tag_1 && M4:1 A %%DTLS_DIGALG%% %%DTLS_DIGSUM%% -> validate_port(_)
geno: L %%OS_CALLID%% 0.0.0.0 0 from_tag_1 to_tag_1 && M4:1 S -> str_split(&&, OS_PORTO, DTLS_PARAMS)
.eval: %%DTLS_PARAMS%% -> str_split( , DTLS_MODE, DTLS_DIGALG, DTLS_DIGSUM)
fwd: L %%OS_CALLID%% 127.0.0.1 %%OS_PORTO%% from_tag_1 to_tag_1 && M4:1 P %%DTLS_DIGALG%% %%DTLS_DIGSUM%% -> validate_port(OS_PORT2)
.sleep: 1
.exec: %%PYINT%% -c "import socket; s=socket.socket(socket.AF_INET,socket.SOCK_DGRAM); [s.sendto(bytes.fromhex('8000%04x%08x00000001' % (q, q * 160))+bytes(n),('127.0.0.1',%%OS_PORT2%%)) for q, n in ((1, 160), (2, 9000), (3, 160))]"
.eval: npkts_ina=3 nrelayed=2 ndropped=1 -> OS_EXPECTED
.until: OS_DONE do oversize.check.rptl every 0.1 5
.eval: 0 -> RES_OK
fwd: D %%OS_CALLID%% from_tag_1 to_tag_1 -> str_compare(RES_OK)
geno: D %%OS_CALLID%% from_tag_1 to_tag_1 -> str_compare(RES_OK)
Loading