Merged revisions 220906 via svnmerge from

https://origsvn.digium.com/svn/asterisk/trunk

................
  r220906 | tilghman | 2009-09-29 14:57:37 -0500 (Tue, 29 Sep 2009) | 16 lines
  
  Merged revisions 220873 via svnmerge from 
  https://origsvn.digium.com/svn/asterisk/branches/1.4
  
  ........
    r220873 | tilghman | 2009-09-29 12:59:26 -0500 (Tue, 29 Sep 2009) | 9 lines
    
    Reduce CPU usage related to building a peer merely for devicestates.
    This fixes a 100% CPU problem in the SIP driver, found by profiling
    the driver while the problem was occurring.
    (closes issue #14309)
     Reported by: pkempgen
     Patches: 
           20090924__issue14309.diff.txt uploaded by tilghman (license 14)
     Tested by: pkempgen, vrban
  ........
................


git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.6.0@220976 65c4cc65-6c06-0410-ace0-fbb531ad65f3
1.6.0
Tilghman Lesher 16 years ago
parent dfcc688a9c
commit 22e1118a93

@ -1942,7 +1942,7 @@ static void sip_dump_history(struct sip_pvt *dialog);
/*--- Device object handling */
static struct sip_peer *temp_peer(const char *name);
static struct sip_peer *build_peer(const char *name, struct ast_variable *v, struct ast_variable *alt, int realtime);
static struct sip_peer *build_peer(const char *name, struct ast_variable *v, struct ast_variable *alt, int realtime, int devstate_only);
static struct sip_user *build_user(const char *name, struct ast_variable *v, struct ast_variable *alt, int realtime);
static int update_call_counter(struct sip_pvt *fup, int event);
static void sip_destroy_peer(struct sip_peer *peer);
@ -4010,7 +4010,7 @@ static struct sip_peer *realtime_peer(const char *newpeername, struct sockaddr_i
/* Peer found in realtime, now build it in memory */
peer = build_peer(newpeername, var, varregs, 1);
peer = build_peer(newpeername, var, varregs, 1, devstate_only);
if (!peer) {
if(peerlist)
ast_config_destroy(peerlist);
@ -21259,7 +21259,7 @@ static void add_peer_mailboxes(struct sip_peer *peer, const char *value)
}
/*! \brief Build peer from configuration (file or realtime static/dynamic) */
static struct sip_peer *build_peer(const char *name, struct ast_variable *v, struct ast_variable *alt, int realtime)
static struct sip_peer *build_peer(const char *name, struct ast_variable *v, struct ast_variable *alt, int realtime, int devstate_only)
{
struct sip_peer *peer = NULL;
struct ast_ha *oldha = NULL;
@ -21324,8 +21324,10 @@ static struct sip_peer *build_peer(const char *name, struct ast_variable *v, str
peer->transports = 0;
for (; v || ((v = alt) && !(alt=NULL)); v = v->next) {
if (handle_common_options(&peerflags[0], &mask[0], v))
if (!devstate_only) {
if (handle_common_options(&peerflags[0], &mask[0], v)) {
continue;
}
if (!strcasecmp(v->name, "transport") && !ast_strlen_zero(v->value)) {
char *val = ast_strdupa(v->value);
char *trans;
@ -21333,14 +21335,15 @@ static struct sip_peer *build_peer(const char *name, struct ast_variable *v, str
while ((trans = strsep(&val, ","))) {
trans = ast_skip_blanks(trans);
if (!strncasecmp(trans, "udp", 3))
if (!strncasecmp(trans, "udp", 3)) {
peer->transports |= SIP_TRANSPORT_UDP;
else if (!strncasecmp(trans, "tcp", 3))
} else if (!strncasecmp(trans, "tcp", 3)) {
peer->transports |= SIP_TRANSPORT_TCP;
else if (!strncasecmp(trans, "tls", 3))
} else if (!strncasecmp(trans, "tls", 3)) {
peer->transports |= SIP_TRANSPORT_TLS;
else
} else {
ast_log(LOG_NOTICE, "'%s' is not a valid transport type. if no other is specified, udp will be used.\n", trans);
}
if (!peer->default_outbound_transport) { /*!< The first transport listed should be default outbound */
peer->default_outbound_transport = peer->transports;
@ -21348,13 +21351,9 @@ static struct sip_peer *build_peer(const char *name, struct ast_variable *v, str
}
} else if (realtime && !strcasecmp(v->name, "regseconds")) {
ast_get_time_t(v->value, &regseconds, 0, NULL);
} else if (realtime && !strcasecmp(v->name, "lastms")) {
sscanf(v->value, "%30d", &peer->lastms);
} else if (realtime && !strcasecmp(v->name, "ipaddr") && !ast_strlen_zero(v->value) ) {
inet_aton(v->value, &(peer->addr.sin_addr));
} else if (realtime && !strcasecmp(v->name, "name"))
} else if (realtime && !strcasecmp(v->name, "name")) {
ast_copy_string(peer->name, v->value, sizeof(peer->name));
else if (realtime && !strcasecmp(v->name, "fullcontact")) {
} else if (realtime && !strcasecmp(v->name, "fullcontact")) {
if (alt_fullcontact && !alt) {
/* Reset, because the alternate also has a fullcontact and we
* do NOT want the field value to be doubled. It might be
@ -21370,13 +21369,13 @@ static struct sip_peer *build_peer(const char *name, struct ast_variable *v, str
} else {
ast_str_set(&fullcontact, 0, "%s", v->value);
}
} else if (!strcasecmp(v->name, "secret"))
} else if (!strcasecmp(v->name, "secret")) {
ast_copy_string(peer->secret, v->value, sizeof(peer->secret));
else if (!strcasecmp(v->name, "md5secret"))
} else if (!strcasecmp(v->name, "md5secret")) {
ast_copy_string(peer->md5secret, v->value, sizeof(peer->md5secret));
else if (!strcasecmp(v->name, "auth"))
} else if (!strcasecmp(v->name, "auth")) {
peer->auth = add_realm_authentication(peer->auth, v->value, v->lineno);
else if (!strcasecmp(v->name, "callerid")) {
} else if (!strcasecmp(v->name, "callerid")) {
ast_callerid_split(v->value, peer->cid_name, sizeof(peer->cid_name), peer->cid_num, sizeof(peer->cid_num));
} else if (!strcasecmp(v->name, "fullname")) {
ast_copy_string(peer->cid_name, v->value, sizeof(peer->cid_name));
@ -21419,7 +21418,6 @@ static struct sip_peer *build_peer(const char *name, struct ast_variable *v, str
peer->defaddr.sin_port = peer->addr.sin_port;
peer->addr.sin_port = 0;
}
}
peer->host_dynamic = TRUE;
} else {
/* Non-dynamic. Make sure we become that way if we're not */
@ -21434,6 +21432,7 @@ static struct sip_peer *build_peer(const char *name, struct ast_variable *v, str
}
}
}
}
} else if (!strcasecmp(v->name, "defaultip")) {
if (ast_get_ip(&peer->defaddr, v->value)) {
unref_peer(peer);
@ -21441,10 +21440,10 @@ static struct sip_peer *build_peer(const char *name, struct ast_variable *v, str
}
} else if (!strcasecmp(v->name, "permit") || !strcasecmp(v->name, "deny")) {
int ha_error = 0;
peer->ha = ast_append_ha(v->name, v->value, peer->ha, &ha_error);
if (ha_error)
if (ha_error) {
ast_log(LOG_ERROR, "Bad ACL entry in configuration line %d : %s\n", v->lineno, v->value);
}
} else if (!strcasecmp(v->name, "contactpermit") || !strcasecmp(v->name, "contactdeny")) {
int ha_error = 0;
peer->contactha = ast_append_ha(v->name + 7, v->value, peer->contactha, &ha_error);
@ -21452,14 +21451,16 @@ static struct sip_peer *build_peer(const char *name, struct ast_variable *v, str
ast_log(LOG_ERROR, "Bad ACL entry in configuration line %d : %s\n", v->lineno, v->value);
}
} else if (!strcasecmp(v->name, "port")) {
if (!realtime && peer->host_dynamic)
if (!realtime && peer->host_dynamic) {
peer->defaddr.sin_port = htons(atoi(v->value));
else
} else {
peer->addr.sin_port = htons(atoi(v->value));
}
} else if (!strcasecmp(v->name, "callingpres")) {
peer->callingpres = ast_parse_caller_presentation(v->value);
if (peer->callingpres == -1)
if (peer->callingpres == -1) {
peer->callingpres = atoi(v->value);
}
} else if (!strcasecmp(v->name, "username") || !strcmp(v->name, "defaultuser")) { /* "username" is deprecated */
ast_copy_string(peer->username, v->value, sizeof(peer->username));
if (!strcasecmp(v->name, "username")) {
@ -21479,12 +21480,14 @@ static struct sip_peer *build_peer(const char *name, struct ast_variable *v, str
peer->call_limit = ast_true(v->value) ? 999 : 0;
} else if (!strcasecmp(v->name, "call-limit")) {
peer->call_limit = atoi(v->value);
if (peer->call_limit < 0)
if (peer->call_limit < 0) {
peer->call_limit = 0;
}
} else if (!strcasecmp(v->name, "busylevel")) {
peer->busy_level = atoi(v->value);
if (peer->busy_level < 0)
if (peer->busy_level < 0) {
peer->busy_level = 0;
}
} else if (!strcasecmp(v->name, "amaflags")) {
format = ast_cdr_amaflags2int(v->value);
if (format < 0) {
@ -21518,12 +21521,14 @@ static struct sip_peer *build_peer(const char *name, struct ast_variable *v, str
peer->pickupgroup = ast_get_group(v->value);
} else if (!strcasecmp(v->name, "allow")) {
int error = ast_parse_allow_disallow(&peer->prefs, &peer->capability, v->value, TRUE);
if (error)
if (error) {
ast_log(LOG_WARNING, "Codec configuration errors found in line %d : %s = %s\n", v->lineno, v->name, v->value);
}
} else if (!strcasecmp(v->name, "disallow")) {
int error = ast_parse_allow_disallow(&peer->prefs, &peer->capability, v->value, FALSE);
if (error)
if (error) {
ast_log(LOG_WARNING, "Codec configuration errors found in line %d : %s = %s\n", v->lineno, v->name, v->value);
}
} else if (!strcasecmp(v->name, "registertrying")) {
ast_set2_flag(&peer->flags[1], ast_true(v->value), SIP_PAGE2_REGISTERTRYING);
} else if (!strcasecmp(v->name, "autoframing")) {
@ -21564,37 +21569,86 @@ static struct sip_peer *build_peer(const char *name, struct ast_variable *v, str
ast_log(LOG_WARNING, "Timer B has been set lower than recommended. (RFC 3261, 17.1.1.2)\n");
}
}
} else if (!strcasecmp(v->name, "setvar")) {
peer->chanvars = add_var(v->value, peer->chanvars);
} else if (!strcasecmp(v->name, "qualify")) {
if (!strcasecmp(v->value, "no")) {
peer->maxms = 0;
} else if (!strcasecmp(v->value, "yes")) {
peer->maxms = default_qualify ? default_qualify : DEFAULT_MAXMS;
} else if (sscanf(v->value, "%30d", &peer->maxms) != 1) {
ast_log(LOG_WARNING, "Qualification of peer '%s' should be 'yes', 'no', or a number of milliseconds at line %d of sip.conf\n", peer->name, v->lineno);
peer->maxms = 0;
} else if (!strcasecmp(v->name, "subscribemwi")) {
ast_set2_flag(&peer->flags[1], ast_true(v->value), SIP_PAGE2_SUBSCRIBEMWIONLY);
} else if (!strcasecmp(v->name, "vmexten")) {
ast_copy_string(peer->vmexten, v->value, sizeof(peer->vmexten));
} else if (!strcasecmp(v->name, "callgroup")) {
peer->callgroup = ast_get_group(v->value);
} else if (!strcasecmp(v->name, "allowtransfer")) {
peer->allowtransfer = ast_true(v->value) ? TRANSFER_OPENFORALL : TRANSFER_CLOSED;
} else if (!strcasecmp(v->name, "pickupgroup")) {
peer->pickupgroup = ast_get_group(v->value);
} else if (!strcasecmp(v->name, "allow")) {
int error = ast_parse_allow_disallow(&peer->prefs, &peer->capability, v->value, TRUE);
if (error) {
ast_log(LOG_WARNING, "Codec configuration errors found in line %d : %s = %s\n", v->lineno, v->name, v->value);
}
if (realtime && !ast_test_flag(&global_flags[1], SIP_PAGE2_RTCACHEFRIENDS) && peer->maxms > 0) {
/* This would otherwise cause a network storm, where the
* qualify response refreshes the peer from the database,
* which in turn causes another qualify to be sent, ad
* infinitum. */
ast_log(LOG_WARNING, "Qualify is incompatible with dynamic uncached realtime. Please either turn rtcachefriends on or turn qualify off on peer '%s'\n", peer->name);
peer->maxms = 0;
} else if (!strcasecmp(v->name, "disallow")) {
int error = ast_parse_allow_disallow(&peer->prefs, &peer->capability, v->value, FALSE);
if (error) {
ast_log(LOG_WARNING, "Codec configuration errors found in line %d : %s = %s\n", v->lineno, v->name, v->value);
}
} else if (!strcasecmp(v->name, "registertrying")) {
ast_set2_flag(&peer->flags[1], ast_true(v->value), SIP_PAGE2_REGISTERTRYING);
} else if (!strcasecmp(v->name, "autoframing")) {
peer->autoframing = ast_true(v->value);
} else if (!strcasecmp(v->name, "rtptimeout")) {
if ((sscanf(v->value, "%30d", &peer->rtptimeout) != 1) || (peer->rtptimeout < 0)) {
ast_log(LOG_WARNING, "'%s' is not a valid RTP hold time at line %d. Using default.\n", v->value, v->lineno);
peer->rtptimeout = global_rtptimeout;
}
} else if (!strcasecmp(v->name, "rtpholdtimeout")) {
if ((sscanf(v->value, "%30d", &peer->rtpholdtimeout) != 1) || (peer->rtpholdtimeout < 0)) {
ast_log(LOG_WARNING, "'%s' is not a valid RTP hold time at line %d. Using default.\n", v->value, v->lineno);
peer->rtpholdtimeout = global_rtpholdtimeout;
}
} else if (!strcasecmp(v->name, "rtpkeepalive")) {
if ((sscanf(v->value, "%30d", &peer->rtpkeepalive) != 1) || (peer->rtpkeepalive < 0)) {
ast_log(LOG_WARNING, "'%s' is not a valid RTP keepalive time at line %d. Using default.\n", v->value, v->lineno);
peer->rtpkeepalive = global_rtpkeepalive;
}
} else if (!strcasecmp(v->name, "timert1")) {
if ((sscanf(v->value, "%30d", &peer->timer_t1) != 1) || (peer->timer_t1 < 0)) {
ast_log(LOG_WARNING, "'%s' is not a valid T1 time at line %d. Using default.\n", v->value, v->lineno);
peer->timer_t1 = global_t1;
}
/* Note that Timer B is dependent upon T1 and MUST NOT be lower
* than T1 * 64, according to RFC 3261, Section 17.1.1.2 */
if (peer->timer_b < peer->timer_t1 * 64) {
peer->timer_b = peer->timer_t1 * 64;
}
} else if (!strcasecmp(v->name, "timerb")) {
if ((sscanf(v->value, "%30d", &peer->timer_b) != 1) || (peer->timer_b < 0)) {
ast_log(LOG_WARNING, "'%s' is not a valid Timer B time at line %d. Using default.\n", v->value, v->lineno);
peer->timer_b = global_timer_b;
}
if (peer->timer_b < peer->timer_t1 * 64) {
static int warning = 0;
if (warning++ % 20 == 0) {
ast_log(LOG_WARNING, "Timer B has been set lower than recommended. (RFC 3261, 17.1.1.2)\n");
}
}
} else if (!strcasecmp(v->name, "rtpkeepalive")) {
if ((sscanf(v->value, "%30d", &peer->rtpkeepalive) != 1) || (peer->rtpkeepalive < 0)) {
ast_log(LOG_WARNING, "'%s' is not a valid RTP keepalive time at line %d. Using default.\n", v->value, v->lineno);
peer->rtpkeepalive = global_rtpkeepalive;
}
} else if (!strcasecmp(v->name, "setvar")) {
peer->chanvars = add_var(v->value, peer->chanvars);
} else if (!strcasecmp(v->name, "qualifyfreq")) {
int i;
if (sscanf(v->value, "%30d", &i) == 1)
if (sscanf(v->value, "%30d", &i) == 1) {
peer->qualifyfreq = i * 1000;
else {
} else {
ast_log(LOG_WARNING, "Invalid qualifyfreq number '%s' at line %d of %s\n", v->value, v->lineno, config);
peer->qualifyfreq = global_qualifyfreq;
}
} else if (!strcasecmp(v->name, "maxcallbitrate")) {
peer->maxcallbitrate = atoi(v->value);
if (peer->maxcallbitrate < 0)
if (peer->maxcallbitrate < 0) {
peer->maxcallbitrate = default_maxcallbitrate;
}
} else if (!strcasecmp(v->name, "session-timers")) {
int i = (int) str2stmode(v->value);
if (i < 0) {
@ -21628,6 +21682,44 @@ static struct sip_peer *build_peer(const char *name, struct ast_variable *v, str
}
}
/* These apply to devstate lookups */
if (realtime && !strcasecmp(v->name, "lastms")) {
sscanf(v->value, "%30d", &peer->lastms);
} else if (realtime && !strcasecmp(v->name, "ipaddr") && !ast_strlen_zero(v->value) ) {
inet_aton(v->value, &(peer->addr.sin_addr));
} else if (!strcasecmp(v->name, "qualify")) {
if (!strcasecmp(v->value, "no")) {
peer->maxms = 0;
} else if (!strcasecmp(v->value, "yes")) {
peer->maxms = default_qualify ? default_qualify : DEFAULT_MAXMS;
} else if (sscanf(v->value, "%30d", &peer->maxms) != 1) {
ast_log(LOG_WARNING, "Qualification of peer '%s' should be 'yes', 'no', or a number of milliseconds at line %d of sip.conf\n", peer->name, v->lineno);
peer->maxms = 0;
}
if (realtime && !ast_test_flag(&global_flags[1], SIP_PAGE2_RTCACHEFRIENDS) && peer->maxms > 0) {
/* This would otherwise cause a network storm, where the
* qualify response refreshes the peer from the database,
* which in turn causes another qualify to be sent, ad
* infinitum. */
ast_log(LOG_WARNING, "Qualify is incompatible with dynamic uncached realtime. Please either turn rtcachefriends on or turn qualify off on peer '%s'\n", peer->name);
peer->maxms = 0;
}
} else if (!strcasecmp(v->name, "callcounter")) {
peer->call_limit = ast_true(v->value) ? INT_MAX : 0;
} else if (!strcasecmp(v->name, "call-limit")) {
peer->call_limit = atoi(v->value);
if (peer->call_limit < 0) {
peer->call_limit = 0;
}
} else if (!strcasecmp(v->name, "busylevel")) {
peer->busy_level = atoi(v->value);
if (peer->busy_level < 0) {
peer->busy_level = 0;
}
}
}
if (!devstate_only) {
if (!peer->default_outbound_transport) {
peer->transports = SIP_TRANSPORT_UDP;
peer->default_outbound_transport = SIP_TRANSPORT_UDP;
@ -21643,7 +21735,7 @@ static struct sip_peer *build_peer(const char *name, struct ast_variable *v, str
set_socket_transport(&peer->socket, peer->default_outbound_transport);
}
if (fullcontact->used > 0) {
if (ast_str_strlen(fullcontact)) {
ast_copy_string(peer->fullcontact, fullcontact->str, sizeof(peer->fullcontact));
peer->rt_fromcontact = TRUE;
/* We have a hostname in the fullcontact, but if we don't have an
@ -21674,12 +21766,6 @@ static struct sip_peer *build_peer(const char *name, struct ast_variable *v, str
ast_copy_string(peer->tohost, srvlookup, sizeof(peer->tohost));
}
if (!peer->addr.sin_port)
peer->addr.sin_port = htons(((peer->socket.type & SIP_TRANSPORT_TLS) ? STANDARD_TLS_PORT : STANDARD_SIP_PORT));
if (!peer->socket.port)
peer->socket.port = htons(((peer->socket.type & SIP_TRANSPORT_TLS) ? STANDARD_TLS_PORT : STANDARD_SIP_PORT));
if (!sip_cfg.ignore_regexpire && peer->host_dynamic && realtime) {
time_t nowtime = time(NULL);
@ -21699,10 +21785,12 @@ static struct sip_peer *build_peer(const char *name, struct ast_variable *v, str
ast_copy_flags(&peer->flags[0], &peerflags[0], mask[0].flags);
ast_copy_flags(&peer->flags[1], &peerflags[1], mask[1].flags);
if (ast_test_flag(&peer->flags[1], SIP_PAGE2_ALLOWSUBSCRIBE))
if (ast_test_flag(&peer->flags[1], SIP_PAGE2_ALLOWSUBSCRIBE)) {
global_allowsubscribe = TRUE; /* No global ban any more */
if (!found && peer->host_dynamic && !peer->is_realtime)
}
if (!found && peer->host_dynamic && !peer->is_realtime) {
reg_source_db(peer);
}
/* If they didn't request that MWI is sent *only* on subscribe, go ahead and
* subscribe to it now. */
@ -21714,6 +21802,7 @@ static struct sip_peer *build_peer(const char *name, struct ast_variable *v, str
* way, then we will get events when app_voicemail gets loaded. */
sip_send_mwi_to_peer(peer, NULL, 1);
}
}
ASTOBJ_UNMARK(peer);
@ -22341,7 +22430,7 @@ static int reload_config(enum channelreloadreason reason)
ASTOBJ_UNREF(user, sip_destroy_user);
user_count++;
}
peer = build_peer(cat, gen, ast_variable_browse(ucfg, cat), 0);
peer = build_peer(cat, gen, ast_variable_browse(ucfg, cat), 0, 0);
if (peer) {
ASTOBJ_CONTAINER_LINK(&peerl, peer);
unref_peer(peer);
@ -22409,7 +22498,7 @@ static int reload_config(enum channelreloadreason reason)
}
}
if (is_peer) {
peer = build_peer(cat, ast_variable_browse(cfg, cat), NULL, 0);
peer = build_peer(cat, ast_variable_browse(cfg, cat), NULL, 0, 0);
if (peer) {
ASTOBJ_CONTAINER_LINK(&peerl, peer);
unref_peer(peer);

Loading…
Cancel
Save