1/* 2 * Copyright (c) 1998 Mark Newton 3 * Copyright (c) 1996 Christos Zoulas. 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. All advertising materials mentioning features or use of this software 15 * must display the following acknowledgement: 16 * This product includes software developed by Christos Zoulas. 17 * 4. The name of the author may not be used to endorse or promote products 18 * derived from this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 *
| 1/* 2 * Copyright (c) 1998 Mark Newton 3 * Copyright (c) 1996 Christos Zoulas. 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. All advertising materials mentioning features or use of this software 15 * must display the following acknowledgement: 16 * This product includes software developed by Christos Zoulas. 17 * 4. The name of the author may not be used to endorse or promote products 18 * derived from this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 *
|
32 */ 33 34/* 35 * In SVR4 unix domain sockets are referenced sometimes 36 * (in putmsg(2) for example) as a [device, inode] pair instead of a pathname. 37 * Since there is no iname() routine in the kernel, and we need access to 38 * a mapping from inode to pathname, we keep our own table. This is a simple 39 * linked list that contains the pathname, the [device, inode] pair, the 40 * file corresponding to that socket and the process. When the 41 * socket gets closed we remove the item from the list. The list gets loaded 42 * every time a stat(2) call finds a socket. 43 */ 44 45#include <sys/param.h> 46#include <sys/systm.h> 47#include <sys/queue.h> 48#include <sys/file.h> 49#include <sys/socket.h> 50#include <sys/socketvar.h> 51#include <sys/sysproto.h> 52#include <sys/un.h> 53#include <sys/stat.h> 54#include <sys/proc.h> 55#include <sys/malloc.h> 56 57#include <compat/svr4/svr4.h> 58#include <compat/svr4/svr4_types.h> 59#include <compat/svr4/svr4_util.h> 60#include <compat/svr4/svr4_socket.h> 61#include <compat/svr4/svr4_signal.h> 62#include <compat/svr4/svr4_sockmod.h> 63#include <compat/svr4/svr4_proto.h> 64
| 32 */ 33 34/* 35 * In SVR4 unix domain sockets are referenced sometimes 36 * (in putmsg(2) for example) as a [device, inode] pair instead of a pathname. 37 * Since there is no iname() routine in the kernel, and we need access to 38 * a mapping from inode to pathname, we keep our own table. This is a simple 39 * linked list that contains the pathname, the [device, inode] pair, the 40 * file corresponding to that socket and the process. When the 41 * socket gets closed we remove the item from the list. The list gets loaded 42 * every time a stat(2) call finds a socket. 43 */ 44 45#include <sys/param.h> 46#include <sys/systm.h> 47#include <sys/queue.h> 48#include <sys/file.h> 49#include <sys/socket.h> 50#include <sys/socketvar.h> 51#include <sys/sysproto.h> 52#include <sys/un.h> 53#include <sys/stat.h> 54#include <sys/proc.h> 55#include <sys/malloc.h> 56 57#include <compat/svr4/svr4.h> 58#include <compat/svr4/svr4_types.h> 59#include <compat/svr4/svr4_util.h> 60#include <compat/svr4/svr4_socket.h> 61#include <compat/svr4/svr4_signal.h> 62#include <compat/svr4/svr4_sockmod.h> 63#include <compat/svr4/svr4_proto.h> 64
|
77struct sockaddr_un * 78svr4_find_socket(td, fp, dev, ino) 79 struct thread *td; 80 struct file *fp; 81 udev_t dev; 82 ino_t ino; 83{ 84 struct svr4_sockcache_entry *e; 85 void *cookie = ((struct socket *)fp->f_data)->so_emuldata; 86 87 if (svr4_str_initialized != 2) { 88 if (atomic_cmpset_acq_int(&svr4_str_initialized, 0, 1)) { 89 DPRINTF(("svr4_find_socket: uninitialized [%p,%d,%d]\n", 90 td, dev, ino)); 91 TAILQ_INIT(&svr4_head); 92 atomic_store_rel_int(&svr4_str_initialized, 2); 93 } 94 return NULL; 95 } 96 97 98 DPRINTF(("svr4_find_socket: [%p,%d,%d]: ", td, dev, ino)); 99 TAILQ_FOREACH(e, &svr4_head, entries) 100 if (e->p == td->td_proc && e->dev == dev && e->ino == ino) { 101#ifdef DIAGNOSTIC 102 if (e->cookie != NULL && e->cookie != cookie) 103 panic("svr4 socket cookie mismatch"); 104#endif 105 e->cookie = cookie; 106 DPRINTF(("%s\n", e->sock.sun_path)); 107 return &e->sock; 108 } 109 110 DPRINTF(("not found\n")); 111 return NULL; 112} 113 114 115/* 116 * svr4_delete_socket() is in sys/dev/streams.c (because it's called by 117 * the streams "soo_close()" routine). 118 */ 119int 120svr4_add_socket(td, path, st) 121 struct thread *td; 122 const char *path; 123 struct stat *st; 124{ 125 struct svr4_sockcache_entry *e; 126 int len, error; 127 128 /* 129 * Wait for the TAILQ to be initialized. Only the very first CPU 130 * will succeed on the atomic_cmpset(). The other CPU's will spin 131 * until the first one finishes the initialization. Once the 132 * initialization is complete, the condition will always fail 133 * avoiding expensive atomic operations in the common case. 134 */ 135 while (svr4_str_initialized != 2) 136 if (atomic_cmpset_acq_int(&svr4_str_initialized, 0, 1)) { 137 TAILQ_INIT(&svr4_head); 138 atomic_store_rel_int(&svr4_str_initialized, 2); 139 } 140 141 e = malloc(sizeof(*e), M_TEMP, M_WAITOK); 142 e->cookie = NULL; 143 e->dev = st->st_dev; 144 e->ino = st->st_ino; 145 e->p = td->td_proc; 146 147 if ((error = copyinstr(path, e->sock.sun_path, 148 sizeof(e->sock.sun_path), &len)) != 0) { 149 DPRINTF(("svr4_add_socket: copyinstr failed %d\n", error)); 150 free(e, M_TEMP); 151 return error; 152 } 153 154 e->sock.sun_family = AF_LOCAL; 155 e->sock.sun_len = len; 156 157 TAILQ_INSERT_HEAD(&svr4_head, e, entries); 158 DPRINTF(("svr4_add_socket: %s [%p,%d,%d]\n", e->sock.sun_path, 159 td->td_proc, e->dev, e->ino)); 160 return 0; 161} 162 163 164int 165svr4_sys_socket(td, uap) 166 struct thread *td; 167 struct svr4_sys_socket_args *uap; 168{ 169 switch (uap->type) { 170 case SVR4_SOCK_DGRAM: 171 uap->type = SOCK_DGRAM; 172 break; 173 174 case SVR4_SOCK_STREAM: 175 uap->type = SOCK_STREAM; 176 break; 177 178 case SVR4_SOCK_RAW: 179 uap->type = SOCK_RAW; 180 break; 181 182 case SVR4_SOCK_RDM: 183 uap->type = SOCK_RDM; 184 break; 185 186 case SVR4_SOCK_SEQPACKET: 187 uap->type = SOCK_SEQPACKET; 188 break; 189 default: 190 return EINVAL; 191 } 192 return socket(td, (struct socket_args *)uap); 193}
| 65struct sockaddr_un * 66svr4_find_socket(td, fp, dev, ino) 67 struct thread *td; 68 struct file *fp; 69 udev_t dev; 70 ino_t ino; 71{ 72 struct svr4_sockcache_entry *e; 73 void *cookie = ((struct socket *)fp->f_data)->so_emuldata; 74 75 if (svr4_str_initialized != 2) { 76 if (atomic_cmpset_acq_int(&svr4_str_initialized, 0, 1)) { 77 DPRINTF(("svr4_find_socket: uninitialized [%p,%d,%d]\n", 78 td, dev, ino)); 79 TAILQ_INIT(&svr4_head); 80 atomic_store_rel_int(&svr4_str_initialized, 2); 81 } 82 return NULL; 83 } 84 85 86 DPRINTF(("svr4_find_socket: [%p,%d,%d]: ", td, dev, ino)); 87 TAILQ_FOREACH(e, &svr4_head, entries) 88 if (e->p == td->td_proc && e->dev == dev && e->ino == ino) { 89#ifdef DIAGNOSTIC 90 if (e->cookie != NULL && e->cookie != cookie) 91 panic("svr4 socket cookie mismatch"); 92#endif 93 e->cookie = cookie; 94 DPRINTF(("%s\n", e->sock.sun_path)); 95 return &e->sock; 96 } 97 98 DPRINTF(("not found\n")); 99 return NULL; 100} 101 102 103/* 104 * svr4_delete_socket() is in sys/dev/streams.c (because it's called by 105 * the streams "soo_close()" routine). 106 */ 107int 108svr4_add_socket(td, path, st) 109 struct thread *td; 110 const char *path; 111 struct stat *st; 112{ 113 struct svr4_sockcache_entry *e; 114 int len, error; 115 116 /* 117 * Wait for the TAILQ to be initialized. Only the very first CPU 118 * will succeed on the atomic_cmpset(). The other CPU's will spin 119 * until the first one finishes the initialization. Once the 120 * initialization is complete, the condition will always fail 121 * avoiding expensive atomic operations in the common case. 122 */ 123 while (svr4_str_initialized != 2) 124 if (atomic_cmpset_acq_int(&svr4_str_initialized, 0, 1)) { 125 TAILQ_INIT(&svr4_head); 126 atomic_store_rel_int(&svr4_str_initialized, 2); 127 } 128 129 e = malloc(sizeof(*e), M_TEMP, M_WAITOK); 130 e->cookie = NULL; 131 e->dev = st->st_dev; 132 e->ino = st->st_ino; 133 e->p = td->td_proc; 134 135 if ((error = copyinstr(path, e->sock.sun_path, 136 sizeof(e->sock.sun_path), &len)) != 0) { 137 DPRINTF(("svr4_add_socket: copyinstr failed %d\n", error)); 138 free(e, M_TEMP); 139 return error; 140 } 141 142 e->sock.sun_family = AF_LOCAL; 143 e->sock.sun_len = len; 144 145 TAILQ_INSERT_HEAD(&svr4_head, e, entries); 146 DPRINTF(("svr4_add_socket: %s [%p,%d,%d]\n", e->sock.sun_path, 147 td->td_proc, e->dev, e->ino)); 148 return 0; 149} 150 151 152int 153svr4_sys_socket(td, uap) 154 struct thread *td; 155 struct svr4_sys_socket_args *uap; 156{ 157 switch (uap->type) { 158 case SVR4_SOCK_DGRAM: 159 uap->type = SOCK_DGRAM; 160 break; 161 162 case SVR4_SOCK_STREAM: 163 uap->type = SOCK_STREAM; 164 break; 165 166 case SVR4_SOCK_RAW: 167 uap->type = SOCK_RAW; 168 break; 169 170 case SVR4_SOCK_RDM: 171 uap->type = SOCK_RDM; 172 break; 173 174 case SVR4_SOCK_SEQPACKET: 175 uap->type = SOCK_SEQPACKET; 176 break; 177 default: 178 return EINVAL; 179 } 180 return socket(td, (struct socket_args *)uap); 181}
|