aboutsummaryrefslogtreecommitdiffstats
path: root/channels
diff options
context:
space:
mode:
authortilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2008-07-13 17:59:34 +0000
committertilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2008-07-13 17:59:34 +0000
commit7a6f03c46c581018773aeefff70446e9dbecea6f (patch)
treee8ee19c282cc88394c1e48815a8fa7a9745554ad /channels
parentfc53f410078ce6d9762155b21246465fe373bfa3 (diff)
Merged revisions 130515 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk ................ r130515 | tilghman | 2008-07-13 12:58:47 -0500 (Sun, 13 Jul 2008) | 12 lines Merged revisions 130514 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r130514 | tilghman | 2008-07-13 12:56:10 -0500 (Sun, 13 Jul 2008) | 4 lines Reverting 2 changesets, as it breaks incoming IAX2 calls (Related to issue #12963) Reported by: mvanbaak ........ ................ git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.6.0@130516 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'channels')
-rw-r--r--channels/chan_iax2.c97
1 files changed, 44 insertions, 53 deletions
diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c
index ea207dfea..fff9a2702 100644
--- a/channels/chan_iax2.c
+++ b/channels/chan_iax2.c
@@ -1489,13 +1489,13 @@ static struct iax_frame *iaxfrdup2(struct iax_frame *fr)
#define NEW_ALLOW 1
#define NEW_FORCE 2
-static int match(struct sockaddr_in *sin, unsigned short callno, unsigned short dcallno, const struct chan_iax2_pvt *cur)
+static int match(struct sockaddr_in *sin, unsigned short callno, unsigned short dcallno, const struct chan_iax2_pvt *cur, int check_dcallno)
{
if ((cur->addr.sin_addr.s_addr == sin->sin_addr.s_addr) &&
(cur->addr.sin_port == sin->sin_port)) {
/* This is the main host */
if ( (cur->peercallno == 0 || cur->peercallno == callno) &&
- (dcallno == 0 || cur->callno == dcallno) ) {
+ (check_dcallno ? dcallno == cur->callno : 1) ) {
/* That's us. Be sure we keep track of the peer call number */
return 1;
}
@@ -1613,7 +1613,7 @@ static void remove_by_peercallno(struct chan_iax2_pvt *pvt)
/*
* \note Calling this function while holding another pvt lock can cause a deadlock.
*/
-static int __find_callno(unsigned short callno, unsigned short dcallno, struct sockaddr_in *sin, int new, int sockfd, int return_locked)
+static int __find_callno(unsigned short callno, unsigned short dcallno, struct sockaddr_in *sin, int new, int sockfd, int return_locked, int check_dcallno)
{
int res = 0;
int x;
@@ -1626,6 +1626,8 @@ static int __find_callno(unsigned short callno, unsigned short dcallno, struct s
struct chan_iax2_pvt tmp_pvt = {
.callno = dcallno,
.peercallno = callno,
+ /* hack!! */
+ .frames_received = check_dcallno,
};
memcpy(&tmp_pvt.addr, sin, sizeof(tmp_pvt.addr));
@@ -1643,7 +1645,7 @@ static int __find_callno(unsigned short callno, unsigned short dcallno, struct s
/* This will occur on the first response to a message that we initiated,
* such as a PING. */
- if (callno && dcallno && iaxs[dcallno] && !iaxs[dcallno]->peercallno && match(sin, callno, dcallno, iaxs[dcallno])) {
+ if (callno && dcallno && iaxs[dcallno] && !iaxs[dcallno]->peercallno && match(sin, callno, dcallno, iaxs[dcallno], check_dcallno)) {
iaxs[dcallno]->peercallno = callno;
res = dcallno;
store_by_peercallno(iaxs[dcallno]);
@@ -1666,7 +1668,7 @@ static int __find_callno(unsigned short callno, unsigned short dcallno, struct s
ast_mutex_lock(&iaxsl[x]);
if (iaxs[x]) {
/* Look for an exact match */
- if (match(sin, callno, dcallno, iaxs[x])) {
+ if (match(sin, callno, dcallno, iaxs[x], check_dcallno)) {
res = x;
}
}
@@ -1677,7 +1679,7 @@ static int __find_callno(unsigned short callno, unsigned short dcallno, struct s
ast_mutex_lock(&iaxsl[x]);
if (iaxs[x]) {
/* Look for an exact match */
- if (match(sin, callno, dcallno, iaxs[x])) {
+ if (match(sin, callno, dcallno, iaxs[x], check_dcallno)) {
res = x;
}
}
@@ -1760,14 +1762,14 @@ static int __find_callno(unsigned short callno, unsigned short dcallno, struct s
return res;
}
-static int find_callno(unsigned short callno, unsigned short dcallno, struct sockaddr_in *sin, int new, int sockfd) {
+static int find_callno(unsigned short callno, unsigned short dcallno, struct sockaddr_in *sin, int new, int sockfd, int full_frame) {
- return __find_callno(callno, dcallno, sin, new, sockfd, 0);
+ return __find_callno(callno, dcallno, sin, new, sockfd, 0, full_frame);
}
-static int find_callno_locked(unsigned short callno, unsigned short dcallno, struct sockaddr_in *sin, int new, int sockfd) {
+static int find_callno_locked(unsigned short callno, unsigned short dcallno, struct sockaddr_in *sin, int new, int sockfd, int full_frame) {
- return __find_callno(callno, dcallno, sin, new, sockfd, 1);
+ return __find_callno(callno, dcallno, sin, new, sockfd, 1, full_frame);
}
/*!
@@ -7780,7 +7782,7 @@ static int socket_process_meta(int packet_len, struct ast_iax2_meta_hdr *meta, s
/* Stop if we don't have enough data */
if (len > packet_len)
break;
- fr->callno = find_callno_locked(callno & ~IAX_FLAG_FULL, 0, sin, NEW_PREVENT, sockfd);
+ fr->callno = find_callno_locked(callno & ~IAX_FLAG_FULL, 0, sin, NEW_PREVENT, sockfd, 0);
if (!fr->callno)
continue;
@@ -7963,7 +7965,7 @@ static int socket_process(struct iax2_thread *thread)
}
/* This is a video frame, get call number */
- fr->callno = find_callno(ntohs(vh->callno) & ~0x8000, dcallno, &sin, new, fd);
+ fr->callno = find_callno(ntohs(vh->callno) & ~0x8000, dcallno, &sin, new, fd, 0);
minivid = 1;
} else if ((meta->zeros == 0) && !(ntohs(meta->metacmd) & 0x8000))
return socket_process_meta(res, meta, &sin, fd, fr);
@@ -7978,6 +7980,8 @@ static int socket_process(struct iax2_thread *thread)
return 1;
}
+ /* Get the destination call number */
+ dcallno = ntohs(fh->dcallno) & ~IAX_FLAG_RETRANS;
/* Retrieve the type and subclass */
f.frametype = fh->type;
if (f.frametype == AST_FRAME_VIDEO) {
@@ -7985,52 +7989,36 @@ static int socket_process(struct iax2_thread *thread)
} else {
f.subclass = uncompress_subclass(fh->csub);
}
+ if ((f.frametype == AST_FRAME_IAX) && ((f.subclass == IAX_COMMAND_NEW) || (f.subclass == IAX_COMMAND_REGREQ) ||
+ (f.subclass == IAX_COMMAND_POKE) || (f.subclass == IAX_COMMAND_FWDOWNL) ||
+ (f.subclass == IAX_COMMAND_REGREL)))
+ new = NEW_ALLOW;
+ } else {
+ /* Don't know anything about it yet */
+ f.frametype = AST_FRAME_NULL;
+ f.subclass = 0;
+ }
+
+ if (!fr->callno) {
+ int check_dcallno = 0;
/*
* We enforce accurate destination call numbers for all full frames except
- * NEW, LAGRQ, and PING commands. For these, we leave dcallno set to 0 to
- * avoid having find_callno() use it when matching against existing calls.
- *
- * For NEW commands, the destination call is always ignored. See section
- * 6.2.2 of the iax2 RFC.
- *
- * For LAGRQ and PING commands, this is because older versions of Asterisk
+ * LAGRQ and PING commands. This is because older versions of Asterisk
* schedule these commands to get sent very quickly, and they will sometimes
* be sent before they receive the first frame from the other side. When
* that happens, it doesn't contain the destination call number. However,
* not checking it for these frames is safe.
- *
+ *
* Discussed in the following thread:
- * http://lists.digium.com/pipermail/asterisk-dev/2008-May/033217.html
+ * http://lists.digium.com/pipermail/asterisk-dev/2008-May/033217.html
*/
- /* Get the destination call number */
- dcallno = ntohs(fh->dcallno) & ~IAX_FLAG_RETRANS;
-
- if (f.frametype == AST_FRAME_IAX &&
- (f.subclass == IAX_COMMAND_NEW ||
- f.subclass == IAX_COMMAND_PING ||
- f.subclass == IAX_COMMAND_LAGRQ)) {
- dcallno = 0;
- } else if (!dcallno) {
- /* All other full-frames must have a non-zero dcallno,
- * We silently drop this frame since it cannot be a
- * valid match to an existing call session.
- */
- return 1;
+ if (ntohs(mh->callno) & IAX_FLAG_FULL) {
+ check_dcallno = f.frametype == AST_FRAME_IAX ? (f.subclass != IAX_COMMAND_PING && f.subclass != IAX_COMMAND_LAGRQ) : 1;
}
- if ((f.frametype == AST_FRAME_IAX) && ((f.subclass == IAX_COMMAND_NEW) || (f.subclass == IAX_COMMAND_REGREQ) ||
- (f.subclass == IAX_COMMAND_POKE) || (f.subclass == IAX_COMMAND_FWDOWNL) ||
- (f.subclass == IAX_COMMAND_REGREL)))
- new = NEW_ALLOW;
- } else {
- /* Don't know anything about it yet */
- f.frametype = AST_FRAME_NULL;
- f.subclass = 0;
- }
- if (!fr->callno) {
- fr->callno = find_callno(ntohs(mh->callno) & ~IAX_FLAG_FULL, dcallno, &sin, new, fd);
+ fr->callno = find_callno(ntohs(mh->callno) & ~IAX_FLAG_FULL, dcallno, &sin, new, fd, check_dcallno);
}
if (fr->callno > 0)
@@ -8116,7 +8104,6 @@ static int socket_process(struct iax2_thread *thread)
if (
((f.subclass != IAX_COMMAND_ACK) &&
(f.subclass != IAX_COMMAND_INVAL) &&
- (f.subclass != IAX_COMMAND_NEW) && /* for duplicate/retrans NEW frames */
(f.subclass != IAX_COMMAND_TXCNT) &&
(f.subclass != IAX_COMMAND_TXREADY) && /* for attended transfer */
(f.subclass != IAX_COMMAND_TXREL) && /* for attended transfer */
@@ -9620,7 +9607,7 @@ static int iax2_do_register(struct iax2_registry *reg)
if (!reg->callno) {
ast_debug(3, "Allocate call number\n");
- reg->callno = find_callno_locked(0, 0, &reg->addr, NEW_FORCE, defaultsockfd);
+ reg->callno = find_callno_locked(0, 0, &reg->addr, NEW_FORCE, defaultsockfd, 0);
if (reg->callno < 1) {
ast_log(LOG_WARNING, "Unable to create call for registration\n");
return -1;
@@ -9671,7 +9658,7 @@ static int iax2_provision(struct sockaddr_in *end, int sockfd, char *dest, const
memset(&ied, 0, sizeof(ied));
iax_ie_append_raw(&ied, IAX_IE_PROVISIONING, provdata.buf, provdata.pos);
- callno = find_callno_locked(0, 0, &sin, NEW_FORCE, cai.sockfd);
+ callno = find_callno_locked(0, 0, &sin, NEW_FORCE, cai.sockfd, 0);
if (!callno)
return -1;
@@ -9832,7 +9819,7 @@ static int iax2_poke_peer(struct iax2_peer *peer, int heldcall)
}
if (heldcall)
ast_mutex_unlock(&iaxsl[heldcall]);
- callno = peer->callno = find_callno(0, 0, &peer->addr, NEW_FORCE, peer->sockfd);
+ callno = peer->callno = find_callno(0, 0, &peer->addr, NEW_FORCE, peer->sockfd, 0);
if (heldcall)
ast_mutex_lock(&iaxsl[heldcall]);
if (peer->callno < 1) {
@@ -9915,7 +9902,7 @@ static struct ast_channel *iax2_request(const char *type, int format, void *data
if (pds.port)
sin.sin_port = htons(atoi(pds.port));
- callno = find_callno_locked(0, 0, &sin, NEW_FORCE, cai.sockfd);
+ callno = find_callno_locked(0, 0, &sin, NEW_FORCE, cai.sockfd, 0);
if (callno < 1) {
ast_log(LOG_WARNING, "Unable to create call\n");
*cause = AST_CAUSE_CONGESTION;
@@ -11289,7 +11276,7 @@ static int cache_get_callno_locked(const char *data)
ast_debug(1, "peer: %s, username: %s, password: %s, context: %s\n",
pds.peer, pds.username, pds.password, pds.context);
- callno = find_callno_locked(0, 0, &sin, NEW_FORCE, cai.sockfd);
+ callno = find_callno_locked(0, 0, &sin, NEW_FORCE, cai.sockfd, 0);
if (callno < 1) {
ast_log(LOG_WARNING, "Unable to create call\n");
return -1;
@@ -12004,7 +11991,11 @@ static int pvt_cmp_cb(void *obj, void *arg, int flags)
{
struct chan_iax2_pvt *pvt = obj, *pvt2 = arg;
- return match(&pvt2->addr, pvt2->peercallno, pvt2->callno, pvt) ? CMP_MATCH : 0;
+ /* The frames_received field is used to hold whether we're matching
+ * against a full frame or not ... */
+
+ return match(&pvt2->addr, pvt2->peercallno, pvt2->callno, pvt,
+ pvt2->frames_received) ? CMP_MATCH : 0;
}
/*! \brief Load IAX2 module, load configuraiton ---*/