pvc.c 3.7 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13
/* net/atm/pvc.c - ATM PVC sockets */

/* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */


#include <linux/net.h>		/* struct socket, struct proto_ops */
#include <linux/atm.h>		/* ATM stuff */
#include <linux/atmdev.h>	/* ATM devices */
#include <linux/errno.h>	/* error codes */
#include <linux/kernel.h>	/* printk */
#include <linux/init.h>
#include <linux/skbuff.h>
#include <linux/bitops.h>
14
#include <linux/export.h>
L
Linus Torvalds 已提交
15 16 17 18 19 20
#include <net/sock.h>		/* for sock_no_* */

#include "resources.h"		/* devs and vccs */
#include "common.h"		/* common for PVCs and SVCs */


J
Joe Perches 已提交
21
static int pvc_shutdown(struct socket *sock, int how)
L
Linus Torvalds 已提交
22 23 24 25
{
	return 0;
}

J
Joe Perches 已提交
26 27
static int pvc_bind(struct socket *sock, struct sockaddr *sockaddr,
		    int sockaddr_len)
L
Linus Torvalds 已提交
28 29 30 31 32 33
{
	struct sock *sk = sock->sk;
	struct sockaddr_atmpvc *addr;
	struct atm_vcc *vcc;
	int error;

J
Joe Perches 已提交
34 35 36 37 38
	if (sockaddr_len != sizeof(struct sockaddr_atmpvc))
		return -EINVAL;
	addr = (struct sockaddr_atmpvc *)sockaddr;
	if (addr->sap_family != AF_ATMPVC)
		return -EAFNOSUPPORT;
L
Linus Torvalds 已提交
39 40 41 42 43 44
	lock_sock(sk);
	vcc = ATM_SD(sock);
	if (!test_bit(ATM_VF_HASQOS, &vcc->flags)) {
		error = -EBADFD;
		goto out;
	}
J
Joe Perches 已提交
45 46 47 48 49
	if (test_bit(ATM_VF_PARTIAL, &vcc->flags)) {
		if (vcc->vpi != ATM_VPI_UNSPEC)
			addr->sap_addr.vpi = vcc->vpi;
		if (vcc->vci != ATM_VCI_UNSPEC)
			addr->sap_addr.vci = vcc->vci;
L
Linus Torvalds 已提交
50 51 52 53 54 55 56 57
	}
	error = vcc_connect(sock, addr->sap_addr.itf, addr->sap_addr.vpi,
			    addr->sap_addr.vci);
out:
	release_sock(sk);
	return error;
}

J
Joe Perches 已提交
58 59
static int pvc_connect(struct socket *sock, struct sockaddr *sockaddr,
		       int sockaddr_len, int flags)
L
Linus Torvalds 已提交
60
{
J
Joe Perches 已提交
61
	return pvc_bind(sock, sockaddr, sockaddr_len);
L
Linus Torvalds 已提交
62 63 64
}

static int pvc_setsockopt(struct socket *sock, int level, int optname,
65
			  char __user *optval, unsigned int optlen)
L
Linus Torvalds 已提交
66 67 68 69 70 71 72 73 74 75 76
{
	struct sock *sk = sock->sk;
	int error;

	lock_sock(sk);
	error = vcc_setsockopt(sock, level, optname, optval, optlen);
	release_sock(sk);
	return error;
}

static int pvc_getsockopt(struct socket *sock, int level, int optname,
77
			  char __user *optval, int __user *optlen)
L
Linus Torvalds 已提交
78 79 80 81 82 83 84 85 86 87
{
	struct sock *sk = sock->sk;
	int error;

	lock_sock(sk);
	error = vcc_getsockopt(sock, level, optname, optval, optlen);
	release_sock(sk);
	return error;
}

J
Joe Perches 已提交
88 89
static int pvc_getname(struct socket *sock, struct sockaddr *sockaddr,
		       int *sockaddr_len, int peer)
L
Linus Torvalds 已提交
90 91 92 93
{
	struct sockaddr_atmpvc *addr;
	struct atm_vcc *vcc = ATM_SD(sock);

J
Joe Perches 已提交
94 95
	if (!vcc->dev || !test_bit(ATM_VF_ADDR, &vcc->flags))
		return -ENOTCONN;
96
	*sockaddr_len = sizeof(struct sockaddr_atmpvc);
J
Joe Perches 已提交
97
	addr = (struct sockaddr_atmpvc *)sockaddr;
L
Linus Torvalds 已提交
98 99 100 101 102 103 104
	addr->sap_family = AF_ATMPVC;
	addr->sap_addr.itf = vcc->dev->number;
	addr->sap_addr.vpi = vcc->vpi;
	addr->sap_addr.vci = vcc->vci;
	return 0;
}

105
static const struct proto_ops pvc_proto_ops = {
L
Linus Torvalds 已提交
106 107 108 109 110 111 112 113 114 115 116
	.family =	PF_ATMPVC,
	.owner =	THIS_MODULE,

	.release =	vcc_release,
	.bind =		pvc_bind,
	.connect =	pvc_connect,
	.socketpair =	sock_no_socketpair,
	.accept =	sock_no_accept,
	.getname =	pvc_getname,
	.poll =		vcc_poll,
	.ioctl =	vcc_ioctl,
D
David Woodhouse 已提交
117 118 119
#ifdef CONFIG_COMPAT
	.compat_ioctl = vcc_compat_ioctl,
#endif
L
Linus Torvalds 已提交
120 121 122 123 124 125 126 127 128 129 130
	.listen =	sock_no_listen,
	.shutdown =	pvc_shutdown,
	.setsockopt =	pvc_setsockopt,
	.getsockopt =	pvc_getsockopt,
	.sendmsg =	vcc_sendmsg,
	.recvmsg =	vcc_recvmsg,
	.mmap =		sock_no_mmap,
	.sendpage =	sock_no_sendpage,
};


131 132
static int pvc_create(struct net *net, struct socket *sock, int protocol,
		      int kern)
L
Linus Torvalds 已提交
133
{
134 135 136
	if (net != &init_net)
		return -EAFNOSUPPORT;

L
Linus Torvalds 已提交
137
	sock->ops = &pvc_proto_ops;
138
	return vcc_create(net, sock, protocol, PF_ATMPVC);
L
Linus Torvalds 已提交
139 140
}

141
static const struct net_proto_family pvc_family_ops = {
L
Linus Torvalds 已提交
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
	.family = PF_ATMPVC,
	.create = pvc_create,
	.owner = THIS_MODULE,
};


/*
 *	Initialize the ATM PVC protocol family
 */


int __init atmpvc_init(void)
{
	return sock_register(&pvc_family_ops);
}

void atmpvc_exit(void)
{
	sock_unregister(PF_ATMPVC);
}