[asterisk-commits] rizzo: trunk r44674 - /trunk/channels/chan_sip.c
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Sat Oct 7 05:20:17 MST 2006
Author: rizzo
Date: Sat Oct 7 07:20:16 2006
New Revision: 44674
URL: http://svn.digium.com/view/asterisk?rev=44674&view=rev
Log:
put repeated code to set nat mode in a function.
Modified:
trunk/channels/chan_sip.c
Modified: trunk/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_sip.c?rev=44674&r1=44673&r2=44674&view=diff
==============================================================================
--- trunk/channels/chan_sip.c (original)
+++ trunk/channels/chan_sip.c Sat Oct 7 07:20:16 2006
@@ -2501,13 +2501,33 @@
return u;
}
+/*! \brief Set nat mode on the various data sockets */
+static void do_setnat(struct sip_pvt *p, int natflags)
+{
+ const char *mode = natflags ? "On" : "Off";
+
+ if (p->rtp) {
+ if (option_debug)
+ ast_log(LOG_DEBUG, "Setting NAT on RTP to %s\n", mode);
+ ast_rtp_setnat(p->rtp, natflags);
+ }
+ if (p->vrtp) {
+ if (option_debug)
+ ast_log(LOG_DEBUG, "Setting NAT on VRTP to %s\n", mode);
+ ast_rtp_setnat(p->vrtp, natflags);
+ }
+ if (p->udptl) {
+ if (option_debug)
+ ast_log(LOG_DEBUG, "Setting NAT on UDPTL to %s\n", mode);
+ ast_udptl_setnat(p->udptl, natflags);
+ }
+}
+
/*! \brief Create address structure from peer reference.
* return -1 on error, 0 on success.
*/
static int create_addr_from_peer(struct sip_pvt *dialog, struct sip_peer *peer)
{
- int natflags;
-
if ((peer->addr.sin_addr.s_addr || peer->defaddr.sin_addr.s_addr) &&
(!peer->maxms || ((peer->lastms >= 0) && (peer->lastms <= peer->maxms)))) {
dialog->sa = (peer->addr.sin_addr.s_addr) ? peer->addr : peer->defaddr;
@@ -2541,26 +2561,17 @@
ast_udptl_destroy(dialog->udptl);
dialog->udptl = NULL;
}
- natflags = ast_test_flag(&dialog->flags[0], SIP_NAT) & SIP_NAT_ROUTE;
+ do_setnat(dialog, ast_test_flag(&dialog->flags[0], SIP_NAT) & SIP_NAT_ROUTE );
+
if (dialog->rtp) {
- if (option_debug)
- ast_log(LOG_DEBUG, "Setting NAT on RTP to %s\n", natflags ? "On" : "Off");
- ast_rtp_setnat(dialog->rtp, natflags);
ast_rtp_setdtmf(dialog->rtp, ast_test_flag(&dialog->flags[0], SIP_DTMF) != SIP_DTMF_INFO);
ast_rtp_setdtmfcompensate(dialog->rtp, ast_test_flag(&dialog->flags[1], SIP_PAGE2_RFC2833_COMPENSATE));
}
if (dialog->vrtp) {
- if (option_debug)
- ast_log(LOG_DEBUG, "Setting NAT on VRTP to %s\n", natflags ? "On" : "Off");
- ast_rtp_setnat(dialog->vrtp, natflags);
ast_rtp_setdtmf(dialog->vrtp, 0);
ast_rtp_setdtmfcompensate(dialog->vrtp, 0);
}
- if (dialog->udptl) {
- if (option_debug)
- ast_log(LOG_DEBUG, "Setting NAT on UDPTL to %s\n", natflags ? "On" : "Off");
- ast_udptl_setnat(dialog->udptl, natflags);
- }
+
/* Set Frame packetization */
if (dialog->rtp) {
ast_rtp_codec_setpref(dialog->rtp, &dialog->prefs);
@@ -4131,17 +4142,10 @@
}
if (useglobal_nat && sin) {
- int natflags;
/* Setup NAT structure according to global settings if we have an address */
ast_copy_flags(&p->flags[0], &global_flags[0], SIP_NAT);
p->recv = *sin;
- natflags = ast_test_flag(&p->flags[0], SIP_NAT) & SIP_NAT_ROUTE;
- if (p->rtp)
- ast_rtp_setnat(p->rtp, natflags);
- if (p->vrtp)
- ast_rtp_setnat(p->vrtp, natflags);
- if (p->udptl)
- ast_udptl_setnat(p->udptl, natflags);
+ do_setnat(p, ast_test_flag(&p->flags[0], SIP_NAT) & SIP_NAT_ROUTE);
}
if (p->method != SIP_REGISTER)
@@ -8687,7 +8691,6 @@
char calleridname[50];
int debug=sip_debug_test_addr(sin);
struct ast_variable *tmpvar = NULL, *v = NULL;
- int usenatroute;
char *uri2 = ast_strdupa(uri);
/* Terminate URI */
@@ -8772,23 +8775,8 @@
ast_string_field_set(p, cid_num, tmp);
}
- usenatroute = ast_test_flag(&p->flags[0], SIP_NAT_ROUTE);
-
- if (p->rtp) {
- if (option_debug)
- ast_log(LOG_DEBUG, "Setting NAT on RTP to %s\n", usenatroute ? "On" : "Off");
- ast_rtp_setnat(p->rtp, usenatroute);
- }
- if (p->vrtp) {
- if (option_debug)
- ast_log(LOG_DEBUG, "Setting NAT on VRTP to %s\n", usenatroute ? "On" : "Off");
- ast_rtp_setnat(p->vrtp, usenatroute);
- }
- if (p->udptl) {
- if (option_debug)
- ast_log(LOG_DEBUG, "Setting NAT on UDPTL to %s\n", usenatroute ? "On" : "Off");
- ast_udptl_setnat(p->udptl, usenatroute);
- }
+ do_setnat(p, ast_test_flag(&p->flags[0], SIP_NAT_ROUTE) );
+
if (!(res = check_auth(p, req, user->name, user->secret, user->md5secret, sipmethod, uri2, reliable, ast_test_flag(req, SIP_PKT_IGNORE)))) {
sip_cancel_destroy(p);
ast_copy_flags(&p->flags[0], &user->flags[0], SIP_FLAGS_TO_COPY);
@@ -8894,22 +8882,8 @@
ast_shrink_phone_number(tmp);
ast_string_field_set(p, cid_num, tmp);
}
- usenatroute = ast_test_flag(&p->flags[0], SIP_NAT_ROUTE);
- if (p->rtp) {
- if (option_debug)
- ast_log(LOG_DEBUG, "Setting NAT on RTP to %s\n", usenatroute ? "On" : "Off");
- ast_rtp_setnat(p->rtp, usenatroute);
- }
- if (p->vrtp) {
- if (option_debug)
- ast_log(LOG_DEBUG, "Setting NAT on VRTP to %s\n", usenatroute ? "On" : "Off");
- ast_rtp_setnat(p->vrtp, usenatroute);
- }
- if (p->udptl) {
- if (option_debug)
- ast_log(LOG_DEBUG, "Setting NAT on UDPTL to %s\n", usenatroute ? "On" : "Off");
- ast_udptl_setnat(p->udptl, usenatroute);
- }
+ do_setnat(p, ast_test_flag(&p->flags[0], SIP_NAT_ROUTE));
+
ast_string_field_set(p, peersecret, peer->secret);
ast_string_field_set(p, peermd5secret, peer->md5secret);
ast_string_field_set(p, subscribecontext, peer->subscribecontext);
More information about the asterisk-commits
mailing list