diff options
Diffstat (limited to 'net')
-rw-r--r-- | net/phonet/af_phonet.c | 1 | ||||
-rw-r--r-- | net/phonet/socket.c | 79 |
2 files changed, 55 insertions, 25 deletions
diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c index 3bd1be6b26f0..8d3a55b4a30c 100644 --- a/net/phonet/af_phonet.c +++ b/net/phonet/af_phonet.c | |||
@@ -481,6 +481,7 @@ static int __init phonet_init(void) | |||
481 | if (err) | 481 | if (err) |
482 | return err; | 482 | return err; |
483 | 483 | ||
484 | pn_sock_init(); | ||
484 | err = sock_register(&phonet_proto_family); | 485 | err = sock_register(&phonet_proto_family); |
485 | if (err) { | 486 | if (err) { |
486 | printk(KERN_ALERT | 487 | printk(KERN_ALERT |
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 | |||
48 | static struct { | 52 | static 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), | 57 | void __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 | |||
66 | static 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) */ |
100 | void pn_deliver_sock_broadcast(struct net *net, struct sk_buff *skb) | 116 | void 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 | ||
123 | void pn_sock_hash(struct sock *sk) | 145 | void 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 | } |
129 | EXPORT_SYMBOL(pn_sock_hash); | 153 | EXPORT_SYMBOL(pn_sock_hash); |
@@ -439,15 +463,20 @@ EXPORT_SYMBOL(pn_sock_get_port); | |||
439 | static struct sock *pn_sock_get_idx(struct seq_file *seq, loff_t pos) | 463 | static 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 | } |