Linux 3.0.62
[linux/fpc-iii.git] / net / atm / pvc.c
blobdb0dd47de61bbeaa1394a75056ee0992e315d41a
1 /* net/atm/pvc.c - ATM PVC sockets */
3 /* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */
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_* */
16 #include "resources.h" /* devs and vccs */
17 #include "common.h" /* common for PVCs and SVCs */
20 static int pvc_shutdown(struct socket *sock, int how)
22 return 0;
25 static int pvc_bind(struct socket *sock, struct sockaddr *sockaddr,
26 int sockaddr_len)
28 struct sock *sk = sock->sk;
29 struct sockaddr_atmpvc *addr;
30 struct atm_vcc *vcc;
31 int error;
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;
38 lock_sock(sk);
39 vcc = ATM_SD(sock);
40 if (!test_bit(ATM_VF_HASQOS, &vcc->flags)) {
41 error = -EBADFD;
42 goto out;
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;
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;
57 static int pvc_connect(struct socket *sock, struct sockaddr *sockaddr,
58 int sockaddr_len, int flags)
60 return pvc_bind(sock, sockaddr, sockaddr_len);
63 static int pvc_setsockopt(struct socket *sock, int level, int optname,
64 char __user *optval, unsigned int optlen)
66 struct sock *sk = sock->sk;
67 int error;
69 lock_sock(sk);
70 error = vcc_setsockopt(sock, level, optname, optval, optlen);
71 release_sock(sk);
72 return error;
75 static int pvc_getsockopt(struct socket *sock, int level, int optname,
76 char __user *optval, int __user *optlen)
78 struct sock *sk = sock->sk;
79 int error;
81 lock_sock(sk);
82 error = vcc_getsockopt(sock, level, optname, optval, optlen);
83 release_sock(sk);
84 return error;
87 static int pvc_getname(struct socket *sock, struct sockaddr *sockaddr,
88 int *sockaddr_len, int peer)
90 struct sockaddr_atmpvc *addr;
91 struct atm_vcc *vcc = ATM_SD(sock);
93 if (!vcc->dev || !test_bit(ATM_VF_ADDR, &vcc->flags))
94 return -ENOTCONN;
95 *sockaddr_len = sizeof(struct sockaddr_atmpvc);
96 addr = (struct sockaddr_atmpvc *)sockaddr;
97 memset(addr, 0, sizeof(*addr));
98 addr->sap_family = AF_ATMPVC;
99 addr->sap_addr.itf = vcc->dev->number;
100 addr->sap_addr.vpi = vcc->vpi;
101 addr->sap_addr.vci = vcc->vci;
102 return 0;
105 static const struct proto_ops pvc_proto_ops = {
106 .family = PF_ATMPVC,
107 .owner = THIS_MODULE,
109 .release = vcc_release,
110 .bind = pvc_bind,
111 .connect = pvc_connect,
112 .socketpair = sock_no_socketpair,
113 .accept = sock_no_accept,
114 .getname = pvc_getname,
115 .poll = vcc_poll,
116 .ioctl = vcc_ioctl,
117 #ifdef CONFIG_COMPAT
118 .compat_ioctl = vcc_compat_ioctl,
119 #endif
120 .listen = sock_no_listen,
121 .shutdown = pvc_shutdown,
122 .setsockopt = pvc_setsockopt,
123 .getsockopt = pvc_getsockopt,
124 .sendmsg = vcc_sendmsg,
125 .recvmsg = vcc_recvmsg,
126 .mmap = sock_no_mmap,
127 .sendpage = sock_no_sendpage,
131 static int pvc_create(struct net *net, struct socket *sock, int protocol,
132 int kern)
134 if (net != &init_net)
135 return -EAFNOSUPPORT;
137 sock->ops = &pvc_proto_ops;
138 return vcc_create(net, sock, protocol, PF_ATMPVC);
141 static const struct net_proto_family pvc_family_ops = {
142 .family = PF_ATMPVC,
143 .create = pvc_create,
144 .owner = THIS_MODULE,
149 * Initialize the ATM PVC protocol family
153 int __init atmpvc_init(void)
155 return sock_register(&pvc_family_ops);
158 void atmpvc_exit(void)
160 sock_unregister(PF_ATMPVC);