aboutsummaryrefslogtreecommitdiffstats
path: root/net/phonet
diff options
context:
space:
mode:
Diffstat (limited to 'net/phonet')
-rw-r--r--net/phonet/af_phonet.c72
-rw-r--r--net/phonet/pep-gprs.c227
-rw-r--r--net/phonet/pep.c38
-rw-r--r--net/phonet/pn_dev.c8
-rw-r--r--net/phonet/pn_netlink.c3
-rw-r--r--net/phonet/socket.c13
-rw-r--r--net/phonet/sysctl.c4
7 files changed, 173 insertions, 192 deletions
diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
index 9e9c6fce11aa..13cb323f8c38 100644
--- a/net/phonet/af_phonet.c
+++ b/net/phonet/af_phonet.c
@@ -33,9 +33,30 @@
33#include <net/phonet/phonet.h> 33#include <net/phonet/phonet.h>
34#include <net/phonet/pn_dev.h> 34#include <net/phonet/pn_dev.h>
35 35
36static struct net_proto_family phonet_proto_family; 36/* Transport protocol registration */
37static struct phonet_protocol *phonet_proto_get(int protocol); 37static struct phonet_protocol *proto_tab[PHONET_NPROTO] __read_mostly;
38static inline void phonet_proto_put(struct phonet_protocol *pp); 38static DEFINE_SPINLOCK(proto_tab_lock);
39
40static struct phonet_protocol *phonet_proto_get(int protocol)
41{
42 struct phonet_protocol *pp;
43
44 if (protocol >= PHONET_NPROTO)
45 return NULL;
46
47 spin_lock(&proto_tab_lock);
48 pp = proto_tab[protocol];
49 if (pp && !try_module_get(pp->prot->owner))
50 pp = NULL;
51 spin_unlock(&proto_tab_lock);
52
53 return pp;
54}
55
56static inline void phonet_proto_put(struct phonet_protocol *pp)
57{
58 module_put(pp->prot->owner);
59}
39 60
40/* protocol family functions */ 61/* protocol family functions */
41 62
@@ -46,9 +67,6 @@ static int pn_socket_create(struct net *net, struct socket *sock, int protocol)
46 struct phonet_protocol *pnp; 67 struct phonet_protocol *pnp;
47 int err; 68 int err;
48 69
49 if (net != &init_net)
50 return -EAFNOSUPPORT;
51
52 if (!capable(CAP_SYS_ADMIN)) 70 if (!capable(CAP_SYS_ADMIN))
53 return -EPERM; 71 return -EPERM;
54 72
@@ -67,11 +85,10 @@ static int pn_socket_create(struct net *net, struct socket *sock, int protocol)
67 } 85 }
68 86
69 pnp = phonet_proto_get(protocol); 87 pnp = phonet_proto_get(protocol);
70#ifdef CONFIG_KMOD
71 if (pnp == NULL && 88 if (pnp == NULL &&
72 request_module("net-pf-%d-proto-%d", PF_PHONET, protocol) == 0) 89 request_module("net-pf-%d-proto-%d", PF_PHONET, protocol) == 0)
73 pnp = phonet_proto_get(protocol); 90 pnp = phonet_proto_get(protocol);
74#endif 91
75 if (pnp == NULL) 92 if (pnp == NULL)
76 return -EPROTONOSUPPORT; 93 return -EPROTONOSUPPORT;
77 if (sock->type != pnp->sock_type) { 94 if (sock->type != pnp->sock_type) {
@@ -145,8 +162,8 @@ static int pn_send(struct sk_buff *skb, struct net_device *dev,
145 struct phonethdr *ph; 162 struct phonethdr *ph;
146 int err; 163 int err;
147 164
148 if (skb->len + 2 > 0xffff) { 165 if (skb->len + 2 > 0xffff /* Phonet length field limit */ ||
149 /* Phonet length field would overflow */ 166 skb->len + sizeof(struct phonethdr) > dev->mtu) {
150 err = -EMSGSIZE; 167 err = -EMSGSIZE;
151 goto drop; 168 goto drop;
152 } 169 }
@@ -262,6 +279,8 @@ static inline int can_respond(struct sk_buff *skb)
262 return 0; /* we are not the destination */ 279 return 0; /* we are not the destination */
263 if (ph->pn_res == PN_PREFIX && !pskb_may_pull(skb, 5)) 280 if (ph->pn_res == PN_PREFIX && !pskb_may_pull(skb, 5))
264 return 0; 281 return 0;
282 if (ph->pn_res == PN_COMMGR) /* indications */
283 return 0;
265 284
266 ph = pn_hdr(skb); /* re-acquires the pointer */ 285 ph = pn_hdr(skb); /* re-acquires the pointer */
267 pm = pn_msg(skb); 286 pm = pn_msg(skb);
@@ -310,7 +329,8 @@ static int send_reset_indications(struct sk_buff *rskb)
310 329
311 return pn_raw_send(data, sizeof(data), rskb->dev, 330 return pn_raw_send(data, sizeof(data), rskb->dev,
312 pn_object(oph->pn_sdev, 0x00), 331 pn_object(oph->pn_sdev, 0x00),
313 pn_object(oph->pn_rdev, oph->pn_robj), 0x10); 332 pn_object(oph->pn_rdev, oph->pn_robj),
333 PN_COMMGR);
314} 334}
315 335
316 336
@@ -329,9 +349,6 @@ static int phonet_rcv(struct sk_buff *skb, struct net_device *dev,
329 struct sockaddr_pn sa; 349 struct sockaddr_pn sa;
330 u16 len; 350 u16 len;
331 351
332 if (dev_net(dev) != &init_net)
333 goto out;
334
335 /* check we have at least a full Phonet header */ 352 /* check we have at least a full Phonet header */
336 if (!pskb_pull(skb, sizeof(struct phonethdr))) 353 if (!pskb_pull(skb, sizeof(struct phonethdr)))
337 goto out; 354 goto out;
@@ -350,7 +367,7 @@ static int phonet_rcv(struct sk_buff *skb, struct net_device *dev,
350 if (pn_sockaddr_get_addr(&sa) == 0) 367 if (pn_sockaddr_get_addr(&sa) == 0)
351 goto out; /* currently, we cannot be device 0 */ 368 goto out; /* currently, we cannot be device 0 */
352 369
353 sk = pn_find_sock_by_sa(&sa); 370 sk = pn_find_sock_by_sa(dev_net(dev), &sa);
354 if (sk == NULL) { 371 if (sk == NULL) {
355 if (can_respond(skb)) { 372 if (can_respond(skb)) {
356 send_obj_unreachable(skb); 373 send_obj_unreachable(skb);
@@ -373,10 +390,6 @@ static struct packet_type phonet_packet_type = {
373 .func = phonet_rcv, 390 .func = phonet_rcv,
374}; 391};
375 392
376/* Transport protocol registration */
377static struct phonet_protocol *proto_tab[PHONET_NPROTO] __read_mostly;
378static DEFINE_SPINLOCK(proto_tab_lock);
379
380int __init_or_module phonet_proto_register(int protocol, 393int __init_or_module phonet_proto_register(int protocol,
381 struct phonet_protocol *pp) 394 struct phonet_protocol *pp)
382{ 395{
@@ -410,27 +423,6 @@ void phonet_proto_unregister(int protocol, struct phonet_protocol *pp)
410} 423}
411EXPORT_SYMBOL(phonet_proto_unregister); 424EXPORT_SYMBOL(phonet_proto_unregister);
412 425
413static struct phonet_protocol *phonet_proto_get(int protocol)
414{
415 struct phonet_protocol *pp;
416
417 if (protocol >= PHONET_NPROTO)
418 return NULL;
419
420 spin_lock(&proto_tab_lock);
421 pp = proto_tab[protocol];
422 if (pp && !try_module_get(pp->prot->owner))
423 pp = NULL;
424 spin_unlock(&proto_tab_lock);
425
426 return pp;
427}
428
429static inline void phonet_proto_put(struct phonet_protocol *pp)
430{
431 module_put(pp->prot->owner);
432}
433
434/* Module registration */ 426/* Module registration */
435static int __init phonet_init(void) 427static int __init phonet_init(void)
436{ 428{
diff --git a/net/phonet/pep-gprs.c b/net/phonet/pep-gprs.c
index 9978afbd9f2a..b0ceac2d6cd1 100644
--- a/net/phonet/pep-gprs.c
+++ b/net/phonet/pep-gprs.c
@@ -40,23 +40,17 @@ struct gprs_dev {
40 void (*old_data_ready)(struct sock *, int); 40 void (*old_data_ready)(struct sock *, int);
41 void (*old_write_space)(struct sock *); 41 void (*old_write_space)(struct sock *);
42 42
43 struct net_device *net; 43 struct net_device *dev;
44 struct net_device_stats stats;
45
46 struct sk_buff_head tx_queue;
47 struct work_struct tx_work;
48 spinlock_t tx_lock;
49 unsigned tx_max;
50}; 44};
51 45
52static int gprs_type_trans(struct sk_buff *skb) 46static __be16 gprs_type_trans(struct sk_buff *skb)
53{ 47{
54 const u8 *pvfc; 48 const u8 *pvfc;
55 u8 buf; 49 u8 buf;
56 50
57 pvfc = skb_header_pointer(skb, 0, 1, &buf); 51 pvfc = skb_header_pointer(skb, 0, 1, &buf);
58 if (!pvfc) 52 if (!pvfc)
59 return 0; 53 return htons(0);
60 /* Look at IP version field */ 54 /* Look at IP version field */
61 switch (*pvfc >> 4) { 55 switch (*pvfc >> 4) {
62 case 4: 56 case 4:
@@ -64,7 +58,15 @@ static int gprs_type_trans(struct sk_buff *skb)
64 case 6: 58 case 6:
65 return htons(ETH_P_IPV6); 59 return htons(ETH_P_IPV6);
66 } 60 }
67 return 0; 61 return htons(0);
62}
63
64static void gprs_writeable(struct gprs_dev *gp)
65{
66 struct net_device *dev = gp->dev;
67
68 if (pep_writeable(gp->sk))
69 netif_wake_queue(dev);
68} 70}
69 71
70/* 72/*
@@ -73,18 +75,21 @@ static int gprs_type_trans(struct sk_buff *skb)
73 75
74static void gprs_state_change(struct sock *sk) 76static void gprs_state_change(struct sock *sk)
75{ 77{
76 struct gprs_dev *dev = sk->sk_user_data; 78 struct gprs_dev *gp = sk->sk_user_data;
77 79
78 if (sk->sk_state == TCP_CLOSE_WAIT) { 80 if (sk->sk_state == TCP_CLOSE_WAIT) {
79 netif_stop_queue(dev->net); 81 struct net_device *dev = gp->dev;
80 netif_carrier_off(dev->net); 82
83 netif_stop_queue(dev);
84 netif_carrier_off(dev);
81 } 85 }
82} 86}
83 87
84static int gprs_recv(struct gprs_dev *dev, struct sk_buff *skb) 88static int gprs_recv(struct gprs_dev *gp, struct sk_buff *skb)
85{ 89{
90 struct net_device *dev = gp->dev;
86 int err = 0; 91 int err = 0;
87 u16 protocol = gprs_type_trans(skb); 92 __be16 protocol = gprs_type_trans(skb);
88 93
89 if (!protocol) { 94 if (!protocol) {
90 err = -EINVAL; 95 err = -EINVAL;
@@ -99,7 +104,7 @@ static int gprs_recv(struct gprs_dev *dev, struct sk_buff *skb)
99 * so wrap the IP packet as a single fragment of an head-less 104 * so wrap the IP packet as a single fragment of an head-less
100 * socket buffer. The network stack will pull what it needs, 105 * socket buffer. The network stack will pull what it needs,
101 * but at least, the whole IP payload is not memcpy'd. */ 106 * but at least, the whole IP payload is not memcpy'd. */
102 rskb = netdev_alloc_skb(dev->net, 0); 107 rskb = netdev_alloc_skb(dev, 0);
103 if (!rskb) { 108 if (!rskb) {
104 err = -ENOBUFS; 109 err = -ENOBUFS;
105 goto drop; 110 goto drop;
@@ -123,9 +128,9 @@ static int gprs_recv(struct gprs_dev *dev, struct sk_buff *skb)
123 128
124 skb->protocol = protocol; 129 skb->protocol = protocol;
125 skb_reset_mac_header(skb); 130 skb_reset_mac_header(skb);
126 skb->dev = dev->net; 131 skb->dev = dev;
127 132
128 if (likely(dev->net->flags & IFF_UP)) { 133 if (likely(dev->flags & IFF_UP)) {
129 dev->stats.rx_packets++; 134 dev->stats.rx_packets++;
130 dev->stats.rx_bytes += skb->len; 135 dev->stats.rx_bytes += skb->len;
131 netif_rx(skb); 136 netif_rx(skb);
@@ -143,34 +148,46 @@ drop:
143 148
144static void gprs_data_ready(struct sock *sk, int len) 149static void gprs_data_ready(struct sock *sk, int len)
145{ 150{
146 struct gprs_dev *dev = sk->sk_user_data; 151 struct gprs_dev *gp = sk->sk_user_data;
147 struct sk_buff *skb; 152 struct sk_buff *skb;
148 153
149 while ((skb = pep_read(sk)) != NULL) { 154 while ((skb = pep_read(sk)) != NULL) {
150 skb_orphan(skb); 155 skb_orphan(skb);
151 gprs_recv(dev, skb); 156 gprs_recv(gp, skb);
152 } 157 }
153} 158}
154 159
155static void gprs_write_space(struct sock *sk) 160static void gprs_write_space(struct sock *sk)
156{ 161{
157 struct gprs_dev *dev = sk->sk_user_data; 162 struct gprs_dev *gp = sk->sk_user_data;
158 unsigned credits = pep_writeable(sk); 163
159 164 if (netif_running(gp->dev))
160 spin_lock_bh(&dev->tx_lock); 165 gprs_writeable(gp);
161 dev->tx_max = credits;
162 if (credits > skb_queue_len(&dev->tx_queue))
163 netif_wake_queue(dev->net);
164 spin_unlock_bh(&dev->tx_lock);
165} 166}
166 167
167/* 168/*
168 * Network device callbacks 169 * Network device callbacks
169 */ 170 */
170 171
171static int gprs_xmit(struct sk_buff *skb, struct net_device *net) 172static int gprs_open(struct net_device *dev)
172{ 173{
173 struct gprs_dev *dev = netdev_priv(net); 174 struct gprs_dev *gp = netdev_priv(dev);
175
176 gprs_writeable(gp);
177 return 0;
178}
179
180static int gprs_close(struct net_device *dev)
181{
182 netif_stop_queue(dev);
183 return 0;
184}
185
186static int gprs_xmit(struct sk_buff *skb, struct net_device *dev)
187{
188 struct gprs_dev *gp = netdev_priv(dev);
189 struct sock *sk = gp->sk;
190 int len, err;
174 191
175 switch (skb->protocol) { 192 switch (skb->protocol) {
176 case htons(ETH_P_IP): 193 case htons(ETH_P_IP):
@@ -181,82 +198,50 @@ static int gprs_xmit(struct sk_buff *skb, struct net_device *net)
181 return 0; 198 return 0;
182 } 199 }
183 200
184 spin_lock(&dev->tx_lock); 201 skb_orphan(skb);
185 if (likely(skb_queue_len(&dev->tx_queue) < dev->tx_max)) { 202 skb_set_owner_w(skb, sk);
186 skb_queue_tail(&dev->tx_queue, skb); 203 len = skb->len;
187 skb = NULL; 204 err = pep_write(sk, skb);
188 } 205 if (err) {
189 if (skb_queue_len(&dev->tx_queue) >= dev->tx_max) 206 LIMIT_NETDEBUG(KERN_WARNING"%s: TX error (%d)\n",
190 netif_stop_queue(net); 207 dev->name, err);
191 spin_unlock(&dev->tx_lock); 208 dev->stats.tx_aborted_errors++;
192 209 dev->stats.tx_errors++;
193 schedule_work(&dev->tx_work);
194 if (unlikely(skb))
195 dev_kfree_skb(skb); 210 dev_kfree_skb(skb);
196 return 0; 211 } else {
197}
198
199static void gprs_tx(struct work_struct *work)
200{
201 struct gprs_dev *dev = container_of(work, struct gprs_dev, tx_work);
202 struct sock *sk = dev->sk;
203 struct sk_buff *skb;
204
205 while ((skb = skb_dequeue(&dev->tx_queue)) != NULL) {
206 int err;
207
208 dev->stats.tx_bytes += skb->len;
209 dev->stats.tx_packets++; 212 dev->stats.tx_packets++;
210 213 dev->stats.tx_bytes += len;
211 skb_orphan(skb);
212 skb_set_owner_w(skb, sk);
213
214 lock_sock(sk);
215 err = pep_write(sk, skb);
216 if (err) {
217 LIMIT_NETDEBUG(KERN_WARNING"%s: TX error (%d)\n",
218 dev->net->name, err);
219 dev->stats.tx_aborted_errors++;
220 dev->stats.tx_errors++;
221 }
222 release_sock(sk);
223 } 214 }
224 215
225 lock_sock(sk); 216 if (!pep_writeable(sk))
226 gprs_write_space(sk); 217 netif_stop_queue(dev);
227 release_sock(sk); 218 return 0;
228} 219}
229 220
230static int gprs_set_mtu(struct net_device *net, int new_mtu) 221static int gprs_set_mtu(struct net_device *dev, int new_mtu)
231{ 222{
232 if ((new_mtu < 576) || (new_mtu > (PHONET_MAX_MTU - 11))) 223 if ((new_mtu < 576) || (new_mtu > (PHONET_MAX_MTU - 11)))
233 return -EINVAL; 224 return -EINVAL;
234 225
235 net->mtu = new_mtu; 226 dev->mtu = new_mtu;
236 return 0; 227 return 0;
237} 228}
238 229
239static struct net_device_stats *gprs_get_stats(struct net_device *net) 230static void gprs_setup(struct net_device *dev)
240{
241 struct gprs_dev *dev = netdev_priv(net);
242
243 return &dev->stats;
244}
245
246static void gprs_setup(struct net_device *net)
247{ 231{
248 net->features = NETIF_F_FRAGLIST; 232 dev->features = NETIF_F_FRAGLIST;
249 net->type = ARPHRD_NONE; 233 dev->type = ARPHRD_PHONET_PIPE;
250 net->flags = IFF_POINTOPOINT | IFF_NOARP; 234 dev->flags = IFF_POINTOPOINT | IFF_NOARP;
251 net->mtu = GPRS_DEFAULT_MTU; 235 dev->mtu = GPRS_DEFAULT_MTU;
252 net->hard_header_len = 0; 236 dev->hard_header_len = 0;
253 net->addr_len = 0; 237 dev->addr_len = 0;
254 net->tx_queue_len = 10; 238 dev->tx_queue_len = 10;
255 239
256 net->destructor = free_netdev; 240 dev->destructor = free_netdev;
257 net->hard_start_xmit = gprs_xmit; /* mandatory */ 241 dev->open = gprs_open;
258 net->change_mtu = gprs_set_mtu; 242 dev->stop = gprs_close;
259 net->get_stats = gprs_get_stats; 243 dev->hard_start_xmit = gprs_xmit; /* mandatory */
244 dev->change_mtu = gprs_set_mtu;
260} 245}
261 246
262/* 247/*
@@ -270,28 +255,25 @@ static void gprs_setup(struct net_device *net)
270int gprs_attach(struct sock *sk) 255int gprs_attach(struct sock *sk)
271{ 256{
272 static const char ifname[] = "gprs%d"; 257 static const char ifname[] = "gprs%d";
273 struct gprs_dev *dev; 258 struct gprs_dev *gp;
274 struct net_device *net; 259 struct net_device *dev;
275 int err; 260 int err;
276 261
277 if (unlikely(sk->sk_type == SOCK_STREAM)) 262 if (unlikely(sk->sk_type == SOCK_STREAM))
278 return -EINVAL; /* need packet boundaries */ 263 return -EINVAL; /* need packet boundaries */
279 264
280 /* Create net device */ 265 /* Create net device */
281 net = alloc_netdev(sizeof(*dev), ifname, gprs_setup); 266 dev = alloc_netdev(sizeof(*gp), ifname, gprs_setup);
282 if (!net) 267 if (!dev)
283 return -ENOMEM; 268 return -ENOMEM;
284 dev = netdev_priv(net); 269 gp = netdev_priv(dev);
285 dev->net = net; 270 gp->sk = sk;
286 dev->tx_max = 0; 271 gp->dev = dev;
287 spin_lock_init(&dev->tx_lock); 272
288 skb_queue_head_init(&dev->tx_queue); 273 netif_stop_queue(dev);
289 INIT_WORK(&dev->tx_work, gprs_tx); 274 err = register_netdev(dev);
290
291 netif_stop_queue(net);
292 err = register_netdev(net);
293 if (err) { 275 if (err) {
294 free_netdev(net); 276 free_netdev(dev);
295 return err; 277 return err;
296 } 278 }
297 279
@@ -305,43 +287,38 @@ int gprs_attach(struct sock *sk)
305 err = -EINVAL; 287 err = -EINVAL;
306 goto out_rel; 288 goto out_rel;
307 } 289 }
308 sk->sk_user_data = dev; 290 sk->sk_user_data = gp;
309 dev->old_state_change = sk->sk_state_change; 291 gp->old_state_change = sk->sk_state_change;
310 dev->old_data_ready = sk->sk_data_ready; 292 gp->old_data_ready = sk->sk_data_ready;
311 dev->old_write_space = sk->sk_write_space; 293 gp->old_write_space = sk->sk_write_space;
312 sk->sk_state_change = gprs_state_change; 294 sk->sk_state_change = gprs_state_change;
313 sk->sk_data_ready = gprs_data_ready; 295 sk->sk_data_ready = gprs_data_ready;
314 sk->sk_write_space = gprs_write_space; 296 sk->sk_write_space = gprs_write_space;
315 release_sock(sk); 297 release_sock(sk);
316
317 sock_hold(sk); 298 sock_hold(sk);
318 dev->sk = sk;
319 299
320 printk(KERN_DEBUG"%s: attached\n", net->name); 300 printk(KERN_DEBUG"%s: attached\n", dev->name);
321 gprs_write_space(sk); /* kick off TX */ 301 return dev->ifindex;
322 return net->ifindex;
323 302
324out_rel: 303out_rel:
325 release_sock(sk); 304 release_sock(sk);
326 unregister_netdev(net); 305 unregister_netdev(dev);
327 return err; 306 return err;
328} 307}
329 308
330void gprs_detach(struct sock *sk) 309void gprs_detach(struct sock *sk)
331{ 310{
332 struct gprs_dev *dev = sk->sk_user_data; 311 struct gprs_dev *gp = sk->sk_user_data;
333 struct net_device *net = dev->net; 312 struct net_device *dev = gp->dev;
334 313
335 lock_sock(sk); 314 lock_sock(sk);
336 sk->sk_user_data = NULL; 315 sk->sk_user_data = NULL;
337 sk->sk_state_change = dev->old_state_change; 316 sk->sk_state_change = gp->old_state_change;
338 sk->sk_data_ready = dev->old_data_ready; 317 sk->sk_data_ready = gp->old_data_ready;
339 sk->sk_write_space = dev->old_write_space; 318 sk->sk_write_space = gp->old_write_space;
340 release_sock(sk); 319 release_sock(sk);
341 320
342 printk(KERN_DEBUG"%s: detached\n", net->name); 321 printk(KERN_DEBUG"%s: detached\n", dev->name);
343 unregister_netdev(net); 322 unregister_netdev(dev);
344 flush_scheduled_work();
345 sock_put(sk); 323 sock_put(sk);
346 skb_queue_purge(&dev->tx_queue);
347} 324}
diff --git a/net/phonet/pep.c b/net/phonet/pep.c
index bc6d50f83249..bb3e67849b38 100644
--- a/net/phonet/pep.c
+++ b/net/phonet/pep.c
@@ -225,6 +225,7 @@ static int pipe_rcv_status(struct sock *sk, struct sk_buff *skb)
225{ 225{
226 struct pep_sock *pn = pep_sk(sk); 226 struct pep_sock *pn = pep_sk(sk);
227 struct pnpipehdr *hdr = pnp_hdr(skb); 227 struct pnpipehdr *hdr = pnp_hdr(skb);
228 int wake = 0;
228 229
229 if (!pskb_may_pull(skb, sizeof(*hdr) + 4)) 230 if (!pskb_may_pull(skb, sizeof(*hdr) + 4))
230 return -EINVAL; 231 return -EINVAL;
@@ -241,16 +242,16 @@ static int pipe_rcv_status(struct sock *sk, struct sk_buff *skb)
241 case PN_LEGACY_FLOW_CONTROL: 242 case PN_LEGACY_FLOW_CONTROL:
242 switch (hdr->data[4]) { 243 switch (hdr->data[4]) {
243 case PEP_IND_BUSY: 244 case PEP_IND_BUSY:
244 pn->tx_credits = 0; 245 atomic_set(&pn->tx_credits, 0);
245 break; 246 break;
246 case PEP_IND_READY: 247 case PEP_IND_READY:
247 pn->tx_credits = 1; 248 atomic_set(&pn->tx_credits, wake = 1);
248 break; 249 break;
249 } 250 }
250 break; 251 break;
251 case PN_ONE_CREDIT_FLOW_CONTROL: 252 case PN_ONE_CREDIT_FLOW_CONTROL:
252 if (hdr->data[4] == PEP_IND_READY) 253 if (hdr->data[4] == PEP_IND_READY)
253 pn->tx_credits = 1; 254 atomic_set(&pn->tx_credits, wake = 1);
254 break; 255 break;
255 } 256 }
256 break; 257 break;
@@ -258,10 +259,7 @@ static int pipe_rcv_status(struct sock *sk, struct sk_buff *skb)
258 case PN_PEP_IND_ID_MCFC_GRANT_CREDITS: 259 case PN_PEP_IND_ID_MCFC_GRANT_CREDITS:
259 if (pn->tx_fc != PN_MULTI_CREDIT_FLOW_CONTROL) 260 if (pn->tx_fc != PN_MULTI_CREDIT_FLOW_CONTROL)
260 break; 261 break;
261 if (pn->tx_credits + hdr->data[4] > 0xff) 262 atomic_add(wake = hdr->data[4], &pn->tx_credits);
262 pn->tx_credits = 0xff;
263 else
264 pn->tx_credits += hdr->data[4];
265 break; 263 break;
266 264
267 default: 265 default:
@@ -269,7 +267,7 @@ static int pipe_rcv_status(struct sock *sk, struct sk_buff *skb)
269 (unsigned)hdr->data[1]); 267 (unsigned)hdr->data[1]);
270 return -EOPNOTSUPP; 268 return -EOPNOTSUPP;
271 } 269 }
272 if (pn->tx_credits) 270 if (wake)
273 sk->sk_write_space(sk); 271 sk->sk_write_space(sk);
274 return 0; 272 return 0;
275} 273}
@@ -343,7 +341,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
343 } 341 }
344 /* fall through */ 342 /* fall through */
345 case PNS_PEP_DISABLE_REQ: 343 case PNS_PEP_DISABLE_REQ:
346 pn->tx_credits = 0; 344 atomic_set(&pn->tx_credits, 0);
347 pep_reply(sk, skb, PN_PIPE_NO_ERROR, NULL, 0, GFP_ATOMIC); 345 pep_reply(sk, skb, PN_PIPE_NO_ERROR, NULL, 0, GFP_ATOMIC);
348 break; 346 break;
349 347
@@ -390,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
390 /* fall through */ 388 /* fall through */
391 case PNS_PIPE_ENABLED_IND: 389 case PNS_PIPE_ENABLED_IND:
392 if (!pn_flow_safe(pn->tx_fc)) { 390 if (!pn_flow_safe(pn->tx_fc)) {
393 pn->tx_credits = 1; 391 atomic_set(&pn->tx_credits, 1);
394 sk->sk_write_space(sk); 392 sk->sk_write_space(sk);
395 } 393 }
396 if (sk->sk_state == TCP_ESTABLISHED) 394 if (sk->sk_state == TCP_ESTABLISHED)
@@ -504,8 +502,9 @@ static int pep_connreq_rcv(struct sock *sk, struct sk_buff *skb)
504 newpn->pn_sk.resource = pn->pn_sk.resource; 502 newpn->pn_sk.resource = pn->pn_sk.resource;
505 skb_queue_head_init(&newpn->ctrlreq_queue); 503 skb_queue_head_init(&newpn->ctrlreq_queue);
506 newpn->pipe_handle = pipe_handle; 504 newpn->pipe_handle = pipe_handle;
505 atomic_set(&newpn->tx_credits, 0);
507 newpn->peer_type = peer_type; 506 newpn->peer_type = peer_type;
508 newpn->rx_credits = newpn->tx_credits = 0; 507 newpn->rx_credits = 0;
509 newpn->rx_fc = newpn->tx_fc = PN_LEGACY_FLOW_CONTROL; 508 newpn->rx_fc = newpn->tx_fc = PN_LEGACY_FLOW_CONTROL;
510 newpn->init_enable = enabled; 509 newpn->init_enable = enabled;
511 510
@@ -821,14 +820,18 @@ static int pipe_skb_send(struct sock *sk, struct sk_buff *skb)
821 struct pep_sock *pn = pep_sk(sk); 820 struct pep_sock *pn = pep_sk(sk);
822 struct pnpipehdr *ph; 821 struct pnpipehdr *ph;
823 822
823 if (pn_flow_safe(pn->tx_fc) &&
824 !atomic_add_unless(&pn->tx_credits, -1, 0)) {
825 kfree_skb(skb);
826 return -ENOBUFS;
827 }
828
824 skb_push(skb, 3); 829 skb_push(skb, 3);
825 skb_reset_transport_header(skb); 830 skb_reset_transport_header(skb);
826 ph = pnp_hdr(skb); 831 ph = pnp_hdr(skb);
827 ph->utid = 0; 832 ph->utid = 0;
828 ph->message_id = PNS_PIPE_DATA; 833 ph->message_id = PNS_PIPE_DATA;
829 ph->pipe_handle = pn->pipe_handle; 834 ph->pipe_handle = pn->pipe_handle;
830 if (pn_flow_safe(pn->tx_fc) && pn->tx_credits)
831 pn->tx_credits--;
832 835
833 return pn_skb_send(sk, skb, &pipe_srv); 836 return pn_skb_send(sk, skb, &pipe_srv);
834} 837}
@@ -866,7 +869,7 @@ disabled:
866 BUG_ON(sk->sk_state != TCP_ESTABLISHED); 869 BUG_ON(sk->sk_state != TCP_ESTABLISHED);
867 870
868 /* Wait until flow control allows TX */ 871 /* Wait until flow control allows TX */
869 done = pn->tx_credits > 0; 872 done = atomic_read(&pn->tx_credits);
870 while (!done) { 873 while (!done) {
871 DEFINE_WAIT(wait); 874 DEFINE_WAIT(wait);
872 875
@@ -881,7 +884,7 @@ disabled:
881 884
882 prepare_to_wait(&sk->sk_socket->wait, &wait, 885 prepare_to_wait(&sk->sk_socket->wait, &wait,
883 TASK_INTERRUPTIBLE); 886 TASK_INTERRUPTIBLE);
884 done = sk_wait_event(sk, &timeo, pn->tx_credits > 0); 887 done = sk_wait_event(sk, &timeo, atomic_read(&pn->tx_credits));
885 finish_wait(&sk->sk_socket->wait, &wait); 888 finish_wait(&sk->sk_socket->wait, &wait);
886 889
887 if (sk->sk_state != TCP_ESTABLISHED) 890 if (sk->sk_state != TCP_ESTABLISHED)
@@ -895,7 +898,8 @@ disabled:
895 goto out; 898 goto out;
896 skb_reserve(skb, MAX_PHONET_HEADER + 3); 899 skb_reserve(skb, MAX_PHONET_HEADER + 3);
897 900
898 if (sk->sk_state != TCP_ESTABLISHED || !pn->tx_credits) 901 if (sk->sk_state != TCP_ESTABLISHED ||
902 !atomic_read(&pn->tx_credits))
899 goto disabled; /* sock_alloc_send_skb might sleep */ 903 goto disabled; /* sock_alloc_send_skb might sleep */
900 } 904 }
901 905
@@ -917,7 +921,7 @@ int pep_writeable(struct sock *sk)
917{ 921{
918 struct pep_sock *pn = pep_sk(sk); 922 struct pep_sock *pn = pep_sk(sk);
919 923
920 return (sk->sk_state == TCP_ESTABLISHED) ? pn->tx_credits : 0; 924 return atomic_read(&pn->tx_credits);
921} 925}
922 926
923int pep_write(struct sock *sk, struct sk_buff *skb) 927int pep_write(struct sock *sk, struct sk_buff *skb)
diff --git a/net/phonet/pn_dev.c b/net/phonet/pn_dev.c
index 53be9fc82aaa..5491bf5e354b 100644
--- a/net/phonet/pn_dev.c
+++ b/net/phonet/pn_dev.c
@@ -76,7 +76,7 @@ struct net_device *phonet_device_get(struct net *net)
76 dev = pnd->netdev; 76 dev = pnd->netdev;
77 BUG_ON(!dev); 77 BUG_ON(!dev);
78 78
79 if (dev_net(dev) == net && 79 if (net_eq(dev_net(dev), net) &&
80 (dev->reg_state == NETREG_REGISTERED) && 80 (dev->reg_state == NETREG_REGISTERED) &&
81 ((pnd->netdev->flags & IFF_UP)) == IFF_UP) 81 ((pnd->netdev->flags & IFF_UP)) == IFF_UP)
82 break; 82 break;
@@ -115,7 +115,7 @@ int phonet_address_del(struct net_device *dev, u8 addr)
115 pnd = __phonet_get(dev); 115 pnd = __phonet_get(dev);
116 if (!pnd || !test_and_clear_bit(addr >> 2, pnd->addrs)) 116 if (!pnd || !test_and_clear_bit(addr >> 2, pnd->addrs))
117 err = -EADDRNOTAVAIL; 117 err = -EADDRNOTAVAIL;
118 if (bitmap_empty(pnd->addrs, 64)) 118 else if (bitmap_empty(pnd->addrs, 64))
119 __phonet_device_free(pnd); 119 __phonet_device_free(pnd);
120 spin_unlock_bh(&pndevs.lock); 120 spin_unlock_bh(&pndevs.lock);
121 return err; 121 return err;
@@ -140,12 +140,14 @@ u8 phonet_address_get(struct net_device *dev, u8 addr)
140 return addr; 140 return addr;
141} 141}
142 142
143int phonet_address_lookup(u8 addr) 143int phonet_address_lookup(struct net *net, u8 addr)
144{ 144{
145 struct phonet_device *pnd; 145 struct phonet_device *pnd;
146 146
147 spin_lock_bh(&pndevs.lock); 147 spin_lock_bh(&pndevs.lock);
148 list_for_each_entry(pnd, &pndevs.list, list) { 148 list_for_each_entry(pnd, &pndevs.list, list) {
149 if (!net_eq(dev_net(pnd->netdev), net))
150 continue;
149 /* Don't allow unregistering devices! */ 151 /* Don't allow unregistering devices! */
150 if ((pnd->netdev->reg_state != NETREG_REGISTERED) || 152 if ((pnd->netdev->reg_state != NETREG_REGISTERED) ||
151 ((pnd->netdev->flags & IFF_UP)) != IFF_UP) 153 ((pnd->netdev->flags & IFF_UP)) != IFF_UP)
diff --git a/net/phonet/pn_netlink.c b/net/phonet/pn_netlink.c
index b1770d66bc8d..242fe8f8c322 100644
--- a/net/phonet/pn_netlink.c
+++ b/net/phonet/pn_netlink.c
@@ -123,6 +123,7 @@ nla_put_failure:
123 123
124static int getaddr_dumpit(struct sk_buff *skb, struct netlink_callback *cb) 124static int getaddr_dumpit(struct sk_buff *skb, struct netlink_callback *cb)
125{ 125{
126 struct net *net = sock_net(skb->sk);
126 struct phonet_device *pnd; 127 struct phonet_device *pnd;
127 int dev_idx = 0, dev_start_idx = cb->args[0]; 128 int dev_idx = 0, dev_start_idx = cb->args[0];
128 int addr_idx = 0, addr_start_idx = cb->args[1]; 129 int addr_idx = 0, addr_start_idx = cb->args[1];
@@ -131,6 +132,8 @@ static int getaddr_dumpit(struct sk_buff *skb, struct netlink_callback *cb)
131 list_for_each_entry(pnd, &pndevs.list, list) { 132 list_for_each_entry(pnd, &pndevs.list, list) {
132 u8 addr; 133 u8 addr;
133 134
135 if (!net_eq(dev_net(pnd->netdev), net))
136 continue;
134 if (dev_idx > dev_start_idx) 137 if (dev_idx > dev_start_idx)
135 addr_start_idx = 0; 138 addr_start_idx = 0;
136 if (dev_idx++ < dev_start_idx) 139 if (dev_idx++ < dev_start_idx)
diff --git a/net/phonet/socket.c b/net/phonet/socket.c
index d81740187fb4..ada2a35bf7a2 100644
--- a/net/phonet/socket.c
+++ b/net/phonet/socket.c
@@ -57,7 +57,7 @@ static struct {
57 * Find address based on socket address, match only certain fields. 57 * Find address based on socket address, match only certain fields.
58 * Also grab sock if it was found. Remember to sock_put it later. 58 * Also grab sock if it was found. Remember to sock_put it later.
59 */ 59 */
60struct sock *pn_find_sock_by_sa(const struct sockaddr_pn *spn) 60struct sock *pn_find_sock_by_sa(struct net *net, const struct sockaddr_pn *spn)
61{ 61{
62 struct hlist_node *node; 62 struct hlist_node *node;
63 struct sock *sknode; 63 struct sock *sknode;
@@ -71,6 +71,8 @@ struct sock *pn_find_sock_by_sa(const struct sockaddr_pn *spn)
71 struct pn_sock *pn = pn_sk(sknode); 71 struct pn_sock *pn = pn_sk(sknode);
72 BUG_ON(!pn->sobject); /* unbound socket */ 72 BUG_ON(!pn->sobject); /* unbound socket */
73 73
74 if (!net_eq(sock_net(sknode), net))
75 continue;
74 if (pn_port(obj)) { 76 if (pn_port(obj)) {
75 /* Look up socket by port */ 77 /* Look up socket by port */
76 if (pn_port(pn->sobject) != pn_port(obj)) 78 if (pn_port(pn->sobject) != pn_port(obj))
@@ -130,7 +132,7 @@ static int pn_socket_bind(struct socket *sock, struct sockaddr *addr, int len)
130 132
131 handle = pn_sockaddr_get_object((struct sockaddr_pn *)addr); 133 handle = pn_sockaddr_get_object((struct sockaddr_pn *)addr);
132 saddr = pn_addr(handle); 134 saddr = pn_addr(handle);
133 if (saddr && phonet_address_lookup(saddr)) 135 if (saddr && phonet_address_lookup(sock_net(sk), saddr))
134 return -EADDRNOTAVAIL; 136 return -EADDRNOTAVAIL;
135 137
136 lock_sock(sk); 138 lock_sock(sk);
@@ -225,7 +227,7 @@ static unsigned int pn_socket_poll(struct file *file, struct socket *sock,
225 if (!mask && sk->sk_state == TCP_CLOSE_WAIT) 227 if (!mask && sk->sk_state == TCP_CLOSE_WAIT)
226 return POLLHUP; 228 return POLLHUP;
227 229
228 if (sk->sk_state == TCP_ESTABLISHED && pn->tx_credits) 230 if (sk->sk_state == TCP_ESTABLISHED && atomic_read(&pn->tx_credits))
229 mask |= POLLOUT | POLLWRNORM | POLLWRBAND; 231 mask |= POLLOUT | POLLWRNORM | POLLWRBAND;
230 232
231 return mask; 233 return mask;
@@ -361,6 +363,7 @@ static DEFINE_MUTEX(port_mutex);
361int pn_sock_get_port(struct sock *sk, unsigned short sport) 363int pn_sock_get_port(struct sock *sk, unsigned short sport)
362{ 364{
363 static int port_cur; 365 static int port_cur;
366 struct net *net = sock_net(sk);
364 struct pn_sock *pn = pn_sk(sk); 367 struct pn_sock *pn = pn_sk(sk);
365 struct sockaddr_pn try_sa; 368 struct sockaddr_pn try_sa;
366 struct sock *tmpsk; 369 struct sock *tmpsk;
@@ -381,7 +384,7 @@ int pn_sock_get_port(struct sock *sk, unsigned short sport)
381 port_cur = pmin; 384 port_cur = pmin;
382 385
383 pn_sockaddr_set_port(&try_sa, port_cur); 386 pn_sockaddr_set_port(&try_sa, port_cur);
384 tmpsk = pn_find_sock_by_sa(&try_sa); 387 tmpsk = pn_find_sock_by_sa(net, &try_sa);
385 if (tmpsk == NULL) { 388 if (tmpsk == NULL) {
386 sport = port_cur; 389 sport = port_cur;
387 goto found; 390 goto found;
@@ -391,7 +394,7 @@ int pn_sock_get_port(struct sock *sk, unsigned short sport)
391 } else { 394 } else {
392 /* try to find specific port */ 395 /* try to find specific port */
393 pn_sockaddr_set_port(&try_sa, sport); 396 pn_sockaddr_set_port(&try_sa, sport);
394 tmpsk = pn_find_sock_by_sa(&try_sa); 397 tmpsk = pn_find_sock_by_sa(net, &try_sa);
395 if (tmpsk == NULL) 398 if (tmpsk == NULL)
396 /* No sock there! We can use that port... */ 399 /* No sock there! We can use that port... */
397 goto found; 400 goto found;
diff --git a/net/phonet/sysctl.c b/net/phonet/sysctl.c
index 600a4309b8c8..7b5749ee2765 100644
--- a/net/phonet/sysctl.c
+++ b/net/phonet/sysctl.c
@@ -89,13 +89,13 @@ static struct ctl_table phonet_table[] = {
89 .data = &local_port_range, 89 .data = &local_port_range,
90 .maxlen = sizeof(local_port_range), 90 .maxlen = sizeof(local_port_range),
91 .mode = 0644, 91 .mode = 0644,
92 .proc_handler = &proc_local_port_range, 92 .proc_handler = proc_local_port_range,
93 .strategy = NULL, 93 .strategy = NULL,
94 }, 94 },
95 { .ctl_name = 0 } 95 { .ctl_name = 0 }
96}; 96};
97 97
98struct ctl_path phonet_ctl_path[] = { 98static struct ctl_path phonet_ctl_path[] = {
99 { .procname = "net", .ctl_name = CTL_NET, }, 99 { .procname = "net", .ctl_name = CTL_NET, },
100 { .procname = "phonet", .ctl_name = CTL_UNNUMBERED, }, 100 { .procname = "phonet", .ctl_name = CTL_UNNUMBERED, },
101 { }, 101 { },