This commit was manufactured by cvs2svn to create branch
[linux-2.6.git] / net / socket.c
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>
7  *              Ross Biro, <bir7@leland.Stanford.Edu>
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)
45  *              Tigran Aivazian :       Made listen(2) backlog sanity checks 
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
56  *      paradigm. 
57  *
58  *      Based upon Swansea University Computer Society NET3.039
59  */
60
61 #include <linux/config.h>
62 #include <linux/mm.h>
63 #include <linux/smp_lock.h>
64 #include <linux/socket.h>
65 #include <linux/file.h>
66 #include <linux/net.h>
67 #include <linux/interrupt.h>
68 #include <linux/netdevice.h>
69 #include <linux/proc_fs.h>
70 #include <linux/seq_file.h>
71 #include <net/tux.h>
72 #include <linux/wanrouter.h>
73 #include <linux/if_bridge.h>
74 #include <linux/init.h>
75 #include <linux/poll.h>
76 #include <linux/cache.h>
77 #include <linux/module.h>
78 #include <linux/highmem.h>
79 #include <linux/divert.h>
80 #include <linux/mount.h>
81 #include <linux/security.h>
82 #include <linux/syscalls.h>
83 #include <linux/compat.h>
84 #include <linux/kmod.h>
85
86 #ifdef CONFIG_NET_RADIO
87 #include <linux/wireless.h>             /* Note : will define WIRELESS_EXT */
88 #endif  /* CONFIG_NET_RADIO */
89
90 #include <asm/uaccess.h>
91 #include <asm/unistd.h>
92
93 #include <net/compat.h>
94
95 #include <net/sock.h>
96 #include <linux/netfilter.h>
97 #include <linux/vs_base.h>
98 #include <linux/vs_socket.h>
99
100 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
101 static ssize_t sock_aio_read(struct kiocb *iocb, char __user *buf,
102                          size_t size, loff_t pos);
103 static ssize_t sock_aio_write(struct kiocb *iocb, const char __user *buf,
104                           size_t size, loff_t pos);
105 static int sock_mmap(struct file *file, struct vm_area_struct * vma);
106
107 static int sock_close(struct inode *inode, struct file *file);
108 static unsigned int sock_poll(struct file *file,
109                               struct poll_table_struct *wait);
110 static int sock_ioctl(struct inode *inode, struct file *file,
111                       unsigned int cmd, unsigned long arg);
112 static int sock_fasync(int fd, struct file *filp, int on);
113 static ssize_t sock_readv(struct file *file, const struct iovec *vector,
114                           unsigned long count, loff_t *ppos);
115 static ssize_t sock_writev(struct file *file, const struct iovec *vector,
116                           unsigned long count, loff_t *ppos);
117 static ssize_t sock_sendpage(struct file *file, struct page *page,
118                              int offset, size_t size, loff_t *ppos, int more);
119
120
121 /*
122  *      Socket files have a set of 'special' operations as well as the generic file ones. These don't appear
123  *      in the operation structures but are done directly via the socketcall() multiplexor.
124  */
125
126 struct file_operations socket_file_ops = {
127         .owner =        THIS_MODULE,
128         .llseek =       no_llseek,
129         .aio_read =     sock_aio_read,
130         .aio_write =    sock_aio_write,
131         .poll =         sock_poll,
132         .ioctl =        sock_ioctl,
133         .mmap =         sock_mmap,
134         .open =         sock_no_open,   /* special open code to disallow open via /proc */
135         .release =      sock_close,
136         .fasync =       sock_fasync,
137         .readv =        sock_readv,
138         .writev =       sock_writev,
139         .sendpage =     sock_sendpage
140 };
141
142 /*
143  *      The protocol list. Each protocol is registered in here.
144  */
145
146 static struct net_proto_family *net_families[NPROTO];
147
148 #if defined(CONFIG_SMP) || defined(CONFIG_PREEMPT)
149 static atomic_t net_family_lockct = ATOMIC_INIT(0);
150 static spinlock_t net_family_lock = SPIN_LOCK_UNLOCKED;
151
152 /* The strategy is: modifications net_family vector are short, do not
153    sleep and veeery rare, but read access should be free of any exclusive
154    locks.
155  */
156
157 static void net_family_write_lock(void)
158 {
159         spin_lock(&net_family_lock);
160         while (atomic_read(&net_family_lockct) != 0) {
161                 spin_unlock(&net_family_lock);
162
163                 yield();
164
165                 spin_lock(&net_family_lock);
166         }
167 }
168
169 static __inline__ void net_family_write_unlock(void)
170 {
171         spin_unlock(&net_family_lock);
172 }
173
174 static __inline__ void net_family_read_lock(void)
175 {
176         atomic_inc(&net_family_lockct);
177         spin_unlock_wait(&net_family_lock);
178 }
179
180 static __inline__ void net_family_read_unlock(void)
181 {
182         atomic_dec(&net_family_lockct);
183 }
184
185 #else
186 #define net_family_write_lock() do { } while(0)
187 #define net_family_write_unlock() do { } while(0)
188 #define net_family_read_lock() do { } while(0)
189 #define net_family_read_unlock() do { } while(0)
190 #endif
191
192
193 /*
194  *      Statistics counters of the socket lists
195  */
196
197 static DEFINE_PER_CPU(int, sockets_in_use) = 0;
198
199 /*
200  *      Support routines. Move socket addresses back and forth across the kernel/user
201  *      divide and look after the messy bits.
202  */
203
204 #define MAX_SOCK_ADDR   128             /* 108 for Unix domain - 
205                                            16 for IP, 16 for IPX,
206                                            24 for IPv6,
207                                            about 80 for AX.25 
208                                            must be at least one bigger than
209                                            the AF_UNIX size (see net/unix/af_unix.c
210                                            :unix_mkname()).  
211                                          */
212                                          
213 /**
214  *      move_addr_to_kernel     -       copy a socket address into kernel space
215  *      @uaddr: Address in user space
216  *      @kaddr: Address in kernel space
217  *      @ulen: Length in user space
218  *
219  *      The address is copied into kernel space. If the provided address is
220  *      too long an error code of -EINVAL is returned. If the copy gives
221  *      invalid addresses -EFAULT is returned. On a success 0 is returned.
222  */
223
224 int move_addr_to_kernel(void __user *uaddr, int ulen, void *kaddr)
225 {
226         if(ulen<0||ulen>MAX_SOCK_ADDR)
227                 return -EINVAL;
228         if(ulen==0)
229                 return 0;
230         if(copy_from_user(kaddr,uaddr,ulen))
231                 return -EFAULT;
232         return 0;
233 }
234
235 /**
236  *      move_addr_to_user       -       copy an address to user space
237  *      @kaddr: kernel space address
238  *      @klen: length of address in kernel
239  *      @uaddr: user space address
240  *      @ulen: pointer to user length field
241  *
242  *      The value pointed to by ulen on entry is the buffer length available.
243  *      This is overwritten with the buffer space used. -EINVAL is returned
244  *      if an overlong buffer is specified or a negative buffer size. -EFAULT
245  *      is returned if either the buffer or the length field are not
246  *      accessible.
247  *      After copying the data up to the limit the user specifies, the true
248  *      length of the data is written over the length limit the user
249  *      specified. Zero is returned for a success.
250  */
251  
252 int move_addr_to_user(void *kaddr, int klen, void __user *uaddr, int __user *ulen)
253 {
254         int err;
255         int len;
256
257         if((err=get_user(len, ulen)))
258                 return err;
259         if(len>klen)
260                 len=klen;
261         if(len<0 || len> MAX_SOCK_ADDR)
262                 return -EINVAL;
263         if(len)
264         {
265                 if(copy_to_user(uaddr,kaddr,len))
266                         return -EFAULT;
267         }
268         /*
269          *      "fromlen shall refer to the value before truncation.."
270          *                      1003.1g
271          */
272         return __put_user(klen, ulen);
273 }
274
275 #define SOCKFS_MAGIC 0x534F434B
276
277 static kmem_cache_t * sock_inode_cachep;
278
279 static struct inode *sock_alloc_inode(struct super_block *sb)
280 {
281         struct socket_alloc *ei;
282         ei = (struct socket_alloc *)kmem_cache_alloc(sock_inode_cachep, SLAB_KERNEL);
283         if (!ei)
284                 return NULL;
285         init_waitqueue_head(&ei->socket.wait);
286         
287         ei->socket.fasync_list = NULL;
288         ei->socket.state = SS_UNCONNECTED;
289         ei->socket.flags = 0;
290         ei->socket.ops = NULL;
291         ei->socket.sk = NULL;
292         ei->socket.file = NULL;
293         ei->socket.flags = 0;
294
295         return &ei->vfs_inode;
296 }
297
298 static void sock_destroy_inode(struct inode *inode)
299 {
300         kmem_cache_free(sock_inode_cachep,
301                         container_of(inode, struct socket_alloc, vfs_inode));
302 }
303
304 static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)
305 {
306         struct socket_alloc *ei = (struct socket_alloc *) foo;
307
308         if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
309             SLAB_CTOR_CONSTRUCTOR)
310                 inode_init_once(&ei->vfs_inode);
311 }
312  
313 static int init_inodecache(void)
314 {
315         sock_inode_cachep = kmem_cache_create("sock_inode_cache",
316                                 sizeof(struct socket_alloc),
317                                 0, SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT,
318                                 init_once, NULL);
319         if (sock_inode_cachep == NULL)
320                 return -ENOMEM;
321         return 0;
322 }
323
324 static struct super_operations sockfs_ops = {
325         .alloc_inode =  sock_alloc_inode,
326         .destroy_inode =sock_destroy_inode,
327         .statfs =       simple_statfs,
328 };
329
330 static struct super_block *sockfs_get_sb(struct file_system_type *fs_type,
331         int flags, const char *dev_name, void *data)
332 {
333         return get_sb_pseudo(fs_type, "socket:", &sockfs_ops, SOCKFS_MAGIC);
334 }
335
336 static struct vfsmount *sock_mnt;
337
338 static struct file_system_type sock_fs_type = {
339         .name =         "sockfs",
340         .get_sb =       sockfs_get_sb,
341         .kill_sb =      kill_anon_super,
342 };
343 static int sockfs_delete_dentry(struct dentry *dentry)
344 {
345         return 1;
346 }
347 static struct dentry_operations sockfs_dentry_operations = {
348         .d_delete =     sockfs_delete_dentry,
349 };
350
351 /*
352  *      Obtains the first available file descriptor and sets it up for use.
353  *
354  *      This function creates file structure and maps it to fd space
355  *      of current process. On success it returns file descriptor
356  *      and file struct implicitly stored in sock->file.
357  *      Note that another thread may close file descriptor before we return
358  *      from this function. We use the fact that now we do not refer
359  *      to socket after mapping. If one day we will need it, this
360  *      function will increment ref. count on file by 1.
361  *
362  *      In any case returned fd MAY BE not valid!
363  *      This race condition is unavoidable
364  *      with shared fd spaces, we cannot solve it inside kernel,
365  *      but we take care of internal coherence yet.
366  */
367
368 struct file * sock_map_file(struct socket *sock)
369 {
370         struct file *file;
371         struct qstr this;
372         char name[32];
373
374         file = get_empty_filp();
375
376         if (!file)
377                 return ERR_PTR(-ENFILE);
378
379         sprintf(name, "[%lu]", SOCK_INODE(sock)->i_ino);
380         this.name = name;
381         this.len = strlen(name);
382         this.hash = SOCK_INODE(sock)->i_ino;
383
384         file->f_dentry = d_alloc(sock_mnt->mnt_sb->s_root, &this);
385         if (!file->f_dentry) {
386                 put_filp(file);
387                 return ERR_PTR(-ENOMEM);
388         }
389         file->f_dentry->d_op = &sockfs_dentry_operations;
390         d_add(file->f_dentry, SOCK_INODE(sock));
391         file->f_vfsmnt = mntget(sock_mnt);
392 file->f_mapping = file->f_dentry->d_inode->i_mapping;
393
394         if (sock->file)
395                 BUG();
396         sock->file = file;
397         file->f_op = SOCK_INODE(sock)->i_fop = &socket_file_ops;
398         file->f_mode = FMODE_READ | FMODE_WRITE;
399         file->f_flags = O_RDWR;
400         file->f_pos = 0;
401
402         return file;
403 }
404
405 int sock_map_fd(struct socket *sock)
406 {
407         int fd;
408         struct file *file;
409  
410         /*
411          *      Find a file descriptor suitable for return to the user. 
412          */
413   
414         fd = get_unused_fd();
415         if (fd < 0)
416                 return fd;
417   
418         file = sock_map_file(sock);
419         if (IS_ERR(file)) {
420                 put_unused_fd(fd);
421                 return PTR_ERR(file);
422         }
423         fd_install(fd, file);
424   
425         return fd;
426 }
427
428 /**
429  *      sockfd_lookup   -       Go from a file number to its socket slot
430  *      @fd: file handle
431  *      @err: pointer to an error code return
432  *
433  *      The file handle passed in is locked and the socket it is bound
434  *      too is returned. If an error occurs the err pointer is overwritten
435  *      with a negative errno code and NULL is returned. The function checks
436  *      for both invalid handles and passing a handle which is not a socket.
437  *
438  *      On a success the socket object pointer is returned.
439  */
440
441 struct socket *sockfd_lookup(int fd, int *err)
442 {
443         struct file *file;
444         struct inode *inode;
445         struct socket *sock;
446
447         if (!(file = fget(fd)))
448         {
449                 *err = -EBADF;
450                 return NULL;
451         }
452
453         inode = file->f_dentry->d_inode;
454         if (!inode->i_sock || !(sock = SOCKET_I(inode)))
455         {
456                 *err = -ENOTSOCK;
457                 fput(file);
458                 return NULL;
459         }
460
461         if (sock->file != file) {
462                 printk(KERN_ERR "socki_lookup: socket file changed!\n");
463                 sock->file = file;
464         }
465         return sock;
466 }
467
468 /**
469  *      sock_alloc      -       allocate a socket
470  *      
471  *      Allocate a new inode and socket object. The two are bound together
472  *      and initialised. The socket is then returned. If we are out of inodes
473  *      NULL is returned.
474  */
475
476 struct socket *sock_alloc(void)
477 {
478         struct inode * inode;
479         struct socket * sock;
480
481         inode = new_inode(sock_mnt->mnt_sb);
482         if (!inode)
483                 return NULL;
484
485         sock = SOCKET_I(inode);
486
487         inode->i_mode = S_IFSOCK|S_IRWXUGO;
488         inode->i_sock = 1;
489         inode->i_uid = current->fsuid;
490         inode->i_gid = current->fsgid;
491
492         get_cpu_var(sockets_in_use)++;
493         put_cpu_var(sockets_in_use);
494         return sock;
495 }
496
497 /*
498  *      In theory you can't get an open on this inode, but /proc provides
499  *      a back door. Remember to keep it shut otherwise you'll let the
500  *      creepy crawlies in.
501  */
502   
503 static int sock_no_open(struct inode *irrelevant, struct file *dontcare)
504 {
505         return -ENXIO;
506 }
507
508 struct file_operations bad_sock_fops = {
509         .owner = THIS_MODULE,
510         .open = sock_no_open,
511 };
512
513 /**
514  *      sock_release    -       close a socket
515  *      @sock: socket to close
516  *
517  *      The socket is released from the protocol stack if it has a release
518  *      callback, and the inode is then released if the socket is bound to
519  *      an inode not a file. 
520  */
521  
522 void sock_release(struct socket *sock)
523 {
524         if (sock->ops) {
525                 struct module *owner = sock->ops->owner;
526
527                 sock->ops->release(sock);
528                 sock->ops = NULL;
529                 module_put(owner);
530         }
531
532         if (sock->fasync_list)
533                 printk(KERN_ERR "sock_release: fasync list not empty!\n");
534
535         get_cpu_var(sockets_in_use)--;
536         put_cpu_var(sockets_in_use);
537         if (!sock->file) {
538                 iput(SOCK_INODE(sock));
539                 return;
540         }
541         sock->file=NULL;
542 }
543
544 static inline int __sock_sendmsg(struct kiocb *iocb, struct socket *sock, 
545                                  struct msghdr *msg, size_t size)
546 {
547         struct sock_iocb *si = kiocb_to_siocb(iocb);
548         int err, len;
549
550         si->sock = sock;
551         si->scm = NULL;
552         si->msg = msg;
553         si->size = size;
554
555         err = security_socket_sendmsg(sock, msg, size);
556         if (err)
557                 return err;
558
559         len = sock->ops->sendmsg(iocb, sock, msg, size);
560         if (sock->sk) {
561                 if (len == size)
562                         vx_sock_send(sock->sk, size);
563                 else
564                         vx_sock_fail(sock->sk, size);
565         }
566         vxdprintk(VXD_CBIT(net, 7),
567                 "__sock_sendmsg: %p[%p,%p,%p;%d]:%d/%d",
568                 sock, sock->sk,
569                 (sock->sk)?sock->sk->sk_nx_info:0,
570                 (sock->sk)?sock->sk->sk_vx_info:0,
571                 (sock->sk)?sock->sk->sk_xid:0,
572                 (unsigned int)size, len);
573         return len;
574 }
575
576 int sock_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
577 {
578         struct kiocb iocb;
579         struct sock_iocb siocb;
580         int ret;
581
582         init_sync_kiocb(&iocb, NULL);
583         iocb.private = &siocb;
584         ret = __sock_sendmsg(&iocb, sock, msg, size);
585         if (-EIOCBQUEUED == ret)
586                 ret = wait_on_sync_kiocb(&iocb);
587         return ret;
588 }
589
590 int kernel_sendmsg(struct socket *sock, struct msghdr *msg,
591                    struct kvec *vec, size_t num, size_t size)
592 {
593         mm_segment_t oldfs = get_fs();
594         int result;
595
596         set_fs(KERNEL_DS);
597         /*
598          * the following is safe, since for compiler definitions of kvec and
599          * iovec are identical, yielding the same in-core layout and alignment
600          */
601         msg->msg_iov = (struct iovec *)vec,
602         msg->msg_iovlen = num;
603         result = sock_sendmsg(sock, msg, size);
604         set_fs(oldfs);
605         return result;
606 }
607
608 static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock, 
609                                  struct msghdr *msg, size_t size, int flags)
610 {
611         int err, len;
612         struct sock_iocb *si = kiocb_to_siocb(iocb);
613
614         si->sock = sock;
615         si->scm = NULL;
616         si->msg = msg;
617         si->size = size;
618         si->flags = flags;
619
620         err = security_socket_recvmsg(sock, msg, size, flags);
621         if (err)
622                 return err;
623
624         len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
625         if ((len >= 0) && sock->sk)
626                 vx_sock_recv(sock->sk, len);
627         vxdprintk(VXD_CBIT(net, 7),
628                 "__sock_recvmsg: %p[%p,%p,%p;%d]:%d/%d",
629                 sock, sock->sk,
630                 (sock->sk)?sock->sk->sk_nx_info:0,
631                 (sock->sk)?sock->sk->sk_vx_info:0,
632                 (sock->sk)?sock->sk->sk_xid:0,
633                 (unsigned int)size, len);
634         return len;
635 }
636
637 int sock_recvmsg(struct socket *sock, struct msghdr *msg, 
638                  size_t size, int flags)
639 {
640         struct kiocb iocb;
641         struct sock_iocb siocb;
642         int ret;
643
644         init_sync_kiocb(&iocb, NULL);
645         iocb.private = &siocb;
646         ret = __sock_recvmsg(&iocb, sock, msg, size, flags);
647         if (-EIOCBQUEUED == ret)
648                 ret = wait_on_sync_kiocb(&iocb);
649         return ret;
650 }
651
652 int kernel_recvmsg(struct socket *sock, struct msghdr *msg, 
653                    struct kvec *vec, size_t num,
654                    size_t size, int flags)
655 {
656         mm_segment_t oldfs = get_fs();
657         int result;
658
659         set_fs(KERNEL_DS);
660         /*
661          * the following is safe, since for compiler definitions of kvec and
662          * iovec are identical, yielding the same in-core layout and alignment
663          */
664         msg->msg_iov = (struct iovec *)vec,
665         msg->msg_iovlen = num;
666         result = sock_recvmsg(sock, msg, size, flags);
667         set_fs(oldfs);
668         return result;
669 }
670
671 static void sock_aio_dtor(struct kiocb *iocb)
672 {
673         kfree(iocb->private);
674 }
675
676 /*
677  *      Read data from a socket. ubuf is a user mode pointer. We make sure the user
678  *      area ubuf...ubuf+size-1 is writable before asking the protocol.
679  */
680
681 static ssize_t sock_aio_read(struct kiocb *iocb, char __user *ubuf,
682                          size_t size, loff_t pos)
683 {
684         struct sock_iocb *x, siocb;
685         struct socket *sock;
686         int flags;
687
688         if (pos != 0)
689                 return -ESPIPE;
690         if (size==0)            /* Match SYS5 behaviour */
691                 return 0;
692
693         if (is_sync_kiocb(iocb))
694                 x = &siocb;
695         else {
696                 x = kmalloc(sizeof(struct sock_iocb), GFP_KERNEL);
697                 if (!x)
698                         return -ENOMEM;
699                 iocb->ki_dtor = sock_aio_dtor;
700         }
701         iocb->private = x;
702         x->kiocb = iocb;
703         sock = SOCKET_I(iocb->ki_filp->f_dentry->d_inode); 
704
705         x->async_msg.msg_name = NULL;
706         x->async_msg.msg_namelen = 0;
707         x->async_msg.msg_iov = &x->async_iov;
708         x->async_msg.msg_iovlen = 1;
709         x->async_msg.msg_control = NULL;
710         x->async_msg.msg_controllen = 0;
711         x->async_iov.iov_base = ubuf;
712         x->async_iov.iov_len = size;
713         flags = !(iocb->ki_filp->f_flags & O_NONBLOCK) ? 0 : MSG_DONTWAIT;
714
715         return __sock_recvmsg(iocb, sock, &x->async_msg, size, flags);
716 }
717
718
719 /*
720  *      Write data to a socket. We verify that the user area ubuf..ubuf+size-1
721  *      is readable by the user process.
722  */
723
724 static ssize_t sock_aio_write(struct kiocb *iocb, const char __user *ubuf,
725                           size_t size, loff_t pos)
726 {
727         struct sock_iocb *x, siocb;
728         struct socket *sock;
729         
730         if (pos != 0)
731                 return -ESPIPE;
732         if(size==0)             /* Match SYS5 behaviour */
733                 return 0;
734
735         if (is_sync_kiocb(iocb))
736                 x = &siocb;
737         else {
738                 x = kmalloc(sizeof(struct sock_iocb), GFP_KERNEL);
739                 if (!x)
740                         return -ENOMEM;
741                 iocb->ki_dtor = sock_aio_dtor;
742         }
743         iocb->private = x;
744         x->kiocb = iocb;
745         sock = SOCKET_I(iocb->ki_filp->f_dentry->d_inode); 
746
747         x->async_msg.msg_name = NULL;
748         x->async_msg.msg_namelen = 0;
749         x->async_msg.msg_iov = &x->async_iov;
750         x->async_msg.msg_iovlen = 1;
751         x->async_msg.msg_control = NULL;
752         x->async_msg.msg_controllen = 0;
753         x->async_msg.msg_flags = !(iocb->ki_filp->f_flags & O_NONBLOCK) ? 0 : MSG_DONTWAIT;
754         if (sock->type == SOCK_SEQPACKET)
755                 x->async_msg.msg_flags |= MSG_EOR;
756         x->async_iov.iov_base = (void __user *)ubuf;
757         x->async_iov.iov_len = size;
758         
759         return __sock_sendmsg(iocb, sock, &x->async_msg, size);
760 }
761
762 ssize_t sock_sendpage(struct file *file, struct page *page,
763                       int offset, size_t size, loff_t *ppos, int more)
764 {
765         struct socket *sock;
766         int flags;
767
768         sock = SOCKET_I(file->f_dentry->d_inode);
769
770         flags = !(file->f_flags & O_NONBLOCK) ? 0 : MSG_DONTWAIT;
771         if (more)
772                 flags |= MSG_MORE;
773
774         return sock->ops->sendpage(sock, page, offset, size, flags);
775 }
776
777 int sock_readv_writev(int type, struct inode * inode, struct file * file,
778                       const struct iovec * iov, long count, size_t size)
779 {
780         struct msghdr msg;
781         struct socket *sock;
782
783         sock = SOCKET_I(inode);
784
785         msg.msg_name = NULL;
786         msg.msg_namelen = 0;
787         msg.msg_control = NULL;
788         msg.msg_controllen = 0;
789         msg.msg_iov = (struct iovec *) iov;
790         msg.msg_iovlen = count;
791         msg.msg_flags = (file->f_flags & O_NONBLOCK) ? MSG_DONTWAIT : 0;
792
793         /* read() does a VERIFY_WRITE */
794         if (type == VERIFY_WRITE)
795                 return sock_recvmsg(sock, &msg, size, msg.msg_flags);
796
797         if (sock->type == SOCK_SEQPACKET)
798                 msg.msg_flags |= MSG_EOR;
799
800         return sock_sendmsg(sock, &msg, size);
801 }
802
803 static ssize_t sock_readv(struct file *file, const struct iovec *vector,
804                           unsigned long count, loff_t *ppos)
805 {
806         size_t tot_len = 0;
807         int i;
808         for (i = 0 ; i < count ; i++)
809                 tot_len += vector[i].iov_len;
810         return sock_readv_writev(VERIFY_WRITE, file->f_dentry->d_inode,
811                                  file, vector, count, tot_len);
812 }
813         
814 static ssize_t sock_writev(struct file *file, const struct iovec *vector,
815                            unsigned long count, loff_t *ppos)
816 {
817         size_t tot_len = 0;
818         int i;
819         for (i = 0 ; i < count ; i++)
820                 tot_len += vector[i].iov_len;
821         return sock_readv_writev(VERIFY_READ, file->f_dentry->d_inode,
822                                  file, vector, count, tot_len);
823 }
824
825
826 /*
827  * Atomic setting of ioctl hooks to avoid race
828  * with module unload.
829  */
830
831 static DECLARE_MUTEX(br_ioctl_mutex);
832 static int (*br_ioctl_hook)(unsigned int cmd, void __user *arg) = NULL;
833
834 void brioctl_set(int (*hook)(unsigned int, void __user *))
835 {
836         down(&br_ioctl_mutex);
837         br_ioctl_hook = hook;
838         up(&br_ioctl_mutex);
839 }
840 EXPORT_SYMBOL(brioctl_set);
841
842 static DECLARE_MUTEX(vlan_ioctl_mutex);
843 static int (*vlan_ioctl_hook)(void __user *arg);
844
845 void vlan_ioctl_set(int (*hook)(void __user *))
846 {
847         down(&vlan_ioctl_mutex);
848         vlan_ioctl_hook = hook;
849         up(&vlan_ioctl_mutex);
850 }
851 EXPORT_SYMBOL(vlan_ioctl_set);
852
853 static DECLARE_MUTEX(dlci_ioctl_mutex);
854 static int (*dlci_ioctl_hook)(unsigned int, void __user *);
855
856 void dlci_ioctl_set(int (*hook)(unsigned int, void __user *))
857 {
858         down(&dlci_ioctl_mutex);
859         dlci_ioctl_hook = hook;
860         up(&dlci_ioctl_mutex);
861 }
862 EXPORT_SYMBOL(dlci_ioctl_set);
863
864 /*
865  *      With an ioctl, arg may well be a user mode pointer, but we don't know
866  *      what to do with it - that's up to the protocol still.
867  */
868
869 static int sock_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
870                       unsigned long arg)
871 {
872         struct socket *sock;
873         void __user *argp = (void __user *)arg;
874         int pid, err;
875
876         unlock_kernel();
877         sock = SOCKET_I(inode);
878         if (cmd >= SIOCDEVPRIVATE && cmd <= (SIOCDEVPRIVATE + 15)) {
879                 err = dev_ioctl(cmd, argp);
880         } else
881 #ifdef WIRELESS_EXT
882         if (cmd >= SIOCIWFIRST && cmd <= SIOCIWLAST) {
883                 err = dev_ioctl(cmd, argp);
884         } else
885 #endif  /* WIRELESS_EXT */
886         switch (cmd) {
887                 case FIOSETOWN:
888                 case SIOCSPGRP:
889                         err = -EFAULT;
890                         if (get_user(pid, (int __user *)argp))
891                                 break;
892                         err = f_setown(sock->file, pid, 1);
893                         break;
894                 case FIOGETOWN:
895                 case SIOCGPGRP:
896                         err = put_user(sock->file->f_owner.pid, (int __user *)argp);
897                         break;
898                 case SIOCGIFBR:
899                 case SIOCSIFBR:
900                 case SIOCBRADDBR:
901                 case SIOCBRDELBR:
902                         err = -ENOPKG;
903                         if (!br_ioctl_hook)
904                                 request_module("bridge");
905
906                         down(&br_ioctl_mutex);
907                         if (br_ioctl_hook) 
908                                 err = br_ioctl_hook(cmd, argp);
909                         up(&br_ioctl_mutex);
910                         break;
911                 case SIOCGIFVLAN:
912                 case SIOCSIFVLAN:
913                         err = -ENOPKG;
914                         if (!vlan_ioctl_hook)
915                                 request_module("8021q");
916
917                         down(&vlan_ioctl_mutex);
918                         if (vlan_ioctl_hook)
919                                 err = vlan_ioctl_hook(argp);
920                         up(&vlan_ioctl_mutex);
921                         break;
922                 case SIOCGIFDIVERT:
923                 case SIOCSIFDIVERT:
924                 /* Convert this to call through a hook */
925                         err = divert_ioctl(cmd, argp);
926                         break;
927                 case SIOCADDDLCI:
928                 case SIOCDELDLCI:
929                         err = -ENOPKG;
930                         if (!dlci_ioctl_hook)
931                                 request_module("dlci");
932
933                         if (dlci_ioctl_hook) {
934                                 down(&dlci_ioctl_mutex);
935                                 err = dlci_ioctl_hook(cmd, argp);
936                                 up(&dlci_ioctl_mutex);
937                         }
938                         break;
939                 default:
940                         err = sock->ops->ioctl(sock, cmd, arg);
941                         break;
942         }
943         lock_kernel();
944
945         return err;
946 }
947
948 int sock_create_lite(int family, int type, int protocol, struct socket **res)
949 {
950         int err;
951         struct socket *sock = NULL;
952         
953         err = security_socket_create(family, type, protocol, 1);
954         if (err)
955                 goto out;
956
957         sock = sock_alloc();
958         if (!sock) {
959                 err = -ENOMEM;
960                 goto out;
961         }
962
963         security_socket_post_create(sock, family, type, protocol, 1);
964         sock->type = type;
965 out:
966         *res = sock;
967         return err;
968 }
969
970 /* No kernel lock held - perfect */
971 static unsigned int sock_poll(struct file *file, poll_table * wait)
972 {
973         struct socket *sock;
974
975         /*
976          *      We can't return errors to poll, so it's either yes or no. 
977          */
978         sock = SOCKET_I(file->f_dentry->d_inode);
979         return sock->ops->poll(file, sock, wait);
980 }
981
982 static int sock_mmap(struct file * file, struct vm_area_struct * vma)
983 {
984         struct socket *sock = SOCKET_I(file->f_dentry->d_inode);
985
986         return sock->ops->mmap(file, sock, vma);
987 }
988
989 int sock_close(struct inode *inode, struct file *filp)
990 {
991         /*
992          *      It was possible the inode is NULL we were 
993          *      closing an unfinished socket. 
994          */
995
996         if (!inode)
997         {
998                 printk(KERN_DEBUG "sock_close: NULL inode\n");
999                 return 0;
1000         }
1001         sock_fasync(-1, filp, 0);
1002         sock_release(SOCKET_I(inode));
1003         return 0;
1004 }
1005
1006 /*
1007  *      Update the socket async list
1008  *
1009  *      Fasync_list locking strategy.
1010  *
1011  *      1. fasync_list is modified only under process context socket lock
1012  *         i.e. under semaphore.
1013  *      2. fasync_list is used under read_lock(&sk->sk_callback_lock)
1014  *         or under socket lock.
1015  *      3. fasync_list can be used from softirq context, so that
1016  *         modification under socket lock have to be enhanced with
1017  *         write_lock_bh(&sk->sk_callback_lock).
1018  *                                                      --ANK (990710)
1019  */
1020
1021 static int sock_fasync(int fd, struct file *filp, int on)
1022 {
1023         struct fasync_struct *fa, *fna=NULL, **prev;
1024         struct socket *sock;
1025         struct sock *sk;
1026
1027         if (on)
1028         {
1029                 fna=(struct fasync_struct *)kmalloc(sizeof(struct fasync_struct), GFP_KERNEL);
1030                 if(fna==NULL)
1031                         return -ENOMEM;
1032         }
1033
1034         sock = SOCKET_I(filp->f_dentry->d_inode);
1035
1036         if ((sk=sock->sk) == NULL) {
1037                 if (fna)
1038                         kfree(fna);
1039                 return -EINVAL;
1040         }
1041
1042         lock_sock(sk);
1043
1044         prev=&(sock->fasync_list);
1045
1046         for (fa=*prev; fa!=NULL; prev=&fa->fa_next,fa=*prev)
1047                 if (fa->fa_file==filp)
1048                         break;
1049
1050         if(on)
1051         {
1052                 if(fa!=NULL)
1053                 {
1054                         write_lock_bh(&sk->sk_callback_lock);
1055                         fa->fa_fd=fd;
1056                         write_unlock_bh(&sk->sk_callback_lock);
1057
1058                         kfree(fna);
1059                         goto out;
1060                 }
1061                 fna->fa_file=filp;
1062                 fna->fa_fd=fd;
1063                 fna->magic=FASYNC_MAGIC;
1064                 fna->fa_next=sock->fasync_list;
1065                 write_lock_bh(&sk->sk_callback_lock);
1066                 sock->fasync_list=fna;
1067                 write_unlock_bh(&sk->sk_callback_lock);
1068         }
1069         else
1070         {
1071                 if (fa!=NULL)
1072                 {
1073                         write_lock_bh(&sk->sk_callback_lock);
1074                         *prev=fa->fa_next;
1075                         write_unlock_bh(&sk->sk_callback_lock);
1076                         kfree(fa);
1077                 }
1078         }
1079
1080 out:
1081         if (sock->sk != sk)
1082                 BUG();
1083         release_sock(sock->sk);
1084         return 0;
1085 }
1086
1087 /* This function may be called only under socket lock or callback_lock */
1088
1089 int sock_wake_async(struct socket *sock, int how, int band)
1090 {
1091         if (!sock || !sock->fasync_list)
1092                 return -1;
1093         switch (how)
1094         {
1095         case 1:
1096                 
1097                 if (test_bit(SOCK_ASYNC_WAITDATA, &sock->flags))
1098                         break;
1099                 goto call_kill;
1100         case 2:
1101                 if (!test_and_clear_bit(SOCK_ASYNC_NOSPACE, &sock->flags))
1102                         break;
1103                 /* fall through */
1104         case 0:
1105         call_kill:
1106                 __kill_fasync(sock->fasync_list, SIGIO, band);
1107                 break;
1108         case 3:
1109                 __kill_fasync(sock->fasync_list, SIGURG, band);
1110         }
1111         return 0;
1112 }
1113
1114 static int __sock_create(int family, int type, int protocol, struct socket **res, int kern)
1115 {
1116         int i;
1117         int err;
1118         struct socket *sock;
1119
1120         /*
1121          *      Check protocol is in range
1122          */
1123         if (family < 0 || family >= NPROTO)
1124                 return -EAFNOSUPPORT;
1125         if (type < 0 || type >= SOCK_MAX)
1126                 return -EINVAL;
1127
1128         /* disable IPv6 inside vservers for now */
1129         if (family == PF_INET6 && !vx_check(0, VX_ADMIN))
1130                 return -EAFNOSUPPORT;
1131
1132         /* Compatibility.
1133
1134            This uglymoron is moved from INET layer to here to avoid
1135            deadlock in module load.
1136          */
1137         if (family == PF_INET && type == SOCK_PACKET) {
1138                 static int warned; 
1139                 if (!warned) {
1140                         warned = 1;
1141                         printk(KERN_INFO "%s uses obsolete (PF_INET,SOCK_PACKET)\n", current->comm);
1142                 }
1143                 family = PF_PACKET;
1144         }
1145
1146         err = security_socket_create(family, type, protocol, kern);
1147         if (err)
1148                 return err;
1149                 
1150 #if defined(CONFIG_KMOD)
1151         /* Attempt to load a protocol module if the find failed. 
1152          * 
1153          * 12/09/1996 Marcin: But! this makes REALLY only sense, if the user 
1154          * requested real, full-featured networking support upon configuration.
1155          * Otherwise module support will break!
1156          */
1157         if (net_families[family]==NULL)
1158         {
1159                 request_module("net-pf-%d",family);
1160         }
1161 #endif
1162
1163         net_family_read_lock();
1164         if (net_families[family] == NULL) {
1165                 i = -EAFNOSUPPORT;
1166                 goto out;
1167         }
1168
1169 /*
1170  *      Allocate the socket and allow the family to set things up. if
1171  *      the protocol is 0, the family is instructed to select an appropriate
1172  *      default.
1173  */
1174
1175         if (!(sock = sock_alloc())) 
1176         {
1177                 printk(KERN_WARNING "socket: no more sockets\n");
1178                 i = -ENFILE;            /* Not exactly a match, but its the
1179                                            closest posix thing */
1180                 goto out;
1181         }
1182
1183         sock->type  = type;
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          */
1189         i = -EAFNOSUPPORT;
1190         if (!try_module_get(net_families[family]->owner))
1191                 goto out_release;
1192
1193         if ((i = net_families[family]->create(sock, protocol)) < 0)
1194                 goto out_module_put;
1195         /*
1196          * Now to bump the refcnt of the [loadable] module that owns this
1197          * socket at sock_release time we decrement its refcnt.
1198          */
1199         if (!try_module_get(sock->ops->owner)) {
1200                 sock->ops = NULL;
1201                 goto out_module_put;
1202         }
1203         /*
1204          * Now that we're done with the ->create function, the [loadable]
1205          * module can have its refcnt decremented
1206          */
1207         module_put(net_families[family]->owner);
1208         *res = sock;
1209         security_socket_post_create(sock, family, type, protocol, kern);
1210
1211 out:
1212         net_family_read_unlock();
1213         return i;
1214 out_module_put:
1215         module_put(net_families[family]->owner);
1216 out_release:
1217         sock_release(sock);
1218         goto out;
1219 }
1220
1221 int sock_create(int family, int type, int protocol, struct socket **res)
1222 {
1223         return __sock_create(family, type, protocol, res, 0);
1224 }
1225
1226 int sock_create_kern(int family, int type, int protocol, struct socket **res)
1227 {
1228         return __sock_create(family, type, protocol, res, 1);
1229 }
1230
1231 asmlinkage long sys_socket(int family, int type, int protocol)
1232 {
1233         int retval;
1234         struct socket *sock;
1235
1236         retval = sock_create(family, type, protocol, &sock);
1237         if (retval < 0)
1238                 goto out;
1239
1240         set_bit(SOCK_USER_SOCKET, &sock->flags);
1241         retval = sock_map_fd(sock);
1242         if (retval < 0)
1243                 goto out_release;
1244
1245 out:
1246         /* It may be already another descriptor 8) Not kernel problem. */
1247         return retval;
1248
1249 out_release:
1250         sock_release(sock);
1251         return retval;
1252 }
1253
1254 /*
1255  *      Create a pair of connected sockets.
1256  */
1257
1258 asmlinkage long sys_socketpair(int family, int type, int protocol, int __user *usockvec)
1259 {
1260         struct socket *sock1, *sock2;
1261         int fd1, fd2, err;
1262
1263         /*
1264          * Obtain the first socket and check if the underlying protocol
1265          * supports the socketpair call.
1266          */
1267
1268         err = sock_create(family, type, protocol, &sock1);
1269         if (err < 0)
1270                 goto out;
1271         set_bit(SOCK_USER_SOCKET, &sock1->flags);
1272
1273         err = sock_create(family, type, protocol, &sock2);
1274         if (err < 0)
1275                 goto out_release_1;
1276         set_bit(SOCK_USER_SOCKET, &sock2->flags);
1277
1278         err = sock1->ops->socketpair(sock1, sock2);
1279         if (err < 0) 
1280                 goto out_release_both;
1281
1282         fd1 = fd2 = -1;
1283
1284         err = sock_map_fd(sock1);
1285         if (err < 0)
1286                 goto out_release_both;
1287         fd1 = err;
1288
1289         err = sock_map_fd(sock2);
1290         if (err < 0)
1291                 goto out_close_1;
1292         fd2 = err;
1293
1294         /* fd1 and fd2 may be already another descriptors.
1295          * Not kernel problem.
1296          */
1297
1298         err = put_user(fd1, &usockvec[0]); 
1299         if (!err)
1300                 err = put_user(fd2, &usockvec[1]);
1301         if (!err)
1302                 return 0;
1303
1304         sys_close(fd2);
1305         sys_close(fd1);
1306         return err;
1307
1308 out_close_1:
1309         sock_release(sock2);
1310         sys_close(fd1);
1311         return err;
1312
1313 out_release_both:
1314         sock_release(sock2);
1315 out_release_1:
1316         sock_release(sock1);
1317 out:
1318         return err;
1319 }
1320
1321
1322 /*
1323  *      Bind a name to a socket. Nothing much to do here since it's
1324  *      the protocol's responsibility to handle the local address.
1325  *
1326  *      We move the socket address to kernel space before we call
1327  *      the protocol layer (having also checked the address is ok).
1328  */
1329
1330 asmlinkage long sys_bind(int fd, struct sockaddr __user *umyaddr, int addrlen)
1331 {
1332         struct socket *sock;
1333         char address[MAX_SOCK_ADDR];
1334         int err;
1335
1336         if((sock = sockfd_lookup(fd,&err))!=NULL)
1337         {
1338                 if((err=move_addr_to_kernel(umyaddr,addrlen,address))>=0) {
1339                         err = security_socket_bind(sock, (struct sockaddr *)address, addrlen);
1340                         if (err) {
1341                                 sockfd_put(sock);
1342                                 return err;
1343                         }
1344                         err = sock->ops->bind(sock, (struct sockaddr *)address, addrlen);
1345                 }
1346                 sockfd_put(sock);
1347         }                       
1348         return err;
1349 }
1350
1351
1352 /*
1353  *      Perform a listen. Basically, we allow the protocol to do anything
1354  *      necessary for a listen, and if that works, we mark the socket as
1355  *      ready for listening.
1356  */
1357
1358 int sysctl_somaxconn = SOMAXCONN;
1359
1360 asmlinkage long sys_listen(int fd, int backlog)
1361 {
1362         struct socket *sock;
1363         int err;
1364         
1365         if ((sock = sockfd_lookup(fd, &err)) != NULL) {
1366                 if ((unsigned) backlog > sysctl_somaxconn)
1367                         backlog = sysctl_somaxconn;
1368
1369                 err = security_socket_listen(sock, backlog);
1370                 if (err) {
1371                         sockfd_put(sock);
1372                         return err;
1373                 }
1374
1375                 err=sock->ops->listen(sock, backlog);
1376                 sockfd_put(sock);
1377         }
1378         return err;
1379 }
1380
1381
1382 /*
1383  *      For accept, we attempt to create a new socket, set up the link
1384  *      with the client, wake up the client, then return the new
1385  *      connected fd. We collect the address of the connector in kernel
1386  *      space and move it to user at the very end. This is unclean because
1387  *      we open the socket then return an error.
1388  *
1389  *      1003.1g adds the ability to recvmsg() to query connection pending
1390  *      status to recvmsg. We need to add that support in a way thats
1391  *      clean when we restucture accept also.
1392  */
1393
1394 asmlinkage long sys_accept(int fd, struct sockaddr __user *upeer_sockaddr, int __user *upeer_addrlen)
1395 {
1396         struct socket *sock, *newsock;
1397         int err, len;
1398         char address[MAX_SOCK_ADDR];
1399
1400         sock = sockfd_lookup(fd, &err);
1401         if (!sock)
1402                 goto out;
1403
1404         err = -EMFILE;
1405         if (!(newsock = sock_alloc())) 
1406                 goto out_put;
1407
1408         newsock->type = sock->type;
1409         newsock->ops = sock->ops;
1410
1411         err = security_socket_accept(sock, newsock);
1412         if (err)
1413                 goto out_release;
1414
1415         /*
1416          * We don't need try_module_get here, as the listening socket (sock)
1417          * has the protocol module (sock->ops->owner) held.
1418          */
1419         __module_get(newsock->ops->owner);
1420
1421         err = sock->ops->accept(sock, newsock, sock->file->f_flags);
1422         if (err < 0)
1423                 goto out_release;
1424
1425         if (upeer_sockaddr) {
1426                 if(newsock->ops->getname(newsock, (struct sockaddr *)address, &len, 2)<0) {
1427                         err = -ECONNABORTED;
1428                         goto out_release;
1429                 }
1430                 err = move_addr_to_user(address, len, upeer_sockaddr, upeer_addrlen);
1431                 if (err < 0)
1432                         goto out_release;
1433         }
1434
1435         /* File flags are not inherited via accept() unlike another OSes. */
1436
1437         if ((err = sock_map_fd(newsock)) < 0)
1438                 goto out_release;
1439
1440         security_socket_post_accept(sock, newsock);
1441
1442 out_put:
1443         sockfd_put(sock);
1444 out:
1445         return err;
1446 out_release:
1447         sock_release(newsock);
1448         goto out_put;
1449 }
1450
1451
1452 /*
1453  *      Attempt to connect to a socket with the server address.  The address
1454  *      is in user space so we verify it is OK and move it to kernel space.
1455  *
1456  *      For 1003.1g we need to add clean support for a bind to AF_UNSPEC to
1457  *      break bindings
1458  *
1459  *      NOTE: 1003.1g draft 6.3 is broken with respect to AX.25/NetROM and
1460  *      other SEQPACKET protocols that take time to connect() as it doesn't
1461  *      include the -EINPROGRESS status for such sockets.
1462  */
1463
1464 asmlinkage long sys_connect(int fd, struct sockaddr __user *uservaddr, int addrlen)
1465 {
1466         struct socket *sock;
1467         char address[MAX_SOCK_ADDR];
1468         int err;
1469
1470         sock = sockfd_lookup(fd, &err);
1471         if (!sock)
1472                 goto out;
1473         err = move_addr_to_kernel(uservaddr, addrlen, address);
1474         if (err < 0)
1475                 goto out_put;
1476
1477         err = security_socket_connect(sock, (struct sockaddr *)address, addrlen);
1478         if (err)
1479                 goto out_put;
1480
1481         err = sock->ops->connect(sock, (struct sockaddr *) address, addrlen,
1482                                  sock->file->f_flags);
1483 out_put:
1484         sockfd_put(sock);
1485 out:
1486         return err;
1487 }
1488
1489 /*
1490  *      Get the local address ('name') of a socket object. Move the obtained
1491  *      name to user space.
1492  */
1493
1494 asmlinkage long sys_getsockname(int fd, struct sockaddr __user *usockaddr, int __user *usockaddr_len)
1495 {
1496         struct socket *sock;
1497         char address[MAX_SOCK_ADDR];
1498         int len, err;
1499         
1500         sock = sockfd_lookup(fd, &err);
1501         if (!sock)
1502                 goto out;
1503
1504         err = security_socket_getsockname(sock);
1505         if (err)
1506                 goto out_put;
1507
1508         err = sock->ops->getname(sock, (struct sockaddr *)address, &len, 0);
1509         if (err)
1510                 goto out_put;
1511         err = move_addr_to_user(address, len, usockaddr, usockaddr_len);
1512
1513 out_put:
1514         sockfd_put(sock);
1515 out:
1516         return err;
1517 }
1518
1519 /*
1520  *      Get the remote address ('name') of a socket object. Move the obtained
1521  *      name to user space.
1522  */
1523
1524 asmlinkage long sys_getpeername(int fd, struct sockaddr __user *usockaddr, int __user *usockaddr_len)
1525 {
1526         struct socket *sock;
1527         char address[MAX_SOCK_ADDR];
1528         int len, err;
1529
1530         if ((sock = sockfd_lookup(fd, &err))!=NULL)
1531         {
1532                 err = security_socket_getpeername(sock);
1533                 if (err) {
1534                         sockfd_put(sock);
1535                         return err;
1536                 }
1537
1538                 err = sock->ops->getname(sock, (struct sockaddr *)address, &len, 1);
1539                 if (!err)
1540                         err=move_addr_to_user(address,len, usockaddr, usockaddr_len);
1541                 sockfd_put(sock);
1542         }
1543         return err;
1544 }
1545
1546 /*
1547  *      Send a datagram to a given address. We move the address into kernel
1548  *      space and check the user space data area is readable before invoking
1549  *      the protocol.
1550  */
1551
1552 asmlinkage long sys_sendto(int fd, void __user * buff, size_t len, unsigned flags,
1553                            struct sockaddr __user *addr, int addr_len)
1554 {
1555         struct socket *sock;
1556         char address[MAX_SOCK_ADDR];
1557         int err;
1558         struct msghdr msg;
1559         struct iovec iov;
1560         
1561         sock = sockfd_lookup(fd, &err);
1562         if (!sock)
1563                 goto out;
1564         iov.iov_base=buff;
1565         iov.iov_len=len;
1566         msg.msg_name=NULL;
1567         msg.msg_iov=&iov;
1568         msg.msg_iovlen=1;
1569         msg.msg_control=NULL;
1570         msg.msg_controllen=0;
1571         msg.msg_namelen=0;
1572         if(addr)
1573         {
1574                 err = move_addr_to_kernel(addr, addr_len, address);
1575                 if (err < 0)
1576                         goto out_put;
1577                 msg.msg_name=address;
1578                 msg.msg_namelen=addr_len;
1579         }
1580         if (sock->file->f_flags & O_NONBLOCK)
1581                 flags |= MSG_DONTWAIT;
1582         msg.msg_flags = flags;
1583         err = sock_sendmsg(sock, &msg, len);
1584
1585 out_put:                
1586         sockfd_put(sock);
1587 out:
1588         return err;
1589 }
1590
1591 /*
1592  *      Send a datagram down a socket. 
1593  */
1594
1595 asmlinkage long sys_send(int fd, void __user * buff, size_t len, unsigned flags)
1596 {
1597         return sys_sendto(fd, buff, len, flags, NULL, 0);
1598 }
1599
1600 /*
1601  *      Receive a frame from the socket and optionally record the address of the 
1602  *      sender. We verify the buffers are writable and if needed move the
1603  *      sender address from kernel to user space.
1604  */
1605
1606 asmlinkage long sys_recvfrom(int fd, void __user * ubuf, size_t size, unsigned flags,
1607                              struct sockaddr __user *addr, int __user *addr_len)
1608 {
1609         struct socket *sock;
1610         struct iovec iov;
1611         struct msghdr msg;
1612         char address[MAX_SOCK_ADDR];
1613         int err,err2;
1614
1615         sock = sockfd_lookup(fd, &err);
1616         if (!sock)
1617                 goto out;
1618
1619         msg.msg_control=NULL;
1620         msg.msg_controllen=0;
1621         msg.msg_iovlen=1;
1622         msg.msg_iov=&iov;
1623         iov.iov_len=size;
1624         iov.iov_base=ubuf;
1625         msg.msg_name=address;
1626         msg.msg_namelen=MAX_SOCK_ADDR;
1627         if (sock->file->f_flags & O_NONBLOCK)
1628                 flags |= MSG_DONTWAIT;
1629         err=sock_recvmsg(sock, &msg, size, flags);
1630
1631         if(err >= 0 && addr != NULL)
1632         {
1633                 err2=move_addr_to_user(address, msg.msg_namelen, addr, addr_len);
1634                 if(err2<0)
1635                         err=err2;
1636         }
1637         sockfd_put(sock);                       
1638 out:
1639         return err;
1640 }
1641
1642 /*
1643  *      Receive a datagram from a socket. 
1644  */
1645
1646 asmlinkage long sys_recv(int fd, void __user * ubuf, size_t size, unsigned flags)
1647 {
1648         return sys_recvfrom(fd, ubuf, size, flags, NULL, NULL);
1649 }
1650
1651 /*
1652  *      Set a socket option. Because we don't know the option lengths we have
1653  *      to pass the user mode parameter for the protocols to sort out.
1654  */
1655
1656 asmlinkage long sys_setsockopt(int fd, int level, int optname, char __user *optval, int optlen)
1657 {
1658         int err;
1659         struct socket *sock;
1660
1661         if (optlen < 0)
1662                 return -EINVAL;
1663                         
1664         if ((sock = sockfd_lookup(fd, &err))!=NULL)
1665         {
1666                 err = security_socket_setsockopt(sock,level,optname);
1667                 if (err) {
1668                         sockfd_put(sock);
1669                         return err;
1670                 }
1671
1672                 if (level == SOL_SOCKET)
1673                         err=sock_setsockopt(sock,level,optname,optval,optlen);
1674                 else
1675                         err=sock->ops->setsockopt(sock, level, optname, optval, optlen);
1676                 sockfd_put(sock);
1677         }
1678         return err;
1679 }
1680
1681 /*
1682  *      Get a socket option. Because we don't know the option lengths we have
1683  *      to pass a user mode parameter for the protocols to sort out.
1684  */
1685
1686 asmlinkage long sys_getsockopt(int fd, int level, int optname, char __user *optval, int __user *optlen)
1687 {
1688         int err;
1689         struct socket *sock;
1690
1691         if ((sock = sockfd_lookup(fd, &err))!=NULL)
1692         {
1693                 err = security_socket_getsockopt(sock, level, 
1694                                                            optname);
1695                 if (err) {
1696                         sockfd_put(sock);
1697                         return err;
1698                 }
1699
1700                 if (level == SOL_SOCKET)
1701                         err=sock_getsockopt(sock,level,optname,optval,optlen);
1702                 else
1703                         err=sock->ops->getsockopt(sock, level, optname, optval, optlen);
1704                 sockfd_put(sock);
1705         }
1706         return err;
1707 }
1708
1709
1710 /*
1711  *      Shutdown a socket.
1712  */
1713
1714 asmlinkage long sys_shutdown(int fd, int how)
1715 {
1716         int err;
1717         struct socket *sock;
1718
1719         if ((sock = sockfd_lookup(fd, &err))!=NULL)
1720         {
1721                 err = security_socket_shutdown(sock, how);
1722                 if (err) {
1723                         sockfd_put(sock);
1724                         return err;
1725                 }
1726                                 
1727                 err=sock->ops->shutdown(sock, how);
1728                 sockfd_put(sock);
1729         }
1730         return err;
1731 }
1732
1733 /* A couple of helpful macros for getting the address of the 32/64 bit 
1734  * fields which are the same type (int / unsigned) on our platforms.
1735  */
1736 #define COMPAT_MSG(msg, member) ((MSG_CMSG_COMPAT & flags) ? &msg##_compat->member : &msg->member)
1737 #define COMPAT_NAMELEN(msg)     COMPAT_MSG(msg, msg_namelen)
1738 #define COMPAT_FLAGS(msg)       COMPAT_MSG(msg, msg_flags)
1739
1740
1741 /*
1742  *      BSD sendmsg interface
1743  */
1744
1745 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags)
1746 {
1747         struct compat_msghdr __user *msg_compat = (struct compat_msghdr __user *)msg;
1748         struct socket *sock;
1749         char address[MAX_SOCK_ADDR];
1750         struct iovec iovstack[UIO_FASTIOV], *iov = iovstack;
1751         unsigned char ctl[sizeof(struct cmsghdr) + 20]; /* 20 is size of ipv6_pktinfo */
1752         unsigned char *ctl_buf = ctl;
1753         struct msghdr msg_sys;
1754         int err, ctl_len, iov_size, total_len;
1755         
1756         err = -EFAULT;
1757         if (MSG_CMSG_COMPAT & flags) {
1758                 if (get_compat_msghdr(&msg_sys, msg_compat))
1759                         return -EFAULT;
1760         } else if (copy_from_user(&msg_sys, msg, sizeof(struct msghdr)))
1761                 return -EFAULT;
1762
1763         sock = sockfd_lookup(fd, &err);
1764         if (!sock) 
1765                 goto out;
1766
1767         /* do not move before msg_sys is valid */
1768         err = -EMSGSIZE;
1769         if (msg_sys.msg_iovlen > UIO_MAXIOV)
1770                 goto out_put;
1771
1772         /* Check whether to allocate the iovec area*/
1773         err = -ENOMEM;
1774         iov_size = msg_sys.msg_iovlen * sizeof(struct iovec);
1775         if (msg_sys.msg_iovlen > UIO_FASTIOV) {
1776                 iov = sock_kmalloc(sock->sk, iov_size, GFP_KERNEL);
1777                 if (!iov)
1778                         goto out_put;
1779         }
1780
1781         /* This will also move the address data into kernel space */
1782         if (MSG_CMSG_COMPAT & flags) {
1783                 err = verify_compat_iovec(&msg_sys, iov, address, VERIFY_READ);
1784         } else
1785                 err = verify_iovec(&msg_sys, iov, address, VERIFY_READ);
1786         if (err < 0) 
1787                 goto out_freeiov;
1788         total_len = err;
1789
1790         err = -ENOBUFS;
1791
1792         if (msg_sys.msg_controllen > INT_MAX)
1793                 goto out_freeiov;
1794         ctl_len = msg_sys.msg_controllen; 
1795         if ((MSG_CMSG_COMPAT & flags) && ctl_len) {
1796                 err = cmsghdr_from_user_compat_to_kern(&msg_sys, ctl, sizeof(ctl));
1797                 if (err)
1798                         goto out_freeiov;
1799                 ctl_buf = msg_sys.msg_control;
1800         } else if (ctl_len) {
1801                 if (ctl_len > sizeof(ctl))
1802                 {
1803                         ctl_buf = sock_kmalloc(sock->sk, ctl_len, GFP_KERNEL);
1804                         if (ctl_buf == NULL) 
1805                                 goto out_freeiov;
1806                 }
1807                 err = -EFAULT;
1808                 /*
1809                  * Careful! Before this, msg_sys.msg_control contains a user pointer.
1810                  * Afterwards, it will be a kernel pointer. Thus the compiler-assisted
1811                  * checking falls down on this.
1812                  */
1813                 if (copy_from_user(ctl_buf, (void __user *) msg_sys.msg_control, ctl_len))
1814                         goto out_freectl;
1815                 msg_sys.msg_control = ctl_buf;
1816         }
1817         msg_sys.msg_flags = flags;
1818
1819         if (sock->file->f_flags & O_NONBLOCK)
1820                 msg_sys.msg_flags |= MSG_DONTWAIT;
1821         err = sock_sendmsg(sock, &msg_sys, total_len);
1822
1823 out_freectl:
1824         if (ctl_buf != ctl)    
1825                 sock_kfree_s(sock->sk, ctl_buf, ctl_len);
1826 out_freeiov:
1827         if (iov != iovstack)
1828                 sock_kfree_s(sock->sk, iov, iov_size);
1829 out_put:
1830         sockfd_put(sock);
1831 out:       
1832         return err;
1833 }
1834
1835 /*
1836  *      BSD recvmsg interface
1837  */
1838
1839 asmlinkage long sys_recvmsg(int fd, struct msghdr __user *msg, unsigned int flags)
1840 {
1841         struct compat_msghdr __user *msg_compat = (struct compat_msghdr __user *)msg;
1842         struct socket *sock;
1843         struct iovec iovstack[UIO_FASTIOV];
1844         struct iovec *iov=iovstack;
1845         struct msghdr msg_sys;
1846         unsigned long cmsg_ptr;
1847         int err, iov_size, total_len, len;
1848
1849         /* kernel mode address */
1850         char addr[MAX_SOCK_ADDR];
1851
1852         /* user mode address pointers */
1853         struct sockaddr __user *uaddr;
1854         int __user *uaddr_len;
1855         
1856         if (MSG_CMSG_COMPAT & flags) {
1857                 if (get_compat_msghdr(&msg_sys, msg_compat))
1858                         return -EFAULT;
1859         } else
1860                 if (copy_from_user(&msg_sys,msg,sizeof(struct msghdr)))
1861                         return -EFAULT;
1862
1863         sock = sockfd_lookup(fd, &err);
1864         if (!sock)
1865                 goto out;
1866
1867         err = -EMSGSIZE;
1868         if (msg_sys.msg_iovlen > UIO_MAXIOV)
1869                 goto out_put;
1870         
1871         /* Check whether to allocate the iovec area*/
1872         err = -ENOMEM;
1873         iov_size = msg_sys.msg_iovlen * sizeof(struct iovec);
1874         if (msg_sys.msg_iovlen > UIO_FASTIOV) {
1875                 iov = sock_kmalloc(sock->sk, iov_size, GFP_KERNEL);
1876                 if (!iov)
1877                         goto out_put;
1878         }
1879
1880         /*
1881          *      Save the user-mode address (verify_iovec will change the
1882          *      kernel msghdr to use the kernel address space)
1883          */
1884          
1885         uaddr = (void __user *) msg_sys.msg_name;
1886         uaddr_len = COMPAT_NAMELEN(msg);
1887         if (MSG_CMSG_COMPAT & flags) {
1888                 err = verify_compat_iovec(&msg_sys, iov, addr, VERIFY_WRITE);
1889         } else
1890                 err = verify_iovec(&msg_sys, iov, addr, VERIFY_WRITE);
1891         if (err < 0)
1892                 goto out_freeiov;
1893         total_len=err;
1894
1895         cmsg_ptr = (unsigned long)msg_sys.msg_control;
1896         msg_sys.msg_flags = 0;
1897         if (MSG_CMSG_COMPAT & flags)
1898                 msg_sys.msg_flags = MSG_CMSG_COMPAT;
1899         
1900         if (sock->file->f_flags & O_NONBLOCK)
1901                 flags |= MSG_DONTWAIT;
1902         err = sock_recvmsg(sock, &msg_sys, total_len, flags);
1903         if (err < 0)
1904                 goto out_freeiov;
1905         len = err;
1906
1907         if (uaddr != NULL) {
1908                 err = move_addr_to_user(addr, msg_sys.msg_namelen, uaddr, uaddr_len);
1909                 if (err < 0)
1910                         goto out_freeiov;
1911         }
1912         err = __put_user(msg_sys.msg_flags, COMPAT_FLAGS(msg));
1913         if (err)
1914                 goto out_freeiov;
1915         if (MSG_CMSG_COMPAT & flags)
1916                 err = __put_user((unsigned long)msg_sys.msg_control-cmsg_ptr, 
1917                                  &msg_compat->msg_controllen);
1918         else
1919                 err = __put_user((unsigned long)msg_sys.msg_control-cmsg_ptr, 
1920                                  &msg->msg_controllen);
1921         if (err)
1922                 goto out_freeiov;
1923         err = len;
1924
1925 out_freeiov:
1926         if (iov != iovstack)
1927                 sock_kfree_s(sock->sk, iov, iov_size);
1928 out_put:
1929         sockfd_put(sock);
1930 out:
1931         return err;
1932 }
1933
1934 #ifdef __ARCH_WANT_SYS_SOCKETCALL
1935
1936 /* Argument list sizes for sys_socketcall */
1937 #define AL(x) ((x) * sizeof(unsigned long))
1938 static unsigned char nargs[18]={AL(0),AL(3),AL(3),AL(3),AL(2),AL(3),
1939                                 AL(3),AL(3),AL(4),AL(4),AL(4),AL(6),
1940                                 AL(6),AL(2),AL(5),AL(5),AL(3),AL(3)};
1941 #undef AL
1942
1943 /*
1944  *      System call vectors. 
1945  *
1946  *      Argument checking cleaned up. Saved 20% in size.
1947  *  This function doesn't need to set the kernel lock because
1948  *  it is set by the callees. 
1949  */
1950
1951 asmlinkage long sys_socketcall(int call, unsigned long __user *args)
1952 {
1953         unsigned long a[6];
1954         unsigned long a0,a1;
1955         int err;
1956
1957         if(call<1||call>SYS_RECVMSG)
1958                 return -EINVAL;
1959
1960         /* copy_from_user should be SMP safe. */
1961         if (copy_from_user(a, args, nargs[call]))
1962                 return -EFAULT;
1963                 
1964         a0=a[0];
1965         a1=a[1];
1966         
1967         switch(call) 
1968         {
1969                 case SYS_SOCKET:
1970                         err = sys_socket(a0,a1,a[2]);
1971                         break;
1972                 case SYS_BIND:
1973                         err = sys_bind(a0,(struct sockaddr __user *)a1, a[2]);
1974                         break;
1975                 case SYS_CONNECT:
1976                         err = sys_connect(a0, (struct sockaddr __user *)a1, a[2]);
1977                         break;
1978                 case SYS_LISTEN:
1979                         err = sys_listen(a0,a1);
1980                         break;
1981                 case SYS_ACCEPT:
1982                         err = sys_accept(a0,(struct sockaddr __user *)a1, (int __user *)a[2]);
1983                         break;
1984                 case SYS_GETSOCKNAME:
1985                         err = sys_getsockname(a0,(struct sockaddr __user *)a1, (int __user *)a[2]);
1986                         break;
1987                 case SYS_GETPEERNAME:
1988                         err = sys_getpeername(a0, (struct sockaddr __user *)a1, (int __user *)a[2]);
1989                         break;
1990                 case SYS_SOCKETPAIR:
1991                         err = sys_socketpair(a0,a1, a[2], (int __user *)a[3]);
1992                         break;
1993                 case SYS_SEND:
1994                         err = sys_send(a0, (void __user *)a1, a[2], a[3]);
1995                         break;
1996                 case SYS_SENDTO:
1997                         err = sys_sendto(a0,(void __user *)a1, a[2], a[3],
1998                                          (struct sockaddr __user *)a[4], a[5]);
1999                         break;
2000                 case SYS_RECV:
2001                         err = sys_recv(a0, (void __user *)a1, a[2], a[3]);
2002                         break;
2003                 case SYS_RECVFROM:
2004                         err = sys_recvfrom(a0, (void __user *)a1, a[2], a[3],
2005                                            (struct sockaddr __user *)a[4], (int __user *)a[5]);
2006                         break;
2007                 case SYS_SHUTDOWN:
2008                         err = sys_shutdown(a0,a1);
2009                         break;
2010                 case SYS_SETSOCKOPT:
2011                         err = sys_setsockopt(a0, a1, a[2], (char __user *)a[3], a[4]);
2012                         break;
2013                 case SYS_GETSOCKOPT:
2014                         err = sys_getsockopt(a0, a1, a[2], (char __user *)a[3], (int __user *)a[4]);
2015                         break;
2016                 case SYS_SENDMSG:
2017                         err = sys_sendmsg(a0, (struct msghdr __user *) a1, a[2]);
2018                         break;
2019                 case SYS_RECVMSG:
2020                         err = sys_recvmsg(a0, (struct msghdr __user *) a1, a[2]);
2021                         break;
2022                 default:
2023                         err = -EINVAL;
2024                         break;
2025         }
2026         return err;
2027 }
2028
2029 #endif /* __ARCH_WANT_SYS_SOCKETCALL */
2030
2031 /*
2032  *      This function is called by a protocol handler that wants to
2033  *      advertise its address family, and have it linked into the
2034  *      SOCKET module.
2035  */
2036
2037 int sock_register(struct net_proto_family *ops)
2038 {
2039         int err;
2040
2041         if (ops->family >= NPROTO) {
2042                 printk(KERN_CRIT "protocol %d >= NPROTO(%d)\n", ops->family, NPROTO);
2043                 return -ENOBUFS;
2044         }
2045         net_family_write_lock();
2046         err = -EEXIST;
2047         if (net_families[ops->family] == NULL) {
2048                 net_families[ops->family]=ops;
2049                 err = 0;
2050         }
2051         net_family_write_unlock();
2052         printk(KERN_INFO "NET: Registered protocol family %d\n",
2053                ops->family);
2054         return err;
2055 }
2056
2057 /*
2058  *      This function is called by a protocol handler that wants to
2059  *      remove its address family, and have it unlinked from the
2060  *      SOCKET module.
2061  */
2062
2063 int sock_unregister(int family)
2064 {
2065         if (family < 0 || family >= NPROTO)
2066                 return -1;
2067
2068         net_family_write_lock();
2069         net_families[family]=NULL;
2070         net_family_write_unlock();
2071         printk(KERN_INFO "NET: Unregistered protocol family %d\n",
2072                family);
2073         return 0;
2074 }
2075
2076
2077 extern void sk_init(void);
2078
2079 void __init sock_init(void)
2080 {
2081         int i;
2082
2083         /*
2084          *      Initialize all address (protocol) families. 
2085          */
2086          
2087         for (i = 0; i < NPROTO; i++) 
2088                 net_families[i] = NULL;
2089
2090         /*
2091          *      Initialize sock SLAB cache.
2092          */
2093          
2094         sk_init();
2095
2096 #ifdef SLAB_SKB
2097         /*
2098          *      Initialize skbuff SLAB cache 
2099          */
2100         skb_init();
2101 #endif
2102
2103         /*
2104          *      Initialize the protocols module. 
2105          */
2106
2107         init_inodecache();
2108         register_filesystem(&sock_fs_type);
2109         sock_mnt = kern_mount(&sock_fs_type);
2110         /* The real protocol initialization is performed when
2111          *  do_initcalls is run.  
2112          */
2113
2114 #ifdef CONFIG_NETFILTER
2115         netfilter_init();
2116 #endif
2117 }
2118
2119 int tux_Dprintk;
2120 int tux_TDprintk;
2121
2122 #ifdef CONFIG_TUX_MODULE
2123
2124 asmlinkage long (*sys_tux_ptr) (unsigned int action, user_req_t *u_info) = NULL;
2125
2126 struct module *tux_module = NULL;
2127 spinlock_t tux_module_lock = SPIN_LOCK_UNLOCKED;
2128
2129 asmlinkage long sys_tux (unsigned int action, user_req_t *u_info)
2130 {
2131         int ret;
2132
2133         if (current->tux_info)
2134                 return sys_tux_ptr(action, u_info);
2135
2136         ret = -ENOSYS;
2137         spin_lock(&tux_module_lock);
2138         if (!tux_module)
2139                 goto out_unlock;
2140         if (!try_module_get(tux_module))
2141                 goto out_unlock;
2142         spin_unlock(&tux_module_lock);
2143
2144         if (!sys_tux_ptr)
2145                 TUX_BUG();
2146         ret = sys_tux_ptr(action, u_info);
2147
2148         spin_lock(&tux_module_lock);
2149         module_put(tux_module);
2150 out_unlock:
2151         spin_unlock(&tux_module_lock);
2152
2153         return ret;
2154 }
2155
2156 EXPORT_SYMBOL_GPL(tux_module);
2157 EXPORT_SYMBOL_GPL(tux_module_lock);
2158 EXPORT_SYMBOL_GPL(sys_tux_ptr);
2159
2160 EXPORT_SYMBOL_GPL(tux_Dprintk);
2161 EXPORT_SYMBOL_GPL(tux_TDprintk);
2162
2163 #endif
2164 #ifdef CONFIG_PROC_FS
2165 void socket_seq_show(struct seq_file *seq)
2166 {
2167         int cpu;
2168         int counter = 0;
2169
2170         for (cpu = 0; cpu < NR_CPUS; cpu++)
2171                 counter += per_cpu(sockets_in_use, cpu);
2172
2173         /* It can be negative, by the way. 8) */
2174         if (counter < 0)
2175                 counter = 0;
2176
2177         seq_printf(seq, "sockets: used %d\n", counter);
2178 }
2179 #endif /* CONFIG_PROC_FS */
2180
2181 /* ABI emulation layers need these two */
2182 EXPORT_SYMBOL(move_addr_to_kernel);
2183 EXPORT_SYMBOL(move_addr_to_user);
2184 EXPORT_SYMBOL(sock_alloc);
2185 EXPORT_SYMBOL(sock_alloc_inode);
2186 EXPORT_SYMBOL(sock_create);
2187 EXPORT_SYMBOL(sock_create_kern);
2188 EXPORT_SYMBOL(sock_create_lite);
2189 EXPORT_SYMBOL(sock_map_fd);
2190 EXPORT_SYMBOL(sock_recvmsg);
2191 EXPORT_SYMBOL(sock_register);
2192 EXPORT_SYMBOL(sock_release);
2193 EXPORT_SYMBOL(sock_sendmsg);
2194 EXPORT_SYMBOL(sock_unregister);
2195 EXPORT_SYMBOL(sock_wake_async);
2196 EXPORT_SYMBOL(sockfd_lookup);
2197 EXPORT_SYMBOL(kernel_sendmsg);
2198 EXPORT_SYMBOL(kernel_recvmsg);