From 05f0317acf1c81fc93d08a9e9790b998a361477c Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Mon, 11 Apr 2016 08:52:36 -0400 Subject: [PATCH 1/2] fix the 'media address' parameter address family string in SDP was not produced when used Change-Id: I33f23a8f3d600ecdb9b469368ac5a8929e4b2fa1 --- daemon/sdp.c | 4 +++- utils/ng-client | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/daemon/sdp.c b/daemon/sdp.c index 4b03276fe..34f684849 100644 --- a/daemon/sdp.c +++ b/daemon/sdp.c @@ -1482,7 +1482,9 @@ static int replace_network_address(struct sdp_chopper *chop, struct network_addr __parse_address(&flags->parsed_media_address, NULL, NULL, &flags->media_address); if (!is_addr_unspecified(&flags->parsed_media_address)) - len = sprintf(buf, "%s", sockaddr_print_buf(&flags->parsed_media_address)); + len = sprintf(buf, "%s %s", + flags->parsed_media_address.family->rfc_name, + sockaddr_print_buf(&flags->parsed_media_address)); else call_stream_address46(buf, ps, SAF_NG, &len, NULL); chopper_append_dup(chop, buf, len); diff --git a/utils/ng-client b/utils/ng-client index c69512fab..45560d677 100755 --- a/utils/ng-client +++ b/utils/ng-client @@ -44,13 +44,14 @@ GetOptions( 'delete-delay=i' => \$options{'delete-delay'}, 'reset' => \$options{'reset'}, 'port-latching' => \$options{'port latching'}, + 'media-address=s' => \$options{'media address'}, ) or die; my $cmd = shift(@ARGV) or die; my %packet = (command => $cmd); -for my $x (split(',', 'from-tag,to-tag,call-id,transport protocol,media address,ICE,address family,TOS,DTLS,via-branch,delete-delay')) { +for my $x (split(',', 'from-tag,to-tag,call-id,transport protocol,media address,ICE,address family,TOS,DTLS,via-branch,delete-delay,media address')) { defined($options{$x}) and $packet{$x} = $options{$x}; } for my $x (split(',', 'trust address,symmetric,asymmetric,force,strict source,media handover,sip source address,reset,port latching')) { From 0206f09b9302a651d5ce46ad027715e7476dee81 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Mon, 11 Apr 2016 11:12:56 -0400 Subject: [PATCH 2/2] fix obj-debug stuff required moving includes/headers around to avoid circular dependencies Change-Id: Ia43e3254f252f94ec387be6b9c85fce4e727b251 --- daemon/aux.h | 30 +++++++++---------- daemon/call.c | 1 + daemon/call.h | 24 +++++++-------- daemon/cli.c | 2 ++ daemon/control_ng.c | 3 ++ daemon/control_tcp.c | 1 + daemon/control_udp.c | 1 + daemon/ice.c | 2 ++ daemon/ice.h | 6 +++- daemon/log.h | 69 +++++-------------------------------------- daemon/log_funcs.h | 69 +++++++++++++++++++++++++++++++++++++++++++ daemon/media_socket.c | 2 ++ daemon/obj.h | 18 +++++------ daemon/redis.c | 1 + daemon/rtcp.c | 1 + 15 files changed, 132 insertions(+), 98 deletions(-) create mode 100644 daemon/log_funcs.h diff --git a/daemon/aux.h b/daemon/aux.h index ac4710947..6d9f46146 100644 --- a/daemon/aux.h +++ b/daemon/aux.h @@ -312,60 +312,60 @@ INLINE int __cond_timedwait_tv(cond_t *c, mutex_t *m, const struct timeval *tv) INLINE int __debug_mutex_init(mutex_t *m, const char *file, unsigned int line) { - mylog(LOG_DEBUG, "mutex_init(%p) at %s:%u", m, file, line); + write_log(LOG_DEBUG, "mutex_init(%p) at %s:%u", m, file, line); return pthread_mutex_init(m, NULL); } INLINE int __debug_mutex_destroy(mutex_t *m, const char *file, unsigned int line) { - mylog(LOG_DEBUG, "mutex_destroy(%p) at %s:%u", m, file, line); + write_log(LOG_DEBUG, "mutex_destroy(%p) at %s:%u", m, file, line); return pthread_mutex_destroy(m); } INLINE int __debug_mutex_lock(mutex_t *m, const char *file, unsigned int line) { int ret; - mylog(LOG_DEBUG, "mutex_lock(%p) at %s:%u ...", m, file, line); + write_log(LOG_DEBUG, "mutex_lock(%p) at %s:%u ...", m, file, line); ret = pthread_mutex_lock(m); - mylog(LOG_DEBUG, "mutex_lock(%p) at %s:%u returning %i", m, file, line, ret); + write_log(LOG_DEBUG, "mutex_lock(%p) at %s:%u returning %i", m, file, line, ret); return ret; } INLINE int __debug_mutex_trylock(mutex_t *m, const char *file, unsigned int line) { int ret; - mylog(LOG_DEBUG, "mutex_trylock(%p) at %s:%u ...", m, file, line); + write_log(LOG_DEBUG, "mutex_trylock(%p) at %s:%u ...", m, file, line); ret = pthread_mutex_trylock(m); - mylog(LOG_DEBUG, "mutex_trylock(%p) at %s:%u returning %i", m, file, line, ret); + write_log(LOG_DEBUG, "mutex_trylock(%p) at %s:%u returning %i", m, file, line, ret); return ret; } INLINE int __debug_mutex_unlock(mutex_t *m, const char *file, unsigned int line) { - mylog(LOG_DEBUG, "mutex_unlock(%p) at %s:%u", m, file, line); + write_log(LOG_DEBUG, "mutex_unlock(%p) at %s:%u", m, file, line); return pthread_mutex_unlock(m); } INLINE int __debug_rwlock_init(rwlock_t *m, const char *file, unsigned int line) { - mylog(LOG_DEBUG, "rwlock_init(%p) at %s:%u", m, file, line); + write_log(LOG_DEBUG, "rwlock_init(%p) at %s:%u", m, file, line); return pthread_rwlock_init(m, NULL); } INLINE int __debug_rwlock_destroy(rwlock_t *m, const char *file, unsigned int line) { - mylog(LOG_DEBUG, "rwlock_destroy(%p) at %s:%u", m, file, line); + write_log(LOG_DEBUG, "rwlock_destroy(%p) at %s:%u", m, file, line); return pthread_rwlock_destroy(m); } INLINE int __debug_rwlock_lock_r(rwlock_t *m, const char *file, unsigned int line) { int ret; - mylog(LOG_DEBUG, "rwlock_lock_r(%p) at %s:%u ...", m, file, line); + write_log(LOG_DEBUG, "rwlock_lock_r(%p) at %s:%u ...", m, file, line); ret = pthread_rwlock_rdlock(m); - mylog(LOG_DEBUG, "rwlock_lock_r(%p) at %s:%u returning %i", m, file, line, ret); + write_log(LOG_DEBUG, "rwlock_lock_r(%p) at %s:%u returning %i", m, file, line, ret); return ret; } INLINE int __debug_rwlock_lock_w(rwlock_t *m, const char *file, unsigned int line) { int ret; - mylog(LOG_DEBUG, "rwlock_lock_w(%p) at %s:%u ...", m, file, line); + write_log(LOG_DEBUG, "rwlock_lock_w(%p) at %s:%u ...", m, file, line); ret = pthread_rwlock_wrlock(m); - mylog(LOG_DEBUG, "rwlock_lock_w(%p) at %s:%u returning %i", m, file, line, ret); + write_log(LOG_DEBUG, "rwlock_lock_w(%p) at %s:%u returning %i", m, file, line, ret); return ret; } INLINE int __debug_rwlock_unlock_r(rwlock_t *m, const char *file, unsigned int line) { - mylog(LOG_DEBUG, "rwlock_unlock_r(%p) at %s:%u", m, file, line); + write_log(LOG_DEBUG, "rwlock_unlock_r(%p) at %s:%u", m, file, line); return pthread_rwlock_unlock(m); } INLINE int __debug_rwlock_unlock_w(rwlock_t *m, const char *file, unsigned int line) { - mylog(LOG_DEBUG, "rwlock_unlock_w(%p) at %s:%u", m, file, line); + write_log(LOG_DEBUG, "rwlock_unlock_w(%p) at %s:%u", m, file, line); return pthread_rwlock_unlock(m); } diff --git a/daemon/call.c b/daemon/call.c index 2c897bd10..79f0997a8 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -35,6 +35,7 @@ #include "call_interfaces.h" #include "ice.h" #include "rtpengine_config.h" +#include "log_funcs.h" diff --git a/daemon/call.h b/daemon/call.h index 321424c20..8f49aba40 100644 --- a/daemon/call.h +++ b/daemon/call.h @@ -15,10 +15,7 @@ #include #include #include "compat.h" -#include "control_ng.h" -#include "aux.h" #include "socket.h" -#include "media_socket.h" #define TRUNCATED " ... Output truncated. Increase Output Buffer ... \n" @@ -80,15 +77,6 @@ enum call_stream_state { CSS_RUNNING, }; -#include "obj.h" -#include "aux.h" -#include "bencode.h" -#include "str.h" -#include "crypto.h" -#include "dtls.h" -#include "rtp.h" - - #define ERROR_NO_FREE_PORTS -100 #define ERROR_NO_FREE_LOGS -101 @@ -195,6 +183,12 @@ enum call_stream_state { +#include "obj.h" +#include "bencode.h" +#include "crypto.h" +#include "dtls.h" + + struct poller; struct control_stream; struct call; @@ -527,6 +521,12 @@ void __payload_type_free(void *p); void __rtp_stats_update(GHashTable *dst, GHashTable *src); + +#include "str.h" +#include "rtp.h" + + + INLINE void *call_malloc(struct call *c, size_t l) { void *ret; mutex_lock(&c->buffer_lock); diff --git a/daemon/cli.c b/daemon/cli.c index 68bfe9967..02038bd00 100644 --- a/daemon/cli.c +++ b/daemon/cli.c @@ -14,6 +14,8 @@ #include "call.h" #include "cli.h" #include "socket.h" +#include "control_ng.h" +#include "media_socket.h" #include "rtpengine_config.h" diff --git a/daemon/control_ng.c b/daemon/control_ng.c index 31d924c11..ca77e8182 100644 --- a/daemon/control_ng.c +++ b/daemon/control_ng.c @@ -12,6 +12,9 @@ #include "sdp.h" #include "call_interfaces.h" #include "socket.h" +#include "log_funcs.h" + + static void timeval_update_request_time(struct request_time *request, const struct timeval *offer_diff) { // lock offers diff --git a/daemon/control_tcp.c b/daemon/control_tcp.c index e21d6b2f2..bbbdba5a4 100644 --- a/daemon/control_tcp.c +++ b/daemon/control_tcp.c @@ -17,6 +17,7 @@ #include "call.h" #include "call_interfaces.h" #include "socket.h" +#include "log_funcs.h" diff --git a/daemon/control_udp.c b/daemon/control_udp.c index 48ffa337a..0cf4eeee4 100644 --- a/daemon/control_udp.c +++ b/daemon/control_udp.c @@ -18,6 +18,7 @@ #include "udp_listener.h" #include "call_interfaces.h" #include "socket.h" +#include "log_funcs.h" static void control_udp_incoming(struct obj *obj, str *buf, const endpoint_t *sin, char *addr, diff --git a/daemon/ice.c b/daemon/ice.c index c822b4782..1243610a2 100644 --- a/daemon/ice.c +++ b/daemon/ice.c @@ -8,6 +8,8 @@ #include "log.h" #include "obj.h" #include "stun.h" +#include "poller.h" +#include "log_funcs.h" diff --git a/daemon/ice.h b/daemon/ice.h index e3c7d790e..660333164 100644 --- a/daemon/ice.h +++ b/daemon/ice.h @@ -10,7 +10,6 @@ #include "str.h" #include "obj.h" #include "aux.h" -#include "call.h" #include "media_socket.h" #include "socket.h" @@ -163,6 +162,11 @@ int ice_request(struct stream_fd *, const endpoint_t *, struct stun_attrs *); int ice_response(struct stream_fd *, const endpoint_t *src, struct stun_attrs *attrs, u_int32_t transaction[3]); + + +#include "call.h" + + /* returns 0 if ICE still has work to do, 1 otherwise */ INLINE int ice_has_finished(struct call_media *media) { if (!media) diff --git a/daemon/log.h b/daemon/log.h index 91f93620c..9a7be2787 100644 --- a/daemon/log.h +++ b/daemon/log.h @@ -9,14 +9,18 @@ +struct call; +struct stream_fd; +struct ice_agent; + struct log_info { union { - const struct call *call; - const struct stream_fd *stream_fd; + struct call *call; + struct stream_fd *stream_fd; const str *str; const char *cstr; - const struct ice_agent *ice_agent; - const void *ptr; + struct ice_agent *ice_agent; + void *ptr; } u; enum { LOG_INFO_NONE = 0, @@ -73,68 +77,11 @@ void cdrlog(const char* cdrbuffer); void rtcplog(const char* cdrbuffer); -#include "obj.h" - -INLINE void log_info_clear() { - switch (log_info.e) { - case LOG_INFO_NONE: - return; - case LOG_INFO_CALL: - case LOG_INFO_STREAM_FD: - case LOG_INFO_ICE_AGENT: - __obj_put((void *) log_info.u.ptr); - break; - case LOG_INFO_STR: - case LOG_INFO_C_STRING: - break; - } - log_info.e = LOG_INFO_NONE; - log_info.u.ptr = NULL; -} -INLINE void log_info_call(const struct call *c) { - log_info_clear(); - if (!c) - return; - log_info.e = LOG_INFO_CALL; - log_info.u.call = __obj_get((void *) c); -} -INLINE void log_info_stream_fd(const struct stream_fd *sfd) { - log_info_clear(); - if (!sfd) - return; - log_info.e = LOG_INFO_STREAM_FD; - log_info.u.stream_fd = __obj_get((void *) sfd); -} -INLINE void log_info_str(const str *s) { - log_info_clear(); - if (!s || !s->s) - return; - log_info.e = LOG_INFO_STR; - log_info.u.str = s; -} -INLINE void log_info_c_string(const char *s) { - log_info_clear(); - if (!s) - return; - log_info.e = LOG_INFO_C_STRING; - log_info.u.cstr = s; -} -INLINE void log_info_ice_agent(const struct ice_agent *ag) { - log_info_clear(); - if (!ag) - return; - log_info.e = LOG_INFO_ICE_AGENT; - log_info.u.ice_agent = __obj_get((void *) ag); -} INLINE int get_log_level(void) { return g_atomic_int_get(&log_level); } - - - - #define LOG_ERROR LOG_ERR #define LOG_WARN LOG_WARNING diff --git a/daemon/log_funcs.h b/daemon/log_funcs.h new file mode 100644 index 000000000..87f62481e --- /dev/null +++ b/daemon/log_funcs.h @@ -0,0 +1,69 @@ +#ifndef __LOG_FUNCS_H__ +#define __LOG_FUNCS_H__ + +#include "aux.h" +#include "obj.h" +#include "call.h" +#include "media_socket.h" +#include "ice.h" + +INLINE void log_info_clear() { + switch (log_info.e) { + case LOG_INFO_NONE: + return; + case LOG_INFO_CALL: + obj_put(log_info.u.call); + break; + case LOG_INFO_STREAM_FD: + obj_put(log_info.u.stream_fd); + break; + case LOG_INFO_ICE_AGENT: + obj_put(log_info.u.ice_agent); + break; + case LOG_INFO_STR: + case LOG_INFO_C_STRING: + break; + } + log_info.e = LOG_INFO_NONE; + log_info.u.ptr = NULL; +} +INLINE void log_info_call(struct call *c) { + log_info_clear(); + if (!c) + return; + log_info.e = LOG_INFO_CALL; + log_info.u.call = obj_get(c); +} +INLINE void log_info_stream_fd(struct stream_fd *sfd) { + log_info_clear(); + if (!sfd) + return; + log_info.e = LOG_INFO_STREAM_FD; + log_info.u.stream_fd = obj_get(sfd); +} +INLINE void log_info_str(const str *s) { + log_info_clear(); + if (!s || !s->s) + return; + log_info.e = LOG_INFO_STR; + log_info.u.str = s; +} +INLINE void log_info_c_string(const char *s) { + log_info_clear(); + if (!s) + return; + log_info.e = LOG_INFO_C_STRING; + log_info.u.cstr = s; +} +INLINE void log_info_ice_agent(struct ice_agent *ag) { + log_info_clear(); + if (!ag) + return; + log_info.e = LOG_INFO_ICE_AGENT; + log_info.u.ice_agent = obj_get(ag); +} + + + + +#endif diff --git a/daemon/media_socket.c b/daemon/media_socket.c index 202c1229f..8a5cc27cd 100644 --- a/daemon/media_socket.c +++ b/daemon/media_socket.c @@ -15,6 +15,8 @@ #include "rtcp.h" #include "sdp.h" #include "aux.h" +#include "log_funcs.h" +#include "poller.h" diff --git a/daemon/obj.h b/daemon/obj.h index be74922db..cc07b0f59 100644 --- a/daemon/obj.h +++ b/daemon/obj.h @@ -59,11 +59,11 @@ INLINE void *__obj_alloc(unsigned int size, void (*free_func)(void *), INLINE void *__obj_alloc0(unsigned int size, void (*free_func)(void *), const char *type, const char *file, unsigned int line); INLINE struct obj *__obj_hold(struct obj *o, - const char *type, const char *file, unsigned int line); + const char *file, unsigned int line); INLINE void *__obj_get(struct obj *o, - const char *type, const char *file, unsigned int line); -INLINE void __obj_put(struct obj *o,, - const char *type, const char *file, unsigned int line); + const char *file, unsigned int line); +INLINE void __obj_put(struct obj *o, + const char *file, unsigned int line); #else @@ -99,7 +99,7 @@ INLINE void __obj_init(struct obj *o, unsigned int size, void (*free_func)(void #if OBJ_DEBUG o->magic = OBJ_MAGIC; o->type = strdup(type); - mylog(LOG_DEBUG, "obj_allocX(\"%s\") -> %p [%s:%u]", type, o, file, line); + write_log(LOG_DEBUG, "obj_allocX(\"%s\") -> %p [%s:%u]", type, o, file, line); #endif o->ref = 1; o->free_func = free_func; @@ -145,12 +145,12 @@ INLINE struct obj *__obj_hold(struct obj *o ) { #if OBJ_DEBUG assert(o->magic == OBJ_MAGIC); - mylog(LOG_DEBUG, "obj_hold(%p, \"%s\"), refcnt before %u [%s:%u]", + write_log(LOG_DEBUG, "obj_hold(%p, \"%s\"), refcnt before %u [%s:%u]", o, o->type, g_atomic_int_get(&o->ref), file, line); #endif g_atomic_int_inc(&o->ref); #if OBJ_DEBUG - mylog(LOG_DEBUG, "obj_hold(%p, \"%s\"), refcnt after %u [%s:%u]", + write_log(LOG_DEBUG, "obj_hold(%p, \"%s\"), refcnt after %u [%s:%u]", o, o->type, g_atomic_int_get(&o->ref), file, line); #endif return o; @@ -175,13 +175,13 @@ INLINE void __obj_put(struct obj *o ) { #if OBJ_DEBUG assert(o->magic == OBJ_MAGIC); - mylog(LOG_DEBUG, "obj_put(%p, \"%s\"), refcnt before %u [%s:%u]", + write_log(LOG_DEBUG, "obj_put(%p, \"%s\"), refcnt before %u [%s:%u]", o, o->type, g_atomic_int_get(&o->ref), file, line); #endif if (!g_atomic_int_dec_and_test(&o->ref)) return; #if OBJ_DEBUG - mylog(LOG_DEBUG, "obj_put(%p, \"%s\"), refcnt after %u [%s:%u]", + write_log(LOG_DEBUG, "obj_put(%p, \"%s\"), refcnt after %u [%s:%u]", o, o->type, g_atomic_int_get(&o->ref), file, line); free(o->type); #endif diff --git a/daemon/redis.c b/daemon/redis.c index d0ba67c33..76ccaabaa 100644 --- a/daemon/redis.c +++ b/daemon/redis.c @@ -14,6 +14,7 @@ #include "str.h" #include "crypto.h" #include "dtls.h" +#include "log_funcs.h" diff --git a/daemon/rtcp.c b/daemon/rtcp.c index 5380f8511..fe3244d1a 100644 --- a/daemon/rtcp.c +++ b/daemon/rtcp.c @@ -13,6 +13,7 @@ #include "crypto.h" #include "rtcp_xr.h" #include "homer.h" +#include "media_socket.h"