Commit 227f06f7 authored by jehan's avatar jehan

modify meta transport api, cleanup srtp code

parent f4d6250a
......@@ -67,11 +67,6 @@ ORTP_PUBLIC err_status_t ortp_srtp_remove_stream(srtp_t session, uint32_t ssrc);
ORTP_PUBLIC err_status_t ortp_crypto_get_random(uint8_t *tmp, int size);
ORTP_PUBLIC bool_t ortp_srtp_supported(void);
/**
* @deprecated Use srtp_transport_modifier_new() instead. Using #srtp_transport_new will prevent usage of multiple
* encryptions and/or custom packets transmission.
*/
ORTP_PUBLIC int srtp_transport_new(srtp_t srtp, RtpTransport **rtpt, RtpTransport **rtcpt );
ORTP_PUBLIC void srtp_transport_destroy(RtpTransport *tp);
ORTP_PUBLIC srtp_t ortp_srtp_create_configure_session(enum ortp_srtp_crypto_suite_t suite, uint32_t ssrc, const char* snd_key, const char* rcv_key);
......
......@@ -429,8 +429,8 @@ ORTP_PUBLIC void rtp_session_clear_aux_remote_addr(RtpSession * session);
/* alternatively to the set_remote_addr() and set_local_addr(), an application can give
a valid socket (potentially connect()ed )to be used by the RtpSession */
ORTP_PUBLIC void rtp_session_set_sockets(RtpSession *session, int rtpfd, int rtcpfd);
ORTP_PUBLIC void rtp_session_set_transports(RtpSession *session, RtpTransport *rtptr, RtpTransport *rtcptr);
ORTP_PUBLIC void rtp_session_get_transports(RtpSession *session, RtpTransport **rtptr, RtpTransport **rtcptr);
ORTP_PUBLIC void rtp_session_get_transports(const RtpSession *session, RtpTransport **rtptr, RtpTransport **rtcptr);
/*those methods are provided for people who wants to send non-RTP messages using the RTP/RTCP sockets */
ORTP_PUBLIC ortp_socket_t rtp_session_get_rtp_socket(const RtpSession *session);
ORTP_PUBLIC ortp_socket_t rtp_session_get_rtcp_socket(const RtpSession *session);
......@@ -586,19 +586,28 @@ ORTP_PUBLIC void rtp_session_dispatch_event(RtpSession *session, OrtpEvent *ev);
ORTP_PUBLIC void rtp_session_set_reuseaddr(RtpSession *session, bool_t yes);
ORTP_PUBLIC int meta_rtp_transport_modifier_inject_packet(const RtpTransport *t, RtpTransportModifier *tpm, mblk_t *msg , int flags);
/**
* #RtpTransport object which can handle multiples security protocols. You can for instance use this object
* to use both sRTP and tunnel transporter. #mblk_t messages received and sent from the endpoint
* will pass through the list of modifiers given. First modifier in list will be first to modify the message
* in send mode and last in receive mode.
* @param[in] t #RtpTransport object that will be generated.
* @param[in] is_rtp Whether this object will be used for RTP packets or not.
* @param[in] endpoint #RtpTransport object in charge of sending/receiving packets. If NULL, it will use standards sendto and recvfrom functions.
* @param[in] modifiers_count number of #RtpModifier object given in the variadic list. Must be 0 if none are given.
* @returns 0 if successful, -1 otherwise
* FIXME johan
**/
ORTP_PUBLIC int meta_rtp_transport_modifier_inject_packet(RtpTransport *t, RtpTransportModifier *tpm, mblk_t *msg , int flags);
ORTP_PUBLIC int meta_rtp_transport_new(RtpTransport **t, bool_t is_rtp, RtpTransport *endpoint, unsigned modifiers_count, ...);
ORTP_PUBLIC int meta_rtp_transport_modifier_inject_packet_to(const RtpTransport *t, RtpTransportModifier *tpm, mblk_t *msg , int flags,const struct sockaddr *to, socklen_t tolen) ;
/**
* get endpoint if any
* @param[in] t #RtpTransport object.
* @return #rtpEndpoint
*
* */
ORTP_PUBLIC RtpTransport* meta_rtp_transport_get_endpoint(const RtpTransport *transport);
/**
* set endpoint
* @param[in] t #RtpTransport object.
* @param[in] t #RtpEndpoint.
*
* */
ORTP_PUBLIC void meta_rtp_transport_set_endpoint(RtpTransport *transport,RtpTransport *endpoint);
ORTP_PUBLIC void meta_rtp_transport_destroy(RtpTransport *tp);
ORTP_PUBLIC void meta_rtp_transport_append_modifier(RtpTransport *tp,RtpTransportModifier *tpm);
#ifdef __cplusplus
......
......@@ -47,22 +47,29 @@
static int _process_on_send(RtpSession* session,srtp_t srtp,mblk_t *m,bool_t is_rtp){
int slen;
err_status_t err;
rtp_header_t *header=is_rtp?(rtp_header_t*)m->b_rptr:NULL;
rtp_header_t *rtp_header=is_rtp?(rtp_header_t*)m->b_rptr:NULL;
rtcp_common_header_t *rtcp_header=!is_rtp?(rtcp_common_header_t*)m->b_rptr:NULL;
slen=msgdsize(m);
/*only encrypt real RTP packets*/
if (!is_rtp||(slen>RTP_FIXED_HEADER_SIZE && header->version==2)){
if (rtp_header && (slen>RTP_FIXED_HEADER_SIZE && rtp_header->version==2)) {
/* enlarge the buffer for srtp to write its data */
msgpullup(m,slen+SRTP_PAD_BYTES);
err=is_rtp?srtp_protect(srtp,m->b_rptr,&slen):srtp_protect_rtcp(srtp,m->b_rptr,&slen);
if (err==err_status_ok){
return slen;
}
ortp_error("srtp_protect%s() failed (%d)", is_rtp?"":"_rtcp", err);
}else if (is_rtp){
err=srtp_protect(srtp,m->b_rptr,&slen);
} else if (rtcp_header && (slen>RTP_FIXED_HEADER_SIZE && rtcp_header->version==2)) {
/* enlarge the buffer for srtp to write its data */
msgpullup(m,slen+SRTP_PAD_BYTES);
err=srtp_protect_rtcp(srtp,m->b_rptr,&slen);
} else {
/*ignoring non rtp/rtcp packets*/
return slen;
}
if (err==err_status_ok){
return slen;
}
ortp_error("srtp_protect%s() failed (%d)", is_rtp?"":"_rtcp", err);
return -1;
}
......@@ -72,20 +79,6 @@ static int srtp_process_on_send(RtpTransportModifier *t, mblk_t *m){
static int srtcp_process_on_send(RtpTransportModifier *t, mblk_t *m){
return _process_on_send(t->session,(srtp_t)t->data, m,FALSE);
}
static int _sendto(RtpTransport *t, mblk_t *m, int flags, const struct sockaddr *to, socklen_t tolen, bool_t is_rtp){
int slen=_process_on_send(t->session,(srtp_t)t->data, m,is_rtp);
if (slen>=0){
return sendto(is_rtp?t->session->rtp.gs.socket:t->session->rtcp.gs.socket,(void*)m->b_rptr,slen,flags,to,tolen);
}
return slen;
}
static int srtp_sendto(RtpTransport *t, mblk_t *m, int flags, const struct sockaddr *to, socklen_t tolen){
return _sendto(t,m,flags,to,tolen,TRUE);
}
static int srtcp_sendto(RtpTransport *t, mblk_t *m, int flags, const struct sockaddr *to, socklen_t tolen){
return _sendto(t,m,flags,to,tolen,FALSE);
}
static srtp_stream_ctx_t * find_other_ssrc(srtp_t srtp, uint32_t ssrc){
srtp_stream_ctx_t *stream;
......@@ -148,20 +141,6 @@ static int srtp_process_on_receive(RtpTransportModifier *t, mblk_t *m){
static int srtcp_process_on_receive(RtpTransportModifier *t, mblk_t *m){
return _process_on_receive(t->session,(srtp_t)t->data, m,FALSE,msgdsize(m));
}
static int _recvfrom(RtpTransport *t, mblk_t *m, int flags, struct sockaddr *from, socklen_t *fromlen,bool_t is_rtp){
int err=rtp_session_rtp_recv_abstract(is_rtp?t->session->rtp.gs.socket:t->session->rtcp.gs.socket,m,flags,from,fromlen);
if (err>0) {
return _process_on_receive(t->session, (srtp_t)t->data,m, is_rtp, err);
}
return err;
}
static int srtp_recvfrom(RtpTransport *t, mblk_t *m, int flags, struct sockaddr *from, socklen_t *fromlen){
return _recvfrom(t,m,flags,from,fromlen,TRUE);
}
static int srtcp_recvfrom(RtpTransport *t, mblk_t *m, int flags, struct sockaddr *from, socklen_t *fromlen){
return _recvfrom(t,m,flags,from,fromlen,FALSE);
}
ortp_socket_t srtp_getsocket(RtpTransport *t)
{
......@@ -173,33 +152,6 @@ ortp_socket_t srtcp_getsocket(RtpTransport *t)
return t->session->rtcp.gs.socket;
}
/**
* Creates a pair of Secure-RTP/Secure-RTCP RtpTransport's.
* oRTP relies on libsrtp (see http://srtp.sf.net ) for secure RTP encryption.
* This function creates a RtpTransport object to be used to the RtpSession using
* rtp_session_set_transport().
* @srtp: the srtp_t session to be used
*
**/
int srtp_transport_new(srtp_t srtp, RtpTransport **rtpt, RtpTransport **rtcpt ){
if (rtpt) {
(*rtpt)=ortp_new0(RtpTransport,1);
(*rtpt)->data=srtp;
(*rtpt)->t_getsocket=srtp_getsocket;
(*rtpt)->t_sendto=srtp_sendto;
(*rtpt)->t_recvfrom=srtp_recvfrom;
(*rtpt)->t_destroy=srtp_transport_destroy;
}
if (rtcpt) {
(*rtcpt)=ortp_new0(RtpTransport,1);
(*rtcpt)->data=srtp;
(*rtcpt)->t_getsocket=srtcp_getsocket;
(*rtcpt)->t_sendto=srtcp_sendto;
(*rtcpt)->t_recvfrom=srtcp_recvfrom;
(*rtcpt)->t_destroy=srtp_transport_destroy;
}
return 0;
}
void srtp_transport_destroy(RtpTransport *tp){
ortp_free(tp);
......
......@@ -38,6 +38,17 @@
#endif
#endif
/**
* #RtpTransport object which can handle multiples security protocols. You can for instance use this object
* to use both sRTP and tunnel transporter. #mblk_t messages received and sent from the endpoint
* will pass through the list of modifiers given. First modifier in list will be first to modify the message
* in send mode and last in receive mode.
* @param[in] is_rtp Whether this object will be used for RTP packets or not.
* @param[in] endpoint #RtpTransport object in charge of sending/receiving packets. If NULL, it will use standards sendto and recvfrom functions.
* @param[in] modifiers_count number of #RtpModifier object given in the variadic list. Must be 0 if none are given.
* @returns #RtpTransport object that will be generated or NULL.
**/
RtpTransport* meta_rtp_transport_new(bool_t is_rtp, RtpTransport *endpoint, unsigned modifiers_count, ...);
/* this function initialize all session parameter's that depend on the payload type */
......@@ -289,6 +300,10 @@ rtp_session_init (RtpSession * session, int mode)
session->permissive=FALSE;
session->reuseaddr=TRUE;
msgb_allocator_init(&session->allocator);
/*set default rtptransport*/
rtp_session_set_transports( session
,meta_rtp_transport_new(TRUE,NULL, 0)
,meta_rtp_transport_new(FALSE,NULL, 0));
}
......@@ -1445,6 +1460,8 @@ static void ortp_stream_uninit(OrtpStream *os){
void rtp_session_uninit (RtpSession * session)
{
RtpTransport *rtp_meta_transport = NULL;
RtpTransport *rtcp_meta_transport = NULL;
/* first of all remove the session from the scheduler */
if (session->flags & RTP_SESSION_SCHEDULED)
{
......@@ -1474,6 +1491,12 @@ void rtp_session_uninit (RtpSession * session)
if (session->net_sim_ctx)
ortp_network_simulator_destroy(session->net_sim_ctx);
rtp_session_get_transports(session,&rtp_meta_transport,&rtcp_meta_transport);
if (rtp_meta_transport)
meta_rtp_transport_destroy(rtp_meta_transport);
if (rtcp_meta_transport)
meta_rtp_transport_destroy(rtcp_meta_transport);
#if (_WIN32_WINNT >= 0x0600) && WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
if (session->rtp.QoSFlowID != 0)
{
......@@ -2027,12 +2050,9 @@ int meta_rtp_transport_sendto(RtpTransport *t, mblk_t *msg , int flags, const st
/**
* allow a modifier to inject a packet wich will be treated by successive modifiers
*/
int meta_rtp_transport_modifier_inject_packet(RtpTransport *t, RtpTransportModifier *tpm, mblk_t *msg , int flags) {
int prev_ret,ret;
OList *elem;
int meta_rtp_transport_modifier_inject_packet(const RtpTransport *t, RtpTransportModifier *tpm, mblk_t *msg , int flags) {
struct sockaddr *to;
socklen_t tolen;
bool_t packetInjected = FALSE;
MetaRtpTransportImpl *m = (MetaRtpTransportImpl*)t->data;
if (!m->has_set_session){
......@@ -2042,6 +2062,20 @@ int meta_rtp_transport_modifier_inject_packet(RtpTransport *t, RtpTransportModif
/* get back socket from transport session */
to=(struct sockaddr*)&t->session->rtp.gs.rem_addr;
tolen=t->session->rtp.gs.rem_addrlen;
return meta_rtp_transport_modifier_inject_packet_to(t,tpm,msg,flags,to,tolen);
}
/**
* allow a modifier to inject a packet wich will be treated by successive modifiers
*/
int meta_rtp_transport_modifier_inject_packet_to(const RtpTransport *t, RtpTransportModifier *tpm, mblk_t *msg , int flags,const struct sockaddr *to, socklen_t tolen) {
int prev_ret,ret;
OList *elem;
bool_t packetInjected = tpm?FALSE:TRUE; /*if no modifier, start from the begening*/
MetaRtpTransportImpl *m = (MetaRtpTransportImpl*)t->data;
if (!m->has_set_session){
meta_rtp_set_session(t->session,m);
}
prev_ret=msgdsize(msg);
for (elem=m->modifiers;elem!=NULL;elem=o_list_next(elem)){
......@@ -2124,22 +2158,19 @@ void meta_rtp_transport_close(RtpTransport *t, void *user_data) {
}
}
int meta_rtp_transport_new(RtpTransport **t, bool_t is_rtp, RtpTransport *endpoint, unsigned modifiers_count, ...) {
RtpTransport* meta_rtp_transport_new(bool_t is_rtp, RtpTransport *endpoint, unsigned modifiers_count, ...) {
va_list arguments;
MetaRtpTransportImpl *m;
RtpTransport *t = ortp_new0(RtpTransport,1);
if (!t){
return 1;
}
(*t)=ortp_new0(RtpTransport,1);
m=(*t)->data=ortp_new0(MetaRtpTransportImpl,1);
t=ortp_new0(RtpTransport,1);
m=t->data=ortp_new0(MetaRtpTransportImpl,1);
(*t)->t_getsocket=meta_rtp_transport_getsocket;
(*t)->t_sendto=meta_rtp_transport_sendto;
(*t)->t_recvfrom=meta_rtp_transport_recvfrom;
(*t)->t_close=meta_rtp_transport_close;
(*t)->t_destroy=meta_rtp_transport_destroy;
t->t_getsocket=meta_rtp_transport_getsocket;
t->t_sendto=meta_rtp_transport_sendto;
t->t_recvfrom=meta_rtp_transport_recvfrom;
t->t_close=meta_rtp_transport_close;
t->t_destroy=meta_rtp_transport_destroy;
m->is_rtp=is_rtp;
m->endpoint=endpoint;
......@@ -2150,7 +2181,18 @@ int meta_rtp_transport_new(RtpTransport **t, bool_t is_rtp, RtpTransport *endpoi
}
va_end(arguments);
return -1;
return t;
}
RtpTransport* meta_rtp_transport_get_endpoint(const RtpTransport *transport) {
return transport->data ? ((MetaRtpTransportImpl *)transport->data)->endpoint:NULL;
}
void meta_rtp_transport_set_endpoint(RtpTransport *transport,RtpTransport *endpoint) {
if (transport->data) {
((MetaRtpTransportImpl *)transport->data)->endpoint=endpoint;
} else
ortp_error("Cannot set endpoint [%p] on rtp transport [%p]",transport,endpoint);
}
void meta_rtp_transport_destroy(RtpTransport *tp) {
......
......@@ -904,7 +904,7 @@ void rtp_session_set_transports(RtpSession *session, struct _RtpTransport *rtptr
else session->flags&=~(RTP_SESSION_USING_TRANSPORT);
}
void rtp_session_get_transports(RtpSession *session, RtpTransport **rtptr, RtpTransport **rtcptr){
void rtp_session_get_transports(const RtpSession *session, RtpTransport **rtptr, RtpTransport **rtcptr){
if (rtptr) *rtptr=session->rtp.gs.tr;
if (rtcptr) *rtcptr=session->rtcp.gs.tr;
}
......
......@@ -77,4 +77,9 @@ void rtp_session_send_regular_rtcp_packet_and_reschedule(RtpSession *session, ui
void rtp_session_send_fb_rtcp_packet_and_reschedule(RtpSession *session);
void ortp_stream_clear_aux_addresses(OrtpStream *os);
/*
* no more public, use modifier instead
* */
void rtp_session_set_transports(RtpSession *session, RtpTransport *rtptr, RtpTransport *rtcptr);
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment