[asterisk-commits] mjordan: branch 1.8 r351027 - /branches/1.8/channels/chan_sip.c
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Jan 16 13:09:55 CST 2012
Author: mjordan
Date: Mon Jan 16 13:09:45 2012
New Revision: 351027
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=351027
Log:
Create and initialize udptl only when dialog negotiates for image media
Prior to this patch, the udptl struct was allocated and initialized when a
dialog was associated with a peer that supported T.38, when a new SIP
channel was allocated, or what an INVITE request was received. This resulted
in any dialog associated with a peer that supported T.38 having udptl support
assigned to it, including the UDP ports needed for communication. This
occurred even in non-INVITE dialogs that would never send image media.
This patch creates and initializes the udptl structure only when the SDP
for a dialog specifies that image media is supported, or when Asterisk
indicates through the appropriate control frame that a dialog is to support
T.38.
(closes issue ASTERISK-16698)
Reported by: under
Tested by: Stefan Schmidt
Patches: udptl_20120113.diff uploaded by mjordan (License #6283)
(closes issue ASTERISK-16794)
Reported by: Elazar Broad
Tested by: Stefan Schmidt
review: https://reviewboard.asterisk.org/r/1668/
Modified:
branches/1.8/channels/chan_sip.c
Modified: branches/1.8/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/channels/chan_sip.c?view=diff&rev=351027&r1=351026&r2=351027
==============================================================================
--- branches/1.8/channels/chan_sip.c (original)
+++ branches/1.8/channels/chan_sip.c Mon Jan 16 13:09:45 2012
@@ -5217,20 +5217,6 @@
ast_copy_flags(&dialog->flags[2], &peer->flags[2], SIP_PAGE3_FLAGS_TO_COPY);
dialog->capability = peer->capability;
dialog->prefs = peer->prefs;
- if (ast_test_flag(&dialog->flags[1], SIP_PAGE2_T38SUPPORT)) {
- /* t38pt_udptl was enabled in the peer and not in [general] */
- if (dialog->udptl || (!dialog->udptl && (dialog->udptl = ast_udptl_new_with_bindaddr(sched, io, 0, &bindaddr)))) {
- dialog->t38_maxdatagram = peer->t38_maxdatagram;
- set_t38_capabilities(dialog);
- } else {
- /* It is impossible to support T38 without udptl */
- ast_debug(1, "UDPTL creation failed on dialog.\n");
- ast_clear_flag(&dialog->flags[1], SIP_PAGE2_T38SUPPORT);
- }
- } else if (dialog->udptl) {
- ast_udptl_destroy(dialog->udptl);
- dialog->udptl = NULL;
- }
ast_string_field_set(dialog, engine, peer->engine);
@@ -6740,6 +6726,53 @@
return res;
}
+/*! \internal \brief Create and initialize UDPTL for the specified dialog
+ * \param p SIP private structure to create UDPTL object for
+ * \pre p is locked
+ * \pre p->owner is locked
+ *
+ * \note In the case of failure, SIP_PAGE2_T38SUPPORT is cleared on p
+ *
+ * \return 0 on success, any other value on failure
+ */
+static int initialize_udptl(struct sip_pvt *p)
+{
+ int natflags = ast_test_flag(&p->flags[1], SIP_PAGE2_SYMMETRICRTP);
+
+ if (!ast_test_flag(&p->flags[1], SIP_PAGE2_T38SUPPORT)) {
+ return 1;
+ }
+
+ if (!p->owner) {
+ ast_log(AST_LOG_WARNING, "Attempted to create UDPTL for dialog with no channel - disabling T38 for this dialog\n");
+ ast_clear_flag(&p->flags[1], SIP_PAGE2_T38SUPPORT);
+ return 1;
+ }
+
+ /* If we've already initialized T38, don't take any further action */
+ if (p->udptl) {
+ return 0;
+ }
+
+ /* 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))) {
+ ast_channel_set_fd(p->owner, 5, ast_udptl_fd(p->udptl));
+
+ ast_udptl_setqos(p->udptl, global_tos_audio, global_cos_audio);
+ p->t38_maxdatagram = p->relatedpeer ? p->relatedpeer->t38_maxdatagram : global_t38_maxdatagram;
+ set_t38_capabilities(p);
+
+ ast_debug(1, "Setting NAT on UDPTL to %s\n", natflags ? "On" : "Off");
+ ast_udptl_setnat(p->udptl, natflags);
+ } else {
+ ast_log(AST_LOG_WARNING, "UDPTL creation failed - disabling T38 for this dialog\n");
+ ast_clear_flag(&p->flags[1], SIP_PAGE2_T38SUPPORT);
+ return 1;
+ }
+
+ return 0;
+}
+
/*! \brief Play indication to user
* With SIP a lot of indications is sent as messages, letting the device play
the indication - busy signal, congestion etc
@@ -6847,12 +6880,14 @@
res = -1;
break;
case AST_CONTROL_T38_PARAMETERS:
+ res = -1;
if (datalen != sizeof(struct ast_control_t38_parameters)) {
ast_log(LOG_ERROR, "Invalid datalen for AST_CONTROL_T38_PARAMETERS. Expected %d, got %d\n", (int) sizeof(struct ast_control_t38_parameters), (int) datalen);
- res = -1;
} else {
const struct ast_control_t38_parameters *parameters = data;
- res = interpret_t38_parameters(p, parameters);
+ if (!initialize_udptl(p)) {
+ res = interpret_t38_parameters(p, parameters);
+ }
}
break;
case AST_CONTROL_SRCUPDATE:
@@ -7031,7 +7066,9 @@
}
}
- /* Set file descriptors for audio, video, realtime text and UDPTL as needed */
+ /* Set file descriptors for audio, video, and realtime text. Since
+ * 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));
@@ -7040,10 +7077,9 @@
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));
}
- if (needtext && i->trtp)
+ if (needtext && i->trtp) {
ast_channel_set_fd(tmp, 4, ast_rtp_instance_fd(i->trtp, 0));
- if (i->udptl)
- ast_channel_set_fd(tmp, 5, ast_udptl_fd(i->udptl));
+ }
if (state == AST_STATE_RING)
tmp->rings = 1;
@@ -7637,16 +7673,6 @@
p->allowed_methods = UINT_MAX;
if (sip_methods[intended_method].need_rtp) {
- if (ast_test_flag(&p->flags[1], SIP_PAGE2_T38SUPPORT)) {
- if ((p->udptl = ast_udptl_new_with_bindaddr(sched, io, 0, &bindaddr))) {
- ast_udptl_setqos(p->udptl, global_tos_audio, global_cos_audio);
- p->t38_maxdatagram = global_t38_maxdatagram;
- } else {
- /* udptl creation failed, T38 can not be supported on this dialog */
- ast_log(LOG_ERROR, "UDPTL creation failed\n");
- ast_clear_flag(&p->flags[1], SIP_PAGE2_T38SUPPORT);
- }
- }
p->maxcallbitrate = default_maxcallbitrate;
p->autoframing = global_autoframing;
}
@@ -7674,11 +7700,8 @@
p->capability = sip_cfg.capability;
p->allowtransfer = sip_cfg.allowtransfer;
if ((ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_RFC2833) ||
- (ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_AUTO))
+ (ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_AUTO)) {
p->noncodeccapability |= AST_RTP_DTMF;
- if (p->udptl) {
- p->t38_maxdatagram = global_t38_maxdatagram;
- set_t38_capabilities(p);
}
ast_string_field_set(p, context, sip_cfg.default_context);
ast_string_field_set(p, parkinglot, default_parkinglot);
@@ -8918,8 +8941,12 @@
ast_rtp_codecs_payloads_set_m_type(&newtextrtp, NULL, codec);
}
/* Search for image media definition */
- } else if (p->udptl && ((sscanf(m, "image %30u udptl t38%n", &x, &len) == 1 && len > 0 && x) ||
+ } else if (((sscanf(m, "image %30u udptl t38%n", &x, &len) == 1 && len > 0 && x) ||
(sscanf(m, "image %30u UDPTL t38%n", &x, &len) == 1 && len > 0 && x) )) {
+ if (initialize_udptl(p)) {
+ continue;
+ }
+
if (p->offered_media[SDP_IMAGE].order_offered) {
ast_log(LOG_WARNING, "Multiple T.38 streams are not supported\n");
return -3;
@@ -9596,6 +9623,10 @@
int found = FALSE;
char s[256];
unsigned int x;
+
+ if (initialize_udptl(p)) {
+ return found;
+ }
if ((sscanf(a, "T38FaxMaxBuffer:%30u", &x) == 1)) {
ast_debug(3, "MaxBufferSize:%d\n", x);
@@ -22400,17 +22431,6 @@
}
if (authpeer) {
p->relatedpeer = ref_peer(authpeer, "setting dialog's relatedpeer pointer");
- }
- /* If T38 is needed but not present, then make it magically appear */
- if (ast_test_flag(&p->flags[1], SIP_PAGE2_T38SUPPORT) && !p->udptl) {
- if ((p->udptl = ast_udptl_new_with_bindaddr(sched, io, 0, &bindaddr))) {
- p->t38_maxdatagram = global_t38_maxdatagram;
- set_t38_capabilities(p);
- } else {
- /* udptl creation failed, T38 can not be supported on this dialog */
- ast_debug(1, "UDPTL creation failed on dialog.\n");
- ast_clear_flag(&p->flags[1], SIP_PAGE2_T38SUPPORT);
- }
}
req->authenticated = 1;
More information about the asterisk-commits
mailing list