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 <asm/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 struct proto vcc_proto
= {
131 .owner
= THIS_MODULE
,
132 .obj_size
= sizeof(struct atm_vcc
),
135 int vcc_create(struct net
*net
, struct socket
*sock
, int protocol
, int family
)
141 if (sock
->type
== SOCK_STREAM
)
143 sk
= sk_alloc(net
, family
, GFP_KERNEL
, &vcc_proto
);
146 sock_init_data(sock
, sk
);
147 sk
->sk_state_change
= vcc_def_wakeup
;
148 sk
->sk_write_space
= vcc_write_space
;
152 memset(&vcc
->local
, 0, sizeof(struct sockaddr_atmsvc
));
153 memset(&vcc
->remote
, 0, sizeof(struct sockaddr_atmsvc
));
154 vcc
->qos
.txtp
.max_sdu
= 1 << 16; /* for meta VCs */
155 atomic_set(&sk
->sk_wmem_alloc
, 1);
156 atomic_set(&sk
->sk_rmem_alloc
, 0);
159 vcc
->push_oam
= NULL
;
160 vcc
->vpi
= vcc
->vci
= 0; /* no VCI/VPI yet */
161 vcc
->atm_options
= vcc
->aal_options
= 0;
162 sk
->sk_destruct
= vcc_sock_destruct
;
166 static void vcc_destroy_socket(struct sock
*sk
)
168 struct atm_vcc
*vcc
= atm_sk(sk
);
171 set_bit(ATM_VF_CLOSE
, &vcc
->flags
);
172 clear_bit(ATM_VF_READY
, &vcc
->flags
);
174 if (vcc
->dev
->ops
->close
)
175 vcc
->dev
->ops
->close(vcc
);
177 vcc
->push(vcc
, NULL
); /* atmarpd has no push */
179 while ((skb
= skb_dequeue(&sk
->sk_receive_queue
)) != NULL
) {
180 atm_return(vcc
, skb
->truesize
);
184 module_put(vcc
->dev
->ops
->owner
);
185 atm_dev_put(vcc
->dev
);
188 vcc_remove_socket(sk
);
191 int vcc_release(struct socket
*sock
)
193 struct sock
*sk
= sock
->sk
;
197 vcc_destroy_socket(sock
->sk
);
205 void vcc_release_async(struct atm_vcc
*vcc
, int reply
)
207 struct sock
*sk
= sk_atm(vcc
);
209 set_bit(ATM_VF_CLOSE
, &vcc
->flags
);
210 sk
->sk_shutdown
|= RCV_SHUTDOWN
;
212 clear_bit(ATM_VF_WAITING
, &vcc
->flags
);
213 sk
->sk_state_change(sk
);
215 EXPORT_SYMBOL(vcc_release_async
);
217 void atm_dev_signal_change(struct atm_dev
*dev
, char signal
)
219 pr_debug("%s signal=%d dev=%p number=%d dev->signal=%d\n",
220 __func__
, signal
, dev
, dev
->number
, dev
->signal
);
222 /* atm driver sending invalid signal */
223 WARN_ON(signal
< ATM_PHY_SIG_LOST
|| signal
> ATM_PHY_SIG_FOUND
);
225 if (dev
->signal
== signal
)
226 return; /* no change */
228 dev
->signal
= signal
;
230 atomic_notifier_call_chain(&atm_dev_notify_chain
, signal
, dev
);
232 EXPORT_SYMBOL(atm_dev_signal_change
);
234 void atm_dev_release_vccs(struct atm_dev
*dev
)
238 write_lock_irq(&vcc_sklist_lock
);
239 for (i
= 0; i
< VCC_HTABLE_SIZE
; i
++) {
240 struct hlist_head
*head
= &vcc_hash
[i
];
241 struct hlist_node
*node
, *tmp
;
245 sk_for_each_safe(s
, node
, tmp
, head
) {
247 if (vcc
->dev
== dev
) {
248 vcc_release_async(vcc
, -EPIPE
);
253 write_unlock_irq(&vcc_sklist_lock
);
256 static int adjust_tp(struct atm_trafprm
*tp
, unsigned char aal
)
260 if (!tp
->traffic_class
)
264 max_sdu
= ATM_CELL_SIZE
-1;
267 max_sdu
= ATM_MAX_AAL34_PDU
;
270 pr_warning("AAL problems ... (%d)\n", aal
);
273 max_sdu
= ATM_MAX_AAL5_PDU
;
276 tp
->max_sdu
= max_sdu
;
277 else if (tp
->max_sdu
> max_sdu
)
280 tp
->max_cdv
= ATM_MAX_CDV
;
284 static int check_ci(const struct atm_vcc
*vcc
, short vpi
, int vci
)
286 struct hlist_head
*head
= &vcc_hash
[vci
& (VCC_HTABLE_SIZE
- 1)];
287 struct hlist_node
*node
;
289 struct atm_vcc
*walk
;
291 sk_for_each(s
, node
, head
) {
293 if (walk
->dev
!= vcc
->dev
)
295 if (test_bit(ATM_VF_ADDR
, &walk
->flags
) && walk
->vpi
== vpi
&&
296 walk
->vci
== vci
&& ((walk
->qos
.txtp
.traffic_class
!=
297 ATM_NONE
&& vcc
->qos
.txtp
.traffic_class
!= ATM_NONE
) ||
298 (walk
->qos
.rxtp
.traffic_class
!= ATM_NONE
&&
299 vcc
->qos
.rxtp
.traffic_class
!= ATM_NONE
)))
303 /* allow VCCs with same VPI/VCI iff they don't collide on
304 TX/RX (but we may refuse such sharing for other reasons,
305 e.g. if protocol requires to have both channels) */
310 static int find_ci(const struct atm_vcc
*vcc
, short *vpi
, int *vci
)
312 static short p
; /* poor man's per-device cache */
318 if (*vpi
!= ATM_VPI_ANY
&& *vci
!= ATM_VCI_ANY
) {
319 err
= check_ci(vcc
, *vpi
, *vci
);
322 /* last scan may have left values out of bounds for current device */
323 if (*vpi
!= ATM_VPI_ANY
)
325 else if (p
>= 1 << vcc
->dev
->ci_range
.vpi_bits
)
327 if (*vci
!= ATM_VCI_ANY
)
329 else if (c
< ATM_NOT_RSV_VCI
|| c
>= 1 << vcc
->dev
->ci_range
.vci_bits
)
334 if (!check_ci(vcc
, p
, c
)) {
339 if (*vci
== ATM_VCI_ANY
) {
341 if (c
>= 1 << vcc
->dev
->ci_range
.vci_bits
)
344 if ((c
== ATM_NOT_RSV_VCI
|| *vci
!= ATM_VCI_ANY
) &&
345 *vpi
== ATM_VPI_ANY
) {
347 if (p
>= 1 << vcc
->dev
->ci_range
.vpi_bits
)
350 } while (old_p
!= p
|| old_c
!= c
);
354 static int __vcc_connect(struct atm_vcc
*vcc
, struct atm_dev
*dev
, short vpi
,
357 struct sock
*sk
= sk_atm(vcc
);
360 if ((vpi
!= ATM_VPI_UNSPEC
&& vpi
!= ATM_VPI_ANY
&&
361 vpi
>> dev
->ci_range
.vpi_bits
) || (vci
!= ATM_VCI_UNSPEC
&&
362 vci
!= ATM_VCI_ANY
&& vci
>> dev
->ci_range
.vci_bits
))
364 if (vci
> 0 && vci
< ATM_NOT_RSV_VCI
&& !capable(CAP_NET_BIND_SERVICE
))
367 if (!try_module_get(dev
->ops
->owner
))
370 write_lock_irq(&vcc_sklist_lock
);
371 if (test_bit(ATM_DF_REMOVED
, &dev
->flags
) ||
372 (error
= find_ci(vcc
, &vpi
, &vci
))) {
373 write_unlock_irq(&vcc_sklist_lock
);
374 goto fail_module_put
;
378 __vcc_insert_socket(sk
);
379 write_unlock_irq(&vcc_sklist_lock
);
380 switch (vcc
->qos
.aal
) {
382 error
= atm_init_aal0(vcc
);
383 vcc
->stats
= &dev
->stats
.aal0
;
386 error
= atm_init_aal34(vcc
);
387 vcc
->stats
= &dev
->stats
.aal34
;
390 /* ATM_AAL5 is also used in the "0 for default" case */
391 vcc
->qos
.aal
= ATM_AAL5
;
394 error
= atm_init_aal5(vcc
);
395 vcc
->stats
= &dev
->stats
.aal5
;
401 error
= adjust_tp(&vcc
->qos
.txtp
, vcc
->qos
.aal
);
403 error
= adjust_tp(&vcc
->qos
.rxtp
, vcc
->qos
.aal
);
406 pr_debug("VCC %d.%d, AAL %d\n", vpi
, vci
, vcc
->qos
.aal
);
407 pr_debug(" TX: %d, PCR %d..%d, SDU %d\n",
408 vcc
->qos
.txtp
.traffic_class
,
409 vcc
->qos
.txtp
.min_pcr
,
410 vcc
->qos
.txtp
.max_pcr
,
411 vcc
->qos
.txtp
.max_sdu
);
412 pr_debug(" RX: %d, PCR %d..%d, SDU %d\n",
413 vcc
->qos
.rxtp
.traffic_class
,
414 vcc
->qos
.rxtp
.min_pcr
,
415 vcc
->qos
.rxtp
.max_pcr
,
416 vcc
->qos
.rxtp
.max_sdu
);
418 if (dev
->ops
->open
) {
419 error
= dev
->ops
->open(vcc
);
426 vcc_remove_socket(sk
);
428 module_put(dev
->ops
->owner
);
429 /* ensure we get dev module ref count correct */
434 int vcc_connect(struct socket
*sock
, int itf
, short vpi
, int vci
)
437 struct atm_vcc
*vcc
= ATM_SD(sock
);
440 pr_debug("(vpi %d, vci %d)\n", vpi
, vci
);
441 if (sock
->state
== SS_CONNECTED
)
443 if (sock
->state
!= SS_UNCONNECTED
)
448 if (vpi
!= ATM_VPI_UNSPEC
&& vci
!= ATM_VCI_UNSPEC
)
449 clear_bit(ATM_VF_PARTIAL
, &vcc
->flags
);
451 if (test_bit(ATM_VF_PARTIAL
, &vcc
->flags
))
453 pr_debug("(TX: cl %d,bw %d-%d,sdu %d; "
454 "RX: cl %d,bw %d-%d,sdu %d,AAL %s%d)\n",
455 vcc
->qos
.txtp
.traffic_class
, vcc
->qos
.txtp
.min_pcr
,
456 vcc
->qos
.txtp
.max_pcr
, vcc
->qos
.txtp
.max_sdu
,
457 vcc
->qos
.rxtp
.traffic_class
, vcc
->qos
.rxtp
.min_pcr
,
458 vcc
->qos
.rxtp
.max_pcr
, vcc
->qos
.rxtp
.max_sdu
,
459 vcc
->qos
.aal
== ATM_AAL5
? "" :
460 vcc
->qos
.aal
== ATM_AAL0
? "" : " ??? code ",
461 vcc
->qos
.aal
== ATM_AAL0
? 0 : vcc
->qos
.aal
);
462 if (!test_bit(ATM_VF_HASQOS
, &vcc
->flags
))
464 if (vcc
->qos
.txtp
.traffic_class
== ATM_ANYCLASS
||
465 vcc
->qos
.rxtp
.traffic_class
== ATM_ANYCLASS
)
467 if (likely(itf
!= ATM_ITF_ANY
)) {
468 dev
= try_then_request_module(atm_dev_lookup(itf
),
469 "atm-device-%d", itf
);
472 mutex_lock(&atm_dev_mutex
);
473 if (!list_empty(&atm_devs
)) {
474 dev
= list_entry(atm_devs
.next
,
475 struct atm_dev
, dev_list
);
478 mutex_unlock(&atm_dev_mutex
);
482 error
= __vcc_connect(vcc
, dev
, vpi
, vci
);
487 if (vpi
== ATM_VPI_UNSPEC
|| vci
== ATM_VCI_UNSPEC
)
488 set_bit(ATM_VF_PARTIAL
, &vcc
->flags
);
489 if (test_bit(ATM_VF_READY
, &ATM_SD(sock
)->flags
))
490 sock
->state
= SS_CONNECTED
;
494 int vcc_recvmsg(struct kiocb
*iocb
, struct socket
*sock
, struct msghdr
*msg
,
495 size_t size
, int flags
)
497 struct sock
*sk
= sock
->sk
;
500 int copied
, error
= -EINVAL
;
502 if (sock
->state
!= SS_CONNECTED
)
504 if (flags
& ~MSG_DONTWAIT
) /* only handle MSG_DONTWAIT */
507 if (test_bit(ATM_VF_RELEASED
, &vcc
->flags
) ||
508 test_bit(ATM_VF_CLOSE
, &vcc
->flags
) ||
509 !test_bit(ATM_VF_READY
, &vcc
->flags
))
512 skb
= skb_recv_datagram(sk
, flags
, flags
& MSG_DONTWAIT
, &error
);
519 msg
->msg_flags
|= MSG_TRUNC
;
522 error
= skb_copy_datagram_iovec(skb
, 0, msg
->msg_iov
, copied
);
525 sock_recv_ts_and_drops(msg
, sk
, skb
);
526 pr_debug("%d -= %d\n", atomic_read(&sk
->sk_rmem_alloc
), skb
->truesize
);
527 atm_return(vcc
, skb
->truesize
);
528 skb_free_datagram(sk
, skb
);
532 int vcc_sendmsg(struct kiocb
*iocb
, struct socket
*sock
, struct msghdr
*m
,
535 struct sock
*sk
= sock
->sk
;
540 const void __user
*buff
;
544 if (sock
->state
!= SS_CONNECTED
) {
552 if (m
->msg_iovlen
!= 1) {
553 error
= -ENOSYS
; /* fix this later @@@ */
556 buff
= m
->msg_iov
->iov_base
;
557 size
= m
->msg_iov
->iov_len
;
559 if (test_bit(ATM_VF_RELEASED
, &vcc
->flags
) ||
560 test_bit(ATM_VF_CLOSE
, &vcc
->flags
) ||
561 !test_bit(ATM_VF_READY
, &vcc
->flags
)) {
563 send_sig(SIGPIPE
, current
, 0);
570 if (size
< 0 || size
> vcc
->qos
.txtp
.max_sdu
) {
575 eff
= (size
+3) & ~3; /* align to word boundary */
576 prepare_to_wait(sk_sleep(sk
), &wait
, TASK_INTERRUPTIBLE
);
578 while (!(skb
= alloc_tx(vcc
, eff
))) {
579 if (m
->msg_flags
& MSG_DONTWAIT
) {
584 if (signal_pending(current
)) {
585 error
= -ERESTARTSYS
;
588 if (test_bit(ATM_VF_RELEASED
, &vcc
->flags
) ||
589 test_bit(ATM_VF_CLOSE
, &vcc
->flags
) ||
590 !test_bit(ATM_VF_READY
, &vcc
->flags
)) {
592 send_sig(SIGPIPE
, current
, 0);
595 prepare_to_wait(sk_sleep(sk
), &wait
, TASK_INTERRUPTIBLE
);
597 finish_wait(sk_sleep(sk
), &wait
);
600 skb
->dev
= NULL
; /* for paths shared with net_device interfaces */
601 ATM_SKB(skb
)->atm_options
= vcc
->atm_options
;
602 if (copy_from_user(skb_put(skb
, size
), buff
, size
)) {
608 memset(skb
->data
+ size
, 0, eff
-size
);
609 error
= vcc
->dev
->ops
->send(vcc
, skb
);
610 error
= error
? error
: size
;
616 unsigned int vcc_poll(struct file
*file
, struct socket
*sock
, poll_table
*wait
)
618 struct sock
*sk
= sock
->sk
;
622 sock_poll_wait(file
, sk_sleep(sk
), wait
);
627 /* exceptional events */
631 if (test_bit(ATM_VF_RELEASED
, &vcc
->flags
) ||
632 test_bit(ATM_VF_CLOSE
, &vcc
->flags
))
636 if (!skb_queue_empty(&sk
->sk_receive_queue
))
637 mask
|= POLLIN
| POLLRDNORM
;
640 if (sock
->state
== SS_CONNECTING
&&
641 test_bit(ATM_VF_WAITING
, &vcc
->flags
))
644 if (vcc
->qos
.txtp
.traffic_class
!= ATM_NONE
&&
646 mask
|= POLLOUT
| POLLWRNORM
| POLLWRBAND
;
651 static int atm_change_qos(struct atm_vcc
*vcc
, struct atm_qos
*qos
)
656 * Don't let the QoS change the already connected AAL type nor the
659 if (qos
->aal
!= vcc
->qos
.aal
||
660 qos
->rxtp
.traffic_class
!= vcc
->qos
.rxtp
.traffic_class
||
661 qos
->txtp
.traffic_class
!= vcc
->qos
.txtp
.traffic_class
)
663 error
= adjust_tp(&qos
->txtp
, qos
->aal
);
665 error
= adjust_tp(&qos
->rxtp
, qos
->aal
);
668 if (!vcc
->dev
->ops
->change_qos
)
670 if (sk_atm(vcc
)->sk_family
== AF_ATMPVC
)
671 return vcc
->dev
->ops
->change_qos(vcc
, qos
, ATM_MF_SET
);
672 return svc_change_qos(vcc
, qos
);
675 static int check_tp(const struct atm_trafprm
*tp
)
677 /* @@@ Should be merged with adjust_tp */
678 if (!tp
->traffic_class
|| tp
->traffic_class
== ATM_ANYCLASS
)
680 if (tp
->traffic_class
!= ATM_UBR
&& !tp
->min_pcr
&& !tp
->pcr
&&
683 if (tp
->min_pcr
== ATM_MAX_PCR
)
685 if (tp
->min_pcr
&& tp
->max_pcr
&& tp
->max_pcr
!= ATM_MAX_PCR
&&
686 tp
->min_pcr
> tp
->max_pcr
)
689 * We allow pcr to be outside [min_pcr,max_pcr], because later
690 * adjustment may still push it in the valid range.
695 static int check_qos(const struct atm_qos
*qos
)
699 if (!qos
->txtp
.traffic_class
&& !qos
->rxtp
.traffic_class
)
701 if (qos
->txtp
.traffic_class
!= qos
->rxtp
.traffic_class
&&
702 qos
->txtp
.traffic_class
&& qos
->rxtp
.traffic_class
&&
703 qos
->txtp
.traffic_class
!= ATM_ANYCLASS
&&
704 qos
->rxtp
.traffic_class
!= ATM_ANYCLASS
)
706 error
= check_tp(&qos
->txtp
);
709 return check_tp(&qos
->rxtp
);
712 int vcc_setsockopt(struct socket
*sock
, int level
, int optname
,
713 char __user
*optval
, unsigned int optlen
)
719 if (__SO_LEVEL_MATCH(optname
, level
) && optlen
!= __SO_SIZE(optname
))
728 if (copy_from_user(&qos
, optval
, sizeof(qos
)))
730 error
= check_qos(&qos
);
733 if (sock
->state
== SS_CONNECTED
)
734 return atm_change_qos(vcc
, &qos
);
735 if (sock
->state
!= SS_UNCONNECTED
)
738 set_bit(ATM_VF_HASQOS
, &vcc
->flags
);
742 if (get_user(value
, (unsigned long __user
*)optval
))
745 vcc
->atm_options
|= ATM_ATMOPT_CLP
;
747 vcc
->atm_options
&= ~ATM_ATMOPT_CLP
;
750 if (level
== SOL_SOCKET
)
754 if (!vcc
->dev
|| !vcc
->dev
->ops
->setsockopt
)
756 return vcc
->dev
->ops
->setsockopt(vcc
, level
, optname
, optval
, optlen
);
759 int vcc_getsockopt(struct socket
*sock
, int level
, int optname
,
760 char __user
*optval
, int __user
*optlen
)
765 if (get_user(len
, optlen
))
767 if (__SO_LEVEL_MATCH(optname
, level
) && len
!= __SO_SIZE(optname
))
773 if (!test_bit(ATM_VF_HASQOS
, &vcc
->flags
))
775 return copy_to_user(optval
, &vcc
->qos
, sizeof(vcc
->qos
))
778 return put_user(vcc
->atm_options
& ATM_ATMOPT_CLP
? 1 : 0,
779 (unsigned long __user
*)optval
) ? -EFAULT
: 0;
782 struct sockaddr_atmpvc pvc
;
784 if (!vcc
->dev
|| !test_bit(ATM_VF_ADDR
, &vcc
->flags
))
786 pvc
.sap_family
= AF_ATMPVC
;
787 pvc
.sap_addr
.itf
= vcc
->dev
->number
;
788 pvc
.sap_addr
.vpi
= vcc
->vpi
;
789 pvc
.sap_addr
.vci
= vcc
->vci
;
790 return copy_to_user(optval
, &pvc
, sizeof(pvc
)) ? -EFAULT
: 0;
793 if (level
== SOL_SOCKET
)
797 if (!vcc
->dev
|| !vcc
->dev
->ops
->getsockopt
)
799 return vcc
->dev
->ops
->getsockopt(vcc
, level
, optname
, optval
, len
);
802 int register_atmdevice_notifier(struct notifier_block
*nb
)
804 return atomic_notifier_chain_register(&atm_dev_notify_chain
, nb
);
806 EXPORT_SYMBOL_GPL(register_atmdevice_notifier
);
808 void unregister_atmdevice_notifier(struct notifier_block
*nb
)
810 atomic_notifier_chain_unregister(&atm_dev_notify_chain
, nb
);
812 EXPORT_SYMBOL_GPL(unregister_atmdevice_notifier
);
814 static int __init
atm_init(void)
818 error
= proto_register(&vcc_proto
, 0);
821 error
= atmpvc_init();
823 pr_err("atmpvc_init() failed with %d\n", error
);
824 goto out_unregister_vcc_proto
;
826 error
= atmsvc_init();
828 pr_err("atmsvc_init() failed with %d\n", error
);
829 goto out_atmpvc_exit
;
831 error
= atm_proc_init();
833 pr_err("atm_proc_init() failed with %d\n", error
);
834 goto out_atmsvc_exit
;
836 error
= atm_sysfs_init();
838 pr_err("atm_sysfs_init() failed with %d\n", error
);
839 goto out_atmproc_exit
;
849 out_unregister_vcc_proto
:
850 proto_unregister(&vcc_proto
);
854 static void __exit
atm_exit(void)
860 proto_unregister(&vcc_proto
);
863 subsys_initcall(atm_init
);
865 module_exit(atm_exit
);
867 MODULE_LICENSE("GPL");
868 MODULE_ALIAS_NETPROTO(PF_ATMPVC
);
869 MODULE_ALIAS_NETPROTO(PF_ATMSVC
);