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
)
26 static int pvc_bind(struct socket
*sock
,struct sockaddr
*sockaddr
,
29 struct sock
*sk
= sock
->sk
;
30 struct sockaddr_atmpvc
*addr
;
34 if (sockaddr_len
!= sizeof(struct sockaddr_atmpvc
)) return -EINVAL
;
35 addr
= (struct sockaddr_atmpvc
*) sockaddr
;
36 if (addr
->sap_family
!= AF_ATMPVC
) return -EAFNOSUPPORT
;
39 if (!test_bit(ATM_VF_HASQOS
, &vcc
->flags
)) {
43 if (test_bit(ATM_VF_PARTIAL
,&vcc
->flags
)) {
44 if (vcc
->vpi
!= ATM_VPI_UNSPEC
) addr
->sap_addr
.vpi
= vcc
->vpi
;
45 if (vcc
->vci
!= ATM_VCI_UNSPEC
) addr
->sap_addr
.vci
= vcc
->vci
;
47 error
= vcc_connect(sock
, addr
->sap_addr
.itf
, addr
->sap_addr
.vpi
,
55 static int pvc_connect(struct socket
*sock
,struct sockaddr
*sockaddr
,
56 int sockaddr_len
,int flags
)
58 return pvc_bind(sock
,sockaddr
,sockaddr_len
);
61 static int pvc_setsockopt(struct socket
*sock
, int level
, int optname
,
62 char __user
*optval
, unsigned int optlen
)
64 struct sock
*sk
= sock
->sk
;
68 error
= vcc_setsockopt(sock
, level
, optname
, optval
, optlen
);
74 static int pvc_getsockopt(struct socket
*sock
, int level
, int optname
,
75 char __user
*optval
, int __user
*optlen
)
77 struct sock
*sk
= sock
->sk
;
81 error
= vcc_getsockopt(sock
, level
, optname
, optval
, optlen
);
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
)) return -ENOTCONN
;
94 *sockaddr_len
= sizeof(struct sockaddr_atmpvc
);
95 addr
= (struct sockaddr_atmpvc
*) sockaddr
;
96 addr
->sap_family
= AF_ATMPVC
;
97 addr
->sap_addr
.itf
= vcc
->dev
->number
;
98 addr
->sap_addr
.vpi
= vcc
->vpi
;
99 addr
->sap_addr
.vci
= vcc
->vci
;
104 static const struct proto_ops pvc_proto_ops
= {
106 .owner
= THIS_MODULE
,
108 .release
= vcc_release
,
110 .connect
= pvc_connect
,
111 .socketpair
= sock_no_socketpair
,
112 .accept
= sock_no_accept
,
113 .getname
= pvc_getname
,
117 .compat_ioctl
= vcc_compat_ioctl
,
119 .listen
= sock_no_listen
,
120 .shutdown
= pvc_shutdown
,
121 .setsockopt
= pvc_setsockopt
,
122 .getsockopt
= pvc_getsockopt
,
123 .sendmsg
= vcc_sendmsg
,
124 .recvmsg
= vcc_recvmsg
,
125 .mmap
= sock_no_mmap
,
126 .sendpage
= sock_no_sendpage
,
130 static int pvc_create(struct net
*net
, struct socket
*sock
,int protocol
)
132 if (net
!= &init_net
)
133 return -EAFNOSUPPORT
;
135 sock
->ops
= &pvc_proto_ops
;
136 return vcc_create(net
, sock
, protocol
, PF_ATMPVC
);
140 static struct net_proto_family pvc_family_ops
= {
142 .create
= pvc_create
,
143 .owner
= THIS_MODULE
,
148 * Initialize the ATM PVC protocol family
152 int __init
atmpvc_init(void)
154 return sock_register(&pvc_family_ops
);
157 void atmpvc_exit(void)
159 sock_unregister(PF_ATMPVC
);