diff options
-rw-r--r-- | CHANGES | 16 | ||||
-rw-r--r-- | UPGRADE.txt | 7 | ||||
-rw-r--r-- | apps/app_queue.c | 28 | ||||
-rw-r--r-- | apps/confbridge/confbridge_manager.c | 2 | ||||
-rw-r--r-- | channels/chan_sip.c | 139 | ||||
-rw-r--r-- | channels/chan_skinny.c | 9 | ||||
-rw-r--r-- | channels/sip/include/sip.h | 3 | ||||
-rw-r--r-- | configs/samples/pjsip.conf.sample | 11 | ||||
-rw-r--r-- | configs/samples/sip.conf.sample | 2 | ||||
-rw-r--r-- | contrib/ast-db-manage/config/versions/15db7b91a97a_add_rtcp_mux.py | 1 | ||||
-rw-r--r-- | contrib/ast-db-manage/config/versions/f638dbe2eb23_symmetric_transport.py | 32 | ||||
-rw-r--r-- | include/asterisk/network.h | 5 | ||||
-rw-r--r-- | include/asterisk/res_pjsip.h | 80 | ||||
-rw-r--r-- | main/http.c | 3 | ||||
-rw-r--r-- | main/manager.c | 4 | ||||
-rw-r--r-- | res/res_pjsip.c | 141 | ||||
-rw-r--r-- | res/res_pjsip/config_transport.c | 22 | ||||
-rw-r--r-- | res/res_pjsip/pjsip_message_ip_updater.c | 83 | ||||
-rw-r--r-- | res/res_pjsip_pubsub.c | 46 | ||||
-rw-r--r-- | res/res_pjsip_sdp_rtp.c | 16 | ||||
-rw-r--r-- | res/res_pjsip_session.c | 34 | ||||
-rw-r--r-- | res/res_rtp_asterisk.c | 12 |
22 files changed, 537 insertions, 159 deletions
@@ -118,6 +118,22 @@ app_voicemail * Added 'fromstring' field to the voicemail boxes. If set, it will override the global 'fromstring' field on a per-mailbox basis. +res_pjsip +------------------ + * A new transport parameter 'symmetric_transport' has been added. + When a request from a dynamic contact comes in on a transport with this + option set to 'yes', the transport name will be saved and used for + subsequent outgoing requests like OPTIONS, NOTIFY and INVITE. It's + saved as a contact uri parameter named 'x-ast-txp' and will display with + the contact uri in CLI, AMI, and ARI output. On the outgoing request, + if a transport wasn't explicitly set on the endpoint AND the request URI + is not a hostname, the saved transport will be used and the 'x-ast-txp' + parameter stripped from the outgoing packet. To facilitate recreation of + subscriptions on asterisk restart, a new column 'contact_uri' needed to be + added to the ps_subcsription_persistence table. Since new columns were + added to both transport and subscription_persistence, an alembic upgrade + should be run to bring the database tables up to date. + res_pjsip_transport_websocket ------------------ * Removed non-secure websocket support. Firefox and Chrome have not allowed diff --git a/UPGRADE.txt b/UPGRADE.txt index 2275580ca..1afacf2a4 100644 --- a/UPGRADE.txt +++ b/UPGRADE.txt @@ -27,9 +27,10 @@ From 14.3.0 to 14.4.0: res_rtp_asterisk: - The RTP layer of Asterisk now has support for RFC 5761: "Multiplexing RTP - Data and Control Packets on a Single Port." So far, the only channel driver - that supports this feature is chan_pjsip. You can set "rtcp_mux = yes" on - a PJSIP endpoint in pjsip.conf to enable the feature. + Data and Control Packets on a Single Port." For the PJSIP channel driver, + chan_pjsip, you can set "rtcp_mux = yes" on a PJSIP endpoint in pjsip.conf + to enable the feature. For chan_sip you can set "rtcp_mux = yes" either + globally or on a per-peer basis in sip.conf. New in 14.0.0 diff --git a/apps/app_queue.c b/apps/app_queue.c index c0de00173..3886b7c7a 100644 --- a/apps/app_queue.c +++ b/apps/app_queue.c @@ -5948,6 +5948,7 @@ static void handle_bridge_enter(void *userdata, struct stasis_subscription *sub, { struct queue_stasis_data *queue_data = userdata; struct ast_bridge_blob *enter_blob = stasis_message_data(msg); + SCOPED_AO2LOCK(lock, queue_data); if (queue_data->dying) { return; @@ -6011,7 +6012,7 @@ static void handle_bridge_left(void *userdata, struct stasis_subscription *sub, ast_debug(3, "Detected redirect of queue caller channel %s\n", caller_snapshot->name); - ast_queue_log(queue_data->queue->name, queue_data->caller_uniqueid, queue_data->member->membername, + ast_queue_log(queue_data->queue->name, caller_snapshot->uniqueid, queue_data->member->membername, "COMPLETECALLER", "%ld|%ld|%d", (long) (queue_data->starttime - queue_data->holdstart), (long) (time(NULL) - queue_data->starttime), queue_data->caller_pos); @@ -6047,16 +6048,17 @@ static void handle_blind_transfer(void *userdata, struct stasis_subscription *su RAII_VAR(struct ast_channel_snapshot *, caller_snapshot, NULL, ao2_cleanup); RAII_VAR(struct ast_channel_snapshot *, member_snapshot, NULL, ao2_cleanup); - if (queue_data->dying) { - return; - } - if (transfer_msg->result != AST_BRIDGE_TRANSFER_SUCCESS) { return; } ao2_lock(queue_data); + if (queue_data->dying) { + ao2_unlock(queue_data); + return; + } + if (ast_strlen_zero(queue_data->bridge_uniqueid) || strcmp(queue_data->bridge_uniqueid, transfer_msg->bridge->uniqueid)) { ao2_unlock(queue_data); @@ -6104,10 +6106,6 @@ static void handle_attended_transfer(void *userdata, struct stasis_subscription RAII_VAR(struct ast_channel_snapshot *, caller_snapshot, NULL, ao2_cleanup); RAII_VAR(struct ast_channel_snapshot *, member_snapshot, NULL, ao2_cleanup); - if (queue_data->dying) { - return; - } - if (atxfer_msg->result != AST_BRIDGE_TRANSFER_SUCCESS || atxfer_msg->dest_type == AST_ATTENDED_TRANSFER_DEST_THREEWAY) { return; @@ -6115,6 +6113,11 @@ static void handle_attended_transfer(void *userdata, struct stasis_subscription ao2_lock(queue_data); + if (queue_data->dying) { + ao2_unlock(queue_data); + return; + } + if (ast_strlen_zero(queue_data->bridge_uniqueid)) { ao2_unlock(queue_data); return; @@ -6298,12 +6301,13 @@ static void handle_hangup(void *userdata, struct stasis_subscription *sub, RAII_VAR(struct ast_channel *, chan, NULL, ao2_cleanup); enum agent_complete_reason reason; + ao2_lock(queue_data); + if (queue_data->dying) { + ao2_unlock(queue_data); return; } - ao2_lock(queue_data); - if (!strcmp(channel_blob->snapshot->uniqueid, queue_data->caller_uniqueid)) { reason = CALLER; } else if (!strcmp(channel_blob->snapshot->uniqueid, queue_data->member_uniqueid)) { @@ -6332,7 +6336,7 @@ static void handle_hangup(void *userdata, struct stasis_subscription *sub, ast_debug(3, "Detected hangup of queue %s channel %s\n", reason == CALLER ? "caller" : "member", channel_blob->snapshot->name); - ast_queue_log(queue_data->queue->name, queue_data->caller_uniqueid, queue_data->member->membername, + ast_queue_log(queue_data->queue->name, caller_snapshot->uniqueid, queue_data->member->membername, reason == CALLER ? "COMPLETECALLER" : "COMPLETEAGENT", "%ld|%ld|%d", (long) (queue_data->starttime - queue_data->holdstart), (long) (time(NULL) - queue_data->starttime), queue_data->caller_pos); diff --git a/apps/confbridge/confbridge_manager.c b/apps/confbridge/confbridge_manager.c index a99362b33..e5db648da 100644 --- a/apps/confbridge/confbridge_manager.c +++ b/apps/confbridge/confbridge_manager.c @@ -189,7 +189,7 @@ </managerEvent> <managerEvent language="en_US" name="ConfbridgeTalking"> <managerEventInstance class="EVENT_FLAG_CALL"> - <synopsis>Raised when a confbridge participant unmutes.</synopsis> + <synopsis>Raised when a confbridge participant begins or ends talking.</synopsis> <syntax> <parameter name="Conference"> <para>The name of the Confbridge conference.</para> diff --git a/channels/chan_sip.c b/channels/chan_sip.c index d158b0dbd..f659a44a3 100644 --- a/channels/chan_sip.c +++ b/channels/chan_sip.c @@ -1216,6 +1216,7 @@ static int process_sdp_o(const char *o, struct sip_pvt *p); static int process_sdp_c(const char *c, struct ast_sockaddr *addr); static int process_sdp_a_sendonly(const char *a, int *sendonly); static int process_sdp_a_ice(const char *a, struct sip_pvt *p, struct ast_rtp_instance *instance); +static int process_sdp_a_rtcp_mux(const char *a, struct sip_pvt *p, int *requested); static int process_sdp_a_dtls(const char *a, struct sip_pvt *p, struct ast_rtp_instance *instance); static int process_sdp_a_audio(const char *a, struct sip_pvt *p, struct ast_rtp_codecs *newaudiortp, int *last_rtpmap_codec); static int process_sdp_a_video(const char *a, struct sip_pvt *p, struct ast_rtp_codecs *newvideortp, int *last_rtpmap_codec); @@ -6011,7 +6012,7 @@ static int dialog_initialize_rtp(struct sip_pvt *dialog) ast_rtp_instance_set_hold_timeout(dialog->vrtp, dialog->rtpholdtimeout); ast_rtp_instance_set_keepalive(dialog->vrtp, dialog->rtpkeepalive); - ast_rtp_instance_set_prop(dialog->vrtp, AST_RTP_PROPERTY_RTCP, 1); + ast_rtp_instance_set_prop(dialog->vrtp, AST_RTP_PROPERTY_RTCP, AST_RTP_INSTANCE_RTCP_STANDARD); ast_rtp_instance_set_qos(dialog->vrtp, global_tos_video, global_cos_video, "SIP VIDEO"); } @@ -6031,14 +6032,14 @@ static int dialog_initialize_rtp(struct sip_pvt *dialog) /* Do not timeout text as its not constant*/ ast_rtp_instance_set_keepalive(dialog->trtp, dialog->rtpkeepalive); - ast_rtp_instance_set_prop(dialog->trtp, AST_RTP_PROPERTY_RTCP, 1); + ast_rtp_instance_set_prop(dialog->trtp, AST_RTP_PROPERTY_RTCP, AST_RTP_INSTANCE_RTCP_STANDARD); } ast_rtp_instance_set_timeout(dialog->rtp, dialog->rtptimeout); ast_rtp_instance_set_hold_timeout(dialog->rtp, dialog->rtpholdtimeout); ast_rtp_instance_set_keepalive(dialog->rtp, dialog->rtpkeepalive); - ast_rtp_instance_set_prop(dialog->rtp, AST_RTP_PROPERTY_RTCP, 1); + ast_rtp_instance_set_prop(dialog->rtp, AST_RTP_PROPERTY_RTCP, AST_RTP_INSTANCE_RTCP_STANDARD); ast_rtp_instance_set_prop(dialog->rtp, AST_RTP_PROPERTY_DTMF, ast_test_flag(&dialog->flags[0], SIP_DTMF) == SIP_DTMF_RFC2833); ast_rtp_instance_set_prop(dialog->rtp, AST_RTP_PROPERTY_DTMF_COMPENSATE, ast_test_flag(&dialog->flags[1], SIP_PAGE2_RFC2833_COMPENSATE)); @@ -7752,6 +7753,15 @@ static int interpret_t38_parameters(struct sip_pvt *p, const struct ast_control_ return res; } +enum sip_media_fds { + SIP_AUDIO_RTP_FD, + SIP_AUDIO_RTCP_FD, + SIP_VIDEO_RTP_FD, + SIP_VIDEO_RTCP_FD, + SIP_TEXT_RTP_FD, + SIP_UDPTL_FD, +}; + /*! * \internal * \brief Create and initialize UDPTL for the specified dialog @@ -7780,7 +7790,7 @@ static int initialize_udptl(struct sip_pvt *p) /* T38 can be supported by this dialog, create it and set the derived properties */ if ((p->udptl = ast_udptl_new_with_bindaddr(sched, io, 0, &bindaddr))) { if (p->owner) { - ast_channel_set_fd(p->owner, 5, ast_udptl_fd(p->udptl)); + ast_channel_set_fd(p->owner, SIP_UDPTL_FD, ast_udptl_fd(p->udptl)); } ast_udptl_setqos(p->udptl, global_tos_audio, global_cos_audio); @@ -8206,20 +8216,28 @@ static struct ast_channel *sip_new(struct sip_pvt *i, int state, const char *tit * UDPTL is created as needed in the lifetime of a dialog, its file * descriptor is set in initialize_udptl */ if (i->rtp) { - ast_channel_set_fd(tmp, 0, ast_rtp_instance_fd(i->rtp, 0)); - ast_channel_set_fd(tmp, 1, ast_rtp_instance_fd(i->rtp, 1)); + ast_channel_set_fd(tmp, SIP_AUDIO_RTP_FD, ast_rtp_instance_fd(i->rtp, 0)); + if (ast_test_flag(&i->flags[2], SIP_PAGE3_RTCP_MUX)) { + ast_channel_set_fd(tmp, SIP_AUDIO_RTCP_FD, -1); + } else { + ast_channel_set_fd(tmp, SIP_AUDIO_RTCP_FD, ast_rtp_instance_fd(i->rtp, 1)); + } ast_rtp_instance_set_write_format(i->rtp, fmt); ast_rtp_instance_set_read_format(i->rtp, fmt); } if (needvideo && i->vrtp) { - ast_channel_set_fd(tmp, 2, ast_rtp_instance_fd(i->vrtp, 0)); - ast_channel_set_fd(tmp, 3, ast_rtp_instance_fd(i->vrtp, 1)); + ast_channel_set_fd(tmp, SIP_VIDEO_RTP_FD, ast_rtp_instance_fd(i->vrtp, 0)); + if (ast_test_flag(&i->flags[2], SIP_PAGE3_RTCP_MUX)) { + ast_channel_set_fd(tmp, SIP_VIDEO_RTCP_FD, -1); + } else { + ast_channel_set_fd(tmp, SIP_VIDEO_RTCP_FD, ast_rtp_instance_fd(i->vrtp, 1)); + } } if (needtext && i->trtp) { - ast_channel_set_fd(tmp, 4, ast_rtp_instance_fd(i->trtp, 0)); + ast_channel_set_fd(tmp, SIP_TEXT_RTP_FD, ast_rtp_instance_fd(i->trtp, 0)); } if (i->udptl) { - ast_channel_set_fd(tmp, 5, ast_udptl_fd(i->udptl)); + ast_channel_set_fd(tmp, SIP_UDPTL_FD, ast_udptl_fd(i->udptl)); } if (state == AST_STATE_RING) { @@ -10074,6 +10092,42 @@ static int has_media_stream(struct sip_pvt *p, enum media_type m) return 0; } +static void configure_rtcp(struct sip_pvt *p, struct ast_rtp_instance *instance, int which, int remote_rtcp_mux) +{ + int local_rtcp_mux = ast_test_flag(&p->flags[2], SIP_PAGE3_RTCP_MUX); + int fd = -1; + + if (local_rtcp_mux && remote_rtcp_mux) { + ast_rtp_instance_set_prop(instance, AST_RTP_PROPERTY_RTCP, AST_RTP_INSTANCE_RTCP_MUX); + } else { + ast_rtp_instance_set_prop(instance, AST_RTP_PROPERTY_RTCP, AST_RTP_INSTANCE_RTCP_STANDARD); + fd = ast_rtp_instance_fd(instance, 1); + } + + if (p->owner) { + ast_channel_set_fd(p->owner, which, fd); + } +} + +static void set_ice_components(struct sip_pvt *p, struct ast_rtp_instance *instance, int remote_rtcp_mux) +{ + struct ast_rtp_engine_ice *ice; + int local_rtcp_mux = ast_test_flag(&p->flags[2], SIP_PAGE3_RTCP_MUX); + + ice = ast_rtp_instance_get_ice(instance); + if (!ice) { + return; + } + + if (local_rtcp_mux && remote_rtcp_mux) { + /* We both support RTCP mux. Only one ICE component necessary */ + ice->change_components(instance, 1); + } else { + /* They either don't support RTCP mux or we don't know if they do yet. */ + ice->change_components(instance, 2); + } +} + /*! \brief Process SIP SDP offer, select formats and activate media channels If offer is rejected, we will not change any properties of the call Return 0 on success, a negative value on errors. @@ -10132,6 +10186,10 @@ static int process_sdp(struct sip_pvt *p, struct sip_request *req, int t38action int secure_audio = FALSE; int secure_video = FALSE; + /* RTCP Multiplexing */ + int remote_rtcp_mux_audio = FALSE; + int remote_rtcp_mux_video = FALSE; + /* Others */ int sendonly = -1; unsigned int numberofports; @@ -10662,6 +10720,8 @@ static int process_sdp(struct sip_pvt *p, struct sip_request *req, int t38action } } else if (process_sdp_a_audio(value, p, &newaudiortp, &last_rtpmap_codec)) { processed = TRUE; + } else if (process_sdp_a_rtcp_mux(value, p, &remote_rtcp_mux_audio)) { + processed = TRUE; } } /* Video specific scanning */ @@ -10683,6 +10743,8 @@ static int process_sdp(struct sip_pvt *p, struct sip_request *req, int t38action } } else if (process_sdp_a_video(value, p, &newvideortp, &last_rtpmap_codec)) { processed = TRUE; + } else if (process_sdp_a_rtcp_mux(value, p, &remote_rtcp_mux_video)) { + processed = TRUE; } } /* Text (T.140) specific scanning */ @@ -10857,6 +10919,7 @@ static int process_sdp(struct sip_pvt *p, struct sip_request *req, int t38action if (sa && portno > 0) { /* Start ICE negotiation here, only when it is response, and setting that we are conrolling agent, as we are offerer */ + set_ice_components(p, p->rtp, remote_rtcp_mux_audio); if (req->method == SIP_RESPONSE) { start_ice(p->rtp, 1); } @@ -10870,11 +10933,7 @@ static int process_sdp(struct sip_pvt *p, struct sip_request *req, int t38action ast_rtp_codecs_payloads_copy(&newaudiortp, ast_rtp_instance_get_codecs(p->rtp), p->rtp); /* Ensure RTCP is enabled since it may be inactive if we're coming back from a T.38 session */ - ast_rtp_instance_set_prop(p->rtp, AST_RTP_PROPERTY_RTCP, 1); - /* Ensure audio RTCP reads are enabled */ - if (p->owner) { - ast_channel_set_fd(p->owner, 1, ast_rtp_instance_fd(p->rtp, 1)); - } + configure_rtcp(p, p->rtp, SIP_AUDIO_RTCP_FD, remote_rtcp_mux_audio); if (ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_AUTO) { ast_clear_flag(&p->flags[0], SIP_DTMF); @@ -10897,10 +10956,10 @@ static int process_sdp(struct sip_pvt *p, struct sip_request *req, int t38action /* Prevent audio RTCP reads */ if (p->owner) { - ast_channel_set_fd(p->owner, 1, -1); + ast_channel_set_fd(p->owner, SIP_AUDIO_RTCP_FD, -1); } /* Silence RTCP while audio RTP is inactive */ - ast_rtp_instance_set_prop(p->rtp, AST_RTP_PROPERTY_RTCP, 0); + ast_rtp_instance_set_prop(p->rtp, AST_RTP_PROPERTY_RTCP, AST_RTP_INSTANCE_RTCP_DISABLED); } else { ast_rtp_instance_stop(p->rtp); if (debug) @@ -10911,6 +10970,7 @@ static int process_sdp(struct sip_pvt *p, struct sip_request *req, int t38action /* Setup video address and port */ if (p->vrtp) { if (vsa && vportno > 0) { + set_ice_components(p, p->vrtp, remote_rtcp_mux_video); start_ice(p->vrtp, (req->method != SIP_RESPONSE) ? 0 : 1); ast_sockaddr_set_port(vsa, vportno); ast_rtp_instance_set_remote_address(p->vrtp, vsa); @@ -10919,6 +10979,7 @@ static int process_sdp(struct sip_pvt *p, struct sip_request *req, int t38action ast_sockaddr_stringify(vsa)); } ast_rtp_codecs_payloads_copy(&newvideortp, ast_rtp_instance_get_codecs(p->vrtp), p->vrtp); + configure_rtcp(p, p->vrtp, SIP_VIDEO_RTCP_FD, remote_rtcp_mux_video); } else { ast_rtp_instance_stop(p->vrtp); if (debug) @@ -11265,6 +11326,18 @@ static int process_sdp_a_ice(const char *a, struct sip_pvt *p, struct ast_rtp_in return found; } +static int process_sdp_a_rtcp_mux(const char *a, struct sip_pvt *p, int *requested) +{ + int found = FALSE; + + if (!strncasecmp(a, "rtcp-mux", 8)) { + *requested = TRUE; + found = TRUE; + } + + return found; +} + static int process_sdp_a_dtls(const char *a, struct sip_pvt *p, struct ast_rtp_instance *instance) { struct ast_rtp_engine_dtls *dtls; @@ -13632,6 +13705,12 @@ static enum sip_result add_sdp(struct sip_request *resp, struct sip_pvt *p, int add_dtls_to_sdp(p->rtp, &a_audio); } + + /* If we've got rtcp-mux enabled, just unconditionally offer it in all SDPs */ + if (ast_test_flag(&p->flags[2], SIP_PAGE3_RTCP_MUX)) { + ast_str_append(&a_audio, 0, "a=rtcp-mux\r\n"); + ast_str_append(&a_video, 0, "a=rtcp-mux\r\n"); + } } if (add_t38) { @@ -13999,18 +14078,18 @@ static int transmit_reinvite_with_sdp(struct sip_pvt *p, int t38version, int old if (p->rtp) { if (t38version) { /* Silence RTCP while audio RTP is inactive */ - ast_rtp_instance_set_prop(p->rtp, AST_RTP_PROPERTY_RTCP, 0); + ast_rtp_instance_set_prop(p->rtp, AST_RTP_PROPERTY_RTCP, AST_RTP_INSTANCE_RTCP_DISABLED); if (p->owner) { /* Prevent audio RTCP reads */ - ast_channel_set_fd(p->owner, 1, -1); + ast_channel_set_fd(p->owner, SIP_AUDIO_RTCP_FD, -1); } } else if (ast_sockaddr_isnull(&p->redirip)) { /* Enable RTCP since it will be inactive if we're coming back * with this reinvite */ - ast_rtp_instance_set_prop(p->rtp, AST_RTP_PROPERTY_RTCP, 1); + ast_rtp_instance_set_prop(p->rtp, AST_RTP_PROPERTY_RTCP, AST_RTP_INSTANCE_RTCP_STANDARD); if (p->owner) { /* Enable audio RTCP reads */ - ast_channel_set_fd(p->owner, 1, ast_rtp_instance_fd(p->rtp, 1)); + ast_channel_set_fd(p->owner, SIP_AUDIO_RTCP_FD, ast_rtp_instance_fd(p->rtp, 1)); } } } @@ -21021,6 +21100,7 @@ static char *_sip_show_peer(int type, int fd, struct mansession *s, const struct ast_cli(fd, " Parkinglot : %s\n", peer->parkinglot); ast_cli(fd, " Use Reason : %s\n", AST_CLI_YESNO(ast_test_flag(&peer->flags[1], SIP_PAGE2_Q850_REASON))); ast_cli(fd, " Encryption : %s\n", AST_CLI_YESNO(ast_test_flag(&peer->flags[1], SIP_PAGE2_USE_SRTP))); + ast_cli(fd, " RTCP Mux : %s\n", AST_CLI_YESNO(ast_test_flag(&peer->flags[2], SIP_PAGE3_RTCP_MUX))); ast_cli(fd, "\n"); peer = sip_unref_peer(peer, "sip_show_peer: sip_unref_peer: done with peer ptr"); } else if (peer && type == 1) { /* manager listing */ @@ -21091,6 +21171,7 @@ static char *_sip_show_peer(int type, int fd, struct mansession *s, const struct astman_append(s, "SIP-Sess-Min: %d\r\n", peer->stimer.st_min_se); astman_append(s, "SIP-RTP-Engine: %s\r\n", peer->engine); astman_append(s, "SIP-Encryption: %s\r\n", ast_test_flag(&peer->flags[1], SIP_PAGE2_USE_SRTP) ? "Y" : "N"); + astman_append(s, "SIP-RTCP-Mux: %s\r\n", ast_test_flag(&peer->flags[2], SIP_PAGE3_RTCP_MUX) ? "Y" : "N"); /* - is enumerated */ astman_append(s, "SIP-DTMFmode: %s\r\n", dtmfmode2str(ast_test_flag(&peer->flags[0], SIP_DTMF))); @@ -21719,6 +21800,7 @@ static char *sip_show_settings(struct ast_cli_entry *e, int cmd, struct ast_cli_ ast_cli(a->fd, " MOH Interpret: %s\n", default_mohinterpret); ast_cli(a->fd, " MOH Suggest: %s\n", default_mohsuggest); ast_cli(a->fd, " Voice Mail Extension: %s\n", default_vmexten); + ast_cli(a->fd, " RTCP Multiplexing: %s\n", AST_CLI_YESNO(ast_test_flag(&global_flags[2], SIP_PAGE3_RTCP_MUX))); if (realtimepeers || realtimeregs) { @@ -30787,6 +30869,9 @@ static int handle_common_options(struct ast_flags *flags, struct ast_flags *mask } else if (!strcasecmp(v->name, "buggymwi")) { ast_set_flag(&mask[1], SIP_PAGE2_BUGGY_MWI); ast_set2_flag(&flags[1], ast_true(v->value), SIP_PAGE2_BUGGY_MWI); + } else if (!strcasecmp(v->name, "rtcp_mux")) { + ast_set_flag(&mask[2], SIP_PAGE3_RTCP_MUX); + ast_set2_flag(&flags[2], ast_true(v->value), SIP_PAGE3_RTCP_MUX); } else res = 0; @@ -33418,9 +33503,9 @@ static int sip_set_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance *i if (p->rtp) { /* Prevent audio RTCP reads */ - ast_channel_set_fd(chan, 1, -1); + ast_channel_set_fd(chan, SIP_AUDIO_RTCP_FD, -1); /* Silence RTCP while audio RTP is inactive */ - ast_rtp_instance_set_prop(p->rtp, AST_RTP_PROPERTY_RTCP, 0); + ast_rtp_instance_set_prop(p->rtp, AST_RTP_PROPERTY_RTCP, AST_RTP_INSTANCE_RTCP_DISABLED); } } else if (!ast_sockaddr_isnull(&p->redirip)) { memset(&p->redirip, 0, sizeof(p->redirip)); @@ -33432,9 +33517,9 @@ static int sip_set_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance *i if (p->vrtp) { /* Prevent video RTCP reads */ - ast_channel_set_fd(chan, 3, -1); + ast_channel_set_fd(chan, SIP_VIDEO_RTCP_FD, -1); /* Silence RTCP while video RTP is inactive */ - ast_rtp_instance_set_prop(p->vrtp, AST_RTP_PROPERTY_RTCP, 0); + ast_rtp_instance_set_prop(p->vrtp, AST_RTP_PROPERTY_RTCP, AST_RTP_INSTANCE_RTCP_DISABLED); } } else if (!ast_sockaddr_isnull(&p->vredirip)) { memset(&p->vredirip, 0, sizeof(p->vredirip)); @@ -33443,9 +33528,9 @@ static int sip_set_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance *i if (p->vrtp) { /* Enable RTCP since it will be inactive if we're coming back * from a reinvite */ - ast_rtp_instance_set_prop(p->vrtp, AST_RTP_PROPERTY_RTCP, 1); + ast_rtp_instance_set_prop(p->vrtp, AST_RTP_PROPERTY_RTCP, AST_RTP_INSTANCE_RTCP_STANDARD); /* Enable video RTCP reads */ - ast_channel_set_fd(chan, 3, ast_rtp_instance_fd(p->vrtp, 1)); + ast_channel_set_fd(chan, SIP_VIDEO_RTCP_FD, ast_rtp_instance_fd(p->vrtp, 1)); } } diff --git a/channels/chan_skinny.c b/channels/chan_skinny.c index a3a2f87fb..d1c2b927a 100644 --- a/channels/chan_skinny.c +++ b/channels/chan_skinny.c @@ -7639,7 +7639,6 @@ static void *accept_thread(void *ignore) struct sockaddr_in sin; socklen_t sinlen; struct skinnysession *s; - struct protoent *p; int arg = 1; for (;;) { @@ -7656,12 +7655,10 @@ static void *accept_thread(void *ignore) continue; } - p = getprotobyname("tcp"); - if(p) { - if( setsockopt(as, p->p_proto, TCP_NODELAY, (char *)&arg, sizeof(arg) ) < 0 ) { - ast_log(LOG_WARNING, "Failed to set Skinny tcp connection to TCP_NODELAY mode: %s\n", strerror(errno)); - } + if (setsockopt(as, IPPROTO_TCP, TCP_NODELAY, (char *) &arg, sizeof(arg)) < 0) { + ast_log(LOG_WARNING, "Failed to set TCP_NODELAY on Skinny TCP connection: %s\n", strerror(errno)); } + if (!(s = ast_calloc(1, sizeof(struct skinnysession)))) { close(as); ast_atomic_fetchadd_int(&unauth_sessions, -1); diff --git a/channels/sip/include/sip.h b/channels/sip/include/sip.h index e511d139b..86f8967c4 100644 --- a/channels/sip/include/sip.h +++ b/channels/sip/include/sip.h @@ -384,11 +384,12 @@ #define SIP_PAGE3_IGNORE_PREFCAPS (1 << 7) /*!< DP: Ignore prefcaps when setting up an outgoing call leg */ #define SIP_PAGE3_DISCARD_REMOTE_HOLD_RETRIEVAL (1 << 8) /*!< DGP: Stop telling the peer to start music on hold */ #define SIP_PAGE3_FORCE_AVP (1 << 9) /*!< DGP: Force 'RTP/AVP' for all streams, even DTLS */ +#define SIP_PAGE3_RTCP_MUX (1 << 10) /*!< DGP: Attempt to negotiate RFC 5761 RTCP multiplexing */ #define SIP_PAGE3_FLAGS_TO_COPY \ (SIP_PAGE3_SNOM_AOC | SIP_PAGE3_SRTP_TAG_32 | SIP_PAGE3_NAT_AUTO_RPORT | SIP_PAGE3_NAT_AUTO_COMEDIA | \ SIP_PAGE3_DIRECT_MEDIA_OUTGOING | SIP_PAGE3_USE_AVPF | SIP_PAGE3_ICE_SUPPORT | SIP_PAGE3_IGNORE_PREFCAPS | \ - SIP_PAGE3_DISCARD_REMOTE_HOLD_RETRIEVAL | SIP_PAGE3_FORCE_AVP) + SIP_PAGE3_DISCARD_REMOTE_HOLD_RETRIEVAL | SIP_PAGE3_FORCE_AVP | SIP_PAGE3_RTCP_MUX) #define CHECK_AUTH_BUF_INITLEN 256 diff --git a/configs/samples/pjsip.conf.sample b/configs/samples/pjsip.conf.sample index b18fdb276..120a7ef1c 100644 --- a/configs/samples/pjsip.conf.sample +++ b/configs/samples/pjsip.conf.sample @@ -853,6 +853,17 @@ ; this option is set to 'no' (the default) changes to the ; particular transport will be ignored. If set to 'yes', ; changes (if any) will be applied. +;symmetric_transport=no ; When a request from a dynamic contact comes in on a + ; transport with this option set to 'yes', the transport + ; name will be saved and used for subsequent outgoing + ; requests like OPTIONS, NOTIFY and INVITE. It's saved + ; as a contact uri parameter named 'x-ast-txp' and will + ; display with the contact uri in CLI, AMI, and ARI + ; output. On the outgoing request, if a transport + ; wasn't explicitly set on the endpoint AND the request + ; URI is not a hostname, the saved transport will be + ; used and the 'x-ast-txp' parameter stripped from the + ; outgoing packet. ;==========================AOR SECTION OPTIONS========================= ;[aor] diff --git a/configs/samples/sip.conf.sample b/configs/samples/sip.conf.sample index 916e2d671..9b52ec06c 100644 --- a/configs/samples/sip.conf.sample +++ b/configs/samples/sip.conf.sample @@ -1090,6 +1090,8 @@ srvlookup=yes ; Enable DNS SRV lookups on outbound calls ; option may be specified at the global or peer scope. ;force_avp=yes ; Force 'RTP/AVP', 'RTP/AVPF', 'RTP/SAVP', and 'RTP/SAVPF' to be used for ; media streams when appropriate, even if a DTLS stream is present. +;rtcp_mux=yes ; Enable support for RFC 5761 RTCP multiplexing which is required for + ; WebRTC support ; ---------------------------------------- REALTIME SUPPORT ------------------------ ; For additional information on ARA, the Asterisk Realtime Architecture, ; please read https://wiki.asterisk.org/wiki/display/AST/Realtime+Database+Configuration diff --git a/contrib/ast-db-manage/config/versions/15db7b91a97a_add_rtcp_mux.py b/contrib/ast-db-manage/config/versions/15db7b91a97a_add_rtcp_mux.py index 50d3ee338..8b0214a17 100644 --- a/contrib/ast-db-manage/config/versions/15db7b91a97a_add_rtcp_mux.py +++ b/contrib/ast-db-manage/config/versions/15db7b91a97a_add_rtcp_mux.py @@ -12,6 +12,7 @@ down_revision = '465e70e8c337' from alembic import op import sqlalchemy as sa +from sqlalchemy.dialects.postgresql import ENUM YESNO_NAME = 'yesno_values' YESNO_VALUES = ['yes', 'no'] diff --git a/contrib/ast-db-manage/config/versions/f638dbe2eb23_symmetric_transport.py b/contrib/ast-db-manage/config/versions/f638dbe2eb23_symmetric_transport.py new file mode 100644 index 000000000..51b5066f5 --- /dev/null +++ b/contrib/ast-db-manage/config/versions/f638dbe2eb23_symmetric_transport.py @@ -0,0 +1,32 @@ +"""symmetric_transport + +Revision ID: f638dbe2eb23 +Revises: 15db7b91a97a +Create Date: 2017-03-09 09:38:59.513479 + +""" + +# revision identifiers, used by Alembic. +revision = 'f638dbe2eb23' +down_revision = '15db7b91a97a' + +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects.postgresql import ENUM + +YESNO_NAME = 'yesno_values' +YESNO_VALUES = ['yes', 'no'] + +def upgrade(): + ############################# Enums ############################## + + # yesno_values have already been created, so use postgres enum object + # type to get around "already created" issue - works okay with mysql + yesno_values = ENUM(*YESNO_VALUES, name=YESNO_NAME, create_type=False) + + op.add_column('ps_transports', sa.Column('symmetric_transport', yesno_values)) + op.add_column('ps_subscription_persistence', sa.Column('contact_uri', sa.String(256))) + +def downgrade(): + op.drop_column('ps_subscription_persistence', 'contact_uri') + op.drop_column('ps_transports', 'symmetric_transport') diff --git a/include/asterisk/network.h b/include/asterisk/network.h index 3371e5895..5216f4c61 100644 --- a/include/asterisk/network.h +++ b/include/asterisk/network.h @@ -86,6 +86,11 @@ const char *ast_inet_ntoa(struct in_addr ia); #endif #define inet_ntoa __dont__use__inet_ntoa__use__ast_inet_ntoa__instead__ +#ifdef getprotobyname +#undef getprotobyname +#endif +#define getprotobyname __getprotobyname_is_not_threadsafe__do_not_use__ + /*! \brief Compares the source address and port of two sockaddr_in */ static force_inline int inaddrcmp(const struct sockaddr_in *sin1, const struct sockaddr_in *sin2) { diff --git a/include/asterisk/res_pjsip.h b/include/asterisk/res_pjsip.h index fb0451307..c6c308bee 100644 --- a/include/asterisk/res_pjsip.h +++ b/include/asterisk/res_pjsip.h @@ -194,6 +194,8 @@ struct ast_sip_transport { int write_timeout; /*! Allow reload */ int allow_reload; + /*! Automatically send requests out the same transport requests have come in on */ + int symmetric_transport; }; #define SIP_SORCERY_DOMAIN_ALIAS_TYPE "domain_alias" @@ -765,6 +767,10 @@ struct ast_sip_endpoint { unsigned int asymmetric_rtp_codec; }; +/*! URI parameter for symmetric transport */ +#define AST_SIP_X_AST_TXP "x-ast-txp" +#define AST_SIP_X_AST_TXP_LEN 9 + /*! * \brief Initialize an auth vector with the configured values. * @@ -1659,6 +1665,26 @@ pjsip_dialog *ast_sip_create_dialog_uas(const struct ast_sip_endpoint *endpoint, /*! * \brief General purpose method for creating an rdata structure using specific information + * \since 13.15.0 + * + * \param rdata[out] The rdata structure that will be populated + * \param packet A SIP message + * \param src_name The source IP address of the message + * \param src_port The source port of the message + * \param transport_type The type of transport the message was received on + * \param local_name The local IP address the message was received on + * \param local_port The local port the message was received on + * \param contact_uri The contact URI of the message + * + * \retval 0 success + * \retval -1 failure + */ +int ast_sip_create_rdata_with_contact(pjsip_rx_data *rdata, char *packet, + const char *src_name, int src_port, char *transport_type, const char *local_name, + int local_port, const char *contact_uri); + +/*! + * \brief General purpose method for creating an rdata structure using specific information * * \param rdata[out] The rdata structure that will be populated * \param packet A SIP message @@ -1671,8 +1697,8 @@ pjsip_dialog *ast_sip_create_dialog_uas(const struct ast_sip_endpoint *endpoint, * \retval 0 success * \retval -1 failure */ -int ast_sip_create_rdata(pjsip_rx_data *rdata, char *packet, const char *src_name, int src_port, char *transport_type, - const char *local_name, int local_port); +int ast_sip_create_rdata(pjsip_rx_data *rdata, char *packet, const char *src_name, + int src_port, char *transport_type, const char *local_name, int local_port); /*! * \brief General purpose method for creating a SIP request @@ -2709,4 +2735,54 @@ void ast_sip_modify_id_header(pj_pool_t *pool, pjsip_fromto_hdr *id_hdr, void ast_sip_get_unidentified_request_thresholds(unsigned int *count, unsigned int *period, unsigned int *prune_interval); +/*! + * \brief Get the transport name from an endpoint or request uri + * \since 13.15.0 + * + * \param endpoint + * \param sip_uri + * \param buf Buffer to receive transport name + * \param buf_len Buffer length + * + * \retval 0 Success + * \retval -1 Failure + * + * \note + * If endpoint->transport is not NULL, it is returned in buf. + * Otherwise if sip_uri has an 'x-ast-txp' parameter AND the sip_uri host is + * an ip4 or ip6 address, its value is returned, + */ +int ast_sip_get_transport_name(const struct ast_sip_endpoint *endpoint, + pjsip_sip_uri *sip_uri, char *buf, size_t buf_len); + +/*! + * \brief Sets pjsip_tpselector from an endpoint or uri + * \since 13.15.0 + * + * \param endpoint If endpoint->transport is set, it's used + * \param sip_uri If sip_uri contains a x-ast-txp parameter, it's used + * \param selector The selector to be populated + * + * \retval 0 success + * \retval -1 failure + */ +int ast_sip_set_tpselector_from_ep_or_uri(const struct ast_sip_endpoint *endpoint, + pjsip_sip_uri *sip_uri, pjsip_tpselector *selector); + +/*! + * \brief Set the transport on a dialog + * \since 13.15.0 + * + * \param endpoint + * \param dlg + * \param selector (optional) + * + * \note + * This API calls ast_sip_get_transport_name(endpoint, dlg->target) and if the result is + * non-NULL, calls pjsip_dlg_set_transport. If 'selector' is non-NULL, it is updated with + * the selector used. + */ +int ast_sip_dlg_set_transport(const struct ast_sip_endpoint *endpoint, pjsip_dialog *dlg, + pjsip_tpselector *selector); + #endif /* _RES_PJSIP_H */ diff --git a/main/http.c b/main/http.c index 0db6ee7b6..ea85a2823 100644 --- a/main/http.c +++ b/main/http.c @@ -1917,9 +1917,8 @@ static void *httpd_helper_thread(void *data) * This is necessary to prevent delays (caused by buffering) as we * write to the socket in bits and pieces. */ - if (setsockopt(ast_iostream_get_fd(ser->stream), IPPROTO_TCP, TCP_NODELAY, (char *) &arg, sizeof(arg) ) < 0) { + if (setsockopt(ast_iostream_get_fd(ser->stream), IPPROTO_TCP, TCP_NODELAY, (char *) &arg, sizeof(arg)) < 0) { ast_log(LOG_WARNING, "Failed to set TCP_NODELAY on HTTP connection: %s\n", strerror(errno)); - ast_log(LOG_WARNING, "Some HTTP requests may be slow to respond.\n"); } ast_iostream_nonblock(ser->stream); diff --git a/main/manager.c b/main/manager.c index eae1ca52a..c1d73dce7 100644 --- a/main/manager.c +++ b/main/manager.c @@ -6647,8 +6647,8 @@ static void *session_do(void *data) /* here we set TCP_NODELAY on the socket to disable Nagle's algorithm. * This is necessary to prevent delays (caused by buffering) as we * write to the socket in bits and pieces. */ - if (setsockopt(ast_iostream_get_fd(ser->stream), IPPROTO_TCP, TCP_NODELAY, (char *)&arg, sizeof(arg) ) < 0) { - ast_log(LOG_WARNING, "Failed to set manager tcp connection to TCP_NODELAY mode: %s\nSome manager actions may be slow to respond.\n", strerror(errno)); + if (setsockopt(ast_iostream_get_fd(ser->stream), IPPROTO_TCP, TCP_NODELAY, (char *) &arg, sizeof(arg)) < 0) { + ast_log(LOG_WARNING, "Failed to set TCP_NODELAY on manager connection: %s\n", strerror(errno)); } ast_iostream_nonblock(ser->stream); diff --git a/res/res_pjsip.c b/res/res_pjsip.c index f4df49836..962c4be4f 100644 --- a/res/res_pjsip.c +++ b/res/res_pjsip.c @@ -1193,6 +1193,22 @@ in-progress calls.</para> </description> </configOption> + <configOption name="symmetric_transport" default="no"> + <synopsis>Use the same transport for outgoing reqests as incoming ones.</synopsis> + <description> + <para>When a request from a dynamic contact + comes in on a transport with this option set to 'yes', + the transport name will be saved and used for subsequent + outgoing requests like OPTIONS, NOTIFY and INVITE. It's + saved as a contact uri parameter named 'x-ast-txp' and will + display with the contact uri in CLI, AMI, and ARI output. + On the outgoing request, if a transport wasn't explicitly + set on the endpoint AND the request URI is not a hostname, + the saved transport will be used and the 'x-ast-txp' + parameter stripped from the outgoing packet. + </para> + </description> + </configOption> </configObject> <configObject name="contact"> <synopsis>A way of creating an aliased name to a SIP URI</synopsis> @@ -2762,7 +2778,54 @@ pjsip_endpoint *ast_sip_get_pjsip_endpoint(void) return ast_pjsip_endpoint; } -static int sip_dialog_create_from(pj_pool_t *pool, pj_str_t *from, const char *user, const char *domain, const pj_str_t *target, pjsip_tpselector *selector) +int ast_sip_get_transport_name(const struct ast_sip_endpoint *endpoint, + pjsip_sip_uri *sip_uri, char *buf, size_t buf_len) +{ + char *host = NULL; + static const pj_str_t x_name = { AST_SIP_X_AST_TXP, AST_SIP_X_AST_TXP_LEN }; + pjsip_param *x_transport; + + if (!ast_strlen_zero(endpoint->transport)) { + ast_copy_string(buf, endpoint->transport, buf_len); + return 0; + } + + x_transport = pjsip_param_find(&sip_uri->other_param, &x_name); + if (!x_transport) { + return -1; + } + + /* Only use x_transport if the uri host is an ip (4 or 6) address */ + host = ast_alloca(sip_uri->host.slen + 1); + ast_copy_pj_str(host, &sip_uri->host, sip_uri->host.slen + 1); + if (!ast_sockaddr_parse(NULL, host, PARSE_PORT_FORBID)) { + return -1; + } + + ast_copy_pj_str(buf, &x_transport->value, buf_len); + + return 0; +} + +int ast_sip_dlg_set_transport(const struct ast_sip_endpoint *endpoint, pjsip_dialog *dlg, + pjsip_tpselector *selector) +{ + pjsip_sip_uri *uri; + pjsip_tpselector sel = { .type = PJSIP_TPSELECTOR_NONE, }; + + uri = pjsip_uri_get_uri(dlg->target); + if (!selector) { + selector = &sel; + } + + ast_sip_set_tpselector_from_ep_or_uri(endpoint, uri, selector); + pjsip_dlg_set_transport(dlg, selector); + + return 0; +} + +static int sip_dialog_create_from(pj_pool_t *pool, pj_str_t *from, const char *user, + const char *domain, const pj_str_t *target, pjsip_tpselector *selector) { pj_str_t tmp, local_addr; pjsip_uri *uri; @@ -2892,15 +2955,16 @@ int ast_sip_set_tpselector_from_transport_name(const char *transport_name, pjsip return ast_sip_set_tpselector_from_transport(transport, selector); } -static int sip_get_tpselector_from_endpoint(const struct ast_sip_endpoint *endpoint, pjsip_tpselector *selector) +int ast_sip_set_tpselector_from_ep_or_uri(const struct ast_sip_endpoint *endpoint, + pjsip_sip_uri *sip_uri, pjsip_tpselector *selector) { - const char *transport_name = endpoint->transport; + char transport_name[128]; - if (ast_strlen_zero(transport_name)) { + if (ast_sip_get_transport_name(endpoint, sip_uri, transport_name, sizeof(transport_name))) { return 0; } - return ast_sip_set_tpselector_from_transport_name(endpoint->transport, selector); + return ast_sip_set_tpselector_from_transport_name(transport_name, selector); } void ast_sip_add_usereqphone(const struct ast_sip_endpoint *endpoint, pj_pool_t *pool, pjsip_uri *uri) @@ -2908,8 +2972,8 @@ void ast_sip_add_usereqphone(const struct ast_sip_endpoint *endpoint, pj_pool_t pjsip_sip_uri *sip_uri; int i = 0; pjsip_param *param; - const pj_str_t STR_USER = { "user", 4 }; - const pj_str_t STR_PHONE = { "phone", 5 }; + static const pj_str_t STR_USER = { "user", 4 }; + static const pj_str_t STR_PHONE = { "phone", 5 }; if (!endpoint || !endpoint->usereqphone || (!PJSIP_URI_SCHEME_IS_SIP(uri) && !PJSIP_URI_SCHEME_IS_SIPS(uri))) { return; @@ -2942,7 +3006,8 @@ void ast_sip_add_usereqphone(const struct ast_sip_endpoint *endpoint, pj_pool_t pj_list_insert_before(&sip_uri->other_param, param); } -pjsip_dialog *ast_sip_create_dialog_uac(const struct ast_sip_endpoint *endpoint, const char *uri, const char *request_user) +pjsip_dialog *ast_sip_create_dialog_uac(const struct ast_sip_endpoint *endpoint, + const char *uri, const char *request_user) { char enclosed_uri[PJSIP_MAX_URL_SIZE]; pj_str_t local_uri = { "sip:temp@temp", 13 }, remote_uri, target_uri; @@ -2967,12 +3032,13 @@ pjsip_dialog *ast_sip_create_dialog_uac(const struct ast_sip_endpoint *endpoint, return NULL; } - if (sip_get_tpselector_from_endpoint(endpoint, &selector)) { - pjsip_dlg_terminate(dlg); - return NULL; - } + /* We have to temporarily bump up the sess_count here so the dialog is not prematurely destroyed */ + dlg->sess_count++; + + ast_sip_dlg_set_transport(endpoint, dlg, &selector); if (sip_dialog_create_from(dlg->pool, &local_uri, endpoint->fromuser, endpoint->fromdomain, &remote_uri, &selector)) { + dlg->sess_count--; pjsip_dlg_terminate(dlg); return NULL; } @@ -3008,11 +3074,6 @@ pjsip_dialog *ast_sip_create_dialog_uac(const struct ast_sip_endpoint *endpoint, ast_sip_add_usereqphone(endpoint, dlg->pool, dlg->target); ast_sip_add_usereqphone(endpoint, dlg->pool, dlg->remote.info->uri); - /* We have to temporarily bump up the sess_count here so the dialog is not prematurely destroyed */ - dlg->sess_count++; - - pjsip_dlg_set_transport(dlg, &selector); - if (!ast_strlen_zero(outbound_proxy)) { pjsip_route_hdr route_set, *route; static const pj_str_t ROUTE_HNAME = { "Route", 5 }; @@ -3081,10 +3142,13 @@ pjsip_dialog *ast_sip_create_dialog_uas(const struct ast_sip_endpoint *endpoint, pjsip_transport_type_e type = rdata->tp_info.transport->key.type; pjsip_tpselector selector = { .type = PJSIP_TPSELECTOR_NONE, }; pjsip_transport *transport; + pjsip_contact_hdr *contact_hdr; ast_assert(status != NULL); - if (sip_get_tpselector_from_endpoint(endpoint, &selector)) { + contact_hdr = pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_CONTACT, NULL); + if (ast_sip_set_tpselector_from_ep_or_uri(endpoint, pjsip_uri_get_uri(contact_hdr->uri), + &selector)) { return NULL; } @@ -3130,8 +3194,8 @@ pjsip_dialog *ast_sip_create_dialog_uas(const struct ast_sip_endpoint *endpoint, return dlg; } -int ast_sip_create_rdata(pjsip_rx_data *rdata, char *packet, const char *src_name, int src_port, - char *transport_type, const char *local_name, int local_port) +int ast_sip_create_rdata_with_contact(pjsip_rx_data *rdata, char *packet, const char *src_name, int src_port, + char *transport_type, const char *local_name, int local_port, const char *contact) { pj_str_t tmp; @@ -3155,6 +3219,16 @@ int ast_sip_create_rdata(pjsip_rx_data *rdata, char *packet, const char *src_nam return -1; } + if (!ast_strlen_zero(contact)) { + pjsip_contact_hdr *contact_hdr; + + contact_hdr = pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_CONTACT, NULL); + if (contact_hdr) { + contact_hdr->uri = pjsip_parse_uri(rdata->tp_info.pool, (char *)contact, + strlen(contact), PJSIP_PARSE_URI_AS_NAMEADDR); + } + } + pj_strdup2(rdata->tp_info.pool, &rdata->msg_info.via->recvd_param, rdata->pkt_info.src_name); rdata->msg_info.via->rport_param = -1; @@ -3166,6 +3240,13 @@ int ast_sip_create_rdata(pjsip_rx_data *rdata, char *packet, const char *src_nam return 0; } +int ast_sip_create_rdata(pjsip_rx_data *rdata, char *packet, const char *src_name, int src_port, + char *transport_type, const char *local_name, int local_port) +{ + return ast_sip_create_rdata_with_contact(rdata, packet, src_name, src_port, transport_type, + local_name, local_port, NULL); +} + /* PJSIP doesn't know about the INFO method, so we have to define it ourselves */ static const pjsip_method info_method = {PJSIP_OTHER_METHOD, {"INFO", 4} }; static const pjsip_method message_method = {PJSIP_OTHER_METHOD, {"MESSAGE", 7} }; @@ -3247,14 +3328,6 @@ static int create_out_of_dialog_request(const pjsip_method *method, struct ast_s pj_cstr(&remote_uri, uri); } - if (endpoint) { - if (sip_get_tpselector_from_endpoint(endpoint, &selector)) { - ast_log(LOG_ERROR, "Unable to retrieve PJSIP transport selector for endpoint %s\n", - ast_sorcery_object_get_id(endpoint)); - return -1; - } - } - pool = pjsip_endpt_create_pool(ast_sip_get_pjsip_endpoint(), "Outbound request", 256, 256); if (!pool) { @@ -3272,6 +3345,8 @@ static int create_out_of_dialog_request(const pjsip_method *method, struct ast_s return -1; } + ast_sip_set_tpselector_from_ep_or_uri(endpoint, pjsip_uri_get_uri(sip_uri), &selector); + fromuser = endpoint ? (!ast_strlen_zero(endpoint->fromuser) ? endpoint->fromuser : ast_sorcery_object_get_id(endpoint)) : NULL; if (sip_dialog_create_from(pool, &from, fromuser, endpoint ? endpoint->fromdomain : NULL, &remote_uri, &selector)) { @@ -3291,6 +3366,8 @@ static int create_out_of_dialog_request(const pjsip_method *method, struct ast_s return -1; } + pjsip_tx_data_set_transport(*tdata, &selector); + if (endpoint && !ast_strlen_zero(endpoint->contact_user)){ pjsip_contact_hdr *contact_hdr; pjsip_sip_uri *contact_uri; @@ -3332,6 +3409,8 @@ int ast_sip_create_request(const char *method, struct pjsip_dialog *dlg, { const pjsip_method *pmethod = get_pjsip_method(method); + ast_assert(endpoint != NULL); + if (!pmethod) { ast_log(LOG_WARNING, "Unknown method '%s'. Cannot send request\n", method); return -1; @@ -3596,7 +3675,6 @@ static pj_status_t endpt_send_request(struct ast_sip_endpoint *endpoint, struct send_request_wrapper *req_wrapper; pj_status_t ret_val; pjsip_endpoint *endpt = ast_sip_get_pjsip_endpoint(); - pjsip_tpselector selector = { .type = PJSIP_TPSELECTOR_NONE, }; if (!cb && token) { /* Silly. Without a callback we cannot do anything with token. */ @@ -3621,11 +3699,6 @@ static pj_status_t endpt_send_request(struct ast_sip_endpoint *endpoint, /* Add a reference to tdata. The wrapper destructor cleans it up. */ pjsip_tx_data_add_ref(tdata); - if (endpoint) { - sip_get_tpselector_from_endpoint(endpoint, &selector); - pjsip_tx_data_set_transport(tdata, &selector); - } - if (timeout > 0) { pj_time_val timeout_timer_val = { timeout / 1000, timeout % 1000 }; diff --git a/res/res_pjsip/config_transport.c b/res/res_pjsip/config_transport.c index 60b4507cd..3c41f175a 100644 --- a/res/res_pjsip/config_transport.c +++ b/res/res_pjsip/config_transport.c @@ -552,13 +552,20 @@ static int transport_apply(const struct ast_sorcery *sorcery, void *obj) } } - if (res == PJ_SUCCESS && (transport->tos || transport->cos)) { - pj_sock_t sock; - pj_qos_params qos_params; - sock = pjsip_udp_transport_get_socket(temp_state->state->transport); - pj_sock_get_qos_params(sock, &qos_params); - set_qos(transport, &qos_params); - pj_sock_set_qos_params(sock, &qos_params); + if (res == PJ_SUCCESS) { + temp_state->state->transport->info = pj_pool_alloc(temp_state->state->transport->pool, + (AST_SIP_X_AST_TXP_LEN + strlen(transport_id) + 2)); + + sprintf(temp_state->state->transport->info, "%s:%s", AST_SIP_X_AST_TXP, transport_id); + + if (transport->tos || transport->cos) { + pj_sock_t sock; + pj_qos_params qos_params; + sock = pjsip_udp_transport_get_socket(temp_state->state->transport); + pj_sock_get_qos_params(sock, &qos_params); + set_qos(transport, &qos_params); + pj_sock_set_qos_params(sock, &qos_params); + } } } else if (transport->type == AST_TRANSPORT_TCP) { pjsip_tcp_transport_cfg cfg; @@ -1375,6 +1382,7 @@ int ast_sip_initialize_sorcery_transport(void) ast_sorcery_object_field_register(sorcery, "transport", "cos", "0", OPT_UINT_T, 0, FLDSET(struct ast_sip_transport, cos)); ast_sorcery_object_field_register(sorcery, "transport", "websocket_write_timeout", AST_DEFAULT_WEBSOCKET_WRITE_TIMEOUT_STR, OPT_INT_T, PARSE_IN_RANGE, FLDSET(struct ast_sip_transport, write_timeout), 1, INT_MAX); ast_sorcery_object_field_register(sorcery, "transport", "allow_reload", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_transport, allow_reload)); + ast_sorcery_object_field_register(sorcery, "transport", "symmetric_transport", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_transport, symmetric_transport)); internal_sip_register_endpoint_formatter(&endpoint_transport_formatter); diff --git a/res/res_pjsip/pjsip_message_ip_updater.c b/res/res_pjsip/pjsip_message_ip_updater.c index 7671ad0a7..864d898b3 100644 --- a/res/res_pjsip/pjsip_message_ip_updater.c +++ b/res/res_pjsip/pjsip_message_ip_updater.c @@ -28,6 +28,7 @@ #define MOD_DATA_RESTRICTIONS "restrictions" static pj_status_t multihomed_on_tx_message(pjsip_tx_data *tdata); +static pj_bool_t multihomed_on_rx_message(pjsip_rx_data *rdata); /*! \brief Outgoing message modification restrictions */ struct multihomed_message_restrictions { @@ -41,6 +42,7 @@ static pjsip_module multihomed_module = { .priority = PJSIP_MOD_PRIORITY_TSX_LAYER - 1, .on_tx_request = multihomed_on_tx_message, .on_tx_response = multihomed_on_tx_message, + .on_rx_request = multihomed_on_rx_message, }; /*! \brief Helper function to get (or allocate if not already present) restrictions on a message */ @@ -151,6 +153,44 @@ static int multihomed_rewrite_sdp(struct pjmedia_sdp_session *sdp) return 0; } +static void sanitize_tdata(pjsip_tx_data *tdata) +{ + static const pj_str_t x_name = { AST_SIP_X_AST_TXP, AST_SIP_X_AST_TXP_LEN }; + pjsip_param *x_transport; + pjsip_sip_uri *uri; + pjsip_fromto_hdr *fromto; + pjsip_contact_hdr *contact; + pjsip_hdr *hdr; + + if (tdata->msg->type == PJSIP_REQUEST_MSG) { + uri = pjsip_uri_get_uri(tdata->msg->line.req.uri); + x_transport = pjsip_param_find(&uri->other_param, &x_name); + if (x_transport) { + pj_list_erase(x_transport); + } + } + + for (hdr = tdata->msg->hdr.next; hdr != &tdata->msg->hdr; hdr = hdr->next) { + if (hdr->type == PJSIP_H_TO || hdr->type == PJSIP_H_FROM) { + fromto = (pjsip_fromto_hdr *) hdr; + uri = pjsip_uri_get_uri(fromto->uri); + x_transport = pjsip_param_find(&uri->other_param, &x_name); + if (x_transport) { + pj_list_erase(x_transport); + } + } else if (hdr->type == PJSIP_H_CONTACT) { + contact = (pjsip_contact_hdr *) hdr; + uri = pjsip_uri_get_uri(contact->uri); + x_transport = pjsip_param_find(&uri->other_param, &x_name); + if (x_transport) { + pj_list_erase(x_transport); + } + } + } + + pjsip_tx_data_invalidate_msg(tdata); +} + static pj_status_t multihomed_on_tx_message(pjsip_tx_data *tdata) { struct multihomed_message_restrictions *restrictions = ast_sip_mod_data_get(tdata->mod_data, multihomed_module.id, MOD_DATA_RESTRICTIONS); @@ -159,6 +199,8 @@ static pj_status_t multihomed_on_tx_message(pjsip_tx_data *tdata) pjsip_via_hdr *via; pjsip_fromto_hdr *from; + sanitize_tdata(tdata); + /* Use the destination information to determine what local interface this message will go out on */ pjsip_tpmgr_fla2_param_default(&prm); prm.tp_type = tdata->tp_info.transport->key.type; @@ -273,6 +315,47 @@ static pj_status_t multihomed_on_tx_message(pjsip_tx_data *tdata) return PJ_SUCCESS; } +static pj_bool_t multihomed_on_rx_message(pjsip_rx_data *rdata) +{ + pjsip_contact_hdr *contact; + pjsip_sip_uri *uri; + const char *transport_id; + struct ast_sip_transport *transport; + pjsip_param *x_transport; + + if (rdata->msg_info.msg->type != PJSIP_REQUEST_MSG) { + return PJ_FALSE; + } + + contact = pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_CONTACT, NULL); + if (!(contact && contact->uri + && ast_begins_with(rdata->tp_info.transport->info, AST_SIP_X_AST_TXP ":"))) { + return PJ_FALSE; + } + + uri = pjsip_uri_get_uri(contact->uri); + + transport_id = rdata->tp_info.transport->info + AST_SIP_X_AST_TXP_LEN + 1; + transport = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "transport", transport_id); + + if (!(transport && transport->symmetric_transport)) { + return PJ_FALSE; + } + + x_transport = PJ_POOL_ALLOC_T(rdata->tp_info.pool, pjsip_param); + x_transport->name = pj_strdup3(rdata->tp_info.pool, AST_SIP_X_AST_TXP); + x_transport->value = pj_strdup3(rdata->tp_info.pool, transport_id); + + pj_list_insert_before(&uri->other_param, x_transport); + + ast_debug(1, "Set transport '%s' on %.*s from %.*s:%d\n", transport_id, + (int)rdata->msg_info.msg->line.req.method.name.slen, + rdata->msg_info.msg->line.req.method.name.ptr, + (int)uri->host.slen, uri->host.ptr, uri->port); + + return PJ_FALSE; +} + void ast_res_pjsip_cleanup_message_ip_updater(void) { ast_sip_unregister_service(&multihomed_module); diff --git a/res/res_pjsip_pubsub.c b/res/res_pjsip_pubsub.c index e90502485..f0467627e 100644 --- a/res/res_pjsip_pubsub.c +++ b/res/res_pjsip_pubsub.c @@ -123,6 +123,9 @@ <configOption name="expires"> <synopsis>The time at which the subscription expires</synopsis> </configOption> + <configOption name="contact_uri"> + <synopsis>The Contact URI of the dialog for the subscription</synopsis> + </configOption> </configObject> <configObject name="resource_list"> <synopsis>Resource list configuration parameters.</synopsis> @@ -376,6 +379,8 @@ struct subscription_persistence { char *tag; /*! When this subscription expires */ struct timeval expires; + /*! Contact URI */ + char contact_uri[PJSIP_MAX_URL_SIZE]; }; /*! @@ -591,8 +596,8 @@ static void subscription_persistence_update(struct sip_subscription_tree *sub_tr return; } - ast_debug(3, "Updating persistence for '%s->%s'\n", - ast_sorcery_object_get_id(sub_tree->endpoint), sub_tree->root->resource); + ast_debug(3, "Updating persistence for '%s->%s'\n", sub_tree->persistence->endpoint, + sub_tree->root->resource); dlg = sub_tree->dlg; sub_tree->persistence->cseq = dlg->local.cseq; @@ -600,10 +605,14 @@ static void subscription_persistence_update(struct sip_subscription_tree *sub_tr if (rdata) { int expires; pjsip_expires_hdr *expires_hdr = pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_EXPIRES, NULL); + pjsip_contact_hdr *contact_hdr = pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_CONTACT, NULL); expires = expires_hdr ? expires_hdr->ivalue : DEFAULT_PUBLISH_EXPIRES; sub_tree->persistence->expires = ast_tvadd(ast_tvnow(), ast_samp2tv(expires, 1)); + pjsip_uri_print(PJSIP_URI_IN_CONTACT_HDR, contact_hdr->uri, + sub_tree->persistence->contact_uri, sizeof(sub_tree->persistence->contact_uri)); + /* When receiving a packet on an streaming transport, it's possible to receive more than one SIP * message at a time into the rdata->pkt_info.packet buffer. However, the rdata->msg_info.msg_buf * will always point to the proper SIP message that is to be processed. When updating subscription @@ -1550,8 +1559,9 @@ static int subscription_persistence_recreate(void *obj, void *arg, int flags) pj_pool_reset(pool); rdata.tp_info.pool = pool; - if (ast_sip_create_rdata(&rdata, persistence->packet, persistence->src_name, persistence->src_port, - persistence->transport_key, persistence->local_name, persistence->local_port)) { + if (ast_sip_create_rdata_with_contact(&rdata, persistence->packet, persistence->src_name, + persistence->src_port, persistence->transport_key, persistence->local_name, + persistence->local_port, persistence->contact_uri)) { ast_log(LOG_WARNING, "Failed recreating '%s' subscription: The message could not be parsed\n", persistence->endpoint); ast_sorcery_delete(ast_sip_get_sorcery(), persistence); @@ -1703,28 +1713,6 @@ void *ast_sip_subscription_get_header(const struct ast_sip_subscription *sub, co return pjsip_msg_find_hdr_by_name(msg, &name, NULL); } -/*! - * \internal - * \brief Wrapper for pjsip_evsub_send_request - * - * This function (re)sets the transport before sending to catch cases - * where the transport might have changed. - * - * If pjproject gives us the ability to resend, we'll only reset the transport - * if PJSIP_ETPNOTAVAIL is returned from send. - * - * \returns pj_status_t - */ -static pj_status_t internal_pjsip_evsub_send_request(struct sip_subscription_tree *sub_tree, pjsip_tx_data *tdata) -{ - pjsip_tpselector selector = { .type = PJSIP_TPSELECTOR_NONE, }; - - ast_sip_set_tpselector_from_transport_name(sub_tree->endpoint->transport, &selector); - pjsip_dlg_set_transport(sub_tree->dlg, &selector); - - return pjsip_evsub_send_request(sub_tree->evsub, tdata); -} - /* XXX This function is not used. */ struct ast_sip_subscription *ast_sip_create_subscription(const struct ast_sip_subscription_handler *handler, struct ast_sip_endpoint *endpoint, const char *resource) @@ -1772,7 +1760,7 @@ struct ast_sip_subscription *ast_sip_create_subscription(const struct ast_sip_su evsub = sub_tree->evsub; if (pjsip_evsub_initiate(evsub, NULL, -1, &tdata) == PJ_SUCCESS) { - internal_pjsip_evsub_send_request(sub_tree, tdata); + pjsip_evsub_send_request(sub_tree->evsub, tdata); } else { /* pjsip_evsub_terminate will result in pubsub_on_evsub_state, * being called and terminating the subscription. Therefore, we don't @@ -1869,7 +1857,7 @@ static int sip_subscription_send_request(struct sip_subscription_tree *sub_tree, return -1; } - res = internal_pjsip_evsub_send_request(sub_tree, tdata); + res = pjsip_evsub_send_request(sub_tree->evsub, tdata); subscription_persistence_update(sub_tree, NULL, SUBSCRIPTION_PERSISTENCE_SEND_REQUEST); @@ -5283,6 +5271,8 @@ static int load_module(void) persistence_tag_str2struct, persistence_tag_struct2str, NULL, 0, 0); ast_sorcery_object_field_register_custom(sorcery, "subscription_persistence", "expires", "", persistence_expires_str2struct, persistence_expires_struct2str, NULL, 0, 0); + ast_sorcery_object_field_register(sorcery, "subscription_persistence", "contact_uri", "", OPT_CHAR_ARRAY_T, 0, + CHARFLDSET(struct subscription_persistence, contact_uri)); if (apply_list_configuration(sorcery)) { ast_sip_unregister_service(&pubsub_module); diff --git a/res/res_pjsip_sdp_rtp.c b/res/res_pjsip_sdp_rtp.c index 75dc83929..a82475774 100644 --- a/res/res_pjsip_sdp_rtp.c +++ b/res/res_pjsip_sdp_rtp.c @@ -196,6 +196,20 @@ static int create_rtp(struct ast_sip_session *session, struct ast_sip_session_me if (session->endpoint->media.bind_rtp_to_media_address && !ast_strlen_zero(session->endpoint->media.address)) { ast_sockaddr_parse(&temp_media_address, session->endpoint->media.address, 0); media_address = &temp_media_address; + } else { + struct ast_sip_transport *transport = + ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "transport", + session->endpoint->transport); + + if (transport && transport->state) { + char hoststr[PJ_INET6_ADDRSTRLEN]; + + pj_sockaddr_print(&transport->state->host, hoststr, sizeof(hoststr), 0); + ast_debug(1, "Transport: %s bound to host: %s, using this for media.\n", + session->endpoint->transport, hoststr); + ast_sockaddr_parse(media_address, hoststr, 0); + } + ao2_cleanup(transport); } if (!(session_media->rtp = ast_rtp_instance_new(session->endpoint->media.rtp.engine, sched, media_address, NULL))) { @@ -217,7 +231,7 @@ static int create_rtp(struct ast_sip_session *session, struct ast_sip_session_me } if (!strcmp(session_media->stream_type, STR_AUDIO) && - (session->endpoint->media.tos_audio || session->endpoint->media.cos_video)) { + (session->endpoint->media.tos_audio || session->endpoint->media.cos_audio)) { ast_rtp_instance_set_qos(session_media->rtp, session->endpoint->media.tos_audio, session->endpoint->media.cos_audio, "SIP RTP Audio"); } else if (!strcmp(session_media->stream_type, STR_VIDEO) && diff --git a/res/res_pjsip_session.c b/res/res_pjsip_session.c index 609d08dc0..de073d304 100644 --- a/res/res_pjsip_session.c +++ b/res/res_pjsip_session.c @@ -973,32 +973,10 @@ int ast_sip_session_refresh(struct ast_sip_session *session, return 0; } -/*! - * \internal - * \brief Wrapper for pjsip_inv_send_msg - * - * This function (re)sets the transport before sending to catch cases - * where the transport might have changed. - * - * If pjproject gives us the ability to resend, we'll only reset the transport - * if PJSIP_ETPNOTAVAIL is returned from send. - * - * \returns pj_status_t - */ -static pj_status_t internal_pjsip_inv_send_msg(pjsip_inv_session *inv, const char *transport_name, pjsip_tx_data *tdata) -{ - pjsip_tpselector selector = { .type = PJSIP_TPSELECTOR_NONE, }; - - ast_sip_set_tpselector_from_transport_name(transport_name, &selector); - pjsip_dlg_set_transport(inv->dlg, &selector); - - return pjsip_inv_send_msg(inv, tdata); -} - void ast_sip_session_send_response(struct ast_sip_session *session, pjsip_tx_data *tdata) { handle_outgoing_response(session, tdata); - internal_pjsip_inv_send_msg(session->inv_session, session->endpoint->transport, tdata); + pjsip_inv_send_msg(session->inv_session, tdata); return; } @@ -1229,7 +1207,7 @@ void ast_sip_session_send_request_with_cb(struct ast_sip_session *session, pjsip MOD_DATA_ON_RESPONSE, on_response); handle_outgoing_request(session, tdata); - internal_pjsip_inv_send_msg(session->inv_session, session->endpoint->transport, tdata); + pjsip_inv_send_msg(session->inv_session, tdata); return; } @@ -2051,7 +2029,7 @@ static pjsip_inv_session *pre_session_setup(pjsip_rx_data *rdata, const struct a if (pjsip_inv_initial_answer(inv_session, rdata, 500, NULL, NULL, &tdata) != PJ_SUCCESS) { pjsip_inv_terminate(inv_session, 500, PJ_FALSE); } - internal_pjsip_inv_send_msg(inv_session, endpoint->transport, tdata); + pjsip_inv_send_msg(inv_session, tdata); return NULL; } return inv_session; @@ -2222,7 +2200,7 @@ static void handle_new_invite_request(pjsip_rx_data *rdata) if (pjsip_inv_initial_answer(inv_session, rdata, 500, NULL, NULL, &tdata) == PJ_SUCCESS) { pjsip_inv_terminate(inv_session, 500, PJ_FALSE); } else { - internal_pjsip_inv_send_msg(inv_session, endpoint->transport, tdata); + pjsip_inv_send_msg(inv_session, tdata); } } return; @@ -2234,7 +2212,7 @@ static void handle_new_invite_request(pjsip_rx_data *rdata) if (pjsip_inv_initial_answer(inv_session, rdata, 500, NULL, NULL, &tdata) == PJ_SUCCESS) { pjsip_inv_terminate(inv_session, 500, PJ_FALSE); } else { - internal_pjsip_inv_send_msg(inv_session, endpoint->transport, tdata); + pjsip_inv_send_msg(inv_session, tdata); } #ifdef HAVE_PJSIP_INV_SESSION_REF pjsip_inv_dec_ref(inv_session); @@ -2247,7 +2225,7 @@ static void handle_new_invite_request(pjsip_rx_data *rdata) if (pjsip_inv_initial_answer(inv_session, rdata, 500, NULL, NULL, &tdata) == PJ_SUCCESS) { pjsip_inv_terminate(inv_session, 500, PJ_FALSE); } else { - internal_pjsip_inv_send_msg(inv_session, endpoint->transport, tdata); + pjsip_inv_send_msg(inv_session, tdata); } #ifdef HAVE_PJSIP_INV_SESSION_REF pjsip_inv_dec_ref(inv_session); diff --git a/res/res_rtp_asterisk.c b/res/res_rtp_asterisk.c index a67bc8135..88201837d 100644 --- a/res/res_rtp_asterisk.c +++ b/res/res_rtp_asterisk.c @@ -1577,7 +1577,7 @@ static int ast_rtp_dtls_active(struct ast_rtp_instance *instance) static void ast_rtp_dtls_stop(struct ast_rtp_instance *instance) { struct ast_rtp *rtp = ast_rtp_instance_get_data(instance); - int rtcp_dtls_unique = (rtp->dtls.ssl != rtp->rtcp->dtls.ssl); + SSL *ssl = rtp->dtls.ssl; dtls_srtp_stop_timeout_timer(instance, rtp, 0); @@ -1595,7 +1595,7 @@ static void ast_rtp_dtls_stop(struct ast_rtp_instance *instance) if (rtp->rtcp) { dtls_srtp_stop_timeout_timer(instance, rtp, 1); - if (rtp->rtcp->dtls.ssl && rtcp_dtls_unique) { + if (rtp->rtcp->dtls.ssl && (rtp->rtcp->dtls.ssl != ssl)) { SSL_free(rtp->rtcp->dtls.ssl); rtp->rtcp->dtls.ssl = NULL; ast_mutex_destroy(&rtp->rtcp->dtls.lock); @@ -4426,7 +4426,7 @@ static struct ast_frame *ast_rtcp_read(struct ast_rtp_instance *instance) return &ast_null_frame; } - if (!*(read_area)) { + if (!*read_area) { struct sockaddr_in addr_tmp; struct ast_sockaddr addr_v4; @@ -4448,7 +4448,7 @@ static struct ast_frame *ast_rtcp_read(struct ast_rtp_instance *instance) return &ast_null_frame; } - return ast_rtcp_interpret(instance, read_area, read_area_size, &addr); + return ast_rtcp_interpret(instance, read_area, res, &addr); } static int bridge_p2p_rtp_write(struct ast_rtp_instance *instance, unsigned int *rtpheader, int len, int hdrlen) @@ -4633,7 +4633,7 @@ static struct ast_frame *ast_rtp_read(struct ast_rtp_instance *instance, int rtc /* This could be a multiplexed RTCP packet. If so, be sure to interpret it correctly */ if (rtcp_mux(rtp, read_area)) { - return ast_rtcp_interpret(instance, read_area, read_area_size, &addr); + return ast_rtcp_interpret(instance, read_area, res, &addr); } /* Make sure the data that was read in is actually enough to make up an RTP packet */ @@ -5040,7 +5040,9 @@ static void ast_rtp_prop_set(struct ast_rtp_instance *instance, enum ast_rtp_pro return; } rtp->rtcp->s = -1; +#ifdef HAVE_OPENSSL_SRTP rtp->rtcp->dtls.timeout_timer = -1; +#endif rtp->rtcp->schedid = -1; } |