Fix max forwards interoperability (bug #5474)

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@6844 65c4cc65-6c06-0410-ace0-fbb531ad65f3
1.2-netsec
Mark Spencer 20 years ago
parent c3c96a7461
commit 5f78c43950

@ -95,6 +95,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#define DEFAULT_DEFAULT_EXPIRY 120 #define DEFAULT_DEFAULT_EXPIRY 120
#define DEFAULT_MAX_EXPIRY 3600 #define DEFAULT_MAX_EXPIRY 3600
#define DEFAULT_REGISTRATION_TIMEOUT 20 #define DEFAULT_REGISTRATION_TIMEOUT 20
#define DEFAULT_MAX_FORWARDS "70"
/* guard limit must be larger than guard secs */ /* guard limit must be larger than guard secs */
/* guard min must be < 1000, and should be >= 250 */ /* guard min must be < 1000, and should be >= 250 */
@ -658,7 +659,6 @@ static struct sip_pvt {
struct sip_request initreq; /* Initial request */ struct sip_request initreq; /* Initial request */
int maxtime; /* Max time for first response */ int maxtime; /* Max time for first response */
int maxforwards; /* keep the max-forwards info */
int initid; /* Auto-congest ID if appropriate */ int initid; /* Auto-congest ID if appropriate */
int autokillid; /* Auto-kill ID */ int autokillid; /* Auto-kill ID */
time_t lastrtprx; /* Last RTP received */ time_t lastrtprx; /* Last RTP received */
@ -2574,7 +2574,6 @@ static int sip_senddigit(struct ast_channel *ast, char digit)
return res; return res;
} }
#define DEFAULT_MAX_FORWARDS 70
/*--- sip_transfer: Transfer SIP call */ /*--- sip_transfer: Transfer SIP call */
@ -3960,6 +3959,7 @@ static int respprep(struct sip_request *resp, struct sip_pvt *p, char *msg, stru
copy_header(resp, req, "CSeq"); copy_header(resp, req, "CSeq");
add_header(resp, "User-Agent", default_useragent); add_header(resp, "User-Agent", default_useragent);
add_header(resp, "Allow", ALLOWED_METHODS); add_header(resp, "Allow", ALLOWED_METHODS);
add_header(resp, "Max-Forwards", DEFAULT_MAX_FORWARDS);
if (msg[0] == '2' && (p->method == SIP_SUBSCRIBE || p->method == SIP_REGISTER)) { if (msg[0] == '2' && (p->method == SIP_SUBSCRIBE || p->method == SIP_REGISTER)) {
/* For registration responses, we also need expiry and /* For registration responses, we also need expiry and
contact info */ contact info */
@ -3975,11 +3975,6 @@ static int respprep(struct sip_request *resp, struct sip_pvt *p, char *msg, stru
} else if (p->our_contact[0]) { } else if (p->our_contact[0]) {
add_header(resp, "Contact", p->our_contact); add_header(resp, "Contact", p->our_contact);
} }
if (p->maxforwards) {
char tmp[256];
snprintf(tmp, sizeof(tmp), "%d", p->maxforwards);
add_header(resp, "Max-Forwards", tmp);
}
return 0; return 0;
} }
@ -4076,6 +4071,7 @@ static int reqprep(struct sip_request *req, struct sip_pvt *p, int sipmethod, in
add_header(req, "CSeq", tmp); add_header(req, "CSeq", tmp);
add_header(req, "User-Agent", default_useragent); add_header(req, "User-Agent", default_useragent);
add_header(req, "Max-Forwards", DEFAULT_MAX_FORWARDS);
if (p->rpid) if (p->rpid)
add_header(req, "Remote-Party-ID", p->rpid); add_header(req, "Remote-Party-ID", p->rpid);
@ -4774,7 +4770,7 @@ static void initreqprep(struct sip_request *req, struct sip_pvt *p, int sipmetho
ast_build_string(&invite, &invite_max, "%s", urioptions); ast_build_string(&invite, &invite_max, "%s", urioptions);
} }
/* If custom URI options have been provided, append them */ /* If custom URI options have been provided, append them */
if (p->options && p->options->uri_options) if (p->options && p->options->uri_options)
ast_build_string(&invite, &invite_max, ";%s", p->options->uri_options); ast_build_string(&invite, &invite_max, ";%s", p->options->uri_options);
@ -4807,6 +4803,7 @@ static void initreqprep(struct sip_request *req, struct sip_pvt *p, int sipmetho
add_header(req, "Call-ID", p->callid); add_header(req, "Call-ID", p->callid);
add_header(req, "CSeq", tmp); add_header(req, "CSeq", tmp);
add_header(req, "User-Agent", default_useragent); add_header(req, "User-Agent", default_useragent);
add_header(req, "Max-Forwards", DEFAULT_MAX_FORWARDS);
if (p->rpid) if (p->rpid)
add_header(req, "Remote-Party-ID", p->rpid); add_header(req, "Remote-Party-ID", p->rpid);
} }
@ -5411,6 +5408,7 @@ static int transmit_register(struct sip_registry *r, int sipmethod, char *auth,
add_header(&req, "Call-ID", p->callid); add_header(&req, "Call-ID", p->callid);
add_header(&req, "CSeq", tmp); add_header(&req, "CSeq", tmp);
add_header(&req, "User-Agent", default_useragent); add_header(&req, "User-Agent", default_useragent);
add_header(&req, "Max-Forwards", DEFAULT_MAX_FORWARDS);
if (auth) /* Add auth header */ if (auth) /* Add auth header */
@ -5471,7 +5469,6 @@ static int transmit_refer(struct sip_pvt *p, const char *dest)
char from[256]; char from[256];
char *of, *c; char *of, *c;
char referto[256]; char referto[256];
char tmp[80];
if (ast_test_flag(p, SIP_OUTGOING)) if (ast_test_flag(p, SIP_OUTGOING))
of = get_header(&p->initreq, "To"); of = get_header(&p->initreq, "To");
@ -5497,26 +5494,16 @@ static int transmit_refer(struct sip_pvt *p, const char *dest)
snprintf(referto, sizeof(referto), "<sip:%s>", dest); snprintf(referto, sizeof(referto), "<sip:%s>", dest);
} }
ast_copy_string(tmp, get_header(&p->initreq, "Max-Forwards"), sizeof(tmp)); /* save in case we get 407 challenge */
if (strlen(tmp) && atoi(tmp)) { ast_copy_string(p->refer_to, referto, sizeof(p->refer_to));
p->maxforwards = atoi(tmp) - 1; ast_copy_string(p->referred_by, p->our_contact, sizeof(p->referred_by));
} else {
p->maxforwards = DEFAULT_MAX_FORWARDS - 1;
}
if (p->maxforwards > -1) {
/* save in case we get 407 challenge */
ast_copy_string(p->refer_to, referto, sizeof(p->refer_to));
ast_copy_string(p->referred_by, p->our_contact, sizeof(p->referred_by));
reqprep(&req, p, SIP_REFER, 0, 1); reqprep(&req, p, SIP_REFER, 0, 1);
add_header(&req, "Refer-To", referto); add_header(&req, "Refer-To", referto);
if (!ast_strlen_zero(p->our_contact)) if (!ast_strlen_zero(p->our_contact))
add_header(&req, "Referred-By", p->our_contact); add_header(&req, "Referred-By", p->our_contact);
add_blank_header(&req); add_blank_header(&req);
return send_request(p, &req, 1, p->ocseq); return send_request(p, &req, 1, p->ocseq);
} else {
return -1;
}
} }
/*--- transmit_info_with_digit: Send SIP INFO dtmf message, see Cisco documentation on cisco.co /*--- transmit_info_with_digit: Send SIP INFO dtmf message, see Cisco documentation on cisco.co
@ -12831,21 +12818,9 @@ static int sip_sipredirect(struct sip_pvt *p, const char *dest)
} }
} }
/* make sure the forwarding won't be forever */ snprintf(p->our_contact, sizeof(p->our_contact), "Transfer <sip:%s@%s%s%s>", extension, host, port ? ":" : "", port ? port : "");
ast_copy_string(tmp, get_header(&p->initreq, "Max-Forwards"), sizeof(tmp)); transmit_response_reliable(p, "302 Moved Temporarily", &p->initreq, 1);
if (strlen(tmp) && atoi(tmp)) {
/* we found Max-Forwards in the original SIP request */
p->maxforwards = atoi(tmp) - 1;
} else {
/* just send our 302 Moved Temporarily */
p->maxforwards = DEFAULT_MAX_FORWARDS - 1;
}
if (p->maxforwards > -1) {
snprintf(p->our_contact, sizeof(p->our_contact), "Transfer <sip:%s@%s%s%s>", extension, host, port ? ":" : "", port ? port : "");
transmit_response_reliable(p, "302 Moved Temporarily", &p->initreq, 1);
} else {
transmit_response(p, "483 Too Many Hops", &p->initreq);
}
/* this is all that we want to send to that SIP device */ /* this is all that we want to send to that SIP device */
ast_set_flag(p, SIP_ALREADYGONE); ast_set_flag(p, SIP_ALREADYGONE);

Loading…
Cancel
Save