[svn-commits] oej: branch oej/sip-max-forwards-trunk r275991 - in /team/oej/sip-max-forward...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Jul 13 11:15:01 CDT 2010


Author: oej
Date: Tue Jul 13 11:14:47 2010
New Revision: 275991

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=275991
Log:
Update max-forwards support to trunk

Modified:
    team/oej/sip-max-forwards-trunk/channels/chan_sip.c
    team/oej/sip-max-forwards-trunk/channels/sip/include/sip.h
    team/oej/sip-max-forwards-trunk/configs/sip.conf.sample
    team/oej/sip-max-forwards-trunk/doc/tex/channelvariables.tex

Modified: team/oej/sip-max-forwards-trunk/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/oej/sip-max-forwards-trunk/channels/chan_sip.c?view=diff&rev=275991&r1=275990&r2=275991
==============================================================================
--- team/oej/sip-max-forwards-trunk/channels/chan_sip.c (original)
+++ team/oej/sip-max-forwards-trunk/channels/chan_sip.c Tue Jul 13 11:14:47 2010
@@ -417,6 +417,9 @@
 					<enum name="useragent">
 						<para>Current user agent id for peer.</para>
 					</enum>
+					<enum name="maxforwards">
+						<para>The value used for SIP loop prevention in outbound requests</para>
+					</enum>
 					<enum name="chanvar[name]">
 						<para>A channel variable configured with setvar for this peer.</para>
 					</enum>
@@ -1483,6 +1486,7 @@
 static void build_callid_registry(struct sip_registry *reg, const struct ast_sockaddr *ourip, const char *fromdomain);
 static void make_our_tag(char *tagbuf, size_t len);
 static int add_header(struct sip_request *req, const char *var, const char *value);
+static int add_header_max_forwards(struct sip_pvt *dialog, struct sip_request *req);
 static int add_content(struct sip_request *req, const char *line);
 static int finalize_content(struct sip_request *req);
 static int add_text(struct sip_request *req, const char *text);
@@ -6932,6 +6936,7 @@
 	p->session_modify = TRUE;
 	p->stimer = NULL;
 	p->prefs = default_prefs;		/* Set default codecs for this call */
+	p->maxforwards = sip_cfg.default_max_forwards;
 
 	if (intended_method != SIP_OPTIONS) {	/* Peerpoke has it's own system */
 		p->timer_t1 = global_t1;	/* Default SIP retransmission timer T1 (RFC 3261) */
@@ -8729,6 +8734,23 @@
 	return 0;	
 }
 
+/*! \brief Add 'Max-Forwards' header to SIP message */
+static int add_header_max_forwards(struct sip_pvt *dialog, struct sip_request *req)
+{
+	char clen[10];
+	const char *max = NULL;
+
+	if (dialog->owner) {
+ 		max = pbx_builtin_getvar_helper(dialog->owner, "SIP_MAX_FORWARDS");
+	}
+
+	/* The channel variable overrides the peer/channel value */
+	if (max == NULL) {
+		snprintf(clen, sizeof(clen), "%d", dialog->maxforwards);
+	}
+	return add_header(req, "Max-Forwards", max != NULL ? max : clen);
+}
+
 /*! \brief Add 'Content-Length' header and content to SIP message */
 static int finalize_content(struct sip_request *req)
 {
@@ -9227,7 +9249,7 @@
 		set_destination(p, p->route->hop);
 		add_route(req, is_strict ? p->route->next : p->route);
 	}
-	add_header(req, "Max-Forwards", DEFAULT_MAX_FORWARDS);
+	add_header_max_forwards(p, req);
 
 	ot = get_header(orig, "To");
 	of = get_header(orig, "From");
@@ -10782,7 +10804,7 @@
 	snprintf(tmp_n, sizeof(tmp_n), "%d %s", ++p->ocseq, sip_methods[sipmethod].text);
 
 	add_header(req, "Via", p->via);
-	add_header(req, "Max-Forwards", DEFAULT_MAX_FORWARDS);
+	add_header_max_forwards(p, req);
 	/* This will be a no-op most of the time. However, under certain circumstances,
 	 * NOTIFY messages will use this function for preparing the request and should
 	 * have Route headers present.
@@ -11921,7 +11943,7 @@
 
 	build_via(p);
 	add_header(&req, "Via", p->via);
-	add_header(&req, "Max-Forwards", DEFAULT_MAX_FORWARDS);
+	add_header_max_forwards(p, &req);
 	add_header(&req, "From", from);
 	add_header(&req, "To", to);
 	add_header(&req, "Call-ID", p->callid);
@@ -14421,6 +14443,9 @@
 		p->capability = peer->capability;
 		p->prefs = peer->prefs;
 		p->jointcapability = peer->capability;
+ 		if (peer->maxforwards > 0) {
+			p->maxforwards = peer->maxforwards;
+		}
 		if (p->peercapability)
 			p->jointcapability &= p->peercapability;
 		p->maxcallbitrate = peer->maxcallbitrate;
@@ -15748,6 +15773,7 @@
 		ast_cli(fd, "  VM Extension : %s\n", peer->vmexten);
 		ast_cli(fd, "  LastMsgsSent : %d/%d\n", (peer->lastmsgssent & 0x7fff0000) >> 16, peer->lastmsgssent & 0xffff);
 		ast_cli(fd, "  Call limit   : %d\n", peer->call_limit);
+		ast_cli(fd, "  Max forwards : %d\n", peer->maxforwards);
 		if (peer->busy_level)
 			ast_cli(fd, "  Busy level   : %d\n", peer->busy_level);
 		ast_cli(fd, "  Dynamic      : %s\n", AST_CLI_YESNO(peer->host_dynamic));
@@ -15858,7 +15884,9 @@
 		peer_mailboxes_to_str(&mailbox_str, peer);
 		astman_append(s, "VoiceMailbox: %s\r\n", mailbox_str->str);
 		astman_append(s, "TransferMode: %s\r\n", transfermode2str(peer->allowtransfer));
+		astman_append(s, "Maxforwards: %d\r\n", peer->maxforwards);
 		astman_append(s, "LastMsgsSent: %d\r\n", peer->lastmsgssent);
+		astman_append(s, "Maxforwards: %d\r\n", peer->maxforwards);
 		astman_append(s, "Call-limit: %d\r\n", peer->call_limit);
 		astman_append(s, "Busy-level: %d\r\n", peer->busy_level);
 		astman_append(s, "MaxCallBR: %d kbps\r\n", peer->maxcallbitrate);
@@ -16434,6 +16462,7 @@
 	ast_cli(a->fd, "  Timer T1 minimum:       %d\n", global_t1min);
  	ast_cli(a->fd, "  Timer B:                %d\n", global_timer_b);
 	ast_cli(a->fd, "  No premature media:     %s\n", AST_CLI_YESNO(global_prematuremediafilter));
+	ast_cli(a->fd, "  Max forwards:           %d\n", sip_cfg.default_max_forwards);
 
 	ast_cli(a->fd, "\nDefault Settings:\n");
 	ast_cli(a->fd, "-----------------\n");
@@ -17654,6 +17683,8 @@
 		snprintf(buf, len, "%d", peer->busy_level);
 	} else  if (!strcasecmp(colname, "curcalls")) {
 		snprintf(buf, len, "%d", peer->inUse);
+	} else if (!strcasecmp(colname, "maxforwards")) {
+		snprintf(buf, len, "%d", peer->maxforwards);
 	} else  if (!strcasecmp(colname, "accountcode")) {
 		ast_copy_string(buf, peer->accountcode, len);
 	} else  if (!strcasecmp(colname, "callgroup")) {
@@ -25477,6 +25508,8 @@
 				} else {
 					peer->amaflags = format;
 				}
+			} else if (!strcasecmp(v->name, "maxforwards")) {
+				peer->maxforwards = abs(atoi(v->value));
 			} else if (!strcasecmp(v->name, "accountcode")) {
 				ast_string_field_set(peer, accountcode, v->value);
 			} else if (!strcasecmp(v->name, "mohinterpret")) {
@@ -26044,6 +26077,7 @@
 	/* Initialize some reasonable defaults at SIP reload (used both for channel and as default for devices */
 	ast_copy_string(sip_cfg.default_context, DEFAULT_CONTEXT, sizeof(sip_cfg.default_context));
 	sip_cfg.default_subscribecontext[0] = '\0';
+	sip_cfg.default_max_forwards = DEFAULT_MAX_FORWARDS;
 	default_language[0] = '\0';
 	default_fromdomain[0] = '\0';
 	default_fromdomainport = 0;
@@ -26524,6 +26558,8 @@
 			}
 		} else if (!strcasecmp(v->name, "use_q850_reason")) {
 			ast_set2_flag(&global_flags[1], ast_true(v->value), SIP_PAGE2_Q850_REASON);
+		} else if (!strcasecmp(v->name, "maxforwards")) {
+			sip_cfg.default_max_forwards = atoi(v->value);
 		} else if (!strcasecmp(v->name, "snom_aoc_enabled")) {
 				ast_set2_flag(&global_flags[2], ast_true(v->value), SIP_PAGE3_SNOM_AOC);
 		}

Modified: team/oej/sip-max-forwards-trunk/channels/sip/include/sip.h
URL: http://svnview.digium.com/svn/asterisk/team/oej/sip-max-forwards-trunk/channels/sip/include/sip.h?view=diff&rev=275991&r1=275990&r2=275991
==============================================================================
--- team/oej/sip-max-forwards-trunk/channels/sip/include/sip.h (original)
+++ team/oej/sip-max-forwards-trunk/channels/sip/include/sip.h Tue Jul 13 11:14:47 2010
@@ -57,7 +57,7 @@
 #define DEFAULT_MAX_EXPIRY           3600
 #define DEFAULT_MWI_EXPIRY           3600
 #define DEFAULT_REGISTRATION_TIMEOUT 20
-#define DEFAULT_MAX_FORWARDS        "70"
+#define DEFAULT_MAX_FORWARDS         70
 
 /* guard limit must be larger than guard secs */
 /* guard min must be < 1000, and should be >= 250 */
@@ -704,6 +704,7 @@
 	struct ast_ha *contact_ha;  /*! \brief Global list of addresses dynamic peers are not allowed to use */
 	format_t capability;        /*!< Supported codecs */
 	int tcp_enabled;
+	int default_max_forwards;    /*!< Default max forwards (SIP Anti-loop) */
 };
 
 /*! \brief The SIP socket definition */
@@ -954,6 +955,7 @@
 		AST_STRING_FIELD(dialstring);   /*!< The dialstring used to call this SIP endpoint */
 	);
 	char via[128];                          /*!< Via: header */
+	int maxforwards;                        /*!< SIP Loop prevention */
 	struct sip_socket socket;               /*!< The socket used for this dialog */
 	unsigned int ocseq;                     /*!< Current outgoing seqno */
 	unsigned int icseq;                     /*!< Current incoming seqno */
@@ -1192,6 +1194,7 @@
 	int call_limit;                 /*!< Limit of concurrent calls */
 	int t38_maxdatagram;            /*!< T.38 FaxMaxDatagram override */
 	int busy_level;                 /*!< Level of active channels where we signal busy */
+	int maxforwards;                /*!< SIP Loop prevention */
 	enum transfermodes allowtransfer;   /*! SIP Refer restriction scheme */
 	struct ast_codec_pref prefs;    /*!<  codec prefs */
 	int lastmsgssent;

Modified: team/oej/sip-max-forwards-trunk/configs/sip.conf.sample
URL: http://svnview.digium.com/svn/asterisk/team/oej/sip-max-forwards-trunk/configs/sip.conf.sample?view=diff&rev=275991&r1=275990&r2=275991
==============================================================================
--- team/oej/sip-max-forwards-trunk/configs/sip.conf.sample (original)
+++ team/oej/sip-max-forwards-trunk/configs/sip.conf.sample Tue Jul 13 11:14:47 2010
@@ -202,6 +202,7 @@
 ;minexpiry=60                   ; Minimum length of registrations/subscriptions (default 60)
 ;defaultexpiry=120              ; Default length of incoming/outgoing registration
 ;mwiexpiry=3600                 ; Expiry time for outgoing MWI subscriptions
+;maxforwards=70			; Default value for the SIP Max-Forwards: header (loop prevention)
 ;qualifyfreq=60                 ; Qualification: How often to check for the host to be up in seconds
                                 ; Set to low value if you use low timeout for NAT of UDP sessions
 				; Default: 60
@@ -1035,6 +1036,7 @@
 ; directmediadeny
 ; unsolicited_mailbox
 ; use_q850_reason
+; maxforwards
 
 ;[sip_proxy]
 ; For incoming calls only. Example: FWD (Free World Dialup)

Modified: team/oej/sip-max-forwards-trunk/doc/tex/channelvariables.tex
URL: http://svnview.digium.com/svn/asterisk/team/oej/sip-max-forwards-trunk/doc/tex/channelvariables.tex?view=diff&rev=275991&r1=275990&r2=275991
==============================================================================
--- team/oej/sip-max-forwards-trunk/doc/tex/channelvariables.tex (original)
+++ team/oej/sip-max-forwards-trunk/doc/tex/channelvariables.tex Tue Jul 13 11:14:47 2010
@@ -933,6 +933,7 @@
 ${SIPFROMDOMAIN}       Set SIP domain on outbound calls
 ${SIPUSERAGENT}      * SIP user agent (deprecated)
 ${SIPURI}            * SIP uri
+${SIP_MAX_FORWARDS}    Set the value of the Max-Forwards header for outbound call
 ${SIP_CODEC}           Set the SIP codec for an inbound call
 ${SIP_CODEC_INBOUND}   Set the SIP codec for an inbound call
 ${SIP_CODEC_OUTBOUND}  Set the SIP codec for an outbound call




More information about the svn-commits mailing list