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/signal.h>
17 #include <linux/time64.h> /* 64-bit time for seconds */
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 bool vcc_tx_ready(struct atm_vcc
*vcc
, unsigned int size
)
67 struct sock
*sk
= sk_atm(vcc
);
69 if (sk_wmem_alloc_get(sk
) && !atm_may_send(vcc
, size
)) {
70 pr_debug("Sorry: wmem_alloc = %d, size = %d, sndbuf = %d\n",
71 sk_wmem_alloc_get(sk
), size
, sk
->sk_sndbuf
);
77 static void vcc_sock_destruct(struct sock
*sk
)
79 if (atomic_read(&sk
->sk_rmem_alloc
))
80 printk(KERN_DEBUG
"%s: rmem leakage (%d bytes) detected.\n",
81 __func__
, atomic_read(&sk
->sk_rmem_alloc
));
83 if (refcount_read(&sk
->sk_wmem_alloc
))
84 printk(KERN_DEBUG
"%s: wmem leakage (%d bytes) detected.\n",
85 __func__
, refcount_read(&sk
->sk_wmem_alloc
));
88 static void vcc_def_wakeup(struct sock
*sk
)
93 wq
= rcu_dereference(sk
->sk_wq
);
94 if (skwq_has_sleeper(wq
))
99 static inline int vcc_writable(struct sock
*sk
)
101 struct atm_vcc
*vcc
= atm_sk(sk
);
103 return (vcc
->qos
.txtp
.max_sdu
+
104 refcount_read(&sk
->sk_wmem_alloc
)) <= sk
->sk_sndbuf
;
107 static void vcc_write_space(struct sock
*sk
)
109 struct socket_wq
*wq
;
113 if (vcc_writable(sk
)) {
114 wq
= rcu_dereference(sk
->sk_wq
);
115 if (skwq_has_sleeper(wq
))
116 wake_up_interruptible(&wq
->wait
);
118 sk_wake_async(sk
, SOCK_WAKE_SPACE
, POLL_OUT
);
124 static void vcc_release_cb(struct sock
*sk
)
126 struct atm_vcc
*vcc
= atm_sk(sk
);
129 vcc
->release_cb(vcc
);
132 static struct proto vcc_proto
= {
134 .owner
= THIS_MODULE
,
135 .obj_size
= sizeof(struct atm_vcc
),
136 .release_cb
= vcc_release_cb
,
139 int vcc_create(struct net
*net
, struct socket
*sock
, int protocol
, int family
, int kern
)
145 if (sock
->type
== SOCK_STREAM
)
147 sk
= sk_alloc(net
, family
, GFP_KERNEL
, &vcc_proto
, kern
);
150 sock_init_data(sock
, sk
);
151 sk
->sk_state_change
= vcc_def_wakeup
;
152 sk
->sk_write_space
= vcc_write_space
;
156 memset(&vcc
->local
, 0, sizeof(struct sockaddr_atmsvc
));
157 memset(&vcc
->remote
, 0, sizeof(struct sockaddr_atmsvc
));
158 vcc
->qos
.txtp
.max_sdu
= 1 << 16; /* for meta VCs */
159 refcount_set(&sk
->sk_wmem_alloc
, 1);
160 atomic_set(&sk
->sk_rmem_alloc
, 0);
164 vcc
->push_oam
= NULL
;
165 vcc
->release_cb
= NULL
;
166 vcc
->vpi
= vcc
->vci
= 0; /* no VCI/VPI yet */
167 vcc
->atm_options
= vcc
->aal_options
= 0;
168 sk
->sk_destruct
= vcc_sock_destruct
;
172 static void vcc_destroy_socket(struct sock
*sk
)
174 struct atm_vcc
*vcc
= atm_sk(sk
);
177 set_bit(ATM_VF_CLOSE
, &vcc
->flags
);
178 clear_bit(ATM_VF_READY
, &vcc
->flags
);
180 if (vcc
->dev
->ops
->close
)
181 vcc
->dev
->ops
->close(vcc
);
183 vcc
->push(vcc
, NULL
); /* atmarpd has no push */
184 module_put(vcc
->owner
);
186 while ((skb
= skb_dequeue(&sk
->sk_receive_queue
)) != NULL
) {
187 atm_return(vcc
, skb
->truesize
);
191 module_put(vcc
->dev
->ops
->owner
);
192 atm_dev_put(vcc
->dev
);
195 vcc_remove_socket(sk
);
198 int vcc_release(struct socket
*sock
)
200 struct sock
*sk
= sock
->sk
;
204 vcc_destroy_socket(sock
->sk
);
212 void vcc_release_async(struct atm_vcc
*vcc
, int reply
)
214 struct sock
*sk
= sk_atm(vcc
);
216 set_bit(ATM_VF_CLOSE
, &vcc
->flags
);
217 sk
->sk_shutdown
|= RCV_SHUTDOWN
;
219 clear_bit(ATM_VF_WAITING
, &vcc
->flags
);
220 sk
->sk_state_change(sk
);
222 EXPORT_SYMBOL(vcc_release_async
);
224 void vcc_process_recv_queue(struct atm_vcc
*vcc
)
226 struct sk_buff_head queue
, *rq
;
227 struct sk_buff
*skb
, *tmp
;
230 __skb_queue_head_init(&queue
);
231 rq
= &sk_atm(vcc
)->sk_receive_queue
;
233 spin_lock_irqsave(&rq
->lock
, flags
);
234 skb_queue_splice_init(rq
, &queue
);
235 spin_unlock_irqrestore(&rq
->lock
, flags
);
237 skb_queue_walk_safe(&queue
, skb
, tmp
) {
238 __skb_unlink(skb
, &queue
);
242 EXPORT_SYMBOL(vcc_process_recv_queue
);
244 void atm_dev_signal_change(struct atm_dev
*dev
, char signal
)
246 pr_debug("%s signal=%d dev=%p number=%d dev->signal=%d\n",
247 __func__
, signal
, dev
, dev
->number
, dev
->signal
);
249 /* atm driver sending invalid signal */
250 WARN_ON(signal
< ATM_PHY_SIG_LOST
|| signal
> ATM_PHY_SIG_FOUND
);
252 if (dev
->signal
== signal
)
253 return; /* no change */
255 dev
->signal
= signal
;
257 atomic_notifier_call_chain(&atm_dev_notify_chain
, signal
, dev
);
259 EXPORT_SYMBOL(atm_dev_signal_change
);
261 void atm_dev_release_vccs(struct atm_dev
*dev
)
265 write_lock_irq(&vcc_sklist_lock
);
266 for (i
= 0; i
< VCC_HTABLE_SIZE
; i
++) {
267 struct hlist_head
*head
= &vcc_hash
[i
];
268 struct hlist_node
*tmp
;
272 sk_for_each_safe(s
, tmp
, head
) {
274 if (vcc
->dev
== dev
) {
275 vcc_release_async(vcc
, -EPIPE
);
280 write_unlock_irq(&vcc_sklist_lock
);
282 EXPORT_SYMBOL(atm_dev_release_vccs
);
284 static int adjust_tp(struct atm_trafprm
*tp
, unsigned char aal
)
288 if (!tp
->traffic_class
)
292 max_sdu
= ATM_CELL_SIZE
-1;
295 max_sdu
= ATM_MAX_AAL34_PDU
;
298 pr_warn("AAL problems ... (%d)\n", aal
);
301 max_sdu
= ATM_MAX_AAL5_PDU
;
304 tp
->max_sdu
= max_sdu
;
305 else if (tp
->max_sdu
> max_sdu
)
308 tp
->max_cdv
= ATM_MAX_CDV
;
312 static int check_ci(const struct atm_vcc
*vcc
, short vpi
, int vci
)
314 struct hlist_head
*head
= &vcc_hash
[vci
& (VCC_HTABLE_SIZE
- 1)];
316 struct atm_vcc
*walk
;
318 sk_for_each(s
, head
) {
320 if (walk
->dev
!= vcc
->dev
)
322 if (test_bit(ATM_VF_ADDR
, &walk
->flags
) && walk
->vpi
== vpi
&&
323 walk
->vci
== vci
&& ((walk
->qos
.txtp
.traffic_class
!=
324 ATM_NONE
&& vcc
->qos
.txtp
.traffic_class
!= ATM_NONE
) ||
325 (walk
->qos
.rxtp
.traffic_class
!= ATM_NONE
&&
326 vcc
->qos
.rxtp
.traffic_class
!= ATM_NONE
)))
330 /* allow VCCs with same VPI/VCI iff they don't collide on
331 TX/RX (but we may refuse such sharing for other reasons,
332 e.g. if protocol requires to have both channels) */
337 static int find_ci(const struct atm_vcc
*vcc
, short *vpi
, int *vci
)
339 static short p
; /* poor man's per-device cache */
345 if (*vpi
!= ATM_VPI_ANY
&& *vci
!= ATM_VCI_ANY
) {
346 err
= check_ci(vcc
, *vpi
, *vci
);
349 /* last scan may have left values out of bounds for current device */
350 if (*vpi
!= ATM_VPI_ANY
)
352 else if (p
>= 1 << vcc
->dev
->ci_range
.vpi_bits
)
354 if (*vci
!= ATM_VCI_ANY
)
356 else if (c
< ATM_NOT_RSV_VCI
|| c
>= 1 << vcc
->dev
->ci_range
.vci_bits
)
361 if (!check_ci(vcc
, p
, c
)) {
366 if (*vci
== ATM_VCI_ANY
) {
368 if (c
>= 1 << vcc
->dev
->ci_range
.vci_bits
)
371 if ((c
== ATM_NOT_RSV_VCI
|| *vci
!= ATM_VCI_ANY
) &&
372 *vpi
== ATM_VPI_ANY
) {
374 if (p
>= 1 << vcc
->dev
->ci_range
.vpi_bits
)
377 } while (old_p
!= p
|| old_c
!= c
);
381 static int __vcc_connect(struct atm_vcc
*vcc
, struct atm_dev
*dev
, short vpi
,
384 struct sock
*sk
= sk_atm(vcc
);
387 if ((vpi
!= ATM_VPI_UNSPEC
&& vpi
!= ATM_VPI_ANY
&&
388 vpi
>> dev
->ci_range
.vpi_bits
) || (vci
!= ATM_VCI_UNSPEC
&&
389 vci
!= ATM_VCI_ANY
&& vci
>> dev
->ci_range
.vci_bits
))
391 if (vci
> 0 && vci
< ATM_NOT_RSV_VCI
&& !capable(CAP_NET_BIND_SERVICE
))
394 if (!try_module_get(dev
->ops
->owner
))
397 write_lock_irq(&vcc_sklist_lock
);
398 if (test_bit(ATM_DF_REMOVED
, &dev
->flags
) ||
399 (error
= find_ci(vcc
, &vpi
, &vci
))) {
400 write_unlock_irq(&vcc_sklist_lock
);
401 goto fail_module_put
;
405 __vcc_insert_socket(sk
);
406 write_unlock_irq(&vcc_sklist_lock
);
407 switch (vcc
->qos
.aal
) {
409 error
= atm_init_aal0(vcc
);
410 vcc
->stats
= &dev
->stats
.aal0
;
413 error
= atm_init_aal34(vcc
);
414 vcc
->stats
= &dev
->stats
.aal34
;
417 /* ATM_AAL5 is also used in the "0 for default" case */
418 vcc
->qos
.aal
= ATM_AAL5
;
421 error
= atm_init_aal5(vcc
);
422 vcc
->stats
= &dev
->stats
.aal5
;
428 error
= adjust_tp(&vcc
->qos
.txtp
, vcc
->qos
.aal
);
430 error
= adjust_tp(&vcc
->qos
.rxtp
, vcc
->qos
.aal
);
433 pr_debug("VCC %d.%d, AAL %d\n", vpi
, vci
, vcc
->qos
.aal
);
434 pr_debug(" TX: %d, PCR %d..%d, SDU %d\n",
435 vcc
->qos
.txtp
.traffic_class
,
436 vcc
->qos
.txtp
.min_pcr
,
437 vcc
->qos
.txtp
.max_pcr
,
438 vcc
->qos
.txtp
.max_sdu
);
439 pr_debug(" RX: %d, PCR %d..%d, SDU %d\n",
440 vcc
->qos
.rxtp
.traffic_class
,
441 vcc
->qos
.rxtp
.min_pcr
,
442 vcc
->qos
.rxtp
.max_pcr
,
443 vcc
->qos
.rxtp
.max_sdu
);
445 if (dev
->ops
->open
) {
446 error
= dev
->ops
->open(vcc
);
453 vcc_remove_socket(sk
);
455 module_put(dev
->ops
->owner
);
456 /* ensure we get dev module ref count correct */
461 int vcc_connect(struct socket
*sock
, int itf
, short vpi
, int vci
)
464 struct atm_vcc
*vcc
= ATM_SD(sock
);
467 pr_debug("(vpi %d, vci %d)\n", vpi
, vci
);
468 if (sock
->state
== SS_CONNECTED
)
470 if (sock
->state
!= SS_UNCONNECTED
)
475 if (vpi
!= ATM_VPI_UNSPEC
&& vci
!= ATM_VCI_UNSPEC
)
476 clear_bit(ATM_VF_PARTIAL
, &vcc
->flags
);
478 if (test_bit(ATM_VF_PARTIAL
, &vcc
->flags
))
480 pr_debug("(TX: cl %d,bw %d-%d,sdu %d; "
481 "RX: cl %d,bw %d-%d,sdu %d,AAL %s%d)\n",
482 vcc
->qos
.txtp
.traffic_class
, vcc
->qos
.txtp
.min_pcr
,
483 vcc
->qos
.txtp
.max_pcr
, vcc
->qos
.txtp
.max_sdu
,
484 vcc
->qos
.rxtp
.traffic_class
, vcc
->qos
.rxtp
.min_pcr
,
485 vcc
->qos
.rxtp
.max_pcr
, vcc
->qos
.rxtp
.max_sdu
,
486 vcc
->qos
.aal
== ATM_AAL5
? "" :
487 vcc
->qos
.aal
== ATM_AAL0
? "" : " ??? code ",
488 vcc
->qos
.aal
== ATM_AAL0
? 0 : vcc
->qos
.aal
);
489 if (!test_bit(ATM_VF_HASQOS
, &vcc
->flags
))
491 if (vcc
->qos
.txtp
.traffic_class
== ATM_ANYCLASS
||
492 vcc
->qos
.rxtp
.traffic_class
== ATM_ANYCLASS
)
494 if (likely(itf
!= ATM_ITF_ANY
)) {
495 dev
= try_then_request_module(atm_dev_lookup(itf
),
496 "atm-device-%d", itf
);
499 mutex_lock(&atm_dev_mutex
);
500 if (!list_empty(&atm_devs
)) {
501 dev
= list_entry(atm_devs
.next
,
502 struct atm_dev
, dev_list
);
505 mutex_unlock(&atm_dev_mutex
);
509 error
= __vcc_connect(vcc
, dev
, vpi
, vci
);
514 if (vpi
== ATM_VPI_UNSPEC
|| vci
== ATM_VCI_UNSPEC
)
515 set_bit(ATM_VF_PARTIAL
, &vcc
->flags
);
516 if (test_bit(ATM_VF_READY
, &ATM_SD(sock
)->flags
))
517 sock
->state
= SS_CONNECTED
;
521 int vcc_recvmsg(struct socket
*sock
, struct msghdr
*msg
, size_t size
,
524 struct sock
*sk
= sock
->sk
;
527 int copied
, error
= -EINVAL
;
529 if (sock
->state
!= SS_CONNECTED
)
532 /* only handle MSG_DONTWAIT and MSG_PEEK */
533 if (flags
& ~(MSG_DONTWAIT
| MSG_PEEK
))
537 if (test_bit(ATM_VF_RELEASED
, &vcc
->flags
) ||
538 test_bit(ATM_VF_CLOSE
, &vcc
->flags
) ||
539 !test_bit(ATM_VF_READY
, &vcc
->flags
))
542 skb
= skb_recv_datagram(sk
, flags
, flags
& MSG_DONTWAIT
, &error
);
549 msg
->msg_flags
|= MSG_TRUNC
;
552 error
= skb_copy_datagram_msg(skb
, 0, msg
, copied
);
555 sock_recv_ts_and_drops(msg
, sk
, skb
);
557 if (!(flags
& MSG_PEEK
)) {
558 pr_debug("%d -= %d\n", atomic_read(&sk
->sk_rmem_alloc
),
560 atm_return(vcc
, skb
->truesize
);
563 skb_free_datagram(sk
, skb
);
567 int vcc_sendmsg(struct socket
*sock
, struct msghdr
*m
, size_t size
)
569 struct sock
*sk
= sock
->sk
;
576 if (sock
->state
!= SS_CONNECTED
) {
585 if (test_bit(ATM_VF_RELEASED
, &vcc
->flags
) ||
586 test_bit(ATM_VF_CLOSE
, &vcc
->flags
) ||
587 !test_bit(ATM_VF_READY
, &vcc
->flags
)) {
589 send_sig(SIGPIPE
, current
, 0);
596 if (size
> vcc
->qos
.txtp
.max_sdu
) {
601 eff
= (size
+3) & ~3; /* align to word boundary */
602 prepare_to_wait(sk_sleep(sk
), &wait
, TASK_INTERRUPTIBLE
);
604 while (!vcc_tx_ready(vcc
, eff
)) {
605 if (m
->msg_flags
& MSG_DONTWAIT
) {
610 if (signal_pending(current
)) {
611 error
= -ERESTARTSYS
;
614 if (test_bit(ATM_VF_RELEASED
, &vcc
->flags
) ||
615 test_bit(ATM_VF_CLOSE
, &vcc
->flags
) ||
616 !test_bit(ATM_VF_READY
, &vcc
->flags
)) {
618 send_sig(SIGPIPE
, current
, 0);
621 prepare_to_wait(sk_sleep(sk
), &wait
, TASK_INTERRUPTIBLE
);
623 finish_wait(sk_sleep(sk
), &wait
);
627 skb
= alloc_skb(eff
, GFP_KERNEL
);
632 pr_debug("%d += %d\n", sk_wmem_alloc_get(sk
), skb
->truesize
);
633 refcount_add(skb
->truesize
, &sk
->sk_wmem_alloc
);
635 skb
->dev
= NULL
; /* for paths shared with net_device interfaces */
636 ATM_SKB(skb
)->atm_options
= vcc
->atm_options
;
637 if (!copy_from_iter_full(skb_put(skb
, size
), size
, &m
->msg_iter
)) {
643 memset(skb
->data
+ size
, 0, eff
-size
);
644 error
= vcc
->dev
->ops
->send(vcc
, skb
);
645 error
= error
? error
: size
;
651 __poll_t
vcc_poll_mask(struct socket
*sock
, __poll_t events
)
653 struct sock
*sk
= sock
->sk
;
654 struct atm_vcc
*vcc
= ATM_SD(sock
);
657 /* exceptional events */
661 if (test_bit(ATM_VF_RELEASED
, &vcc
->flags
) ||
662 test_bit(ATM_VF_CLOSE
, &vcc
->flags
))
666 if (!skb_queue_empty(&sk
->sk_receive_queue
))
667 mask
|= EPOLLIN
| EPOLLRDNORM
;
670 if (sock
->state
== SS_CONNECTING
&&
671 test_bit(ATM_VF_WAITING
, &vcc
->flags
))
674 if (vcc
->qos
.txtp
.traffic_class
!= ATM_NONE
&&
676 mask
|= EPOLLOUT
| EPOLLWRNORM
| EPOLLWRBAND
;
681 static int atm_change_qos(struct atm_vcc
*vcc
, struct atm_qos
*qos
)
686 * Don't let the QoS change the already connected AAL type nor the
689 if (qos
->aal
!= vcc
->qos
.aal
||
690 qos
->rxtp
.traffic_class
!= vcc
->qos
.rxtp
.traffic_class
||
691 qos
->txtp
.traffic_class
!= vcc
->qos
.txtp
.traffic_class
)
693 error
= adjust_tp(&qos
->txtp
, qos
->aal
);
695 error
= adjust_tp(&qos
->rxtp
, qos
->aal
);
698 if (!vcc
->dev
->ops
->change_qos
)
700 if (sk_atm(vcc
)->sk_family
== AF_ATMPVC
)
701 return vcc
->dev
->ops
->change_qos(vcc
, qos
, ATM_MF_SET
);
702 return svc_change_qos(vcc
, qos
);
705 static int check_tp(const struct atm_trafprm
*tp
)
707 /* @@@ Should be merged with adjust_tp */
708 if (!tp
->traffic_class
|| tp
->traffic_class
== ATM_ANYCLASS
)
710 if (tp
->traffic_class
!= ATM_UBR
&& !tp
->min_pcr
&& !tp
->pcr
&&
713 if (tp
->min_pcr
== ATM_MAX_PCR
)
715 if (tp
->min_pcr
&& tp
->max_pcr
&& tp
->max_pcr
!= ATM_MAX_PCR
&&
716 tp
->min_pcr
> tp
->max_pcr
)
719 * We allow pcr to be outside [min_pcr,max_pcr], because later
720 * adjustment may still push it in the valid range.
725 static int check_qos(const struct atm_qos
*qos
)
729 if (!qos
->txtp
.traffic_class
&& !qos
->rxtp
.traffic_class
)
731 if (qos
->txtp
.traffic_class
!= qos
->rxtp
.traffic_class
&&
732 qos
->txtp
.traffic_class
&& qos
->rxtp
.traffic_class
&&
733 qos
->txtp
.traffic_class
!= ATM_ANYCLASS
&&
734 qos
->rxtp
.traffic_class
!= ATM_ANYCLASS
)
736 error
= check_tp(&qos
->txtp
);
739 return check_tp(&qos
->rxtp
);
742 int vcc_setsockopt(struct socket
*sock
, int level
, int optname
,
743 char __user
*optval
, unsigned int optlen
)
749 if (__SO_LEVEL_MATCH(optname
, level
) && optlen
!= __SO_SIZE(optname
))
758 if (copy_from_user(&qos
, optval
, sizeof(qos
)))
760 error
= check_qos(&qos
);
763 if (sock
->state
== SS_CONNECTED
)
764 return atm_change_qos(vcc
, &qos
);
765 if (sock
->state
!= SS_UNCONNECTED
)
768 set_bit(ATM_VF_HASQOS
, &vcc
->flags
);
772 if (get_user(value
, (unsigned long __user
*)optval
))
775 vcc
->atm_options
|= ATM_ATMOPT_CLP
;
777 vcc
->atm_options
&= ~ATM_ATMOPT_CLP
;
780 if (level
== SOL_SOCKET
)
784 if (!vcc
->dev
|| !vcc
->dev
->ops
->setsockopt
)
786 return vcc
->dev
->ops
->setsockopt(vcc
, level
, optname
, optval
, optlen
);
789 int vcc_getsockopt(struct socket
*sock
, int level
, int optname
,
790 char __user
*optval
, int __user
*optlen
)
795 if (get_user(len
, optlen
))
797 if (__SO_LEVEL_MATCH(optname
, level
) && len
!= __SO_SIZE(optname
))
803 if (!test_bit(ATM_VF_HASQOS
, &vcc
->flags
))
805 return copy_to_user(optval
, &vcc
->qos
, sizeof(vcc
->qos
))
808 return put_user(vcc
->atm_options
& ATM_ATMOPT_CLP
? 1 : 0,
809 (unsigned long __user
*)optval
) ? -EFAULT
: 0;
812 struct sockaddr_atmpvc pvc
;
814 if (!vcc
->dev
|| !test_bit(ATM_VF_ADDR
, &vcc
->flags
))
816 memset(&pvc
, 0, sizeof(pvc
));
817 pvc
.sap_family
= AF_ATMPVC
;
818 pvc
.sap_addr
.itf
= vcc
->dev
->number
;
819 pvc
.sap_addr
.vpi
= vcc
->vpi
;
820 pvc
.sap_addr
.vci
= vcc
->vci
;
821 return copy_to_user(optval
, &pvc
, sizeof(pvc
)) ? -EFAULT
: 0;
824 if (level
== SOL_SOCKET
)
828 if (!vcc
->dev
|| !vcc
->dev
->ops
->getsockopt
)
830 return vcc
->dev
->ops
->getsockopt(vcc
, level
, optname
, optval
, len
);
833 int register_atmdevice_notifier(struct notifier_block
*nb
)
835 return atomic_notifier_chain_register(&atm_dev_notify_chain
, nb
);
837 EXPORT_SYMBOL_GPL(register_atmdevice_notifier
);
839 void unregister_atmdevice_notifier(struct notifier_block
*nb
)
841 atomic_notifier_chain_unregister(&atm_dev_notify_chain
, nb
);
843 EXPORT_SYMBOL_GPL(unregister_atmdevice_notifier
);
845 static int __init
atm_init(void)
849 error
= proto_register(&vcc_proto
, 0);
852 error
= atmpvc_init();
854 pr_err("atmpvc_init() failed with %d\n", error
);
855 goto out_unregister_vcc_proto
;
857 error
= atmsvc_init();
859 pr_err("atmsvc_init() failed with %d\n", error
);
860 goto out_atmpvc_exit
;
862 error
= atm_proc_init();
864 pr_err("atm_proc_init() failed with %d\n", error
);
865 goto out_atmsvc_exit
;
867 error
= atm_sysfs_init();
869 pr_err("atm_sysfs_init() failed with %d\n", error
);
870 goto out_atmproc_exit
;
880 out_unregister_vcc_proto
:
881 proto_unregister(&vcc_proto
);
885 static void __exit
atm_exit(void)
891 proto_unregister(&vcc_proto
);
894 subsys_initcall(atm_init
);
896 module_exit(atm_exit
);
898 MODULE_LICENSE("GPL");
899 MODULE_ALIAS_NETPROTO(PF_ATMPVC
);
900 MODULE_ALIAS_NETPROTO(PF_ATMSVC
);