blob: e1140b3bdcaa1984694b5b753732f4cb20cd1a6e [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/* net/atm/pvc.c - ATM PVC sockets */
3
4/* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */
5
6
Linus Torvalds1da177e2005-04-16 15:20:36 -07007#include <linux/net.h> /* struct socket, struct proto_ops */
8#include <linux/atm.h> /* ATM stuff */
9#include <linux/atmdev.h> /* ATM devices */
10#include <linux/errno.h> /* error codes */
11#include <linux/kernel.h> /* printk */
12#include <linux/init.h>
13#include <linux/skbuff.h>
14#include <linux/bitops.h>
Paul Gortmakerbc3b2d72011-07-15 11:47:34 -040015#include <linux/export.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <net/sock.h> /* for sock_no_* */
17
18#include "resources.h" /* devs and vccs */
19#include "common.h" /* common for PVCs and SVCs */
20
21
Joe Perches6b6dd492010-01-26 11:40:14 +000022static int pvc_shutdown(struct socket *sock, int how)
Linus Torvalds1da177e2005-04-16 15:20:36 -070023{
24 return 0;
25}
26
Joe Perches6b6dd492010-01-26 11:40:14 +000027static int pvc_bind(struct socket *sock, struct sockaddr *sockaddr,
28 int sockaddr_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -070029{
30 struct sock *sk = sock->sk;
31 struct sockaddr_atmpvc *addr;
32 struct atm_vcc *vcc;
33 int error;
34
Joe Perches6b6dd492010-01-26 11:40:14 +000035 if (sockaddr_len != sizeof(struct sockaddr_atmpvc))
36 return -EINVAL;
37 addr = (struct sockaddr_atmpvc *)sockaddr;
38 if (addr->sap_family != AF_ATMPVC)
39 return -EAFNOSUPPORT;
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 lock_sock(sk);
41 vcc = ATM_SD(sock);
42 if (!test_bit(ATM_VF_HASQOS, &vcc->flags)) {
43 error = -EBADFD;
44 goto out;
45 }
Joe Perches6b6dd492010-01-26 11:40:14 +000046 if (test_bit(ATM_VF_PARTIAL, &vcc->flags)) {
47 if (vcc->vpi != ATM_VPI_UNSPEC)
48 addr->sap_addr.vpi = vcc->vpi;
49 if (vcc->vci != ATM_VCI_UNSPEC)
50 addr->sap_addr.vci = vcc->vci;
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 }
52 error = vcc_connect(sock, addr->sap_addr.itf, addr->sap_addr.vpi,
53 addr->sap_addr.vci);
54out:
55 release_sock(sk);
56 return error;
57}
58
Joe Perches6b6dd492010-01-26 11:40:14 +000059static int pvc_connect(struct socket *sock, struct sockaddr *sockaddr,
60 int sockaddr_len, int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -070061{
Joe Perches6b6dd492010-01-26 11:40:14 +000062 return pvc_bind(sock, sockaddr, sockaddr_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063}
64
65static int pvc_setsockopt(struct socket *sock, int level, int optname,
David S. Millerb7058842009-09-30 16:12:20 -070066 char __user *optval, unsigned int optlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -070067{
68 struct sock *sk = sock->sk;
69 int error;
70
71 lock_sock(sk);
72 error = vcc_setsockopt(sock, level, optname, optval, optlen);
73 release_sock(sk);
74 return error;
75}
76
Linus Torvalds1da177e2005-04-16 15:20:36 -070077static int pvc_getsockopt(struct socket *sock, int level, int optname,
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +090078 char __user *optval, int __user *optlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -070079{
80 struct sock *sk = sock->sk;
81 int error;
82
83 lock_sock(sk);
84 error = vcc_getsockopt(sock, level, optname, optval, optlen);
85 release_sock(sk);
86 return error;
87}
88
Joe Perches6b6dd492010-01-26 11:40:14 +000089static int pvc_getname(struct socket *sock, struct sockaddr *sockaddr,
90 int *sockaddr_len, int peer)
Linus Torvalds1da177e2005-04-16 15:20:36 -070091{
92 struct sockaddr_atmpvc *addr;
93 struct atm_vcc *vcc = ATM_SD(sock);
94
Joe Perches6b6dd492010-01-26 11:40:14 +000095 if (!vcc->dev || !test_bit(ATM_VF_ADDR, &vcc->flags))
96 return -ENOTCONN;
YOSHIFUJI Hideakif7d57452007-02-09 23:24:29 +090097 *sockaddr_len = sizeof(struct sockaddr_atmpvc);
Joe Perches6b6dd492010-01-26 11:40:14 +000098 addr = (struct sockaddr_atmpvc *)sockaddr;
Mathias Krause3c0c5cf2012-08-15 11:31:45 +000099 memset(addr, 0, sizeof(*addr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 addr->sap_family = AF_ATMPVC;
101 addr->sap_addr.itf = vcc->dev->number;
102 addr->sap_addr.vpi = vcc->vpi;
103 addr->sap_addr.vci = vcc->vci;
104 return 0;
105}
106
Eric Dumazet90ddc4f2005-12-22 12:49:22 -0800107static const struct proto_ops pvc_proto_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 .family = PF_ATMPVC,
109 .owner = THIS_MODULE,
110
111 .release = vcc_release,
112 .bind = pvc_bind,
113 .connect = pvc_connect,
114 .socketpair = sock_no_socketpair,
115 .accept = sock_no_accept,
116 .getname = pvc_getname,
117 .poll = vcc_poll,
118 .ioctl = vcc_ioctl,
David Woodhouse8865c412008-12-03 22:12:38 -0800119#ifdef CONFIG_COMPAT
120 .compat_ioctl = vcc_compat_ioctl,
121#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 .listen = sock_no_listen,
123 .shutdown = pvc_shutdown,
124 .setsockopt = pvc_setsockopt,
125 .getsockopt = pvc_getsockopt,
126 .sendmsg = vcc_sendmsg,
127 .recvmsg = vcc_recvmsg,
128 .mmap = sock_no_mmap,
129 .sendpage = sock_no_sendpage,
130};
131
132
Eric Paris3f378b62009-11-05 22:18:14 -0800133static int pvc_create(struct net *net, struct socket *sock, int protocol,
134 int kern)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135{
Eric W. Biederman1b8d7ae2007-10-08 23:24:22 -0700136 if (net != &init_net)
137 return -EAFNOSUPPORT;
138
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 sock->ops = &pvc_proto_ops;
Eric W. Biederman11aa9c22015-05-08 21:09:13 -0500140 return vcc_create(net, sock, protocol, PF_ATMPVC, kern);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141}
142
Stephen Hemmingerec1b4cf2009-10-05 05:58:39 +0000143static const struct net_proto_family pvc_family_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 .family = PF_ATMPVC,
145 .create = pvc_create,
146 .owner = THIS_MODULE,
147};
148
149
150/*
151 * Initialize the ATM PVC protocol family
152 */
153
154
155int __init atmpvc_init(void)
156{
157 return sock_register(&pvc_family_ops);
158}
159
160void atmpvc_exit(void)
161{
162 sock_unregister(PF_ATMPVC);
163}