2 * NET4: Implementation of BSD Unix domain sockets.
4 * Authors: Alan Cox, <alan.cox@linux.org>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
11 * Version: $Id: af_unix.c,v 1.133 2002/02/08 03:57:19 davem Exp $
14 * Linus Torvalds : Assorted bug cures.
15 * Niibe Yutaka : async I/O support.
16 * Carsten Paeth : PF_UNIX check, address fixes.
17 * Alan Cox : Limit size of allocated blocks.
18 * Alan Cox : Fixed the stupid socketpair bug.
19 * Alan Cox : BSD compatibility fine tuning.
20 * Alan Cox : Fixed a bug in connect when interrupted.
21 * Alan Cox : Sorted out a proper draft version of
22 * file descriptor passing hacked up from
24 * Marty Leisner : Fixes to fd passing
25 * Nick Nevin : recvmsg bugfix.
26 * Alan Cox : Started proper garbage collector
27 * Heiko EiBfeldt : Missing verify_area check
28 * Alan Cox : Started POSIXisms
29 * Andreas Schwab : Replace inode by dentry for proper
31 * Kirk Petersen : Made this a module
32 * Christoph Rohland : Elegant non-blocking accept/connect algorithm.
34 * Alexey Kuznetosv : Repaired (I hope) bugs introduces
35 * by above two patches.
36 * Andrea Arcangeli : If possible we block in connect(2)
37 * if the max backlog of the listen socket
38 * is been reached. This won't break
39 * old apps and it will avoid huge amount
40 * of socks hashed (this for unix_gc()
41 * performances reasons).
42 * Security fix that limits the max
43 * number of socks to 2*max_files and
44 * the number of skb queueable in the
46 * Artur Skawina : Hash function optimizations
47 * Alexey Kuznetsov : Full scale SMP. Lot of bugs are introduced 8)
48 * Malcolm Beattie : Set peercred for socketpair
49 * Michal Ostrowski : Module initialization cleanup.
50 * Arnaldo C. Melo : Remove MOD_{INC,DEC}_USE_COUNT,
51 * the core infrastructure is doing that
52 * for all net proto families now (2.5.69+)
55 * Known differences from reference BSD that was tested:
58 * ECONNREFUSED is not returned from one end of a connected() socket to the
59 * other the moment one end closes.
60 * fstat() doesn't return st_dev=0, and give the blksize as high water mark
61 * and a fake inode identifier (nor the BSD first socket fstat twice bug).
63 * accept() returns a path name even if the connecting socket has closed
64 * in the meantime (BSD loses the path and gives up).
65 * accept() returns 0 length path for an unbound connector. BSD returns 16
66 * and a null first byte in the path (but not for gethost/peername - BSD bug ??)
67 * socketpair(...SOCK_RAW..) doesn't panic the kernel.
68 * BSD af_unix apparently has connect forgetting to block properly.
69 * (need to check this with the POSIX spec in detail)
71 * Differences from 2.0.0-11-... (ANK)
72 * Bug fixes and improvements.
73 * - client shutdown killed server socket.
74 * - removed all useless cli/sti pairs.
76 * Semantic changes/extensions.
77 * - generic control message passing.
78 * - SCM_CREDENTIALS control message.
79 * - "Abstract" (not FS based) socket bindings.
80 * Abstract names are sequences of bytes (not zero terminated)
81 * started by 0, so that this name space does not intersect
85 #include <linux/module.h>
86 #include <linux/config.h>
87 #include <linux/kernel.h>
88 #include <linux/major.h>
89 #include <linux/signal.h>
90 #include <linux/sched.h>
91 #include <linux/errno.h>
92 #include <linux/string.h>
93 #include <linux/stat.h>
94 #include <linux/dcache.h>
95 #include <linux/namei.h>
96 #include <linux/socket.h>
98 #include <linux/fcntl.h>
99 #include <linux/termios.h>
100 #include <linux/sockios.h>
101 #include <linux/net.h>
102 #include <linux/in.h>
103 #include <linux/fs.h>
104 #include <linux/slab.h>
105 #include <asm/uaccess.h>
106 #include <linux/skbuff.h>
107 #include <linux/netdevice.h>
108 #include <net/sock.h>
109 #include <linux/tcp.h>
110 #include <net/af_unix.h>
111 #include <linux/proc_fs.h>
112 #include <linux/seq_file.h>
114 #include <linux/init.h>
115 #include <linux/poll.h>
116 #include <linux/smp_lock.h>
117 #include <linux/rtnetlink.h>
118 #include <linux/mount.h>
119 #include <net/checksum.h>
120 #include <linux/security.h>
122 int sysctl_unix_max_dgram_qlen = 10;
124 kmem_cache_t *unix_sk_cachep;
126 struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1];
127 rwlock_t unix_table_lock = RW_LOCK_UNLOCKED;
128 static atomic_t unix_nr_socks = ATOMIC_INIT(0);
130 #define unix_sockets_unbound (&unix_socket_table[UNIX_HASH_SIZE])
132 #define UNIX_ABSTRACT(sk) (unix_sk(sk)->addr->hash != UNIX_HASH_SIZE)
135 * SMP locking strategy:
136 * hash table is protected with rwlock unix_table_lock
137 * each socket state is protected by separate rwlock.
140 static inline unsigned unix_hash_fold(unsigned hash)
144 return hash&(UNIX_HASH_SIZE-1);
147 #define unix_peer(sk) ((sk)->sk_pair)
149 static inline int unix_our_peer(struct sock *sk, struct sock *osk)
151 return unix_peer(osk) == sk;
154 static inline int unix_may_send(struct sock *sk, struct sock *osk)
156 return (unix_peer(osk) == NULL || unix_our_peer(sk, osk));
159 static struct sock *unix_peer_get(struct sock *s)
167 unix_state_runlock(s);
171 static inline void unix_release_addr(struct unix_address *addr)
173 if (atomic_dec_and_test(&addr->refcnt))
178 * Check unix socket name:
179 * - should be not zero length.
180 * - if started by not zero, should be NULL terminated (FS object)
181 * - if started by zero, it is abstract name.
184 static int unix_mkname(struct sockaddr_un * sunaddr, int len, unsigned *hashp)
186 if (len <= sizeof(short) || len > sizeof(*sunaddr))
188 if (!sunaddr || sunaddr->sun_family != AF_UNIX)
190 if (sunaddr->sun_path[0])
193 * This may look like an off by one error but it is
194 * a bit more subtle. 108 is the longest valid AF_UNIX
195 * path for a binding. sun_path[108] doesn't as such
196 * exist. However in kernel space we are guaranteed that
197 * it is a valid memory location in our kernel
200 if (len > sizeof(*sunaddr))
201 len = sizeof(*sunaddr);
202 ((char *)sunaddr)[len]=0;
203 len = strlen(sunaddr->sun_path)+1+sizeof(short);
207 *hashp = unix_hash_fold(csum_partial((char*)sunaddr, len, 0));
211 static void __unix_remove_socket(struct sock *sk)
213 sk_del_node_init(sk);
216 static void __unix_insert_socket(struct hlist_head *list, struct sock *sk)
218 BUG_TRAP(sk_unhashed(sk));
219 sk_add_node(sk, list);
222 static inline void unix_remove_socket(struct sock *sk)
224 write_lock(&unix_table_lock);
225 __unix_remove_socket(sk);
226 write_unlock(&unix_table_lock);
229 static inline void unix_insert_socket(struct hlist_head *list, struct sock *sk)
231 write_lock(&unix_table_lock);
232 __unix_insert_socket(list, sk);
233 write_unlock(&unix_table_lock);
236 static struct sock *__unix_find_socket_byname(struct sockaddr_un *sunname,
237 int len, int type, unsigned hash)
240 struct hlist_node *node;
242 sk_for_each(s, node, &unix_socket_table[hash ^ type]) {
243 struct unix_sock *u = unix_sk(s);
245 if (u->addr->len == len &&
246 !memcmp(u->addr->name, sunname, len))
254 static inline struct sock *unix_find_socket_byname(struct sockaddr_un *sunname,
260 read_lock(&unix_table_lock);
261 s = __unix_find_socket_byname(sunname, len, type, hash);
264 read_unlock(&unix_table_lock);
268 static struct sock *unix_find_socket_byinode(struct inode *i)
271 struct hlist_node *node;
273 read_lock(&unix_table_lock);
275 &unix_socket_table[i->i_ino & (UNIX_HASH_SIZE - 1)]) {
276 struct dentry *dentry = unix_sk(s)->dentry;
278 if(dentry && dentry->d_inode == i)
286 read_unlock(&unix_table_lock);
290 static inline int unix_writable(struct sock *sk)
292 return (atomic_read(&sk->sk_wmem_alloc) << 2) <= sk->sk_sndbuf;
295 static void unix_write_space(struct sock *sk)
297 read_lock(&sk->sk_callback_lock);
298 if (unix_writable(sk)) {
299 if (sk->sk_sleep && waitqueue_active(sk->sk_sleep))
300 wake_up_interruptible(sk->sk_sleep);
301 sk_wake_async(sk, 2, POLL_OUT);
303 read_unlock(&sk->sk_callback_lock);
306 /* When dgram socket disconnects (or changes its peer), we clear its receive
307 * queue of packets arrived from previous peer. First, it allows to do
308 * flow control based only on wmem_alloc; second, sk connected to peer
309 * may receive messages only from that peer. */
310 static void unix_dgram_disconnected(struct sock *sk, struct sock *other)
312 if (skb_queue_len(&sk->sk_receive_queue)) {
313 skb_queue_purge(&sk->sk_receive_queue);
314 wake_up_interruptible_all(&unix_sk(sk)->peer_wait);
316 /* If one link of bidirectional dgram pipe is disconnected,
317 * we signal error. Messages are lost. Do not make this,
318 * when peer was not connected to us.
320 if (!sock_flag(other, SOCK_DEAD) && unix_peer(other) == sk) {
321 other->sk_err = ECONNRESET;
322 other->sk_error_report(other);
327 static void unix_sock_destructor(struct sock *sk)
329 struct unix_sock *u = unix_sk(sk);
331 skb_queue_purge(&sk->sk_receive_queue);
333 BUG_TRAP(!atomic_read(&sk->sk_wmem_alloc));
334 BUG_TRAP(sk_unhashed(sk));
335 BUG_TRAP(!sk->sk_socket);
336 if (!sock_flag(sk, SOCK_DEAD)) {
337 printk("Attempt to release alive unix socket: %p\n", sk);
342 unix_release_addr(u->addr);
344 atomic_dec(&unix_nr_socks);
345 #ifdef UNIX_REFCNT_DEBUG
346 printk(KERN_DEBUG "UNIX %p is destroyed, %d are still alive.\n", sk, atomic_read(&unix_nr_socks));
350 static int unix_release_sock (struct sock *sk, int embrion)
352 struct unix_sock *u = unix_sk(sk);
353 struct dentry *dentry;
354 struct vfsmount *mnt;
359 unix_remove_socket(sk);
362 unix_state_wlock(sk);
364 sk->sk_shutdown = SHUTDOWN_MASK;
369 state = sk->sk_state;
370 sk->sk_state = TCP_CLOSE;
371 unix_state_wunlock(sk);
373 wake_up_interruptible_all(&u->peer_wait);
375 skpair=unix_peer(sk);
378 if (sk->sk_type == SOCK_STREAM || sk->sk_type == SOCK_SEQPACKET) {
379 unix_state_wlock(skpair);
381 skpair->sk_shutdown = SHUTDOWN_MASK;
382 if (!skb_queue_empty(&sk->sk_receive_queue) || embrion)
383 skpair->sk_err = ECONNRESET;
384 unix_state_wunlock(skpair);
385 skpair->sk_state_change(skpair);
386 read_lock(&skpair->sk_callback_lock);
387 sk_wake_async(skpair,1,POLL_HUP);
388 read_unlock(&skpair->sk_callback_lock);
390 sock_put(skpair); /* It may now die */
391 unix_peer(sk) = NULL;
394 /* Try to flush out this socket. Throw out buffers at least */
396 while ((skb = skb_dequeue(&sk->sk_receive_queue)) != NULL) {
397 if (state==TCP_LISTEN)
398 unix_release_sock(skb->sk, 1);
399 /* passed fds are erased in the kfree_skb hook */
408 clr_vx_info(&sk->sk_vx_info);
409 clr_nx_info(&sk->sk_nx_info);
412 /* ---- Socket is dead now and most probably destroyed ---- */
415 * Fixme: BSD difference: In BSD all sockets connected to use get
416 * ECONNRESET and we die on the spot. In Linux we behave
417 * like files and pipes do and wait for the last
420 * Can't we simply set sock->err?
422 * What the above comment does talk about? --ANK(980817)
425 if (atomic_read(&unix_tot_inflight))
426 unix_gc(); /* Garbage collect fds */
431 static int unix_listen(struct socket *sock, int backlog)
434 struct sock *sk = sock->sk;
435 struct unix_sock *u = unix_sk(sk);
438 if (sock->type!=SOCK_STREAM && sock->type!=SOCK_SEQPACKET)
439 goto out; /* Only stream/seqpacket sockets accept */
442 goto out; /* No listens on an unbound socket */
443 unix_state_wlock(sk);
444 if (sk->sk_state != TCP_CLOSE && sk->sk_state != TCP_LISTEN)
446 if (backlog > sk->sk_max_ack_backlog)
447 wake_up_interruptible_all(&u->peer_wait);
448 sk->sk_max_ack_backlog = backlog;
449 sk->sk_state = TCP_LISTEN;
450 /* set credentials so connect can copy them */
451 sk->sk_peercred.pid = current->tgid;
452 sk->sk_peercred.uid = current->euid;
453 sk->sk_peercred.gid = current->egid;
457 unix_state_wunlock(sk);
462 static int unix_release(struct socket *);
463 static int unix_bind(struct socket *, struct sockaddr *, int);
464 static int unix_stream_connect(struct socket *, struct sockaddr *,
465 int addr_len, int flags);
466 static int unix_socketpair(struct socket *, struct socket *);
467 static int unix_accept(struct socket *, struct socket *, int);
468 static int unix_getname(struct socket *, struct sockaddr *, int *, int);
469 static unsigned int unix_poll(struct file *, struct socket *, poll_table *);
470 static int unix_ioctl(struct socket *, unsigned int, unsigned long);
471 static int unix_shutdown(struct socket *, int);
472 static int unix_stream_sendmsg(struct kiocb *, struct socket *,
473 struct msghdr *, size_t);
474 static int unix_stream_recvmsg(struct kiocb *, struct socket *,
475 struct msghdr *, size_t, int);
476 static int unix_dgram_sendmsg(struct kiocb *, struct socket *,
477 struct msghdr *, size_t);
478 static int unix_dgram_recvmsg(struct kiocb *, struct socket *,
479 struct msghdr *, size_t, int);
480 static int unix_dgram_connect(struct socket *, struct sockaddr *,
483 static struct proto_ops unix_stream_ops = {
485 .owner = THIS_MODULE,
486 .release = unix_release,
488 .connect = unix_stream_connect,
489 .socketpair = unix_socketpair,
490 .accept = unix_accept,
491 .getname = unix_getname,
494 .listen = unix_listen,
495 .shutdown = unix_shutdown,
496 .setsockopt = sock_no_setsockopt,
497 .getsockopt = sock_no_getsockopt,
498 .sendmsg = unix_stream_sendmsg,
499 .recvmsg = unix_stream_recvmsg,
500 .mmap = sock_no_mmap,
501 .sendpage = sock_no_sendpage,
504 static struct proto_ops unix_dgram_ops = {
506 .owner = THIS_MODULE,
507 .release = unix_release,
509 .connect = unix_dgram_connect,
510 .socketpair = unix_socketpair,
511 .accept = sock_no_accept,
512 .getname = unix_getname,
513 .poll = datagram_poll,
515 .listen = sock_no_listen,
516 .shutdown = unix_shutdown,
517 .setsockopt = sock_no_setsockopt,
518 .getsockopt = sock_no_getsockopt,
519 .sendmsg = unix_dgram_sendmsg,
520 .recvmsg = unix_dgram_recvmsg,
521 .mmap = sock_no_mmap,
522 .sendpage = sock_no_sendpage,
525 static struct proto_ops unix_seqpacket_ops = {
527 .owner = THIS_MODULE,
528 .release = unix_release,
530 .connect = unix_stream_connect,
531 .socketpair = unix_socketpair,
532 .accept = unix_accept,
533 .getname = unix_getname,
534 .poll = datagram_poll,
536 .listen = unix_listen,
537 .shutdown = unix_shutdown,
538 .setsockopt = sock_no_setsockopt,
539 .getsockopt = sock_no_getsockopt,
540 .sendmsg = unix_dgram_sendmsg,
541 .recvmsg = unix_dgram_recvmsg,
542 .mmap = sock_no_mmap,
543 .sendpage = sock_no_sendpage,
546 static struct sock * unix_create1(struct socket *sock)
548 struct sock *sk = NULL;
551 if (atomic_read(&unix_nr_socks) >= 2*files_stat.max_files)
554 sk = sk_alloc(PF_UNIX, GFP_KERNEL, sizeof(struct unix_sock),
559 atomic_inc(&unix_nr_socks);
561 sock_init_data(sock,sk);
562 sk_set_owner(sk, THIS_MODULE);
564 set_vx_info(&sk->sk_vx_info, current->vx_info);
565 set_nx_info(&sk->sk_nx_info, current->nx_info);
566 sk->sk_xid = vx_current_xid();
568 sk->sk_write_space = unix_write_space;
569 sk->sk_max_ack_backlog = sysctl_unix_max_dgram_qlen;
570 sk->sk_destruct = unix_sock_destructor;
574 rwlock_init(&u->lock);
575 atomic_set(&u->inflight, sock ? 0 : -1);
576 init_MUTEX(&u->readsem); /* single task reading lock */
577 init_waitqueue_head(&u->peer_wait);
578 unix_insert_socket(unix_sockets_unbound, sk);
583 static int unix_create(struct socket *sock, int protocol)
585 if (protocol && protocol != PF_UNIX)
586 return -EPROTONOSUPPORT;
588 sock->state = SS_UNCONNECTED;
590 switch (sock->type) {
592 sock->ops = &unix_stream_ops;
595 * Believe it or not BSD has AF_UNIX, SOCK_RAW though
599 sock->type=SOCK_DGRAM;
601 sock->ops = &unix_dgram_ops;
604 sock->ops = &unix_seqpacket_ops;
607 return -ESOCKTNOSUPPORT;
610 return unix_create1(sock) ? 0 : -ENOMEM;
613 static int unix_release(struct socket *sock)
615 struct sock *sk = sock->sk;
622 return unix_release_sock (sk, 0);
625 static int unix_autobind(struct socket *sock)
627 struct sock *sk = sock->sk;
628 struct unix_sock *u = unix_sk(sk);
629 static u32 ordernum = 1;
630 struct unix_address * addr;
640 addr = kmalloc(sizeof(*addr) + sizeof(short) + 16, GFP_KERNEL);
644 memset(addr, 0, sizeof(*addr) + sizeof(short) + 16);
645 addr->name->sun_family = AF_UNIX;
646 atomic_set(&addr->refcnt, 1);
649 addr->len = sprintf(addr->name->sun_path+1, "%05x", ordernum) + 1 + sizeof(short);
650 addr->hash = unix_hash_fold(csum_partial((void*)addr->name, addr->len, 0));
652 write_lock(&unix_table_lock);
653 ordernum = (ordernum+1)&0xFFFFF;
655 if (__unix_find_socket_byname(addr->name, addr->len, sock->type,
657 write_unlock(&unix_table_lock);
658 /* Sanity yield. It is unusual case, but yet... */
659 if (!(ordernum&0xFF))
663 addr->hash ^= sk->sk_type;
665 __unix_remove_socket(sk);
667 __unix_insert_socket(&unix_socket_table[addr->hash], sk);
668 write_unlock(&unix_table_lock);
671 out: up(&u->readsem);
675 static struct sock *unix_find_other(struct sockaddr_un *sunname, int len,
676 int type, unsigned hash, int *error)
682 if (sunname->sun_path[0]) {
683 err = path_lookup(sunname->sun_path, LOOKUP_FOLLOW, &nd);
686 err = permission(nd.dentry->d_inode,MAY_WRITE, &nd);
691 if (!S_ISSOCK(nd.dentry->d_inode->i_mode))
693 u=unix_find_socket_byinode(nd.dentry->d_inode);
697 if (u->sk_type == type)
698 touch_atime(nd.mnt, nd.dentry);
703 if (u->sk_type != type) {
709 u=unix_find_socket_byname(sunname, len, type, hash);
711 struct dentry *dentry;
712 dentry = unix_sk(u)->dentry;
714 touch_atime(unix_sk(u)->mnt, dentry);
728 static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
730 struct sock *sk = sock->sk;
731 struct unix_sock *u = unix_sk(sk);
732 struct sockaddr_un *sunaddr=(struct sockaddr_un *)uaddr;
733 struct dentry * dentry = NULL;
737 struct unix_address *addr;
738 struct hlist_head *list;
741 if (sunaddr->sun_family != AF_UNIX)
744 if (addr_len==sizeof(short)) {
745 err = unix_autobind(sock);
749 err = unix_mkname(sunaddr, addr_len, &hash);
761 addr = kmalloc(sizeof(*addr)+addr_len, GFP_KERNEL);
765 memcpy(addr->name, sunaddr, addr_len);
766 addr->len = addr_len;
767 addr->hash = hash ^ sk->sk_type;
768 atomic_set(&addr->refcnt, 1);
770 if (sunaddr->sun_path[0]) {
774 * Get the parent directory, calculate the hash for last
777 err = path_lookup(sunaddr->sun_path, LOOKUP_PARENT, &nd);
779 goto out_mknod_parent;
781 * Yucky last component or no last component at all?
782 * (foo/., foo/.., /////)
785 if (nd.last_type != LAST_NORM)
788 * Lock the directory.
790 down(&nd.dentry->d_inode->i_sem);
792 * Do the final lookup.
794 dentry = lookup_hash(&nd.last, nd.dentry);
795 err = PTR_ERR(dentry);
797 goto out_mknod_unlock;
800 * Special case - lookup gave negative, but... we had foo/bar/
801 * From the vfs_mknod() POV we just have a negative dentry -
802 * all is fine. Let's be bastards - you had / on the end, you've
803 * been asking for (non-existent) directory. -ENOENT for you.
805 if (nd.last.name[nd.last.len] && !dentry->d_inode)
808 * All right, let's create it.
811 (SOCK_INODE(sock)->i_mode & ~current->fs->umask);
812 err = vfs_mknod(nd.dentry->d_inode, dentry, mode, 0);
815 up(&nd.dentry->d_inode->i_sem);
819 addr->hash = UNIX_HASH_SIZE;
822 write_lock(&unix_table_lock);
824 if (!sunaddr->sun_path[0]) {
826 if (__unix_find_socket_byname(sunaddr, addr_len,
827 sk->sk_type, hash)) {
828 unix_release_addr(addr);
832 list = &unix_socket_table[addr->hash];
834 list = &unix_socket_table[dentry->d_inode->i_ino & (UNIX_HASH_SIZE-1)];
835 u->dentry = nd.dentry;
840 __unix_remove_socket(sk);
842 __unix_insert_socket(list, sk);
845 write_unlock(&unix_table_lock);
854 up(&nd.dentry->d_inode->i_sem);
860 unix_release_addr(addr);
864 static int unix_dgram_connect(struct socket *sock, struct sockaddr *addr,
867 struct sock *sk = sock->sk;
868 struct sockaddr_un *sunaddr=(struct sockaddr_un*)addr;
873 if (addr->sa_family != AF_UNSPEC) {
874 err = unix_mkname(sunaddr, alen, &hash);
879 if (test_bit(SOCK_PASS_CRED, &sock->flags) && !unix_sk(sk)->addr &&
880 (err = unix_autobind(sock)) != 0)
883 other=unix_find_other(sunaddr, alen, sock->type, hash, &err);
887 unix_state_wlock(sk);
890 if (!unix_may_send(sk, other))
893 err = security_unix_may_send(sk->sk_socket, other->sk_socket);
899 * 1003.1g breaking connected state with AF_UNSPEC
902 unix_state_wlock(sk);
906 * If it was connected, reconnect.
909 struct sock *old_peer = unix_peer(sk);
911 unix_state_wunlock(sk);
913 if (other != old_peer)
914 unix_dgram_disconnected(sk, old_peer);
918 unix_state_wunlock(sk);
923 unix_state_wunlock(sk);
929 static long unix_wait_for_peer(struct sock *other, long timeo)
931 struct unix_sock *u = unix_sk(other);
935 prepare_to_wait_exclusive(&u->peer_wait, &wait, TASK_INTERRUPTIBLE);
937 sched = !sock_flag(other, SOCK_DEAD) &&
938 !(other->sk_shutdown & RCV_SHUTDOWN) &&
939 (skb_queue_len(&other->sk_receive_queue) >
940 other->sk_max_ack_backlog);
942 unix_state_runlock(other);
945 timeo = schedule_timeout(timeo);
947 finish_wait(&u->peer_wait, &wait);
951 static int unix_stream_connect(struct socket *sock, struct sockaddr *uaddr,
952 int addr_len, int flags)
954 struct sockaddr_un *sunaddr=(struct sockaddr_un *)uaddr;
955 struct sock *sk = sock->sk;
956 struct unix_sock *u = unix_sk(sk), *newu, *otheru;
957 struct sock *newsk = NULL;
958 struct sock *other = NULL;
959 struct sk_buff *skb = NULL;
965 err = unix_mkname(sunaddr, addr_len, &hash);
970 if (test_bit(SOCK_PASS_CRED, &sock->flags)
971 && !u->addr && (err = unix_autobind(sock)) != 0)
974 timeo = sock_sndtimeo(sk, flags & O_NONBLOCK);
976 /* First of all allocate resources.
977 If we will make it after state is locked,
978 we will have to recheck all again in any case.
983 /* create new sock for complete connection */
984 newsk = unix_create1(NULL);
988 /* Allocate skb for sending to listening sock */
989 skb = sock_wmalloc(newsk, 1, 0, GFP_KERNEL);
994 /* Find listening sock. */
995 other = unix_find_other(sunaddr, addr_len, sk->sk_type, hash, &err);
999 /* Latch state of peer */
1000 unix_state_rlock(other);
1002 /* Apparently VFS overslept socket death. Retry. */
1003 if (sock_flag(other, SOCK_DEAD)) {
1004 unix_state_runlock(other);
1009 err = -ECONNREFUSED;
1010 if (other->sk_state != TCP_LISTEN)
1013 if (skb_queue_len(&other->sk_receive_queue) >
1014 other->sk_max_ack_backlog) {
1019 timeo = unix_wait_for_peer(other, timeo);
1021 err = sock_intr_errno(timeo);
1022 if (signal_pending(current))
1030 It is tricky place. We need to grab write lock and cannot
1031 drop lock on peer. It is dangerous because deadlock is
1032 possible. Connect to self case and simultaneous
1033 attempt to connect are eliminated by checking socket
1034 state. other is TCP_LISTEN, if sk is TCP_LISTEN we
1035 check this before attempt to grab lock.
1037 Well, and we have to recheck the state after socket locked.
1043 /* This is ok... continue with connect */
1045 case TCP_ESTABLISHED:
1046 /* Socket is already connected */
1054 unix_state_wlock(sk);
1056 if (sk->sk_state != st) {
1057 unix_state_wunlock(sk);
1058 unix_state_runlock(other);
1063 err = security_unix_stream_connect(sock, other->sk_socket, newsk);
1065 unix_state_wunlock(sk);
1069 /* The way is open! Fastly set all the necessary fields... */
1072 unix_peer(newsk) = sk;
1073 newsk->sk_state = TCP_ESTABLISHED;
1074 newsk->sk_type = sk->sk_type;
1075 newsk->sk_peercred.pid = current->tgid;
1076 newsk->sk_peercred.uid = current->euid;
1077 newsk->sk_peercred.gid = current->egid;
1078 newu = unix_sk(newsk);
1079 newsk->sk_sleep = &newu->peer_wait;
1080 otheru = unix_sk(other);
1082 /* copy address information from listening to new sock*/
1084 atomic_inc(&otheru->addr->refcnt);
1085 newu->addr = otheru->addr;
1087 if (otheru->dentry) {
1088 newu->dentry = dget(otheru->dentry);
1089 newu->mnt = mntget(otheru->mnt);
1092 /* Set credentials */
1093 sk->sk_peercred = other->sk_peercred;
1096 unix_peer(sk) = newsk;
1097 sock->state = SS_CONNECTED;
1098 sk->sk_state = TCP_ESTABLISHED;
1100 unix_state_wunlock(sk);
1102 /* take ten and and send info to listening sock */
1103 spin_lock(&other->sk_receive_queue.lock);
1104 __skb_queue_tail(&other->sk_receive_queue, skb);
1105 /* Undo artificially decreased inflight after embrion
1106 * is installed to listening socket. */
1107 atomic_inc(&newu->inflight);
1108 spin_unlock(&other->sk_receive_queue.lock);
1109 unix_state_runlock(other);
1110 other->sk_data_ready(other, 0);
1116 unix_state_runlock(other);
1122 unix_release_sock(newsk, 0);
1128 static int unix_socketpair(struct socket *socka, struct socket *sockb)
1130 struct sock *ska=socka->sk, *skb = sockb->sk;
1132 /* Join our sockets back to back */
1137 ska->sk_peercred.pid = skb->sk_peercred.pid = current->tgid;
1138 ska->sk_peercred.uid = skb->sk_peercred.uid = current->euid;
1139 ska->sk_peercred.gid = skb->sk_peercred.gid = current->egid;
1141 if (ska->sk_type != SOCK_DGRAM) {
1142 ska->sk_state = TCP_ESTABLISHED;
1143 skb->sk_state = TCP_ESTABLISHED;
1144 socka->state = SS_CONNECTED;
1145 sockb->state = SS_CONNECTED;
1150 static int unix_accept(struct socket *sock, struct socket *newsock, int flags)
1152 struct sock *sk = sock->sk;
1154 struct sk_buff *skb;
1158 if (sock->type!=SOCK_STREAM && sock->type!=SOCK_SEQPACKET)
1162 if (sk->sk_state != TCP_LISTEN)
1165 /* If socket state is TCP_LISTEN it cannot change (for now...),
1166 * so that no locks are necessary.
1169 skb = skb_recv_datagram(sk, 0, flags&O_NONBLOCK, &err);
1171 /* This means receive shutdown. */
1178 skb_free_datagram(sk, skb);
1179 wake_up_interruptible(&unix_sk(sk)->peer_wait);
1181 /* attach accepted sock to socket */
1182 unix_state_wlock(tsk);
1183 newsock->state = SS_CONNECTED;
1184 sock_graft(tsk, newsock);
1185 unix_state_wunlock(tsk);
1193 static int unix_getname(struct socket *sock, struct sockaddr *uaddr, int *uaddr_len, int peer)
1195 struct sock *sk = sock->sk;
1196 struct unix_sock *u;
1197 struct sockaddr_un *sunaddr=(struct sockaddr_un *)uaddr;
1201 sk = unix_peer_get(sk);
1212 unix_state_rlock(sk);
1214 sunaddr->sun_family = AF_UNIX;
1215 sunaddr->sun_path[0] = 0;
1216 *uaddr_len = sizeof(short);
1218 struct unix_address *addr = u->addr;
1220 *uaddr_len = addr->len;
1221 memcpy(sunaddr, addr->name, *uaddr_len);
1223 unix_state_runlock(sk);
1229 static void unix_detach_fds(struct scm_cookie *scm, struct sk_buff *skb)
1233 scm->fp = UNIXCB(skb).fp;
1234 skb->destructor = sock_wfree;
1235 UNIXCB(skb).fp = NULL;
1237 for (i=scm->fp->count-1; i>=0; i--)
1238 unix_notinflight(scm->fp->fp[i]);
1241 static void unix_destruct_fds(struct sk_buff *skb)
1243 struct scm_cookie scm;
1244 memset(&scm, 0, sizeof(scm));
1245 unix_detach_fds(&scm, skb);
1247 /* Alas, it calls VFS */
1248 /* So fscking what? fput() had been SMP-safe since the last Summer */
1253 static void unix_attach_fds(struct scm_cookie *scm, struct sk_buff *skb)
1256 for (i=scm->fp->count-1; i>=0; i--)
1257 unix_inflight(scm->fp->fp[i]);
1258 UNIXCB(skb).fp = scm->fp;
1259 skb->destructor = unix_destruct_fds;
1264 * Send AF_UNIX data.
1267 static int unix_dgram_sendmsg(struct kiocb *kiocb, struct socket *sock,
1268 struct msghdr *msg, size_t len)
1270 struct sock_iocb *siocb = kiocb_to_siocb(kiocb);
1271 struct sock *sk = sock->sk;
1272 struct unix_sock *u = unix_sk(sk);
1273 struct sockaddr_un *sunaddr=msg->msg_name;
1274 struct sock *other = NULL;
1275 int namelen = 0; /* fake GCC */
1278 struct sk_buff *skb;
1280 struct scm_cookie tmp_scm;
1282 if (NULL == siocb->scm)
1283 siocb->scm = &tmp_scm;
1284 err = scm_send(sock, msg, siocb->scm);
1289 if (msg->msg_flags&MSG_OOB)
1292 if (msg->msg_namelen) {
1293 err = unix_mkname(sunaddr, msg->msg_namelen, &hash);
1300 other = unix_peer_get(sk);
1305 if (test_bit(SOCK_PASS_CRED, &sock->flags)
1306 && !u->addr && (err = unix_autobind(sock)) != 0)
1310 if (len > sk->sk_sndbuf - 32)
1313 skb = sock_alloc_send_skb(sk, len, msg->msg_flags&MSG_DONTWAIT, &err);
1317 memcpy(UNIXCREDS(skb), &siocb->scm->creds, sizeof(struct ucred));
1319 unix_attach_fds(siocb->scm, skb);
1321 skb->h.raw = skb->data;
1322 err = memcpy_fromiovec(skb_put(skb,len), msg->msg_iov, len);
1326 timeo = sock_sndtimeo(sk, msg->msg_flags & MSG_DONTWAIT);
1331 if (sunaddr == NULL)
1334 other = unix_find_other(sunaddr, namelen, sk->sk_type,
1340 unix_state_rlock(other);
1342 if (!unix_may_send(sk, other))
1345 if (sock_flag(other, SOCK_DEAD)) {
1347 * Check with 1003.1g - what should
1350 unix_state_runlock(other);
1354 unix_state_wlock(sk);
1355 if (unix_peer(sk) == other) {
1357 unix_state_wunlock(sk);
1359 unix_dgram_disconnected(sk, other);
1361 err = -ECONNREFUSED;
1363 unix_state_wunlock(sk);
1373 if (other->sk_shutdown & RCV_SHUTDOWN)
1376 err = security_unix_may_send(sk->sk_socket, other->sk_socket);
1380 if (unix_peer(other) != sk &&
1381 (skb_queue_len(&other->sk_receive_queue) >
1382 other->sk_max_ack_backlog)) {
1388 timeo = unix_wait_for_peer(other, timeo);
1390 err = sock_intr_errno(timeo);
1391 if (signal_pending(current))
1397 skb_queue_tail(&other->sk_receive_queue, skb);
1398 unix_state_runlock(other);
1399 other->sk_data_ready(other, len);
1401 scm_destroy(siocb->scm);
1405 unix_state_runlock(other);
1411 scm_destroy(siocb->scm);
1416 static int unix_stream_sendmsg(struct kiocb *kiocb, struct socket *sock,
1417 struct msghdr *msg, size_t len)
1419 struct sock_iocb *siocb = kiocb_to_siocb(kiocb);
1420 struct sock *sk = sock->sk;
1421 struct sock *other = NULL;
1422 struct sockaddr_un *sunaddr=msg->msg_name;
1424 struct sk_buff *skb;
1426 struct scm_cookie tmp_scm;
1428 if (NULL == siocb->scm)
1429 siocb->scm = &tmp_scm;
1430 err = scm_send(sock, msg, siocb->scm);
1435 if (msg->msg_flags&MSG_OOB)
1438 if (msg->msg_namelen) {
1439 err = sk->sk_state == TCP_ESTABLISHED ? -EISCONN : -EOPNOTSUPP;
1444 other = unix_peer_get(sk);
1449 if (sk->sk_shutdown & SEND_SHUTDOWN)
1455 * Optimisation for the fact that under 0.01% of X messages typically
1461 /* Keep two messages in the pipe so it schedules better */
1462 if (size > sk->sk_sndbuf / 2 - 64)
1463 size = sk->sk_sndbuf / 2 - 64;
1465 if (size > SKB_MAX_ALLOC)
1466 size = SKB_MAX_ALLOC;
1472 skb=sock_alloc_send_skb(sk,size,msg->msg_flags&MSG_DONTWAIT, &err);
1478 * If you pass two values to the sock_alloc_send_skb
1479 * it tries to grab the large buffer with GFP_NOFS
1480 * (which can fail easily), and if it fails grab the
1481 * fallback size buffer which is under a page and will
1484 size = min_t(int, size, skb_tailroom(skb));
1486 memcpy(UNIXCREDS(skb), &siocb->scm->creds, sizeof(struct ucred));
1488 unix_attach_fds(siocb->scm, skb);
1490 if ((err = memcpy_fromiovec(skb_put(skb,size), msg->msg_iov, size)) != 0) {
1495 unix_state_rlock(other);
1497 if (sock_flag(other, SOCK_DEAD) ||
1498 (other->sk_shutdown & RCV_SHUTDOWN))
1501 skb_queue_tail(&other->sk_receive_queue, skb);
1502 unix_state_runlock(other);
1503 other->sk_data_ready(other, size);
1508 scm_destroy(siocb->scm);
1514 unix_state_runlock(other);
1517 if (sent==0 && !(msg->msg_flags&MSG_NOSIGNAL))
1518 send_sig(SIGPIPE,current,0);
1523 scm_destroy(siocb->scm);
1525 return sent ? : err;
1528 static void unix_copy_addr(struct msghdr *msg, struct sock *sk)
1530 struct unix_sock *u = unix_sk(sk);
1532 msg->msg_namelen = 0;
1534 msg->msg_namelen = u->addr->len;
1535 memcpy(msg->msg_name, u->addr->name, u->addr->len);
1539 static int unix_dgram_recvmsg(struct kiocb *iocb, struct socket *sock,
1540 struct msghdr *msg, size_t size,
1543 struct sock_iocb *siocb = kiocb_to_siocb(iocb);
1544 struct scm_cookie tmp_scm;
1545 struct sock *sk = sock->sk;
1546 struct unix_sock *u = unix_sk(sk);
1547 int noblock = flags & MSG_DONTWAIT;
1548 struct sk_buff *skb;
1555 msg->msg_namelen = 0;
1557 skb = skb_recv_datagram(sk, flags, noblock, &err);
1561 wake_up_interruptible(&u->peer_wait);
1564 unix_copy_addr(msg, skb->sk);
1566 if (size > skb->len)
1568 else if (size < skb->len)
1569 msg->msg_flags |= MSG_TRUNC;
1571 err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, size);
1576 siocb->scm = &tmp_scm;
1577 memset(&tmp_scm, 0, sizeof(tmp_scm));
1579 siocb->scm->creds = *UNIXCREDS(skb);
1581 if (!(flags & MSG_PEEK))
1584 unix_detach_fds(siocb->scm, skb);
1588 /* It is questionable: on PEEK we could:
1589 - do not return fds - good, but too simple 8)
1590 - return fds, and do not return them on read (old strategy,
1592 - clone fds (I chose it for now, it is the most universal
1595 POSIX 1003.1g does not actually define this clearly
1596 at all. POSIX 1003.1g doesn't define a lot of things
1601 siocb->scm->fp = scm_fp_dup(UNIXCB(skb).fp);
1605 scm_recv(sock, msg, siocb->scm, flags);
1608 skb_free_datagram(sk,skb);
1614 * Sleep until data has arrive. But check for races..
1617 static long unix_stream_data_wait(struct sock * sk, long timeo)
1621 unix_state_rlock(sk);
1624 prepare_to_wait(sk->sk_sleep, &wait, TASK_INTERRUPTIBLE);
1626 if (skb_queue_len(&sk->sk_receive_queue) ||
1628 (sk->sk_shutdown & RCV_SHUTDOWN) ||
1629 signal_pending(current) ||
1633 set_bit(SOCK_ASYNC_WAITDATA, &sk->sk_socket->flags);
1634 unix_state_runlock(sk);
1635 timeo = schedule_timeout(timeo);
1636 unix_state_rlock(sk);
1637 clear_bit(SOCK_ASYNC_WAITDATA, &sk->sk_socket->flags);
1640 finish_wait(sk->sk_sleep, &wait);
1641 unix_state_runlock(sk);
1647 static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
1648 struct msghdr *msg, size_t size,
1651 struct sock_iocb *siocb = kiocb_to_siocb(iocb);
1652 struct scm_cookie tmp_scm;
1653 struct sock *sk = sock->sk;
1654 struct unix_sock *u = unix_sk(sk);
1655 struct sockaddr_un *sunaddr=msg->msg_name;
1657 int check_creds = 0;
1663 if (sk->sk_state != TCP_ESTABLISHED)
1670 target = sock_rcvlowat(sk, flags&MSG_WAITALL, size);
1671 timeo = sock_rcvtimeo(sk, flags&MSG_DONTWAIT);
1673 msg->msg_namelen = 0;
1675 /* Lock the socket to prevent queue disordering
1676 * while sleeps in memcpy_tomsg
1680 siocb->scm = &tmp_scm;
1681 memset(&tmp_scm, 0, sizeof(tmp_scm));
1689 struct sk_buff *skb;
1691 skb = skb_dequeue(&sk->sk_receive_queue);
1694 if (copied >= target)
1698 * POSIX 1003.1g mandates this order.
1701 if ((err = sock_error(sk)) != 0)
1703 if (sk->sk_shutdown & RCV_SHUTDOWN)
1710 timeo = unix_stream_data_wait(sk, timeo);
1712 if (signal_pending(current)) {
1713 err = sock_intr_errno(timeo);
1721 /* Never glue messages from different writers */
1722 if (memcmp(UNIXCREDS(skb), &siocb->scm->creds, sizeof(siocb->scm->creds)) != 0) {
1723 skb_queue_head(&sk->sk_receive_queue, skb);
1727 /* Copy credentials */
1728 siocb->scm->creds = *UNIXCREDS(skb);
1732 /* Copy address just once */
1735 unix_copy_addr(msg, skb->sk);
1739 chunk = min_t(unsigned int, skb->len, size);
1740 if (memcpy_toiovec(msg->msg_iov, skb->data, chunk)) {
1741 skb_queue_head(&sk->sk_receive_queue, skb);
1749 /* Mark read part of skb as used */
1750 if (!(flags & MSG_PEEK))
1752 skb_pull(skb, chunk);
1755 unix_detach_fds(siocb->scm, skb);
1757 /* put the skb back if we didn't use it up.. */
1760 skb_queue_head(&sk->sk_receive_queue, skb);
1771 /* It is questionable, see note in unix_dgram_recvmsg.
1774 siocb->scm->fp = scm_fp_dup(UNIXCB(skb).fp);
1776 /* put message back and return */
1777 skb_queue_head(&sk->sk_receive_queue, skb);
1783 scm_recv(sock, msg, siocb->scm, flags);
1785 return copied ? : err;
1788 static int unix_shutdown(struct socket *sock, int mode)
1790 struct sock *sk = sock->sk;
1793 mode = (mode+1)&(RCV_SHUTDOWN|SEND_SHUTDOWN);
1796 unix_state_wlock(sk);
1797 sk->sk_shutdown |= mode;
1798 other=unix_peer(sk);
1801 unix_state_wunlock(sk);
1802 sk->sk_state_change(sk);
1805 (sk->sk_type == SOCK_STREAM || sk->sk_type == SOCK_SEQPACKET)) {
1809 if (mode&RCV_SHUTDOWN)
1810 peer_mode |= SEND_SHUTDOWN;
1811 if (mode&SEND_SHUTDOWN)
1812 peer_mode |= RCV_SHUTDOWN;
1813 unix_state_wlock(other);
1814 other->sk_shutdown |= peer_mode;
1815 unix_state_wunlock(other);
1816 other->sk_state_change(other);
1817 read_lock(&other->sk_callback_lock);
1818 if (peer_mode == SHUTDOWN_MASK)
1819 sk_wake_async(other,1,POLL_HUP);
1820 else if (peer_mode & RCV_SHUTDOWN)
1821 sk_wake_async(other,1,POLL_IN);
1822 read_unlock(&other->sk_callback_lock);
1830 static int unix_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1832 struct sock *sk = sock->sk;
1839 amount = atomic_read(&sk->sk_wmem_alloc);
1840 err = put_user(amount, (int *)arg);
1844 struct sk_buff *skb;
1845 if (sk->sk_state == TCP_LISTEN) {
1850 spin_lock(&sk->sk_receive_queue.lock);
1851 skb = skb_peek(&sk->sk_receive_queue);
1854 spin_unlock(&sk->sk_receive_queue.lock);
1855 err = put_user(amount, (int *)arg);
1860 err = dev_ioctl(cmd, (void *)arg);
1866 static unsigned int unix_poll(struct file * file, struct socket *sock, poll_table *wait)
1868 struct sock *sk = sock->sk;
1871 poll_wait(file, sk->sk_sleep, wait);
1874 /* exceptional events? */
1877 if (sk->sk_shutdown == SHUTDOWN_MASK)
1881 if (!skb_queue_empty(&sk->sk_receive_queue) ||
1882 (sk->sk_shutdown & RCV_SHUTDOWN))
1883 mask |= POLLIN | POLLRDNORM;
1885 /* Connection-based need to check for termination and startup */
1886 if ((sk->sk_type == SOCK_STREAM || sk->sk_type == SOCK_SEQPACKET) && sk->sk_state == TCP_CLOSE)
1890 * we set writable also when the other side has shut down the
1891 * connection. This prevents stuck sockets.
1893 if (unix_writable(sk))
1894 mask |= POLLOUT | POLLWRNORM | POLLWRBAND;
1900 #ifdef CONFIG_PROC_FS
1901 static struct sock *unix_seq_idx(int *iter, loff_t pos)
1906 for (s = first_unix_socket(iter); s; s = next_unix_socket(iter, s)) {
1915 static void *unix_seq_start(struct seq_file *seq, loff_t *pos)
1917 read_lock(&unix_table_lock);
1918 return *pos ? unix_seq_idx(seq->private, *pos - 1) : ((void *) 1);
1921 static void *unix_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1926 return first_unix_socket(seq->private);
1927 return next_unix_socket(seq->private, v);
1930 static void unix_seq_stop(struct seq_file *seq, void *v)
1932 read_unlock(&unix_table_lock);
1935 static int unix_seq_show(struct seq_file *seq, void *v)
1939 seq_puts(seq, "Num RefCount Protocol Flags Type St "
1943 struct unix_sock *u = unix_sk(s);
1944 unix_state_rlock(s);
1946 seq_printf(seq, "%p: %08X %08X %08X %04X %02X %5lu",
1948 atomic_read(&s->sk_refcnt),
1950 s->sk_state == TCP_LISTEN ? __SO_ACCEPTCON : 0,
1953 (s->sk_state == TCP_ESTABLISHED ? SS_CONNECTED : SS_UNCONNECTED) :
1954 (s->sk_state == TCP_ESTABLISHED ? SS_CONNECTING : SS_DISCONNECTING),
1962 len = u->addr->len - sizeof(short);
1963 if (!UNIX_ABSTRACT(s))
1969 for ( ; i < len; i++)
1970 seq_putc(seq, u->addr->name->sun_path[i]);
1972 unix_state_runlock(s);
1973 seq_putc(seq, '\n');
1979 static struct seq_operations unix_seq_ops = {
1980 .start = unix_seq_start,
1981 .next = unix_seq_next,
1982 .stop = unix_seq_stop,
1983 .show = unix_seq_show,
1987 static int unix_seq_open(struct inode *inode, struct file *file)
1989 struct seq_file *seq;
1991 int *iter = kmalloc(sizeof(int), GFP_KERNEL);
1996 rc = seq_open(file, &unix_seq_ops);
2000 seq = file->private_data;
2001 seq->private = iter;
2010 static struct file_operations unix_seq_fops = {
2011 .owner = THIS_MODULE,
2012 .open = unix_seq_open,
2014 .llseek = seq_lseek,
2015 .release = seq_release_private,
2020 static struct net_proto_family unix_family_ops = {
2022 .create = unix_create,
2023 .owner = THIS_MODULE,
2026 #ifdef CONFIG_SYSCTL
2027 extern void unix_sysctl_register(void);
2028 extern void unix_sysctl_unregister(void);
2030 static inline void unix_sysctl_register(void) {}
2031 static inline void unix_sysctl_unregister(void) {}
2034 static int __init af_unix_init(void)
2036 struct sk_buff *dummy_skb;
2038 if (sizeof(struct unix_skb_parms) > sizeof(dummy_skb->cb)) {
2039 printk(KERN_CRIT "%s: panic\n", __FUNCTION__);
2042 /* allocate our sock slab cache */
2043 unix_sk_cachep = kmem_cache_create("unix_sock",
2044 sizeof(struct unix_sock), 0,
2045 SLAB_HWCACHE_ALIGN, 0, 0);
2046 if (!unix_sk_cachep)
2048 "af_unix_init: Cannot create unix_sock SLAB cache!\n");
2050 sock_register(&unix_family_ops);
2051 #ifdef CONFIG_PROC_FS
2052 proc_net_fops_create("unix", 0, &unix_seq_fops);
2054 unix_sysctl_register();
2058 static void __exit af_unix_exit(void)
2060 sock_unregister(PF_UNIX);
2061 unix_sysctl_unregister();
2062 proc_net_remove("unix");
2063 kmem_cache_destroy(unix_sk_cachep);
2066 module_init(af_unix_init);
2067 module_exit(af_unix_exit);
2069 MODULE_LICENSE("GPL");
2070 MODULE_ALIAS_NETPROTO(PF_UNIX);