aboutsummaryrefslogtreecommitdiffstats
path: root/net/phonet/socket.c
diff options
context:
space:
mode:
authorRémi Denis-Courmont <remi.denis-courmont@nokia.com>2009-11-08 21:17:01 -0500
committerDavid S. Miller <davem@davemloft.net>2009-11-10 23:54:33 -0500
commit6b0d07ba152893b40f1014a9db8da5aa564aa00e (patch)
tree012470cadabfe9307f9c4fbc1b2eb56efbb6edc7 /net/phonet/socket.c
parent4a9b5e5053a184ada2e9b19aee12b6200bb8980f (diff)
Phonet: put sockets in a hash table
Signed-off-by: Rémi Denis-Courmont <remi.denis-courmont@nokia.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/phonet/socket.c')
-rw-r--r--net/phonet/socket.c79
1 files changed, 54 insertions, 25 deletions
diff --git a/net/phonet/socket.c b/net/phonet/socket.c
index 0412beb59a05..4112b6e1c48a 100644
--- a/net/phonet/socket.c
+++ b/net/phonet/socket.c
@@ -45,13 +45,28 @@ static int pn_socket_release(struct socket *sock)
45 return 0; 45 return 0;
46} 46}
47 47
48#define PN_HASHSIZE 16
49#define PN_HASHMASK (PN_HASHSIZE-1)
50
51
48static struct { 52static struct {
49 struct hlist_head hlist; 53 struct hlist_head hlist[PN_HASHSIZE];
50 spinlock_t lock; 54 spinlock_t lock;
51} pnsocks = { 55} pnsocks;
52 .hlist = HLIST_HEAD_INIT, 56
53 .lock = __SPIN_LOCK_UNLOCKED(pnsocks.lock), 57void __init pn_sock_init(void)
54}; 58{
59 unsigned i;
60
61 for (i = 0; i < PN_HASHSIZE; i++)
62 INIT_HLIST_HEAD(pnsocks.hlist + i);
63 spin_lock_init(&pnsocks.lock);
64}
65
66static struct hlist_head *pn_hash_list(u16 obj)
67{
68 return pnsocks.hlist + (obj & PN_HASHMASK);
69}
55 70
56/* 71/*
57 * Find address based on socket address, match only certain fields. 72 * Find address based on socket address, match only certain fields.
@@ -64,10 +79,11 @@ struct sock *pn_find_sock_by_sa(struct net *net, const struct sockaddr_pn *spn)
64 struct sock *rval = NULL; 79 struct sock *rval = NULL;
65 u16 obj = pn_sockaddr_get_object(spn); 80 u16 obj = pn_sockaddr_get_object(spn);
66 u8 res = spn->spn_resource; 81 u8 res = spn->spn_resource;
82 struct hlist_head *hlist = pn_hash_list(obj);
67 83
68 spin_lock_bh(&pnsocks.lock); 84 spin_lock_bh(&pnsocks.lock);
69 85
70 sk_for_each(sknode, node, &pnsocks.hlist) { 86 sk_for_each(sknode, node, hlist) {
71 struct pn_sock *pn = pn_sk(sknode); 87 struct pn_sock *pn = pn_sk(sknode);
72 BUG_ON(!pn->sobject); /* unbound socket */ 88 BUG_ON(!pn->sobject); /* unbound socket */
73 89
@@ -99,31 +115,39 @@ struct sock *pn_find_sock_by_sa(struct net *net, const struct sockaddr_pn *spn)
99/* Deliver a broadcast packet (only in bottom-half) */ 115/* Deliver a broadcast packet (only in bottom-half) */
100void pn_deliver_sock_broadcast(struct net *net, struct sk_buff *skb) 116void pn_deliver_sock_broadcast(struct net *net, struct sk_buff *skb)
101{ 117{
102 struct hlist_node *node; 118 struct hlist_head *hlist = pnsocks.hlist;
103 struct sock *sknode; 119 unsigned h;
104 120
105 spin_lock(&pnsocks.lock); 121 spin_lock(&pnsocks.lock);
106 sk_for_each(sknode, node, &pnsocks.hlist) { 122 for (h = 0; h < PN_HASHSIZE; h++) {
107 struct sk_buff *clone; 123 struct hlist_node *node;
124 struct sock *sknode;
108 125
109 if (!net_eq(sock_net(sknode), net)) 126 sk_for_each(sknode, node, hlist) {
110 continue; 127 struct sk_buff *clone;
111 if (!sock_flag(sknode, SOCK_BROADCAST))
112 continue;
113 128
114 clone = skb_clone(skb, GFP_ATOMIC); 129 if (!net_eq(sock_net(sknode), net))
115 if (clone) { 130 continue;
116 sock_hold(sknode); 131 if (!sock_flag(sknode, SOCK_BROADCAST))
117 sk_receive_skb(sknode, clone, 0); 132 continue;
133
134 clone = skb_clone(skb, GFP_ATOMIC);
135 if (clone) {
136 sock_hold(sknode);
137 sk_receive_skb(sknode, clone, 0);
138 }
118 } 139 }
140 hlist++;
119 } 141 }
120 spin_unlock(&pnsocks.lock); 142 spin_unlock(&pnsocks.lock);
121} 143}
122 144
123void pn_sock_hash(struct sock *sk) 145void pn_sock_hash(struct sock *sk)
124{ 146{
147 struct hlist_head *hlist = pn_hash_list(pn_sk(sk)->sobject);
148
125 spin_lock_bh(&pnsocks.lock); 149 spin_lock_bh(&pnsocks.lock);
126 sk_add_node(sk, &pnsocks.hlist); 150 sk_add_node(sk, hlist);
127 spin_unlock_bh(&pnsocks.lock); 151 spin_unlock_bh(&pnsocks.lock);
128} 152}
129EXPORT_SYMBOL(pn_sock_hash); 153EXPORT_SYMBOL(pn_sock_hash);
@@ -439,15 +463,20 @@ EXPORT_SYMBOL(pn_sock_get_port);
439static struct sock *pn_sock_get_idx(struct seq_file *seq, loff_t pos) 463static struct sock *pn_sock_get_idx(struct seq_file *seq, loff_t pos)
440{ 464{
441 struct net *net = seq_file_net(seq); 465 struct net *net = seq_file_net(seq);
466 struct hlist_head *hlist = pnsocks.hlist;
442 struct hlist_node *node; 467 struct hlist_node *node;
443 struct sock *sknode; 468 struct sock *sknode;
469 unsigned h;
444 470
445 sk_for_each(sknode, node, &pnsocks.hlist) { 471 for (h = 0; h < PN_HASHSIZE; h++) {
446 if (!net_eq(net, sock_net(sknode))) 472 sk_for_each(sknode, node, hlist) {
447 continue; 473 if (!net_eq(net, sock_net(sknode)))
448 if (!pos) 474 continue;
449 return sknode; 475 if (!pos)
450 pos--; 476 return sknode;
477 pos--;
478 }
479 hlist++;
451 } 480 }
452 return NULL; 481 return NULL;
453} 482}