Optimize andes_clear_page() and andes_copy_page() with prefetch
[linux-2.6/linux-mips.git] / net / socket.c
blob1870a867c6ac0d5ce215877441eddb3bec7c457c
1 /*
2 * NET An implementation of the SOCKET network access protocol.
4 * Version: @(#)socket.c 1.1.93 18/02/95
6 * Authors: Orest Zborowski, <obz@Kodak.COM>
7 * Ross Biro, <bir7@leland.Stanford.Edu>
8 * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
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
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.
55 * This module is effectively the top level interface to the BSD socket
56 * paradigm.
60 #include <linux/config.h>
61 #include <linux/mm.h>
62 #include <linux/smp_lock.h>
63 #include <linux/socket.h>
64 #include <linux/file.h>
65 #include <linux/net.h>
66 #include <linux/interrupt.h>
67 #include <linux/netdevice.h>
68 #include <linux/proc_fs.h>
69 #include <linux/wanrouter.h>
70 #include <linux/init.h>
71 #include <linux/poll.h>
72 #include <linux/cache.h>
73 #include <linux/module.h>
75 #if defined(CONFIG_KMOD) && defined(CONFIG_NET)
76 #include <linux/kmod.h>
77 #endif
79 #include <asm/uaccess.h>
81 #include <linux/inet.h>
82 #include <net/ip.h>
83 #include <net/sock.h>
84 #include <net/tcp.h>
85 #include <net/udp.h>
86 #include <net/scm.h>
87 #include <linux/netfilter.h>
89 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
90 static loff_t sock_lseek(struct file *file, loff_t offset, int whence);
91 static ssize_t sock_read(struct file *file, char *buf,
92 size_t size, loff_t *ppos);
93 static ssize_t sock_write(struct file *file, const char *buf,
94 size_t size, loff_t *ppos);
95 static int sock_mmap(struct file *file, struct vm_area_struct * vma);
97 static int sock_close(struct inode *inode, struct file *file);
98 static unsigned int sock_poll(struct file *file,
99 struct poll_table_struct *wait);
100 static int sock_ioctl(struct inode *inode, struct file *file,
101 unsigned int cmd, unsigned long arg);
102 static int sock_fasync(int fd, struct file *filp, int on);
103 static ssize_t sock_readv(struct file *file, const struct iovec *vector,
104 unsigned long count, loff_t *ppos);
105 static ssize_t sock_writev(struct file *file, const struct iovec *vector,
106 unsigned long count, loff_t *ppos);
110 * Socket files have a set of 'special' operations as well as the generic file ones. These don't appear
111 * in the operation structures but are done directly via the socketcall() multiplexor.
114 static struct file_operations socket_file_ops = {
115 llseek: sock_lseek,
116 read: sock_read,
117 write: sock_write,
118 poll: sock_poll,
119 ioctl: sock_ioctl,
120 mmap: sock_mmap,
121 open: sock_no_open, /* special open code to disallow open via /proc */
122 release: sock_close,
123 fasync: sock_fasync,
124 readv: sock_readv,
125 writev: sock_writev
129 * The protocol list. Each protocol is registered in here.
132 static struct net_proto_family *net_families[NPROTO];
134 #ifdef CONFIG_SMP
135 static atomic_t net_family_lockct = ATOMIC_INIT(0);
136 static spinlock_t net_family_lock = SPIN_LOCK_UNLOCKED;
138 /* The strategy is: modifications net_family vector are short, do not
139 sleep and veeery rare, but read access should be free of any exclusive
140 locks.
143 static void net_family_write_lock(void)
145 spin_lock(&net_family_lock);
146 while (atomic_read(&net_family_lockct) != 0) {
147 spin_unlock(&net_family_lock);
149 current->policy |= SCHED_YIELD;
150 schedule();
152 spin_lock(&net_family_lock);
156 static __inline__ void net_family_write_unlock(void)
158 spin_unlock(&net_family_lock);
161 static __inline__ void net_family_read_lock(void)
163 atomic_inc(&net_family_lockct);
164 spin_unlock_wait(&net_family_lock);
167 static __inline__ void net_family_read_unlock(void)
169 atomic_dec(&net_family_lockct);
172 #else
173 #define net_family_write_lock() do { } while(0)
174 #define net_family_write_unlock() do { } while(0)
175 #define net_family_read_lock() do { } while(0)
176 #define net_family_read_unlock() do { } while(0)
177 #endif
181 * Statistics counters of the socket lists
184 static union {
185 int counter;
186 char __pad[SMP_CACHE_BYTES];
187 } sockets_in_use[NR_CPUS] __cacheline_aligned = {{0}};
190 * Support routines. Move socket addresses back and forth across the kernel/user
191 * divide and look after the messy bits.
194 #define MAX_SOCK_ADDR 128 /* 108 for Unix domain -
195 16 for IP, 16 for IPX,
196 24 for IPv6,
197 about 80 for AX.25
198 must be at least one bigger than
199 the AF_UNIX size (see net/unix/af_unix.c
200 :unix_mkname()).
204 * move_addr_to_kernel - copy a socket address into kernel space
205 * @uaddr: Address in user space
206 * @kaddr: Address in kernel space
207 * @ulen: Length in user space
209 * The address is copied into kernel space. If the provided address is
210 * too long an error code of -EINVAL is returned. If the copy gives
211 * invalid addresses -EFAULT is returned. On a success 0 is returned.
214 int move_addr_to_kernel(void *uaddr, int ulen, void *kaddr)
216 if(ulen<0||ulen>MAX_SOCK_ADDR)
217 return -EINVAL;
218 if(ulen==0)
219 return 0;
220 if(copy_from_user(kaddr,uaddr,ulen))
221 return -EFAULT;
222 return 0;
226 * move_addr_to_user - copy an address to user space
227 * @kaddr: kernel space address
228 * @klen: length of address in kernel
229 * @uaddr: user space address
230 * @ulen: pointer to user length field
232 * The value pointed to by ulen on entry is the buffer length available.
233 * This is overwritten with the buffer space used. -EINVAL is returned
234 * if an overlong buffer is specified or a negative buffer size. -EFAULT
235 * is returned if either the buffer or the length field are not
236 * accessible.
237 * After copying the data up to the limit the user specifies, the true
238 * length of the data is written over the length limit the user
239 * specified. Zero is returned for a success.
242 int move_addr_to_user(void *kaddr, int klen, void *uaddr, int *ulen)
244 int err;
245 int len;
247 if((err=get_user(len, ulen)))
248 return err;
249 if(len>klen)
250 len=klen;
251 if(len<0 || len> MAX_SOCK_ADDR)
252 return -EINVAL;
253 if(len)
255 if(copy_to_user(uaddr,kaddr,len))
256 return -EFAULT;
259 * "fromlen shall refer to the value before truncation.."
260 * 1003.1g
262 return __put_user(klen, ulen);
265 #define SOCKFS_MAGIC 0x534F434B
266 static int sockfs_statfs(struct super_block *sb, struct statfs *buf)
268 buf->f_type = SOCKFS_MAGIC;
269 buf->f_bsize = 1024;
270 buf->f_namelen = 255;
271 return 0;
274 static struct super_operations sockfs_ops = {
275 statfs: sockfs_statfs,
278 static struct super_block * sockfs_read_super(struct super_block *sb, void *data, int silent)
280 struct inode *root = get_empty_inode();
281 if (!root)
282 return NULL;
283 root->i_mode = S_IFDIR | S_IRUSR | S_IWUSR;
284 root->i_uid = root->i_gid = 0;
285 root->i_atime = root->i_mtime = root->i_ctime = CURRENT_TIME;
286 root->i_sb = sb;
287 root->i_dev = sb->s_dev;
288 sb->s_blocksize = 1024;
289 sb->s_blocksize_bits = 10;
290 sb->s_magic = SOCKFS_MAGIC;
291 sb->s_op = &sockfs_ops;
292 sb->s_root = d_alloc(NULL, &(const struct qstr) { "socket:", 7, 0 });
293 if (!sb->s_root) {
294 iput(root);
295 return NULL;
297 sb->s_root->d_sb = sb;
298 sb->s_root->d_parent = sb->s_root;
299 d_instantiate(sb->s_root, root);
300 return sb;
303 static struct vfsmount *sock_mnt;
304 static DECLARE_FSTYPE(sock_fs_type, "sockfs", sockfs_read_super,
305 FS_NOMOUNT|FS_SINGLE);
306 static int sockfs_delete_dentry(struct dentry *dentry)
308 return 1;
310 static struct dentry_operations sockfs_dentry_operations = {
311 d_delete: sockfs_delete_dentry,
315 * Obtains the first available file descriptor and sets it up for use.
317 * This functions creates file structure and maps it to fd space
318 * of current process. On success it returns file descriptor
319 * and file struct implicitly stored in sock->file.
320 * Note that another thread may close file descriptor before we return
321 * from this function. We use the fact that now we do not refer
322 * to socket after mapping. If one day we will need it, this
323 * function will inincrement ref. count on file by 1.
325 * In any case returned fd MAY BE not valid!
326 * This race condition is inavoidable
327 * with shared fd spaces, we cannot solve is inside kernel,
328 * but we take care of internal coherence yet.
331 static int sock_map_fd(struct socket *sock)
333 int fd;
334 struct qstr this;
335 char name[32];
338 * Find a file descriptor suitable for return to the user.
341 fd = get_unused_fd();
342 if (fd >= 0) {
343 struct file *file = get_empty_filp();
345 if (!file) {
346 put_unused_fd(fd);
347 fd = -ENFILE;
348 goto out;
351 sprintf(name, "[%lu]", sock->inode->i_ino);
352 this.name = name;
353 this.len = strlen(name);
354 this.hash = sock->inode->i_ino;
356 file->f_dentry = d_alloc(sock_mnt->mnt_sb->s_root, &this);
357 if (!file->f_dentry) {
358 put_filp(file);
359 put_unused_fd(fd);
360 fd = -ENOMEM;
361 goto out;
363 file->f_dentry->d_op = &sockfs_dentry_operations;
364 d_add(file->f_dentry, sock->inode);
365 file->f_vfsmnt = mntget(sock_mnt);
367 sock->file = file;
368 file->f_op = sock->inode->i_fop = &socket_file_ops;
369 file->f_mode = 3;
370 file->f_flags = O_RDWR;
371 file->f_pos = 0;
372 fd_install(fd, file);
375 out:
376 return fd;
379 extern __inline__ struct socket *socki_lookup(struct inode *inode)
381 return &inode->u.socket_i;
385 * sockfd_lookup - Go from a file number to its socket slot
386 * @fd: file handle
387 * @err: pointer to an error code return
389 * The file handle passed in is locked and the socket it is bound
390 * too is returned. If an error occurs the err pointer is overwritten
391 * with a negative errno code and NULL is returned. The function checks
392 * for both invalid handles and passing a handle which is not a socket.
394 * On a success the socket object pointer is returned.
397 struct socket *sockfd_lookup(int fd, int *err)
399 struct file *file;
400 struct inode *inode;
401 struct socket *sock;
403 if (!(file = fget(fd)))
405 *err = -EBADF;
406 return NULL;
409 inode = file->f_dentry->d_inode;
410 if (!inode || !inode->i_sock || !(sock = socki_lookup(inode)))
412 *err = -ENOTSOCK;
413 fput(file);
414 return NULL;
417 if (sock->file != file) {
418 printk(KERN_ERR "socki_lookup: socket file changed!\n");
419 sock->file = file;
421 return sock;
424 extern __inline__ void sockfd_put(struct socket *sock)
426 fput(sock->file);
430 * sock_alloc - allocate a socket
432 * Allocate a new inode and socket object. The two are bound together
433 * and initialised. The socket is then returned. If we are out of inodes
434 * NULL is returned.
437 struct socket *sock_alloc(void)
439 struct inode * inode;
440 struct socket * sock;
442 inode = get_empty_inode();
443 if (!inode)
444 return NULL;
446 sock = socki_lookup(inode);
448 inode->i_mode = S_IFSOCK|S_IRWXUGO;
449 inode->i_sock = 1;
450 inode->i_uid = current->fsuid;
451 inode->i_gid = current->fsgid;
453 sock->inode = inode;
454 init_waitqueue_head(&sock->wait);
455 sock->fasync_list = NULL;
456 sock->state = SS_UNCONNECTED;
457 sock->flags = 0;
458 sock->ops = NULL;
459 sock->sk = NULL;
460 sock->file = NULL;
462 sockets_in_use[smp_processor_id()].counter++;
463 return sock;
467 * In theory you can't get an open on this inode, but /proc provides
468 * a back door. Remember to keep it shut otherwise you'll let the
469 * creepy crawlies in.
472 static int sock_no_open(struct inode *irrelevant, struct file *dontcare)
474 return -ENXIO;
478 * sock_release - close a socket
479 * @sock: socket to close
481 * The socket is released from the protocol stack if it has a release
482 * callback, and the inode is then released if the socket is bound to
483 * an inode not a file.
486 void sock_release(struct socket *sock)
488 if (sock->ops)
489 sock->ops->release(sock);
491 if (sock->fasync_list)
492 printk(KERN_ERR "sock_release: fasync list not empty!\n");
494 sockets_in_use[smp_processor_id()].counter--;
495 if (!sock->file) {
496 iput(sock->inode);
497 return;
499 sock->file=NULL;
502 int sock_sendmsg(struct socket *sock, struct msghdr *msg, int size)
504 int err;
505 struct scm_cookie scm;
507 err = scm_send(sock, msg, &scm);
508 if (err >= 0) {
509 err = sock->ops->sendmsg(sock, msg, size, &scm);
510 scm_destroy(&scm);
512 return err;
515 int sock_recvmsg(struct socket *sock, struct msghdr *msg, int size, int flags)
517 struct scm_cookie scm;
519 memset(&scm, 0, sizeof(scm));
521 size = sock->ops->recvmsg(sock, msg, size, flags, &scm);
522 if (size >= 0)
523 scm_recv(sock, msg, &scm, flags);
525 return size;
530 * Sockets are not seekable.
533 static loff_t sock_lseek(struct file *file, loff_t offset, int whence)
535 return -ESPIPE;
539 * Read data from a socket. ubuf is a user mode pointer. We make sure the user
540 * area ubuf...ubuf+size-1 is writable before asking the protocol.
543 static ssize_t sock_read(struct file *file, char *ubuf,
544 size_t size, loff_t *ppos)
546 struct socket *sock;
547 struct iovec iov;
548 struct msghdr msg;
549 int flags;
551 if (ppos != &file->f_pos)
552 return -ESPIPE;
553 if (size==0) /* Match SYS5 behaviour */
554 return 0;
556 sock = socki_lookup(file->f_dentry->d_inode);
558 msg.msg_name=NULL;
559 msg.msg_namelen=0;
560 msg.msg_iov=&iov;
561 msg.msg_iovlen=1;
562 msg.msg_control=NULL;
563 msg.msg_controllen=0;
564 iov.iov_base=ubuf;
565 iov.iov_len=size;
566 flags = !(file->f_flags & O_NONBLOCK) ? 0 : MSG_DONTWAIT;
568 return sock_recvmsg(sock, &msg, size, flags);
573 * Write data to a socket. We verify that the user area ubuf..ubuf+size-1
574 * is readable by the user process.
577 static ssize_t sock_write(struct file *file, const char *ubuf,
578 size_t size, loff_t *ppos)
580 struct socket *sock;
581 struct msghdr msg;
582 struct iovec iov;
584 if (ppos != &file->f_pos)
585 return -ESPIPE;
586 if(size==0) /* Match SYS5 behaviour */
587 return 0;
589 sock = socki_lookup(file->f_dentry->d_inode);
591 msg.msg_name=NULL;
592 msg.msg_namelen=0;
593 msg.msg_iov=&iov;
594 msg.msg_iovlen=1;
595 msg.msg_control=NULL;
596 msg.msg_controllen=0;
597 msg.msg_flags=!(file->f_flags & O_NONBLOCK) ? 0 : MSG_DONTWAIT;
598 if (sock->type == SOCK_SEQPACKET)
599 msg.msg_flags |= MSG_EOR;
600 iov.iov_base=(void *)ubuf;
601 iov.iov_len=size;
603 return sock_sendmsg(sock, &msg, size);
606 int sock_readv_writev(int type, struct inode * inode, struct file * file,
607 const struct iovec * iov, long count, long size)
609 struct msghdr msg;
610 struct socket *sock;
612 sock = socki_lookup(inode);
614 msg.msg_name = NULL;
615 msg.msg_namelen = 0;
616 msg.msg_control = NULL;
617 msg.msg_controllen = 0;
618 msg.msg_iov = (struct iovec *) iov;
619 msg.msg_iovlen = count;
620 msg.msg_flags = (file->f_flags & O_NONBLOCK) ? MSG_DONTWAIT : 0;
622 /* read() does a VERIFY_WRITE */
623 if (type == VERIFY_WRITE)
624 return sock_recvmsg(sock, &msg, size, msg.msg_flags);
626 if (sock->type == SOCK_SEQPACKET)
627 msg.msg_flags |= MSG_EOR;
629 return sock_sendmsg(sock, &msg, size);
632 static ssize_t sock_readv(struct file *file, const struct iovec *vector,
633 unsigned long count, loff_t *ppos)
635 size_t tot_len = 0;
636 int i;
637 for (i = 0 ; i < count ; i++)
638 tot_len += vector[i].iov_len;
639 return sock_readv_writev(VERIFY_WRITE, file->f_dentry->d_inode,
640 file, vector, count, tot_len);
643 static ssize_t sock_writev(struct file *file, const struct iovec *vector,
644 unsigned long count, loff_t *ppos)
646 size_t tot_len = 0;
647 int i;
648 for (i = 0 ; i < count ; i++)
649 tot_len += vector[i].iov_len;
650 return sock_readv_writev(VERIFY_READ, file->f_dentry->d_inode,
651 file, vector, count, tot_len);
655 * With an ioctl arg may well be a user mode pointer, but we don't know what to do
656 * with it - that's up to the protocol still.
659 int sock_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
660 unsigned long arg)
662 struct socket *sock;
663 int err;
665 unlock_kernel();
666 sock = socki_lookup(inode);
667 err = sock->ops->ioctl(sock, cmd, arg);
668 lock_kernel();
670 return err;
674 /* No kernel lock held - perfect */
675 static unsigned int sock_poll(struct file *file, poll_table * wait)
677 struct socket *sock;
680 * We can't return errors to poll, so it's either yes or no.
682 sock = socki_lookup(file->f_dentry->d_inode);
683 return sock->ops->poll(file, sock, wait);
686 static int sock_mmap(struct file * file, struct vm_area_struct * vma)
688 struct socket *sock = socki_lookup(file->f_dentry->d_inode);
690 return sock->ops->mmap(file, sock, vma);
693 int sock_close(struct inode *inode, struct file *filp)
696 * It was possible the inode is NULL we were
697 * closing an unfinished socket.
700 if (!inode)
702 printk(KERN_DEBUG "sock_close: NULL inode\n");
703 return 0;
705 sock_fasync(-1, filp, 0);
706 sock_release(socki_lookup(inode));
707 return 0;
711 * Update the socket async list
713 * Fasync_list locking strategy.
715 * 1. fasync_list is modified only under process context socket lock
716 * i.e. under semaphore.
717 * 2. fasync_list is used under read_lock(&sk->callback_lock)
718 * or under socket lock.
719 * 3. fasync_list can be used from softirq context, so that
720 * modification under socket lock have to be enhanced with
721 * write_lock_bh(&sk->callback_lock).
722 * --ANK (990710)
725 static int sock_fasync(int fd, struct file *filp, int on)
727 struct fasync_struct *fa, *fna=NULL, **prev;
728 struct socket *sock;
729 struct sock *sk;
731 if (on)
733 fna=(struct fasync_struct *)kmalloc(sizeof(struct fasync_struct), GFP_KERNEL);
734 if(fna==NULL)
735 return -ENOMEM;
739 sock = socki_lookup(filp->f_dentry->d_inode);
741 if ((sk=sock->sk) == NULL)
742 return -EINVAL;
744 lock_sock(sk);
746 prev=&(sock->fasync_list);
748 for (fa=*prev; fa!=NULL; prev=&fa->fa_next,fa=*prev)
749 if (fa->fa_file==filp)
750 break;
752 if(on)
754 if(fa!=NULL)
756 write_lock_bh(&sk->callback_lock);
757 fa->fa_fd=fd;
758 write_unlock_bh(&sk->callback_lock);
760 kfree(fna);
761 goto out;
763 fna->fa_file=filp;
764 fna->fa_fd=fd;
765 fna->magic=FASYNC_MAGIC;
766 fna->fa_next=sock->fasync_list;
767 write_lock_bh(&sk->callback_lock);
768 sock->fasync_list=fna;
769 write_unlock_bh(&sk->callback_lock);
771 else
773 if (fa!=NULL)
775 write_lock_bh(&sk->callback_lock);
776 *prev=fa->fa_next;
777 write_unlock_bh(&sk->callback_lock);
778 kfree(fa);
782 out:
783 release_sock(sock->sk);
784 return 0;
787 /* This function may be called only under socket lock or callback_lock */
789 int sock_wake_async(struct socket *sock, int how, int band)
791 if (!sock || !sock->fasync_list)
792 return -1;
793 switch (how)
795 case 1:
797 if (test_bit(SOCK_ASYNC_WAITDATA, &sock->flags))
798 break;
799 goto call_kill;
800 case 2:
801 if (!test_and_clear_bit(SOCK_ASYNC_NOSPACE, &sock->flags))
802 break;
803 /* fall through */
804 case 0:
805 call_kill:
806 __kill_fasync(sock->fasync_list, SIGIO, band);
807 break;
808 case 3:
809 __kill_fasync(sock->fasync_list, SIGURG, band);
811 return 0;
815 int sock_create(int family, int type, int protocol, struct socket **res)
817 int i;
818 struct socket *sock;
821 * Check protocol is in range
823 if(family<0 || family>=NPROTO)
824 return -EINVAL;
826 /* Compatibility.
828 This uglymoron is moved from INET layer to here to avoid
829 deadlock in module load.
831 if (family == PF_INET && type == SOCK_PACKET) {
832 static int warned;
833 if (!warned) {
834 warned = 1;
835 printk(KERN_INFO "%s uses obsolete (PF_INET,SOCK_PACKET)\n", current->comm);
837 family = PF_PACKET;
840 #if defined(CONFIG_KMOD) && defined(CONFIG_NET)
841 /* Attempt to load a protocol module if the find failed.
843 * 12/09/1996 Marcin: But! this makes REALLY only sense, if the user
844 * requested real, full-featured networking support upon configuration.
845 * Otherwise module support will break!
847 if (net_families[family]==NULL)
849 char module_name[30];
850 sprintf(module_name,"net-pf-%d",family);
851 request_module(module_name);
853 #endif
855 net_family_read_lock();
856 if (net_families[family] == NULL) {
857 i = -EINVAL;
858 goto out;
862 * Allocate the socket and allow the family to set things up. if
863 * the protocol is 0, the family is instructed to select an appropriate
864 * default.
867 if (!(sock = sock_alloc()))
869 printk(KERN_WARNING "socket: no more sockets\n");
870 i = -ENFILE; /* Not exactly a match, but its the
871 closest posix thing */
872 goto out;
875 sock->type = type;
877 if ((i = net_families[family]->create(sock, protocol)) < 0)
879 sock_release(sock);
880 goto out;
883 *res = sock;
885 out:
886 net_family_read_unlock();
887 return i;
890 asmlinkage long sys_socket(int family, int type, int protocol)
892 int retval;
893 struct socket *sock;
895 retval = sock_create(family, type, protocol, &sock);
896 if (retval < 0)
897 goto out;
899 retval = sock_map_fd(sock);
900 if (retval < 0)
901 goto out_release;
903 out:
904 /* It may be already another descriptor 8) Not kernel problem. */
905 return retval;
907 out_release:
908 sock_release(sock);
909 return retval;
913 * Create a pair of connected sockets.
916 asmlinkage long sys_socketpair(int family, int type, int protocol, int usockvec[2])
918 struct socket *sock1, *sock2;
919 int fd1, fd2, err;
922 * Obtain the first socket and check if the underlying protocol
923 * supports the socketpair call.
926 err = sock_create(family, type, protocol, &sock1);
927 if (err < 0)
928 goto out;
930 err = sock_create(family, type, protocol, &sock2);
931 if (err < 0)
932 goto out_release_1;
934 err = sock1->ops->socketpair(sock1, sock2);
935 if (err < 0)
936 goto out_release_both;
938 fd1 = fd2 = -1;
940 err = sock_map_fd(sock1);
941 if (err < 0)
942 goto out_release_both;
943 fd1 = err;
945 err = sock_map_fd(sock2);
946 if (err < 0)
947 goto out_close_1;
948 fd2 = err;
950 /* fd1 and fd2 may be already another descriptors.
951 * Not kernel problem.
954 err = put_user(fd1, &usockvec[0]);
955 if (!err)
956 err = put_user(fd2, &usockvec[1]);
957 if (!err)
958 return 0;
960 sys_close(fd2);
961 sys_close(fd1);
962 return err;
964 out_close_1:
965 sock_release(sock2);
966 sys_close(fd1);
967 return err;
969 out_release_both:
970 sock_release(sock2);
971 out_release_1:
972 sock_release(sock1);
973 out:
974 return err;
979 * Bind a name to a socket. Nothing much to do here since it's
980 * the protocol's responsibility to handle the local address.
982 * We move the socket address to kernel space before we call
983 * the protocol layer (having also checked the address is ok).
986 asmlinkage long sys_bind(int fd, struct sockaddr *umyaddr, int addrlen)
988 struct socket *sock;
989 char address[MAX_SOCK_ADDR];
990 int err;
992 if((sock = sockfd_lookup(fd,&err))!=NULL)
994 if((err=move_addr_to_kernel(umyaddr,addrlen,address))>=0)
995 err = sock->ops->bind(sock, (struct sockaddr *)address, addrlen);
996 sockfd_put(sock);
998 return err;
1003 * Perform a listen. Basically, we allow the protocol to do anything
1004 * necessary for a listen, and if that works, we mark the socket as
1005 * ready for listening.
1008 asmlinkage long sys_listen(int fd, int backlog)
1010 struct socket *sock;
1011 int err;
1013 if ((sock = sockfd_lookup(fd, &err)) != NULL) {
1014 if ((unsigned) backlog > SOMAXCONN)
1015 backlog = SOMAXCONN;
1016 err=sock->ops->listen(sock, backlog);
1017 sockfd_put(sock);
1019 return err;
1024 * For accept, we attempt to create a new socket, set up the link
1025 * with the client, wake up the client, then return the new
1026 * connected fd. We collect the address of the connector in kernel
1027 * space and move it to user at the very end. This is unclean because
1028 * we open the socket then return an error.
1030 * 1003.1g adds the ability to recvmsg() to query connection pending
1031 * status to recvmsg. We need to add that support in a way thats
1032 * clean when we restucture accept also.
1035 asmlinkage long sys_accept(int fd, struct sockaddr *upeer_sockaddr, int *upeer_addrlen)
1037 struct socket *sock, *newsock;
1038 int err, len;
1039 char address[MAX_SOCK_ADDR];
1041 sock = sockfd_lookup(fd, &err);
1042 if (!sock)
1043 goto out;
1045 err = -EMFILE;
1046 if (!(newsock = sock_alloc()))
1047 goto out_put;
1049 newsock->type = sock->type;
1050 newsock->ops = sock->ops;
1052 err = sock->ops->accept(sock, newsock, sock->file->f_flags);
1053 if (err < 0)
1054 goto out_release;
1056 if (upeer_sockaddr) {
1057 if(newsock->ops->getname(newsock, (struct sockaddr *)address, &len, 2)<0) {
1058 err = -ECONNABORTED;
1059 goto out_release;
1061 err = move_addr_to_user(address, len, upeer_sockaddr, upeer_addrlen);
1062 if (err < 0)
1063 goto out_release;
1066 /* File flags are not inherited via accept() unlike another OSes. */
1068 if ((err = sock_map_fd(newsock)) < 0)
1069 goto out_release;
1071 out_put:
1072 sockfd_put(sock);
1073 out:
1074 return err;
1076 out_release:
1077 sock_release(newsock);
1078 goto out_put;
1083 * Attempt to connect to a socket with the server address. The address
1084 * is in user space so we verify it is OK and move it to kernel space.
1086 * For 1003.1g we need to add clean support for a bind to AF_UNSPEC to
1087 * break bindings
1089 * NOTE: 1003.1g draft 6.3 is broken with respect to AX.25/NetROM and
1090 * other SEQPACKET protocols that take time to connect() as it doesn't
1091 * include the -EINPROGRESS status for such sockets.
1094 asmlinkage long sys_connect(int fd, struct sockaddr *uservaddr, int addrlen)
1096 struct socket *sock;
1097 char address[MAX_SOCK_ADDR];
1098 int err;
1100 sock = sockfd_lookup(fd, &err);
1101 if (!sock)
1102 goto out;
1103 err = move_addr_to_kernel(uservaddr, addrlen, address);
1104 if (err < 0)
1105 goto out_put;
1106 err = sock->ops->connect(sock, (struct sockaddr *) address, addrlen,
1107 sock->file->f_flags);
1108 out_put:
1109 sockfd_put(sock);
1110 out:
1111 return err;
1115 * Get the local address ('name') of a socket object. Move the obtained
1116 * name to user space.
1119 asmlinkage long sys_getsockname(int fd, struct sockaddr *usockaddr, int *usockaddr_len)
1121 struct socket *sock;
1122 char address[MAX_SOCK_ADDR];
1123 int len, err;
1125 sock = sockfd_lookup(fd, &err);
1126 if (!sock)
1127 goto out;
1128 err = sock->ops->getname(sock, (struct sockaddr *)address, &len, 0);
1129 if (err)
1130 goto out_put;
1131 err = move_addr_to_user(address, len, usockaddr, usockaddr_len);
1133 out_put:
1134 sockfd_put(sock);
1135 out:
1136 return err;
1140 * Get the remote address ('name') of a socket object. Move the obtained
1141 * name to user space.
1144 asmlinkage long sys_getpeername(int fd, struct sockaddr *usockaddr, int *usockaddr_len)
1146 struct socket *sock;
1147 char address[MAX_SOCK_ADDR];
1148 int len, err;
1150 if ((sock = sockfd_lookup(fd, &err))!=NULL)
1152 err = sock->ops->getname(sock, (struct sockaddr *)address, &len, 1);
1153 if (!err)
1154 err=move_addr_to_user(address,len, usockaddr, usockaddr_len);
1155 sockfd_put(sock);
1157 return err;
1161 * Send a datagram to a given address. We move the address into kernel
1162 * space and check the user space data area is readable before invoking
1163 * the protocol.
1166 asmlinkage long sys_sendto(int fd, void * buff, size_t len, unsigned flags,
1167 struct sockaddr *addr, int addr_len)
1169 struct socket *sock;
1170 char address[MAX_SOCK_ADDR];
1171 int err;
1172 struct msghdr msg;
1173 struct iovec iov;
1175 sock = sockfd_lookup(fd, &err);
1176 if (!sock)
1177 goto out;
1178 iov.iov_base=buff;
1179 iov.iov_len=len;
1180 msg.msg_name=NULL;
1181 msg.msg_iov=&iov;
1182 msg.msg_iovlen=1;
1183 msg.msg_control=NULL;
1184 msg.msg_controllen=0;
1185 msg.msg_namelen=addr_len;
1186 if(addr)
1188 err = move_addr_to_kernel(addr, addr_len, address);
1189 if (err < 0)
1190 goto out_put;
1191 msg.msg_name=address;
1193 if (sock->file->f_flags & O_NONBLOCK)
1194 flags |= MSG_DONTWAIT;
1195 msg.msg_flags = flags;
1196 err = sock_sendmsg(sock, &msg, len);
1198 out_put:
1199 sockfd_put(sock);
1200 out:
1201 return err;
1205 * Send a datagram down a socket.
1208 asmlinkage long sys_send(int fd, void * buff, size_t len, unsigned flags)
1210 return sys_sendto(fd, buff, len, flags, NULL, 0);
1214 * Receive a frame from the socket and optionally record the address of the
1215 * sender. We verify the buffers are writable and if needed move the
1216 * sender address from kernel to user space.
1219 asmlinkage long sys_recvfrom(int fd, void * ubuf, size_t size, unsigned flags,
1220 struct sockaddr *addr, int *addr_len)
1222 struct socket *sock;
1223 struct iovec iov;
1224 struct msghdr msg;
1225 char address[MAX_SOCK_ADDR];
1226 int err,err2;
1228 sock = sockfd_lookup(fd, &err);
1229 if (!sock)
1230 goto out;
1232 msg.msg_control=NULL;
1233 msg.msg_controllen=0;
1234 msg.msg_iovlen=1;
1235 msg.msg_iov=&iov;
1236 iov.iov_len=size;
1237 iov.iov_base=ubuf;
1238 msg.msg_name=address;
1239 msg.msg_namelen=MAX_SOCK_ADDR;
1240 if (sock->file->f_flags & O_NONBLOCK)
1241 flags |= MSG_DONTWAIT;
1242 err=sock_recvmsg(sock, &msg, size, flags);
1244 if(err >= 0 && addr != NULL && msg.msg_namelen)
1246 err2=move_addr_to_user(address, msg.msg_namelen, addr, addr_len);
1247 if(err2<0)
1248 err=err2;
1250 sockfd_put(sock);
1251 out:
1252 return err;
1256 * Receive a datagram from a socket.
1259 asmlinkage long sys_recv(int fd, void * ubuf, size_t size, unsigned flags)
1261 return sys_recvfrom(fd, ubuf, size, flags, NULL, NULL);
1265 * Set a socket option. Because we don't know the option lengths we have
1266 * to pass the user mode parameter for the protocols to sort out.
1269 asmlinkage long sys_setsockopt(int fd, int level, int optname, char *optval, int optlen)
1271 int err;
1272 struct socket *sock;
1274 if ((sock = sockfd_lookup(fd, &err))!=NULL)
1276 if (level == SOL_SOCKET)
1277 err=sock_setsockopt(sock,level,optname,optval,optlen);
1278 else
1279 err=sock->ops->setsockopt(sock, level, optname, optval, optlen);
1280 sockfd_put(sock);
1282 return err;
1286 * Get a socket option. Because we don't know the option lengths we have
1287 * to pass a user mode parameter for the protocols to sort out.
1290 asmlinkage long sys_getsockopt(int fd, int level, int optname, char *optval, int *optlen)
1292 int err;
1293 struct socket *sock;
1295 if ((sock = sockfd_lookup(fd, &err))!=NULL)
1297 if (level == SOL_SOCKET)
1298 err=sock_getsockopt(sock,level,optname,optval,optlen);
1299 else
1300 err=sock->ops->getsockopt(sock, level, optname, optval, optlen);
1301 sockfd_put(sock);
1303 return err;
1308 * Shutdown a socket.
1311 asmlinkage long sys_shutdown(int fd, int how)
1313 int err;
1314 struct socket *sock;
1316 if ((sock = sockfd_lookup(fd, &err))!=NULL)
1318 err=sock->ops->shutdown(sock, how);
1319 sockfd_put(sock);
1321 return err;
1325 * BSD sendmsg interface
1328 asmlinkage long sys_sendmsg(int fd, struct msghdr *msg, unsigned flags)
1330 struct socket *sock;
1331 char address[MAX_SOCK_ADDR];
1332 struct iovec iovstack[UIO_FASTIOV], *iov = iovstack;
1333 unsigned char ctl[sizeof(struct cmsghdr) + 20]; /* 20 is size of ipv6_pktinfo */
1334 unsigned char *ctl_buf = ctl;
1335 struct msghdr msg_sys;
1336 int err, ctl_len, iov_size, total_len;
1338 err = -EFAULT;
1339 if (copy_from_user(&msg_sys,msg,sizeof(struct msghdr)))
1340 goto out;
1342 sock = sockfd_lookup(fd, &err);
1343 if (!sock)
1344 goto out;
1346 /* do not move before msg_sys is valid */
1347 err = -EINVAL;
1348 if (msg_sys.msg_iovlen > UIO_MAXIOV)
1349 goto out_put;
1351 /* Check whether to allocate the iovec area*/
1352 err = -ENOMEM;
1353 iov_size = msg_sys.msg_iovlen * sizeof(struct iovec);
1354 if (msg_sys.msg_iovlen > UIO_FASTIOV) {
1355 iov = sock_kmalloc(sock->sk, iov_size, GFP_KERNEL);
1356 if (!iov)
1357 goto out_put;
1360 /* This will also move the address data into kernel space */
1361 err = verify_iovec(&msg_sys, iov, address, VERIFY_READ);
1362 if (err < 0)
1363 goto out_freeiov;
1364 total_len = err;
1366 err = -ENOBUFS;
1368 if (msg_sys.msg_controllen > INT_MAX)
1369 goto out_freeiov;
1370 ctl_len = msg_sys.msg_controllen;
1371 if (ctl_len)
1373 if (ctl_len > sizeof(ctl))
1375 err = -ENOBUFS;
1376 ctl_buf = sock_kmalloc(sock->sk, ctl_len, GFP_KERNEL);
1377 if (ctl_buf == NULL)
1378 goto out_freeiov;
1380 err = -EFAULT;
1381 if (copy_from_user(ctl_buf, msg_sys.msg_control, ctl_len))
1382 goto out_freectl;
1383 msg_sys.msg_control = ctl_buf;
1385 msg_sys.msg_flags = flags;
1387 if (sock->file->f_flags & O_NONBLOCK)
1388 msg_sys.msg_flags |= MSG_DONTWAIT;
1389 err = sock_sendmsg(sock, &msg_sys, total_len);
1391 out_freectl:
1392 if (ctl_buf != ctl)
1393 sock_kfree_s(sock->sk, ctl_buf, ctl_len);
1394 out_freeiov:
1395 if (iov != iovstack)
1396 sock_kfree_s(sock->sk, iov, iov_size);
1397 out_put:
1398 sockfd_put(sock);
1399 out:
1400 return err;
1404 * BSD recvmsg interface
1407 asmlinkage long sys_recvmsg(int fd, struct msghdr *msg, unsigned int flags)
1409 struct socket *sock;
1410 struct iovec iovstack[UIO_FASTIOV];
1411 struct iovec *iov=iovstack;
1412 struct msghdr msg_sys;
1413 unsigned long cmsg_ptr;
1414 int err, iov_size, total_len, len;
1416 /* kernel mode address */
1417 char addr[MAX_SOCK_ADDR];
1419 /* user mode address pointers */
1420 struct sockaddr *uaddr;
1421 int *uaddr_len;
1423 err=-EFAULT;
1424 if (copy_from_user(&msg_sys,msg,sizeof(struct msghdr)))
1425 goto out;
1427 sock = sockfd_lookup(fd, &err);
1428 if (!sock)
1429 goto out;
1431 err = -EINVAL;
1432 if (msg_sys.msg_iovlen > UIO_MAXIOV)
1433 goto out_put;
1435 /* Check whether to allocate the iovec area*/
1436 err = -ENOMEM;
1437 iov_size = msg_sys.msg_iovlen * sizeof(struct iovec);
1438 if (msg_sys.msg_iovlen > UIO_FASTIOV) {
1439 iov = sock_kmalloc(sock->sk, iov_size, GFP_KERNEL);
1440 if (!iov)
1441 goto out_put;
1445 * Save the user-mode address (verify_iovec will change the
1446 * kernel msghdr to use the kernel address space)
1449 uaddr = msg_sys.msg_name;
1450 uaddr_len = &msg->msg_namelen;
1451 err = verify_iovec(&msg_sys, iov, addr, VERIFY_WRITE);
1452 if (err < 0)
1453 goto out_freeiov;
1454 total_len=err;
1456 cmsg_ptr = (unsigned long)msg_sys.msg_control;
1457 msg_sys.msg_flags = 0;
1459 if (sock->file->f_flags & O_NONBLOCK)
1460 flags |= MSG_DONTWAIT;
1461 err = sock_recvmsg(sock, &msg_sys, total_len, flags);
1462 if (err < 0)
1463 goto out_freeiov;
1464 len = err;
1466 if (uaddr != NULL && msg_sys.msg_namelen) {
1467 err = move_addr_to_user(addr, msg_sys.msg_namelen, uaddr, uaddr_len);
1468 if (err < 0)
1469 goto out_freeiov;
1471 err = __put_user(msg_sys.msg_flags, &msg->msg_flags);
1472 if (err)
1473 goto out_freeiov;
1474 err = __put_user((unsigned long)msg_sys.msg_control-cmsg_ptr,
1475 &msg->msg_controllen);
1476 if (err)
1477 goto out_freeiov;
1478 err = len;
1480 out_freeiov:
1481 if (iov != iovstack)
1482 sock_kfree_s(sock->sk, iov, iov_size);
1483 out_put:
1484 sockfd_put(sock);
1485 out:
1486 return err;
1491 * Perform a file control on a socket file descriptor.
1493 * Doesn't aquire a fd lock, because no network fcntl
1494 * function sleeps currently.
1497 int sock_fcntl(struct file *filp, unsigned int cmd, unsigned long arg)
1499 struct socket *sock;
1501 sock = socki_lookup (filp->f_dentry->d_inode);
1502 if (sock && sock->ops)
1503 return sock_no_fcntl(sock, cmd, arg);
1504 return(-EINVAL);
1507 /* Argument list sizes for sys_socketcall */
1508 #define AL(x) ((x) * sizeof(unsigned long))
1509 static unsigned char nargs[18]={AL(0),AL(3),AL(3),AL(3),AL(2),AL(3),
1510 AL(3),AL(3),AL(4),AL(4),AL(4),AL(6),
1511 AL(6),AL(2),AL(5),AL(5),AL(3),AL(3)};
1512 #undef AL
1515 * System call vectors.
1517 * Argument checking cleaned up. Saved 20% in size.
1518 * This function doesn't need to set the kernel lock because
1519 * it is set by the callees.
1522 asmlinkage long sys_socketcall(int call, unsigned long *args)
1524 unsigned long a[6];
1525 unsigned long a0,a1;
1526 int err;
1528 if(call<1||call>SYS_RECVMSG)
1529 return -EINVAL;
1531 /* copy_from_user should be SMP safe. */
1532 if (copy_from_user(a, args, nargs[call]))
1533 return -EFAULT;
1535 a0=a[0];
1536 a1=a[1];
1538 switch(call)
1540 case SYS_SOCKET:
1541 err = sys_socket(a0,a1,a[2]);
1542 break;
1543 case SYS_BIND:
1544 err = sys_bind(a0,(struct sockaddr *)a1, a[2]);
1545 break;
1546 case SYS_CONNECT:
1547 err = sys_connect(a0, (struct sockaddr *)a1, a[2]);
1548 break;
1549 case SYS_LISTEN:
1550 err = sys_listen(a0,a1);
1551 break;
1552 case SYS_ACCEPT:
1553 err = sys_accept(a0,(struct sockaddr *)a1, (int *)a[2]);
1554 break;
1555 case SYS_GETSOCKNAME:
1556 err = sys_getsockname(a0,(struct sockaddr *)a1, (int *)a[2]);
1557 break;
1558 case SYS_GETPEERNAME:
1559 err = sys_getpeername(a0, (struct sockaddr *)a1, (int *)a[2]);
1560 break;
1561 case SYS_SOCKETPAIR:
1562 err = sys_socketpair(a0,a1, a[2], (int *)a[3]);
1563 break;
1564 case SYS_SEND:
1565 err = sys_send(a0, (void *)a1, a[2], a[3]);
1566 break;
1567 case SYS_SENDTO:
1568 err = sys_sendto(a0,(void *)a1, a[2], a[3],
1569 (struct sockaddr *)a[4], a[5]);
1570 break;
1571 case SYS_RECV:
1572 err = sys_recv(a0, (void *)a1, a[2], a[3]);
1573 break;
1574 case SYS_RECVFROM:
1575 err = sys_recvfrom(a0, (void *)a1, a[2], a[3],
1576 (struct sockaddr *)a[4], (int *)a[5]);
1577 break;
1578 case SYS_SHUTDOWN:
1579 err = sys_shutdown(a0,a1);
1580 break;
1581 case SYS_SETSOCKOPT:
1582 err = sys_setsockopt(a0, a1, a[2], (char *)a[3], a[4]);
1583 break;
1584 case SYS_GETSOCKOPT:
1585 err = sys_getsockopt(a0, a1, a[2], (char *)a[3], (int *)a[4]);
1586 break;
1587 case SYS_SENDMSG:
1588 err = sys_sendmsg(a0, (struct msghdr *) a1, a[2]);
1589 break;
1590 case SYS_RECVMSG:
1591 err = sys_recvmsg(a0, (struct msghdr *) a1, a[2]);
1592 break;
1593 default:
1594 err = -EINVAL;
1595 break;
1597 return err;
1601 * This function is called by a protocol handler that wants to
1602 * advertise its address family, and have it linked into the
1603 * SOCKET module.
1606 int sock_register(struct net_proto_family *ops)
1608 int err;
1610 if (ops->family >= NPROTO) {
1611 printk(KERN_CRIT "protocol %d >= NPROTO(%d)\n", ops->family, NPROTO);
1612 return -ENOBUFS;
1614 net_family_write_lock();
1615 err = -EEXIST;
1616 if (net_families[ops->family] == NULL) {
1617 net_families[ops->family]=ops;
1618 err = 0;
1620 net_family_write_unlock();
1621 return err;
1625 * This function is called by a protocol handler that wants to
1626 * remove its address family, and have it unlinked from the
1627 * SOCKET module.
1630 int sock_unregister(int family)
1632 if (family < 0 || family >= NPROTO)
1633 return -1;
1635 net_family_write_lock();
1636 net_families[family]=NULL;
1637 net_family_write_unlock();
1638 return 0;
1641 void __init proto_init(void)
1643 extern struct net_proto protocols[]; /* Network protocols */
1644 struct net_proto *pro;
1646 /* Kick all configured protocols. */
1647 pro = protocols;
1648 while (pro->name != NULL)
1650 (*pro->init_func)(pro);
1651 pro++;
1653 /* We're all done... */
1656 extern void sk_init(void);
1658 #ifdef CONFIG_BRIDGE
1659 extern int br_init(void);
1660 #endif
1662 #ifdef CONFIG_WAN_ROUTER
1663 extern void wanrouter_init(void);
1664 #endif
1666 void __init sock_init(void)
1668 int i;
1670 printk(KERN_INFO "Linux NET4.0 for Linux 2.3\n");
1671 printk(KERN_INFO "Based upon Swansea University Computer Society NET3.039\n");
1674 * Initialize all address (protocol) families.
1677 for (i = 0; i < NPROTO; i++)
1678 net_families[i] = NULL;
1681 * Initialize sock SLAB cache.
1684 sk_init();
1686 #ifdef SLAB_SKB
1688 * Initialize skbuff SLAB cache
1690 skb_init();
1691 #endif
1694 * Ethernet bridge layer.
1697 #ifdef CONFIG_BRIDGE
1698 br_init();
1699 #endif
1702 * Wan router layer.
1705 #ifdef CONFIG_WAN_ROUTER
1706 wanrouter_init();
1707 #endif
1710 * Initialize the protocols module.
1713 proto_init();
1716 * The netlink device handler may be needed early.
1719 #ifdef CONFIG_RTNETLINK
1720 rtnetlink_init();
1721 #endif
1722 #ifdef CONFIG_NETLINK_DEV
1723 init_netlink();
1724 #endif
1725 #ifdef CONFIG_NETFILTER
1726 netfilter_init();
1727 #endif
1728 register_filesystem(&sock_fs_type);
1729 sock_mnt = kern_mount(&sock_fs_type);
1732 int socket_get_info(char *buffer, char **start, off_t offset, int length)
1734 int len, cpu;
1735 int counter = 0;
1737 for (cpu=0; cpu<smp_num_cpus; cpu++)
1738 counter += sockets_in_use[cpu_logical_map(cpu)].counter;
1740 /* It can be negative, by the way. 8) */
1741 if (counter < 0)
1742 counter = 0;
1744 len = sprintf(buffer, "sockets: used %d\n", counter);
1745 if (offset >= len)
1747 *start = buffer;
1748 return 0;
1750 *start = buffer + offset;
1751 len -= offset;
1752 if (len > length)
1753 len = length;
1754 if (len < 0)
1755 len = 0;
1756 return len;