1 // SPDX-License-Identifier: GPL-2.0
2 /* net/atm/pvc.c - ATM PVC sockets */
4 /* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */
7 #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>
15 #include <linux/export.h>
16 #include <net/sock.h> /* for sock_no_* */
18 #include "resources.h" /* devs and vccs */
19 #include "common.h" /* common for PVCs and SVCs */
22 static int pvc_shutdown(struct socket *sock, int how)
27 static int pvc_bind(struct socket *sock, struct sockaddr *sockaddr,
30 struct sock *sk = sock->sk;
31 struct sockaddr_atmpvc *addr;
35 if (sockaddr_len != sizeof(struct sockaddr_atmpvc))
37 addr = (struct sockaddr_atmpvc *)sockaddr;
38 if (addr->sap_family != AF_ATMPVC)
42 if (!test_bit(ATM_VF_HASQOS, &vcc->flags)) {
46 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;
52 error = vcc_connect(sock, addr->sap_addr.itf, addr->sap_addr.vpi,
59 static int pvc_connect(struct socket *sock, struct sockaddr *sockaddr,
60 int sockaddr_len, int flags)
62 return pvc_bind(sock, sockaddr, sockaddr_len);
65 static int pvc_setsockopt(struct socket *sock, int level, int optname,
66 sockptr_t optval, unsigned int optlen)
68 struct sock *sk = sock->sk;
72 error = vcc_setsockopt(sock, level, optname, optval, optlen);
77 static int pvc_getsockopt(struct socket *sock, int level, int optname,
78 char __user *optval, int __user *optlen)
80 struct sock *sk = sock->sk;
84 error = vcc_getsockopt(sock, level, optname, optval, optlen);
89 static int pvc_getname(struct socket *sock, struct sockaddr *sockaddr,
92 struct sockaddr_atmpvc *addr;
93 struct atm_vcc *vcc = ATM_SD(sock);
95 if (!vcc->dev || !test_bit(ATM_VF_ADDR, &vcc->flags))
97 addr = (struct sockaddr_atmpvc *)sockaddr;
98 memset(addr, 0, sizeof(*addr));
99 addr->sap_family = AF_ATMPVC;
100 addr->sap_addr.itf = vcc->dev->number;
101 addr->sap_addr.vpi = vcc->vpi;
102 addr->sap_addr.vci = vcc->vci;
103 return sizeof(struct sockaddr_atmpvc);
106 static const struct proto_ops pvc_proto_ops = {
108 .owner = THIS_MODULE,
110 .release = vcc_release,
112 .connect = pvc_connect,
113 .socketpair = sock_no_socketpair,
114 .accept = sock_no_accept,
115 .getname = pvc_getname,
119 .compat_ioctl = vcc_compat_ioctl,
121 .gettstamp = sock_gettstamp,
122 .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,
133 static int pvc_create(struct net *net, struct socket *sock, int protocol,
136 if (net != &init_net)
137 return -EAFNOSUPPORT;
139 sock->ops = &pvc_proto_ops;
140 return vcc_create(net, sock, protocol, PF_ATMPVC, kern);
143 static const struct net_proto_family pvc_family_ops = {
145 .create = pvc_create,
146 .owner = THIS_MODULE,
151 * Initialize the ATM PVC protocol family
155 int __init atmpvc_init(void)
157 return sock_register(&pvc_family_ops);
160 void atmpvc_exit(void)
162 sock_unregister(PF_ATMPVC);