[asterisk-dev] [PATCH] Honor "423 Interval too brief" errors at
registration time
Samuel Tardieu
sam at rfc1149.net
Wed May 31 11:29:14 MST 2006
An "expiry" field is added to the sip_registry structure. It is set to
default_expiry at start time, and is increased (within bounds of
min_expiry and max_expiry) if a 423 (Interval Too Brief) message is
received by the peer. A new registration is then attempted without
increasing the number of attempts, as this is not a timeout but a
negotiation of options.
1 file changed, 25 insertions(+), 1 deletion(-)
channels/chan_sip.c | 26 +++++++++++++++++++++++++-
diff -r fc55abbddee7 -r 13ec26da5a3a channels/chan_sip.c
--- a/channels/chan_sip.c Wed May 31 16:47:21 2006 +0200
+++ b/channels/chan_sip.c Wed May 31 20:27:21 2006 +0200
@@ -982,6 +982,7 @@ struct sip_registry {
);
int portno; /*!< Optional port override */
int expire; /*!< Sched ID of expiration */
+ int expiry; /*<! Value to use for the Expires header */
int regattempts; /*!< Number of attempts (since the last success) */
int timeout; /*!< sched id of sip_reg_timeout */
int refresh; /*!< How often to refresh */
@@ -3794,6 +3795,7 @@ static int sip_register(char *value, int
if (secret)
ast_string_field_set(reg, secret, secret);
reg->expire = -1;
+ reg->expiry = default_expiry;
reg->timeout = -1;
reg->refresh = default_expiry;
reg->portno = porta ? atoi(porta) : 0;
@@ -6022,7 +6024,7 @@ static int transmit_register(struct sip_
}
- snprintf(tmp, sizeof(tmp), "%d", default_expiry);
+ snprintf(tmp, sizeof(tmp), "%d", r->expiry);
add_header(&req, "Expires", tmp);
add_header(&req, "Contact", p->our_contact);
add_header(&req, "Event", "registration");
@@ -10353,6 +10355,24 @@ static int handle_response_register(stru
ast_log(LOG_NOTICE, "Failed to authenticate on REGISTER to '%s' (tries '%d')\n", get_header(&p->initreq, "From"), p->authtries);
ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
}
+ break;
+ case 423: /* Interval too brief */
+ r->expiry = atoi(get_header(req, "Min-Expires"));
+ ast_log(LOG_WARNING, "Got 423 Interval too brief to service %s@%s, minimum is %d seconds\n", p->registry->username, p->registry->hostname, r->expiry);
+ r->timeout = -1;
+ if (r->call) {
+ r->call = NULL;
+ ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
+ }
+ if (r->expiry > max_expiry) {
+ ast_log(LOG_WARNING, "Required expiration time from %s@%s is too high, giving up\n", p->registry->username, p->registry->hostname);
+ r->expiry = default_expiry;
+ r->regstate = REG_STATE_REJECTED;
+ } else {
+ r->regstate = REG_STATE_UNREGISTERED;
+ transmit_register(r, SIP_REGISTER, NULL, NULL);
+ }
+ manager_event(EVENT_FLAG_SYSTEM, "Registry", "Channel: SIP\r\nUsername: %s\r\nDomain: %s\r\nStatus: %s\r\n", r->username, r->hostname, regstate2str(r->regstate));
break;
case 479: /* SER: Not able to process the URI - address is wrong in register*/
ast_log(LOG_WARNING, "Got error 479 on register to %s@%s, giving up (check config)\n", p->registry->username,p->registry->hostname);
@@ -10617,6 +10637,10 @@ static void handle_response(struct sip_p
} else /* We can't handle this, giving up in a bad way */
ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
+ break;
+ case 423: /* Interval too brief */
+ if (sipmethod == SIP_REGISTER)
+ res = handle_response_register(p, resp, rest, req, ignore, seqno);
break;
case 481: /* Call leg does not exist */
if (sipmethod == SIP_INVITE) {
More information about the asterisk-dev
mailing list