1 /* net/atm/pvc.c - ATM PVC sockets */
2 
3 /* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */
4 
5 
6 #include <linux/config.h>
7 #include <linux/net.h>		/* struct socket, struct net_proto,
8 				   struct proto_ops */
9 #include <linux/atm.h>		/* ATM stuff */
10 #include <linux/atmdev.h>	/* ATM devices */
11 #include <linux/errno.h>	/* error codes */
12 #include <linux/kernel.h>	/* printk */
13 #include <linux/init.h>
14 #include <linux/skbuff.h>
15 #include <linux/bitops.h>
16 #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 
pvc_shutdown(struct socket * sock,int how)22 static int pvc_shutdown(struct socket *sock,int how)
23 {
24 	return 0;
25 }
26 
27 
pvc_bind(struct socket * sock,struct sockaddr * sockaddr,int sockaddr_len)28 static int pvc_bind(struct socket *sock,struct sockaddr *sockaddr,
29     int sockaddr_len)
30 {
31 	struct sock *sk = sock->sk;
32 	struct sockaddr_atmpvc *addr;
33 	struct atm_vcc *vcc;
34 	int error;
35 
36 	if (sockaddr_len != sizeof(struct sockaddr_atmpvc)) return -EINVAL;
37 	addr = (struct sockaddr_atmpvc *) sockaddr;
38 	if (addr->sap_family != AF_ATMPVC) return -EAFNOSUPPORT;
39 	lock_sock(sk);
40 	vcc = ATM_SD(sock);
41 	if (!test_bit(ATM_VF_HASQOS, &vcc->flags)) {
42 		error = -EBADFD;
43 		goto out;
44 	}
45 	if (test_bit(ATM_VF_PARTIAL,&vcc->flags)) {
46 		if (vcc->vpi != ATM_VPI_UNSPEC) addr->sap_addr.vpi = vcc->vpi;
47 		if (vcc->vci != ATM_VCI_UNSPEC) addr->sap_addr.vci = vcc->vci;
48 	}
49 	error = vcc_connect(sock, addr->sap_addr.itf, addr->sap_addr.vpi,
50 			   addr->sap_addr.vci);
51 out:
52 	release_sock(sk);
53 	return error;
54 }
55 
56 
pvc_connect(struct socket * sock,struct sockaddr * sockaddr,int sockaddr_len,int flags)57 static int pvc_connect(struct socket *sock,struct sockaddr *sockaddr,
58     int sockaddr_len,int flags)
59 {
60 	return pvc_bind(sock,sockaddr,sockaddr_len);
61 }
62 
pvc_setsockopt(struct socket * sock,int level,int optname,char * optval,int optlen)63 static int pvc_setsockopt(struct socket *sock, int level, int optname,
64 			  char *optval, int optlen)
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 
75 
pvc_getsockopt(struct socket * sock,int level,int optname,char * optval,int * optlen)76 static int pvc_getsockopt(struct socket *sock, int level, int optname,
77 		          char *optval, int *optlen)
78 {
79 	struct sock *sk = sock->sk;
80 	int error;
81 
82 	lock_sock(sk);
83 	error = vcc_getsockopt(sock, level, optname, optval, optlen);
84 	release_sock(sk);
85 	return error;
86 }
87 
88 
pvc_getname(struct socket * sock,struct sockaddr * sockaddr,int * sockaddr_len,int peer)89 static int pvc_getname(struct socket *sock,struct sockaddr *sockaddr,
90     int *sockaddr_len,int peer)
91 {
92 	struct sockaddr_atmpvc *addr;
93 	struct atm_vcc *vcc = ATM_SD(sock);
94 
95 	if (!vcc->dev || !test_bit(ATM_VF_ADDR,&vcc->flags)) return -ENOTCONN;
96         *sockaddr_len = sizeof(struct sockaddr_atmpvc);
97 	addr = (struct sockaddr_atmpvc *) sockaddr;
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;
103 }
104 
105 
106 static struct proto_ops pvc_proto_ops = {
107 	.family =	PF_ATMPVC,
108 
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 =		atm_poll,
116 	.ioctl =	vcc_ioctl,
117 	.listen =	sock_no_listen,
118 	.shutdown =	pvc_shutdown,
119 	.setsockopt =	pvc_setsockopt,
120 	.getsockopt =	pvc_getsockopt,
121 	.sendmsg =	vcc_sendmsg,
122 	.recvmsg =	vcc_recvmsg,
123 	.mmap =		sock_no_mmap,
124 	.sendpage =	sock_no_sendpage,
125 };
126 
127 
pvc_create(struct socket * sock,int protocol)128 static int pvc_create(struct socket *sock,int protocol)
129 {
130 	sock->ops = &pvc_proto_ops;
131 	return vcc_create(sock, protocol, PF_ATMPVC);
132 }
133 
134 
135 static struct net_proto_family pvc_family_ops = {
136 	PF_ATMPVC,
137 	pvc_create,
138 	0,			/* no authentication */
139 	0,			/* no encryption */
140 	0			/* no encrypt_net */
141 };
142 
143 
144 /*
145  *	Initialize the ATM PVC protocol family
146  */
147 
148 
atmpvc_init(void)149 int atmpvc_init(void)
150 {
151 	return sock_register(&pvc_family_ops);
152 }
153 
atmpvc_exit(void)154 void atmpvc_exit(void)
155 {
156 	sock_unregister(PF_ATMPVC);
157 }
158