Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * NET An implementation of the SOCKET network access protocol. |
| 3 | * |
| 4 | * Version: @(#)socket.c 1.1.93 18/02/95 |
| 5 | * |
| 6 | * Authors: Orest Zborowski, <obz@Kodak.COM> |
Jesper Juhl | 02c30a8 | 2005-05-05 16:16:16 -0700 | [diff] [blame] | 7 | * Ross Biro |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG> |
| 9 | * |
| 10 | * Fixes: |
| 11 | * Anonymous : NOTSOCK/BADF cleanup. Error fix in |
| 12 | * shutdown() |
| 13 | * Alan Cox : verify_area() fixes |
| 14 | * Alan Cox : Removed DDI |
| 15 | * Jonathan Kamens : SOCK_DGRAM reconnect bug |
| 16 | * Alan Cox : Moved a load of checks to the very |
| 17 | * top level. |
| 18 | * Alan Cox : Move address structures to/from user |
| 19 | * mode above the protocol layers. |
| 20 | * Rob Janssen : Allow 0 length sends. |
| 21 | * Alan Cox : Asynchronous I/O support (cribbed from the |
| 22 | * tty drivers). |
| 23 | * Niibe Yutaka : Asynchronous I/O for writes (4.4BSD style) |
| 24 | * Jeff Uphoff : Made max number of sockets command-line |
| 25 | * configurable. |
| 26 | * Matti Aarnio : Made the number of sockets dynamic, |
| 27 | * to be allocated when needed, and mr. |
| 28 | * Uphoff's max is used as max to be |
| 29 | * allowed to allocate. |
| 30 | * Linus : Argh. removed all the socket allocation |
| 31 | * altogether: it's in the inode now. |
| 32 | * Alan Cox : Made sock_alloc()/sock_release() public |
| 33 | * for NetROM and future kernel nfsd type |
| 34 | * stuff. |
| 35 | * Alan Cox : sendmsg/recvmsg basics. |
| 36 | * Tom Dyas : Export net symbols. |
| 37 | * Marcin Dalecki : Fixed problems with CONFIG_NET="n". |
| 38 | * Alan Cox : Added thread locking to sys_* calls |
| 39 | * for sockets. May have errors at the |
| 40 | * moment. |
| 41 | * Kevin Buhr : Fixed the dumb errors in the above. |
| 42 | * Andi Kleen : Some small cleanups, optimizations, |
| 43 | * and fixed a copy_from_user() bug. |
| 44 | * Tigran Aivazian : sys_send(args) calls sys_sendto(args, NULL, 0) |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 45 | * Tigran Aivazian : Made listen(2) backlog sanity checks |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | * protocol-independent |
| 47 | * |
| 48 | * |
| 49 | * This program is free software; you can redistribute it and/or |
| 50 | * modify it under the terms of the GNU General Public License |
| 51 | * as published by the Free Software Foundation; either version |
| 52 | * 2 of the License, or (at your option) any later version. |
| 53 | * |
| 54 | * |
| 55 | * This module is effectively the top level interface to the BSD socket |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 56 | * paradigm. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | * |
| 58 | * Based upon Swansea University Computer Society NET3.039 |
| 59 | */ |
| 60 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | #include <linux/socket.h> |
| 63 | #include <linux/file.h> |
| 64 | #include <linux/net.h> |
| 65 | #include <linux/interrupt.h> |
Ulrich Drepper | aaca0bd | 2008-07-23 21:29:20 -0700 | [diff] [blame] | 66 | #include <linux/thread_info.h> |
Stephen Hemminger | 55737fd | 2006-09-01 00:23:39 -0700 | [diff] [blame] | 67 | #include <linux/rcupdate.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | #include <linux/netdevice.h> |
| 69 | #include <linux/proc_fs.h> |
| 70 | #include <linux/seq_file.h> |
Arjan van de Ven | 4a3e2f7 | 2006-03-20 22:33:17 -0800 | [diff] [blame] | 71 | #include <linux/mutex.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | #include <linux/wanrouter.h> |
| 73 | #include <linux/if_bridge.h> |
Arnaldo Carvalho de Melo | 2038073 | 2005-08-16 02:18:02 -0300 | [diff] [blame] | 74 | #include <linux/if_frad.h> |
| 75 | #include <linux/if_vlan.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | #include <linux/init.h> |
| 77 | #include <linux/poll.h> |
| 78 | #include <linux/cache.h> |
| 79 | #include <linux/module.h> |
| 80 | #include <linux/highmem.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | #include <linux/mount.h> |
| 82 | #include <linux/security.h> |
| 83 | #include <linux/syscalls.h> |
| 84 | #include <linux/compat.h> |
| 85 | #include <linux/kmod.h> |
David Woodhouse | 3ec3b2f | 2005-05-17 12:08:48 +0100 | [diff] [blame] | 86 | #include <linux/audit.h> |
Adrian Bunk | d86b5e0 | 2006-01-21 00:46:55 +0100 | [diff] [blame] | 87 | #include <linux/wireless.h> |
Eric W. Biederman | 1b8d7ae | 2007-10-08 23:24:22 -0700 | [diff] [blame] | 88 | #include <linux/nsproxy.h> |
Nick Black | 1fd7317d | 2009-09-22 16:43:33 -0700 | [diff] [blame] | 89 | #include <linux/magic.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 90 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | |
| 92 | #include <asm/uaccess.h> |
| 93 | #include <asm/unistd.h> |
| 94 | |
| 95 | #include <net/compat.h> |
David S. Miller | 87de87d | 2008-06-03 09:14:03 -0700 | [diff] [blame] | 96 | #include <net/wext.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | |
| 98 | #include <net/sock.h> |
| 99 | #include <linux/netfilter.h> |
| 100 | |
Arnd Bergmann | 6b96018 | 2009-11-06 23:10:54 -0800 | [diff] [blame] | 101 | #include <linux/if_tun.h> |
| 102 | #include <linux/ipv6_route.h> |
| 103 | #include <linux/route.h> |
Arnd Bergmann | 6b96018 | 2009-11-06 23:10:54 -0800 | [diff] [blame] | 104 | #include <linux/sockios.h> |
| 105 | #include <linux/atalk.h> |
| 106 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | static int sock_no_open(struct inode *irrelevant, struct file *dontcare); |
Badari Pulavarty | 027445c | 2006-09-30 23:28:46 -0700 | [diff] [blame] | 108 | static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov, |
| 109 | unsigned long nr_segs, loff_t pos); |
| 110 | static ssize_t sock_aio_write(struct kiocb *iocb, const struct iovec *iov, |
| 111 | unsigned long nr_segs, loff_t pos); |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 112 | static int sock_mmap(struct file *file, struct vm_area_struct *vma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | |
| 114 | static int sock_close(struct inode *inode, struct file *file); |
| 115 | static unsigned int sock_poll(struct file *file, |
| 116 | struct poll_table_struct *wait); |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 117 | static long sock_ioctl(struct file *file, unsigned int cmd, unsigned long arg); |
Shaun Pereira | 89bbfc9 | 2006-03-21 23:58:08 -0800 | [diff] [blame] | 118 | #ifdef CONFIG_COMPAT |
| 119 | static long compat_sock_ioctl(struct file *file, |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 120 | unsigned int cmd, unsigned long arg); |
Shaun Pereira | 89bbfc9 | 2006-03-21 23:58:08 -0800 | [diff] [blame] | 121 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | static int sock_fasync(int fd, struct file *filp, int on); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | static ssize_t sock_sendpage(struct file *file, struct page *page, |
| 124 | int offset, size_t size, loff_t *ppos, int more); |
Jens Axboe | 9c55e01 | 2007-11-06 23:30:13 -0800 | [diff] [blame] | 125 | static ssize_t sock_splice_read(struct file *file, loff_t *ppos, |
| 126 | struct pipe_inode_info *pipe, size_t len, |
| 127 | unsigned int flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | /* |
| 130 | * Socket files have a set of 'special' operations as well as the generic file ones. These don't appear |
| 131 | * in the operation structures but are done directly via the socketcall() multiplexor. |
| 132 | */ |
| 133 | |
Arjan van de Ven | da7071d | 2007-02-12 00:55:36 -0800 | [diff] [blame] | 134 | static const struct file_operations socket_file_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | .owner = THIS_MODULE, |
| 136 | .llseek = no_llseek, |
| 137 | .aio_read = sock_aio_read, |
| 138 | .aio_write = sock_aio_write, |
| 139 | .poll = sock_poll, |
| 140 | .unlocked_ioctl = sock_ioctl, |
Shaun Pereira | 89bbfc9 | 2006-03-21 23:58:08 -0800 | [diff] [blame] | 141 | #ifdef CONFIG_COMPAT |
| 142 | .compat_ioctl = compat_sock_ioctl, |
| 143 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | .mmap = sock_mmap, |
| 145 | .open = sock_no_open, /* special open code to disallow open via /proc */ |
| 146 | .release = sock_close, |
| 147 | .fasync = sock_fasync, |
Jens Axboe | 5274f05 | 2006-03-30 15:15:30 +0200 | [diff] [blame] | 148 | .sendpage = sock_sendpage, |
| 149 | .splice_write = generic_splice_sendpage, |
Jens Axboe | 9c55e01 | 2007-11-06 23:30:13 -0800 | [diff] [blame] | 150 | .splice_read = sock_splice_read, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | }; |
| 152 | |
| 153 | /* |
| 154 | * The protocol list. Each protocol is registered in here. |
| 155 | */ |
| 156 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | static DEFINE_SPINLOCK(net_family_lock); |
Stephen Hemminger | f0fd27d | 2006-08-09 21:03:17 -0700 | [diff] [blame] | 158 | static const struct net_proto_family *net_families[NPROTO] __read_mostly; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | /* |
| 161 | * Statistics counters of the socket lists |
| 162 | */ |
| 163 | |
| 164 | static DEFINE_PER_CPU(int, sockets_in_use) = 0; |
| 165 | |
| 166 | /* |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 167 | * Support routines. |
| 168 | * Move socket addresses back and forth across the kernel/user |
| 169 | * divide and look after the messy bits. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | */ |
| 171 | |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 172 | #define MAX_SOCK_ADDR 128 /* 108 for Unix domain - |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | 16 for IP, 16 for IPX, |
| 174 | 24 for IPv6, |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 175 | about 80 for AX.25 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | must be at least one bigger than |
| 177 | the AF_UNIX size (see net/unix/af_unix.c |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 178 | :unix_mkname()). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | */ |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 180 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | /** |
| 182 | * move_addr_to_kernel - copy a socket address into kernel space |
| 183 | * @uaddr: Address in user space |
| 184 | * @kaddr: Address in kernel space |
| 185 | * @ulen: Length in user space |
| 186 | * |
| 187 | * The address is copied into kernel space. If the provided address is |
| 188 | * too long an error code of -EINVAL is returned. If the copy gives |
| 189 | * invalid addresses -EFAULT is returned. On a success 0 is returned. |
| 190 | */ |
| 191 | |
YOSHIFUJI Hideaki | 230b183 | 2008-07-19 22:35:47 -0700 | [diff] [blame] | 192 | int move_addr_to_kernel(void __user *uaddr, int ulen, struct sockaddr *kaddr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | { |
YOSHIFUJI Hideaki | 230b183 | 2008-07-19 22:35:47 -0700 | [diff] [blame] | 194 | if (ulen < 0 || ulen > sizeof(struct sockaddr_storage)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | return -EINVAL; |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 196 | if (ulen == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | return 0; |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 198 | if (copy_from_user(kaddr, uaddr, ulen)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | return -EFAULT; |
David Woodhouse | 3ec3b2f | 2005-05-17 12:08:48 +0100 | [diff] [blame] | 200 | return audit_sockaddr(ulen, kaddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | /** |
| 204 | * move_addr_to_user - copy an address to user space |
| 205 | * @kaddr: kernel space address |
| 206 | * @klen: length of address in kernel |
| 207 | * @uaddr: user space address |
| 208 | * @ulen: pointer to user length field |
| 209 | * |
| 210 | * The value pointed to by ulen on entry is the buffer length available. |
| 211 | * This is overwritten with the buffer space used. -EINVAL is returned |
| 212 | * if an overlong buffer is specified or a negative buffer size. -EFAULT |
| 213 | * is returned if either the buffer or the length field are not |
| 214 | * accessible. |
| 215 | * After copying the data up to the limit the user specifies, the true |
| 216 | * length of the data is written over the length limit the user |
| 217 | * specified. Zero is returned for a success. |
| 218 | */ |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 219 | |
YOSHIFUJI Hideaki | 230b183 | 2008-07-19 22:35:47 -0700 | [diff] [blame] | 220 | int move_addr_to_user(struct sockaddr *kaddr, int klen, void __user *uaddr, |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 221 | int __user *ulen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | { |
| 223 | int err; |
| 224 | int len; |
| 225 | |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 226 | err = get_user(len, ulen); |
| 227 | if (err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | return err; |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 229 | if (len > klen) |
| 230 | len = klen; |
YOSHIFUJI Hideaki | 230b183 | 2008-07-19 22:35:47 -0700 | [diff] [blame] | 231 | if (len < 0 || len > sizeof(struct sockaddr_storage)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | return -EINVAL; |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 233 | if (len) { |
Steve Grubb | d6fe394 | 2006-03-30 12:20:22 -0500 | [diff] [blame] | 234 | if (audit_sockaddr(klen, kaddr)) |
| 235 | return -ENOMEM; |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 236 | if (copy_to_user(uaddr, kaddr, len)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | return -EFAULT; |
| 238 | } |
| 239 | /* |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 240 | * "fromlen shall refer to the value before truncation.." |
| 241 | * 1003.1g |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | */ |
| 243 | return __put_user(klen, ulen); |
| 244 | } |
| 245 | |
Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 246 | static struct kmem_cache *sock_inode_cachep __read_mostly; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | |
| 248 | static struct inode *sock_alloc_inode(struct super_block *sb) |
| 249 | { |
| 250 | struct socket_alloc *ei; |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 251 | |
Christoph Lameter | e94b176 | 2006-12-06 20:33:17 -0800 | [diff] [blame] | 252 | ei = kmem_cache_alloc(sock_inode_cachep, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | if (!ei) |
| 254 | return NULL; |
| 255 | init_waitqueue_head(&ei->socket.wait); |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 256 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | ei->socket.fasync_list = NULL; |
| 258 | ei->socket.state = SS_UNCONNECTED; |
| 259 | ei->socket.flags = 0; |
| 260 | ei->socket.ops = NULL; |
| 261 | ei->socket.sk = NULL; |
| 262 | ei->socket.file = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | |
| 264 | return &ei->vfs_inode; |
| 265 | } |
| 266 | |
| 267 | static void sock_destroy_inode(struct inode *inode) |
| 268 | { |
| 269 | kmem_cache_free(sock_inode_cachep, |
| 270 | container_of(inode, struct socket_alloc, vfs_inode)); |
| 271 | } |
| 272 | |
Alexey Dobriyan | 51cc506 | 2008-07-25 19:45:34 -0700 | [diff] [blame] | 273 | static void init_once(void *foo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | { |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 275 | struct socket_alloc *ei = (struct socket_alloc *)foo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | |
Christoph Lameter | a35afb8 | 2007-05-16 22:10:57 -0700 | [diff] [blame] | 277 | inode_init_once(&ei->vfs_inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | } |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 279 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | static int init_inodecache(void) |
| 281 | { |
| 282 | sock_inode_cachep = kmem_cache_create("sock_inode_cache", |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 283 | sizeof(struct socket_alloc), |
| 284 | 0, |
| 285 | (SLAB_HWCACHE_ALIGN | |
| 286 | SLAB_RECLAIM_ACCOUNT | |
| 287 | SLAB_MEM_SPREAD), |
Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 288 | init_once); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | if (sock_inode_cachep == NULL) |
| 290 | return -ENOMEM; |
| 291 | return 0; |
| 292 | } |
| 293 | |
Alexey Dobriyan | b87221d | 2009-09-21 17:01:09 -0700 | [diff] [blame] | 294 | static const struct super_operations sockfs_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | .alloc_inode = sock_alloc_inode, |
| 296 | .destroy_inode =sock_destroy_inode, |
| 297 | .statfs = simple_statfs, |
| 298 | }; |
| 299 | |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 300 | static int sockfs_get_sb(struct file_system_type *fs_type, |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 301 | int flags, const char *dev_name, void *data, |
| 302 | struct vfsmount *mnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | { |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 304 | return get_sb_pseudo(fs_type, "socket:", &sockfs_ops, SOCKFS_MAGIC, |
| 305 | mnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | } |
| 307 | |
Eric Dumazet | ba89966 | 2005-08-26 12:05:31 -0700 | [diff] [blame] | 308 | static struct vfsmount *sock_mnt __read_mostly; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | |
| 310 | static struct file_system_type sock_fs_type = { |
| 311 | .name = "sockfs", |
| 312 | .get_sb = sockfs_get_sb, |
| 313 | .kill_sb = kill_anon_super, |
| 314 | }; |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 315 | |
Eric Dumazet | c23fbb6 | 2007-05-08 00:26:18 -0700 | [diff] [blame] | 316 | /* |
| 317 | * sockfs_dname() is called from d_path(). |
| 318 | */ |
| 319 | static char *sockfs_dname(struct dentry *dentry, char *buffer, int buflen) |
| 320 | { |
| 321 | return dynamic_dname(dentry, buffer, buflen, "socket:[%lu]", |
| 322 | dentry->d_inode->i_ino); |
| 323 | } |
| 324 | |
Al Viro | 3ba13d1 | 2009-02-20 06:02:22 +0000 | [diff] [blame] | 325 | static const struct dentry_operations sockfs_dentry_operations = { |
Eric Dumazet | c23fbb6 | 2007-05-08 00:26:18 -0700 | [diff] [blame] | 326 | .d_dname = sockfs_dname, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | }; |
| 328 | |
| 329 | /* |
| 330 | * Obtains the first available file descriptor and sets it up for use. |
| 331 | * |
David S. Miller | 39d8c1b | 2006-03-20 17:13:49 -0800 | [diff] [blame] | 332 | * These functions create file structures and maps them to fd space |
| 333 | * of the current process. On success it returns file descriptor |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | * and file struct implicitly stored in sock->file. |
| 335 | * Note that another thread may close file descriptor before we return |
| 336 | * from this function. We use the fact that now we do not refer |
| 337 | * to socket after mapping. If one day we will need it, this |
| 338 | * function will increment ref. count on file by 1. |
| 339 | * |
| 340 | * In any case returned fd MAY BE not valid! |
| 341 | * This race condition is unavoidable |
| 342 | * with shared fd spaces, we cannot solve it inside kernel, |
| 343 | * but we take care of internal coherence yet. |
| 344 | */ |
| 345 | |
Al Viro | 7cbe66b | 2009-08-05 19:59:08 +0400 | [diff] [blame] | 346 | static int sock_alloc_file(struct socket *sock, struct file **f, int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | { |
Al Viro | 7cbe66b | 2009-08-05 19:59:08 +0400 | [diff] [blame] | 348 | struct qstr name = { .name = "" }; |
Al Viro | 2c48b9c | 2009-08-09 00:52:35 +0400 | [diff] [blame] | 349 | struct path path; |
Al Viro | 7cbe66b | 2009-08-05 19:59:08 +0400 | [diff] [blame] | 350 | struct file *file; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | int fd; |
David S. Miller | 39d8c1b | 2006-03-20 17:13:49 -0800 | [diff] [blame] | 352 | |
Ulrich Drepper | a677a03 | 2008-07-23 21:29:17 -0700 | [diff] [blame] | 353 | fd = get_unused_fd_flags(flags); |
Al Viro | 7cbe66b | 2009-08-05 19:59:08 +0400 | [diff] [blame] | 354 | if (unlikely(fd < 0)) |
| 355 | return fd; |
David S. Miller | 39d8c1b | 2006-03-20 17:13:49 -0800 | [diff] [blame] | 356 | |
Al Viro | 2c48b9c | 2009-08-09 00:52:35 +0400 | [diff] [blame] | 357 | path.dentry = d_alloc(sock_mnt->mnt_sb->s_root, &name); |
| 358 | if (unlikely(!path.dentry)) { |
Al Viro | 7cbe66b | 2009-08-05 19:59:08 +0400 | [diff] [blame] | 359 | put_unused_fd(fd); |
David S. Miller | 39d8c1b | 2006-03-20 17:13:49 -0800 | [diff] [blame] | 360 | return -ENOMEM; |
Al Viro | 7cbe66b | 2009-08-05 19:59:08 +0400 | [diff] [blame] | 361 | } |
Al Viro | 2c48b9c | 2009-08-09 00:52:35 +0400 | [diff] [blame] | 362 | path.mnt = mntget(sock_mnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | |
Al Viro | 2c48b9c | 2009-08-09 00:52:35 +0400 | [diff] [blame] | 364 | path.dentry->d_op = &sockfs_dentry_operations; |
Al Viro | 2c48b9c | 2009-08-09 00:52:35 +0400 | [diff] [blame] | 365 | d_instantiate(path.dentry, SOCK_INODE(sock)); |
Al Viro | cc3808f | 2009-08-06 09:43:59 +0400 | [diff] [blame] | 366 | SOCK_INODE(sock)->i_fop = &socket_file_ops; |
| 367 | |
Al Viro | 2c48b9c | 2009-08-09 00:52:35 +0400 | [diff] [blame] | 368 | file = alloc_file(&path, FMODE_READ | FMODE_WRITE, |
Al Viro | cc3808f | 2009-08-06 09:43:59 +0400 | [diff] [blame] | 369 | &socket_file_ops); |
| 370 | if (unlikely(!file)) { |
| 371 | /* drop dentry, keep inode */ |
| 372 | atomic_inc(&path.dentry->d_inode->i_count); |
Al Viro | 2c48b9c | 2009-08-09 00:52:35 +0400 | [diff] [blame] | 373 | path_put(&path); |
Al Viro | cc3808f | 2009-08-06 09:43:59 +0400 | [diff] [blame] | 374 | put_unused_fd(fd); |
| 375 | return -ENFILE; |
| 376 | } |
David S. Miller | 39d8c1b | 2006-03-20 17:13:49 -0800 | [diff] [blame] | 377 | |
| 378 | sock->file = file; |
Ulrich Drepper | 77d2720 | 2008-07-23 21:29:35 -0700 | [diff] [blame] | 379 | file->f_flags = O_RDWR | (flags & O_NONBLOCK); |
David S. Miller | 39d8c1b | 2006-03-20 17:13:49 -0800 | [diff] [blame] | 380 | file->f_pos = 0; |
| 381 | file->private_data = sock; |
| 382 | |
Al Viro | 7cbe66b | 2009-08-05 19:59:08 +0400 | [diff] [blame] | 383 | *f = file; |
| 384 | return fd; |
David S. Miller | 39d8c1b | 2006-03-20 17:13:49 -0800 | [diff] [blame] | 385 | } |
| 386 | |
Ulrich Drepper | a677a03 | 2008-07-23 21:29:17 -0700 | [diff] [blame] | 387 | int sock_map_fd(struct socket *sock, int flags) |
David S. Miller | 39d8c1b | 2006-03-20 17:13:49 -0800 | [diff] [blame] | 388 | { |
| 389 | struct file *newfile; |
Al Viro | 7cbe66b | 2009-08-05 19:59:08 +0400 | [diff] [blame] | 390 | int fd = sock_alloc_file(sock, &newfile, flags); |
David S. Miller | 39d8c1b | 2006-03-20 17:13:49 -0800 | [diff] [blame] | 391 | |
Al Viro | 7cbe66b | 2009-08-05 19:59:08 +0400 | [diff] [blame] | 392 | if (likely(fd >= 0)) |
David S. Miller | 39d8c1b | 2006-03-20 17:13:49 -0800 | [diff] [blame] | 393 | fd_install(fd, newfile); |
Al Viro | 7cbe66b | 2009-08-05 19:59:08 +0400 | [diff] [blame] | 394 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | return fd; |
| 396 | } |
| 397 | |
Benjamin LaHaise | 6cb153c | 2006-03-20 22:27:12 -0800 | [diff] [blame] | 398 | static struct socket *sock_from_file(struct file *file, int *err) |
| 399 | { |
Benjamin LaHaise | 6cb153c | 2006-03-20 22:27:12 -0800 | [diff] [blame] | 400 | if (file->f_op == &socket_file_ops) |
| 401 | return file->private_data; /* set in sock_map_fd */ |
| 402 | |
Eric Dumazet | 23bb80d | 2007-02-08 14:59:57 -0800 | [diff] [blame] | 403 | *err = -ENOTSOCK; |
| 404 | return NULL; |
Benjamin LaHaise | 6cb153c | 2006-03-20 22:27:12 -0800 | [diff] [blame] | 405 | } |
| 406 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | /** |
| 408 | * sockfd_lookup - Go from a file number to its socket slot |
| 409 | * @fd: file handle |
| 410 | * @err: pointer to an error code return |
| 411 | * |
| 412 | * The file handle passed in is locked and the socket it is bound |
| 413 | * too is returned. If an error occurs the err pointer is overwritten |
| 414 | * with a negative errno code and NULL is returned. The function checks |
| 415 | * for both invalid handles and passing a handle which is not a socket. |
| 416 | * |
| 417 | * On a success the socket object pointer is returned. |
| 418 | */ |
| 419 | |
| 420 | struct socket *sockfd_lookup(int fd, int *err) |
| 421 | { |
| 422 | struct file *file; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | struct socket *sock; |
| 424 | |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 425 | file = fget(fd); |
| 426 | if (!file) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | *err = -EBADF; |
| 428 | return NULL; |
| 429 | } |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 430 | |
Benjamin LaHaise | 6cb153c | 2006-03-20 22:27:12 -0800 | [diff] [blame] | 431 | sock = sock_from_file(file, err); |
| 432 | if (!sock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | fput(file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | return sock; |
| 435 | } |
| 436 | |
Benjamin LaHaise | 6cb153c | 2006-03-20 22:27:12 -0800 | [diff] [blame] | 437 | static struct socket *sockfd_lookup_light(int fd, int *err, int *fput_needed) |
| 438 | { |
| 439 | struct file *file; |
| 440 | struct socket *sock; |
| 441 | |
Hua Zhong | 3672558 | 2006-04-19 15:25:02 -0700 | [diff] [blame] | 442 | *err = -EBADF; |
Benjamin LaHaise | 6cb153c | 2006-03-20 22:27:12 -0800 | [diff] [blame] | 443 | file = fget_light(fd, fput_needed); |
| 444 | if (file) { |
| 445 | sock = sock_from_file(file, err); |
| 446 | if (sock) |
| 447 | return sock; |
| 448 | fput_light(file, *fput_needed); |
| 449 | } |
| 450 | return NULL; |
| 451 | } |
| 452 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | /** |
| 454 | * sock_alloc - allocate a socket |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 455 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | * Allocate a new inode and socket object. The two are bound together |
| 457 | * and initialised. The socket is then returned. If we are out of inodes |
| 458 | * NULL is returned. |
| 459 | */ |
| 460 | |
| 461 | static struct socket *sock_alloc(void) |
| 462 | { |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 463 | struct inode *inode; |
| 464 | struct socket *sock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | |
| 466 | inode = new_inode(sock_mnt->mnt_sb); |
| 467 | if (!inode) |
| 468 | return NULL; |
| 469 | |
| 470 | sock = SOCKET_I(inode); |
| 471 | |
Eric Dumazet | 29a020d | 2009-09-15 02:39:20 -0700 | [diff] [blame] | 472 | kmemcheck_annotate_bitfield(sock, type); |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 473 | inode->i_mode = S_IFSOCK | S_IRWXUGO; |
David Howells | 8192b0c | 2008-11-14 10:39:10 +1100 | [diff] [blame] | 474 | inode->i_uid = current_fsuid(); |
| 475 | inode->i_gid = current_fsgid(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | |
Eric Dumazet | 4e69489 | 2009-04-04 16:41:09 -0700 | [diff] [blame] | 477 | percpu_add(sockets_in_use, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | return sock; |
| 479 | } |
| 480 | |
| 481 | /* |
| 482 | * In theory you can't get an open on this inode, but /proc provides |
| 483 | * a back door. Remember to keep it shut otherwise you'll let the |
| 484 | * creepy crawlies in. |
| 485 | */ |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 486 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | static int sock_no_open(struct inode *irrelevant, struct file *dontcare) |
| 488 | { |
| 489 | return -ENXIO; |
| 490 | } |
| 491 | |
Arjan van de Ven | 4b6f5d2 | 2006-03-28 01:56:42 -0800 | [diff] [blame] | 492 | const struct file_operations bad_sock_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | .owner = THIS_MODULE, |
| 494 | .open = sock_no_open, |
| 495 | }; |
| 496 | |
| 497 | /** |
| 498 | * sock_release - close a socket |
| 499 | * @sock: socket to close |
| 500 | * |
| 501 | * The socket is released from the protocol stack if it has a release |
| 502 | * callback, and the inode is then released if the socket is bound to |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 503 | * an inode not a file. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | */ |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 505 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | void sock_release(struct socket *sock) |
| 507 | { |
| 508 | if (sock->ops) { |
| 509 | struct module *owner = sock->ops->owner; |
| 510 | |
| 511 | sock->ops->release(sock); |
| 512 | sock->ops = NULL; |
| 513 | module_put(owner); |
| 514 | } |
| 515 | |
| 516 | if (sock->fasync_list) |
| 517 | printk(KERN_ERR "sock_release: fasync list not empty!\n"); |
| 518 | |
Eric Dumazet | 4e69489 | 2009-04-04 16:41:09 -0700 | [diff] [blame] | 519 | percpu_sub(sockets_in_use, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | if (!sock->file) { |
| 521 | iput(SOCK_INODE(sock)); |
| 522 | return; |
| 523 | } |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 524 | sock->file = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | } |
| 526 | |
Patrick Ohly | 20d4947 | 2009-02-12 05:03:38 +0000 | [diff] [blame] | 527 | int sock_tx_timestamp(struct msghdr *msg, struct sock *sk, |
| 528 | union skb_shared_tx *shtx) |
| 529 | { |
| 530 | shtx->flags = 0; |
| 531 | if (sock_flag(sk, SOCK_TIMESTAMPING_TX_HARDWARE)) |
| 532 | shtx->hardware = 1; |
| 533 | if (sock_flag(sk, SOCK_TIMESTAMPING_TX_SOFTWARE)) |
| 534 | shtx->software = 1; |
| 535 | return 0; |
| 536 | } |
| 537 | EXPORT_SYMBOL(sock_tx_timestamp); |
| 538 | |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 539 | static inline int __sock_sendmsg(struct kiocb *iocb, struct socket *sock, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | struct msghdr *msg, size_t size) |
| 541 | { |
| 542 | struct sock_iocb *si = kiocb_to_siocb(iocb); |
| 543 | int err; |
| 544 | |
| 545 | si->sock = sock; |
| 546 | si->scm = NULL; |
| 547 | si->msg = msg; |
| 548 | si->size = size; |
| 549 | |
| 550 | err = security_socket_sendmsg(sock, msg, size); |
| 551 | if (err) |
| 552 | return err; |
| 553 | |
| 554 | return sock->ops->sendmsg(iocb, sock, msg, size); |
| 555 | } |
| 556 | |
| 557 | int sock_sendmsg(struct socket *sock, struct msghdr *msg, size_t size) |
| 558 | { |
| 559 | struct kiocb iocb; |
| 560 | struct sock_iocb siocb; |
| 561 | int ret; |
| 562 | |
| 563 | init_sync_kiocb(&iocb, NULL); |
| 564 | iocb.private = &siocb; |
| 565 | ret = __sock_sendmsg(&iocb, sock, msg, size); |
| 566 | if (-EIOCBQUEUED == ret) |
| 567 | ret = wait_on_sync_kiocb(&iocb); |
| 568 | return ret; |
| 569 | } |
| 570 | |
| 571 | int kernel_sendmsg(struct socket *sock, struct msghdr *msg, |
| 572 | struct kvec *vec, size_t num, size_t size) |
| 573 | { |
| 574 | mm_segment_t oldfs = get_fs(); |
| 575 | int result; |
| 576 | |
| 577 | set_fs(KERNEL_DS); |
| 578 | /* |
| 579 | * the following is safe, since for compiler definitions of kvec and |
| 580 | * iovec are identical, yielding the same in-core layout and alignment |
| 581 | */ |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 582 | msg->msg_iov = (struct iovec *)vec; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | msg->msg_iovlen = num; |
| 584 | result = sock_sendmsg(sock, msg, size); |
| 585 | set_fs(oldfs); |
| 586 | return result; |
| 587 | } |
| 588 | |
Patrick Ohly | 20d4947 | 2009-02-12 05:03:38 +0000 | [diff] [blame] | 589 | static int ktime2ts(ktime_t kt, struct timespec *ts) |
| 590 | { |
| 591 | if (kt.tv64) { |
| 592 | *ts = ktime_to_timespec(kt); |
| 593 | return 1; |
| 594 | } else { |
| 595 | return 0; |
| 596 | } |
| 597 | } |
| 598 | |
Eric Dumazet | 92f37fd | 2007-03-25 22:14:49 -0700 | [diff] [blame] | 599 | /* |
| 600 | * called from sock_recv_timestamp() if sock_flag(sk, SOCK_RCVTSTAMP) |
| 601 | */ |
| 602 | void __sock_recv_timestamp(struct msghdr *msg, struct sock *sk, |
| 603 | struct sk_buff *skb) |
| 604 | { |
Patrick Ohly | 20d4947 | 2009-02-12 05:03:38 +0000 | [diff] [blame] | 605 | int need_software_tstamp = sock_flag(sk, SOCK_RCVTSTAMP); |
| 606 | struct timespec ts[3]; |
| 607 | int empty = 1; |
| 608 | struct skb_shared_hwtstamps *shhwtstamps = |
| 609 | skb_hwtstamps(skb); |
Eric Dumazet | 92f37fd | 2007-03-25 22:14:49 -0700 | [diff] [blame] | 610 | |
Patrick Ohly | 20d4947 | 2009-02-12 05:03:38 +0000 | [diff] [blame] | 611 | /* Race occurred between timestamp enabling and packet |
| 612 | receiving. Fill in the current time for now. */ |
| 613 | if (need_software_tstamp && skb->tstamp.tv64 == 0) |
| 614 | __net_timestamp(skb); |
| 615 | |
| 616 | if (need_software_tstamp) { |
| 617 | if (!sock_flag(sk, SOCK_RCVTSTAMPNS)) { |
| 618 | struct timeval tv; |
| 619 | skb_get_timestamp(skb, &tv); |
| 620 | put_cmsg(msg, SOL_SOCKET, SCM_TIMESTAMP, |
| 621 | sizeof(tv), &tv); |
| 622 | } else { |
Hagen Paul Pfeifer | 842509b | 2010-04-06 05:39:52 +0000 | [diff] [blame] | 623 | skb_get_timestampns(skb, &ts[0]); |
Patrick Ohly | 20d4947 | 2009-02-12 05:03:38 +0000 | [diff] [blame] | 624 | put_cmsg(msg, SOL_SOCKET, SCM_TIMESTAMPNS, |
Hagen Paul Pfeifer | 842509b | 2010-04-06 05:39:52 +0000 | [diff] [blame] | 625 | sizeof(ts[0]), &ts[0]); |
Patrick Ohly | 20d4947 | 2009-02-12 05:03:38 +0000 | [diff] [blame] | 626 | } |
Eric Dumazet | 92f37fd | 2007-03-25 22:14:49 -0700 | [diff] [blame] | 627 | } |
Patrick Ohly | 20d4947 | 2009-02-12 05:03:38 +0000 | [diff] [blame] | 628 | |
| 629 | |
| 630 | memset(ts, 0, sizeof(ts)); |
| 631 | if (skb->tstamp.tv64 && |
| 632 | sock_flag(sk, SOCK_TIMESTAMPING_SOFTWARE)) { |
| 633 | skb_get_timestampns(skb, ts + 0); |
| 634 | empty = 0; |
| 635 | } |
| 636 | if (shhwtstamps) { |
| 637 | if (sock_flag(sk, SOCK_TIMESTAMPING_SYS_HARDWARE) && |
| 638 | ktime2ts(shhwtstamps->syststamp, ts + 1)) |
| 639 | empty = 0; |
| 640 | if (sock_flag(sk, SOCK_TIMESTAMPING_RAW_HARDWARE) && |
| 641 | ktime2ts(shhwtstamps->hwtstamp, ts + 2)) |
| 642 | empty = 0; |
| 643 | } |
| 644 | if (!empty) |
| 645 | put_cmsg(msg, SOL_SOCKET, |
| 646 | SCM_TIMESTAMPING, sizeof(ts), &ts); |
Eric Dumazet | 92f37fd | 2007-03-25 22:14:49 -0700 | [diff] [blame] | 647 | } |
| 648 | |
Arnaldo Carvalho de Melo | 7c81fd8 | 2007-03-10 00:39:35 -0300 | [diff] [blame] | 649 | EXPORT_SYMBOL_GPL(__sock_recv_timestamp); |
| 650 | |
Neil Horman | 3b88578 | 2009-10-12 13:26:31 -0700 | [diff] [blame] | 651 | inline void sock_recv_drops(struct msghdr *msg, struct sock *sk, struct sk_buff *skb) |
| 652 | { |
| 653 | if (sock_flag(sk, SOCK_RXQ_OVFL) && skb && skb->dropcount) |
| 654 | put_cmsg(msg, SOL_SOCKET, SO_RXQ_OVFL, |
| 655 | sizeof(__u32), &skb->dropcount); |
| 656 | } |
| 657 | |
| 658 | void sock_recv_ts_and_drops(struct msghdr *msg, struct sock *sk, |
| 659 | struct sk_buff *skb) |
| 660 | { |
| 661 | sock_recv_timestamp(msg, sk, skb); |
| 662 | sock_recv_drops(msg, sk, skb); |
| 663 | } |
| 664 | EXPORT_SYMBOL_GPL(sock_recv_ts_and_drops); |
| 665 | |
Arnaldo Carvalho de Melo | a2e2725 | 2009-10-12 23:40:10 -0700 | [diff] [blame] | 666 | static inline int __sock_recvmsg_nosec(struct kiocb *iocb, struct socket *sock, |
| 667 | struct msghdr *msg, size_t size, int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | struct sock_iocb *si = kiocb_to_siocb(iocb); |
| 670 | |
| 671 | si->sock = sock; |
| 672 | si->scm = NULL; |
| 673 | si->msg = msg; |
| 674 | si->size = size; |
| 675 | si->flags = flags; |
| 676 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | return sock->ops->recvmsg(iocb, sock, msg, size, flags); |
| 678 | } |
| 679 | |
Arnaldo Carvalho de Melo | a2e2725 | 2009-10-12 23:40:10 -0700 | [diff] [blame] | 680 | static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock, |
| 681 | struct msghdr *msg, size_t size, int flags) |
| 682 | { |
| 683 | int err = security_socket_recvmsg(sock, msg, size, flags); |
| 684 | |
| 685 | return err ?: __sock_recvmsg_nosec(iocb, sock, msg, size, flags); |
| 686 | } |
| 687 | |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 688 | int sock_recvmsg(struct socket *sock, struct msghdr *msg, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | size_t size, int flags) |
| 690 | { |
| 691 | struct kiocb iocb; |
| 692 | struct sock_iocb siocb; |
| 693 | int ret; |
| 694 | |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 695 | init_sync_kiocb(&iocb, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | iocb.private = &siocb; |
| 697 | ret = __sock_recvmsg(&iocb, sock, msg, size, flags); |
| 698 | if (-EIOCBQUEUED == ret) |
| 699 | ret = wait_on_sync_kiocb(&iocb); |
| 700 | return ret; |
| 701 | } |
| 702 | |
Arnaldo Carvalho de Melo | a2e2725 | 2009-10-12 23:40:10 -0700 | [diff] [blame] | 703 | static int sock_recvmsg_nosec(struct socket *sock, struct msghdr *msg, |
| 704 | size_t size, int flags) |
| 705 | { |
| 706 | struct kiocb iocb; |
| 707 | struct sock_iocb siocb; |
| 708 | int ret; |
| 709 | |
| 710 | init_sync_kiocb(&iocb, NULL); |
| 711 | iocb.private = &siocb; |
| 712 | ret = __sock_recvmsg_nosec(&iocb, sock, msg, size, flags); |
| 713 | if (-EIOCBQUEUED == ret) |
| 714 | ret = wait_on_sync_kiocb(&iocb); |
| 715 | return ret; |
| 716 | } |
| 717 | |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 718 | int kernel_recvmsg(struct socket *sock, struct msghdr *msg, |
| 719 | struct kvec *vec, size_t num, size_t size, int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | { |
| 721 | mm_segment_t oldfs = get_fs(); |
| 722 | int result; |
| 723 | |
| 724 | set_fs(KERNEL_DS); |
| 725 | /* |
| 726 | * the following is safe, since for compiler definitions of kvec and |
| 727 | * iovec are identical, yielding the same in-core layout and alignment |
| 728 | */ |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 729 | msg->msg_iov = (struct iovec *)vec, msg->msg_iovlen = num; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | result = sock_recvmsg(sock, msg, size, flags); |
| 731 | set_fs(oldfs); |
| 732 | return result; |
| 733 | } |
| 734 | |
| 735 | static void sock_aio_dtor(struct kiocb *iocb) |
| 736 | { |
| 737 | kfree(iocb->private); |
| 738 | } |
| 739 | |
Arnaldo Carvalho de Melo | 2038073 | 2005-08-16 02:18:02 -0300 | [diff] [blame] | 740 | static ssize_t sock_sendpage(struct file *file, struct page *page, |
| 741 | int offset, size_t size, loff_t *ppos, int more) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | { |
| 743 | struct socket *sock; |
| 744 | int flags; |
| 745 | |
Eric Dumazet | b69aee0 | 2005-09-06 14:42:45 -0700 | [diff] [blame] | 746 | sock = file->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | |
| 748 | flags = !(file->f_flags & O_NONBLOCK) ? 0 : MSG_DONTWAIT; |
| 749 | if (more) |
| 750 | flags |= MSG_MORE; |
| 751 | |
Linus Torvalds | e694958 | 2009-08-13 08:28:36 -0700 | [diff] [blame] | 752 | return kernel_sendpage(sock, page, offset, size, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | } |
| 754 | |
Jens Axboe | 9c55e01 | 2007-11-06 23:30:13 -0800 | [diff] [blame] | 755 | static ssize_t sock_splice_read(struct file *file, loff_t *ppos, |
| 756 | struct pipe_inode_info *pipe, size_t len, |
| 757 | unsigned int flags) |
| 758 | { |
| 759 | struct socket *sock = file->private_data; |
| 760 | |
Rémi Denis-Courmont | 997b37d | 2008-02-15 02:35:45 -0800 | [diff] [blame] | 761 | if (unlikely(!sock->ops->splice_read)) |
| 762 | return -EINVAL; |
| 763 | |
Jens Axboe | 9c55e01 | 2007-11-06 23:30:13 -0800 | [diff] [blame] | 764 | return sock->ops->splice_read(sock, ppos, pipe, len, flags); |
| 765 | } |
| 766 | |
Christoph Hellwig | ce1d4d3 | 2005-12-22 21:08:46 -0800 | [diff] [blame] | 767 | static struct sock_iocb *alloc_sock_iocb(struct kiocb *iocb, |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 768 | struct sock_iocb *siocb) |
Christoph Hellwig | ce1d4d3 | 2005-12-22 21:08:46 -0800 | [diff] [blame] | 769 | { |
| 770 | if (!is_sync_kiocb(iocb)) { |
| 771 | siocb = kmalloc(sizeof(*siocb), GFP_KERNEL); |
| 772 | if (!siocb) |
| 773 | return NULL; |
| 774 | iocb->ki_dtor = sock_aio_dtor; |
| 775 | } |
| 776 | |
| 777 | siocb->kiocb = iocb; |
Christoph Hellwig | ce1d4d3 | 2005-12-22 21:08:46 -0800 | [diff] [blame] | 778 | iocb->private = siocb; |
| 779 | return siocb; |
| 780 | } |
| 781 | |
| 782 | static ssize_t do_sock_read(struct msghdr *msg, struct kiocb *iocb, |
Badari Pulavarty | 027445c | 2006-09-30 23:28:46 -0700 | [diff] [blame] | 783 | struct file *file, const struct iovec *iov, |
| 784 | unsigned long nr_segs) |
Christoph Hellwig | ce1d4d3 | 2005-12-22 21:08:46 -0800 | [diff] [blame] | 785 | { |
| 786 | struct socket *sock = file->private_data; |
| 787 | size_t size = 0; |
| 788 | int i; |
| 789 | |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 790 | for (i = 0; i < nr_segs; i++) |
| 791 | size += iov[i].iov_len; |
Christoph Hellwig | ce1d4d3 | 2005-12-22 21:08:46 -0800 | [diff] [blame] | 792 | |
| 793 | msg->msg_name = NULL; |
| 794 | msg->msg_namelen = 0; |
| 795 | msg->msg_control = NULL; |
| 796 | msg->msg_controllen = 0; |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 797 | msg->msg_iov = (struct iovec *)iov; |
Christoph Hellwig | ce1d4d3 | 2005-12-22 21:08:46 -0800 | [diff] [blame] | 798 | msg->msg_iovlen = nr_segs; |
| 799 | msg->msg_flags = (file->f_flags & O_NONBLOCK) ? MSG_DONTWAIT : 0; |
| 800 | |
| 801 | return __sock_recvmsg(iocb, sock, msg, size, msg->msg_flags); |
| 802 | } |
| 803 | |
Badari Pulavarty | 027445c | 2006-09-30 23:28:46 -0700 | [diff] [blame] | 804 | static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov, |
| 805 | unsigned long nr_segs, loff_t pos) |
Christoph Hellwig | ce1d4d3 | 2005-12-22 21:08:46 -0800 | [diff] [blame] | 806 | { |
| 807 | struct sock_iocb siocb, *x; |
| 808 | |
| 809 | if (pos != 0) |
| 810 | return -ESPIPE; |
Badari Pulavarty | 027445c | 2006-09-30 23:28:46 -0700 | [diff] [blame] | 811 | |
| 812 | if (iocb->ki_left == 0) /* Match SYS5 behaviour */ |
Christoph Hellwig | ce1d4d3 | 2005-12-22 21:08:46 -0800 | [diff] [blame] | 813 | return 0; |
| 814 | |
Badari Pulavarty | 027445c | 2006-09-30 23:28:46 -0700 | [diff] [blame] | 815 | |
| 816 | x = alloc_sock_iocb(iocb, &siocb); |
Christoph Hellwig | ce1d4d3 | 2005-12-22 21:08:46 -0800 | [diff] [blame] | 817 | if (!x) |
| 818 | return -ENOMEM; |
Badari Pulavarty | 027445c | 2006-09-30 23:28:46 -0700 | [diff] [blame] | 819 | return do_sock_read(&x->async_msg, iocb, iocb->ki_filp, iov, nr_segs); |
Christoph Hellwig | ce1d4d3 | 2005-12-22 21:08:46 -0800 | [diff] [blame] | 820 | } |
| 821 | |
| 822 | static ssize_t do_sock_write(struct msghdr *msg, struct kiocb *iocb, |
Badari Pulavarty | 027445c | 2006-09-30 23:28:46 -0700 | [diff] [blame] | 823 | struct file *file, const struct iovec *iov, |
| 824 | unsigned long nr_segs) |
Christoph Hellwig | ce1d4d3 | 2005-12-22 21:08:46 -0800 | [diff] [blame] | 825 | { |
| 826 | struct socket *sock = file->private_data; |
| 827 | size_t size = 0; |
| 828 | int i; |
| 829 | |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 830 | for (i = 0; i < nr_segs; i++) |
| 831 | size += iov[i].iov_len; |
Christoph Hellwig | ce1d4d3 | 2005-12-22 21:08:46 -0800 | [diff] [blame] | 832 | |
| 833 | msg->msg_name = NULL; |
| 834 | msg->msg_namelen = 0; |
| 835 | msg->msg_control = NULL; |
| 836 | msg->msg_controllen = 0; |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 837 | msg->msg_iov = (struct iovec *)iov; |
Christoph Hellwig | ce1d4d3 | 2005-12-22 21:08:46 -0800 | [diff] [blame] | 838 | msg->msg_iovlen = nr_segs; |
| 839 | msg->msg_flags = (file->f_flags & O_NONBLOCK) ? MSG_DONTWAIT : 0; |
| 840 | if (sock->type == SOCK_SEQPACKET) |
| 841 | msg->msg_flags |= MSG_EOR; |
| 842 | |
| 843 | return __sock_sendmsg(iocb, sock, msg, size); |
| 844 | } |
| 845 | |
Badari Pulavarty | 027445c | 2006-09-30 23:28:46 -0700 | [diff] [blame] | 846 | static ssize_t sock_aio_write(struct kiocb *iocb, const struct iovec *iov, |
| 847 | unsigned long nr_segs, loff_t pos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 848 | { |
Christoph Hellwig | ce1d4d3 | 2005-12-22 21:08:46 -0800 | [diff] [blame] | 849 | struct sock_iocb siocb, *x; |
| 850 | |
| 851 | if (pos != 0) |
| 852 | return -ESPIPE; |
Badari Pulavarty | 027445c | 2006-09-30 23:28:46 -0700 | [diff] [blame] | 853 | |
Badari Pulavarty | 027445c | 2006-09-30 23:28:46 -0700 | [diff] [blame] | 854 | x = alloc_sock_iocb(iocb, &siocb); |
Christoph Hellwig | ce1d4d3 | 2005-12-22 21:08:46 -0800 | [diff] [blame] | 855 | if (!x) |
| 856 | return -ENOMEM; |
| 857 | |
Badari Pulavarty | 027445c | 2006-09-30 23:28:46 -0700 | [diff] [blame] | 858 | return do_sock_write(&x->async_msg, iocb, iocb->ki_filp, iov, nr_segs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | } |
| 860 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 861 | /* |
| 862 | * Atomic setting of ioctl hooks to avoid race |
| 863 | * with module unload. |
| 864 | */ |
| 865 | |
Arjan van de Ven | 4a3e2f7 | 2006-03-20 22:33:17 -0800 | [diff] [blame] | 866 | static DEFINE_MUTEX(br_ioctl_mutex); |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame] | 867 | static int (*br_ioctl_hook) (struct net *, unsigned int cmd, void __user *arg) = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame] | 869 | void brioctl_set(int (*hook) (struct net *, unsigned int, void __user *)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 870 | { |
Arjan van de Ven | 4a3e2f7 | 2006-03-20 22:33:17 -0800 | [diff] [blame] | 871 | mutex_lock(&br_ioctl_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | br_ioctl_hook = hook; |
Arjan van de Ven | 4a3e2f7 | 2006-03-20 22:33:17 -0800 | [diff] [blame] | 873 | mutex_unlock(&br_ioctl_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | } |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 875 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | EXPORT_SYMBOL(brioctl_set); |
| 877 | |
Arjan van de Ven | 4a3e2f7 | 2006-03-20 22:33:17 -0800 | [diff] [blame] | 878 | static DEFINE_MUTEX(vlan_ioctl_mutex); |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame] | 879 | static int (*vlan_ioctl_hook) (struct net *, void __user *arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame] | 881 | void vlan_ioctl_set(int (*hook) (struct net *, void __user *)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | { |
Arjan van de Ven | 4a3e2f7 | 2006-03-20 22:33:17 -0800 | [diff] [blame] | 883 | mutex_lock(&vlan_ioctl_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | vlan_ioctl_hook = hook; |
Arjan van de Ven | 4a3e2f7 | 2006-03-20 22:33:17 -0800 | [diff] [blame] | 885 | mutex_unlock(&vlan_ioctl_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | } |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 887 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | EXPORT_SYMBOL(vlan_ioctl_set); |
| 889 | |
Arjan van de Ven | 4a3e2f7 | 2006-03-20 22:33:17 -0800 | [diff] [blame] | 890 | static DEFINE_MUTEX(dlci_ioctl_mutex); |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 891 | static int (*dlci_ioctl_hook) (unsigned int, void __user *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 893 | void dlci_ioctl_set(int (*hook) (unsigned int, void __user *)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | { |
Arjan van de Ven | 4a3e2f7 | 2006-03-20 22:33:17 -0800 | [diff] [blame] | 895 | mutex_lock(&dlci_ioctl_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | dlci_ioctl_hook = hook; |
Arjan van de Ven | 4a3e2f7 | 2006-03-20 22:33:17 -0800 | [diff] [blame] | 897 | mutex_unlock(&dlci_ioctl_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | } |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 899 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | EXPORT_SYMBOL(dlci_ioctl_set); |
| 901 | |
Arnd Bergmann | 6b96018 | 2009-11-06 23:10:54 -0800 | [diff] [blame] | 902 | static long sock_do_ioctl(struct net *net, struct socket *sock, |
| 903 | unsigned int cmd, unsigned long arg) |
| 904 | { |
| 905 | int err; |
| 906 | void __user *argp = (void __user *)arg; |
| 907 | |
| 908 | err = sock->ops->ioctl(sock, cmd, arg); |
| 909 | |
| 910 | /* |
| 911 | * If this ioctl is unknown try to hand it down |
| 912 | * to the NIC driver. |
| 913 | */ |
| 914 | if (err == -ENOIOCTLCMD) |
| 915 | err = dev_ioctl(net, cmd, argp); |
| 916 | |
| 917 | return err; |
| 918 | } |
| 919 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | /* |
| 921 | * With an ioctl, arg may well be a user mode pointer, but we don't know |
| 922 | * what to do with it - that's up to the protocol still. |
| 923 | */ |
| 924 | |
| 925 | static long sock_ioctl(struct file *file, unsigned cmd, unsigned long arg) |
| 926 | { |
| 927 | struct socket *sock; |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame] | 928 | struct sock *sk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | void __user *argp = (void __user *)arg; |
| 930 | int pid, err; |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame] | 931 | struct net *net; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | |
Eric Dumazet | b69aee0 | 2005-09-06 14:42:45 -0700 | [diff] [blame] | 933 | sock = file->private_data; |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame] | 934 | sk = sock->sk; |
YOSHIFUJI Hideaki | 3b1e0a6 | 2008-03-26 02:26:21 +0900 | [diff] [blame] | 935 | net = sock_net(sk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 936 | if (cmd >= SIOCDEVPRIVATE && cmd <= (SIOCDEVPRIVATE + 15)) { |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame] | 937 | err = dev_ioctl(net, cmd, argp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 | } else |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 939 | #ifdef CONFIG_WEXT_CORE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | if (cmd >= SIOCIWFIRST && cmd <= SIOCIWLAST) { |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame] | 941 | err = dev_ioctl(net, cmd, argp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 | } else |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 943 | #endif |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 944 | switch (cmd) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 945 | case FIOSETOWN: |
| 946 | case SIOCSPGRP: |
| 947 | err = -EFAULT; |
| 948 | if (get_user(pid, (int __user *)argp)) |
| 949 | break; |
| 950 | err = f_setown(sock->file, pid, 1); |
| 951 | break; |
| 952 | case FIOGETOWN: |
| 953 | case SIOCGPGRP: |
Eric W. Biederman | 609d7fa | 2006-10-02 02:17:15 -0700 | [diff] [blame] | 954 | err = put_user(f_getown(sock->file), |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 955 | (int __user *)argp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 956 | break; |
| 957 | case SIOCGIFBR: |
| 958 | case SIOCSIFBR: |
| 959 | case SIOCBRADDBR: |
| 960 | case SIOCBRDELBR: |
| 961 | err = -ENOPKG; |
| 962 | if (!br_ioctl_hook) |
| 963 | request_module("bridge"); |
| 964 | |
Arjan van de Ven | 4a3e2f7 | 2006-03-20 22:33:17 -0800 | [diff] [blame] | 965 | mutex_lock(&br_ioctl_mutex); |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 966 | if (br_ioctl_hook) |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame] | 967 | err = br_ioctl_hook(net, cmd, argp); |
Arjan van de Ven | 4a3e2f7 | 2006-03-20 22:33:17 -0800 | [diff] [blame] | 968 | mutex_unlock(&br_ioctl_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 969 | break; |
| 970 | case SIOCGIFVLAN: |
| 971 | case SIOCSIFVLAN: |
| 972 | err = -ENOPKG; |
| 973 | if (!vlan_ioctl_hook) |
| 974 | request_module("8021q"); |
| 975 | |
Arjan van de Ven | 4a3e2f7 | 2006-03-20 22:33:17 -0800 | [diff] [blame] | 976 | mutex_lock(&vlan_ioctl_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 977 | if (vlan_ioctl_hook) |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame] | 978 | err = vlan_ioctl_hook(net, argp); |
Arjan van de Ven | 4a3e2f7 | 2006-03-20 22:33:17 -0800 | [diff] [blame] | 979 | mutex_unlock(&vlan_ioctl_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 980 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | case SIOCADDDLCI: |
| 982 | case SIOCDELDLCI: |
| 983 | err = -ENOPKG; |
| 984 | if (!dlci_ioctl_hook) |
| 985 | request_module("dlci"); |
| 986 | |
Pavel Emelyanov | 7512cbf | 2008-03-21 15:58:52 -0700 | [diff] [blame] | 987 | mutex_lock(&dlci_ioctl_mutex); |
| 988 | if (dlci_ioctl_hook) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 989 | err = dlci_ioctl_hook(cmd, argp); |
Pavel Emelyanov | 7512cbf | 2008-03-21 15:58:52 -0700 | [diff] [blame] | 990 | mutex_unlock(&dlci_ioctl_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 991 | break; |
| 992 | default: |
Arnd Bergmann | 6b96018 | 2009-11-06 23:10:54 -0800 | [diff] [blame] | 993 | err = sock_do_ioctl(net, sock, cmd, arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 994 | break; |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 995 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 996 | return err; |
| 997 | } |
| 998 | |
| 999 | int sock_create_lite(int family, int type, int protocol, struct socket **res) |
| 1000 | { |
| 1001 | int err; |
| 1002 | struct socket *sock = NULL; |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1003 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1004 | err = security_socket_create(family, type, protocol, 1); |
| 1005 | if (err) |
| 1006 | goto out; |
| 1007 | |
| 1008 | sock = sock_alloc(); |
| 1009 | if (!sock) { |
| 1010 | err = -ENOMEM; |
| 1011 | goto out; |
| 1012 | } |
| 1013 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1014 | sock->type = type; |
Venkat Yekkirala | 7420ed2 | 2006-08-04 23:17:57 -0700 | [diff] [blame] | 1015 | err = security_socket_post_create(sock, family, type, protocol, 1); |
| 1016 | if (err) |
| 1017 | goto out_release; |
| 1018 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1019 | out: |
| 1020 | *res = sock; |
| 1021 | return err; |
Venkat Yekkirala | 7420ed2 | 2006-08-04 23:17:57 -0700 | [diff] [blame] | 1022 | out_release: |
| 1023 | sock_release(sock); |
| 1024 | sock = NULL; |
| 1025 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1026 | } |
| 1027 | |
| 1028 | /* No kernel lock held - perfect */ |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1029 | static unsigned int sock_poll(struct file *file, poll_table *wait) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | { |
| 1031 | struct socket *sock; |
| 1032 | |
| 1033 | /* |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1034 | * We can't return errors to poll, so it's either yes or no. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1035 | */ |
Eric Dumazet | b69aee0 | 2005-09-06 14:42:45 -0700 | [diff] [blame] | 1036 | sock = file->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | return sock->ops->poll(file, sock, wait); |
| 1038 | } |
| 1039 | |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1040 | static int sock_mmap(struct file *file, struct vm_area_struct *vma) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | { |
Eric Dumazet | b69aee0 | 2005-09-06 14:42:45 -0700 | [diff] [blame] | 1042 | struct socket *sock = file->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1043 | |
| 1044 | return sock->ops->mmap(file, sock, vma); |
| 1045 | } |
| 1046 | |
Arnaldo Carvalho de Melo | 2038073 | 2005-08-16 02:18:02 -0300 | [diff] [blame] | 1047 | static int sock_close(struct inode *inode, struct file *filp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1048 | { |
| 1049 | /* |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1050 | * It was possible the inode is NULL we were |
| 1051 | * closing an unfinished socket. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1052 | */ |
| 1053 | |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1054 | if (!inode) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1055 | printk(KERN_DEBUG "sock_close: NULL inode\n"); |
| 1056 | return 0; |
| 1057 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1058 | sock_release(SOCKET_I(inode)); |
| 1059 | return 0; |
| 1060 | } |
| 1061 | |
| 1062 | /* |
| 1063 | * Update the socket async list |
| 1064 | * |
| 1065 | * Fasync_list locking strategy. |
| 1066 | * |
| 1067 | * 1. fasync_list is modified only under process context socket lock |
| 1068 | * i.e. under semaphore. |
| 1069 | * 2. fasync_list is used under read_lock(&sk->sk_callback_lock) |
Eric Dumazet | 989a297 | 2010-04-14 09:55:35 +0000 | [diff] [blame^] | 1070 | * or under socket lock |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1071 | */ |
| 1072 | |
| 1073 | static int sock_fasync(int fd, struct file *filp, int on) |
| 1074 | { |
Eric Dumazet | 989a297 | 2010-04-14 09:55:35 +0000 | [diff] [blame^] | 1075 | struct socket *sock = filp->private_data; |
| 1076 | struct sock *sk = sock->sk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1077 | |
Eric Dumazet | 989a297 | 2010-04-14 09:55:35 +0000 | [diff] [blame^] | 1078 | if (sk == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1079 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1080 | |
| 1081 | lock_sock(sk); |
| 1082 | |
Eric Dumazet | 989a297 | 2010-04-14 09:55:35 +0000 | [diff] [blame^] | 1083 | fasync_helper(fd, filp, on, &sock->fasync_list); |
| 1084 | |
| 1085 | if (!sock->fasync_list) |
| 1086 | sock_reset_flag(sk, SOCK_FASYNC); |
Jonathan Corbet | 7639842 | 2009-02-01 14:26:59 -0700 | [diff] [blame] | 1087 | else |
Eric Dumazet | bcdce71 | 2009-10-06 17:28:29 -0700 | [diff] [blame] | 1088 | sock_set_flag(sk, SOCK_FASYNC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1089 | |
Eric Dumazet | 989a297 | 2010-04-14 09:55:35 +0000 | [diff] [blame^] | 1090 | release_sock(sk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1091 | return 0; |
| 1092 | } |
| 1093 | |
| 1094 | /* This function may be called only under socket lock or callback_lock */ |
| 1095 | |
| 1096 | int sock_wake_async(struct socket *sock, int how, int band) |
| 1097 | { |
| 1098 | if (!sock || !sock->fasync_list) |
| 1099 | return -1; |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1100 | switch (how) { |
Pavel Emelyanov | 8d8ad9d | 2007-11-26 20:10:50 +0800 | [diff] [blame] | 1101 | case SOCK_WAKE_WAITD: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1102 | if (test_bit(SOCK_ASYNC_WAITDATA, &sock->flags)) |
| 1103 | break; |
| 1104 | goto call_kill; |
Pavel Emelyanov | 8d8ad9d | 2007-11-26 20:10:50 +0800 | [diff] [blame] | 1105 | case SOCK_WAKE_SPACE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1106 | if (!test_and_clear_bit(SOCK_ASYNC_NOSPACE, &sock->flags)) |
| 1107 | break; |
| 1108 | /* fall through */ |
Pavel Emelyanov | 8d8ad9d | 2007-11-26 20:10:50 +0800 | [diff] [blame] | 1109 | case SOCK_WAKE_IO: |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1110 | call_kill: |
Eric Dumazet | 989a297 | 2010-04-14 09:55:35 +0000 | [diff] [blame^] | 1111 | kill_fasync(&sock->fasync_list, SIGIO, band); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1112 | break; |
Pavel Emelyanov | 8d8ad9d | 2007-11-26 20:10:50 +0800 | [diff] [blame] | 1113 | case SOCK_WAKE_URG: |
Eric Dumazet | 989a297 | 2010-04-14 09:55:35 +0000 | [diff] [blame^] | 1114 | kill_fasync(&sock->fasync_list, SIGURG, band); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1115 | } |
| 1116 | return 0; |
| 1117 | } |
| 1118 | |
Eric W. Biederman | 1b8d7ae | 2007-10-08 23:24:22 -0700 | [diff] [blame] | 1119 | static int __sock_create(struct net *net, int family, int type, int protocol, |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1120 | struct socket **res, int kern) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1121 | { |
| 1122 | int err; |
| 1123 | struct socket *sock; |
Stephen Hemminger | 55737fd | 2006-09-01 00:23:39 -0700 | [diff] [blame] | 1124 | const struct net_proto_family *pf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1125 | |
| 1126 | /* |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1127 | * Check protocol is in range |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1128 | */ |
| 1129 | if (family < 0 || family >= NPROTO) |
| 1130 | return -EAFNOSUPPORT; |
| 1131 | if (type < 0 || type >= SOCK_MAX) |
| 1132 | return -EINVAL; |
| 1133 | |
| 1134 | /* Compatibility. |
| 1135 | |
| 1136 | This uglymoron is moved from INET layer to here to avoid |
| 1137 | deadlock in module load. |
| 1138 | */ |
| 1139 | if (family == PF_INET && type == SOCK_PACKET) { |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1140 | static int warned; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1141 | if (!warned) { |
| 1142 | warned = 1; |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1143 | printk(KERN_INFO "%s uses obsolete (PF_INET,SOCK_PACKET)\n", |
| 1144 | current->comm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1145 | } |
| 1146 | family = PF_PACKET; |
| 1147 | } |
| 1148 | |
| 1149 | err = security_socket_create(family, type, protocol, kern); |
| 1150 | if (err) |
| 1151 | return err; |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1152 | |
Stephen Hemminger | 55737fd | 2006-09-01 00:23:39 -0700 | [diff] [blame] | 1153 | /* |
| 1154 | * Allocate the socket and allow the family to set things up. if |
| 1155 | * the protocol is 0, the family is instructed to select an appropriate |
| 1156 | * default. |
| 1157 | */ |
| 1158 | sock = sock_alloc(); |
| 1159 | if (!sock) { |
| 1160 | if (net_ratelimit()) |
| 1161 | printk(KERN_WARNING "socket: no more sockets\n"); |
| 1162 | return -ENFILE; /* Not exactly a match, but its the |
| 1163 | closest posix thing */ |
| 1164 | } |
| 1165 | |
| 1166 | sock->type = type; |
| 1167 | |
Johannes Berg | 95a5afc | 2008-10-16 15:24:51 -0700 | [diff] [blame] | 1168 | #ifdef CONFIG_MODULES |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1169 | /* Attempt to load a protocol module if the find failed. |
| 1170 | * |
| 1171 | * 12/09/1996 Marcin: But! this makes REALLY only sense, if the user |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1172 | * requested real, full-featured networking support upon configuration. |
| 1173 | * Otherwise module support will break! |
| 1174 | */ |
Stephen Hemminger | 55737fd | 2006-09-01 00:23:39 -0700 | [diff] [blame] | 1175 | if (net_families[family] == NULL) |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1176 | request_module("net-pf-%d", family); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1177 | #endif |
| 1178 | |
Stephen Hemminger | 55737fd | 2006-09-01 00:23:39 -0700 | [diff] [blame] | 1179 | rcu_read_lock(); |
| 1180 | pf = rcu_dereference(net_families[family]); |
| 1181 | err = -EAFNOSUPPORT; |
| 1182 | if (!pf) |
| 1183 | goto out_release; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1184 | |
| 1185 | /* |
| 1186 | * We will call the ->create function, that possibly is in a loadable |
| 1187 | * module, so we have to bump that loadable module refcnt first. |
| 1188 | */ |
Stephen Hemminger | 55737fd | 2006-09-01 00:23:39 -0700 | [diff] [blame] | 1189 | if (!try_module_get(pf->owner)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1190 | goto out_release; |
| 1191 | |
Stephen Hemminger | 55737fd | 2006-09-01 00:23:39 -0700 | [diff] [blame] | 1192 | /* Now protected by module ref count */ |
| 1193 | rcu_read_unlock(); |
| 1194 | |
Eric Paris | 3f378b6 | 2009-11-05 22:18:14 -0800 | [diff] [blame] | 1195 | err = pf->create(net, sock, protocol, kern); |
Stephen Hemminger | 55737fd | 2006-09-01 00:23:39 -0700 | [diff] [blame] | 1196 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1197 | goto out_module_put; |
Frank Filz | a79af59 | 2005-09-27 15:23:38 -0700 | [diff] [blame] | 1198 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1199 | /* |
| 1200 | * Now to bump the refcnt of the [loadable] module that owns this |
| 1201 | * socket at sock_release time we decrement its refcnt. |
| 1202 | */ |
Stephen Hemminger | 55737fd | 2006-09-01 00:23:39 -0700 | [diff] [blame] | 1203 | if (!try_module_get(sock->ops->owner)) |
| 1204 | goto out_module_busy; |
| 1205 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1206 | /* |
| 1207 | * Now that we're done with the ->create function, the [loadable] |
| 1208 | * module can have its refcnt decremented |
| 1209 | */ |
Stephen Hemminger | 55737fd | 2006-09-01 00:23:39 -0700 | [diff] [blame] | 1210 | module_put(pf->owner); |
Venkat Yekkirala | 7420ed2 | 2006-08-04 23:17:57 -0700 | [diff] [blame] | 1211 | err = security_socket_post_create(sock, family, type, protocol, kern); |
| 1212 | if (err) |
Herbert Xu | 3b18552 | 2007-08-15 14:46:02 -0700 | [diff] [blame] | 1213 | goto out_sock_release; |
Stephen Hemminger | 55737fd | 2006-09-01 00:23:39 -0700 | [diff] [blame] | 1214 | *res = sock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1215 | |
Stephen Hemminger | 55737fd | 2006-09-01 00:23:39 -0700 | [diff] [blame] | 1216 | return 0; |
| 1217 | |
| 1218 | out_module_busy: |
| 1219 | err = -EAFNOSUPPORT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1220 | out_module_put: |
Stephen Hemminger | 55737fd | 2006-09-01 00:23:39 -0700 | [diff] [blame] | 1221 | sock->ops = NULL; |
| 1222 | module_put(pf->owner); |
| 1223 | out_sock_release: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1224 | sock_release(sock); |
Stephen Hemminger | 55737fd | 2006-09-01 00:23:39 -0700 | [diff] [blame] | 1225 | return err; |
| 1226 | |
| 1227 | out_release: |
| 1228 | rcu_read_unlock(); |
| 1229 | goto out_sock_release; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1230 | } |
| 1231 | |
| 1232 | int sock_create(int family, int type, int protocol, struct socket **res) |
| 1233 | { |
Eric W. Biederman | 1b8d7ae | 2007-10-08 23:24:22 -0700 | [diff] [blame] | 1234 | return __sock_create(current->nsproxy->net_ns, family, type, protocol, res, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1235 | } |
| 1236 | |
| 1237 | int sock_create_kern(int family, int type, int protocol, struct socket **res) |
| 1238 | { |
Eric W. Biederman | 1b8d7ae | 2007-10-08 23:24:22 -0700 | [diff] [blame] | 1239 | return __sock_create(&init_net, family, type, protocol, res, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1240 | } |
| 1241 | |
Heiko Carstens | 3e0fa65 | 2009-01-14 14:14:24 +0100 | [diff] [blame] | 1242 | SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1243 | { |
| 1244 | int retval; |
| 1245 | struct socket *sock; |
Ulrich Drepper | a677a03 | 2008-07-23 21:29:17 -0700 | [diff] [blame] | 1246 | int flags; |
| 1247 | |
Ulrich Drepper | e38b36f | 2008-07-23 21:29:42 -0700 | [diff] [blame] | 1248 | /* Check the SOCK_* constants for consistency. */ |
| 1249 | BUILD_BUG_ON(SOCK_CLOEXEC != O_CLOEXEC); |
| 1250 | BUILD_BUG_ON((SOCK_MAX | SOCK_TYPE_MASK) != SOCK_TYPE_MASK); |
| 1251 | BUILD_BUG_ON(SOCK_CLOEXEC & SOCK_TYPE_MASK); |
| 1252 | BUILD_BUG_ON(SOCK_NONBLOCK & SOCK_TYPE_MASK); |
| 1253 | |
Ulrich Drepper | a677a03 | 2008-07-23 21:29:17 -0700 | [diff] [blame] | 1254 | flags = type & ~SOCK_TYPE_MASK; |
Ulrich Drepper | 77d2720 | 2008-07-23 21:29:35 -0700 | [diff] [blame] | 1255 | if (flags & ~(SOCK_CLOEXEC | SOCK_NONBLOCK)) |
Ulrich Drepper | a677a03 | 2008-07-23 21:29:17 -0700 | [diff] [blame] | 1256 | return -EINVAL; |
| 1257 | type &= SOCK_TYPE_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1258 | |
Ulrich Drepper | aaca0bd | 2008-07-23 21:29:20 -0700 | [diff] [blame] | 1259 | if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK)) |
| 1260 | flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK; |
| 1261 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1262 | retval = sock_create(family, type, protocol, &sock); |
| 1263 | if (retval < 0) |
| 1264 | goto out; |
| 1265 | |
Ulrich Drepper | 77d2720 | 2008-07-23 21:29:35 -0700 | [diff] [blame] | 1266 | retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1267 | if (retval < 0) |
| 1268 | goto out_release; |
| 1269 | |
| 1270 | out: |
| 1271 | /* It may be already another descriptor 8) Not kernel problem. */ |
| 1272 | return retval; |
| 1273 | |
| 1274 | out_release: |
| 1275 | sock_release(sock); |
| 1276 | return retval; |
| 1277 | } |
| 1278 | |
| 1279 | /* |
| 1280 | * Create a pair of connected sockets. |
| 1281 | */ |
| 1282 | |
Heiko Carstens | 3e0fa65 | 2009-01-14 14:14:24 +0100 | [diff] [blame] | 1283 | SYSCALL_DEFINE4(socketpair, int, family, int, type, int, protocol, |
| 1284 | int __user *, usockvec) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1285 | { |
| 1286 | struct socket *sock1, *sock2; |
| 1287 | int fd1, fd2, err; |
Al Viro | db34950 | 2007-02-07 01:48:00 -0500 | [diff] [blame] | 1288 | struct file *newfile1, *newfile2; |
Ulrich Drepper | a677a03 | 2008-07-23 21:29:17 -0700 | [diff] [blame] | 1289 | int flags; |
| 1290 | |
| 1291 | flags = type & ~SOCK_TYPE_MASK; |
Ulrich Drepper | 77d2720 | 2008-07-23 21:29:35 -0700 | [diff] [blame] | 1292 | if (flags & ~(SOCK_CLOEXEC | SOCK_NONBLOCK)) |
Ulrich Drepper | a677a03 | 2008-07-23 21:29:17 -0700 | [diff] [blame] | 1293 | return -EINVAL; |
| 1294 | type &= SOCK_TYPE_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1295 | |
Ulrich Drepper | aaca0bd | 2008-07-23 21:29:20 -0700 | [diff] [blame] | 1296 | if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK)) |
| 1297 | flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK; |
| 1298 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1299 | /* |
| 1300 | * Obtain the first socket and check if the underlying protocol |
| 1301 | * supports the socketpair call. |
| 1302 | */ |
| 1303 | |
| 1304 | err = sock_create(family, type, protocol, &sock1); |
| 1305 | if (err < 0) |
| 1306 | goto out; |
| 1307 | |
| 1308 | err = sock_create(family, type, protocol, &sock2); |
| 1309 | if (err < 0) |
| 1310 | goto out_release_1; |
| 1311 | |
| 1312 | err = sock1->ops->socketpair(sock1, sock2); |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1313 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1314 | goto out_release_both; |
| 1315 | |
Al Viro | 7cbe66b | 2009-08-05 19:59:08 +0400 | [diff] [blame] | 1316 | fd1 = sock_alloc_file(sock1, &newfile1, flags); |
David S. Miller | bf3c23d | 2007-10-29 21:54:02 -0700 | [diff] [blame] | 1317 | if (unlikely(fd1 < 0)) { |
| 1318 | err = fd1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1319 | goto out_release_both; |
David S. Miller | bf3c23d | 2007-10-29 21:54:02 -0700 | [diff] [blame] | 1320 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1321 | |
Al Viro | 7cbe66b | 2009-08-05 19:59:08 +0400 | [diff] [blame] | 1322 | fd2 = sock_alloc_file(sock2, &newfile2, flags); |
Al Viro | 198de4d | 2009-08-05 19:29:23 +0400 | [diff] [blame] | 1323 | if (unlikely(fd2 < 0)) { |
| 1324 | err = fd2; |
| 1325 | fput(newfile1); |
| 1326 | put_unused_fd(fd1); |
| 1327 | sock_release(sock2); |
| 1328 | goto out; |
Al Viro | db34950 | 2007-02-07 01:48:00 -0500 | [diff] [blame] | 1329 | } |
| 1330 | |
Al Viro | 157cf64 | 2008-12-14 04:57:47 -0500 | [diff] [blame] | 1331 | audit_fd_pair(fd1, fd2); |
Al Viro | db34950 | 2007-02-07 01:48:00 -0500 | [diff] [blame] | 1332 | fd_install(fd1, newfile1); |
| 1333 | fd_install(fd2, newfile2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1334 | /* fd1 and fd2 may be already another descriptors. |
| 1335 | * Not kernel problem. |
| 1336 | */ |
| 1337 | |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1338 | err = put_user(fd1, &usockvec[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1339 | if (!err) |
| 1340 | err = put_user(fd2, &usockvec[1]); |
| 1341 | if (!err) |
| 1342 | return 0; |
| 1343 | |
| 1344 | sys_close(fd2); |
| 1345 | sys_close(fd1); |
| 1346 | return err; |
| 1347 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1348 | out_release_both: |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1349 | sock_release(sock2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1350 | out_release_1: |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1351 | sock_release(sock1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1352 | out: |
| 1353 | return err; |
| 1354 | } |
| 1355 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1356 | /* |
| 1357 | * Bind a name to a socket. Nothing much to do here since it's |
| 1358 | * the protocol's responsibility to handle the local address. |
| 1359 | * |
| 1360 | * We move the socket address to kernel space before we call |
| 1361 | * the protocol layer (having also checked the address is ok). |
| 1362 | */ |
| 1363 | |
Heiko Carstens | 20f3703 | 2009-01-14 14:14:23 +0100 | [diff] [blame] | 1364 | SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1365 | { |
| 1366 | struct socket *sock; |
YOSHIFUJI Hideaki | 230b183 | 2008-07-19 22:35:47 -0700 | [diff] [blame] | 1367 | struct sockaddr_storage address; |
Benjamin LaHaise | 6cb153c | 2006-03-20 22:27:12 -0800 | [diff] [blame] | 1368 | int err, fput_needed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1369 | |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1370 | sock = sockfd_lookup_light(fd, &err, &fput_needed); |
Stephen Hemminger | e71a478 | 2007-04-10 20:10:33 -0700 | [diff] [blame] | 1371 | if (sock) { |
YOSHIFUJI Hideaki | 230b183 | 2008-07-19 22:35:47 -0700 | [diff] [blame] | 1372 | err = move_addr_to_kernel(umyaddr, addrlen, (struct sockaddr *)&address); |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1373 | if (err >= 0) { |
| 1374 | err = security_socket_bind(sock, |
YOSHIFUJI Hideaki | 230b183 | 2008-07-19 22:35:47 -0700 | [diff] [blame] | 1375 | (struct sockaddr *)&address, |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1376 | addrlen); |
Benjamin LaHaise | 6cb153c | 2006-03-20 22:27:12 -0800 | [diff] [blame] | 1377 | if (!err) |
| 1378 | err = sock->ops->bind(sock, |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1379 | (struct sockaddr *) |
YOSHIFUJI Hideaki | 230b183 | 2008-07-19 22:35:47 -0700 | [diff] [blame] | 1380 | &address, addrlen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1381 | } |
Benjamin LaHaise | 6cb153c | 2006-03-20 22:27:12 -0800 | [diff] [blame] | 1382 | fput_light(sock->file, fput_needed); |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1383 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1384 | return err; |
| 1385 | } |
| 1386 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1387 | /* |
| 1388 | * Perform a listen. Basically, we allow the protocol to do anything |
| 1389 | * necessary for a listen, and if that works, we mark the socket as |
| 1390 | * ready for listening. |
| 1391 | */ |
| 1392 | |
Heiko Carstens | 3e0fa65 | 2009-01-14 14:14:24 +0100 | [diff] [blame] | 1393 | SYSCALL_DEFINE2(listen, int, fd, int, backlog) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1394 | { |
| 1395 | struct socket *sock; |
Benjamin LaHaise | 6cb153c | 2006-03-20 22:27:12 -0800 | [diff] [blame] | 1396 | int err, fput_needed; |
Pavel Emelyanov | b8e1f9b | 2007-12-08 00:12:33 -0800 | [diff] [blame] | 1397 | int somaxconn; |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1398 | |
| 1399 | sock = sockfd_lookup_light(fd, &err, &fput_needed); |
| 1400 | if (sock) { |
Pavel Emelyanov | 8efa6e9 | 2008-03-31 19:41:14 -0700 | [diff] [blame] | 1401 | somaxconn = sock_net(sock->sk)->core.sysctl_somaxconn; |
Pavel Emelyanov | b8e1f9b | 2007-12-08 00:12:33 -0800 | [diff] [blame] | 1402 | if ((unsigned)backlog > somaxconn) |
| 1403 | backlog = somaxconn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1404 | |
| 1405 | err = security_socket_listen(sock, backlog); |
Benjamin LaHaise | 6cb153c | 2006-03-20 22:27:12 -0800 | [diff] [blame] | 1406 | if (!err) |
| 1407 | err = sock->ops->listen(sock, backlog); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1408 | |
Benjamin LaHaise | 6cb153c | 2006-03-20 22:27:12 -0800 | [diff] [blame] | 1409 | fput_light(sock->file, fput_needed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1410 | } |
| 1411 | return err; |
| 1412 | } |
| 1413 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1414 | /* |
| 1415 | * For accept, we attempt to create a new socket, set up the link |
| 1416 | * with the client, wake up the client, then return the new |
| 1417 | * connected fd. We collect the address of the connector in kernel |
| 1418 | * space and move it to user at the very end. This is unclean because |
| 1419 | * we open the socket then return an error. |
| 1420 | * |
| 1421 | * 1003.1g adds the ability to recvmsg() to query connection pending |
| 1422 | * status to recvmsg. We need to add that support in a way thats |
| 1423 | * clean when we restucture accept also. |
| 1424 | */ |
| 1425 | |
Heiko Carstens | 20f3703 | 2009-01-14 14:14:23 +0100 | [diff] [blame] | 1426 | SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr, |
| 1427 | int __user *, upeer_addrlen, int, flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1428 | { |
| 1429 | struct socket *sock, *newsock; |
David S. Miller | 39d8c1b | 2006-03-20 17:13:49 -0800 | [diff] [blame] | 1430 | struct file *newfile; |
Benjamin LaHaise | 6cb153c | 2006-03-20 22:27:12 -0800 | [diff] [blame] | 1431 | int err, len, newfd, fput_needed; |
YOSHIFUJI Hideaki | 230b183 | 2008-07-19 22:35:47 -0700 | [diff] [blame] | 1432 | struct sockaddr_storage address; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1433 | |
Ulrich Drepper | 77d2720 | 2008-07-23 21:29:35 -0700 | [diff] [blame] | 1434 | if (flags & ~(SOCK_CLOEXEC | SOCK_NONBLOCK)) |
Ulrich Drepper | aaca0bd | 2008-07-23 21:29:20 -0700 | [diff] [blame] | 1435 | return -EINVAL; |
| 1436 | |
| 1437 | if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK)) |
| 1438 | flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK; |
| 1439 | |
Benjamin LaHaise | 6cb153c | 2006-03-20 22:27:12 -0800 | [diff] [blame] | 1440 | sock = sockfd_lookup_light(fd, &err, &fput_needed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1441 | if (!sock) |
| 1442 | goto out; |
| 1443 | |
| 1444 | err = -ENFILE; |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1445 | if (!(newsock = sock_alloc())) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1446 | goto out_put; |
| 1447 | |
| 1448 | newsock->type = sock->type; |
| 1449 | newsock->ops = sock->ops; |
| 1450 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1451 | /* |
| 1452 | * We don't need try_module_get here, as the listening socket (sock) |
| 1453 | * has the protocol module (sock->ops->owner) held. |
| 1454 | */ |
| 1455 | __module_get(newsock->ops->owner); |
| 1456 | |
Al Viro | 7cbe66b | 2009-08-05 19:59:08 +0400 | [diff] [blame] | 1457 | newfd = sock_alloc_file(newsock, &newfile, flags); |
David S. Miller | 39d8c1b | 2006-03-20 17:13:49 -0800 | [diff] [blame] | 1458 | if (unlikely(newfd < 0)) { |
| 1459 | err = newfd; |
David S. Miller | 9a1875e | 2006-04-01 12:48:36 -0800 | [diff] [blame] | 1460 | sock_release(newsock); |
| 1461 | goto out_put; |
David S. Miller | 39d8c1b | 2006-03-20 17:13:49 -0800 | [diff] [blame] | 1462 | } |
| 1463 | |
Frank Filz | a79af59 | 2005-09-27 15:23:38 -0700 | [diff] [blame] | 1464 | err = security_socket_accept(sock, newsock); |
| 1465 | if (err) |
David S. Miller | 39d8c1b | 2006-03-20 17:13:49 -0800 | [diff] [blame] | 1466 | goto out_fd; |
Frank Filz | a79af59 | 2005-09-27 15:23:38 -0700 | [diff] [blame] | 1467 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1468 | err = sock->ops->accept(sock, newsock, sock->file->f_flags); |
| 1469 | if (err < 0) |
David S. Miller | 39d8c1b | 2006-03-20 17:13:49 -0800 | [diff] [blame] | 1470 | goto out_fd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1471 | |
| 1472 | if (upeer_sockaddr) { |
YOSHIFUJI Hideaki | 230b183 | 2008-07-19 22:35:47 -0700 | [diff] [blame] | 1473 | if (newsock->ops->getname(newsock, (struct sockaddr *)&address, |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1474 | &len, 2) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1475 | err = -ECONNABORTED; |
David S. Miller | 39d8c1b | 2006-03-20 17:13:49 -0800 | [diff] [blame] | 1476 | goto out_fd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1477 | } |
YOSHIFUJI Hideaki | 230b183 | 2008-07-19 22:35:47 -0700 | [diff] [blame] | 1478 | err = move_addr_to_user((struct sockaddr *)&address, |
| 1479 | len, upeer_sockaddr, upeer_addrlen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1480 | if (err < 0) |
David S. Miller | 39d8c1b | 2006-03-20 17:13:49 -0800 | [diff] [blame] | 1481 | goto out_fd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1482 | } |
| 1483 | |
| 1484 | /* File flags are not inherited via accept() unlike another OSes. */ |
| 1485 | |
David S. Miller | 39d8c1b | 2006-03-20 17:13:49 -0800 | [diff] [blame] | 1486 | fd_install(newfd, newfile); |
| 1487 | err = newfd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1488 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1489 | out_put: |
Benjamin LaHaise | 6cb153c | 2006-03-20 22:27:12 -0800 | [diff] [blame] | 1490 | fput_light(sock->file, fput_needed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1491 | out: |
| 1492 | return err; |
David S. Miller | 39d8c1b | 2006-03-20 17:13:49 -0800 | [diff] [blame] | 1493 | out_fd: |
David S. Miller | 9606a21 | 2006-04-01 01:00:14 -0800 | [diff] [blame] | 1494 | fput(newfile); |
David S. Miller | 39d8c1b | 2006-03-20 17:13:49 -0800 | [diff] [blame] | 1495 | put_unused_fd(newfd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1496 | goto out_put; |
| 1497 | } |
| 1498 | |
Heiko Carstens | 20f3703 | 2009-01-14 14:14:23 +0100 | [diff] [blame] | 1499 | SYSCALL_DEFINE3(accept, int, fd, struct sockaddr __user *, upeer_sockaddr, |
| 1500 | int __user *, upeer_addrlen) |
Ulrich Drepper | aaca0bd | 2008-07-23 21:29:20 -0700 | [diff] [blame] | 1501 | { |
Ulrich Drepper | de11def | 2008-11-19 15:36:14 -0800 | [diff] [blame] | 1502 | return sys_accept4(fd, upeer_sockaddr, upeer_addrlen, 0); |
Ulrich Drepper | aaca0bd | 2008-07-23 21:29:20 -0700 | [diff] [blame] | 1503 | } |
| 1504 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1505 | /* |
| 1506 | * Attempt to connect to a socket with the server address. The address |
| 1507 | * is in user space so we verify it is OK and move it to kernel space. |
| 1508 | * |
| 1509 | * For 1003.1g we need to add clean support for a bind to AF_UNSPEC to |
| 1510 | * break bindings |
| 1511 | * |
| 1512 | * NOTE: 1003.1g draft 6.3 is broken with respect to AX.25/NetROM and |
| 1513 | * other SEQPACKET protocols that take time to connect() as it doesn't |
| 1514 | * include the -EINPROGRESS status for such sockets. |
| 1515 | */ |
| 1516 | |
Heiko Carstens | 20f3703 | 2009-01-14 14:14:23 +0100 | [diff] [blame] | 1517 | SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr, |
| 1518 | int, addrlen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1519 | { |
| 1520 | struct socket *sock; |
YOSHIFUJI Hideaki | 230b183 | 2008-07-19 22:35:47 -0700 | [diff] [blame] | 1521 | struct sockaddr_storage address; |
Benjamin LaHaise | 6cb153c | 2006-03-20 22:27:12 -0800 | [diff] [blame] | 1522 | int err, fput_needed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1523 | |
Benjamin LaHaise | 6cb153c | 2006-03-20 22:27:12 -0800 | [diff] [blame] | 1524 | sock = sockfd_lookup_light(fd, &err, &fput_needed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1525 | if (!sock) |
| 1526 | goto out; |
YOSHIFUJI Hideaki | 230b183 | 2008-07-19 22:35:47 -0700 | [diff] [blame] | 1527 | err = move_addr_to_kernel(uservaddr, addrlen, (struct sockaddr *)&address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1528 | if (err < 0) |
| 1529 | goto out_put; |
| 1530 | |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1531 | err = |
YOSHIFUJI Hideaki | 230b183 | 2008-07-19 22:35:47 -0700 | [diff] [blame] | 1532 | security_socket_connect(sock, (struct sockaddr *)&address, addrlen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1533 | if (err) |
| 1534 | goto out_put; |
| 1535 | |
YOSHIFUJI Hideaki | 230b183 | 2008-07-19 22:35:47 -0700 | [diff] [blame] | 1536 | err = sock->ops->connect(sock, (struct sockaddr *)&address, addrlen, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1537 | sock->file->f_flags); |
| 1538 | out_put: |
Benjamin LaHaise | 6cb153c | 2006-03-20 22:27:12 -0800 | [diff] [blame] | 1539 | fput_light(sock->file, fput_needed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1540 | out: |
| 1541 | return err; |
| 1542 | } |
| 1543 | |
| 1544 | /* |
| 1545 | * Get the local address ('name') of a socket object. Move the obtained |
| 1546 | * name to user space. |
| 1547 | */ |
| 1548 | |
Heiko Carstens | 20f3703 | 2009-01-14 14:14:23 +0100 | [diff] [blame] | 1549 | SYSCALL_DEFINE3(getsockname, int, fd, struct sockaddr __user *, usockaddr, |
| 1550 | int __user *, usockaddr_len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1551 | { |
| 1552 | struct socket *sock; |
YOSHIFUJI Hideaki | 230b183 | 2008-07-19 22:35:47 -0700 | [diff] [blame] | 1553 | struct sockaddr_storage address; |
Benjamin LaHaise | 6cb153c | 2006-03-20 22:27:12 -0800 | [diff] [blame] | 1554 | int len, err, fput_needed; |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1555 | |
Benjamin LaHaise | 6cb153c | 2006-03-20 22:27:12 -0800 | [diff] [blame] | 1556 | sock = sockfd_lookup_light(fd, &err, &fput_needed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1557 | if (!sock) |
| 1558 | goto out; |
| 1559 | |
| 1560 | err = security_socket_getsockname(sock); |
| 1561 | if (err) |
| 1562 | goto out_put; |
| 1563 | |
YOSHIFUJI Hideaki | 230b183 | 2008-07-19 22:35:47 -0700 | [diff] [blame] | 1564 | err = sock->ops->getname(sock, (struct sockaddr *)&address, &len, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1565 | if (err) |
| 1566 | goto out_put; |
YOSHIFUJI Hideaki | 230b183 | 2008-07-19 22:35:47 -0700 | [diff] [blame] | 1567 | err = move_addr_to_user((struct sockaddr *)&address, len, usockaddr, usockaddr_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1568 | |
| 1569 | out_put: |
Benjamin LaHaise | 6cb153c | 2006-03-20 22:27:12 -0800 | [diff] [blame] | 1570 | fput_light(sock->file, fput_needed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1571 | out: |
| 1572 | return err; |
| 1573 | } |
| 1574 | |
| 1575 | /* |
| 1576 | * Get the remote address ('name') of a socket object. Move the obtained |
| 1577 | * name to user space. |
| 1578 | */ |
| 1579 | |
Heiko Carstens | 20f3703 | 2009-01-14 14:14:23 +0100 | [diff] [blame] | 1580 | SYSCALL_DEFINE3(getpeername, int, fd, struct sockaddr __user *, usockaddr, |
| 1581 | int __user *, usockaddr_len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1582 | { |
| 1583 | struct socket *sock; |
YOSHIFUJI Hideaki | 230b183 | 2008-07-19 22:35:47 -0700 | [diff] [blame] | 1584 | struct sockaddr_storage address; |
Benjamin LaHaise | 6cb153c | 2006-03-20 22:27:12 -0800 | [diff] [blame] | 1585 | int len, err, fput_needed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1586 | |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1587 | sock = sockfd_lookup_light(fd, &err, &fput_needed); |
| 1588 | if (sock != NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1589 | err = security_socket_getpeername(sock); |
| 1590 | if (err) { |
Benjamin LaHaise | 6cb153c | 2006-03-20 22:27:12 -0800 | [diff] [blame] | 1591 | fput_light(sock->file, fput_needed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1592 | return err; |
| 1593 | } |
| 1594 | |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1595 | err = |
YOSHIFUJI Hideaki | 230b183 | 2008-07-19 22:35:47 -0700 | [diff] [blame] | 1596 | sock->ops->getname(sock, (struct sockaddr *)&address, &len, |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1597 | 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1598 | if (!err) |
YOSHIFUJI Hideaki | 230b183 | 2008-07-19 22:35:47 -0700 | [diff] [blame] | 1599 | err = move_addr_to_user((struct sockaddr *)&address, len, usockaddr, |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1600 | usockaddr_len); |
Benjamin LaHaise | 6cb153c | 2006-03-20 22:27:12 -0800 | [diff] [blame] | 1601 | fput_light(sock->file, fput_needed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1602 | } |
| 1603 | return err; |
| 1604 | } |
| 1605 | |
| 1606 | /* |
| 1607 | * Send a datagram to a given address. We move the address into kernel |
| 1608 | * space and check the user space data area is readable before invoking |
| 1609 | * the protocol. |
| 1610 | */ |
| 1611 | |
Heiko Carstens | 3e0fa65 | 2009-01-14 14:14:24 +0100 | [diff] [blame] | 1612 | SYSCALL_DEFINE6(sendto, int, fd, void __user *, buff, size_t, len, |
| 1613 | unsigned, flags, struct sockaddr __user *, addr, |
| 1614 | int, addr_len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1615 | { |
| 1616 | struct socket *sock; |
YOSHIFUJI Hideaki | 230b183 | 2008-07-19 22:35:47 -0700 | [diff] [blame] | 1617 | struct sockaddr_storage address; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1618 | int err; |
| 1619 | struct msghdr msg; |
| 1620 | struct iovec iov; |
Benjamin LaHaise | 6cb153c | 2006-03-20 22:27:12 -0800 | [diff] [blame] | 1621 | int fput_needed; |
Benjamin LaHaise | 6cb153c | 2006-03-20 22:27:12 -0800 | [diff] [blame] | 1622 | |
Pavel Emelyanov | de0fa95 | 2007-11-14 16:01:43 -0800 | [diff] [blame] | 1623 | sock = sockfd_lookup_light(fd, &err, &fput_needed); |
| 1624 | if (!sock) |
David S. Miller | 4387ff7 | 2007-02-08 15:06:08 -0800 | [diff] [blame] | 1625 | goto out; |
Benjamin LaHaise | 6cb153c | 2006-03-20 22:27:12 -0800 | [diff] [blame] | 1626 | |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1627 | iov.iov_base = buff; |
| 1628 | iov.iov_len = len; |
| 1629 | msg.msg_name = NULL; |
| 1630 | msg.msg_iov = &iov; |
| 1631 | msg.msg_iovlen = 1; |
| 1632 | msg.msg_control = NULL; |
| 1633 | msg.msg_controllen = 0; |
| 1634 | msg.msg_namelen = 0; |
Benjamin LaHaise | 6cb153c | 2006-03-20 22:27:12 -0800 | [diff] [blame] | 1635 | if (addr) { |
YOSHIFUJI Hideaki | 230b183 | 2008-07-19 22:35:47 -0700 | [diff] [blame] | 1636 | err = move_addr_to_kernel(addr, addr_len, (struct sockaddr *)&address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1637 | if (err < 0) |
| 1638 | goto out_put; |
YOSHIFUJI Hideaki | 230b183 | 2008-07-19 22:35:47 -0700 | [diff] [blame] | 1639 | msg.msg_name = (struct sockaddr *)&address; |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1640 | msg.msg_namelen = addr_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1641 | } |
| 1642 | if (sock->file->f_flags & O_NONBLOCK) |
| 1643 | flags |= MSG_DONTWAIT; |
| 1644 | msg.msg_flags = flags; |
| 1645 | err = sock_sendmsg(sock, &msg, len); |
| 1646 | |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1647 | out_put: |
Pavel Emelyanov | de0fa95 | 2007-11-14 16:01:43 -0800 | [diff] [blame] | 1648 | fput_light(sock->file, fput_needed); |
David S. Miller | 4387ff7 | 2007-02-08 15:06:08 -0800 | [diff] [blame] | 1649 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1650 | return err; |
| 1651 | } |
| 1652 | |
| 1653 | /* |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1654 | * Send a datagram down a socket. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1655 | */ |
| 1656 | |
Heiko Carstens | 3e0fa65 | 2009-01-14 14:14:24 +0100 | [diff] [blame] | 1657 | SYSCALL_DEFINE4(send, int, fd, void __user *, buff, size_t, len, |
| 1658 | unsigned, flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1659 | { |
| 1660 | return sys_sendto(fd, buff, len, flags, NULL, 0); |
| 1661 | } |
| 1662 | |
| 1663 | /* |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1664 | * Receive a frame from the socket and optionally record the address of the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1665 | * sender. We verify the buffers are writable and if needed move the |
| 1666 | * sender address from kernel to user space. |
| 1667 | */ |
| 1668 | |
Heiko Carstens | 3e0fa65 | 2009-01-14 14:14:24 +0100 | [diff] [blame] | 1669 | SYSCALL_DEFINE6(recvfrom, int, fd, void __user *, ubuf, size_t, size, |
| 1670 | unsigned, flags, struct sockaddr __user *, addr, |
| 1671 | int __user *, addr_len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1672 | { |
| 1673 | struct socket *sock; |
| 1674 | struct iovec iov; |
| 1675 | struct msghdr msg; |
YOSHIFUJI Hideaki | 230b183 | 2008-07-19 22:35:47 -0700 | [diff] [blame] | 1676 | struct sockaddr_storage address; |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1677 | int err, err2; |
Benjamin LaHaise | 6cb153c | 2006-03-20 22:27:12 -0800 | [diff] [blame] | 1678 | int fput_needed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1679 | |
Pavel Emelyanov | de0fa95 | 2007-11-14 16:01:43 -0800 | [diff] [blame] | 1680 | sock = sockfd_lookup_light(fd, &err, &fput_needed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1681 | if (!sock) |
Pavel Emelyanov | de0fa95 | 2007-11-14 16:01:43 -0800 | [diff] [blame] | 1682 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1683 | |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1684 | msg.msg_control = NULL; |
| 1685 | msg.msg_controllen = 0; |
| 1686 | msg.msg_iovlen = 1; |
| 1687 | msg.msg_iov = &iov; |
| 1688 | iov.iov_len = size; |
| 1689 | iov.iov_base = ubuf; |
YOSHIFUJI Hideaki | 230b183 | 2008-07-19 22:35:47 -0700 | [diff] [blame] | 1690 | msg.msg_name = (struct sockaddr *)&address; |
| 1691 | msg.msg_namelen = sizeof(address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1692 | if (sock->file->f_flags & O_NONBLOCK) |
| 1693 | flags |= MSG_DONTWAIT; |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1694 | err = sock_recvmsg(sock, &msg, size, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1695 | |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1696 | if (err >= 0 && addr != NULL) { |
YOSHIFUJI Hideaki | 230b183 | 2008-07-19 22:35:47 -0700 | [diff] [blame] | 1697 | err2 = move_addr_to_user((struct sockaddr *)&address, |
| 1698 | msg.msg_namelen, addr, addr_len); |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1699 | if (err2 < 0) |
| 1700 | err = err2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1701 | } |
Pavel Emelyanov | de0fa95 | 2007-11-14 16:01:43 -0800 | [diff] [blame] | 1702 | |
| 1703 | fput_light(sock->file, fput_needed); |
David S. Miller | 4387ff7 | 2007-02-08 15:06:08 -0800 | [diff] [blame] | 1704 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1705 | return err; |
| 1706 | } |
| 1707 | |
| 1708 | /* |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1709 | * Receive a datagram from a socket. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1710 | */ |
| 1711 | |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1712 | asmlinkage long sys_recv(int fd, void __user *ubuf, size_t size, |
| 1713 | unsigned flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1714 | { |
| 1715 | return sys_recvfrom(fd, ubuf, size, flags, NULL, NULL); |
| 1716 | } |
| 1717 | |
| 1718 | /* |
| 1719 | * Set a socket option. Because we don't know the option lengths we have |
| 1720 | * to pass the user mode parameter for the protocols to sort out. |
| 1721 | */ |
| 1722 | |
Heiko Carstens | 20f3703 | 2009-01-14 14:14:23 +0100 | [diff] [blame] | 1723 | SYSCALL_DEFINE5(setsockopt, int, fd, int, level, int, optname, |
| 1724 | char __user *, optval, int, optlen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1725 | { |
Benjamin LaHaise | 6cb153c | 2006-03-20 22:27:12 -0800 | [diff] [blame] | 1726 | int err, fput_needed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1727 | struct socket *sock; |
| 1728 | |
| 1729 | if (optlen < 0) |
| 1730 | return -EINVAL; |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1731 | |
| 1732 | sock = sockfd_lookup_light(fd, &err, &fput_needed); |
| 1733 | if (sock != NULL) { |
| 1734 | err = security_socket_setsockopt(sock, level, optname); |
Benjamin LaHaise | 6cb153c | 2006-03-20 22:27:12 -0800 | [diff] [blame] | 1735 | if (err) |
| 1736 | goto out_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1737 | |
| 1738 | if (level == SOL_SOCKET) |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1739 | err = |
| 1740 | sock_setsockopt(sock, level, optname, optval, |
| 1741 | optlen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1742 | else |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1743 | err = |
| 1744 | sock->ops->setsockopt(sock, level, optname, optval, |
| 1745 | optlen); |
Benjamin LaHaise | 6cb153c | 2006-03-20 22:27:12 -0800 | [diff] [blame] | 1746 | out_put: |
| 1747 | fput_light(sock->file, fput_needed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1748 | } |
| 1749 | return err; |
| 1750 | } |
| 1751 | |
| 1752 | /* |
| 1753 | * Get a socket option. Because we don't know the option lengths we have |
| 1754 | * to pass a user mode parameter for the protocols to sort out. |
| 1755 | */ |
| 1756 | |
Heiko Carstens | 20f3703 | 2009-01-14 14:14:23 +0100 | [diff] [blame] | 1757 | SYSCALL_DEFINE5(getsockopt, int, fd, int, level, int, optname, |
| 1758 | char __user *, optval, int __user *, optlen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1759 | { |
Benjamin LaHaise | 6cb153c | 2006-03-20 22:27:12 -0800 | [diff] [blame] | 1760 | int err, fput_needed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1761 | struct socket *sock; |
| 1762 | |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1763 | sock = sockfd_lookup_light(fd, &err, &fput_needed); |
| 1764 | if (sock != NULL) { |
Benjamin LaHaise | 6cb153c | 2006-03-20 22:27:12 -0800 | [diff] [blame] | 1765 | err = security_socket_getsockopt(sock, level, optname); |
| 1766 | if (err) |
| 1767 | goto out_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1768 | |
| 1769 | if (level == SOL_SOCKET) |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1770 | err = |
| 1771 | sock_getsockopt(sock, level, optname, optval, |
| 1772 | optlen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1773 | else |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1774 | err = |
| 1775 | sock->ops->getsockopt(sock, level, optname, optval, |
| 1776 | optlen); |
Benjamin LaHaise | 6cb153c | 2006-03-20 22:27:12 -0800 | [diff] [blame] | 1777 | out_put: |
| 1778 | fput_light(sock->file, fput_needed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1779 | } |
| 1780 | return err; |
| 1781 | } |
| 1782 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1783 | /* |
| 1784 | * Shutdown a socket. |
| 1785 | */ |
| 1786 | |
Heiko Carstens | 754fe8d | 2009-01-14 14:14:09 +0100 | [diff] [blame] | 1787 | SYSCALL_DEFINE2(shutdown, int, fd, int, how) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1788 | { |
Benjamin LaHaise | 6cb153c | 2006-03-20 22:27:12 -0800 | [diff] [blame] | 1789 | int err, fput_needed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1790 | struct socket *sock; |
| 1791 | |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1792 | sock = sockfd_lookup_light(fd, &err, &fput_needed); |
| 1793 | if (sock != NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1794 | err = security_socket_shutdown(sock, how); |
Benjamin LaHaise | 6cb153c | 2006-03-20 22:27:12 -0800 | [diff] [blame] | 1795 | if (!err) |
| 1796 | err = sock->ops->shutdown(sock, how); |
| 1797 | fput_light(sock->file, fput_needed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1798 | } |
| 1799 | return err; |
| 1800 | } |
| 1801 | |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1802 | /* A couple of helpful macros for getting the address of the 32/64 bit |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1803 | * fields which are the same type (int / unsigned) on our platforms. |
| 1804 | */ |
| 1805 | #define COMPAT_MSG(msg, member) ((MSG_CMSG_COMPAT & flags) ? &msg##_compat->member : &msg->member) |
| 1806 | #define COMPAT_NAMELEN(msg) COMPAT_MSG(msg, msg_namelen) |
| 1807 | #define COMPAT_FLAGS(msg) COMPAT_MSG(msg, msg_flags) |
| 1808 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1809 | /* |
| 1810 | * BSD sendmsg interface |
| 1811 | */ |
| 1812 | |
Heiko Carstens | 3e0fa65 | 2009-01-14 14:14:24 +0100 | [diff] [blame] | 1813 | SYSCALL_DEFINE3(sendmsg, int, fd, struct msghdr __user *, msg, unsigned, flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1814 | { |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1815 | struct compat_msghdr __user *msg_compat = |
| 1816 | (struct compat_msghdr __user *)msg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1817 | struct socket *sock; |
YOSHIFUJI Hideaki | 230b183 | 2008-07-19 22:35:47 -0700 | [diff] [blame] | 1818 | struct sockaddr_storage address; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1819 | struct iovec iovstack[UIO_FASTIOV], *iov = iovstack; |
Alex Williamson | b9d717a | 2005-09-26 14:28:02 -0700 | [diff] [blame] | 1820 | unsigned char ctl[sizeof(struct cmsghdr) + 20] |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1821 | __attribute__ ((aligned(sizeof(__kernel_size_t)))); |
| 1822 | /* 20 is size of ipv6_pktinfo */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1823 | unsigned char *ctl_buf = ctl; |
| 1824 | struct msghdr msg_sys; |
| 1825 | int err, ctl_len, iov_size, total_len; |
Benjamin LaHaise | 6cb153c | 2006-03-20 22:27:12 -0800 | [diff] [blame] | 1826 | int fput_needed; |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1827 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1828 | err = -EFAULT; |
| 1829 | if (MSG_CMSG_COMPAT & flags) { |
| 1830 | if (get_compat_msghdr(&msg_sys, msg_compat)) |
| 1831 | return -EFAULT; |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1832 | } |
| 1833 | else if (copy_from_user(&msg_sys, msg, sizeof(struct msghdr))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1834 | return -EFAULT; |
| 1835 | |
Benjamin LaHaise | 6cb153c | 2006-03-20 22:27:12 -0800 | [diff] [blame] | 1836 | sock = sockfd_lookup_light(fd, &err, &fput_needed); |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1837 | if (!sock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1838 | goto out; |
| 1839 | |
| 1840 | /* do not move before msg_sys is valid */ |
| 1841 | err = -EMSGSIZE; |
| 1842 | if (msg_sys.msg_iovlen > UIO_MAXIOV) |
| 1843 | goto out_put; |
| 1844 | |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1845 | /* Check whether to allocate the iovec area */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1846 | err = -ENOMEM; |
| 1847 | iov_size = msg_sys.msg_iovlen * sizeof(struct iovec); |
| 1848 | if (msg_sys.msg_iovlen > UIO_FASTIOV) { |
| 1849 | iov = sock_kmalloc(sock->sk, iov_size, GFP_KERNEL); |
| 1850 | if (!iov) |
| 1851 | goto out_put; |
| 1852 | } |
| 1853 | |
| 1854 | /* This will also move the address data into kernel space */ |
| 1855 | if (MSG_CMSG_COMPAT & flags) { |
YOSHIFUJI Hideaki | 230b183 | 2008-07-19 22:35:47 -0700 | [diff] [blame] | 1856 | err = verify_compat_iovec(&msg_sys, iov, |
| 1857 | (struct sockaddr *)&address, |
| 1858 | VERIFY_READ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1859 | } else |
YOSHIFUJI Hideaki | 230b183 | 2008-07-19 22:35:47 -0700 | [diff] [blame] | 1860 | err = verify_iovec(&msg_sys, iov, |
| 1861 | (struct sockaddr *)&address, |
| 1862 | VERIFY_READ); |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1863 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1864 | goto out_freeiov; |
| 1865 | total_len = err; |
| 1866 | |
| 1867 | err = -ENOBUFS; |
| 1868 | |
| 1869 | if (msg_sys.msg_controllen > INT_MAX) |
| 1870 | goto out_freeiov; |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1871 | ctl_len = msg_sys.msg_controllen; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1872 | if ((MSG_CMSG_COMPAT & flags) && ctl_len) { |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1873 | err = |
| 1874 | cmsghdr_from_user_compat_to_kern(&msg_sys, sock->sk, ctl, |
| 1875 | sizeof(ctl)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1876 | if (err) |
| 1877 | goto out_freeiov; |
| 1878 | ctl_buf = msg_sys.msg_control; |
Al Viro | 8920e8f | 2005-09-07 18:28:51 -0700 | [diff] [blame] | 1879 | ctl_len = msg_sys.msg_controllen; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1880 | } else if (ctl_len) { |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1881 | if (ctl_len > sizeof(ctl)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1882 | ctl_buf = sock_kmalloc(sock->sk, ctl_len, GFP_KERNEL); |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1883 | if (ctl_buf == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1884 | goto out_freeiov; |
| 1885 | } |
| 1886 | err = -EFAULT; |
| 1887 | /* |
| 1888 | * Careful! Before this, msg_sys.msg_control contains a user pointer. |
| 1889 | * Afterwards, it will be a kernel pointer. Thus the compiler-assisted |
| 1890 | * checking falls down on this. |
| 1891 | */ |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1892 | if (copy_from_user(ctl_buf, (void __user *)msg_sys.msg_control, |
| 1893 | ctl_len)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1894 | goto out_freectl; |
| 1895 | msg_sys.msg_control = ctl_buf; |
| 1896 | } |
| 1897 | msg_sys.msg_flags = flags; |
| 1898 | |
| 1899 | if (sock->file->f_flags & O_NONBLOCK) |
| 1900 | msg_sys.msg_flags |= MSG_DONTWAIT; |
| 1901 | err = sock_sendmsg(sock, &msg_sys, total_len); |
| 1902 | |
| 1903 | out_freectl: |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1904 | if (ctl_buf != ctl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1905 | sock_kfree_s(sock->sk, ctl_buf, ctl_len); |
| 1906 | out_freeiov: |
| 1907 | if (iov != iovstack) |
| 1908 | sock_kfree_s(sock->sk, iov, iov_size); |
| 1909 | out_put: |
Benjamin LaHaise | 6cb153c | 2006-03-20 22:27:12 -0800 | [diff] [blame] | 1910 | fput_light(sock->file, fput_needed); |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1911 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1912 | return err; |
| 1913 | } |
| 1914 | |
Arnaldo Carvalho de Melo | a2e2725 | 2009-10-12 23:40:10 -0700 | [diff] [blame] | 1915 | static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg, |
| 1916 | struct msghdr *msg_sys, unsigned flags, int nosec) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1917 | { |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1918 | struct compat_msghdr __user *msg_compat = |
| 1919 | (struct compat_msghdr __user *)msg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1920 | struct iovec iovstack[UIO_FASTIOV]; |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1921 | struct iovec *iov = iovstack; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1922 | unsigned long cmsg_ptr; |
| 1923 | int err, iov_size, total_len, len; |
| 1924 | |
| 1925 | /* kernel mode address */ |
YOSHIFUJI Hideaki | 230b183 | 2008-07-19 22:35:47 -0700 | [diff] [blame] | 1926 | struct sockaddr_storage addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1927 | |
| 1928 | /* user mode address pointers */ |
| 1929 | struct sockaddr __user *uaddr; |
| 1930 | int __user *uaddr_len; |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1931 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1932 | if (MSG_CMSG_COMPAT & flags) { |
Arnaldo Carvalho de Melo | a2e2725 | 2009-10-12 23:40:10 -0700 | [diff] [blame] | 1933 | if (get_compat_msghdr(msg_sys, msg_compat)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1934 | return -EFAULT; |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1935 | } |
Arnaldo Carvalho de Melo | a2e2725 | 2009-10-12 23:40:10 -0700 | [diff] [blame] | 1936 | else if (copy_from_user(msg_sys, msg, sizeof(struct msghdr))) |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1937 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1938 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1939 | err = -EMSGSIZE; |
Arnaldo Carvalho de Melo | a2e2725 | 2009-10-12 23:40:10 -0700 | [diff] [blame] | 1940 | if (msg_sys->msg_iovlen > UIO_MAXIOV) |
| 1941 | goto out; |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1942 | |
| 1943 | /* Check whether to allocate the iovec area */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1944 | err = -ENOMEM; |
Arnaldo Carvalho de Melo | a2e2725 | 2009-10-12 23:40:10 -0700 | [diff] [blame] | 1945 | iov_size = msg_sys->msg_iovlen * sizeof(struct iovec); |
| 1946 | if (msg_sys->msg_iovlen > UIO_FASTIOV) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1947 | iov = sock_kmalloc(sock->sk, iov_size, GFP_KERNEL); |
| 1948 | if (!iov) |
Arnaldo Carvalho de Melo | a2e2725 | 2009-10-12 23:40:10 -0700 | [diff] [blame] | 1949 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1950 | } |
| 1951 | |
| 1952 | /* |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1953 | * Save the user-mode address (verify_iovec will change the |
| 1954 | * kernel msghdr to use the kernel address space) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1955 | */ |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1956 | |
Arnaldo Carvalho de Melo | a2e2725 | 2009-10-12 23:40:10 -0700 | [diff] [blame] | 1957 | uaddr = (__force void __user *)msg_sys->msg_name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1958 | uaddr_len = COMPAT_NAMELEN(msg); |
| 1959 | if (MSG_CMSG_COMPAT & flags) { |
Arnaldo Carvalho de Melo | a2e2725 | 2009-10-12 23:40:10 -0700 | [diff] [blame] | 1960 | err = verify_compat_iovec(msg_sys, iov, |
YOSHIFUJI Hideaki | 230b183 | 2008-07-19 22:35:47 -0700 | [diff] [blame] | 1961 | (struct sockaddr *)&addr, |
| 1962 | VERIFY_WRITE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1963 | } else |
Arnaldo Carvalho de Melo | a2e2725 | 2009-10-12 23:40:10 -0700 | [diff] [blame] | 1964 | err = verify_iovec(msg_sys, iov, |
YOSHIFUJI Hideaki | 230b183 | 2008-07-19 22:35:47 -0700 | [diff] [blame] | 1965 | (struct sockaddr *)&addr, |
| 1966 | VERIFY_WRITE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1967 | if (err < 0) |
| 1968 | goto out_freeiov; |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1969 | total_len = err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1970 | |
Arnaldo Carvalho de Melo | a2e2725 | 2009-10-12 23:40:10 -0700 | [diff] [blame] | 1971 | cmsg_ptr = (unsigned long)msg_sys->msg_control; |
| 1972 | msg_sys->msg_flags = flags & (MSG_CMSG_CLOEXEC|MSG_CMSG_COMPAT); |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1973 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1974 | if (sock->file->f_flags & O_NONBLOCK) |
| 1975 | flags |= MSG_DONTWAIT; |
Arnaldo Carvalho de Melo | a2e2725 | 2009-10-12 23:40:10 -0700 | [diff] [blame] | 1976 | err = (nosec ? sock_recvmsg_nosec : sock_recvmsg)(sock, msg_sys, |
| 1977 | total_len, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1978 | if (err < 0) |
| 1979 | goto out_freeiov; |
| 1980 | len = err; |
| 1981 | |
| 1982 | if (uaddr != NULL) { |
YOSHIFUJI Hideaki | 230b183 | 2008-07-19 22:35:47 -0700 | [diff] [blame] | 1983 | err = move_addr_to_user((struct sockaddr *)&addr, |
Arnaldo Carvalho de Melo | a2e2725 | 2009-10-12 23:40:10 -0700 | [diff] [blame] | 1984 | msg_sys->msg_namelen, uaddr, |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 1985 | uaddr_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1986 | if (err < 0) |
| 1987 | goto out_freeiov; |
| 1988 | } |
Arnaldo Carvalho de Melo | a2e2725 | 2009-10-12 23:40:10 -0700 | [diff] [blame] | 1989 | err = __put_user((msg_sys->msg_flags & ~MSG_CMSG_COMPAT), |
David S. Miller | 37f7f42 | 2005-09-16 16:51:01 -0700 | [diff] [blame] | 1990 | COMPAT_FLAGS(msg)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1991 | if (err) |
| 1992 | goto out_freeiov; |
| 1993 | if (MSG_CMSG_COMPAT & flags) |
Arnaldo Carvalho de Melo | a2e2725 | 2009-10-12 23:40:10 -0700 | [diff] [blame] | 1994 | err = __put_user((unsigned long)msg_sys->msg_control - cmsg_ptr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1995 | &msg_compat->msg_controllen); |
| 1996 | else |
Arnaldo Carvalho de Melo | a2e2725 | 2009-10-12 23:40:10 -0700 | [diff] [blame] | 1997 | err = __put_user((unsigned long)msg_sys->msg_control - cmsg_ptr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1998 | &msg->msg_controllen); |
| 1999 | if (err) |
| 2000 | goto out_freeiov; |
| 2001 | err = len; |
| 2002 | |
| 2003 | out_freeiov: |
| 2004 | if (iov != iovstack) |
| 2005 | sock_kfree_s(sock->sk, iov, iov_size); |
Arnaldo Carvalho de Melo | a2e2725 | 2009-10-12 23:40:10 -0700 | [diff] [blame] | 2006 | out: |
| 2007 | return err; |
| 2008 | } |
| 2009 | |
| 2010 | /* |
| 2011 | * BSD recvmsg interface |
| 2012 | */ |
| 2013 | |
| 2014 | SYSCALL_DEFINE3(recvmsg, int, fd, struct msghdr __user *, msg, |
| 2015 | unsigned int, flags) |
| 2016 | { |
| 2017 | int fput_needed, err; |
| 2018 | struct msghdr msg_sys; |
| 2019 | struct socket *sock = sockfd_lookup_light(fd, &err, &fput_needed); |
| 2020 | |
| 2021 | if (!sock) |
| 2022 | goto out; |
| 2023 | |
| 2024 | err = __sys_recvmsg(sock, msg, &msg_sys, flags, 0); |
| 2025 | |
Benjamin LaHaise | 6cb153c | 2006-03-20 22:27:12 -0800 | [diff] [blame] | 2026 | fput_light(sock->file, fput_needed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2027 | out: |
| 2028 | return err; |
| 2029 | } |
| 2030 | |
Arnaldo Carvalho de Melo | a2e2725 | 2009-10-12 23:40:10 -0700 | [diff] [blame] | 2031 | /* |
| 2032 | * Linux recvmmsg interface |
| 2033 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2034 | |
Arnaldo Carvalho de Melo | a2e2725 | 2009-10-12 23:40:10 -0700 | [diff] [blame] | 2035 | int __sys_recvmmsg(int fd, struct mmsghdr __user *mmsg, unsigned int vlen, |
| 2036 | unsigned int flags, struct timespec *timeout) |
| 2037 | { |
| 2038 | int fput_needed, err, datagrams; |
| 2039 | struct socket *sock; |
| 2040 | struct mmsghdr __user *entry; |
Jean-Mickael Guerin | d7256d0 | 2009-12-01 08:47:26 +0000 | [diff] [blame] | 2041 | struct compat_mmsghdr __user *compat_entry; |
Arnaldo Carvalho de Melo | a2e2725 | 2009-10-12 23:40:10 -0700 | [diff] [blame] | 2042 | struct msghdr msg_sys; |
| 2043 | struct timespec end_time; |
| 2044 | |
| 2045 | if (timeout && |
| 2046 | poll_select_set_timeout(&end_time, timeout->tv_sec, |
| 2047 | timeout->tv_nsec)) |
| 2048 | return -EINVAL; |
| 2049 | |
| 2050 | datagrams = 0; |
| 2051 | |
| 2052 | sock = sockfd_lookup_light(fd, &err, &fput_needed); |
| 2053 | if (!sock) |
| 2054 | return err; |
| 2055 | |
| 2056 | err = sock_error(sock->sk); |
| 2057 | if (err) |
| 2058 | goto out_put; |
| 2059 | |
| 2060 | entry = mmsg; |
Jean-Mickael Guerin | d7256d0 | 2009-12-01 08:47:26 +0000 | [diff] [blame] | 2061 | compat_entry = (struct compat_mmsghdr __user *)mmsg; |
Arnaldo Carvalho de Melo | a2e2725 | 2009-10-12 23:40:10 -0700 | [diff] [blame] | 2062 | |
| 2063 | while (datagrams < vlen) { |
| 2064 | /* |
| 2065 | * No need to ask LSM for more than the first datagram. |
| 2066 | */ |
Jean-Mickael Guerin | d7256d0 | 2009-12-01 08:47:26 +0000 | [diff] [blame] | 2067 | if (MSG_CMSG_COMPAT & flags) { |
| 2068 | err = __sys_recvmsg(sock, (struct msghdr __user *)compat_entry, |
| 2069 | &msg_sys, flags, datagrams); |
| 2070 | if (err < 0) |
| 2071 | break; |
| 2072 | err = __put_user(err, &compat_entry->msg_len); |
| 2073 | ++compat_entry; |
| 2074 | } else { |
| 2075 | err = __sys_recvmsg(sock, (struct msghdr __user *)entry, |
| 2076 | &msg_sys, flags, datagrams); |
| 2077 | if (err < 0) |
| 2078 | break; |
| 2079 | err = put_user(err, &entry->msg_len); |
| 2080 | ++entry; |
| 2081 | } |
| 2082 | |
Arnaldo Carvalho de Melo | a2e2725 | 2009-10-12 23:40:10 -0700 | [diff] [blame] | 2083 | if (err) |
| 2084 | break; |
Arnaldo Carvalho de Melo | a2e2725 | 2009-10-12 23:40:10 -0700 | [diff] [blame] | 2085 | ++datagrams; |
| 2086 | |
Brandon L Black | 71c5c159 | 2010-03-26 16:18:03 +0000 | [diff] [blame] | 2087 | /* MSG_WAITFORONE turns on MSG_DONTWAIT after one packet */ |
| 2088 | if (flags & MSG_WAITFORONE) |
| 2089 | flags |= MSG_DONTWAIT; |
| 2090 | |
Arnaldo Carvalho de Melo | a2e2725 | 2009-10-12 23:40:10 -0700 | [diff] [blame] | 2091 | if (timeout) { |
| 2092 | ktime_get_ts(timeout); |
| 2093 | *timeout = timespec_sub(end_time, *timeout); |
| 2094 | if (timeout->tv_sec < 0) { |
| 2095 | timeout->tv_sec = timeout->tv_nsec = 0; |
| 2096 | break; |
| 2097 | } |
| 2098 | |
| 2099 | /* Timeout, return less than vlen datagrams */ |
| 2100 | if (timeout->tv_nsec == 0 && timeout->tv_sec == 0) |
| 2101 | break; |
| 2102 | } |
| 2103 | |
| 2104 | /* Out of band data, return right away */ |
| 2105 | if (msg_sys.msg_flags & MSG_OOB) |
| 2106 | break; |
| 2107 | } |
| 2108 | |
| 2109 | out_put: |
| 2110 | fput_light(sock->file, fput_needed); |
| 2111 | |
| 2112 | if (err == 0) |
| 2113 | return datagrams; |
| 2114 | |
| 2115 | if (datagrams != 0) { |
| 2116 | /* |
| 2117 | * We may return less entries than requested (vlen) if the |
| 2118 | * sock is non block and there aren't enough datagrams... |
| 2119 | */ |
| 2120 | if (err != -EAGAIN) { |
| 2121 | /* |
| 2122 | * ... or if recvmsg returns an error after we |
| 2123 | * received some datagrams, where we record the |
| 2124 | * error to return on the next call or if the |
| 2125 | * app asks about it using getsockopt(SO_ERROR). |
| 2126 | */ |
| 2127 | sock->sk->sk_err = -err; |
| 2128 | } |
| 2129 | |
| 2130 | return datagrams; |
| 2131 | } |
| 2132 | |
| 2133 | return err; |
| 2134 | } |
| 2135 | |
| 2136 | SYSCALL_DEFINE5(recvmmsg, int, fd, struct mmsghdr __user *, mmsg, |
| 2137 | unsigned int, vlen, unsigned int, flags, |
| 2138 | struct timespec __user *, timeout) |
| 2139 | { |
| 2140 | int datagrams; |
| 2141 | struct timespec timeout_sys; |
| 2142 | |
| 2143 | if (!timeout) |
| 2144 | return __sys_recvmmsg(fd, mmsg, vlen, flags, NULL); |
| 2145 | |
| 2146 | if (copy_from_user(&timeout_sys, timeout, sizeof(timeout_sys))) |
| 2147 | return -EFAULT; |
| 2148 | |
| 2149 | datagrams = __sys_recvmmsg(fd, mmsg, vlen, flags, &timeout_sys); |
| 2150 | |
| 2151 | if (datagrams > 0 && |
| 2152 | copy_to_user(timeout, &timeout_sys, sizeof(timeout_sys))) |
| 2153 | datagrams = -EFAULT; |
| 2154 | |
| 2155 | return datagrams; |
| 2156 | } |
| 2157 | |
| 2158 | #ifdef __ARCH_WANT_SYS_SOCKETCALL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2159 | /* Argument list sizes for sys_socketcall */ |
| 2160 | #define AL(x) ((x) * sizeof(unsigned long)) |
Arnaldo Carvalho de Melo | a2e2725 | 2009-10-12 23:40:10 -0700 | [diff] [blame] | 2161 | static const unsigned char nargs[20] = { |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 2162 | AL(0),AL(3),AL(3),AL(3),AL(2),AL(3), |
| 2163 | AL(3),AL(3),AL(4),AL(4),AL(4),AL(6), |
Ulrich Drepper | aaca0bd | 2008-07-23 21:29:20 -0700 | [diff] [blame] | 2164 | AL(6),AL(2),AL(5),AL(5),AL(3),AL(3), |
Arnaldo Carvalho de Melo | a2e2725 | 2009-10-12 23:40:10 -0700 | [diff] [blame] | 2165 | AL(4),AL(5) |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 2166 | }; |
| 2167 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2168 | #undef AL |
| 2169 | |
| 2170 | /* |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 2171 | * System call vectors. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2172 | * |
| 2173 | * Argument checking cleaned up. Saved 20% in size. |
| 2174 | * This function doesn't need to set the kernel lock because |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 2175 | * it is set by the callees. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2176 | */ |
| 2177 | |
Heiko Carstens | 3e0fa65 | 2009-01-14 14:14:24 +0100 | [diff] [blame] | 2178 | SYSCALL_DEFINE2(socketcall, int, call, unsigned long __user *, args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2179 | { |
| 2180 | unsigned long a[6]; |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 2181 | unsigned long a0, a1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2182 | int err; |
Arjan van de Ven | 4737905 | 2009-09-28 12:57:44 -0700 | [diff] [blame] | 2183 | unsigned int len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2184 | |
Arnaldo Carvalho de Melo | a2e2725 | 2009-10-12 23:40:10 -0700 | [diff] [blame] | 2185 | if (call < 1 || call > SYS_RECVMMSG) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2186 | return -EINVAL; |
| 2187 | |
Arjan van de Ven | 4737905 | 2009-09-28 12:57:44 -0700 | [diff] [blame] | 2188 | len = nargs[call]; |
| 2189 | if (len > sizeof(a)) |
| 2190 | return -EINVAL; |
| 2191 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2192 | /* copy_from_user should be SMP safe. */ |
Arjan van de Ven | 4737905 | 2009-09-28 12:57:44 -0700 | [diff] [blame] | 2193 | if (copy_from_user(a, args, len)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2194 | return -EFAULT; |
David Woodhouse | 3ec3b2f | 2005-05-17 12:08:48 +0100 | [diff] [blame] | 2195 | |
Al Viro | f3298dc | 2008-12-10 03:16:51 -0500 | [diff] [blame] | 2196 | audit_socketcall(nargs[call] / sizeof(unsigned long), a); |
David Woodhouse | 3ec3b2f | 2005-05-17 12:08:48 +0100 | [diff] [blame] | 2197 | |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 2198 | a0 = a[0]; |
| 2199 | a1 = a[1]; |
| 2200 | |
| 2201 | switch (call) { |
| 2202 | case SYS_SOCKET: |
| 2203 | err = sys_socket(a0, a1, a[2]); |
| 2204 | break; |
| 2205 | case SYS_BIND: |
| 2206 | err = sys_bind(a0, (struct sockaddr __user *)a1, a[2]); |
| 2207 | break; |
| 2208 | case SYS_CONNECT: |
| 2209 | err = sys_connect(a0, (struct sockaddr __user *)a1, a[2]); |
| 2210 | break; |
| 2211 | case SYS_LISTEN: |
| 2212 | err = sys_listen(a0, a1); |
| 2213 | break; |
| 2214 | case SYS_ACCEPT: |
Ulrich Drepper | de11def | 2008-11-19 15:36:14 -0800 | [diff] [blame] | 2215 | err = sys_accept4(a0, (struct sockaddr __user *)a1, |
| 2216 | (int __user *)a[2], 0); |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 2217 | break; |
| 2218 | case SYS_GETSOCKNAME: |
| 2219 | err = |
| 2220 | sys_getsockname(a0, (struct sockaddr __user *)a1, |
| 2221 | (int __user *)a[2]); |
| 2222 | break; |
| 2223 | case SYS_GETPEERNAME: |
| 2224 | err = |
| 2225 | sys_getpeername(a0, (struct sockaddr __user *)a1, |
| 2226 | (int __user *)a[2]); |
| 2227 | break; |
| 2228 | case SYS_SOCKETPAIR: |
| 2229 | err = sys_socketpair(a0, a1, a[2], (int __user *)a[3]); |
| 2230 | break; |
| 2231 | case SYS_SEND: |
| 2232 | err = sys_send(a0, (void __user *)a1, a[2], a[3]); |
| 2233 | break; |
| 2234 | case SYS_SENDTO: |
| 2235 | err = sys_sendto(a0, (void __user *)a1, a[2], a[3], |
| 2236 | (struct sockaddr __user *)a[4], a[5]); |
| 2237 | break; |
| 2238 | case SYS_RECV: |
| 2239 | err = sys_recv(a0, (void __user *)a1, a[2], a[3]); |
| 2240 | break; |
| 2241 | case SYS_RECVFROM: |
| 2242 | err = sys_recvfrom(a0, (void __user *)a1, a[2], a[3], |
| 2243 | (struct sockaddr __user *)a[4], |
| 2244 | (int __user *)a[5]); |
| 2245 | break; |
| 2246 | case SYS_SHUTDOWN: |
| 2247 | err = sys_shutdown(a0, a1); |
| 2248 | break; |
| 2249 | case SYS_SETSOCKOPT: |
| 2250 | err = sys_setsockopt(a0, a1, a[2], (char __user *)a[3], a[4]); |
| 2251 | break; |
| 2252 | case SYS_GETSOCKOPT: |
| 2253 | err = |
| 2254 | sys_getsockopt(a0, a1, a[2], (char __user *)a[3], |
| 2255 | (int __user *)a[4]); |
| 2256 | break; |
| 2257 | case SYS_SENDMSG: |
| 2258 | err = sys_sendmsg(a0, (struct msghdr __user *)a1, a[2]); |
| 2259 | break; |
| 2260 | case SYS_RECVMSG: |
| 2261 | err = sys_recvmsg(a0, (struct msghdr __user *)a1, a[2]); |
| 2262 | break; |
Arnaldo Carvalho de Melo | a2e2725 | 2009-10-12 23:40:10 -0700 | [diff] [blame] | 2263 | case SYS_RECVMMSG: |
| 2264 | err = sys_recvmmsg(a0, (struct mmsghdr __user *)a1, a[2], a[3], |
| 2265 | (struct timespec __user *)a[4]); |
| 2266 | break; |
Ulrich Drepper | de11def | 2008-11-19 15:36:14 -0800 | [diff] [blame] | 2267 | case SYS_ACCEPT4: |
| 2268 | err = sys_accept4(a0, (struct sockaddr __user *)a1, |
| 2269 | (int __user *)a[2], a[3]); |
Ulrich Drepper | aaca0bd | 2008-07-23 21:29:20 -0700 | [diff] [blame] | 2270 | break; |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 2271 | default: |
| 2272 | err = -EINVAL; |
| 2273 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2274 | } |
| 2275 | return err; |
| 2276 | } |
| 2277 | |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 2278 | #endif /* __ARCH_WANT_SYS_SOCKETCALL */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2279 | |
Stephen Hemminger | 55737fd | 2006-09-01 00:23:39 -0700 | [diff] [blame] | 2280 | /** |
| 2281 | * sock_register - add a socket protocol handler |
| 2282 | * @ops: description of protocol |
| 2283 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2284 | * This function is called by a protocol handler that wants to |
| 2285 | * advertise its address family, and have it linked into the |
Stephen Hemminger | 55737fd | 2006-09-01 00:23:39 -0700 | [diff] [blame] | 2286 | * socket interface. The value ops->family coresponds to the |
| 2287 | * socket system call protocol family. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2288 | */ |
Stephen Hemminger | f0fd27d | 2006-08-09 21:03:17 -0700 | [diff] [blame] | 2289 | int sock_register(const struct net_proto_family *ops) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2290 | { |
| 2291 | int err; |
| 2292 | |
| 2293 | if (ops->family >= NPROTO) { |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 2294 | printk(KERN_CRIT "protocol %d >= NPROTO(%d)\n", ops->family, |
| 2295 | NPROTO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2296 | return -ENOBUFS; |
| 2297 | } |
Stephen Hemminger | 55737fd | 2006-09-01 00:23:39 -0700 | [diff] [blame] | 2298 | |
| 2299 | spin_lock(&net_family_lock); |
| 2300 | if (net_families[ops->family]) |
| 2301 | err = -EEXIST; |
| 2302 | else { |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 2303 | net_families[ops->family] = ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2304 | err = 0; |
| 2305 | } |
Stephen Hemminger | 55737fd | 2006-09-01 00:23:39 -0700 | [diff] [blame] | 2306 | spin_unlock(&net_family_lock); |
| 2307 | |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 2308 | printk(KERN_INFO "NET: Registered protocol family %d\n", ops->family); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2309 | return err; |
| 2310 | } |
| 2311 | |
Stephen Hemminger | 55737fd | 2006-09-01 00:23:39 -0700 | [diff] [blame] | 2312 | /** |
| 2313 | * sock_unregister - remove a protocol handler |
| 2314 | * @family: protocol family to remove |
| 2315 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2316 | * This function is called by a protocol handler that wants to |
| 2317 | * remove its address family, and have it unlinked from the |
Stephen Hemminger | 55737fd | 2006-09-01 00:23:39 -0700 | [diff] [blame] | 2318 | * new socket creation. |
| 2319 | * |
| 2320 | * If protocol handler is a module, then it can use module reference |
| 2321 | * counts to protect against new references. If protocol handler is not |
| 2322 | * a module then it needs to provide its own protection in |
| 2323 | * the ops->create routine. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2324 | */ |
Stephen Hemminger | f0fd27d | 2006-08-09 21:03:17 -0700 | [diff] [blame] | 2325 | void sock_unregister(int family) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2326 | { |
Stephen Hemminger | f0fd27d | 2006-08-09 21:03:17 -0700 | [diff] [blame] | 2327 | BUG_ON(family < 0 || family >= NPROTO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2328 | |
Stephen Hemminger | 55737fd | 2006-09-01 00:23:39 -0700 | [diff] [blame] | 2329 | spin_lock(&net_family_lock); |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 2330 | net_families[family] = NULL; |
Stephen Hemminger | 55737fd | 2006-09-01 00:23:39 -0700 | [diff] [blame] | 2331 | spin_unlock(&net_family_lock); |
| 2332 | |
| 2333 | synchronize_rcu(); |
| 2334 | |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 2335 | printk(KERN_INFO "NET: Unregistered protocol family %d\n", family); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2336 | } |
| 2337 | |
Andi Kleen | 77d76ea | 2005-12-22 12:43:42 -0800 | [diff] [blame] | 2338 | static int __init sock_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2339 | { |
| 2340 | /* |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 2341 | * Initialize sock SLAB cache. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2342 | */ |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 2343 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2344 | sk_init(); |
| 2345 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2346 | /* |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 2347 | * Initialize skbuff SLAB cache |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2348 | */ |
| 2349 | skb_init(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2350 | |
| 2351 | /* |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 2352 | * Initialize the protocols module. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2353 | */ |
| 2354 | |
| 2355 | init_inodecache(); |
| 2356 | register_filesystem(&sock_fs_type); |
| 2357 | sock_mnt = kern_mount(&sock_fs_type); |
Andi Kleen | 77d76ea | 2005-12-22 12:43:42 -0800 | [diff] [blame] | 2358 | |
| 2359 | /* The real protocol initialization is performed in later initcalls. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2360 | */ |
| 2361 | |
| 2362 | #ifdef CONFIG_NETFILTER |
| 2363 | netfilter_init(); |
| 2364 | #endif |
David S. Miller | cbeb321 | 2005-12-22 12:58:55 -0800 | [diff] [blame] | 2365 | |
| 2366 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2367 | } |
| 2368 | |
Andi Kleen | 77d76ea | 2005-12-22 12:43:42 -0800 | [diff] [blame] | 2369 | core_initcall(sock_init); /* early initcall */ |
| 2370 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2371 | #ifdef CONFIG_PROC_FS |
| 2372 | void socket_seq_show(struct seq_file *seq) |
| 2373 | { |
| 2374 | int cpu; |
| 2375 | int counter = 0; |
| 2376 | |
KAMEZAWA Hiroyuki | 6f91204 | 2006-04-10 22:52:50 -0700 | [diff] [blame] | 2377 | for_each_possible_cpu(cpu) |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 2378 | counter += per_cpu(sockets_in_use, cpu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2379 | |
| 2380 | /* It can be negative, by the way. 8) */ |
| 2381 | if (counter < 0) |
| 2382 | counter = 0; |
| 2383 | |
| 2384 | seq_printf(seq, "sockets: used %d\n", counter); |
| 2385 | } |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 2386 | #endif /* CONFIG_PROC_FS */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2387 | |
Shaun Pereira | 89bbfc9 | 2006-03-21 23:58:08 -0800 | [diff] [blame] | 2388 | #ifdef CONFIG_COMPAT |
Arnd Bergmann | 6b96018 | 2009-11-06 23:10:54 -0800 | [diff] [blame] | 2389 | static int do_siocgstamp(struct net *net, struct socket *sock, |
| 2390 | unsigned int cmd, struct compat_timeval __user *up) |
Arnd Bergmann | 7a22938 | 2009-11-06 23:00:29 -0800 | [diff] [blame] | 2391 | { |
Arnd Bergmann | 7a22938 | 2009-11-06 23:00:29 -0800 | [diff] [blame] | 2392 | mm_segment_t old_fs = get_fs(); |
| 2393 | struct timeval ktv; |
| 2394 | int err; |
| 2395 | |
| 2396 | set_fs(KERNEL_DS); |
Arnd Bergmann | 6b96018 | 2009-11-06 23:10:54 -0800 | [diff] [blame] | 2397 | err = sock_do_ioctl(net, sock, cmd, (unsigned long)&ktv); |
Arnd Bergmann | 7a22938 | 2009-11-06 23:00:29 -0800 | [diff] [blame] | 2398 | set_fs(old_fs); |
| 2399 | if (!err) { |
| 2400 | err = put_user(ktv.tv_sec, &up->tv_sec); |
| 2401 | err |= __put_user(ktv.tv_usec, &up->tv_usec); |
| 2402 | } |
| 2403 | return err; |
| 2404 | } |
| 2405 | |
Arnd Bergmann | 6b96018 | 2009-11-06 23:10:54 -0800 | [diff] [blame] | 2406 | static int do_siocgstampns(struct net *net, struct socket *sock, |
| 2407 | unsigned int cmd, struct compat_timespec __user *up) |
Arnd Bergmann | 7a22938 | 2009-11-06 23:00:29 -0800 | [diff] [blame] | 2408 | { |
Arnd Bergmann | 7a22938 | 2009-11-06 23:00:29 -0800 | [diff] [blame] | 2409 | mm_segment_t old_fs = get_fs(); |
| 2410 | struct timespec kts; |
| 2411 | int err; |
| 2412 | |
| 2413 | set_fs(KERNEL_DS); |
Arnd Bergmann | 6b96018 | 2009-11-06 23:10:54 -0800 | [diff] [blame] | 2414 | err = sock_do_ioctl(net, sock, cmd, (unsigned long)&kts); |
Arnd Bergmann | 7a22938 | 2009-11-06 23:00:29 -0800 | [diff] [blame] | 2415 | set_fs(old_fs); |
| 2416 | if (!err) { |
| 2417 | err = put_user(kts.tv_sec, &up->tv_sec); |
| 2418 | err |= __put_user(kts.tv_nsec, &up->tv_nsec); |
| 2419 | } |
| 2420 | return err; |
| 2421 | } |
| 2422 | |
Arnd Bergmann | 6b96018 | 2009-11-06 23:10:54 -0800 | [diff] [blame] | 2423 | static int dev_ifname32(struct net *net, struct compat_ifreq __user *uifr32) |
Arnd Bergmann | 7a22938 | 2009-11-06 23:00:29 -0800 | [diff] [blame] | 2424 | { |
| 2425 | struct ifreq __user *uifr; |
| 2426 | int err; |
| 2427 | |
| 2428 | uifr = compat_alloc_user_space(sizeof(struct ifreq)); |
Arnd Bergmann | 6b96018 | 2009-11-06 23:10:54 -0800 | [diff] [blame] | 2429 | if (copy_in_user(uifr, uifr32, sizeof(struct compat_ifreq))) |
Arnd Bergmann | 7a22938 | 2009-11-06 23:00:29 -0800 | [diff] [blame] | 2430 | return -EFAULT; |
| 2431 | |
Arnd Bergmann | 6b96018 | 2009-11-06 23:10:54 -0800 | [diff] [blame] | 2432 | err = dev_ioctl(net, SIOCGIFNAME, uifr); |
Arnd Bergmann | 7a22938 | 2009-11-06 23:00:29 -0800 | [diff] [blame] | 2433 | if (err) |
| 2434 | return err; |
| 2435 | |
Arnd Bergmann | 6b96018 | 2009-11-06 23:10:54 -0800 | [diff] [blame] | 2436 | if (copy_in_user(uifr32, uifr, sizeof(struct compat_ifreq))) |
Arnd Bergmann | 7a22938 | 2009-11-06 23:00:29 -0800 | [diff] [blame] | 2437 | return -EFAULT; |
| 2438 | |
| 2439 | return 0; |
| 2440 | } |
| 2441 | |
Arnd Bergmann | 6b96018 | 2009-11-06 23:10:54 -0800 | [diff] [blame] | 2442 | static int dev_ifconf(struct net *net, struct compat_ifconf __user *uifc32) |
Arnd Bergmann | 7a22938 | 2009-11-06 23:00:29 -0800 | [diff] [blame] | 2443 | { |
Arnd Bergmann | 6b96018 | 2009-11-06 23:10:54 -0800 | [diff] [blame] | 2444 | struct compat_ifconf ifc32; |
Arnd Bergmann | 7a22938 | 2009-11-06 23:00:29 -0800 | [diff] [blame] | 2445 | struct ifconf ifc; |
| 2446 | struct ifconf __user *uifc; |
Arnd Bergmann | 6b96018 | 2009-11-06 23:10:54 -0800 | [diff] [blame] | 2447 | struct compat_ifreq __user *ifr32; |
Arnd Bergmann | 7a22938 | 2009-11-06 23:00:29 -0800 | [diff] [blame] | 2448 | struct ifreq __user *ifr; |
| 2449 | unsigned int i, j; |
| 2450 | int err; |
| 2451 | |
Arnd Bergmann | 6b96018 | 2009-11-06 23:10:54 -0800 | [diff] [blame] | 2452 | if (copy_from_user(&ifc32, uifc32, sizeof(struct compat_ifconf))) |
Arnd Bergmann | 7a22938 | 2009-11-06 23:00:29 -0800 | [diff] [blame] | 2453 | return -EFAULT; |
| 2454 | |
| 2455 | if (ifc32.ifcbuf == 0) { |
| 2456 | ifc32.ifc_len = 0; |
| 2457 | ifc.ifc_len = 0; |
| 2458 | ifc.ifc_req = NULL; |
| 2459 | uifc = compat_alloc_user_space(sizeof(struct ifconf)); |
| 2460 | } else { |
Arnd Bergmann | 6b96018 | 2009-11-06 23:10:54 -0800 | [diff] [blame] | 2461 | size_t len =((ifc32.ifc_len / sizeof (struct compat_ifreq)) + 1) * |
Arnd Bergmann | 7a22938 | 2009-11-06 23:00:29 -0800 | [diff] [blame] | 2462 | sizeof (struct ifreq); |
| 2463 | uifc = compat_alloc_user_space(sizeof(struct ifconf) + len); |
| 2464 | ifc.ifc_len = len; |
| 2465 | ifr = ifc.ifc_req = (void __user *)(uifc + 1); |
| 2466 | ifr32 = compat_ptr(ifc32.ifcbuf); |
Arnd Bergmann | 6b96018 | 2009-11-06 23:10:54 -0800 | [diff] [blame] | 2467 | for (i = 0; i < ifc32.ifc_len; i += sizeof (struct compat_ifreq)) { |
| 2468 | if (copy_in_user(ifr, ifr32, sizeof(struct compat_ifreq))) |
Arnd Bergmann | 7a22938 | 2009-11-06 23:00:29 -0800 | [diff] [blame] | 2469 | return -EFAULT; |
| 2470 | ifr++; |
| 2471 | ifr32++; |
| 2472 | } |
| 2473 | } |
| 2474 | if (copy_to_user(uifc, &ifc, sizeof(struct ifconf))) |
| 2475 | return -EFAULT; |
| 2476 | |
Arnd Bergmann | 6b96018 | 2009-11-06 23:10:54 -0800 | [diff] [blame] | 2477 | err = dev_ioctl(net, SIOCGIFCONF, uifc); |
Arnd Bergmann | 7a22938 | 2009-11-06 23:00:29 -0800 | [diff] [blame] | 2478 | if (err) |
| 2479 | return err; |
| 2480 | |
| 2481 | if (copy_from_user(&ifc, uifc, sizeof(struct ifconf))) |
| 2482 | return -EFAULT; |
| 2483 | |
| 2484 | ifr = ifc.ifc_req; |
| 2485 | ifr32 = compat_ptr(ifc32.ifcbuf); |
| 2486 | for (i = 0, j = 0; |
Arnd Bergmann | 6b96018 | 2009-11-06 23:10:54 -0800 | [diff] [blame] | 2487 | i + sizeof (struct compat_ifreq) <= ifc32.ifc_len && j < ifc.ifc_len; |
| 2488 | i += sizeof (struct compat_ifreq), j += sizeof (struct ifreq)) { |
| 2489 | if (copy_in_user(ifr32, ifr, sizeof (struct compat_ifreq))) |
Arnd Bergmann | 7a22938 | 2009-11-06 23:00:29 -0800 | [diff] [blame] | 2490 | return -EFAULT; |
| 2491 | ifr32++; |
| 2492 | ifr++; |
| 2493 | } |
| 2494 | |
| 2495 | if (ifc32.ifcbuf == 0) { |
| 2496 | /* Translate from 64-bit structure multiple to |
| 2497 | * a 32-bit one. |
| 2498 | */ |
| 2499 | i = ifc.ifc_len; |
Arnd Bergmann | 6b96018 | 2009-11-06 23:10:54 -0800 | [diff] [blame] | 2500 | i = ((i / sizeof(struct ifreq)) * sizeof(struct compat_ifreq)); |
Arnd Bergmann | 7a22938 | 2009-11-06 23:00:29 -0800 | [diff] [blame] | 2501 | ifc32.ifc_len = i; |
| 2502 | } else { |
| 2503 | ifc32.ifc_len = i; |
| 2504 | } |
Arnd Bergmann | 6b96018 | 2009-11-06 23:10:54 -0800 | [diff] [blame] | 2505 | if (copy_to_user(uifc32, &ifc32, sizeof(struct compat_ifconf))) |
Arnd Bergmann | 7a22938 | 2009-11-06 23:00:29 -0800 | [diff] [blame] | 2506 | return -EFAULT; |
| 2507 | |
| 2508 | return 0; |
| 2509 | } |
| 2510 | |
Arnd Bergmann | 6b96018 | 2009-11-06 23:10:54 -0800 | [diff] [blame] | 2511 | static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32) |
Arnd Bergmann | 7a22938 | 2009-11-06 23:00:29 -0800 | [diff] [blame] | 2512 | { |
| 2513 | struct ifreq __user *ifr; |
Arnd Bergmann | 7a22938 | 2009-11-06 23:00:29 -0800 | [diff] [blame] | 2514 | u32 data; |
| 2515 | void __user *datap; |
| 2516 | |
| 2517 | ifr = compat_alloc_user_space(sizeof(*ifr)); |
Arnd Bergmann | 7a22938 | 2009-11-06 23:00:29 -0800 | [diff] [blame] | 2518 | |
| 2519 | if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ)) |
| 2520 | return -EFAULT; |
| 2521 | |
| 2522 | if (get_user(data, &ifr32->ifr_ifru.ifru_data)) |
| 2523 | return -EFAULT; |
| 2524 | |
| 2525 | datap = compat_ptr(data); |
| 2526 | if (put_user(datap, &ifr->ifr_ifru.ifru_data)) |
| 2527 | return -EFAULT; |
| 2528 | |
Arnd Bergmann | 6b96018 | 2009-11-06 23:10:54 -0800 | [diff] [blame] | 2529 | return dev_ioctl(net, SIOCETHTOOL, ifr); |
Arnd Bergmann | 7a22938 | 2009-11-06 23:00:29 -0800 | [diff] [blame] | 2530 | } |
| 2531 | |
Arnd Bergmann | 7a50a24 | 2009-11-08 20:57:03 -0800 | [diff] [blame] | 2532 | static int compat_siocwandev(struct net *net, struct compat_ifreq __user *uifr32) |
| 2533 | { |
| 2534 | void __user *uptr; |
| 2535 | compat_uptr_t uptr32; |
| 2536 | struct ifreq __user *uifr; |
| 2537 | |
| 2538 | uifr = compat_alloc_user_space(sizeof (*uifr)); |
| 2539 | if (copy_in_user(uifr, uifr32, sizeof(struct compat_ifreq))) |
| 2540 | return -EFAULT; |
| 2541 | |
| 2542 | if (get_user(uptr32, &uifr32->ifr_settings.ifs_ifsu)) |
| 2543 | return -EFAULT; |
| 2544 | |
| 2545 | uptr = compat_ptr(uptr32); |
| 2546 | |
| 2547 | if (put_user(uptr, &uifr->ifr_settings.ifs_ifsu.raw_hdlc)) |
| 2548 | return -EFAULT; |
| 2549 | |
| 2550 | return dev_ioctl(net, SIOCWANDEV, uifr); |
| 2551 | } |
| 2552 | |
Arnd Bergmann | 6b96018 | 2009-11-06 23:10:54 -0800 | [diff] [blame] | 2553 | static int bond_ioctl(struct net *net, unsigned int cmd, |
| 2554 | struct compat_ifreq __user *ifr32) |
Arnd Bergmann | 7a22938 | 2009-11-06 23:00:29 -0800 | [diff] [blame] | 2555 | { |
| 2556 | struct ifreq kifr; |
| 2557 | struct ifreq __user *uifr; |
Arnd Bergmann | 7a22938 | 2009-11-06 23:00:29 -0800 | [diff] [blame] | 2558 | mm_segment_t old_fs; |
| 2559 | int err; |
| 2560 | u32 data; |
| 2561 | void __user *datap; |
| 2562 | |
| 2563 | switch (cmd) { |
| 2564 | case SIOCBONDENSLAVE: |
| 2565 | case SIOCBONDRELEASE: |
| 2566 | case SIOCBONDSETHWADDR: |
| 2567 | case SIOCBONDCHANGEACTIVE: |
Arnd Bergmann | 6b96018 | 2009-11-06 23:10:54 -0800 | [diff] [blame] | 2568 | if (copy_from_user(&kifr, ifr32, sizeof(struct compat_ifreq))) |
Arnd Bergmann | 7a22938 | 2009-11-06 23:00:29 -0800 | [diff] [blame] | 2569 | return -EFAULT; |
| 2570 | |
| 2571 | old_fs = get_fs(); |
| 2572 | set_fs (KERNEL_DS); |
Arnd Bergmann | 6b96018 | 2009-11-06 23:10:54 -0800 | [diff] [blame] | 2573 | err = dev_ioctl(net, cmd, &kifr); |
Arnd Bergmann | 7a22938 | 2009-11-06 23:00:29 -0800 | [diff] [blame] | 2574 | set_fs (old_fs); |
| 2575 | |
| 2576 | return err; |
| 2577 | case SIOCBONDSLAVEINFOQUERY: |
| 2578 | case SIOCBONDINFOQUERY: |
| 2579 | uifr = compat_alloc_user_space(sizeof(*uifr)); |
| 2580 | if (copy_in_user(&uifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ)) |
| 2581 | return -EFAULT; |
| 2582 | |
| 2583 | if (get_user(data, &ifr32->ifr_ifru.ifru_data)) |
| 2584 | return -EFAULT; |
| 2585 | |
| 2586 | datap = compat_ptr(data); |
| 2587 | if (put_user(datap, &uifr->ifr_ifru.ifru_data)) |
| 2588 | return -EFAULT; |
| 2589 | |
Arnd Bergmann | 6b96018 | 2009-11-06 23:10:54 -0800 | [diff] [blame] | 2590 | return dev_ioctl(net, cmd, uifr); |
Arnd Bergmann | 7a22938 | 2009-11-06 23:00:29 -0800 | [diff] [blame] | 2591 | default: |
| 2592 | return -EINVAL; |
| 2593 | }; |
| 2594 | } |
| 2595 | |
Arnd Bergmann | 6b96018 | 2009-11-06 23:10:54 -0800 | [diff] [blame] | 2596 | static int siocdevprivate_ioctl(struct net *net, unsigned int cmd, |
| 2597 | struct compat_ifreq __user *u_ifreq32) |
Arnd Bergmann | 7a22938 | 2009-11-06 23:00:29 -0800 | [diff] [blame] | 2598 | { |
| 2599 | struct ifreq __user *u_ifreq64; |
Arnd Bergmann | 7a22938 | 2009-11-06 23:00:29 -0800 | [diff] [blame] | 2600 | char tmp_buf[IFNAMSIZ]; |
| 2601 | void __user *data64; |
| 2602 | u32 data32; |
| 2603 | |
| 2604 | if (copy_from_user(&tmp_buf[0], &(u_ifreq32->ifr_ifrn.ifrn_name[0]), |
| 2605 | IFNAMSIZ)) |
| 2606 | return -EFAULT; |
| 2607 | if (__get_user(data32, &u_ifreq32->ifr_ifru.ifru_data)) |
| 2608 | return -EFAULT; |
| 2609 | data64 = compat_ptr(data32); |
| 2610 | |
| 2611 | u_ifreq64 = compat_alloc_user_space(sizeof(*u_ifreq64)); |
| 2612 | |
| 2613 | /* Don't check these user accesses, just let that get trapped |
| 2614 | * in the ioctl handler instead. |
| 2615 | */ |
| 2616 | if (copy_to_user(&u_ifreq64->ifr_ifrn.ifrn_name[0], &tmp_buf[0], |
| 2617 | IFNAMSIZ)) |
| 2618 | return -EFAULT; |
| 2619 | if (__put_user(data64, &u_ifreq64->ifr_ifru.ifru_data)) |
| 2620 | return -EFAULT; |
| 2621 | |
Arnd Bergmann | 6b96018 | 2009-11-06 23:10:54 -0800 | [diff] [blame] | 2622 | return dev_ioctl(net, cmd, u_ifreq64); |
Arnd Bergmann | 7a22938 | 2009-11-06 23:00:29 -0800 | [diff] [blame] | 2623 | } |
| 2624 | |
Arnd Bergmann | 6b96018 | 2009-11-06 23:10:54 -0800 | [diff] [blame] | 2625 | static int dev_ifsioc(struct net *net, struct socket *sock, |
| 2626 | unsigned int cmd, struct compat_ifreq __user *uifr32) |
Arnd Bergmann | 7a22938 | 2009-11-06 23:00:29 -0800 | [diff] [blame] | 2627 | { |
Arnd Bergmann | a2116ed | 2009-11-11 03:39:40 +0000 | [diff] [blame] | 2628 | struct ifreq __user *uifr; |
Arnd Bergmann | 7a22938 | 2009-11-06 23:00:29 -0800 | [diff] [blame] | 2629 | int err; |
| 2630 | |
Arnd Bergmann | a2116ed | 2009-11-11 03:39:40 +0000 | [diff] [blame] | 2631 | uifr = compat_alloc_user_space(sizeof(*uifr)); |
| 2632 | if (copy_in_user(uifr, uifr32, sizeof(*uifr32))) |
| 2633 | return -EFAULT; |
| 2634 | |
| 2635 | err = sock_do_ioctl(net, sock, cmd, (unsigned long)uifr); |
| 2636 | |
Arnd Bergmann | 7a22938 | 2009-11-06 23:00:29 -0800 | [diff] [blame] | 2637 | if (!err) { |
| 2638 | switch (cmd) { |
| 2639 | case SIOCGIFFLAGS: |
| 2640 | case SIOCGIFMETRIC: |
| 2641 | case SIOCGIFMTU: |
| 2642 | case SIOCGIFMEM: |
| 2643 | case SIOCGIFHWADDR: |
| 2644 | case SIOCGIFINDEX: |
| 2645 | case SIOCGIFADDR: |
| 2646 | case SIOCGIFBRDADDR: |
| 2647 | case SIOCGIFDSTADDR: |
| 2648 | case SIOCGIFNETMASK: |
Arnd Bergmann | fab2532 | 2009-11-08 20:56:21 -0800 | [diff] [blame] | 2649 | case SIOCGIFPFLAGS: |
Arnd Bergmann | 7a22938 | 2009-11-06 23:00:29 -0800 | [diff] [blame] | 2650 | case SIOCGIFTXQLEN: |
Arnd Bergmann | fab2532 | 2009-11-08 20:56:21 -0800 | [diff] [blame] | 2651 | case SIOCGMIIPHY: |
| 2652 | case SIOCGMIIREG: |
Arnd Bergmann | a2116ed | 2009-11-11 03:39:40 +0000 | [diff] [blame] | 2653 | if (copy_in_user(uifr32, uifr, sizeof(*uifr32))) |
Arnd Bergmann | 7a22938 | 2009-11-06 23:00:29 -0800 | [diff] [blame] | 2654 | err = -EFAULT; |
| 2655 | break; |
| 2656 | } |
| 2657 | } |
| 2658 | return err; |
| 2659 | } |
| 2660 | |
Arnd Bergmann | a2116ed | 2009-11-11 03:39:40 +0000 | [diff] [blame] | 2661 | static int compat_sioc_ifmap(struct net *net, unsigned int cmd, |
| 2662 | struct compat_ifreq __user *uifr32) |
| 2663 | { |
| 2664 | struct ifreq ifr; |
| 2665 | struct compat_ifmap __user *uifmap32; |
| 2666 | mm_segment_t old_fs; |
| 2667 | int err; |
| 2668 | |
| 2669 | uifmap32 = &uifr32->ifr_ifru.ifru_map; |
| 2670 | err = copy_from_user(&ifr, uifr32, sizeof(ifr.ifr_name)); |
| 2671 | err |= __get_user(ifr.ifr_map.mem_start, &uifmap32->mem_start); |
| 2672 | err |= __get_user(ifr.ifr_map.mem_end, &uifmap32->mem_end); |
| 2673 | err |= __get_user(ifr.ifr_map.base_addr, &uifmap32->base_addr); |
| 2674 | err |= __get_user(ifr.ifr_map.irq, &uifmap32->irq); |
| 2675 | err |= __get_user(ifr.ifr_map.dma, &uifmap32->dma); |
| 2676 | err |= __get_user(ifr.ifr_map.port, &uifmap32->port); |
| 2677 | if (err) |
| 2678 | return -EFAULT; |
| 2679 | |
| 2680 | old_fs = get_fs(); |
| 2681 | set_fs (KERNEL_DS); |
| 2682 | err = dev_ioctl(net, cmd, (void __user *)&ifr); |
| 2683 | set_fs (old_fs); |
| 2684 | |
| 2685 | if (cmd == SIOCGIFMAP && !err) { |
| 2686 | err = copy_to_user(uifr32, &ifr, sizeof(ifr.ifr_name)); |
| 2687 | err |= __put_user(ifr.ifr_map.mem_start, &uifmap32->mem_start); |
| 2688 | err |= __put_user(ifr.ifr_map.mem_end, &uifmap32->mem_end); |
| 2689 | err |= __put_user(ifr.ifr_map.base_addr, &uifmap32->base_addr); |
| 2690 | err |= __put_user(ifr.ifr_map.irq, &uifmap32->irq); |
| 2691 | err |= __put_user(ifr.ifr_map.dma, &uifmap32->dma); |
| 2692 | err |= __put_user(ifr.ifr_map.port, &uifmap32->port); |
| 2693 | if (err) |
| 2694 | err = -EFAULT; |
| 2695 | } |
| 2696 | return err; |
| 2697 | } |
| 2698 | |
| 2699 | static int compat_siocshwtstamp(struct net *net, struct compat_ifreq __user *uifr32) |
| 2700 | { |
| 2701 | void __user *uptr; |
| 2702 | compat_uptr_t uptr32; |
| 2703 | struct ifreq __user *uifr; |
| 2704 | |
| 2705 | uifr = compat_alloc_user_space(sizeof (*uifr)); |
| 2706 | if (copy_in_user(uifr, uifr32, sizeof(struct compat_ifreq))) |
| 2707 | return -EFAULT; |
| 2708 | |
| 2709 | if (get_user(uptr32, &uifr32->ifr_data)) |
| 2710 | return -EFAULT; |
| 2711 | |
| 2712 | uptr = compat_ptr(uptr32); |
| 2713 | |
| 2714 | if (put_user(uptr, &uifr->ifr_data)) |
| 2715 | return -EFAULT; |
| 2716 | |
| 2717 | return dev_ioctl(net, SIOCSHWTSTAMP, uifr); |
| 2718 | } |
| 2719 | |
Arnd Bergmann | 7a22938 | 2009-11-06 23:00:29 -0800 | [diff] [blame] | 2720 | struct rtentry32 { |
| 2721 | u32 rt_pad1; |
| 2722 | struct sockaddr rt_dst; /* target address */ |
| 2723 | struct sockaddr rt_gateway; /* gateway addr (RTF_GATEWAY) */ |
| 2724 | struct sockaddr rt_genmask; /* target network mask (IP) */ |
| 2725 | unsigned short rt_flags; |
| 2726 | short rt_pad2; |
| 2727 | u32 rt_pad3; |
| 2728 | unsigned char rt_tos; |
| 2729 | unsigned char rt_class; |
| 2730 | short rt_pad4; |
| 2731 | short rt_metric; /* +1 for binary compatibility! */ |
| 2732 | /* char * */ u32 rt_dev; /* forcing the device at add */ |
| 2733 | u32 rt_mtu; /* per route MTU/Window */ |
| 2734 | u32 rt_window; /* Window clamping */ |
| 2735 | unsigned short rt_irtt; /* Initial RTT */ |
| 2736 | }; |
| 2737 | |
| 2738 | struct in6_rtmsg32 { |
| 2739 | struct in6_addr rtmsg_dst; |
| 2740 | struct in6_addr rtmsg_src; |
| 2741 | struct in6_addr rtmsg_gateway; |
| 2742 | u32 rtmsg_type; |
| 2743 | u16 rtmsg_dst_len; |
| 2744 | u16 rtmsg_src_len; |
| 2745 | u32 rtmsg_metric; |
| 2746 | u32 rtmsg_info; |
| 2747 | u32 rtmsg_flags; |
| 2748 | s32 rtmsg_ifindex; |
| 2749 | }; |
| 2750 | |
Arnd Bergmann | 6b96018 | 2009-11-06 23:10:54 -0800 | [diff] [blame] | 2751 | static int routing_ioctl(struct net *net, struct socket *sock, |
| 2752 | unsigned int cmd, void __user *argp) |
Arnd Bergmann | 7a22938 | 2009-11-06 23:00:29 -0800 | [diff] [blame] | 2753 | { |
| 2754 | int ret; |
| 2755 | void *r = NULL; |
| 2756 | struct in6_rtmsg r6; |
| 2757 | struct rtentry r4; |
| 2758 | char devname[16]; |
| 2759 | u32 rtdev; |
| 2760 | mm_segment_t old_fs = get_fs(); |
| 2761 | |
Arnd Bergmann | 6b96018 | 2009-11-06 23:10:54 -0800 | [diff] [blame] | 2762 | if (sock && sock->sk && sock->sk->sk_family == AF_INET6) { /* ipv6 */ |
| 2763 | struct in6_rtmsg32 __user *ur6 = argp; |
Arnd Bergmann | 7a22938 | 2009-11-06 23:00:29 -0800 | [diff] [blame] | 2764 | ret = copy_from_user (&r6.rtmsg_dst, &(ur6->rtmsg_dst), |
| 2765 | 3 * sizeof(struct in6_addr)); |
| 2766 | ret |= __get_user (r6.rtmsg_type, &(ur6->rtmsg_type)); |
| 2767 | ret |= __get_user (r6.rtmsg_dst_len, &(ur6->rtmsg_dst_len)); |
| 2768 | ret |= __get_user (r6.rtmsg_src_len, &(ur6->rtmsg_src_len)); |
| 2769 | ret |= __get_user (r6.rtmsg_metric, &(ur6->rtmsg_metric)); |
| 2770 | ret |= __get_user (r6.rtmsg_info, &(ur6->rtmsg_info)); |
| 2771 | ret |= __get_user (r6.rtmsg_flags, &(ur6->rtmsg_flags)); |
| 2772 | ret |= __get_user (r6.rtmsg_ifindex, &(ur6->rtmsg_ifindex)); |
| 2773 | |
| 2774 | r = (void *) &r6; |
| 2775 | } else { /* ipv4 */ |
Arnd Bergmann | 6b96018 | 2009-11-06 23:10:54 -0800 | [diff] [blame] | 2776 | struct rtentry32 __user *ur4 = argp; |
Arnd Bergmann | 7a22938 | 2009-11-06 23:00:29 -0800 | [diff] [blame] | 2777 | ret = copy_from_user (&r4.rt_dst, &(ur4->rt_dst), |
| 2778 | 3 * sizeof(struct sockaddr)); |
| 2779 | ret |= __get_user (r4.rt_flags, &(ur4->rt_flags)); |
| 2780 | ret |= __get_user (r4.rt_metric, &(ur4->rt_metric)); |
| 2781 | ret |= __get_user (r4.rt_mtu, &(ur4->rt_mtu)); |
| 2782 | ret |= __get_user (r4.rt_window, &(ur4->rt_window)); |
| 2783 | ret |= __get_user (r4.rt_irtt, &(ur4->rt_irtt)); |
| 2784 | ret |= __get_user (rtdev, &(ur4->rt_dev)); |
| 2785 | if (rtdev) { |
| 2786 | ret |= copy_from_user (devname, compat_ptr(rtdev), 15); |
| 2787 | r4.rt_dev = devname; devname[15] = 0; |
| 2788 | } else |
| 2789 | r4.rt_dev = NULL; |
| 2790 | |
| 2791 | r = (void *) &r4; |
| 2792 | } |
| 2793 | |
| 2794 | if (ret) { |
| 2795 | ret = -EFAULT; |
| 2796 | goto out; |
| 2797 | } |
| 2798 | |
| 2799 | set_fs (KERNEL_DS); |
Arnd Bergmann | 6b96018 | 2009-11-06 23:10:54 -0800 | [diff] [blame] | 2800 | ret = sock_do_ioctl(net, sock, cmd, (unsigned long) r); |
Arnd Bergmann | 7a22938 | 2009-11-06 23:00:29 -0800 | [diff] [blame] | 2801 | set_fs (old_fs); |
| 2802 | |
| 2803 | out: |
Arnd Bergmann | 7a22938 | 2009-11-06 23:00:29 -0800 | [diff] [blame] | 2804 | return ret; |
| 2805 | } |
| 2806 | |
| 2807 | /* Since old style bridge ioctl's endup using SIOCDEVPRIVATE |
| 2808 | * for some operations; this forces use of the newer bridge-utils that |
| 2809 | * use compatiable ioctls |
| 2810 | */ |
Arnd Bergmann | 6b96018 | 2009-11-06 23:10:54 -0800 | [diff] [blame] | 2811 | static int old_bridge_ioctl(compat_ulong_t __user *argp) |
Arnd Bergmann | 7a22938 | 2009-11-06 23:00:29 -0800 | [diff] [blame] | 2812 | { |
Arnd Bergmann | 6b96018 | 2009-11-06 23:10:54 -0800 | [diff] [blame] | 2813 | compat_ulong_t tmp; |
Arnd Bergmann | 7a22938 | 2009-11-06 23:00:29 -0800 | [diff] [blame] | 2814 | |
Arnd Bergmann | 6b96018 | 2009-11-06 23:10:54 -0800 | [diff] [blame] | 2815 | if (get_user(tmp, argp)) |
Arnd Bergmann | 7a22938 | 2009-11-06 23:00:29 -0800 | [diff] [blame] | 2816 | return -EFAULT; |
| 2817 | if (tmp == BRCTL_GET_VERSION) |
| 2818 | return BRCTL_VERSION + 1; |
| 2819 | return -EINVAL; |
| 2820 | } |
| 2821 | |
Arnd Bergmann | 6b96018 | 2009-11-06 23:10:54 -0800 | [diff] [blame] | 2822 | static int compat_sock_ioctl_trans(struct file *file, struct socket *sock, |
| 2823 | unsigned int cmd, unsigned long arg) |
| 2824 | { |
| 2825 | void __user *argp = compat_ptr(arg); |
| 2826 | struct sock *sk = sock->sk; |
| 2827 | struct net *net = sock_net(sk); |
Arnd Bergmann | 7a22938 | 2009-11-06 23:00:29 -0800 | [diff] [blame] | 2828 | |
Arnd Bergmann | 6b96018 | 2009-11-06 23:10:54 -0800 | [diff] [blame] | 2829 | if (cmd >= SIOCDEVPRIVATE && cmd <= (SIOCDEVPRIVATE + 15)) |
| 2830 | return siocdevprivate_ioctl(net, cmd, argp); |
Arnd Bergmann | 7a22938 | 2009-11-06 23:00:29 -0800 | [diff] [blame] | 2831 | |
Arnd Bergmann | 6b96018 | 2009-11-06 23:10:54 -0800 | [diff] [blame] | 2832 | switch (cmd) { |
| 2833 | case SIOCSIFBR: |
| 2834 | case SIOCGIFBR: |
| 2835 | return old_bridge_ioctl(argp); |
| 2836 | case SIOCGIFNAME: |
| 2837 | return dev_ifname32(net, argp); |
| 2838 | case SIOCGIFCONF: |
| 2839 | return dev_ifconf(net, argp); |
| 2840 | case SIOCETHTOOL: |
| 2841 | return ethtool_ioctl(net, argp); |
Arnd Bergmann | 7a50a24 | 2009-11-08 20:57:03 -0800 | [diff] [blame] | 2842 | case SIOCWANDEV: |
| 2843 | return compat_siocwandev(net, argp); |
Arnd Bergmann | a2116ed | 2009-11-11 03:39:40 +0000 | [diff] [blame] | 2844 | case SIOCGIFMAP: |
| 2845 | case SIOCSIFMAP: |
| 2846 | return compat_sioc_ifmap(net, cmd, argp); |
Arnd Bergmann | 6b96018 | 2009-11-06 23:10:54 -0800 | [diff] [blame] | 2847 | case SIOCBONDENSLAVE: |
| 2848 | case SIOCBONDRELEASE: |
| 2849 | case SIOCBONDSETHWADDR: |
| 2850 | case SIOCBONDSLAVEINFOQUERY: |
| 2851 | case SIOCBONDINFOQUERY: |
| 2852 | case SIOCBONDCHANGEACTIVE: |
| 2853 | return bond_ioctl(net, cmd, argp); |
| 2854 | case SIOCADDRT: |
| 2855 | case SIOCDELRT: |
| 2856 | return routing_ioctl(net, sock, cmd, argp); |
| 2857 | case SIOCGSTAMP: |
| 2858 | return do_siocgstamp(net, sock, cmd, argp); |
| 2859 | case SIOCGSTAMPNS: |
| 2860 | return do_siocgstampns(net, sock, cmd, argp); |
Arnd Bergmann | a2116ed | 2009-11-11 03:39:40 +0000 | [diff] [blame] | 2861 | case SIOCSHWTSTAMP: |
| 2862 | return compat_siocshwtstamp(net, argp); |
Arnd Bergmann | 7a22938 | 2009-11-06 23:00:29 -0800 | [diff] [blame] | 2863 | |
Arnd Bergmann | 6b96018 | 2009-11-06 23:10:54 -0800 | [diff] [blame] | 2864 | case FIOSETOWN: |
| 2865 | case SIOCSPGRP: |
| 2866 | case FIOGETOWN: |
| 2867 | case SIOCGPGRP: |
| 2868 | case SIOCBRADDBR: |
| 2869 | case SIOCBRDELBR: |
| 2870 | case SIOCGIFVLAN: |
| 2871 | case SIOCSIFVLAN: |
| 2872 | case SIOCADDDLCI: |
| 2873 | case SIOCDELDLCI: |
| 2874 | return sock_ioctl(file, cmd, arg); |
| 2875 | |
| 2876 | case SIOCGIFFLAGS: |
| 2877 | case SIOCSIFFLAGS: |
| 2878 | case SIOCGIFMETRIC: |
| 2879 | case SIOCSIFMETRIC: |
| 2880 | case SIOCGIFMTU: |
| 2881 | case SIOCSIFMTU: |
| 2882 | case SIOCGIFMEM: |
| 2883 | case SIOCSIFMEM: |
| 2884 | case SIOCGIFHWADDR: |
| 2885 | case SIOCSIFHWADDR: |
| 2886 | case SIOCADDMULTI: |
| 2887 | case SIOCDELMULTI: |
| 2888 | case SIOCGIFINDEX: |
Arnd Bergmann | 6b96018 | 2009-11-06 23:10:54 -0800 | [diff] [blame] | 2889 | case SIOCGIFADDR: |
| 2890 | case SIOCSIFADDR: |
| 2891 | case SIOCSIFHWBROADCAST: |
Arnd Bergmann | 6b96018 | 2009-11-06 23:10:54 -0800 | [diff] [blame] | 2892 | case SIOCDIFADDR: |
Arnd Bergmann | 6b96018 | 2009-11-06 23:10:54 -0800 | [diff] [blame] | 2893 | case SIOCGIFBRDADDR: |
| 2894 | case SIOCSIFBRDADDR: |
| 2895 | case SIOCGIFDSTADDR: |
| 2896 | case SIOCSIFDSTADDR: |
| 2897 | case SIOCGIFNETMASK: |
| 2898 | case SIOCSIFNETMASK: |
| 2899 | case SIOCSIFPFLAGS: |
| 2900 | case SIOCGIFPFLAGS: |
| 2901 | case SIOCGIFTXQLEN: |
| 2902 | case SIOCSIFTXQLEN: |
| 2903 | case SIOCBRADDIF: |
| 2904 | case SIOCBRDELIF: |
Arnd Bergmann | 9177efd | 2009-11-06 08:09:09 +0000 | [diff] [blame] | 2905 | case SIOCSIFNAME: |
| 2906 | case SIOCGMIIPHY: |
| 2907 | case SIOCGMIIREG: |
| 2908 | case SIOCSMIIREG: |
Arnd Bergmann | 6b96018 | 2009-11-06 23:10:54 -0800 | [diff] [blame] | 2909 | return dev_ifsioc(net, sock, cmd, argp); |
Arnd Bergmann | 9177efd | 2009-11-06 08:09:09 +0000 | [diff] [blame] | 2910 | |
Arnd Bergmann | 6b96018 | 2009-11-06 23:10:54 -0800 | [diff] [blame] | 2911 | case SIOCSARP: |
| 2912 | case SIOCGARP: |
| 2913 | case SIOCDARP: |
Arnd Bergmann | 6b96018 | 2009-11-06 23:10:54 -0800 | [diff] [blame] | 2914 | case SIOCATMARK: |
Arnd Bergmann | 9177efd | 2009-11-06 08:09:09 +0000 | [diff] [blame] | 2915 | return sock_do_ioctl(net, sock, cmd, arg); |
| 2916 | } |
| 2917 | |
| 2918 | /* Prevent warning from compat_sys_ioctl, these always |
| 2919 | * result in -EINVAL in the native case anyway. */ |
| 2920 | switch (cmd) { |
| 2921 | case SIOCRTMSG: |
| 2922 | case SIOCGIFCOUNT: |
Arnd Bergmann | 6b96018 | 2009-11-06 23:10:54 -0800 | [diff] [blame] | 2923 | case SIOCSRARP: |
| 2924 | case SIOCGRARP: |
| 2925 | case SIOCDRARP: |
Arnd Bergmann | 9177efd | 2009-11-06 08:09:09 +0000 | [diff] [blame] | 2926 | case SIOCSIFLINK: |
| 2927 | case SIOCGIFSLAVE: |
| 2928 | case SIOCSIFSLAVE: |
| 2929 | return -EINVAL; |
Arnd Bergmann | 6b96018 | 2009-11-06 23:10:54 -0800 | [diff] [blame] | 2930 | } |
| 2931 | |
| 2932 | return -ENOIOCTLCMD; |
| 2933 | } |
Arnd Bergmann | 7a22938 | 2009-11-06 23:00:29 -0800 | [diff] [blame] | 2934 | |
Shaun Pereira | 89bbfc9 | 2006-03-21 23:58:08 -0800 | [diff] [blame] | 2935 | static long compat_sock_ioctl(struct file *file, unsigned cmd, |
Stephen Hemminger | 89bddce | 2006-09-01 00:19:31 -0700 | [diff] [blame] | 2936 | unsigned long arg) |
Shaun Pereira | 89bbfc9 | 2006-03-21 23:58:08 -0800 | [diff] [blame] | 2937 | { |
| 2938 | struct socket *sock = file->private_data; |
| 2939 | int ret = -ENOIOCTLCMD; |
David S. Miller | 87de87d | 2008-06-03 09:14:03 -0700 | [diff] [blame] | 2940 | struct sock *sk; |
| 2941 | struct net *net; |
| 2942 | |
| 2943 | sk = sock->sk; |
| 2944 | net = sock_net(sk); |
Shaun Pereira | 89bbfc9 | 2006-03-21 23:58:08 -0800 | [diff] [blame] | 2945 | |
| 2946 | if (sock->ops->compat_ioctl) |
| 2947 | ret = sock->ops->compat_ioctl(sock, cmd, arg); |
| 2948 | |
David S. Miller | 87de87d | 2008-06-03 09:14:03 -0700 | [diff] [blame] | 2949 | if (ret == -ENOIOCTLCMD && |
| 2950 | (cmd >= SIOCIWFIRST && cmd <= SIOCIWLAST)) |
| 2951 | ret = compat_wext_handle_ioctl(net, cmd, arg); |
| 2952 | |
Arnd Bergmann | 6b96018 | 2009-11-06 23:10:54 -0800 | [diff] [blame] | 2953 | if (ret == -ENOIOCTLCMD) |
| 2954 | ret = compat_sock_ioctl_trans(file, sock, cmd, arg); |
| 2955 | |
Shaun Pereira | 89bbfc9 | 2006-03-21 23:58:08 -0800 | [diff] [blame] | 2956 | return ret; |
| 2957 | } |
| 2958 | #endif |
| 2959 | |
Sridhar Samudrala | ac5a488 | 2006-08-07 20:57:31 -0700 | [diff] [blame] | 2960 | int kernel_bind(struct socket *sock, struct sockaddr *addr, int addrlen) |
| 2961 | { |
| 2962 | return sock->ops->bind(sock, addr, addrlen); |
| 2963 | } |
| 2964 | |
| 2965 | int kernel_listen(struct socket *sock, int backlog) |
| 2966 | { |
| 2967 | return sock->ops->listen(sock, backlog); |
| 2968 | } |
| 2969 | |
| 2970 | int kernel_accept(struct socket *sock, struct socket **newsock, int flags) |
| 2971 | { |
| 2972 | struct sock *sk = sock->sk; |
| 2973 | int err; |
| 2974 | |
| 2975 | err = sock_create_lite(sk->sk_family, sk->sk_type, sk->sk_protocol, |
| 2976 | newsock); |
| 2977 | if (err < 0) |
| 2978 | goto done; |
| 2979 | |
| 2980 | err = sock->ops->accept(sock, *newsock, flags); |
| 2981 | if (err < 0) { |
| 2982 | sock_release(*newsock); |
Tony Battersby | fa8705b | 2007-10-10 21:09:04 -0700 | [diff] [blame] | 2983 | *newsock = NULL; |
Sridhar Samudrala | ac5a488 | 2006-08-07 20:57:31 -0700 | [diff] [blame] | 2984 | goto done; |
| 2985 | } |
| 2986 | |
| 2987 | (*newsock)->ops = sock->ops; |
Wei Yongjun | 1b08534 | 2008-12-18 19:35:10 -0800 | [diff] [blame] | 2988 | __module_get((*newsock)->ops->owner); |
Sridhar Samudrala | ac5a488 | 2006-08-07 20:57:31 -0700 | [diff] [blame] | 2989 | |
| 2990 | done: |
| 2991 | return err; |
| 2992 | } |
| 2993 | |
| 2994 | int kernel_connect(struct socket *sock, struct sockaddr *addr, int addrlen, |
YOSHIFUJI Hideaki | 4768fbc | 2007-02-09 23:25:31 +0900 | [diff] [blame] | 2995 | int flags) |
Sridhar Samudrala | ac5a488 | 2006-08-07 20:57:31 -0700 | [diff] [blame] | 2996 | { |
| 2997 | return sock->ops->connect(sock, addr, addrlen, flags); |
| 2998 | } |
| 2999 | |
| 3000 | int kernel_getsockname(struct socket *sock, struct sockaddr *addr, |
| 3001 | int *addrlen) |
| 3002 | { |
| 3003 | return sock->ops->getname(sock, addr, addrlen, 0); |
| 3004 | } |
| 3005 | |
| 3006 | int kernel_getpeername(struct socket *sock, struct sockaddr *addr, |
| 3007 | int *addrlen) |
| 3008 | { |
| 3009 | return sock->ops->getname(sock, addr, addrlen, 1); |
| 3010 | } |
| 3011 | |
| 3012 | int kernel_getsockopt(struct socket *sock, int level, int optname, |
| 3013 | char *optval, int *optlen) |
| 3014 | { |
| 3015 | mm_segment_t oldfs = get_fs(); |
| 3016 | int err; |
| 3017 | |
| 3018 | set_fs(KERNEL_DS); |
| 3019 | if (level == SOL_SOCKET) |
| 3020 | err = sock_getsockopt(sock, level, optname, optval, optlen); |
| 3021 | else |
| 3022 | err = sock->ops->getsockopt(sock, level, optname, optval, |
| 3023 | optlen); |
| 3024 | set_fs(oldfs); |
| 3025 | return err; |
| 3026 | } |
| 3027 | |
| 3028 | int kernel_setsockopt(struct socket *sock, int level, int optname, |
David S. Miller | b705884 | 2009-09-30 16:12:20 -0700 | [diff] [blame] | 3029 | char *optval, unsigned int optlen) |
Sridhar Samudrala | ac5a488 | 2006-08-07 20:57:31 -0700 | [diff] [blame] | 3030 | { |
| 3031 | mm_segment_t oldfs = get_fs(); |
| 3032 | int err; |
| 3033 | |
| 3034 | set_fs(KERNEL_DS); |
| 3035 | if (level == SOL_SOCKET) |
| 3036 | err = sock_setsockopt(sock, level, optname, optval, optlen); |
| 3037 | else |
| 3038 | err = sock->ops->setsockopt(sock, level, optname, optval, |
| 3039 | optlen); |
| 3040 | set_fs(oldfs); |
| 3041 | return err; |
| 3042 | } |
| 3043 | |
| 3044 | int kernel_sendpage(struct socket *sock, struct page *page, int offset, |
| 3045 | size_t size, int flags) |
| 3046 | { |
| 3047 | if (sock->ops->sendpage) |
| 3048 | return sock->ops->sendpage(sock, page, offset, size, flags); |
| 3049 | |
| 3050 | return sock_no_sendpage(sock, page, offset, size, flags); |
| 3051 | } |
| 3052 | |
| 3053 | int kernel_sock_ioctl(struct socket *sock, int cmd, unsigned long arg) |
| 3054 | { |
| 3055 | mm_segment_t oldfs = get_fs(); |
| 3056 | int err; |
| 3057 | |
| 3058 | set_fs(KERNEL_DS); |
| 3059 | err = sock->ops->ioctl(sock, cmd, arg); |
| 3060 | set_fs(oldfs); |
| 3061 | |
| 3062 | return err; |
| 3063 | } |
| 3064 | |
Trond Myklebust | 91cf45f | 2007-11-12 18:10:39 -0800 | [diff] [blame] | 3065 | int kernel_sock_shutdown(struct socket *sock, enum sock_shutdown_cmd how) |
| 3066 | { |
| 3067 | return sock->ops->shutdown(sock, how); |
| 3068 | } |
| 3069 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3070 | EXPORT_SYMBOL(sock_create); |
| 3071 | EXPORT_SYMBOL(sock_create_kern); |
| 3072 | EXPORT_SYMBOL(sock_create_lite); |
| 3073 | EXPORT_SYMBOL(sock_map_fd); |
| 3074 | EXPORT_SYMBOL(sock_recvmsg); |
| 3075 | EXPORT_SYMBOL(sock_register); |
| 3076 | EXPORT_SYMBOL(sock_release); |
| 3077 | EXPORT_SYMBOL(sock_sendmsg); |
| 3078 | EXPORT_SYMBOL(sock_unregister); |
| 3079 | EXPORT_SYMBOL(sock_wake_async); |
| 3080 | EXPORT_SYMBOL(sockfd_lookup); |
| 3081 | EXPORT_SYMBOL(kernel_sendmsg); |
| 3082 | EXPORT_SYMBOL(kernel_recvmsg); |
Sridhar Samudrala | ac5a488 | 2006-08-07 20:57:31 -0700 | [diff] [blame] | 3083 | EXPORT_SYMBOL(kernel_bind); |
| 3084 | EXPORT_SYMBOL(kernel_listen); |
| 3085 | EXPORT_SYMBOL(kernel_accept); |
| 3086 | EXPORT_SYMBOL(kernel_connect); |
| 3087 | EXPORT_SYMBOL(kernel_getsockname); |
| 3088 | EXPORT_SYMBOL(kernel_getpeername); |
| 3089 | EXPORT_SYMBOL(kernel_getsockopt); |
| 3090 | EXPORT_SYMBOL(kernel_setsockopt); |
| 3091 | EXPORT_SYMBOL(kernel_sendpage); |
| 3092 | EXPORT_SYMBOL(kernel_sock_ioctl); |
Trond Myklebust | 91cf45f | 2007-11-12 18:10:39 -0800 | [diff] [blame] | 3093 | EXPORT_SYMBOL(kernel_sock_shutdown); |