static bool recv_handler(struct sa *src, struct mbuf *mb, void *arg) { struct menc_st *st = arg; err_status_t e; int len; (void)src; if (!st->use_srtp || !is_rtp_or_rtcp(mb)) return false; len = (int)mbuf_get_left(mb); if (is_rtcp_packet(mb)) { e = srtp_unprotect_rtcp(st->srtp_rx, mbuf_buf(mb), &len); } else { e = srtp_unprotect(st->srtp_rx, mbuf_buf(mb), &len); } if (e != err_status_ok) { DEBUG_WARNING("recv: failed to unprotect %s-packet" " with %d bytes (%H)\n", is_rtcp_packet(mb) ? "RTCP" : "RTP", len, errstatus_print, e); return true; /* error - drop packet */ } mbuf_set_end(mb, mb->pos + len); return false; /* continue processing */ }
static bool send_handler(int *err, struct sa *dst, struct mbuf *mb, void *arg) { struct menc_st *st = arg; size_t len = mbuf_get_left(mb); int lerr = 0; (void)dst; if (!st->use_srtp || !is_rtp_or_rtcp(mb)) return false; if (is_rtcp_packet(mb)) { lerr = srtcp_encrypt(st->srtp_tx, mb); } else { lerr = srtp_encrypt(st->srtp_tx, mb); } if (lerr) { warning("srtp: failed to encrypt %s-packet" " with %zu bytes (%m)\n", is_rtcp_packet(mb) ? "RTCP" : "RTP", len, lerr); *err = lerr; return false; } return false; /* continue processing */ }
static bool recv_handler(struct sa *src, struct mbuf *mb, void *arg) { struct menc_st *st = arg; size_t len = mbuf_get_left(mb); int err = 0; (void)src; if (!st->got_sdp) return true; /* drop the packet */ if (!st->use_srtp || !is_rtp_or_rtcp(mb)) return false; if (is_rtcp_packet(mb)) { err = srtcp_decrypt(st->srtp_rx, mb); if (err) { warning("srtp: failed to decrypt RTCP packet" " with %zu bytes (%m)\n", len, err); } } else { err = srtp_decrypt(st->srtp_rx, mb); if (err) { warning("srtp: failed to decrypt RTP packet" " with %zu bytes (%m)\n", len, err); } } return err ? true : false; }
static bool send_handler(int *err, struct sa *dst, struct mbuf *mb, void *arg) { struct menc_st *st = arg; err_status_t e; int len; (void)dst; if (!st->use_srtp || !is_rtp_or_rtcp(mb)) return false; len = (int)mbuf_get_left(mb); if (mbuf_get_space(mb) < ((size_t)len + SRTP_MAX_TRAILER_LEN)) { mbuf_resize(mb, mb->pos + len + SRTP_MAX_TRAILER_LEN); } if (is_rtcp_packet(mb)) { e = srtp_protect_rtcp(st->srtp_tx, mbuf_buf(mb), &len); } else { e = srtp_protect(st->srtp_tx, mbuf_buf(mb), &len); } if (err_status_ok != e) { DEBUG_WARNING("send: failed to protect %s-packet" " with %d bytes (%H)\n", is_rtcp_packet(mb) ? "RTCP" : "RTP", len, errstatus_print, e); *err = EPROTO; return false; } mbuf_set_end(mb, mb->pos + len); return false; /* continue processing */ }