1 /* net/atm/common.c - ATM sockets (common part for PVC and SVC) */
3 /* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */
5 #define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__
7 #include <linux/module.h>
8 #include <linux/kmod.h>
9 #include <linux/net.h> /* struct socket, struct proto_ops */
10 #include <linux/atm.h> /* ATM stuff */
11 #include <linux/atmdev.h>
12 #include <linux/socket.h> /* SOL_SOCKET */
13 #include <linux/errno.h> /* error codes */
14 #include <linux/capability.h>
16 #include <linux/sched.h>
17 #include <linux/time.h> /* struct timeval */
18 #include <linux/skbuff.h>
19 #include <linux/bitops.h>
20 #include <linux/init.h>
21 #include <linux/slab.h>
22 #include <net/sock.h> /* struct sock */
23 #include <linux/uaccess.h>
24 #include <linux/poll.h>
26 #include <linux/atomic.h>
28 #include "resources.h" /* atm_find_dev */
29 #include "common.h" /* prototypes */
30 #include "protocols.h" /* atm_init_<transport> */
31 #include "addr.h" /* address registry */
32 #include "signaling.h" /* for WAITING and sigd_attach */
34 struct hlist_head vcc_hash
[VCC_HTABLE_SIZE
];
35 EXPORT_SYMBOL(vcc_hash
);
37 DEFINE_RWLOCK(vcc_sklist_lock
);
38 EXPORT_SYMBOL(vcc_sklist_lock
);
40 static ATOMIC_NOTIFIER_HEAD(atm_dev_notify_chain
);
42 static void __vcc_insert_socket(struct sock
*sk
)
44 struct atm_vcc
*vcc
= atm_sk(sk
);
45 struct hlist_head
*head
= &vcc_hash
[vcc
->vci
& (VCC_HTABLE_SIZE
- 1)];
46 sk
->sk_hash
= vcc
->vci
& (VCC_HTABLE_SIZE
- 1);
47 sk_add_node(sk
, head
);
50 void vcc_insert_socket(struct sock
*sk
)
52 write_lock_irq(&vcc_sklist_lock
);
53 __vcc_insert_socket(sk
);
54 write_unlock_irq(&vcc_sklist_lock
);
56 EXPORT_SYMBOL(vcc_insert_socket
);
58 static void vcc_remove_socket(struct sock
*sk
)
60 write_lock_irq(&vcc_sklist_lock
);
62 write_unlock_irq(&vcc_sklist_lock
);
65 static struct sk_buff
*alloc_tx(struct atm_vcc
*vcc
, unsigned int size
)
68 struct sock
*sk
= sk_atm(vcc
);
70 if (sk_wmem_alloc_get(sk
) && !atm_may_send(vcc
, size
)) {
71 pr_debug("Sorry: wmem_alloc = %d, size = %d, sndbuf = %d\n",
72 sk_wmem_alloc_get(sk
), size
, sk
->sk_sndbuf
);
75 while (!(skb
= alloc_skb(size
, GFP_KERNEL
)))
77 pr_debug("%d += %d\n", sk_wmem_alloc_get(sk
), skb
->truesize
);
78 atomic_add(skb
->truesize
, &sk
->sk_wmem_alloc
);
82 static void vcc_sock_destruct(struct sock
*sk
)
84 if (atomic_read(&sk
->sk_rmem_alloc
))
85 printk(KERN_DEBUG
"%s: rmem leakage (%d bytes) detected.\n",
86 __func__
, atomic_read(&sk
->sk_rmem_alloc
));
88 if (atomic_read(&sk
->sk_wmem_alloc
))
89 printk(KERN_DEBUG
"%s: wmem leakage (%d bytes) detected.\n",
90 __func__
, atomic_read(&sk
->sk_wmem_alloc
));
93 static void vcc_def_wakeup(struct sock
*sk
)
98 wq
= rcu_dereference(sk
->sk_wq
);
99 if (wq_has_sleeper(wq
))
104 static inline int vcc_writable(struct sock
*sk
)
106 struct atm_vcc
*vcc
= atm_sk(sk
);
108 return (vcc
->qos
.txtp
.max_sdu
+
109 atomic_read(&sk
->sk_wmem_alloc
)) <= sk
->sk_sndbuf
;
112 static void vcc_write_space(struct sock
*sk
)
114 struct socket_wq
*wq
;
118 if (vcc_writable(sk
)) {
119 wq
= rcu_dereference(sk
->sk_wq
);
120 if (wq_has_sleeper(wq
))
121 wake_up_interruptible(&wq
->wait
);
123 sk_wake_async(sk
, SOCK_WAKE_SPACE
, POLL_OUT
);
129 static void vcc_release_cb(struct sock
*sk
)
131 struct atm_vcc
*vcc
= atm_sk(sk
);
134 vcc
->release_cb(vcc
);
137 static struct proto vcc_proto
= {
139 .owner
= THIS_MODULE
,
140 .obj_size
= sizeof(struct atm_vcc
),
141 .release_cb
= vcc_release_cb
,
144 int vcc_create(struct net
*net
, struct socket
*sock
, int protocol
, int family
)
150 if (sock
->type
== SOCK_STREAM
)
152 sk
= sk_alloc(net
, family
, GFP_KERNEL
, &vcc_proto
);
155 sock_init_data(sock
, sk
);
156 sk
->sk_state_change
= vcc_def_wakeup
;
157 sk
->sk_write_space
= vcc_write_space
;
161 memset(&vcc
->local
, 0, sizeof(struct sockaddr_atmsvc
));
162 memset(&vcc
->remote
, 0, sizeof(struct sockaddr_atmsvc
));
163 vcc
->qos
.txtp
.max_sdu
= 1 << 16; /* for meta VCs */
164 atomic_set(&sk
->sk_wmem_alloc
, 1);
165 atomic_set(&sk
->sk_rmem_alloc
, 0);
169 vcc
->push_oam
= NULL
;
170 vcc
->release_cb
= NULL
;
171 vcc
->vpi
= vcc
->vci
= 0; /* no VCI/VPI yet */
172 vcc
->atm_options
= vcc
->aal_options
= 0;
173 sk
->sk_destruct
= vcc_sock_destruct
;
177 static void vcc_destroy_socket(struct sock
*sk
)
179 struct atm_vcc
*vcc
= atm_sk(sk
);
182 set_bit(ATM_VF_CLOSE
, &vcc
->flags
);
183 clear_bit(ATM_VF_READY
, &vcc
->flags
);
185 if (vcc
->dev
->ops
->close
)
186 vcc
->dev
->ops
->close(vcc
);
188 vcc
->push(vcc
, NULL
); /* atmarpd has no push */
189 module_put(vcc
->owner
);
191 while ((skb
= skb_dequeue(&sk
->sk_receive_queue
)) != NULL
) {
192 atm_return(vcc
, skb
->truesize
);
196 module_put(vcc
->dev
->ops
->owner
);
197 atm_dev_put(vcc
->dev
);
200 vcc_remove_socket(sk
);
203 int vcc_release(struct socket
*sock
)
205 struct sock
*sk
= sock
->sk
;
209 vcc_destroy_socket(sock
->sk
);
217 void vcc_release_async(struct atm_vcc
*vcc
, int reply
)
219 struct sock
*sk
= sk_atm(vcc
);
221 set_bit(ATM_VF_CLOSE
, &vcc
->flags
);
222 sk
->sk_shutdown
|= RCV_SHUTDOWN
;
224 clear_bit(ATM_VF_WAITING
, &vcc
->flags
);
225 sk
->sk_state_change(sk
);
227 EXPORT_SYMBOL(vcc_release_async
);
229 void vcc_process_recv_queue(struct atm_vcc
*vcc
)
231 struct sk_buff_head queue
, *rq
;
232 struct sk_buff
*skb
, *tmp
;
235 __skb_queue_head_init(&queue
);
236 rq
= &sk_atm(vcc
)->sk_receive_queue
;
238 spin_lock_irqsave(&rq
->lock
, flags
);
239 skb_queue_splice_init(rq
, &queue
);
240 spin_unlock_irqrestore(&rq
->lock
, flags
);
242 skb_queue_walk_safe(&queue
, skb
, tmp
) {
243 __skb_unlink(skb
, &queue
);
247 EXPORT_SYMBOL(vcc_process_recv_queue
);
249 void atm_dev_signal_change(struct atm_dev
*dev
, char signal
)
251 pr_debug("%s signal=%d dev=%p number=%d dev->signal=%d\n",
252 __func__
, signal
, dev
, dev
->number
, dev
->signal
);
254 /* atm driver sending invalid signal */
255 WARN_ON(signal
< ATM_PHY_SIG_LOST
|| signal
> ATM_PHY_SIG_FOUND
);
257 if (dev
->signal
== signal
)
258 return; /* no change */
260 dev
->signal
= signal
;
262 atomic_notifier_call_chain(&atm_dev_notify_chain
, signal
, dev
);
264 EXPORT_SYMBOL(atm_dev_signal_change
);
266 void atm_dev_release_vccs(struct atm_dev
*dev
)
270 write_lock_irq(&vcc_sklist_lock
);
271 for (i
= 0; i
< VCC_HTABLE_SIZE
; i
++) {
272 struct hlist_head
*head
= &vcc_hash
[i
];
273 struct hlist_node
*node
, *tmp
;
277 sk_for_each_safe(s
, node
, tmp
, head
) {
279 if (vcc
->dev
== dev
) {
280 vcc_release_async(vcc
, -EPIPE
);
285 write_unlock_irq(&vcc_sklist_lock
);
287 EXPORT_SYMBOL(atm_dev_release_vccs
);
289 static int adjust_tp(struct atm_trafprm
*tp
, unsigned char aal
)
293 if (!tp
->traffic_class
)
297 max_sdu
= ATM_CELL_SIZE
-1;
300 max_sdu
= ATM_MAX_AAL34_PDU
;
303 pr_warning("AAL problems ... (%d)\n", aal
);
306 max_sdu
= ATM_MAX_AAL5_PDU
;
309 tp
->max_sdu
= max_sdu
;
310 else if (tp
->max_sdu
> max_sdu
)
313 tp
->max_cdv
= ATM_MAX_CDV
;
317 static int check_ci(const struct atm_vcc
*vcc
, short vpi
, int vci
)
319 struct hlist_head
*head
= &vcc_hash
[vci
& (VCC_HTABLE_SIZE
- 1)];
320 struct hlist_node
*node
;
322 struct atm_vcc
*walk
;
324 sk_for_each(s
, node
, head
) {
326 if (walk
->dev
!= vcc
->dev
)
328 if (test_bit(ATM_VF_ADDR
, &walk
->flags
) && walk
->vpi
== vpi
&&
329 walk
->vci
== vci
&& ((walk
->qos
.txtp
.traffic_class
!=
330 ATM_NONE
&& vcc
->qos
.txtp
.traffic_class
!= ATM_NONE
) ||
331 (walk
->qos
.rxtp
.traffic_class
!= ATM_NONE
&&
332 vcc
->qos
.rxtp
.traffic_class
!= ATM_NONE
)))
336 /* allow VCCs with same VPI/VCI iff they don't collide on
337 TX/RX (but we may refuse such sharing for other reasons,
338 e.g. if protocol requires to have both channels) */
343 static int find_ci(const struct atm_vcc
*vcc
, short *vpi
, int *vci
)
345 static short p
; /* poor man's per-device cache */
351 if (*vpi
!= ATM_VPI_ANY
&& *vci
!= ATM_VCI_ANY
) {
352 err
= check_ci(vcc
, *vpi
, *vci
);
355 /* last scan may have left values out of bounds for current device */
356 if (*vpi
!= ATM_VPI_ANY
)
358 else if (p
>= 1 << vcc
->dev
->ci_range
.vpi_bits
)
360 if (*vci
!= ATM_VCI_ANY
)
362 else if (c
< ATM_NOT_RSV_VCI
|| c
>= 1 << vcc
->dev
->ci_range
.vci_bits
)
367 if (!check_ci(vcc
, p
, c
)) {
372 if (*vci
== ATM_VCI_ANY
) {
374 if (c
>= 1 << vcc
->dev
->ci_range
.vci_bits
)
377 if ((c
== ATM_NOT_RSV_VCI
|| *vci
!= ATM_VCI_ANY
) &&
378 *vpi
== ATM_VPI_ANY
) {
380 if (p
>= 1 << vcc
->dev
->ci_range
.vpi_bits
)
383 } while (old_p
!= p
|| old_c
!= c
);
387 static int __vcc_connect(struct atm_vcc
*vcc
, struct atm_dev
*dev
, short vpi
,
390 struct sock
*sk
= sk_atm(vcc
);
393 if ((vpi
!= ATM_VPI_UNSPEC
&& vpi
!= ATM_VPI_ANY
&&
394 vpi
>> dev
->ci_range
.vpi_bits
) || (vci
!= ATM_VCI_UNSPEC
&&
395 vci
!= ATM_VCI_ANY
&& vci
>> dev
->ci_range
.vci_bits
))
397 if (vci
> 0 && vci
< ATM_NOT_RSV_VCI
&& !capable(CAP_NET_BIND_SERVICE
))
400 if (!try_module_get(dev
->ops
->owner
))
403 write_lock_irq(&vcc_sklist_lock
);
404 if (test_bit(ATM_DF_REMOVED
, &dev
->flags
) ||
405 (error
= find_ci(vcc
, &vpi
, &vci
))) {
406 write_unlock_irq(&vcc_sklist_lock
);
407 goto fail_module_put
;
411 __vcc_insert_socket(sk
);
412 write_unlock_irq(&vcc_sklist_lock
);
413 switch (vcc
->qos
.aal
) {
415 error
= atm_init_aal0(vcc
);
416 vcc
->stats
= &dev
->stats
.aal0
;
419 error
= atm_init_aal34(vcc
);
420 vcc
->stats
= &dev
->stats
.aal34
;
423 /* ATM_AAL5 is also used in the "0 for default" case */
424 vcc
->qos
.aal
= ATM_AAL5
;
427 error
= atm_init_aal5(vcc
);
428 vcc
->stats
= &dev
->stats
.aal5
;
434 error
= adjust_tp(&vcc
->qos
.txtp
, vcc
->qos
.aal
);
436 error
= adjust_tp(&vcc
->qos
.rxtp
, vcc
->qos
.aal
);
439 pr_debug("VCC %d.%d, AAL %d\n", vpi
, vci
, vcc
->qos
.aal
);
440 pr_debug(" TX: %d, PCR %d..%d, SDU %d\n",
441 vcc
->qos
.txtp
.traffic_class
,
442 vcc
->qos
.txtp
.min_pcr
,
443 vcc
->qos
.txtp
.max_pcr
,
444 vcc
->qos
.txtp
.max_sdu
);
445 pr_debug(" RX: %d, PCR %d..%d, SDU %d\n",
446 vcc
->qos
.rxtp
.traffic_class
,
447 vcc
->qos
.rxtp
.min_pcr
,
448 vcc
->qos
.rxtp
.max_pcr
,
449 vcc
->qos
.rxtp
.max_sdu
);
451 if (dev
->ops
->open
) {
452 error
= dev
->ops
->open(vcc
);
459 vcc_remove_socket(sk
);
461 module_put(dev
->ops
->owner
);
462 /* ensure we get dev module ref count correct */
467 int vcc_connect(struct socket
*sock
, int itf
, short vpi
, int vci
)
470 struct atm_vcc
*vcc
= ATM_SD(sock
);
473 pr_debug("(vpi %d, vci %d)\n", vpi
, vci
);
474 if (sock
->state
== SS_CONNECTED
)
476 if (sock
->state
!= SS_UNCONNECTED
)
481 if (vpi
!= ATM_VPI_UNSPEC
&& vci
!= ATM_VCI_UNSPEC
)
482 clear_bit(ATM_VF_PARTIAL
, &vcc
->flags
);
484 if (test_bit(ATM_VF_PARTIAL
, &vcc
->flags
))
486 pr_debug("(TX: cl %d,bw %d-%d,sdu %d; "
487 "RX: cl %d,bw %d-%d,sdu %d,AAL %s%d)\n",
488 vcc
->qos
.txtp
.traffic_class
, vcc
->qos
.txtp
.min_pcr
,
489 vcc
->qos
.txtp
.max_pcr
, vcc
->qos
.txtp
.max_sdu
,
490 vcc
->qos
.rxtp
.traffic_class
, vcc
->qos
.rxtp
.min_pcr
,
491 vcc
->qos
.rxtp
.max_pcr
, vcc
->qos
.rxtp
.max_sdu
,
492 vcc
->qos
.aal
== ATM_AAL5
? "" :
493 vcc
->qos
.aal
== ATM_AAL0
? "" : " ??? code ",
494 vcc
->qos
.aal
== ATM_AAL0
? 0 : vcc
->qos
.aal
);
495 if (!test_bit(ATM_VF_HASQOS
, &vcc
->flags
))
497 if (vcc
->qos
.txtp
.traffic_class
== ATM_ANYCLASS
||
498 vcc
->qos
.rxtp
.traffic_class
== ATM_ANYCLASS
)
500 if (likely(itf
!= ATM_ITF_ANY
)) {
501 dev
= try_then_request_module(atm_dev_lookup(itf
),
502 "atm-device-%d", itf
);
505 mutex_lock(&atm_dev_mutex
);
506 if (!list_empty(&atm_devs
)) {
507 dev
= list_entry(atm_devs
.next
,
508 struct atm_dev
, dev_list
);
511 mutex_unlock(&atm_dev_mutex
);
515 error
= __vcc_connect(vcc
, dev
, vpi
, vci
);
520 if (vpi
== ATM_VPI_UNSPEC
|| vci
== ATM_VCI_UNSPEC
)
521 set_bit(ATM_VF_PARTIAL
, &vcc
->flags
);
522 if (test_bit(ATM_VF_READY
, &ATM_SD(sock
)->flags
))
523 sock
->state
= SS_CONNECTED
;
527 int vcc_recvmsg(struct kiocb
*iocb
, struct socket
*sock
, struct msghdr
*msg
,
528 size_t size
, int flags
)
530 struct sock
*sk
= sock
->sk
;
533 int copied
, error
= -EINVAL
;
535 if (sock
->state
!= SS_CONNECTED
)
538 /* only handle MSG_DONTWAIT and MSG_PEEK */
539 if (flags
& ~(MSG_DONTWAIT
| MSG_PEEK
))
543 if (test_bit(ATM_VF_RELEASED
, &vcc
->flags
) ||
544 test_bit(ATM_VF_CLOSE
, &vcc
->flags
) ||
545 !test_bit(ATM_VF_READY
, &vcc
->flags
))
548 skb
= skb_recv_datagram(sk
, flags
, flags
& MSG_DONTWAIT
, &error
);
555 msg
->msg_flags
|= MSG_TRUNC
;
558 error
= skb_copy_datagram_iovec(skb
, 0, msg
->msg_iov
, copied
);
561 sock_recv_ts_and_drops(msg
, sk
, skb
);
563 if (!(flags
& MSG_PEEK
)) {
564 pr_debug("%d -= %d\n", atomic_read(&sk
->sk_rmem_alloc
),
566 atm_return(vcc
, skb
->truesize
);
569 skb_free_datagram(sk
, skb
);
573 int vcc_sendmsg(struct kiocb
*iocb
, struct socket
*sock
, struct msghdr
*m
,
576 struct sock
*sk
= sock
->sk
;
581 const void __user
*buff
;
585 if (sock
->state
!= SS_CONNECTED
) {
593 if (m
->msg_iovlen
!= 1) {
594 error
= -ENOSYS
; /* fix this later @@@ */
597 buff
= m
->msg_iov
->iov_base
;
598 size
= m
->msg_iov
->iov_len
;
600 if (test_bit(ATM_VF_RELEASED
, &vcc
->flags
) ||
601 test_bit(ATM_VF_CLOSE
, &vcc
->flags
) ||
602 !test_bit(ATM_VF_READY
, &vcc
->flags
)) {
604 send_sig(SIGPIPE
, current
, 0);
611 if (size
< 0 || size
> vcc
->qos
.txtp
.max_sdu
) {
616 eff
= (size
+3) & ~3; /* align to word boundary */
617 prepare_to_wait(sk_sleep(sk
), &wait
, TASK_INTERRUPTIBLE
);
619 while (!(skb
= alloc_tx(vcc
, eff
))) {
620 if (m
->msg_flags
& MSG_DONTWAIT
) {
625 if (signal_pending(current
)) {
626 error
= -ERESTARTSYS
;
629 if (test_bit(ATM_VF_RELEASED
, &vcc
->flags
) ||
630 test_bit(ATM_VF_CLOSE
, &vcc
->flags
) ||
631 !test_bit(ATM_VF_READY
, &vcc
->flags
)) {
633 send_sig(SIGPIPE
, current
, 0);
636 prepare_to_wait(sk_sleep(sk
), &wait
, TASK_INTERRUPTIBLE
);
638 finish_wait(sk_sleep(sk
), &wait
);
641 skb
->dev
= NULL
; /* for paths shared with net_device interfaces */
642 ATM_SKB(skb
)->atm_options
= vcc
->atm_options
;
643 if (copy_from_user(skb_put(skb
, size
), buff
, size
)) {
649 memset(skb
->data
+ size
, 0, eff
-size
);
650 error
= vcc
->dev
->ops
->send(vcc
, skb
);
651 error
= error
? error
: size
;
657 unsigned int vcc_poll(struct file
*file
, struct socket
*sock
, poll_table
*wait
)
659 struct sock
*sk
= sock
->sk
;
663 sock_poll_wait(file
, sk_sleep(sk
), wait
);
668 /* exceptional events */
672 if (test_bit(ATM_VF_RELEASED
, &vcc
->flags
) ||
673 test_bit(ATM_VF_CLOSE
, &vcc
->flags
))
677 if (!skb_queue_empty(&sk
->sk_receive_queue
))
678 mask
|= POLLIN
| POLLRDNORM
;
681 if (sock
->state
== SS_CONNECTING
&&
682 test_bit(ATM_VF_WAITING
, &vcc
->flags
))
685 if (vcc
->qos
.txtp
.traffic_class
!= ATM_NONE
&&
687 mask
|= POLLOUT
| POLLWRNORM
| POLLWRBAND
;
692 static int atm_change_qos(struct atm_vcc
*vcc
, struct atm_qos
*qos
)
697 * Don't let the QoS change the already connected AAL type nor the
700 if (qos
->aal
!= vcc
->qos
.aal
||
701 qos
->rxtp
.traffic_class
!= vcc
->qos
.rxtp
.traffic_class
||
702 qos
->txtp
.traffic_class
!= vcc
->qos
.txtp
.traffic_class
)
704 error
= adjust_tp(&qos
->txtp
, qos
->aal
);
706 error
= adjust_tp(&qos
->rxtp
, qos
->aal
);
709 if (!vcc
->dev
->ops
->change_qos
)
711 if (sk_atm(vcc
)->sk_family
== AF_ATMPVC
)
712 return vcc
->dev
->ops
->change_qos(vcc
, qos
, ATM_MF_SET
);
713 return svc_change_qos(vcc
, qos
);
716 static int check_tp(const struct atm_trafprm
*tp
)
718 /* @@@ Should be merged with adjust_tp */
719 if (!tp
->traffic_class
|| tp
->traffic_class
== ATM_ANYCLASS
)
721 if (tp
->traffic_class
!= ATM_UBR
&& !tp
->min_pcr
&& !tp
->pcr
&&
724 if (tp
->min_pcr
== ATM_MAX_PCR
)
726 if (tp
->min_pcr
&& tp
->max_pcr
&& tp
->max_pcr
!= ATM_MAX_PCR
&&
727 tp
->min_pcr
> tp
->max_pcr
)
730 * We allow pcr to be outside [min_pcr,max_pcr], because later
731 * adjustment may still push it in the valid range.
736 static int check_qos(const struct atm_qos
*qos
)
740 if (!qos
->txtp
.traffic_class
&& !qos
->rxtp
.traffic_class
)
742 if (qos
->txtp
.traffic_class
!= qos
->rxtp
.traffic_class
&&
743 qos
->txtp
.traffic_class
&& qos
->rxtp
.traffic_class
&&
744 qos
->txtp
.traffic_class
!= ATM_ANYCLASS
&&
745 qos
->rxtp
.traffic_class
!= ATM_ANYCLASS
)
747 error
= check_tp(&qos
->txtp
);
750 return check_tp(&qos
->rxtp
);
753 int vcc_setsockopt(struct socket
*sock
, int level
, int optname
,
754 char __user
*optval
, unsigned int optlen
)
760 if (__SO_LEVEL_MATCH(optname
, level
) && optlen
!= __SO_SIZE(optname
))
769 if (copy_from_user(&qos
, optval
, sizeof(qos
)))
771 error
= check_qos(&qos
);
774 if (sock
->state
== SS_CONNECTED
)
775 return atm_change_qos(vcc
, &qos
);
776 if (sock
->state
!= SS_UNCONNECTED
)
779 set_bit(ATM_VF_HASQOS
, &vcc
->flags
);
783 if (get_user(value
, (unsigned long __user
*)optval
))
786 vcc
->atm_options
|= ATM_ATMOPT_CLP
;
788 vcc
->atm_options
&= ~ATM_ATMOPT_CLP
;
791 if (level
== SOL_SOCKET
)
795 if (!vcc
->dev
|| !vcc
->dev
->ops
->setsockopt
)
797 return vcc
->dev
->ops
->setsockopt(vcc
, level
, optname
, optval
, optlen
);
800 int vcc_getsockopt(struct socket
*sock
, int level
, int optname
,
801 char __user
*optval
, int __user
*optlen
)
806 if (get_user(len
, optlen
))
808 if (__SO_LEVEL_MATCH(optname
, level
) && len
!= __SO_SIZE(optname
))
814 if (!test_bit(ATM_VF_HASQOS
, &vcc
->flags
))
816 return copy_to_user(optval
, &vcc
->qos
, sizeof(vcc
->qos
))
819 return put_user(vcc
->atm_options
& ATM_ATMOPT_CLP
? 1 : 0,
820 (unsigned long __user
*)optval
) ? -EFAULT
: 0;
823 struct sockaddr_atmpvc pvc
;
825 if (!vcc
->dev
|| !test_bit(ATM_VF_ADDR
, &vcc
->flags
))
827 memset(&pvc
, 0, sizeof(pvc
));
828 pvc
.sap_family
= AF_ATMPVC
;
829 pvc
.sap_addr
.itf
= vcc
->dev
->number
;
830 pvc
.sap_addr
.vpi
= vcc
->vpi
;
831 pvc
.sap_addr
.vci
= vcc
->vci
;
832 return copy_to_user(optval
, &pvc
, sizeof(pvc
)) ? -EFAULT
: 0;
835 if (level
== SOL_SOCKET
)
839 if (!vcc
->dev
|| !vcc
->dev
->ops
->getsockopt
)
841 return vcc
->dev
->ops
->getsockopt(vcc
, level
, optname
, optval
, len
);
844 int register_atmdevice_notifier(struct notifier_block
*nb
)
846 return atomic_notifier_chain_register(&atm_dev_notify_chain
, nb
);
848 EXPORT_SYMBOL_GPL(register_atmdevice_notifier
);
850 void unregister_atmdevice_notifier(struct notifier_block
*nb
)
852 atomic_notifier_chain_unregister(&atm_dev_notify_chain
, nb
);
854 EXPORT_SYMBOL_GPL(unregister_atmdevice_notifier
);
856 static int __init
atm_init(void)
860 error
= proto_register(&vcc_proto
, 0);
863 error
= atmpvc_init();
865 pr_err("atmpvc_init() failed with %d\n", error
);
866 goto out_unregister_vcc_proto
;
868 error
= atmsvc_init();
870 pr_err("atmsvc_init() failed with %d\n", error
);
871 goto out_atmpvc_exit
;
873 error
= atm_proc_init();
875 pr_err("atm_proc_init() failed with %d\n", error
);
876 goto out_atmsvc_exit
;
878 error
= atm_sysfs_init();
880 pr_err("atm_sysfs_init() failed with %d\n", error
);
881 goto out_atmproc_exit
;
891 out_unregister_vcc_proto
:
892 proto_unregister(&vcc_proto
);
896 static void __exit
atm_exit(void)
902 proto_unregister(&vcc_proto
);
905 subsys_initcall(atm_init
);
907 module_exit(atm_exit
);
909 MODULE_LICENSE("GPL");
910 MODULE_ALIAS_NETPROTO(PF_ATMPVC
);
911 MODULE_ALIAS_NETPROTO(PF_ATMSVC
);