diff options
Diffstat (limited to 'net/atm/common.c')
-rw-r--r-- | net/atm/common.c | 389 |
1 files changed, 202 insertions, 187 deletions
diff --git a/net/atm/common.c b/net/atm/common.c index 950bd16d2383..97ed94aa0cbc 100644 --- a/net/atm/common.c +++ b/net/atm/common.c | |||
@@ -2,6 +2,7 @@ | |||
2 | 2 | ||
3 | /* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */ | 3 | /* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */ |
4 | 4 | ||
5 | #define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__ | ||
5 | 6 | ||
6 | #include <linux/module.h> | 7 | #include <linux/module.h> |
7 | #include <linux/kmod.h> | 8 | #include <linux/kmod.h> |
@@ -17,12 +18,12 @@ | |||
17 | #include <linux/skbuff.h> | 18 | #include <linux/skbuff.h> |
18 | #include <linux/bitops.h> | 19 | #include <linux/bitops.h> |
19 | #include <linux/init.h> | 20 | #include <linux/init.h> |
21 | #include <linux/slab.h> | ||
20 | #include <net/sock.h> /* struct sock */ | 22 | #include <net/sock.h> /* struct sock */ |
23 | #include <linux/uaccess.h> | ||
24 | #include <linux/poll.h> | ||
21 | 25 | ||
22 | #include <asm/uaccess.h> | ||
23 | #include <asm/atomic.h> | 26 | #include <asm/atomic.h> |
24 | #include <asm/poll.h> | ||
25 | |||
26 | 27 | ||
27 | #include "resources.h" /* atm_find_dev */ | 28 | #include "resources.h" /* atm_find_dev */ |
28 | #include "common.h" /* prototypes */ | 29 | #include "common.h" /* prototypes */ |
@@ -31,13 +32,15 @@ | |||
31 | #include "signaling.h" /* for WAITING and sigd_attach */ | 32 | #include "signaling.h" /* for WAITING and sigd_attach */ |
32 | 33 | ||
33 | struct hlist_head vcc_hash[VCC_HTABLE_SIZE]; | 34 | struct hlist_head vcc_hash[VCC_HTABLE_SIZE]; |
35 | EXPORT_SYMBOL(vcc_hash); | ||
36 | |||
34 | DEFINE_RWLOCK(vcc_sklist_lock); | 37 | DEFINE_RWLOCK(vcc_sklist_lock); |
38 | EXPORT_SYMBOL(vcc_sklist_lock); | ||
35 | 39 | ||
36 | static void __vcc_insert_socket(struct sock *sk) | 40 | static void __vcc_insert_socket(struct sock *sk) |
37 | { | 41 | { |
38 | struct atm_vcc *vcc = atm_sk(sk); | 42 | struct atm_vcc *vcc = atm_sk(sk); |
39 | struct hlist_head *head = &vcc_hash[vcc->vci & | 43 | struct hlist_head *head = &vcc_hash[vcc->vci & (VCC_HTABLE_SIZE - 1)]; |
40 | (VCC_HTABLE_SIZE - 1)]; | ||
41 | sk->sk_hash = vcc->vci & (VCC_HTABLE_SIZE - 1); | 44 | sk->sk_hash = vcc->vci & (VCC_HTABLE_SIZE - 1); |
42 | sk_add_node(sk, head); | 45 | sk_add_node(sk, head); |
43 | } | 46 | } |
@@ -48,6 +51,7 @@ void vcc_insert_socket(struct sock *sk) | |||
48 | __vcc_insert_socket(sk); | 51 | __vcc_insert_socket(sk); |
49 | write_unlock_irq(&vcc_sklist_lock); | 52 | write_unlock_irq(&vcc_sklist_lock); |
50 | } | 53 | } |
54 | EXPORT_SYMBOL(vcc_insert_socket); | ||
51 | 55 | ||
52 | static void vcc_remove_socket(struct sock *sk) | 56 | static void vcc_remove_socket(struct sock *sk) |
53 | { | 57 | { |
@@ -56,37 +60,32 @@ static void vcc_remove_socket(struct sock *sk) | |||
56 | write_unlock_irq(&vcc_sklist_lock); | 60 | write_unlock_irq(&vcc_sklist_lock); |
57 | } | 61 | } |
58 | 62 | ||
59 | 63 | static struct sk_buff *alloc_tx(struct atm_vcc *vcc, unsigned int size) | |
60 | static struct sk_buff *alloc_tx(struct atm_vcc *vcc,unsigned int size) | ||
61 | { | 64 | { |
62 | struct sk_buff *skb; | 65 | struct sk_buff *skb; |
63 | struct sock *sk = sk_atm(vcc); | 66 | struct sock *sk = sk_atm(vcc); |
64 | 67 | ||
65 | if (sk_wmem_alloc_get(sk) && !atm_may_send(vcc, size)) { | 68 | if (sk_wmem_alloc_get(sk) && !atm_may_send(vcc, size)) { |
66 | pr_debug("Sorry: wmem_alloc = %d, size = %d, sndbuf = %d\n", | 69 | pr_debug("Sorry: wmem_alloc = %d, size = %d, sndbuf = %d\n", |
67 | sk_wmem_alloc_get(sk), size, | 70 | sk_wmem_alloc_get(sk), size, sk->sk_sndbuf); |
68 | sk->sk_sndbuf); | ||
69 | return NULL; | 71 | return NULL; |
70 | } | 72 | } |
71 | while (!(skb = alloc_skb(size, GFP_KERNEL))) | 73 | while (!(skb = alloc_skb(size, GFP_KERNEL))) |
72 | schedule(); | 74 | schedule(); |
73 | pr_debug("AlTx %d += %d\n", sk_wmem_alloc_get(sk), skb->truesize); | 75 | pr_debug("%d += %d\n", sk_wmem_alloc_get(sk), skb->truesize); |
74 | atomic_add(skb->truesize, &sk->sk_wmem_alloc); | 76 | atomic_add(skb->truesize, &sk->sk_wmem_alloc); |
75 | return skb; | 77 | return skb; |
76 | } | 78 | } |
77 | 79 | ||
78 | |||
79 | EXPORT_SYMBOL(vcc_hash); | ||
80 | EXPORT_SYMBOL(vcc_sklist_lock); | ||
81 | EXPORT_SYMBOL(vcc_insert_socket); | ||
82 | |||
83 | static void vcc_sock_destruct(struct sock *sk) | 80 | static void vcc_sock_destruct(struct sock *sk) |
84 | { | 81 | { |
85 | if (atomic_read(&sk->sk_rmem_alloc)) | 82 | if (atomic_read(&sk->sk_rmem_alloc)) |
86 | printk(KERN_DEBUG "vcc_sock_destruct: rmem leakage (%d bytes) detected.\n", atomic_read(&sk->sk_rmem_alloc)); | 83 | printk(KERN_DEBUG "%s: rmem leakage (%d bytes) detected.\n", |
84 | __func__, atomic_read(&sk->sk_rmem_alloc)); | ||
87 | 85 | ||
88 | if (atomic_read(&sk->sk_wmem_alloc)) | 86 | if (atomic_read(&sk->sk_wmem_alloc)) |
89 | printk(KERN_DEBUG "vcc_sock_destruct: wmem leakage (%d bytes) detected.\n", atomic_read(&sk->sk_wmem_alloc)); | 87 | printk(KERN_DEBUG "%s: wmem leakage (%d bytes) detected.\n", |
88 | __func__, atomic_read(&sk->sk_wmem_alloc)); | ||
90 | } | 89 | } |
91 | 90 | ||
92 | static void vcc_def_wakeup(struct sock *sk) | 91 | static void vcc_def_wakeup(struct sock *sk) |
@@ -142,8 +141,8 @@ int vcc_create(struct net *net, struct socket *sock, int protocol, int family) | |||
142 | 141 | ||
143 | vcc = atm_sk(sk); | 142 | vcc = atm_sk(sk); |
144 | vcc->dev = NULL; | 143 | vcc->dev = NULL; |
145 | memset(&vcc->local,0,sizeof(struct sockaddr_atmsvc)); | 144 | memset(&vcc->local, 0, sizeof(struct sockaddr_atmsvc)); |
146 | memset(&vcc->remote,0,sizeof(struct sockaddr_atmsvc)); | 145 | memset(&vcc->remote, 0, sizeof(struct sockaddr_atmsvc)); |
147 | vcc->qos.txtp.max_sdu = 1 << 16; /* for meta VCs */ | 146 | vcc->qos.txtp.max_sdu = 1 << 16; /* for meta VCs */ |
148 | atomic_set(&sk->sk_wmem_alloc, 1); | 147 | atomic_set(&sk->sk_wmem_alloc, 1); |
149 | atomic_set(&sk->sk_rmem_alloc, 0); | 148 | atomic_set(&sk->sk_rmem_alloc, 0); |
@@ -156,7 +155,6 @@ int vcc_create(struct net *net, struct socket *sock, int protocol, int family) | |||
156 | return 0; | 155 | return 0; |
157 | } | 156 | } |
158 | 157 | ||
159 | |||
160 | static void vcc_destroy_socket(struct sock *sk) | 158 | static void vcc_destroy_socket(struct sock *sk) |
161 | { | 159 | { |
162 | struct atm_vcc *vcc = atm_sk(sk); | 160 | struct atm_vcc *vcc = atm_sk(sk); |
@@ -171,7 +169,7 @@ static void vcc_destroy_socket(struct sock *sk) | |||
171 | vcc->push(vcc, NULL); /* atmarpd has no push */ | 169 | vcc->push(vcc, NULL); /* atmarpd has no push */ |
172 | 170 | ||
173 | while ((skb = skb_dequeue(&sk->sk_receive_queue)) != NULL) { | 171 | while ((skb = skb_dequeue(&sk->sk_receive_queue)) != NULL) { |
174 | atm_return(vcc,skb->truesize); | 172 | atm_return(vcc, skb->truesize); |
175 | kfree_skb(skb); | 173 | kfree_skb(skb); |
176 | } | 174 | } |
177 | 175 | ||
@@ -182,7 +180,6 @@ static void vcc_destroy_socket(struct sock *sk) | |||
182 | vcc_remove_socket(sk); | 180 | vcc_remove_socket(sk); |
183 | } | 181 | } |
184 | 182 | ||
185 | |||
186 | int vcc_release(struct socket *sock) | 183 | int vcc_release(struct socket *sock) |
187 | { | 184 | { |
188 | struct sock *sk = sock->sk; | 185 | struct sock *sk = sock->sk; |
@@ -197,7 +194,6 @@ int vcc_release(struct socket *sock) | |||
197 | return 0; | 194 | return 0; |
198 | } | 195 | } |
199 | 196 | ||
200 | |||
201 | void vcc_release_async(struct atm_vcc *vcc, int reply) | 197 | void vcc_release_async(struct atm_vcc *vcc, int reply) |
202 | { | 198 | { |
203 | struct sock *sk = sk_atm(vcc); | 199 | struct sock *sk = sk_atm(vcc); |
@@ -208,8 +204,6 @@ void vcc_release_async(struct atm_vcc *vcc, int reply) | |||
208 | clear_bit(ATM_VF_WAITING, &vcc->flags); | 204 | clear_bit(ATM_VF_WAITING, &vcc->flags); |
209 | sk->sk_state_change(sk); | 205 | sk->sk_state_change(sk); |
210 | } | 206 | } |
211 | |||
212 | |||
213 | EXPORT_SYMBOL(vcc_release_async); | 207 | EXPORT_SYMBOL(vcc_release_async); |
214 | 208 | ||
215 | 209 | ||
@@ -235,37 +229,37 @@ void atm_dev_release_vccs(struct atm_dev *dev) | |||
235 | write_unlock_irq(&vcc_sklist_lock); | 229 | write_unlock_irq(&vcc_sklist_lock); |
236 | } | 230 | } |
237 | 231 | ||
238 | 232 | static int adjust_tp(struct atm_trafprm *tp, unsigned char aal) | |
239 | static int adjust_tp(struct atm_trafprm *tp,unsigned char aal) | ||
240 | { | 233 | { |
241 | int max_sdu; | 234 | int max_sdu; |
242 | 235 | ||
243 | if (!tp->traffic_class) return 0; | 236 | if (!tp->traffic_class) |
237 | return 0; | ||
244 | switch (aal) { | 238 | switch (aal) { |
245 | case ATM_AAL0: | 239 | case ATM_AAL0: |
246 | max_sdu = ATM_CELL_SIZE-1; | 240 | max_sdu = ATM_CELL_SIZE-1; |
247 | break; | 241 | break; |
248 | case ATM_AAL34: | 242 | case ATM_AAL34: |
249 | max_sdu = ATM_MAX_AAL34_PDU; | 243 | max_sdu = ATM_MAX_AAL34_PDU; |
250 | break; | 244 | break; |
251 | default: | 245 | default: |
252 | printk(KERN_WARNING "ATM: AAL problems ... " | 246 | pr_warning("AAL problems ... (%d)\n", aal); |
253 | "(%d)\n",aal); | 247 | /* fall through */ |
254 | /* fall through */ | 248 | case ATM_AAL5: |
255 | case ATM_AAL5: | 249 | max_sdu = ATM_MAX_AAL5_PDU; |
256 | max_sdu = ATM_MAX_AAL5_PDU; | ||
257 | } | 250 | } |
258 | if (!tp->max_sdu) tp->max_sdu = max_sdu; | 251 | if (!tp->max_sdu) |
259 | else if (tp->max_sdu > max_sdu) return -EINVAL; | 252 | tp->max_sdu = max_sdu; |
260 | if (!tp->max_cdv) tp->max_cdv = ATM_MAX_CDV; | 253 | else if (tp->max_sdu > max_sdu) |
254 | return -EINVAL; | ||
255 | if (!tp->max_cdv) | ||
256 | tp->max_cdv = ATM_MAX_CDV; | ||
261 | return 0; | 257 | return 0; |
262 | } | 258 | } |
263 | 259 | ||
264 | |||
265 | static int check_ci(const struct atm_vcc *vcc, short vpi, int vci) | 260 | static int check_ci(const struct atm_vcc *vcc, short vpi, int vci) |
266 | { | 261 | { |
267 | struct hlist_head *head = &vcc_hash[vci & | 262 | struct hlist_head *head = &vcc_hash[vci & (VCC_HTABLE_SIZE - 1)]; |
268 | (VCC_HTABLE_SIZE - 1)]; | ||
269 | struct hlist_node *node; | 263 | struct hlist_node *node; |
270 | struct sock *s; | 264 | struct sock *s; |
271 | struct atm_vcc *walk; | 265 | struct atm_vcc *walk; |
@@ -289,7 +283,6 @@ static int check_ci(const struct atm_vcc *vcc, short vpi, int vci) | |||
289 | return 0; | 283 | return 0; |
290 | } | 284 | } |
291 | 285 | ||
292 | |||
293 | static int find_ci(const struct atm_vcc *vcc, short *vpi, int *vci) | 286 | static int find_ci(const struct atm_vcc *vcc, short *vpi, int *vci) |
294 | { | 287 | { |
295 | static short p; /* poor man's per-device cache */ | 288 | static short p; /* poor man's per-device cache */ |
@@ -327,14 +320,13 @@ static int find_ci(const struct atm_vcc *vcc, short *vpi, int *vci) | |||
327 | if ((c == ATM_NOT_RSV_VCI || *vci != ATM_VCI_ANY) && | 320 | if ((c == ATM_NOT_RSV_VCI || *vci != ATM_VCI_ANY) && |
328 | *vpi == ATM_VPI_ANY) { | 321 | *vpi == ATM_VPI_ANY) { |
329 | p++; | 322 | p++; |
330 | if (p >= 1 << vcc->dev->ci_range.vpi_bits) p = 0; | 323 | if (p >= 1 << vcc->dev->ci_range.vpi_bits) |
324 | p = 0; | ||
331 | } | 325 | } |
332 | } | 326 | } while (old_p != p || old_c != c); |
333 | while (old_p != p || old_c != c); | ||
334 | return -EADDRINUSE; | 327 | return -EADDRINUSE; |
335 | } | 328 | } |
336 | 329 | ||
337 | |||
338 | static int __vcc_connect(struct atm_vcc *vcc, struct atm_dev *dev, short vpi, | 330 | static int __vcc_connect(struct atm_vcc *vcc, struct atm_dev *dev, short vpi, |
339 | int vci) | 331 | int vci) |
340 | { | 332 | { |
@@ -362,37 +354,46 @@ static int __vcc_connect(struct atm_vcc *vcc, struct atm_dev *dev, short vpi, | |||
362 | __vcc_insert_socket(sk); | 354 | __vcc_insert_socket(sk); |
363 | write_unlock_irq(&vcc_sklist_lock); | 355 | write_unlock_irq(&vcc_sklist_lock); |
364 | switch (vcc->qos.aal) { | 356 | switch (vcc->qos.aal) { |
365 | case ATM_AAL0: | 357 | case ATM_AAL0: |
366 | error = atm_init_aal0(vcc); | 358 | error = atm_init_aal0(vcc); |
367 | vcc->stats = &dev->stats.aal0; | 359 | vcc->stats = &dev->stats.aal0; |
368 | break; | 360 | break; |
369 | case ATM_AAL34: | 361 | case ATM_AAL34: |
370 | error = atm_init_aal34(vcc); | 362 | error = atm_init_aal34(vcc); |
371 | vcc->stats = &dev->stats.aal34; | 363 | vcc->stats = &dev->stats.aal34; |
372 | break; | 364 | break; |
373 | case ATM_NO_AAL: | 365 | case ATM_NO_AAL: |
374 | /* ATM_AAL5 is also used in the "0 for default" case */ | 366 | /* ATM_AAL5 is also used in the "0 for default" case */ |
375 | vcc->qos.aal = ATM_AAL5; | 367 | vcc->qos.aal = ATM_AAL5; |
376 | /* fall through */ | 368 | /* fall through */ |
377 | case ATM_AAL5: | 369 | case ATM_AAL5: |
378 | error = atm_init_aal5(vcc); | 370 | error = atm_init_aal5(vcc); |
379 | vcc->stats = &dev->stats.aal5; | 371 | vcc->stats = &dev->stats.aal5; |
380 | break; | 372 | break; |
381 | default: | 373 | default: |
382 | error = -EPROTOTYPE; | 374 | error = -EPROTOTYPE; |
383 | } | 375 | } |
384 | if (!error) error = adjust_tp(&vcc->qos.txtp,vcc->qos.aal); | 376 | if (!error) |
385 | if (!error) error = adjust_tp(&vcc->qos.rxtp,vcc->qos.aal); | 377 | error = adjust_tp(&vcc->qos.txtp, vcc->qos.aal); |
378 | if (!error) | ||
379 | error = adjust_tp(&vcc->qos.rxtp, vcc->qos.aal); | ||
386 | if (error) | 380 | if (error) |
387 | goto fail; | 381 | goto fail; |
388 | pr_debug("VCC %d.%d, AAL %d\n",vpi,vci,vcc->qos.aal); | 382 | pr_debug("VCC %d.%d, AAL %d\n", vpi, vci, vcc->qos.aal); |
389 | pr_debug(" TX: %d, PCR %d..%d, SDU %d\n",vcc->qos.txtp.traffic_class, | 383 | pr_debug(" TX: %d, PCR %d..%d, SDU %d\n", |
390 | vcc->qos.txtp.min_pcr,vcc->qos.txtp.max_pcr,vcc->qos.txtp.max_sdu); | 384 | vcc->qos.txtp.traffic_class, |
391 | pr_debug(" RX: %d, PCR %d..%d, SDU %d\n",vcc->qos.rxtp.traffic_class, | 385 | vcc->qos.txtp.min_pcr, |
392 | vcc->qos.rxtp.min_pcr,vcc->qos.rxtp.max_pcr,vcc->qos.rxtp.max_sdu); | 386 | vcc->qos.txtp.max_pcr, |
387 | vcc->qos.txtp.max_sdu); | ||
388 | pr_debug(" RX: %d, PCR %d..%d, SDU %d\n", | ||
389 | vcc->qos.rxtp.traffic_class, | ||
390 | vcc->qos.rxtp.min_pcr, | ||
391 | vcc->qos.rxtp.max_pcr, | ||
392 | vcc->qos.rxtp.max_sdu); | ||
393 | 393 | ||
394 | if (dev->ops->open) { | 394 | if (dev->ops->open) { |
395 | if ((error = dev->ops->open(vcc))) | 395 | error = dev->ops->open(vcc); |
396 | if (error) | ||
396 | goto fail; | 397 | goto fail; |
397 | } | 398 | } |
398 | return 0; | 399 | return 0; |
@@ -406,14 +407,13 @@ fail_module_put: | |||
406 | return error; | 407 | return error; |
407 | } | 408 | } |
408 | 409 | ||
409 | |||
410 | int vcc_connect(struct socket *sock, int itf, short vpi, int vci) | 410 | int vcc_connect(struct socket *sock, int itf, short vpi, int vci) |
411 | { | 411 | { |
412 | struct atm_dev *dev; | 412 | struct atm_dev *dev; |
413 | struct atm_vcc *vcc = ATM_SD(sock); | 413 | struct atm_vcc *vcc = ATM_SD(sock); |
414 | int error; | 414 | int error; |
415 | 415 | ||
416 | pr_debug("vcc_connect (vpi %d, vci %d)\n",vpi,vci); | 416 | pr_debug("(vpi %d, vci %d)\n", vpi, vci); |
417 | if (sock->state == SS_CONNECTED) | 417 | if (sock->state == SS_CONNECTED) |
418 | return -EISCONN; | 418 | return -EISCONN; |
419 | if (sock->state != SS_UNCONNECTED) | 419 | if (sock->state != SS_UNCONNECTED) |
@@ -422,30 +422,33 @@ int vcc_connect(struct socket *sock, int itf, short vpi, int vci) | |||
422 | return -EINVAL; | 422 | return -EINVAL; |
423 | 423 | ||
424 | if (vpi != ATM_VPI_UNSPEC && vci != ATM_VCI_UNSPEC) | 424 | if (vpi != ATM_VPI_UNSPEC && vci != ATM_VCI_UNSPEC) |
425 | clear_bit(ATM_VF_PARTIAL,&vcc->flags); | 425 | clear_bit(ATM_VF_PARTIAL, &vcc->flags); |
426 | else | 426 | else |
427 | if (test_bit(ATM_VF_PARTIAL,&vcc->flags)) | 427 | if (test_bit(ATM_VF_PARTIAL, &vcc->flags)) |
428 | return -EINVAL; | 428 | return -EINVAL; |
429 | pr_debug("vcc_connect (TX: cl %d,bw %d-%d,sdu %d; " | 429 | pr_debug("(TX: cl %d,bw %d-%d,sdu %d; " |
430 | "RX: cl %d,bw %d-%d,sdu %d,AAL %s%d)\n", | 430 | "RX: cl %d,bw %d-%d,sdu %d,AAL %s%d)\n", |
431 | vcc->qos.txtp.traffic_class,vcc->qos.txtp.min_pcr, | 431 | vcc->qos.txtp.traffic_class, vcc->qos.txtp.min_pcr, |
432 | vcc->qos.txtp.max_pcr,vcc->qos.txtp.max_sdu, | 432 | vcc->qos.txtp.max_pcr, vcc->qos.txtp.max_sdu, |
433 | vcc->qos.rxtp.traffic_class,vcc->qos.rxtp.min_pcr, | 433 | vcc->qos.rxtp.traffic_class, vcc->qos.rxtp.min_pcr, |
434 | vcc->qos.rxtp.max_pcr,vcc->qos.rxtp.max_sdu, | 434 | vcc->qos.rxtp.max_pcr, vcc->qos.rxtp.max_sdu, |
435 | vcc->qos.aal == ATM_AAL5 ? "" : vcc->qos.aal == ATM_AAL0 ? "" : | 435 | vcc->qos.aal == ATM_AAL5 ? "" : |
436 | " ??? code ",vcc->qos.aal == ATM_AAL0 ? 0 : vcc->qos.aal); | 436 | vcc->qos.aal == ATM_AAL0 ? "" : " ??? code ", |
437 | vcc->qos.aal == ATM_AAL0 ? 0 : vcc->qos.aal); | ||
437 | if (!test_bit(ATM_VF_HASQOS, &vcc->flags)) | 438 | if (!test_bit(ATM_VF_HASQOS, &vcc->flags)) |
438 | return -EBADFD; | 439 | return -EBADFD; |
439 | if (vcc->qos.txtp.traffic_class == ATM_ANYCLASS || | 440 | if (vcc->qos.txtp.traffic_class == ATM_ANYCLASS || |
440 | vcc->qos.rxtp.traffic_class == ATM_ANYCLASS) | 441 | vcc->qos.rxtp.traffic_class == ATM_ANYCLASS) |
441 | return -EINVAL; | 442 | return -EINVAL; |
442 | if (likely(itf != ATM_ITF_ANY)) { | 443 | if (likely(itf != ATM_ITF_ANY)) { |
443 | dev = try_then_request_module(atm_dev_lookup(itf), "atm-device-%d", itf); | 444 | dev = try_then_request_module(atm_dev_lookup(itf), |
445 | "atm-device-%d", itf); | ||
444 | } else { | 446 | } else { |
445 | dev = NULL; | 447 | dev = NULL; |
446 | mutex_lock(&atm_dev_mutex); | 448 | mutex_lock(&atm_dev_mutex); |
447 | if (!list_empty(&atm_devs)) { | 449 | if (!list_empty(&atm_devs)) { |
448 | dev = list_entry(atm_devs.next, struct atm_dev, dev_list); | 450 | dev = list_entry(atm_devs.next, |
451 | struct atm_dev, dev_list); | ||
449 | atm_dev_hold(dev); | 452 | atm_dev_hold(dev); |
450 | } | 453 | } |
451 | mutex_unlock(&atm_dev_mutex); | 454 | mutex_unlock(&atm_dev_mutex); |
@@ -458,13 +461,12 @@ int vcc_connect(struct socket *sock, int itf, short vpi, int vci) | |||
458 | return error; | 461 | return error; |
459 | } | 462 | } |
460 | if (vpi == ATM_VPI_UNSPEC || vci == ATM_VCI_UNSPEC) | 463 | if (vpi == ATM_VPI_UNSPEC || vci == ATM_VCI_UNSPEC) |
461 | set_bit(ATM_VF_PARTIAL,&vcc->flags); | 464 | set_bit(ATM_VF_PARTIAL, &vcc->flags); |
462 | if (test_bit(ATM_VF_READY,&ATM_SD(sock)->flags)) | 465 | if (test_bit(ATM_VF_READY, &ATM_SD(sock)->flags)) |
463 | sock->state = SS_CONNECTED; | 466 | sock->state = SS_CONNECTED; |
464 | return 0; | 467 | return 0; |
465 | } | 468 | } |
466 | 469 | ||
467 | |||
468 | int vcc_recvmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg, | 470 | int vcc_recvmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg, |
469 | size_t size, int flags) | 471 | size_t size, int flags) |
470 | { | 472 | { |
@@ -478,8 +480,8 @@ int vcc_recvmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg, | |||
478 | if (flags & ~MSG_DONTWAIT) /* only handle MSG_DONTWAIT */ | 480 | if (flags & ~MSG_DONTWAIT) /* only handle MSG_DONTWAIT */ |
479 | return -EOPNOTSUPP; | 481 | return -EOPNOTSUPP; |
480 | vcc = ATM_SD(sock); | 482 | vcc = ATM_SD(sock); |
481 | if (test_bit(ATM_VF_RELEASED,&vcc->flags) || | 483 | if (test_bit(ATM_VF_RELEASED, &vcc->flags) || |
482 | test_bit(ATM_VF_CLOSE,&vcc->flags) || | 484 | test_bit(ATM_VF_CLOSE, &vcc->flags) || |
483 | !test_bit(ATM_VF_READY, &vcc->flags)) | 485 | !test_bit(ATM_VF_READY, &vcc->flags)) |
484 | return 0; | 486 | return 0; |
485 | 487 | ||
@@ -496,14 +498,13 @@ int vcc_recvmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg, | |||
496 | error = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied); | 498 | error = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied); |
497 | if (error) | 499 | if (error) |
498 | return error; | 500 | return error; |
499 | sock_recv_timestamp(msg, sk, skb); | 501 | sock_recv_ts_and_drops(msg, sk, skb); |
500 | pr_debug("RcvM %d -= %d\n", atomic_read(&sk->sk_rmem_alloc), skb->truesize); | 502 | pr_debug("%d -= %d\n", atomic_read(&sk->sk_rmem_alloc), skb->truesize); |
501 | atm_return(vcc, skb->truesize); | 503 | atm_return(vcc, skb->truesize); |
502 | skb_free_datagram(sk, skb); | 504 | skb_free_datagram(sk, skb); |
503 | return copied; | 505 | return copied; |
504 | } | 506 | } |
505 | 507 | ||
506 | |||
507 | int vcc_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *m, | 508 | int vcc_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *m, |
508 | size_t total_len) | 509 | size_t total_len) |
509 | { | 510 | { |
@@ -511,7 +512,7 @@ int vcc_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *m, | |||
511 | DEFINE_WAIT(wait); | 512 | DEFINE_WAIT(wait); |
512 | struct atm_vcc *vcc; | 513 | struct atm_vcc *vcc; |
513 | struct sk_buff *skb; | 514 | struct sk_buff *skb; |
514 | int eff,error; | 515 | int eff, error; |
515 | const void __user *buff; | 516 | const void __user *buff; |
516 | int size; | 517 | int size; |
517 | 518 | ||
@@ -550,7 +551,7 @@ int vcc_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *m, | |||
550 | eff = (size+3) & ~3; /* align to word boundary */ | 551 | eff = (size+3) & ~3; /* align to word boundary */ |
551 | prepare_to_wait(sk->sk_sleep, &wait, TASK_INTERRUPTIBLE); | 552 | prepare_to_wait(sk->sk_sleep, &wait, TASK_INTERRUPTIBLE); |
552 | error = 0; | 553 | error = 0; |
553 | while (!(skb = alloc_tx(vcc,eff))) { | 554 | while (!(skb = alloc_tx(vcc, eff))) { |
554 | if (m->msg_flags & MSG_DONTWAIT) { | 555 | if (m->msg_flags & MSG_DONTWAIT) { |
555 | error = -EAGAIN; | 556 | error = -EAGAIN; |
556 | break; | 557 | break; |
@@ -560,9 +561,9 @@ int vcc_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *m, | |||
560 | error = -ERESTARTSYS; | 561 | error = -ERESTARTSYS; |
561 | break; | 562 | break; |
562 | } | 563 | } |
563 | if (test_bit(ATM_VF_RELEASED,&vcc->flags) || | 564 | if (test_bit(ATM_VF_RELEASED, &vcc->flags) || |
564 | test_bit(ATM_VF_CLOSE,&vcc->flags) || | 565 | test_bit(ATM_VF_CLOSE, &vcc->flags) || |
565 | !test_bit(ATM_VF_READY,&vcc->flags)) { | 566 | !test_bit(ATM_VF_READY, &vcc->flags)) { |
566 | error = -EPIPE; | 567 | error = -EPIPE; |
567 | send_sig(SIGPIPE, current, 0); | 568 | send_sig(SIGPIPE, current, 0); |
568 | break; | 569 | break; |
@@ -574,20 +575,20 @@ int vcc_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *m, | |||
574 | goto out; | 575 | goto out; |
575 | skb->dev = NULL; /* for paths shared with net_device interfaces */ | 576 | skb->dev = NULL; /* for paths shared with net_device interfaces */ |
576 | ATM_SKB(skb)->atm_options = vcc->atm_options; | 577 | ATM_SKB(skb)->atm_options = vcc->atm_options; |
577 | if (copy_from_user(skb_put(skb,size),buff,size)) { | 578 | if (copy_from_user(skb_put(skb, size), buff, size)) { |
578 | kfree_skb(skb); | 579 | kfree_skb(skb); |
579 | error = -EFAULT; | 580 | error = -EFAULT; |
580 | goto out; | 581 | goto out; |
581 | } | 582 | } |
582 | if (eff != size) memset(skb->data+size,0,eff-size); | 583 | if (eff != size) |
583 | error = vcc->dev->ops->send(vcc,skb); | 584 | memset(skb->data + size, 0, eff-size); |
585 | error = vcc->dev->ops->send(vcc, skb); | ||
584 | error = error ? error : size; | 586 | error = error ? error : size; |
585 | out: | 587 | out: |
586 | release_sock(sk); | 588 | release_sock(sk); |
587 | return error; | 589 | return error; |
588 | } | 590 | } |
589 | 591 | ||
590 | |||
591 | unsigned int vcc_poll(struct file *file, struct socket *sock, poll_table *wait) | 592 | unsigned int vcc_poll(struct file *file, struct socket *sock, poll_table *wait) |
592 | { | 593 | { |
593 | struct sock *sk = sock->sk; | 594 | struct sock *sk = sock->sk; |
@@ -623,8 +624,7 @@ unsigned int vcc_poll(struct file *file, struct socket *sock, poll_table *wait) | |||
623 | return mask; | 624 | return mask; |
624 | } | 625 | } |
625 | 626 | ||
626 | 627 | static int atm_change_qos(struct atm_vcc *vcc, struct atm_qos *qos) | |
627 | static int atm_change_qos(struct atm_vcc *vcc,struct atm_qos *qos) | ||
628 | { | 628 | { |
629 | int error; | 629 | int error; |
630 | 630 | ||
@@ -636,25 +636,31 @@ static int atm_change_qos(struct atm_vcc *vcc,struct atm_qos *qos) | |||
636 | qos->rxtp.traffic_class != vcc->qos.rxtp.traffic_class || | 636 | qos->rxtp.traffic_class != vcc->qos.rxtp.traffic_class || |
637 | qos->txtp.traffic_class != vcc->qos.txtp.traffic_class) | 637 | qos->txtp.traffic_class != vcc->qos.txtp.traffic_class) |
638 | return -EINVAL; | 638 | return -EINVAL; |
639 | error = adjust_tp(&qos->txtp,qos->aal); | 639 | error = adjust_tp(&qos->txtp, qos->aal); |
640 | if (!error) error = adjust_tp(&qos->rxtp,qos->aal); | 640 | if (!error) |
641 | if (error) return error; | 641 | error = adjust_tp(&qos->rxtp, qos->aal); |
642 | if (!vcc->dev->ops->change_qos) return -EOPNOTSUPP; | 642 | if (error) |
643 | return error; | ||
644 | if (!vcc->dev->ops->change_qos) | ||
645 | return -EOPNOTSUPP; | ||
643 | if (sk_atm(vcc)->sk_family == AF_ATMPVC) | 646 | if (sk_atm(vcc)->sk_family == AF_ATMPVC) |
644 | return vcc->dev->ops->change_qos(vcc,qos,ATM_MF_SET); | 647 | return vcc->dev->ops->change_qos(vcc, qos, ATM_MF_SET); |
645 | return svc_change_qos(vcc,qos); | 648 | return svc_change_qos(vcc, qos); |
646 | } | 649 | } |
647 | 650 | ||
648 | |||
649 | static int check_tp(const struct atm_trafprm *tp) | 651 | static int check_tp(const struct atm_trafprm *tp) |
650 | { | 652 | { |
651 | /* @@@ Should be merged with adjust_tp */ | 653 | /* @@@ Should be merged with adjust_tp */ |
652 | if (!tp->traffic_class || tp->traffic_class == ATM_ANYCLASS) return 0; | 654 | if (!tp->traffic_class || tp->traffic_class == ATM_ANYCLASS) |
655 | return 0; | ||
653 | if (tp->traffic_class != ATM_UBR && !tp->min_pcr && !tp->pcr && | 656 | if (tp->traffic_class != ATM_UBR && !tp->min_pcr && !tp->pcr && |
654 | !tp->max_pcr) return -EINVAL; | 657 | !tp->max_pcr) |
655 | if (tp->min_pcr == ATM_MAX_PCR) return -EINVAL; | 658 | return -EINVAL; |
659 | if (tp->min_pcr == ATM_MAX_PCR) | ||
660 | return -EINVAL; | ||
656 | if (tp->min_pcr && tp->max_pcr && tp->max_pcr != ATM_MAX_PCR && | 661 | if (tp->min_pcr && tp->max_pcr && tp->max_pcr != ATM_MAX_PCR && |
657 | tp->min_pcr > tp->max_pcr) return -EINVAL; | 662 | tp->min_pcr > tp->max_pcr) |
663 | return -EINVAL; | ||
658 | /* | 664 | /* |
659 | * We allow pcr to be outside [min_pcr,max_pcr], because later | 665 | * We allow pcr to be outside [min_pcr,max_pcr], because later |
660 | * adjustment may still push it in the valid range. | 666 | * adjustment may still push it in the valid range. |
@@ -662,7 +668,6 @@ static int check_tp(const struct atm_trafprm *tp) | |||
662 | return 0; | 668 | return 0; |
663 | } | 669 | } |
664 | 670 | ||
665 | |||
666 | static int check_qos(const struct atm_qos *qos) | 671 | static int check_qos(const struct atm_qos *qos) |
667 | { | 672 | { |
668 | int error; | 673 | int error; |
@@ -672,9 +677,11 @@ static int check_qos(const struct atm_qos *qos) | |||
672 | if (qos->txtp.traffic_class != qos->rxtp.traffic_class && | 677 | if (qos->txtp.traffic_class != qos->rxtp.traffic_class && |
673 | qos->txtp.traffic_class && qos->rxtp.traffic_class && | 678 | qos->txtp.traffic_class && qos->rxtp.traffic_class && |
674 | qos->txtp.traffic_class != ATM_ANYCLASS && | 679 | qos->txtp.traffic_class != ATM_ANYCLASS && |
675 | qos->rxtp.traffic_class != ATM_ANYCLASS) return -EINVAL; | 680 | qos->rxtp.traffic_class != ATM_ANYCLASS) |
681 | return -EINVAL; | ||
676 | error = check_tp(&qos->txtp); | 682 | error = check_tp(&qos->txtp); |
677 | if (error) return error; | 683 | if (error) |
684 | return error; | ||
678 | return check_tp(&qos->rxtp); | 685 | return check_tp(&qos->rxtp); |
679 | } | 686 | } |
680 | 687 | ||
@@ -690,37 +697,41 @@ int vcc_setsockopt(struct socket *sock, int level, int optname, | |||
690 | 697 | ||
691 | vcc = ATM_SD(sock); | 698 | vcc = ATM_SD(sock); |
692 | switch (optname) { | 699 | switch (optname) { |
693 | case SO_ATMQOS: | 700 | case SO_ATMQOS: |
694 | { | 701 | { |
695 | struct atm_qos qos; | 702 | struct atm_qos qos; |
696 | 703 | ||
697 | if (copy_from_user(&qos,optval,sizeof(qos))) | 704 | if (copy_from_user(&qos, optval, sizeof(qos))) |
698 | return -EFAULT; | 705 | return -EFAULT; |
699 | error = check_qos(&qos); | 706 | error = check_qos(&qos); |
700 | if (error) return error; | 707 | if (error) |
701 | if (sock->state == SS_CONNECTED) | 708 | return error; |
702 | return atm_change_qos(vcc,&qos); | 709 | if (sock->state == SS_CONNECTED) |
703 | if (sock->state != SS_UNCONNECTED) | 710 | return atm_change_qos(vcc, &qos); |
704 | return -EBADFD; | 711 | if (sock->state != SS_UNCONNECTED) |
705 | vcc->qos = qos; | 712 | return -EBADFD; |
706 | set_bit(ATM_VF_HASQOS,&vcc->flags); | 713 | vcc->qos = qos; |
707 | return 0; | 714 | set_bit(ATM_VF_HASQOS, &vcc->flags); |
708 | } | 715 | return 0; |
709 | case SO_SETCLP: | ||
710 | if (get_user(value,(unsigned long __user *)optval)) | ||
711 | return -EFAULT; | ||
712 | if (value) vcc->atm_options |= ATM_ATMOPT_CLP; | ||
713 | else vcc->atm_options &= ~ATM_ATMOPT_CLP; | ||
714 | return 0; | ||
715 | default: | ||
716 | if (level == SOL_SOCKET) return -EINVAL; | ||
717 | break; | ||
718 | } | 716 | } |
719 | if (!vcc->dev || !vcc->dev->ops->setsockopt) return -EINVAL; | 717 | case SO_SETCLP: |
720 | return vcc->dev->ops->setsockopt(vcc,level,optname,optval,optlen); | 718 | if (get_user(value, (unsigned long __user *)optval)) |
719 | return -EFAULT; | ||
720 | if (value) | ||
721 | vcc->atm_options |= ATM_ATMOPT_CLP; | ||
722 | else | ||
723 | vcc->atm_options &= ~ATM_ATMOPT_CLP; | ||
724 | return 0; | ||
725 | default: | ||
726 | if (level == SOL_SOCKET) | ||
727 | return -EINVAL; | ||
728 | break; | ||
729 | } | ||
730 | if (!vcc->dev || !vcc->dev->ops->setsockopt) | ||
731 | return -EINVAL; | ||
732 | return vcc->dev->ops->setsockopt(vcc, level, optname, optval, optlen); | ||
721 | } | 733 | } |
722 | 734 | ||
723 | |||
724 | int vcc_getsockopt(struct socket *sock, int level, int optname, | 735 | int vcc_getsockopt(struct socket *sock, int level, int optname, |
725 | char __user *optval, int __user *optlen) | 736 | char __user *optval, int __user *optlen) |
726 | { | 737 | { |
@@ -734,33 +745,33 @@ int vcc_getsockopt(struct socket *sock, int level, int optname, | |||
734 | 745 | ||
735 | vcc = ATM_SD(sock); | 746 | vcc = ATM_SD(sock); |
736 | switch (optname) { | 747 | switch (optname) { |
737 | case SO_ATMQOS: | 748 | case SO_ATMQOS: |
738 | if (!test_bit(ATM_VF_HASQOS,&vcc->flags)) | 749 | if (!test_bit(ATM_VF_HASQOS, &vcc->flags)) |
739 | return -EINVAL; | 750 | return -EINVAL; |
740 | return copy_to_user(optval,&vcc->qos,sizeof(vcc->qos)) ? | 751 | return copy_to_user(optval, &vcc->qos, sizeof(vcc->qos)) |
741 | -EFAULT : 0; | 752 | ? -EFAULT : 0; |
742 | case SO_SETCLP: | 753 | case SO_SETCLP: |
743 | return put_user(vcc->atm_options & ATM_ATMOPT_CLP ? 1 : | 754 | return put_user(vcc->atm_options & ATM_ATMOPT_CLP ? 1 : 0, |
744 | 0,(unsigned long __user *)optval) ? -EFAULT : 0; | 755 | (unsigned long __user *)optval) ? -EFAULT : 0; |
745 | case SO_ATMPVC: | 756 | case SO_ATMPVC: |
746 | { | 757 | { |
747 | struct sockaddr_atmpvc pvc; | 758 | struct sockaddr_atmpvc pvc; |
748 | 759 | ||
749 | if (!vcc->dev || | 760 | if (!vcc->dev || !test_bit(ATM_VF_ADDR, &vcc->flags)) |
750 | !test_bit(ATM_VF_ADDR,&vcc->flags)) | 761 | return -ENOTCONN; |
751 | return -ENOTCONN; | 762 | pvc.sap_family = AF_ATMPVC; |
752 | pvc.sap_family = AF_ATMPVC; | 763 | pvc.sap_addr.itf = vcc->dev->number; |
753 | pvc.sap_addr.itf = vcc->dev->number; | 764 | pvc.sap_addr.vpi = vcc->vpi; |
754 | pvc.sap_addr.vpi = vcc->vpi; | 765 | pvc.sap_addr.vci = vcc->vci; |
755 | pvc.sap_addr.vci = vcc->vci; | 766 | return copy_to_user(optval, &pvc, sizeof(pvc)) ? -EFAULT : 0; |
756 | return copy_to_user(optval,&pvc,sizeof(pvc)) ? | 767 | } |
757 | -EFAULT : 0; | 768 | default: |
758 | } | 769 | if (level == SOL_SOCKET) |
759 | default: | 770 | return -EINVAL; |
760 | if (level == SOL_SOCKET) return -EINVAL; | ||
761 | break; | 771 | break; |
762 | } | 772 | } |
763 | if (!vcc->dev || !vcc->dev->ops->getsockopt) return -EINVAL; | 773 | if (!vcc->dev || !vcc->dev->ops->getsockopt) |
774 | return -EINVAL; | ||
764 | return vcc->dev->ops->getsockopt(vcc, level, optname, optval, len); | 775 | return vcc->dev->ops->getsockopt(vcc, level, optname, optval, len); |
765 | } | 776 | } |
766 | 777 | ||
@@ -768,23 +779,27 @@ static int __init atm_init(void) | |||
768 | { | 779 | { |
769 | int error; | 780 | int error; |
770 | 781 | ||
771 | if ((error = proto_register(&vcc_proto, 0)) < 0) | 782 | error = proto_register(&vcc_proto, 0); |
783 | if (error < 0) | ||
772 | goto out; | 784 | goto out; |
773 | 785 | error = atmpvc_init(); | |
774 | if ((error = atmpvc_init()) < 0) { | 786 | if (error < 0) { |
775 | printk(KERN_ERR "atmpvc_init() failed with %d\n", error); | 787 | pr_err("atmpvc_init() failed with %d\n", error); |
776 | goto out_unregister_vcc_proto; | 788 | goto out_unregister_vcc_proto; |
777 | } | 789 | } |
778 | if ((error = atmsvc_init()) < 0) { | 790 | error = atmsvc_init(); |
779 | printk(KERN_ERR "atmsvc_init() failed with %d\n", error); | 791 | if (error < 0) { |
792 | pr_err("atmsvc_init() failed with %d\n", error); | ||
780 | goto out_atmpvc_exit; | 793 | goto out_atmpvc_exit; |
781 | } | 794 | } |
782 | if ((error = atm_proc_init()) < 0) { | 795 | error = atm_proc_init(); |
783 | printk(KERN_ERR "atm_proc_init() failed with %d\n",error); | 796 | if (error < 0) { |
797 | pr_err("atm_proc_init() failed with %d\n", error); | ||
784 | goto out_atmsvc_exit; | 798 | goto out_atmsvc_exit; |
785 | } | 799 | } |
786 | if ((error = atm_sysfs_init()) < 0) { | 800 | error = atm_sysfs_init(); |
787 | printk(KERN_ERR "atm_sysfs_init() failed with %d\n",error); | 801 | if (error < 0) { |
802 | pr_err("atm_sysfs_init() failed with %d\n", error); | ||
788 | goto out_atmproc_exit; | 803 | goto out_atmproc_exit; |
789 | } | 804 | } |
790 | out: | 805 | out: |