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