1 // SPDX-License-Identifier: GPL-2.0 << 2 /* net/atm/pvc.c - ATM PVC sockets */ 1 /* net/atm/pvc.c - ATM PVC sockets */ 3 2 4 /* Written 1995-2000 by Werner Almesberger, EP 3 /* Written 1995-2000 by Werner Almesberger, EPFL LRC/ICA */ 5 4 6 5 7 #include <linux/net.h> /* struct sock 6 #include <linux/net.h> /* struct socket, struct proto_ops */ 8 #include <linux/atm.h> /* ATM stuff * 7 #include <linux/atm.h> /* ATM stuff */ 9 #include <linux/atmdev.h> /* ATM devices 8 #include <linux/atmdev.h> /* ATM devices */ 10 #include <linux/errno.h> /* error codes 9 #include <linux/errno.h> /* error codes */ 11 #include <linux/kernel.h> /* printk */ 10 #include <linux/kernel.h> /* printk */ 12 #include <linux/init.h> 11 #include <linux/init.h> 13 #include <linux/skbuff.h> 12 #include <linux/skbuff.h> 14 #include <linux/bitops.h> 13 #include <linux/bitops.h> 15 #include <linux/export.h> 14 #include <linux/export.h> 16 #include <net/sock.h> /* for sock_no 15 #include <net/sock.h> /* for sock_no_* */ 17 16 18 #include "resources.h" /* devs and vc 17 #include "resources.h" /* devs and vccs */ 19 #include "common.h" /* common for 18 #include "common.h" /* common for PVCs and SVCs */ 20 19 21 20 22 static int pvc_shutdown(struct socket *sock, i 21 static int pvc_shutdown(struct socket *sock, int how) 23 { 22 { 24 return 0; 23 return 0; 25 } 24 } 26 25 27 static int pvc_bind(struct socket *sock, struc 26 static int pvc_bind(struct socket *sock, struct sockaddr *sockaddr, 28 int sockaddr_len) 27 int sockaddr_len) 29 { 28 { 30 struct sock *sk = sock->sk; 29 struct sock *sk = sock->sk; 31 struct sockaddr_atmpvc *addr; 30 struct sockaddr_atmpvc *addr; 32 struct atm_vcc *vcc; 31 struct atm_vcc *vcc; 33 int error; 32 int error; 34 33 35 if (sockaddr_len != sizeof(struct sock 34 if (sockaddr_len != sizeof(struct sockaddr_atmpvc)) 36 return -EINVAL; 35 return -EINVAL; 37 addr = (struct sockaddr_atmpvc *)socka 36 addr = (struct sockaddr_atmpvc *)sockaddr; 38 if (addr->sap_family != AF_ATMPVC) 37 if (addr->sap_family != AF_ATMPVC) 39 return -EAFNOSUPPORT; 38 return -EAFNOSUPPORT; 40 lock_sock(sk); 39 lock_sock(sk); 41 vcc = ATM_SD(sock); 40 vcc = ATM_SD(sock); 42 if (!test_bit(ATM_VF_HASQOS, &vcc->fla 41 if (!test_bit(ATM_VF_HASQOS, &vcc->flags)) { 43 error = -EBADFD; 42 error = -EBADFD; 44 goto out; 43 goto out; 45 } 44 } 46 if (test_bit(ATM_VF_PARTIAL, &vcc->fla 45 if (test_bit(ATM_VF_PARTIAL, &vcc->flags)) { 47 if (vcc->vpi != ATM_VPI_UNSPEC 46 if (vcc->vpi != ATM_VPI_UNSPEC) 48 addr->sap_addr.vpi = v 47 addr->sap_addr.vpi = vcc->vpi; 49 if (vcc->vci != ATM_VCI_UNSPEC 48 if (vcc->vci != ATM_VCI_UNSPEC) 50 addr->sap_addr.vci = v 49 addr->sap_addr.vci = vcc->vci; 51 } 50 } 52 error = vcc_connect(sock, addr->sap_ad 51 error = vcc_connect(sock, addr->sap_addr.itf, addr->sap_addr.vpi, 53 addr->sap_addr.vci 52 addr->sap_addr.vci); 54 out: 53 out: 55 release_sock(sk); 54 release_sock(sk); 56 return error; 55 return error; 57 } 56 } 58 57 59 static int pvc_connect(struct socket *sock, st 58 static int pvc_connect(struct socket *sock, struct sockaddr *sockaddr, 60 int sockaddr_len, int f 59 int sockaddr_len, int flags) 61 { 60 { 62 return pvc_bind(sock, sockaddr, sockad 61 return pvc_bind(sock, sockaddr, sockaddr_len); 63 } 62 } 64 63 65 static int pvc_setsockopt(struct socket *sock, 64 static int pvc_setsockopt(struct socket *sock, int level, int optname, 66 sockptr_t optval, un !! 65 char __user *optval, unsigned int optlen) 67 { 66 { 68 struct sock *sk = sock->sk; 67 struct sock *sk = sock->sk; 69 int error; 68 int error; 70 69 71 lock_sock(sk); 70 lock_sock(sk); 72 error = vcc_setsockopt(sock, level, op 71 error = vcc_setsockopt(sock, level, optname, optval, optlen); 73 release_sock(sk); 72 release_sock(sk); 74 return error; 73 return error; 75 } 74 } 76 75 77 static int pvc_getsockopt(struct socket *sock, 76 static int pvc_getsockopt(struct socket *sock, int level, int optname, 78 char __user *optval, 77 char __user *optval, int __user *optlen) 79 { 78 { 80 struct sock *sk = sock->sk; 79 struct sock *sk = sock->sk; 81 int error; 80 int error; 82 81 83 lock_sock(sk); 82 lock_sock(sk); 84 error = vcc_getsockopt(sock, level, op 83 error = vcc_getsockopt(sock, level, optname, optval, optlen); 85 release_sock(sk); 84 release_sock(sk); 86 return error; 85 return error; 87 } 86 } 88 87 89 static int pvc_getname(struct socket *sock, st 88 static int pvc_getname(struct socket *sock, struct sockaddr *sockaddr, 90 int peer) !! 89 int *sockaddr_len, int peer) 91 { 90 { 92 struct sockaddr_atmpvc *addr; 91 struct sockaddr_atmpvc *addr; 93 struct atm_vcc *vcc = ATM_SD(sock); 92 struct atm_vcc *vcc = ATM_SD(sock); 94 93 95 if (!vcc->dev || !test_bit(ATM_VF_ADDR 94 if (!vcc->dev || !test_bit(ATM_VF_ADDR, &vcc->flags)) 96 return -ENOTCONN; 95 return -ENOTCONN; >> 96 *sockaddr_len = sizeof(struct sockaddr_atmpvc); 97 addr = (struct sockaddr_atmpvc *)socka 97 addr = (struct sockaddr_atmpvc *)sockaddr; 98 memset(addr, 0, sizeof(*addr)); 98 memset(addr, 0, sizeof(*addr)); 99 addr->sap_family = AF_ATMPVC; 99 addr->sap_family = AF_ATMPVC; 100 addr->sap_addr.itf = vcc->dev->number; 100 addr->sap_addr.itf = vcc->dev->number; 101 addr->sap_addr.vpi = vcc->vpi; 101 addr->sap_addr.vpi = vcc->vpi; 102 addr->sap_addr.vci = vcc->vci; 102 addr->sap_addr.vci = vcc->vci; 103 return sizeof(struct sockaddr_atmpvc); !! 103 return 0; 104 } 104 } 105 105 106 static const struct proto_ops pvc_proto_ops = 106 static const struct proto_ops pvc_proto_ops = { 107 .family = PF_ATMPVC, 107 .family = PF_ATMPVC, 108 .owner = THIS_MODULE, 108 .owner = THIS_MODULE, 109 109 110 .release = vcc_release, 110 .release = vcc_release, 111 .bind = pvc_bind, 111 .bind = pvc_bind, 112 .connect = pvc_connect, 112 .connect = pvc_connect, 113 .socketpair = sock_no_socketpair, 113 .socketpair = sock_no_socketpair, 114 .accept = sock_no_accept, 114 .accept = sock_no_accept, 115 .getname = pvc_getname, 115 .getname = pvc_getname, 116 .poll = vcc_poll, 116 .poll = vcc_poll, 117 .ioctl = vcc_ioctl, 117 .ioctl = vcc_ioctl, 118 #ifdef CONFIG_COMPAT 118 #ifdef CONFIG_COMPAT 119 .compat_ioctl = vcc_compat_ioctl, 119 .compat_ioctl = vcc_compat_ioctl, 120 #endif 120 #endif 121 .gettstamp = sock_gettstamp, << 122 .listen = sock_no_listen, 121 .listen = sock_no_listen, 123 .shutdown = pvc_shutdown, 122 .shutdown = pvc_shutdown, 124 .setsockopt = pvc_setsockopt, 123 .setsockopt = pvc_setsockopt, 125 .getsockopt = pvc_getsockopt, 124 .getsockopt = pvc_getsockopt, 126 .sendmsg = vcc_sendmsg, 125 .sendmsg = vcc_sendmsg, 127 .recvmsg = vcc_recvmsg, 126 .recvmsg = vcc_recvmsg, 128 .mmap = sock_no_mmap, 127 .mmap = sock_no_mmap, >> 128 .sendpage = sock_no_sendpage, 129 }; 129 }; 130 130 131 131 132 static int pvc_create(struct net *net, struct 132 static int pvc_create(struct net *net, struct socket *sock, int protocol, 133 int kern) 133 int kern) 134 { 134 { 135 if (net != &init_net) 135 if (net != &init_net) 136 return -EAFNOSUPPORT; 136 return -EAFNOSUPPORT; 137 137 138 sock->ops = &pvc_proto_ops; 138 sock->ops = &pvc_proto_ops; 139 return vcc_create(net, sock, protocol, 139 return vcc_create(net, sock, protocol, PF_ATMPVC, kern); 140 } 140 } 141 141 142 static const struct net_proto_family pvc_famil 142 static const struct net_proto_family pvc_family_ops = { 143 .family = PF_ATMPVC, 143 .family = PF_ATMPVC, 144 .create = pvc_create, 144 .create = pvc_create, 145 .owner = THIS_MODULE, 145 .owner = THIS_MODULE, 146 }; 146 }; 147 147 148 148 149 /* 149 /* 150 * Initialize the ATM PVC protocol family 150 * Initialize the ATM PVC protocol family 151 */ 151 */ 152 152 153 153 154 int __init atmpvc_init(void) 154 int __init atmpvc_init(void) 155 { 155 { 156 return sock_register(&pvc_family_ops); 156 return sock_register(&pvc_family_ops); 157 } 157 } 158 158 159 void atmpvc_exit(void) 159 void atmpvc_exit(void) 160 { 160 { 161 sock_unregister(PF_ATMPVC); 161 sock_unregister(PF_ATMPVC); 162 } 162 } 163 163
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.