Skip to content

Commit

Permalink
sctp: bail from sctp_endpoint_lookup_assoc() if not bound
Browse files Browse the repository at this point in the history
The sctp_endpoint_lookup_assoc() function uses a port hash
to lookup the association and then checks to see if any of
them are on the current endpoint.  However, if the current
endpoint is not bound, there can't be any associations on
it, thus we can bail early.

Signed-off-by: Vlad Yasevich <[email protected]>
Signed-off-by: Wei Yongjun <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
Vlad Yasevich authored and davem330 committed Apr 20, 2011
1 parent 0b8f9e2 commit deb85a6
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions net/sctp/endpointola.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ static struct sctp_association *__sctp_endpoint_lookup_assoc(
struct sctp_transport **transport)
{
struct sctp_association *asoc = NULL;
struct sctp_association *tmp;
struct sctp_transport *t = NULL;
struct sctp_hashbucket *head;
struct sctp_ep_common *epb;
Expand All @@ -333,25 +334,32 @@ static struct sctp_association *__sctp_endpoint_lookup_assoc(
int rport;

*transport = NULL;

/* If the local port is not set, there can't be any associations
* on this endpoint.
*/
if (!ep->base.bind_addr.port)
goto out;

rport = ntohs(paddr->v4.sin_port);

hash = sctp_assoc_hashfn(ep->base.bind_addr.port, rport);
head = &sctp_assoc_hashtable[hash];
read_lock(&head->lock);
sctp_for_each_hentry(epb, node, &head->chain) {
asoc = sctp_assoc(epb);
if (asoc->ep != ep || rport != asoc->peer.port)
goto next;
tmp = sctp_assoc(epb);
if (tmp->ep != ep || rport != tmp->peer.port)
continue;

t = sctp_assoc_lookup_paddr(asoc, paddr);
t = sctp_assoc_lookup_paddr(tmp, paddr);
if (t) {
asoc = tmp;
*transport = t;
break;
}
next:
asoc = NULL;
}
read_unlock(&head->lock);
out:
return asoc;
}

Expand Down

0 comments on commit deb85a6

Please sign in to comment.