Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* net/atm/pvc.c - ATM PVC sockets */ |
| 2 | |
| 3 | /* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */ |
| 4 | |
| 5 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | #include <linux/net.h> /* struct socket, struct proto_ops */ |
| 7 | #include <linux/atm.h> /* ATM stuff */ |
| 8 | #include <linux/atmdev.h> /* ATM devices */ |
| 9 | #include <linux/errno.h> /* error codes */ |
| 10 | #include <linux/kernel.h> /* printk */ |
| 11 | #include <linux/init.h> |
| 12 | #include <linux/skbuff.h> |
| 13 | #include <linux/bitops.h> |
| 14 | #include <net/sock.h> /* for sock_no_* */ |
| 15 | |
| 16 | #include "resources.h" /* devs and vccs */ |
| 17 | #include "common.h" /* common for PVCs and SVCs */ |
| 18 | |
| 19 | |
Joe Perches | 6b6dd49 | 2010-01-26 11:40:14 +0000 | [diff] [blame] | 20 | static int pvc_shutdown(struct socket *sock, int how) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | { |
| 22 | return 0; |
| 23 | } |
| 24 | |
Joe Perches | 6b6dd49 | 2010-01-26 11:40:14 +0000 | [diff] [blame] | 25 | static int pvc_bind(struct socket *sock, struct sockaddr *sockaddr, |
| 26 | int sockaddr_len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | { |
| 28 | struct sock *sk = sock->sk; |
| 29 | struct sockaddr_atmpvc *addr; |
| 30 | struct atm_vcc *vcc; |
| 31 | int error; |
| 32 | |
Joe Perches | 6b6dd49 | 2010-01-26 11:40:14 +0000 | [diff] [blame] | 33 | if (sockaddr_len != sizeof(struct sockaddr_atmpvc)) |
| 34 | return -EINVAL; |
| 35 | addr = (struct sockaddr_atmpvc *)sockaddr; |
| 36 | if (addr->sap_family != AF_ATMPVC) |
| 37 | return -EAFNOSUPPORT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | lock_sock(sk); |
| 39 | vcc = ATM_SD(sock); |
| 40 | if (!test_bit(ATM_VF_HASQOS, &vcc->flags)) { |
| 41 | error = -EBADFD; |
| 42 | goto out; |
| 43 | } |
Joe Perches | 6b6dd49 | 2010-01-26 11:40:14 +0000 | [diff] [blame] | 44 | if (test_bit(ATM_VF_PARTIAL, &vcc->flags)) { |
| 45 | if (vcc->vpi != ATM_VPI_UNSPEC) |
| 46 | addr->sap_addr.vpi = vcc->vpi; |
| 47 | if (vcc->vci != ATM_VCI_UNSPEC) |
| 48 | addr->sap_addr.vci = vcc->vci; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | } |
| 50 | error = vcc_connect(sock, addr->sap_addr.itf, addr->sap_addr.vpi, |
| 51 | addr->sap_addr.vci); |
| 52 | out: |
| 53 | release_sock(sk); |
| 54 | return error; |
| 55 | } |
| 56 | |
Joe Perches | 6b6dd49 | 2010-01-26 11:40:14 +0000 | [diff] [blame] | 57 | static int pvc_connect(struct socket *sock, struct sockaddr *sockaddr, |
| 58 | int sockaddr_len, int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | { |
Joe Perches | 6b6dd49 | 2010-01-26 11:40:14 +0000 | [diff] [blame] | 60 | return pvc_bind(sock, sockaddr, sockaddr_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | static int pvc_setsockopt(struct socket *sock, int level, int optname, |
David S. Miller | b705884 | 2009-09-30 16:12:20 -0700 | [diff] [blame] | 64 | char __user *optval, unsigned int optlen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | { |
| 66 | struct sock *sk = sock->sk; |
| 67 | int error; |
| 68 | |
| 69 | lock_sock(sk); |
| 70 | error = vcc_setsockopt(sock, level, optname, optval, optlen); |
| 71 | release_sock(sk); |
| 72 | return error; |
| 73 | } |
| 74 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | static int pvc_getsockopt(struct socket *sock, int level, int optname, |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 76 | char __user *optval, int __user *optlen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | { |
| 78 | struct sock *sk = sock->sk; |
| 79 | int error; |
| 80 | |
| 81 | lock_sock(sk); |
| 82 | error = vcc_getsockopt(sock, level, optname, optval, optlen); |
| 83 | release_sock(sk); |
| 84 | return error; |
| 85 | } |
| 86 | |
Joe Perches | 6b6dd49 | 2010-01-26 11:40:14 +0000 | [diff] [blame] | 87 | static int pvc_getname(struct socket *sock, struct sockaddr *sockaddr, |
| 88 | int *sockaddr_len, int peer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | { |
| 90 | struct sockaddr_atmpvc *addr; |
| 91 | struct atm_vcc *vcc = ATM_SD(sock); |
| 92 | |
Joe Perches | 6b6dd49 | 2010-01-26 11:40:14 +0000 | [diff] [blame] | 93 | if (!vcc->dev || !test_bit(ATM_VF_ADDR, &vcc->flags)) |
| 94 | return -ENOTCONN; |
YOSHIFUJI Hideaki | f7d5745 | 2007-02-09 23:24:29 +0900 | [diff] [blame] | 95 | *sockaddr_len = sizeof(struct sockaddr_atmpvc); |
Joe Perches | 6b6dd49 | 2010-01-26 11:40:14 +0000 | [diff] [blame] | 96 | addr = (struct sockaddr_atmpvc *)sockaddr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | addr->sap_family = AF_ATMPVC; |
| 98 | addr->sap_addr.itf = vcc->dev->number; |
| 99 | addr->sap_addr.vpi = vcc->vpi; |
| 100 | addr->sap_addr.vci = vcc->vci; |
| 101 | return 0; |
| 102 | } |
| 103 | |
Eric Dumazet | 90ddc4f | 2005-12-22 12:49:22 -0800 | [diff] [blame] | 104 | static const struct proto_ops pvc_proto_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | .family = PF_ATMPVC, |
| 106 | .owner = THIS_MODULE, |
| 107 | |
| 108 | .release = vcc_release, |
| 109 | .bind = pvc_bind, |
| 110 | .connect = pvc_connect, |
| 111 | .socketpair = sock_no_socketpair, |
| 112 | .accept = sock_no_accept, |
| 113 | .getname = pvc_getname, |
| 114 | .poll = vcc_poll, |
| 115 | .ioctl = vcc_ioctl, |
David Woodhouse | 8865c41 | 2008-12-03 22:12:38 -0800 | [diff] [blame] | 116 | #ifdef CONFIG_COMPAT |
| 117 | .compat_ioctl = vcc_compat_ioctl, |
| 118 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | .listen = sock_no_listen, |
| 120 | .shutdown = pvc_shutdown, |
| 121 | .setsockopt = pvc_setsockopt, |
| 122 | .getsockopt = pvc_getsockopt, |
| 123 | .sendmsg = vcc_sendmsg, |
| 124 | .recvmsg = vcc_recvmsg, |
| 125 | .mmap = sock_no_mmap, |
| 126 | .sendpage = sock_no_sendpage, |
| 127 | }; |
| 128 | |
| 129 | |
Eric Paris | 3f378b6 | 2009-11-05 22:18:14 -0800 | [diff] [blame] | 130 | static int pvc_create(struct net *net, struct socket *sock, int protocol, |
| 131 | int kern) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | { |
Eric W. Biederman | 1b8d7ae | 2007-10-08 23:24:22 -0700 | [diff] [blame] | 133 | if (net != &init_net) |
| 134 | return -EAFNOSUPPORT; |
| 135 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | sock->ops = &pvc_proto_ops; |
Eric W. Biederman | 1b8d7ae | 2007-10-08 23:24:22 -0700 | [diff] [blame] | 137 | return vcc_create(net, sock, protocol, PF_ATMPVC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | } |
| 139 | |
Stephen Hemminger | ec1b4cf | 2009-10-05 05:58:39 +0000 | [diff] [blame] | 140 | static const struct net_proto_family pvc_family_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | .family = PF_ATMPVC, |
| 142 | .create = pvc_create, |
| 143 | .owner = THIS_MODULE, |
| 144 | }; |
| 145 | |
| 146 | |
| 147 | /* |
| 148 | * Initialize the ATM PVC protocol family |
| 149 | */ |
| 150 | |
| 151 | |
| 152 | int __init atmpvc_init(void) |
| 153 | { |
| 154 | return sock_register(&pvc_family_ops); |
| 155 | } |
| 156 | |
| 157 | void atmpvc_exit(void) |
| 158 | { |
| 159 | sock_unregister(PF_ATMPVC); |
| 160 | } |