aboutsummaryrefslogtreecommitdiffstats
path: root/net/phonet
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2008-12-28 15:49:40 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2008-12-28 15:49:40 -0500
commit0191b625ca5a46206d2fb862bb08f36f2fcb3b31 (patch)
tree454d1842b1833d976da62abcbd5c47521ebe9bd7 /net/phonet
parent54a696bd07c14d3b1192d03ce7269bc59b45209a (diff)
parenteb56092fc168bf5af199d47af50c0d84a96db898 (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next-2.6
* git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next-2.6: (1429 commits) net: Allow dependancies of FDDI & Tokenring to be modular. igb: Fix build warning when DCA is disabled. net: Fix warning fallout from recent NAPI interface changes. gro: Fix potential use after free sfc: If AN is enabled, always read speed/duplex from the AN advertising bits sfc: When disabling the NIC, close the device rather than unregistering it sfc: SFT9001: Add cable diagnostics sfc: Add support for multiple PHY self-tests sfc: Merge top-level functions for self-tests sfc: Clean up PHY mode management in loopback self-test sfc: Fix unreliable link detection in some loopback modes sfc: Generate unique names for per-NIC workqueues 802.3ad: use standard ethhdr instead of ad_header 802.3ad: generalize out mac address initializer 802.3ad: initialize ports LACPDU from const initializer 802.3ad: remove typedef around ad_system 802.3ad: turn ports is_individual into a bool 802.3ad: turn ports is_enabled into a bool 802.3ad: make ntt bool ixgbe: Fix set_ringparam in ixgbe to use the same memory pools. ... Fixed trivial IPv4/6 address printing conflicts in fs/cifs/connect.c due to the conversion to %pI (in this networking merge) and the addition of doing IPv6 addresses (from the earlier merge of CIFS).
Diffstat (limited to 'net/phonet')
-rw-r--r--net/phonet/af_phonet.c8
-rw-r--r--net/phonet/pep-gprs.c218
-rw-r--r--net/phonet/pep.c38
-rw-r--r--net/phonet/pn_dev.c6
-rw-r--r--net/phonet/socket.c13
-rw-r--r--net/phonet/sysctl.c4
6 files changed, 125 insertions, 162 deletions
diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
index 9d211f12582b..13cb323f8c38 100644
--- a/net/phonet/af_phonet.c
+++ b/net/phonet/af_phonet.c
@@ -67,9 +67,6 @@ static int pn_socket_create(struct net *net, struct socket *sock, int protocol)
67 struct phonet_protocol *pnp; 67 struct phonet_protocol *pnp;
68 int err; 68 int err;
69 69
70 if (net != &init_net)
71 return -EAFNOSUPPORT;
72
73 if (!capable(CAP_SYS_ADMIN)) 70 if (!capable(CAP_SYS_ADMIN))
74 return -EPERM; 71 return -EPERM;
75 72
@@ -352,9 +349,6 @@ static int phonet_rcv(struct sk_buff *skb, struct net_device *dev,
352 struct sockaddr_pn sa; 349 struct sockaddr_pn sa;
353 u16 len; 350 u16 len;
354 351
355 if (dev_net(dev) != &init_net)
356 goto out;
357
358 /* check we have at least a full Phonet header */ 352 /* check we have at least a full Phonet header */
359 if (!pskb_pull(skb, sizeof(struct phonethdr))) 353 if (!pskb_pull(skb, sizeof(struct phonethdr)))
360 goto out; 354 goto out;
@@ -373,7 +367,7 @@ static int phonet_rcv(struct sk_buff *skb, struct net_device *dev,
373 if (pn_sockaddr_get_addr(&sa) == 0) 367 if (pn_sockaddr_get_addr(&sa) == 0)
374 goto out; /* currently, we cannot be device 0 */ 368 goto out; /* currently, we cannot be device 0 */
375 369
376 sk = pn_find_sock_by_sa(&sa); 370 sk = pn_find_sock_by_sa(dev_net(dev), &sa);
377 if (sk == NULL) { 371 if (sk == NULL) {
378 if (can_respond(skb)) { 372 if (can_respond(skb)) {
379 send_obj_unreachable(skb); 373 send_obj_unreachable(skb);
diff --git a/net/phonet/pep-gprs.c b/net/phonet/pep-gprs.c
index 803eeef0aa85..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,26 +148,21 @@ 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 struct net_device *net = dev->net; 163
159 unsigned credits = pep_writeable(sk); 164 if (netif_running(gp->dev))
160 165 gprs_writeable(gp);
161 spin_lock_bh(&dev->tx_lock);
162 dev->tx_max = credits;
163 if (credits > skb_queue_len(&dev->tx_queue) && netif_running(net))
164 netif_wake_queue(net);
165 spin_unlock_bh(&dev->tx_lock);
166} 166}
167 167
168/* 168/*
@@ -173,22 +173,21 @@ static int gprs_open(struct net_device *dev)
173{ 173{
174 struct gprs_dev *gp = netdev_priv(dev); 174 struct gprs_dev *gp = netdev_priv(dev);
175 175
176 gprs_write_space(gp->sk); 176 gprs_writeable(gp);
177 return 0; 177 return 0;
178} 178}
179 179
180static int gprs_close(struct net_device *dev) 180static int gprs_close(struct net_device *dev)
181{ 181{
182 struct gprs_dev *gp = netdev_priv(dev);
183
184 netif_stop_queue(dev); 182 netif_stop_queue(dev);
185 flush_work(&gp->tx_work);
186 return 0; 183 return 0;
187} 184}
188 185
189static int gprs_xmit(struct sk_buff *skb, struct net_device *net) 186static int gprs_xmit(struct sk_buff *skb, struct net_device *dev)
190{ 187{
191 struct gprs_dev *dev = netdev_priv(net); 188 struct gprs_dev *gp = netdev_priv(dev);
189 struct sock *sk = gp->sk;
190 int len, err;
192 191
193 switch (skb->protocol) { 192 switch (skb->protocol) {
194 case htons(ETH_P_IP): 193 case htons(ETH_P_IP):
@@ -199,84 +198,50 @@ static int gprs_xmit(struct sk_buff *skb, struct net_device *net)
199 return 0; 198 return 0;
200 } 199 }
201 200
202 spin_lock(&dev->tx_lock); 201 skb_orphan(skb);
203 if (likely(skb_queue_len(&dev->tx_queue) < dev->tx_max)) { 202 skb_set_owner_w(skb, sk);
204 skb_queue_tail(&dev->tx_queue, skb); 203 len = skb->len;
205 skb = NULL; 204 err = pep_write(sk, skb);
206 } 205 if (err) {
207 if (skb_queue_len(&dev->tx_queue) >= dev->tx_max) 206 LIMIT_NETDEBUG(KERN_WARNING"%s: TX error (%d)\n",
208 netif_stop_queue(net); 207 dev->name, err);
209 spin_unlock(&dev->tx_lock); 208 dev->stats.tx_aborted_errors++;
210 209 dev->stats.tx_errors++;
211 schedule_work(&dev->tx_work);
212 if (unlikely(skb))
213 dev_kfree_skb(skb); 210 dev_kfree_skb(skb);
214 return 0; 211 } else {
215}
216
217static void gprs_tx(struct work_struct *work)
218{
219 struct gprs_dev *dev = container_of(work, struct gprs_dev, tx_work);
220 struct sock *sk = dev->sk;
221 struct sk_buff *skb;
222
223 while ((skb = skb_dequeue(&dev->tx_queue)) != NULL) {
224 int err;
225
226 dev->stats.tx_bytes += skb->len;
227 dev->stats.tx_packets++; 212 dev->stats.tx_packets++;
228 213 dev->stats.tx_bytes += len;
229 skb_orphan(skb);
230 skb_set_owner_w(skb, sk);
231
232 lock_sock(sk);
233 err = pep_write(sk, skb);
234 if (err) {
235 LIMIT_NETDEBUG(KERN_WARNING"%s: TX error (%d)\n",
236 dev->net->name, err);
237 dev->stats.tx_aborted_errors++;
238 dev->stats.tx_errors++;
239 }
240 release_sock(sk);
241 } 214 }
242 215
243 lock_sock(sk); 216 if (!pep_writeable(sk))
244 gprs_write_space(sk); 217 netif_stop_queue(dev);
245 release_sock(sk); 218 return 0;
246} 219}
247 220
248static int gprs_set_mtu(struct net_device *net, int new_mtu) 221static int gprs_set_mtu(struct net_device *dev, int new_mtu)
249{ 222{
250 if ((new_mtu < 576) || (new_mtu > (PHONET_MAX_MTU - 11))) 223 if ((new_mtu < 576) || (new_mtu > (PHONET_MAX_MTU - 11)))
251 return -EINVAL; 224 return -EINVAL;
252 225
253 net->mtu = new_mtu; 226 dev->mtu = new_mtu;
254 return 0; 227 return 0;
255} 228}
256 229
257static struct net_device_stats *gprs_get_stats(struct net_device *net) 230static void gprs_setup(struct net_device *dev)
258{ 231{
259 struct gprs_dev *dev = netdev_priv(net); 232 dev->features = NETIF_F_FRAGLIST;
260 233 dev->type = ARPHRD_PHONET_PIPE;
261 return &dev->stats; 234 dev->flags = IFF_POINTOPOINT | IFF_NOARP;
262} 235 dev->mtu = GPRS_DEFAULT_MTU;
263 236 dev->hard_header_len = 0;
264static void gprs_setup(struct net_device *net) 237 dev->addr_len = 0;
265{ 238 dev->tx_queue_len = 10;
266 net->features = NETIF_F_FRAGLIST; 239
267 net->type = ARPHRD_NONE; 240 dev->destructor = free_netdev;
268 net->flags = IFF_POINTOPOINT | IFF_NOARP; 241 dev->open = gprs_open;
269 net->mtu = GPRS_DEFAULT_MTU; 242 dev->stop = gprs_close;
270 net->hard_header_len = 0; 243 dev->hard_start_xmit = gprs_xmit; /* mandatory */
271 net->addr_len = 0; 244 dev->change_mtu = gprs_set_mtu;
272 net->tx_queue_len = 10;
273
274 net->destructor = free_netdev;
275 net->open = gprs_open;
276 net->stop = gprs_close;
277 net->hard_start_xmit = gprs_xmit; /* mandatory */
278 net->change_mtu = gprs_set_mtu;
279 net->get_stats = gprs_get_stats;
280} 245}
281 246
282/* 247/*
@@ -290,28 +255,25 @@ static void gprs_setup(struct net_device *net)
290int gprs_attach(struct sock *sk) 255int gprs_attach(struct sock *sk)
291{ 256{
292 static const char ifname[] = "gprs%d"; 257 static const char ifname[] = "gprs%d";
293 struct gprs_dev *dev; 258 struct gprs_dev *gp;
294 struct net_device *net; 259 struct net_device *dev;
295 int err; 260 int err;
296 261
297 if (unlikely(sk->sk_type == SOCK_STREAM)) 262 if (unlikely(sk->sk_type == SOCK_STREAM))
298 return -EINVAL; /* need packet boundaries */ 263 return -EINVAL; /* need packet boundaries */
299 264
300 /* Create net device */ 265 /* Create net device */
301 net = alloc_netdev(sizeof(*dev), ifname, gprs_setup); 266 dev = alloc_netdev(sizeof(*gp), ifname, gprs_setup);
302 if (!net) 267 if (!dev)
303 return -ENOMEM; 268 return -ENOMEM;
304 dev = netdev_priv(net); 269 gp = netdev_priv(dev);
305 dev->net = net; 270 gp->sk = sk;
306 dev->tx_max = 0; 271 gp->dev = dev;
307 spin_lock_init(&dev->tx_lock); 272
308 skb_queue_head_init(&dev->tx_queue); 273 netif_stop_queue(dev);
309 INIT_WORK(&dev->tx_work, gprs_tx); 274 err = register_netdev(dev);
310
311 netif_stop_queue(net);
312 err = register_netdev(net);
313 if (err) { 275 if (err) {
314 free_netdev(net); 276 free_netdev(dev);
315 return err; 277 return err;
316 } 278 }
317 279
@@ -325,40 +287,38 @@ int gprs_attach(struct sock *sk)
325 err = -EINVAL; 287 err = -EINVAL;
326 goto out_rel; 288 goto out_rel;
327 } 289 }
328 sk->sk_user_data = dev; 290 sk->sk_user_data = gp;
329 dev->old_state_change = sk->sk_state_change; 291 gp->old_state_change = sk->sk_state_change;
330 dev->old_data_ready = sk->sk_data_ready; 292 gp->old_data_ready = sk->sk_data_ready;
331 dev->old_write_space = sk->sk_write_space; 293 gp->old_write_space = sk->sk_write_space;
332 sk->sk_state_change = gprs_state_change; 294 sk->sk_state_change = gprs_state_change;
333 sk->sk_data_ready = gprs_data_ready; 295 sk->sk_data_ready = gprs_data_ready;
334 sk->sk_write_space = gprs_write_space; 296 sk->sk_write_space = gprs_write_space;
335 release_sock(sk); 297 release_sock(sk);
336
337 sock_hold(sk); 298 sock_hold(sk);
338 dev->sk = sk;
339 299
340 printk(KERN_DEBUG"%s: attached\n", net->name); 300 printk(KERN_DEBUG"%s: attached\n", dev->name);
341 return net->ifindex; 301 return dev->ifindex;
342 302
343out_rel: 303out_rel:
344 release_sock(sk); 304 release_sock(sk);
345 unregister_netdev(net); 305 unregister_netdev(dev);
346 return err; 306 return err;
347} 307}
348 308
349void gprs_detach(struct sock *sk) 309void gprs_detach(struct sock *sk)
350{ 310{
351 struct gprs_dev *dev = sk->sk_user_data; 311 struct gprs_dev *gp = sk->sk_user_data;
352 struct net_device *net = dev->net; 312 struct net_device *dev = gp->dev;
353 313
354 lock_sock(sk); 314 lock_sock(sk);
355 sk->sk_user_data = NULL; 315 sk->sk_user_data = NULL;
356 sk->sk_state_change = dev->old_state_change; 316 sk->sk_state_change = gp->old_state_change;
357 sk->sk_data_ready = dev->old_data_ready; 317 sk->sk_data_ready = gp->old_data_ready;
358 sk->sk_write_space = dev->old_write_space; 318 sk->sk_write_space = gp->old_write_space;
359 release_sock(sk); 319 release_sock(sk);
360 320
361 printk(KERN_DEBUG"%s: detached\n", net->name); 321 printk(KERN_DEBUG"%s: detached\n", dev->name);
362 unregister_netdev(net); 322 unregister_netdev(dev);
363 sock_put(sk); 323 sock_put(sk);
364} 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 f93ff8ef47d0..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;
@@ -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/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 { },