1 /* net/atm/common.c - ATM sockets (common part for PVC and SVC) */
3 /* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */
6 #include <linux/config.h>
7 #include <linux/module.h>
8 #include <linux/kmod.h>
9 #include <linux/net.h> /* struct socket, struct net_proto, struct
11 #include <linux/atm.h> /* ATM stuff */
12 #include <linux/atmdev.h>
13 #include <linux/atmclip.h> /* CLIP_*ENCAP */
14 #include <linux/atmarp.h> /* manifest constants */
15 #include <linux/sonet.h> /* for ioctls */
16 #include <linux/socket.h> /* SOL_SOCKET */
17 #include <linux/errno.h> /* error codes */
18 #include <linux/capability.h>
19 #include <linux/mm.h> /* verify_area */
20 #include <linux/sched.h>
21 #include <linux/time.h> /* struct timeval */
22 #include <linux/skbuff.h>
23 #include <linux/bitops.h>
24 #include <linux/init.h>
25 #include <net/sock.h> /* struct sock */
27 #include <asm/uaccess.h>
28 #include <asm/atomic.h>
30 #include <asm/ioctls.h>
32 #if defined(CONFIG_ATM_LANE) || defined(CONFIG_ATM_LANE_MODULE)
33 #include <linux/atmlec.h>
36 struct atm_lane_ops *atm_lane_ops;
37 static DECLARE_MUTEX(atm_lane_ops_mutex);
39 void atm_lane_ops_set(struct atm_lane_ops *hook)
41 down(&atm_lane_ops_mutex);
43 up(&atm_lane_ops_mutex);
46 int try_atm_lane_ops(void)
48 down(&atm_lane_ops_mutex);
49 if (atm_lane_ops && try_inc_mod_count(atm_lane_ops->owner)) {
50 up(&atm_lane_ops_mutex);
53 up(&atm_lane_ops_mutex);
57 #if defined(CONFIG_ATM_LANE_MODULE) || defined(CONFIG_ATM_MPOA_MODULE)
58 EXPORT_SYMBOL(atm_lane_ops);
59 EXPORT_SYMBOL(try_atm_lane_ops);
60 EXPORT_SYMBOL(atm_lane_ops_set);
64 #if defined(CONFIG_ATM_MPOA) || defined(CONFIG_ATM_MPOA_MODULE)
65 #include <linux/atmmpc.h>
67 struct atm_mpoa_ops *atm_mpoa_ops;
68 static DECLARE_MUTEX(atm_mpoa_ops_mutex);
70 void atm_mpoa_ops_set(struct atm_mpoa_ops *hook)
72 down(&atm_mpoa_ops_mutex);
74 up(&atm_mpoa_ops_mutex);
77 int try_atm_mpoa_ops(void)
79 down(&atm_mpoa_ops_mutex);
80 if (atm_mpoa_ops && try_inc_mod_count(atm_mpoa_ops->owner)) {
81 up(&atm_mpoa_ops_mutex);
84 up(&atm_mpoa_ops_mutex);
87 #ifdef CONFIG_ATM_MPOA_MODULE
88 EXPORT_SYMBOL(atm_mpoa_ops);
89 EXPORT_SYMBOL(try_atm_mpoa_ops);
90 EXPORT_SYMBOL(atm_mpoa_ops_set);
94 #if defined(CONFIG_ATM_TCP) || defined(CONFIG_ATM_TCP_MODULE)
95 #include <linux/atm_tcp.h>
96 #ifdef CONFIG_ATM_TCP_MODULE
97 struct atm_tcp_ops atm_tcp_ops;
98 EXPORT_SYMBOL(atm_tcp_ops);
102 #if defined(CONFIG_ATM_CLIP) || defined(CONFIG_ATM_CLIP_MODULE)
103 #include <net/atmclip.h>
104 struct atm_clip_ops *atm_clip_ops;
105 static DECLARE_MUTEX(atm_clip_ops_mutex);
107 void atm_clip_ops_set(struct atm_clip_ops *hook)
109 down(&atm_clip_ops_mutex);
111 up(&atm_clip_ops_mutex);
114 int try_atm_clip_ops(void)
116 down(&atm_clip_ops_mutex);
117 if (atm_clip_ops && try_inc_mod_count(atm_clip_ops->owner)) {
118 up(&atm_clip_ops_mutex);
121 up(&atm_clip_ops_mutex);
125 #ifdef CONFIG_ATM_CLIP_MODULE
126 EXPORT_SYMBOL(atm_clip_ops);
127 EXPORT_SYMBOL(try_atm_clip_ops);
128 EXPORT_SYMBOL(atm_clip_ops_set);
132 #if defined(CONFIG_PPPOATM) || defined(CONFIG_PPPOATM_MODULE)
133 static DECLARE_MUTEX(pppoatm_ioctl_mutex);
135 static int (*pppoatm_ioctl_hook)(struct atm_vcc *, unsigned int, unsigned long);
137 void pppoatm_ioctl_set(int (*hook)(struct atm_vcc *, unsigned int, unsigned long))
139 down(&pppoatm_ioctl_mutex);
140 pppoatm_ioctl_hook = hook;
141 up(&pppoatm_ioctl_mutex);
143 #ifdef CONFIG_PPPOATM_MODULE
144 EXPORT_SYMBOL(pppoatm_ioctl_set);
148 #if defined(CONFIG_ATM_BR2684) || defined(CONFIG_ATM_BR2684_MODULE)
149 static DECLARE_MUTEX(br2684_ioctl_mutex);
151 static int (*br2684_ioctl_hook)(struct atm_vcc *, unsigned int, unsigned long);
153 void br2684_ioctl_set(int (*hook)(struct atm_vcc *, unsigned int, unsigned long))
155 down(&br2684_ioctl_mutex);
156 br2684_ioctl_hook = hook;
157 up(&br2684_ioctl_mutex);
159 #ifdef CONFIG_ATM_BR2684_MODULE
160 EXPORT_SYMBOL(br2684_ioctl_set);
164 #include "resources.h" /* atm_find_dev */
165 #include "common.h" /* prototypes */
166 #include "protocols.h" /* atm_init_<transport> */
167 #include "addr.h" /* address registry */
168 #ifdef CONFIG_ATM_CLIP
169 #include <net/atmclip.h> /* for clip_create */
171 #include "signaling.h" /* for WAITING and sigd_attach */
175 #define DPRINTK(format,args...) printk(KERN_DEBUG format,##args)
177 #define DPRINTK(format,args...)
181 struct sock *vcc_sklist;
182 rwlock_t vcc_sklist_lock = RW_LOCK_UNLOCKED;
184 void __vcc_insert_socket(struct sock *sk)
186 sk->next = vcc_sklist;
188 vcc_sklist->pprev = &sk->next;
190 sk->pprev = &vcc_sklist;
193 void vcc_insert_socket(struct sock *sk)
195 write_lock_irq(&vcc_sklist_lock);
196 __vcc_insert_socket(sk);
197 write_unlock_irq(&vcc_sklist_lock);
200 void vcc_remove_socket(struct sock *sk)
202 write_lock_irq(&vcc_sklist_lock);
205 sk->next->pprev = sk->pprev;
206 *sk->pprev = sk->next;
209 write_unlock_irq(&vcc_sklist_lock);
213 static struct sk_buff *alloc_tx(struct atm_vcc *vcc,unsigned int size)
217 if (atomic_read(&vcc->sk->wmem_alloc) && !atm_may_send(vcc,size)) {
218 DPRINTK("Sorry: wmem_alloc = %d, size = %d, sndbuf = %d\n",
219 atomic_read(&vcc->sk->wmem_alloc),size,vcc->sk->sndbuf);
222 while (!(skb = alloc_skb(size,GFP_KERNEL))) schedule();
223 DPRINTK("AlTx %d += %d\n",atomic_read(&vcc->sk->wmem_alloc),skb->truesize);
224 atomic_add(skb->truesize, &vcc->sk->wmem_alloc);
229 EXPORT_SYMBOL(vcc_sklist);
230 EXPORT_SYMBOL(vcc_sklist_lock);
231 EXPORT_SYMBOL(vcc_insert_socket);
232 EXPORT_SYMBOL(vcc_remove_socket);
234 static void vcc_sock_destruct(struct sock *sk)
236 struct atm_vcc *vcc = sk->protinfo.af_atm;
238 if (atomic_read(&vcc->sk->rmem_alloc))
239 printk(KERN_DEBUG "vcc_sock_destruct: rmem leakage (%d bytes) detected.\n", atomic_read(&sk->rmem_alloc));
241 if (atomic_read(&vcc->sk->wmem_alloc))
242 printk(KERN_DEBUG "vcc_sock_destruct: wmem leakage (%d bytes) detected.\n", atomic_read(&sk->wmem_alloc));
244 kfree(sk->protinfo.af_atm);
249 int vcc_create(struct socket *sock, int protocol, int family)
255 if (sock->type == SOCK_STREAM)
257 sk = sk_alloc(family, GFP_KERNEL, 1);
260 sock_init_data(NULL, sk);
262 vcc = sk->protinfo.af_atm = kmalloc(sizeof(*vcc), GFP_KERNEL);
268 memset(vcc, 0, sizeof(*vcc));
272 vcc->callback = NULL;
273 memset(&vcc->local,0,sizeof(struct sockaddr_atmsvc));
274 memset(&vcc->remote,0,sizeof(struct sockaddr_atmsvc));
275 vcc->qos.txtp.max_sdu = 1 << 16; /* for meta VCs */
276 atomic_set(&vcc->sk->wmem_alloc,0);
277 atomic_set(&vcc->sk->rmem_alloc,0);
280 vcc->push_oam = NULL;
281 vcc->vpi = vcc->vci = 0; /* no VCI/VPI yet */
282 vcc->atm_options = vcc->aal_options = 0;
283 init_waitqueue_head(&vcc->sleep);
284 sk->sleep = &vcc->sleep;
285 sk->destruct = vcc_sock_destruct;
294 static void vcc_destroy_socket(struct sock *sk)
299 vcc = sk->protinfo.af_atm;
300 clear_bit(ATM_VF_READY, &vcc->flags);
302 if (vcc->dev->ops->close)
303 vcc->dev->ops->close(vcc);
305 vcc->push(vcc, NULL); /* atmarpd has no push */
307 vcc_remove_socket(sk); /* no more receive */
309 while ((skb = skb_dequeue(&vcc->sk->receive_queue))) {
310 atm_return(vcc,skb->truesize);
314 if (vcc->dev->ops->owner)
315 __MOD_DEC_USE_COUNT(vcc->dev->ops->owner);
316 atm_dev_put(vcc->dev);
321 int vcc_release(struct socket *sock)
323 struct sock *sk = sock->sk;
327 vcc_destroy_socket(sock->sk);
336 void vcc_release_async(struct atm_vcc *vcc, int reply)
338 set_bit(ATM_VF_CLOSE, &vcc->flags);
340 vcc->sk->err = -reply;
341 wake_up(&vcc->sleep);
345 EXPORT_SYMBOL(vcc_release_async);
348 static int adjust_tp(struct atm_trafprm *tp,unsigned char aal)
352 if (!tp->traffic_class) return 0;
355 max_sdu = ATM_CELL_SIZE-1;
358 max_sdu = ATM_MAX_AAL34_PDU;
361 printk(KERN_WARNING "ATM: AAL problems ... "
365 max_sdu = ATM_MAX_AAL5_PDU;
367 if (!tp->max_sdu) tp->max_sdu = max_sdu;
368 else if (tp->max_sdu > max_sdu) return -EINVAL;
369 if (!tp->max_cdv) tp->max_cdv = ATM_MAX_CDV;
374 static int __vcc_connect(struct atm_vcc *vcc, struct atm_dev *dev, int vpi,
379 if ((vpi != ATM_VPI_UNSPEC && vpi != ATM_VPI_ANY &&
380 vpi >> dev->ci_range.vpi_bits) || (vci != ATM_VCI_UNSPEC &&
381 vci != ATM_VCI_ANY && vci >> dev->ci_range.vci_bits))
383 if (vci > 0 && vci < ATM_NOT_RSV_VCI && !capable(CAP_NET_BIND_SERVICE))
386 if (!try_inc_mod_count(dev->ops->owner))
389 vcc_insert_socket(vcc->sk);
390 switch (vcc->qos.aal) {
392 error = atm_init_aal0(vcc);
393 vcc->stats = &dev->stats.aal0;
396 error = atm_init_aal34(vcc);
397 vcc->stats = &dev->stats.aal34;
400 /* ATM_AAL5 is also used in the "0 for default" case */
401 vcc->qos.aal = ATM_AAL5;
404 error = atm_init_aal5(vcc);
405 vcc->stats = &dev->stats.aal5;
410 if (!error) error = adjust_tp(&vcc->qos.txtp,vcc->qos.aal);
411 if (!error) error = adjust_tp(&vcc->qos.rxtp,vcc->qos.aal);
414 DPRINTK("VCC %d.%d, AAL %d\n",vpi,vci,vcc->qos.aal);
415 DPRINTK(" TX: %d, PCR %d..%d, SDU %d\n",vcc->qos.txtp.traffic_class,
416 vcc->qos.txtp.min_pcr,vcc->qos.txtp.max_pcr,vcc->qos.txtp.max_sdu);
417 DPRINTK(" RX: %d, PCR %d..%d, SDU %d\n",vcc->qos.rxtp.traffic_class,
418 vcc->qos.rxtp.min_pcr,vcc->qos.rxtp.max_pcr,vcc->qos.rxtp.max_sdu);
419 if (dev->ops->open) {
420 if ((error = dev->ops->open(vcc,vpi,vci)))
426 vcc_remove_socket(vcc->sk);
428 __MOD_DEC_USE_COUNT(dev->ops->owner);
429 /* ensure we get dev module ref count correct */
436 int vcc_connect(struct socket *sock, int itf, short vpi, int vci)
439 struct atm_vcc *vcc = ATM_SD(sock);
442 DPRINTK("vcc_connect (vpi %d, vci %d)\n",vpi,vci);
443 if (sock->state == SS_CONNECTED)
445 if (sock->state != SS_UNCONNECTED)
450 if (vpi != ATM_VPI_UNSPEC && vci != ATM_VCI_UNSPEC)
451 clear_bit(ATM_VF_PARTIAL,&vcc->flags);
453 if (test_bit(ATM_VF_PARTIAL,&vcc->flags))
455 DPRINTK("vcc_connect (TX: cl %d,bw %d-%d,sdu %d; "
456 "RX: cl %d,bw %d-%d,sdu %d,AAL %s%d)\n",
457 vcc->qos.txtp.traffic_class,vcc->qos.txtp.min_pcr,
458 vcc->qos.txtp.max_pcr,vcc->qos.txtp.max_sdu,
459 vcc->qos.rxtp.traffic_class,vcc->qos.rxtp.min_pcr,
460 vcc->qos.rxtp.max_pcr,vcc->qos.rxtp.max_sdu,
461 vcc->qos.aal == ATM_AAL5 ? "" : vcc->qos.aal == ATM_AAL0 ? "" :
462 " ??? code ",vcc->qos.aal == ATM_AAL0 ? 0 : vcc->qos.aal);
463 if (!test_bit(ATM_VF_HASQOS, &vcc->flags))
465 if (vcc->qos.txtp.traffic_class == ATM_ANYCLASS ||
466 vcc->qos.rxtp.traffic_class == ATM_ANYCLASS)
468 if (itf != ATM_ITF_ANY) {
469 dev = atm_dev_lookup(itf);
472 error = __vcc_connect(vcc, dev, vpi, vci);
478 struct list_head *p, *next;
481 spin_lock(&atm_dev_lock);
482 list_for_each_safe(p, next, &atm_devs) {
483 dev = list_entry(p, struct atm_dev, dev_list);
485 spin_unlock(&atm_dev_lock);
486 if (!__vcc_connect(vcc, dev, vpi, vci))
490 spin_lock(&atm_dev_lock);
492 spin_unlock(&atm_dev_lock);
496 if (vpi == ATM_VPI_UNSPEC || vci == ATM_VCI_UNSPEC)
497 set_bit(ATM_VF_PARTIAL,&vcc->flags);
498 if (test_bit(ATM_VF_READY,&ATM_SD(sock)->flags))
499 sock->state = SS_CONNECTED;
504 int vcc_recvmsg(struct socket *sock, struct msghdr *msg,
505 int size, int flags, struct scm_cookie *scm)
507 struct sock *sk = sock->sk;
510 int copied, error = -EINVAL;
512 if (sock->state != SS_CONNECTED)
514 if (flags & ~MSG_DONTWAIT) /* only handle MSG_DONTWAIT */
517 if (test_bit(ATM_VF_RELEASED,&vcc->flags) ||
518 test_bit(ATM_VF_CLOSE, &vcc->flags) ||
519 !test_bit(ATM_VF_READY, &vcc->flags))
522 skb = skb_recv_datagram(sk, flags, flags & MSG_DONTWAIT, &error);
529 msg->msg_flags |= MSG_TRUNC;
532 error = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
535 sock_recv_timestamp(msg, sk, skb);
536 if (vcc->dev->ops->feedback)
537 vcc->dev->ops->feedback(vcc, skb, (unsigned long) skb->data,
538 (unsigned long) msg->msg_iov->iov_base, copied);
539 DPRINTK("RcvM %d -= %d\n", atomic_read(&vcc->sk->rmem_alloc), skb->truesize);
540 atm_return(vcc, skb->truesize);
541 skb_free_datagram(sk, skb);
547 int vcc_sendmsg(struct socket *sock, struct msghdr *m, int total_len,
548 struct scm_cookie *scm)
550 struct sock *sk = sock->sk;
551 DECLARE_WAITQUEUE(wait,current);
559 if (sock->state != SS_CONNECTED) {
567 if (m->msg_iovlen != 1) {
568 error = -ENOSYS; /* fix this later @@@ */
571 buff = m->msg_iov->iov_base;
572 size = m->msg_iov->iov_len;
574 if (test_bit(ATM_VF_RELEASED, &vcc->flags) ||
575 test_bit(ATM_VF_CLOSE, &vcc->flags) ||
576 !test_bit(ATM_VF_READY, &vcc->flags)) {
578 send_sig(SIGPIPE, current, 0);
585 if (size < 0 || size > vcc->qos.txtp.max_sdu) {
589 /* verify_area is done by net/socket.c */
590 eff = (size+3) & ~3; /* align to word boundary */
591 add_wait_queue(&vcc->sleep,&wait);
592 set_current_state(TASK_INTERRUPTIBLE);
594 while (!(skb = alloc_tx(vcc,eff))) {
595 if (m->msg_flags & MSG_DONTWAIT) {
600 set_current_state(TASK_INTERRUPTIBLE);
601 if (signal_pending(current)) {
602 error = -ERESTARTSYS;
605 if (test_bit(ATM_VF_RELEASED,&vcc->flags) ||
606 test_bit(ATM_VF_CLOSE, &vcc->flags) ||
607 !test_bit(ATM_VF_READY, &vcc->flags)) {
609 send_sig(SIGPIPE, current, 0);
613 set_current_state(TASK_RUNNING);
614 remove_wait_queue(&vcc->sleep,&wait);
617 skb->dev = NULL; /* for paths shared with net_device interfaces */
618 ATM_SKB(skb)->atm_options = vcc->atm_options;
619 if (copy_from_user(skb_put(skb,size),buff,size)) {
624 if (eff != size) memset(skb->data+size,0,eff-size);
625 error = vcc->dev->ops->send(vcc,skb);
626 error = error ? error : size;
633 unsigned int atm_poll(struct file *file,struct socket *sock,poll_table *wait)
639 poll_wait(file,&vcc->sleep,wait);
641 if (skb_peek(&vcc->sk->receive_queue))
642 mask |= POLLIN | POLLRDNORM;
643 if (test_bit(ATM_VF_RELEASED,&vcc->flags) ||
644 test_bit(ATM_VF_CLOSE,&vcc->flags))
646 if (sock->state != SS_CONNECTING) {
647 if (vcc->qos.txtp.traffic_class != ATM_NONE &&
648 vcc->qos.txtp.max_sdu+atomic_read(&vcc->sk->wmem_alloc) <= vcc->sk->sndbuf)
649 mask |= POLLOUT | POLLWRNORM;
651 else if (vcc->reply != WAITING) {
652 mask |= POLLOUT | POLLWRNORM;
653 if (vcc->reply) mask |= POLLERR;
659 int vcc_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
667 if (sock->state != SS_CONNECTED ||
668 !test_bit(ATM_VF_READY, &vcc->flags)) {
672 error = put_user(vcc->sk->sndbuf-
673 atomic_read(&vcc->sk->wmem_alloc),
674 (int *) arg) ? -EFAULT : 0;
680 if (sock->state != SS_CONNECTED) {
684 skb = skb_peek(&vcc->sk->receive_queue);
685 error = put_user(skb ? skb->len : 0,
686 (int *) arg) ? -EFAULT : 0;
689 case SIOCGSTAMP: /* borrowed from IP */
690 if (!vcc->sk->stamp.tv_sec) {
694 error = copy_to_user((void *) arg, &vcc->sk->stamp,
695 sizeof(struct timeval)) ? -EFAULT : 0;
698 printk(KERN_WARNING "ATM_SETSC is obsolete\n");
702 if (!capable(CAP_NET_ADMIN)) {
707 * The user/kernel protocol for exchanging signalling
708 * info uses kernel pointers as opaque references,
709 * so the holder of the file descriptor can scribble
710 * on the kernel... so we should make sure that we
711 * have the same privledges that /proc/kcore needs
713 if (!capable(CAP_SYS_RAWIO)) {
717 error = sigd_attach(vcc);
719 sock->state = SS_CONNECTED;
721 #if defined(CONFIG_ATM_CLIP) || defined(CONFIG_ATM_CLIP_MODULE)
723 if (!capable(CAP_NET_ADMIN)) {
727 if (try_atm_clip_ops()) {
728 error = atm_clip_ops->clip_create(arg);
729 if (atm_clip_ops->owner)
730 __MOD_DEC_USE_COUNT(atm_clip_ops->owner);
735 if (!capable(CAP_NET_ADMIN)) {
739 #if defined(CONFIG_ATM_CLIP_MODULE)
741 request_module("clip");
743 if (try_atm_clip_ops()) {
744 error = atm_clip_ops->atm_init_atmarp(vcc);
745 if (atm_clip_ops->owner)
746 __MOD_DEC_USE_COUNT(atm_clip_ops->owner);
748 sock->state = SS_CONNECTED;
753 if (!capable(CAP_NET_ADMIN)) {
757 if (try_atm_clip_ops()) {
758 error = atm_clip_ops->clip_mkip(vcc, arg);
759 if (atm_clip_ops->owner)
760 __MOD_DEC_USE_COUNT(atm_clip_ops->owner);
764 case ATMARP_SETENTRY:
765 if (!capable(CAP_NET_ADMIN)) {
769 if (try_atm_clip_ops()) {
770 error = atm_clip_ops->clip_setentry(vcc, arg);
771 if (atm_clip_ops->owner)
772 __MOD_DEC_USE_COUNT(atm_clip_ops->owner);
777 if (!capable(CAP_NET_ADMIN)) {
781 if (try_atm_clip_ops()) {
782 error = atm_clip_ops->clip_encap(vcc, arg);
783 if (atm_clip_ops->owner)
784 __MOD_DEC_USE_COUNT(atm_clip_ops->owner);
789 #if defined(CONFIG_ATM_LANE) || defined(CONFIG_ATM_LANE_MODULE)
791 if (!capable(CAP_NET_ADMIN)) {
795 #if defined(CONFIG_ATM_LANE_MODULE)
797 request_module("lec");
799 if (try_atm_lane_ops()) {
800 error = atm_lane_ops->lecd_attach(vcc, (int) arg);
801 if (atm_lane_ops->owner)
802 __MOD_DEC_USE_COUNT(atm_lane_ops->owner);
804 sock->state = SS_CONNECTED;
809 if (!capable(CAP_NET_ADMIN)) {
813 if (try_atm_lane_ops()) {
814 error = atm_lane_ops->mcast_attach(vcc, (int) arg);
815 if (atm_lane_ops->owner)
816 __MOD_DEC_USE_COUNT(atm_lane_ops->owner);
821 if (!capable(CAP_NET_ADMIN)) {
825 if (try_atm_lane_ops()) {
826 error = atm_lane_ops->vcc_attach(vcc, (void *) arg);
827 if (atm_lane_ops->owner)
828 __MOD_DEC_USE_COUNT(atm_lane_ops->owner);
833 #if defined(CONFIG_ATM_MPOA) || defined(CONFIG_ATM_MPOA_MODULE)
835 if (!capable(CAP_NET_ADMIN)) {
839 #if defined(CONFIG_ATM_MPOA_MODULE)
841 request_module("mpoa");
843 if (try_atm_mpoa_ops()) {
844 error = atm_mpoa_ops->mpoad_attach(vcc, (int) arg);
845 if (atm_mpoa_ops->owner)
846 __MOD_DEC_USE_COUNT(atm_mpoa_ops->owner);
848 sock->state = SS_CONNECTED;
853 if (!capable(CAP_NET_ADMIN)) {
857 if (try_atm_mpoa_ops()) {
858 error = atm_mpoa_ops->vcc_attach(vcc, arg);
859 if (atm_mpoa_ops->owner)
860 __MOD_DEC_USE_COUNT(atm_mpoa_ops->owner);
865 #if defined(CONFIG_ATM_TCP) || defined(CONFIG_ATM_TCP_MODULE)
867 if (!capable(CAP_NET_ADMIN)) {
871 if (!atm_tcp_ops.attach) {
875 fops_get(&atm_tcp_ops);
876 error = atm_tcp_ops.attach(vcc, (int) arg);
878 sock->state = SS_CONNECTED;
880 fops_put(&atm_tcp_ops);
883 if (!capable(CAP_NET_ADMIN)) {
887 if (!atm_tcp_ops.create_persistent) {
891 error = atm_tcp_ops.create_persistent((int) arg);
893 fops_put(&atm_tcp_ops);
896 if (!capable(CAP_NET_ADMIN)) {
900 if (!atm_tcp_ops.remove_persistent) {
904 error = atm_tcp_ops.remove_persistent((int) arg);
905 fops_put(&atm_tcp_ops);
911 error = -ENOIOCTLCMD;
912 #if defined(CONFIG_PPPOATM) || defined(CONFIG_PPPOATM_MODULE)
913 down(&pppoatm_ioctl_mutex);
914 if (pppoatm_ioctl_hook)
915 error = pppoatm_ioctl_hook(vcc, cmd, arg);
916 up(&pppoatm_ioctl_mutex);
917 if (error != -ENOIOCTLCMD)
920 #if defined(CONFIG_ATM_BR2684) || defined(CONFIG_ATM_BR2684_MODULE)
921 down(&br2684_ioctl_mutex);
922 if (br2684_ioctl_hook)
923 error = br2684_ioctl_hook(vcc, cmd, arg);
924 up(&br2684_ioctl_mutex);
925 if (error != -ENOIOCTLCMD)
929 error = atm_dev_ioctl(cmd, arg);
936 static int atm_change_qos(struct atm_vcc *vcc,struct atm_qos *qos)
941 * Don't let the QoS change the already connected AAL type nor the
944 if (qos->aal != vcc->qos.aal ||
945 qos->rxtp.traffic_class != vcc->qos.rxtp.traffic_class ||
946 qos->txtp.traffic_class != vcc->qos.txtp.traffic_class)
948 error = adjust_tp(&qos->txtp,qos->aal);
949 if (!error) error = adjust_tp(&qos->rxtp,qos->aal);
950 if (error) return error;
951 if (!vcc->dev->ops->change_qos) return -EOPNOTSUPP;
952 if (vcc->sk->family == AF_ATMPVC)
953 return vcc->dev->ops->change_qos(vcc,qos,ATM_MF_SET);
954 return svc_change_qos(vcc,qos);
958 static int check_tp(struct atm_trafprm *tp)
960 /* @@@ Should be merged with adjust_tp */
961 if (!tp->traffic_class || tp->traffic_class == ATM_ANYCLASS) return 0;
962 if (tp->traffic_class != ATM_UBR && !tp->min_pcr && !tp->pcr &&
963 !tp->max_pcr) return -EINVAL;
964 if (tp->min_pcr == ATM_MAX_PCR) return -EINVAL;
965 if (tp->min_pcr && tp->max_pcr && tp->max_pcr != ATM_MAX_PCR &&
966 tp->min_pcr > tp->max_pcr) return -EINVAL;
968 * We allow pcr to be outside [min_pcr,max_pcr], because later
969 * adjustment may still push it in the valid range.
975 static int check_qos(struct atm_qos *qos)
979 if (!qos->txtp.traffic_class && !qos->rxtp.traffic_class)
981 if (qos->txtp.traffic_class != qos->rxtp.traffic_class &&
982 qos->txtp.traffic_class && qos->rxtp.traffic_class &&
983 qos->txtp.traffic_class != ATM_ANYCLASS &&
984 qos->rxtp.traffic_class != ATM_ANYCLASS) return -EINVAL;
985 error = check_tp(&qos->txtp);
986 if (error) return error;
987 return check_tp(&qos->rxtp);
990 int vcc_setsockopt(struct socket *sock, int level, int optname,
991 char *optval, int optlen)
997 if (__SO_LEVEL_MATCH(optname, level) && optlen != __SO_SIZE(optname))
1006 if (copy_from_user(&qos,optval,sizeof(qos)))
1008 error = check_qos(&qos);
1009 if (error) return error;
1010 if (sock->state == SS_CONNECTED)
1011 return atm_change_qos(vcc,&qos);
1012 if (sock->state != SS_UNCONNECTED)
1015 set_bit(ATM_VF_HASQOS,&vcc->flags);
1019 if (get_user(value,(unsigned long *) optval))
1021 if (value) vcc->atm_options |= ATM_ATMOPT_CLP;
1022 else vcc->atm_options &= ~ATM_ATMOPT_CLP;
1025 if (level == SOL_SOCKET) return -EINVAL;
1028 if (!vcc->dev || !vcc->dev->ops->setsockopt) return -EINVAL;
1029 return vcc->dev->ops->setsockopt(vcc,level,optname,optval,optlen);
1033 int vcc_getsockopt(struct socket *sock, int level, int optname,
1034 char *optval, int *optlen)
1036 struct atm_vcc *vcc;
1039 if (get_user(len, optlen))
1041 if (__SO_LEVEL_MATCH(optname, level) && len != __SO_SIZE(optname))
1047 if (!test_bit(ATM_VF_HASQOS,&vcc->flags))
1049 return copy_to_user(optval,&vcc->qos,sizeof(vcc->qos)) ?
1052 return put_user(vcc->atm_options & ATM_ATMOPT_CLP ? 1 :
1053 0,(unsigned long *) optval) ? -EFAULT : 0;
1056 struct sockaddr_atmpvc pvc;
1059 !test_bit(ATM_VF_ADDR,&vcc->flags))
1061 pvc.sap_family = AF_ATMPVC;
1062 pvc.sap_addr.itf = vcc->dev->number;
1063 pvc.sap_addr.vpi = vcc->vpi;
1064 pvc.sap_addr.vci = vcc->vci;
1065 return copy_to_user(optval,&pvc,sizeof(pvc)) ?
1069 if (level == SOL_SOCKET) return -EINVAL;
1072 if (!vcc->dev || !vcc->dev->ops->getsockopt) return -EINVAL;
1073 return vcc->dev->ops->getsockopt(vcc, level, optname, optval, len);
1077 #if defined(CONFIG_ATM_LANE) || defined(CONFIG_ATM_LANE_MODULE)
1078 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
1079 struct net_bridge_fdb_entry *(*br_fdb_get_hook)(struct net_bridge *br,
1080 unsigned char *addr) = NULL;
1081 void (*br_fdb_put_hook)(struct net_bridge_fdb_entry *ent) = NULL;
1082 #if defined(CONFIG_ATM_LANE_MODULE) || defined(CONFIG_BRIDGE_MODULE)
1083 EXPORT_SYMBOL(br_fdb_get_hook);
1084 EXPORT_SYMBOL(br_fdb_put_hook);
1085 #endif /* defined(CONFIG_ATM_LANE_MODULE) || defined(CONFIG_BRIDGE_MODULE) */
1086 #endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
1087 #endif /* defined(CONFIG_ATM_LANE) || defined(CONFIG_ATM_LANE_MODULE) */
1090 static int __init atm_init(void)
1094 if ((error = atmpvc_init()) < 0) {
1095 printk(KERN_ERR "atmpvc_init() failed with %d\n", error);
1098 if ((error = atmsvc_init()) < 0) {
1099 printk(KERN_ERR "atmsvc_init() failed with %d\n", error);
1102 #ifdef CONFIG_PROC_FS
1103 if ((error = atm_proc_init()) < 0) {
1104 printk(KERN_ERR "atm_proc_init() failed with %d\n",error);
1116 static void __exit atm_exit(void)
1118 #ifdef CONFIG_PROC_FS
1125 module_init(atm_init);
1126 module_exit(atm_exit);
1128 MODULE_LICENSE("GPL");