Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 73592
b: refs/heads/master
c: d970dbf
h: refs/heads/master
v: v3
  • Loading branch information
Vlad Yasevich committed Nov 9, 2007
1 parent d16b1e8 commit fa864a6
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 54 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 123ed979eaa8de0dd2422862d247469eda0bd645
refs/heads/master: d970dbf8455eb1b8cebd3cde6e18f73dd1b3ce38
3 changes: 3 additions & 0 deletions trunk/include/net/sctp/sctp.h
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,9 @@ static inline int sctp_vtag_hashfn(__u16 lport, __u16 rport, __u32 vtag)
return (h & (sctp_assoc_hashsize-1));
}

#define sctp_for_each_hentry(epb, node, head) \
hlist_for_each_entry(epb, node, head, node)

/* Is a socket of this style? */
#define sctp_style(sk, style) __sctp_style((sk), (SCTP_SOCKET_##style))
static inline int __sctp_style(const struct sock *sk, sctp_socket_type_t style)
Expand Down
10 changes: 4 additions & 6 deletions trunk/include/net/sctp/structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,20 +100,19 @@ struct crypto_hash;
struct sctp_bind_bucket {
unsigned short port;
unsigned short fastreuse;
struct sctp_bind_bucket *next;
struct sctp_bind_bucket **pprev;
struct hlist_node node;
struct hlist_head owner;
};

struct sctp_bind_hashbucket {
spinlock_t lock;
struct sctp_bind_bucket *chain;
struct hlist_head chain;
};

/* Used for hashing all associations. */
struct sctp_hashbucket {
rwlock_t lock;
struct sctp_ep_common *chain;
struct hlist_head chain;
} __attribute__((__aligned__(8)));


Expand Down Expand Up @@ -1230,8 +1229,7 @@ typedef enum {

struct sctp_ep_common {
/* Fields to help us manage our entries in the hash tables. */
struct sctp_ep_common *next;
struct sctp_ep_common **pprev;
struct hlist_node node;
int hashent;

/* Runtime type information. What kind of endpoint is this? */
Expand Down
3 changes: 2 additions & 1 deletion trunk/net/sctp/endpointola.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ static struct sctp_association *__sctp_endpoint_lookup_assoc(
struct sctp_transport *t = NULL;
struct sctp_hashbucket *head;
struct sctp_ep_common *epb;
struct hlist_node *node;
int hash;
int rport;

Expand All @@ -341,7 +342,7 @@ static struct sctp_association *__sctp_endpoint_lookup_assoc(
hash = sctp_assoc_hashfn(ep->base.bind_addr.port, rport);
head = &sctp_assoc_hashtable[hash];
read_lock(&head->lock);
for (epb = head->chain; epb; epb = epb->next) {
sctp_for_each_hentry(epb, node, &head->chain) {
asoc = sctp_assoc(epb);
if (asoc->ep != ep || rport != asoc->peer.port)
goto next;
Expand Down
43 changes: 11 additions & 32 deletions trunk/net/sctp/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,6 @@ static int sctp_rcv_ootb(struct sk_buff *skb)
/* Insert endpoint into the hash table. */
static void __sctp_hash_endpoint(struct sctp_endpoint *ep)
{
struct sctp_ep_common **epp;
struct sctp_ep_common *epb;
struct sctp_hashbucket *head;

Expand All @@ -666,12 +665,7 @@ static void __sctp_hash_endpoint(struct sctp_endpoint *ep)
head = &sctp_ep_hashtable[epb->hashent];

sctp_write_lock(&head->lock);
epp = &head->chain;
epb->next = *epp;
if (epb->next)
(*epp)->pprev = &epb->next;
*epp = epb;
epb->pprev = epp;
hlist_add_head(&epb->node, &head->chain);
sctp_write_unlock(&head->lock);
}

Expand All @@ -691,19 +685,15 @@ static void __sctp_unhash_endpoint(struct sctp_endpoint *ep)

epb = &ep->base;

if (hlist_unhashed(&epb->node))
return;

epb->hashent = sctp_ep_hashfn(epb->bind_addr.port);

head = &sctp_ep_hashtable[epb->hashent];

sctp_write_lock(&head->lock);

if (epb->pprev) {
if (epb->next)
epb->next->pprev = epb->pprev;
*epb->pprev = epb->next;
epb->pprev = NULL;
}

__hlist_del(&epb->node);
sctp_write_unlock(&head->lock);
}

Expand All @@ -721,12 +711,13 @@ static struct sctp_endpoint *__sctp_rcv_lookup_endpoint(const union sctp_addr *l
struct sctp_hashbucket *head;
struct sctp_ep_common *epb;
struct sctp_endpoint *ep;
struct hlist_node *node;
int hash;

hash = sctp_ep_hashfn(ntohs(laddr->v4.sin_port));
head = &sctp_ep_hashtable[hash];
read_lock(&head->lock);
for (epb = head->chain; epb; epb = epb->next) {
sctp_for_each_hentry(epb, node, &head->chain) {
ep = sctp_ep(epb);
if (sctp_endpoint_is_match(ep, laddr))
goto hit;
Expand All @@ -744,7 +735,6 @@ static struct sctp_endpoint *__sctp_rcv_lookup_endpoint(const union sctp_addr *l
/* Insert association into the hash table. */
static void __sctp_hash_established(struct sctp_association *asoc)
{
struct sctp_ep_common **epp;
struct sctp_ep_common *epb;
struct sctp_hashbucket *head;

Expand All @@ -756,12 +746,7 @@ static void __sctp_hash_established(struct sctp_association *asoc)
head = &sctp_assoc_hashtable[epb->hashent];

sctp_write_lock(&head->lock);
epp = &head->chain;
epb->next = *epp;
if (epb->next)
(*epp)->pprev = &epb->next;
*epp = epb;
epb->pprev = epp;
hlist_add_head(&epb->node, &head->chain);
sctp_write_unlock(&head->lock);
}

Expand Down Expand Up @@ -790,14 +775,7 @@ static void __sctp_unhash_established(struct sctp_association *asoc)
head = &sctp_assoc_hashtable[epb->hashent];

sctp_write_lock(&head->lock);

if (epb->pprev) {
if (epb->next)
epb->next->pprev = epb->pprev;
*epb->pprev = epb->next;
epb->pprev = NULL;
}

__hlist_del(&epb->node);
sctp_write_unlock(&head->lock);
}

Expand All @@ -822,6 +800,7 @@ static struct sctp_association *__sctp_lookup_association(
struct sctp_ep_common *epb;
struct sctp_association *asoc;
struct sctp_transport *transport;
struct hlist_node *node;
int hash;

/* Optimize here for direct hit, only listening connections can
Expand All @@ -830,7 +809,7 @@ static struct sctp_association *__sctp_lookup_association(
hash = sctp_assoc_hashfn(ntohs(local->v4.sin_port), ntohs(peer->v4.sin_port));
head = &sctp_assoc_hashtable[hash];
read_lock(&head->lock);
for (epb = head->chain; epb; epb = epb->next) {
sctp_for_each_hentry(epb, node, &head->chain) {
asoc = sctp_assoc(epb);
transport = sctp_assoc_is_match(asoc, local, peer);
if (transport)
Expand Down
6 changes: 4 additions & 2 deletions trunk/net/sctp/proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ static int sctp_eps_seq_show(struct seq_file *seq, void *v)
struct sctp_ep_common *epb;
struct sctp_endpoint *ep;
struct sock *sk;
struct hlist_node *node;
int hash = *(loff_t *)v;

if (hash >= sctp_ep_hashsize)
Expand All @@ -233,7 +234,7 @@ static int sctp_eps_seq_show(struct seq_file *seq, void *v)
head = &sctp_ep_hashtable[hash];
sctp_local_bh_disable();
read_lock(&head->lock);
for (epb = head->chain; epb; epb = epb->next) {
sctp_for_each_hentry(epb, node, &head->chain) {
ep = sctp_ep(epb);
sk = epb->sk;
seq_printf(seq, "%8p %8p %-3d %-3d %-4d %-5d %5d %5lu ", ep, sk,
Expand Down Expand Up @@ -328,6 +329,7 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
struct sctp_ep_common *epb;
struct sctp_association *assoc;
struct sock *sk;
struct hlist_node *node;
int hash = *(loff_t *)v;

if (hash >= sctp_assoc_hashsize)
Expand All @@ -336,7 +338,7 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
head = &sctp_assoc_hashtable[hash];
sctp_local_bh_disable();
read_lock(&head->lock);
for (epb = head->chain; epb; epb = epb->next) {
sctp_for_each_hentry(epb, node, &head->chain) {
assoc = sctp_assoc(epb);
sk = epb->sk;
seq_printf(seq,
Expand Down
6 changes: 3 additions & 3 deletions trunk/net/sctp/protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,7 @@ SCTP_STATIC __init int sctp_init(void)
}
for (i = 0; i < sctp_assoc_hashsize; i++) {
rwlock_init(&sctp_assoc_hashtable[i].lock);
sctp_assoc_hashtable[i].chain = NULL;
INIT_HLIST_HEAD(&sctp_assoc_hashtable[i].chain);
}

/* Allocate and initialize the endpoint hash table. */
Expand All @@ -1151,7 +1151,7 @@ SCTP_STATIC __init int sctp_init(void)
}
for (i = 0; i < sctp_ep_hashsize; i++) {
rwlock_init(&sctp_ep_hashtable[i].lock);
sctp_ep_hashtable[i].chain = NULL;
INIT_HLIST_HEAD(&sctp_ep_hashtable[i].chain);
}

/* Allocate and initialize the SCTP port hash table. */
Expand All @@ -1170,7 +1170,7 @@ SCTP_STATIC __init int sctp_init(void)
}
for (i = 0; i < sctp_port_hashsize; i++) {
spin_lock_init(&sctp_port_hashtable[i].lock);
sctp_port_hashtable[i].chain = NULL;
INIT_HLIST_HEAD(&sctp_port_hashtable[i].chain);
}

printk(KERN_INFO "SCTP: Hash tables configured "
Expand Down
14 changes: 5 additions & 9 deletions trunk/net/sctp/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -5307,6 +5307,7 @@ static long sctp_get_port_local(struct sock *sk, union sctp_addr *addr)
{
struct sctp_bind_hashbucket *head; /* hash list */
struct sctp_bind_bucket *pp; /* hash list port iterator */
struct hlist_node *node;
unsigned short snum;
int ret;

Expand All @@ -5331,7 +5332,7 @@ static long sctp_get_port_local(struct sock *sk, union sctp_addr *addr)
index = sctp_phashfn(rover);
head = &sctp_port_hashtable[index];
sctp_spin_lock(&head->lock);
for (pp = head->chain; pp; pp = pp->next)
sctp_for_each_hentry(pp, node, &head->chain)
if (pp->port == rover)
goto next;
break;
Expand All @@ -5358,7 +5359,7 @@ static long sctp_get_port_local(struct sock *sk, union sctp_addr *addr)
*/
head = &sctp_port_hashtable[sctp_phashfn(snum)];
sctp_spin_lock(&head->lock);
for (pp = head->chain; pp; pp = pp->next) {
sctp_for_each_hentry(pp, node, &head->chain) {
if (pp->port == snum)
goto pp_found;
}
Expand Down Expand Up @@ -5702,10 +5703,7 @@ static struct sctp_bind_bucket *sctp_bucket_create(
pp->port = snum;
pp->fastreuse = 0;
INIT_HLIST_HEAD(&pp->owner);
if ((pp->next = head->chain) != NULL)
pp->next->pprev = &pp->next;
head->chain = pp;
pp->pprev = &head->chain;
hlist_add_head(&pp->node, &head->chain);
}
return pp;
}
Expand All @@ -5714,9 +5712,7 @@ static struct sctp_bind_bucket *sctp_bucket_create(
static void sctp_bucket_destroy(struct sctp_bind_bucket *pp)
{
if (pp && hlist_empty(&pp->owner)) {
if (pp->next)
pp->next->pprev = pp->pprev;
*(pp->pprev) = pp->next;
__hlist_del(&pp->node);
kmem_cache_free(sctp_bucket_cachep, pp);
SCTP_DBG_OBJCNT_DEC(bind_bucket);
}
Expand Down

0 comments on commit fa864a6

Please sign in to comment.