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/signal.h>
89 #include <linux/sched.h>
90 #include <linux/errno.h>
91 #include <linux/string.h>
92 #include <linux/stat.h>
93 #include <linux/dcache.h>
94 #include <linux/namei.h>
95 #include <linux/socket.h>
97 #include <linux/fcntl.h>
98 #include <linux/termios.h>
99 #include <linux/sockios.h>
100 #include <linux/net.h>
101 #include <linux/in.h>
102 #include <linux/fs.h>
103 #include <linux/slab.h>
104 #include <asm/uaccess.h>
105 #include <linux/skbuff.h>
106 #include <linux/netdevice.h>
107 #include <net/sock.h>
108 #include <linux/tcp.h>
109 #include <net/af_unix.h>
110 #include <linux/proc_fs.h>
111 #include <linux/seq_file.h>
113 #include <linux/init.h>
114 #include <linux/poll.h>
115 #include <linux/smp_lock.h>
116 #include <linux/rtnetlink.h>
117 #include <linux/mount.h>
118 #include <net/checksum.h>
119 #include <linux/security.h>
120 #include <linux/vs_context.h>
121 #include <linux/vs_network.h>
122 #include <linux/vs_limit.h>
124 int sysctl_unix_max_dgram_qlen = 10;
126 struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1];
127 DEFINE_RWLOCK(unix_table_lock);
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) (unix_sk(sk)->peer)
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]) {
192 * This may look like an off by one error but it is a bit more
193 * subtle. 108 is the longest valid AF_UNIX path for a binding.
194 * sun_path[108] doesnt as such exist. However in kernel space
195 * we are guaranteed that it is a valid memory location in our
196 * kernel address buffer.
198 ((char *)sunaddr)[len]=0;
199 len = strlen(sunaddr->sun_path)+1+sizeof(short);
203 *hashp = unix_hash_fold(csum_partial((char*)sunaddr, len, 0));
207 static void __unix_remove_socket(struct sock *sk)
209 sk_del_node_init(sk);
212 static void __unix_insert_socket(struct hlist_head *list, struct sock *sk)
214 BUG_TRAP(sk_unhashed(sk));
215 sk_add_node(sk, list);
218 static inline void unix_remove_socket(struct sock *sk)
220 write_lock(&unix_table_lock);
221 __unix_remove_socket(sk);
222 write_unlock(&unix_table_lock);
225 static inline void unix_insert_socket(struct hlist_head *list, struct sock *sk)
227 write_lock(&unix_table_lock);
228 __unix_insert_socket(list, sk);
229 write_unlock(&unix_table_lock);
232 static struct sock *__unix_find_socket_byname(struct sockaddr_un *sunname,
233 int len, int type, unsigned hash)
236 struct hlist_node *node;
238 sk_for_each(s, node, &unix_socket_table[hash ^ type]) {
239 struct unix_sock *u = unix_sk(s);
241 if (u->addr->len == len &&
242 !memcmp(u->addr->name, sunname, len))
250 static inline struct sock *unix_find_socket_byname(struct sockaddr_un *sunname,
256 read_lock(&unix_table_lock);
257 s = __unix_find_socket_byname(sunname, len, type, hash);
260 read_unlock(&unix_table_lock);
264 static struct sock *unix_find_socket_byinode(struct inode *i)
267 struct hlist_node *node;
269 read_lock(&unix_table_lock);
271 &unix_socket_table[i->i_ino & (UNIX_HASH_SIZE - 1)]) {
272 struct dentry *dentry = unix_sk(s)->dentry;
274 if(dentry && dentry->d_inode == i)
282 read_unlock(&unix_table_lock);
286 static inline int unix_writable(struct sock *sk)
288 return (atomic_read(&sk->sk_wmem_alloc) << 2) <= sk->sk_sndbuf;
291 static void unix_write_space(struct sock *sk)
293 read_lock(&sk->sk_callback_lock);
294 if (unix_writable(sk)) {
295 if (sk->sk_sleep && waitqueue_active(sk->sk_sleep))
296 wake_up_interruptible(sk->sk_sleep);
297 sk_wake_async(sk, 2, POLL_OUT);
299 read_unlock(&sk->sk_callback_lock);
302 /* When dgram socket disconnects (or changes its peer), we clear its receive
303 * queue of packets arrived from previous peer. First, it allows to do
304 * flow control based only on wmem_alloc; second, sk connected to peer
305 * may receive messages only from that peer. */
306 static void unix_dgram_disconnected(struct sock *sk, struct sock *other)
308 if (skb_queue_len(&sk->sk_receive_queue)) {
309 skb_queue_purge(&sk->sk_receive_queue);
310 wake_up_interruptible_all(&unix_sk(sk)->peer_wait);
312 /* If one link of bidirectional dgram pipe is disconnected,
313 * we signal error. Messages are lost. Do not make this,
314 * when peer was not connected to us.
316 if (!sock_flag(other, SOCK_DEAD) && unix_peer(other) == sk) {
317 other->sk_err = ECONNRESET;
318 other->sk_error_report(other);
323 static void unix_sock_destructor(struct sock *sk)
325 struct unix_sock *u = unix_sk(sk);
327 skb_queue_purge(&sk->sk_receive_queue);
329 BUG_TRAP(!atomic_read(&sk->sk_wmem_alloc));
330 BUG_TRAP(sk_unhashed(sk));
331 BUG_TRAP(!sk->sk_socket);
332 if (!sock_flag(sk, SOCK_DEAD)) {
333 printk("Attempt to release alive unix socket: %p\n", sk);
338 unix_release_addr(u->addr);
340 atomic_dec(&unix_nr_socks);
341 #ifdef UNIX_REFCNT_DEBUG
342 printk(KERN_DEBUG "UNIX %p is destroyed, %d are still alive.\n", sk, atomic_read(&unix_nr_socks));
346 static int unix_release_sock (struct sock *sk, int embrion)
348 struct unix_sock *u = unix_sk(sk);
349 struct dentry *dentry;
350 struct vfsmount *mnt;
355 unix_remove_socket(sk);
358 unix_state_wlock(sk);
360 sk->sk_shutdown = SHUTDOWN_MASK;
365 state = sk->sk_state;
366 sk->sk_state = TCP_CLOSE;
367 unix_state_wunlock(sk);
369 wake_up_interruptible_all(&u->peer_wait);
371 skpair=unix_peer(sk);
374 if (sk->sk_type == SOCK_STREAM || sk->sk_type == SOCK_SEQPACKET) {
375 unix_state_wlock(skpair);
377 skpair->sk_shutdown = SHUTDOWN_MASK;
378 if (!skb_queue_empty(&sk->sk_receive_queue) || embrion)
379 skpair->sk_err = ECONNRESET;
380 unix_state_wunlock(skpair);
381 skpair->sk_state_change(skpair);
382 read_lock(&skpair->sk_callback_lock);
383 sk_wake_async(skpair,1,POLL_HUP);
384 read_unlock(&skpair->sk_callback_lock);
386 sock_put(skpair); /* It may now die */
387 unix_peer(sk) = NULL;
390 /* Try to flush out this socket. Throw out buffers at least */
392 while ((skb = skb_dequeue(&sk->sk_receive_queue)) != NULL) {
393 if (state==TCP_LISTEN)
394 unix_release_sock(skb->sk, 1);
395 /* passed fds are erased in the kfree_skb hook */
406 /* ---- Socket is dead now and most probably destroyed ---- */
409 * Fixme: BSD difference: In BSD all sockets connected to use get
410 * ECONNRESET and we die on the spot. In Linux we behave
411 * like files and pipes do and wait for the last
414 * Can't we simply set sock->err?
416 * What the above comment does talk about? --ANK(980817)
419 if (atomic_read(&unix_tot_inflight))
420 unix_gc(); /* Garbage collect fds */
425 static int unix_listen(struct socket *sock, int backlog)
428 struct sock *sk = sock->sk;
429 struct unix_sock *u = unix_sk(sk);
432 if (sock->type!=SOCK_STREAM && sock->type!=SOCK_SEQPACKET)
433 goto out; /* Only stream/seqpacket sockets accept */
436 goto out; /* No listens on an unbound socket */
437 unix_state_wlock(sk);
438 if (sk->sk_state != TCP_CLOSE && sk->sk_state != TCP_LISTEN)
440 if (backlog > sk->sk_max_ack_backlog)
441 wake_up_interruptible_all(&u->peer_wait);
442 sk->sk_max_ack_backlog = backlog;
443 sk->sk_state = TCP_LISTEN;
444 /* set credentials so connect can copy them */
445 sk->sk_peercred.pid = current->tgid;
446 sk->sk_peercred.uid = current->euid;
447 sk->sk_peercred.gid = current->egid;
451 unix_state_wunlock(sk);
456 static int unix_release(struct socket *);
457 static int unix_bind(struct socket *, struct sockaddr *, int);
458 static int unix_stream_connect(struct socket *, struct sockaddr *,
459 int addr_len, int flags);
460 static int unix_socketpair(struct socket *, struct socket *);
461 static int unix_accept(struct socket *, struct socket *, int);
462 static int unix_getname(struct socket *, struct sockaddr *, int *, int);
463 static unsigned int unix_poll(struct file *, struct socket *, poll_table *);
464 static int unix_ioctl(struct socket *, unsigned int, unsigned long);
465 static int unix_shutdown(struct socket *, int);
466 static int unix_stream_sendmsg(struct kiocb *, struct socket *,
467 struct msghdr *, size_t);
468 static int unix_stream_recvmsg(struct kiocb *, struct socket *,
469 struct msghdr *, size_t, int);
470 static int unix_dgram_sendmsg(struct kiocb *, struct socket *,
471 struct msghdr *, size_t);
472 static int unix_dgram_recvmsg(struct kiocb *, struct socket *,
473 struct msghdr *, size_t, int);
474 static int unix_dgram_connect(struct socket *, struct sockaddr *,
476 static int unix_seqpacket_sendmsg(struct kiocb *, struct socket *,
477 struct msghdr *, size_t);
479 static struct proto_ops unix_stream_ops = {
481 .owner = THIS_MODULE,
482 .release = unix_release,
484 .connect = unix_stream_connect,
485 .socketpair = unix_socketpair,
486 .accept = unix_accept,
487 .getname = unix_getname,
490 .listen = unix_listen,
491 .shutdown = unix_shutdown,
492 .setsockopt = sock_no_setsockopt,
493 .getsockopt = sock_no_getsockopt,
494 .sendmsg = unix_stream_sendmsg,
495 .recvmsg = unix_stream_recvmsg,
496 .mmap = sock_no_mmap,
497 .sendpage = sock_no_sendpage,
500 static struct proto_ops unix_dgram_ops = {
502 .owner = THIS_MODULE,
503 .release = unix_release,
505 .connect = unix_dgram_connect,
506 .socketpair = unix_socketpair,
507 .accept = sock_no_accept,
508 .getname = unix_getname,
509 .poll = datagram_poll,
511 .listen = sock_no_listen,
512 .shutdown = unix_shutdown,
513 .setsockopt = sock_no_setsockopt,
514 .getsockopt = sock_no_getsockopt,
515 .sendmsg = unix_dgram_sendmsg,
516 .recvmsg = unix_dgram_recvmsg,
517 .mmap = sock_no_mmap,
518 .sendpage = sock_no_sendpage,
521 static struct proto_ops unix_seqpacket_ops = {
523 .owner = THIS_MODULE,
524 .release = unix_release,
526 .connect = unix_stream_connect,
527 .socketpair = unix_socketpair,
528 .accept = unix_accept,
529 .getname = unix_getname,
530 .poll = datagram_poll,
532 .listen = unix_listen,
533 .shutdown = unix_shutdown,
534 .setsockopt = sock_no_setsockopt,
535 .getsockopt = sock_no_getsockopt,
536 .sendmsg = unix_seqpacket_sendmsg,
537 .recvmsg = unix_dgram_recvmsg,
538 .mmap = sock_no_mmap,
539 .sendpage = sock_no_sendpage,
542 static struct proto unix_proto = {
544 .owner = THIS_MODULE,
545 .obj_size = sizeof(struct unix_sock),
548 static struct sock * unix_create1(struct socket *sock)
550 struct sock *sk = NULL;
553 if (atomic_read(&unix_nr_socks) >= 2*files_stat.max_files)
556 sk = sk_alloc(PF_UNIX, GFP_KERNEL, &unix_proto, 1);
560 atomic_inc(&unix_nr_socks);
562 sock_init_data(sock,sk);
564 sk->sk_write_space = unix_write_space;
565 sk->sk_max_ack_backlog = sysctl_unix_max_dgram_qlen;
566 sk->sk_destruct = unix_sock_destructor;
570 rwlock_init(&u->lock);
571 atomic_set(&u->inflight, sock ? 0 : -1);
572 init_MUTEX(&u->readsem); /* single task reading lock */
573 init_waitqueue_head(&u->peer_wait);
574 unix_insert_socket(unix_sockets_unbound, sk);
579 static int unix_create(struct socket *sock, int protocol)
581 if (protocol && protocol != PF_UNIX)
582 return -EPROTONOSUPPORT;
584 sock->state = SS_UNCONNECTED;
586 switch (sock->type) {
588 sock->ops = &unix_stream_ops;
591 * Believe it or not BSD has AF_UNIX, SOCK_RAW though
595 sock->type=SOCK_DGRAM;
597 sock->ops = &unix_dgram_ops;
600 sock->ops = &unix_seqpacket_ops;
603 return -ESOCKTNOSUPPORT;
606 return unix_create1(sock) ? 0 : -ENOMEM;
609 static int unix_release(struct socket *sock)
611 struct sock *sk = sock->sk;
618 return unix_release_sock (sk, 0);
621 static int unix_autobind(struct socket *sock)
623 struct sock *sk = sock->sk;
624 struct unix_sock *u = unix_sk(sk);
625 static u32 ordernum = 1;
626 struct unix_address * addr;
636 addr = kmalloc(sizeof(*addr) + sizeof(short) + 16, GFP_KERNEL);
640 memset(addr, 0, sizeof(*addr) + sizeof(short) + 16);
641 addr->name->sun_family = AF_UNIX;
642 atomic_set(&addr->refcnt, 1);
645 addr->len = sprintf(addr->name->sun_path+1, "%05x", ordernum) + 1 + sizeof(short);
646 addr->hash = unix_hash_fold(csum_partial((void*)addr->name, addr->len, 0));
648 write_lock(&unix_table_lock);
649 ordernum = (ordernum+1)&0xFFFFF;
651 if (__unix_find_socket_byname(addr->name, addr->len, sock->type,
653 write_unlock(&unix_table_lock);
654 /* Sanity yield. It is unusual case, but yet... */
655 if (!(ordernum&0xFF))
659 addr->hash ^= sk->sk_type;
661 __unix_remove_socket(sk);
663 __unix_insert_socket(&unix_socket_table[addr->hash], sk);
664 write_unlock(&unix_table_lock);
667 out: up(&u->readsem);
671 static struct sock *unix_find_other(struct sockaddr_un *sunname, int len,
672 int type, unsigned hash, int *error)
678 if (sunname->sun_path[0]) {
679 err = path_lookup(sunname->sun_path, LOOKUP_FOLLOW, &nd);
682 err = permission(nd.dentry->d_inode,MAY_WRITE, &nd);
687 if (!S_ISSOCK(nd.dentry->d_inode->i_mode))
689 u=unix_find_socket_byinode(nd.dentry->d_inode);
693 if (u->sk_type == type)
694 touch_atime(nd.mnt, nd.dentry);
699 if (u->sk_type != type) {
705 u=unix_find_socket_byname(sunname, len, type, hash);
707 struct dentry *dentry;
708 dentry = unix_sk(u)->dentry;
710 touch_atime(unix_sk(u)->mnt, dentry);
724 static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
726 struct sock *sk = sock->sk;
727 struct unix_sock *u = unix_sk(sk);
728 struct sockaddr_un *sunaddr=(struct sockaddr_un *)uaddr;
729 struct dentry * dentry = NULL;
733 struct unix_address *addr;
734 struct hlist_head *list;
737 if (sunaddr->sun_family != AF_UNIX)
740 if (addr_len==sizeof(short)) {
741 err = unix_autobind(sock);
745 err = unix_mkname(sunaddr, addr_len, &hash);
757 addr = kmalloc(sizeof(*addr)+addr_len, GFP_KERNEL);
761 memcpy(addr->name, sunaddr, addr_len);
762 addr->len = addr_len;
763 addr->hash = hash ^ sk->sk_type;
764 atomic_set(&addr->refcnt, 1);
766 if (sunaddr->sun_path[0]) {
770 * Get the parent directory, calculate the hash for last
773 err = path_lookup(sunaddr->sun_path, LOOKUP_PARENT, &nd);
775 goto out_mknod_parent;
777 dentry = lookup_create(&nd, 0);
778 err = PTR_ERR(dentry);
780 goto out_mknod_unlock;
783 * All right, let's create it.
786 (SOCK_INODE(sock)->i_mode & ~current->fs->umask);
787 err = vfs_mknod(nd.dentry->d_inode, dentry, mode, 0);
790 up(&nd.dentry->d_inode->i_sem);
794 addr->hash = UNIX_HASH_SIZE;
797 write_lock(&unix_table_lock);
799 if (!sunaddr->sun_path[0]) {
801 if (__unix_find_socket_byname(sunaddr, addr_len,
802 sk->sk_type, hash)) {
803 unix_release_addr(addr);
807 list = &unix_socket_table[addr->hash];
809 list = &unix_socket_table[dentry->d_inode->i_ino & (UNIX_HASH_SIZE-1)];
810 u->dentry = nd.dentry;
815 __unix_remove_socket(sk);
817 __unix_insert_socket(list, sk);
820 write_unlock(&unix_table_lock);
829 up(&nd.dentry->d_inode->i_sem);
834 unix_release_addr(addr);
838 static int unix_dgram_connect(struct socket *sock, struct sockaddr *addr,
841 struct sock *sk = sock->sk;
842 struct sockaddr_un *sunaddr=(struct sockaddr_un*)addr;
847 if (addr->sa_family != AF_UNSPEC) {
848 err = unix_mkname(sunaddr, alen, &hash);
853 if (test_bit(SOCK_PASSCRED, &sock->flags) &&
854 !unix_sk(sk)->addr && (err = unix_autobind(sock)) != 0)
857 other=unix_find_other(sunaddr, alen, sock->type, hash, &err);
861 unix_state_wlock(sk);
864 if (!unix_may_send(sk, other))
867 err = security_unix_may_send(sk->sk_socket, other->sk_socket);
873 * 1003.1g breaking connected state with AF_UNSPEC
876 unix_state_wlock(sk);
880 * If it was connected, reconnect.
883 struct sock *old_peer = unix_peer(sk);
885 unix_state_wunlock(sk);
887 if (other != old_peer)
888 unix_dgram_disconnected(sk, old_peer);
892 unix_state_wunlock(sk);
897 unix_state_wunlock(sk);
903 static long unix_wait_for_peer(struct sock *other, long timeo)
905 struct unix_sock *u = unix_sk(other);
909 prepare_to_wait_exclusive(&u->peer_wait, &wait, TASK_INTERRUPTIBLE);
911 sched = !sock_flag(other, SOCK_DEAD) &&
912 !(other->sk_shutdown & RCV_SHUTDOWN) &&
913 (skb_queue_len(&other->sk_receive_queue) >
914 other->sk_max_ack_backlog);
916 unix_state_runlock(other);
919 timeo = schedule_timeout(timeo);
921 finish_wait(&u->peer_wait, &wait);
925 static int unix_stream_connect(struct socket *sock, struct sockaddr *uaddr,
926 int addr_len, int flags)
928 struct sockaddr_un *sunaddr=(struct sockaddr_un *)uaddr;
929 struct sock *sk = sock->sk;
930 struct unix_sock *u = unix_sk(sk), *newu, *otheru;
931 struct sock *newsk = NULL;
932 struct sock *other = NULL;
933 struct sk_buff *skb = NULL;
939 err = unix_mkname(sunaddr, addr_len, &hash);
944 if (test_bit(SOCK_PASSCRED, &sock->flags)
945 && !u->addr && (err = unix_autobind(sock)) != 0)
948 timeo = sock_sndtimeo(sk, flags & O_NONBLOCK);
950 /* First of all allocate resources.
951 If we will make it after state is locked,
952 we will have to recheck all again in any case.
957 /* create new sock for complete connection */
958 newsk = unix_create1(NULL);
962 /* Allocate skb for sending to listening sock */
963 skb = sock_wmalloc(newsk, 1, 0, GFP_KERNEL);
968 /* Find listening sock. */
969 other = unix_find_other(sunaddr, addr_len, sk->sk_type, hash, &err);
973 /* Latch state of peer */
974 unix_state_rlock(other);
976 /* Apparently VFS overslept socket death. Retry. */
977 if (sock_flag(other, SOCK_DEAD)) {
978 unix_state_runlock(other);
984 if (other->sk_state != TCP_LISTEN)
987 if (skb_queue_len(&other->sk_receive_queue) >
988 other->sk_max_ack_backlog) {
993 timeo = unix_wait_for_peer(other, timeo);
995 err = sock_intr_errno(timeo);
996 if (signal_pending(current))
1004 It is tricky place. We need to grab write lock and cannot
1005 drop lock on peer. It is dangerous because deadlock is
1006 possible. Connect to self case and simultaneous
1007 attempt to connect are eliminated by checking socket
1008 state. other is TCP_LISTEN, if sk is TCP_LISTEN we
1009 check this before attempt to grab lock.
1011 Well, and we have to recheck the state after socket locked.
1017 /* This is ok... continue with connect */
1019 case TCP_ESTABLISHED:
1020 /* Socket is already connected */
1028 unix_state_wlock(sk);
1030 if (sk->sk_state != st) {
1031 unix_state_wunlock(sk);
1032 unix_state_runlock(other);
1037 err = security_unix_stream_connect(sock, other->sk_socket, newsk);
1039 unix_state_wunlock(sk);
1043 /* The way is open! Fastly set all the necessary fields... */
1046 unix_peer(newsk) = sk;
1047 newsk->sk_state = TCP_ESTABLISHED;
1048 newsk->sk_type = sk->sk_type;
1049 newsk->sk_peercred.pid = current->tgid;
1050 newsk->sk_peercred.uid = current->euid;
1051 newsk->sk_peercred.gid = current->egid;
1052 newu = unix_sk(newsk);
1053 newsk->sk_sleep = &newu->peer_wait;
1054 otheru = unix_sk(other);
1056 /* copy address information from listening to new sock*/
1058 atomic_inc(&otheru->addr->refcnt);
1059 newu->addr = otheru->addr;
1061 if (otheru->dentry) {
1062 newu->dentry = dget(otheru->dentry);
1063 newu->mnt = mntget(otheru->mnt);
1066 /* Set credentials */
1067 sk->sk_peercred = other->sk_peercred;
1070 unix_peer(sk) = newsk;
1071 sock->state = SS_CONNECTED;
1072 sk->sk_state = TCP_ESTABLISHED;
1074 unix_state_wunlock(sk);
1076 /* take ten and and send info to listening sock */
1077 spin_lock(&other->sk_receive_queue.lock);
1078 __skb_queue_tail(&other->sk_receive_queue, skb);
1079 /* Undo artificially decreased inflight after embrion
1080 * is installed to listening socket. */
1081 atomic_inc(&newu->inflight);
1082 spin_unlock(&other->sk_receive_queue.lock);
1083 unix_state_runlock(other);
1084 other->sk_data_ready(other, 0);
1090 unix_state_runlock(other);
1096 unix_release_sock(newsk, 0);
1102 static int unix_socketpair(struct socket *socka, struct socket *sockb)
1104 struct sock *ska=socka->sk, *skb = sockb->sk;
1106 /* Join our sockets back to back */
1111 ska->sk_peercred.pid = skb->sk_peercred.pid = current->tgid;
1112 ska->sk_peercred.uid = skb->sk_peercred.uid = current->euid;
1113 ska->sk_peercred.gid = skb->sk_peercred.gid = current->egid;
1115 if (ska->sk_type != SOCK_DGRAM) {
1116 ska->sk_state = TCP_ESTABLISHED;
1117 skb->sk_state = TCP_ESTABLISHED;
1118 socka->state = SS_CONNECTED;
1119 sockb->state = SS_CONNECTED;
1124 static int unix_accept(struct socket *sock, struct socket *newsock, int flags)
1126 struct sock *sk = sock->sk;
1128 struct sk_buff *skb;
1132 if (sock->type!=SOCK_STREAM && sock->type!=SOCK_SEQPACKET)
1136 if (sk->sk_state != TCP_LISTEN)
1139 /* If socket state is TCP_LISTEN it cannot change (for now...),
1140 * so that no locks are necessary.
1143 skb = skb_recv_datagram(sk, 0, flags&O_NONBLOCK, &err);
1145 /* This means receive shutdown. */
1152 skb_free_datagram(sk, skb);
1153 wake_up_interruptible(&unix_sk(sk)->peer_wait);
1155 /* attach accepted sock to socket */
1156 unix_state_wlock(tsk);
1157 newsock->state = SS_CONNECTED;
1158 sock_graft(tsk, newsock);
1159 unix_state_wunlock(tsk);
1167 static int unix_getname(struct socket *sock, struct sockaddr *uaddr, int *uaddr_len, int peer)
1169 struct sock *sk = sock->sk;
1170 struct unix_sock *u;
1171 struct sockaddr_un *sunaddr=(struct sockaddr_un *)uaddr;
1175 sk = unix_peer_get(sk);
1186 unix_state_rlock(sk);
1188 sunaddr->sun_family = AF_UNIX;
1189 sunaddr->sun_path[0] = 0;
1190 *uaddr_len = sizeof(short);
1192 struct unix_address *addr = u->addr;
1194 *uaddr_len = addr->len;
1195 memcpy(sunaddr, addr->name, *uaddr_len);
1197 unix_state_runlock(sk);
1203 static void unix_detach_fds(struct scm_cookie *scm, struct sk_buff *skb)
1207 scm->fp = UNIXCB(skb).fp;
1208 skb->destructor = sock_wfree;
1209 UNIXCB(skb).fp = NULL;
1211 for (i=scm->fp->count-1; i>=0; i--)
1212 unix_notinflight(scm->fp->fp[i]);
1215 static void unix_destruct_fds(struct sk_buff *skb)
1217 struct scm_cookie scm;
1218 memset(&scm, 0, sizeof(scm));
1219 unix_detach_fds(&scm, skb);
1221 /* Alas, it calls VFS */
1222 /* So fscking what? fput() had been SMP-safe since the last Summer */
1227 static void unix_attach_fds(struct scm_cookie *scm, struct sk_buff *skb)
1230 for (i=scm->fp->count-1; i>=0; i--)
1231 unix_inflight(scm->fp->fp[i]);
1232 UNIXCB(skb).fp = scm->fp;
1233 skb->destructor = unix_destruct_fds;
1238 * Send AF_UNIX data.
1241 static int unix_dgram_sendmsg(struct kiocb *kiocb, struct socket *sock,
1242 struct msghdr *msg, size_t len)
1244 struct sock_iocb *siocb = kiocb_to_siocb(kiocb);
1245 struct sock *sk = sock->sk;
1246 struct unix_sock *u = unix_sk(sk);
1247 struct sockaddr_un *sunaddr=msg->msg_name;
1248 struct sock *other = NULL;
1249 int namelen = 0; /* fake GCC */
1252 struct sk_buff *skb;
1254 struct scm_cookie tmp_scm;
1256 if (NULL == siocb->scm)
1257 siocb->scm = &tmp_scm;
1258 err = scm_send(sock, msg, siocb->scm);
1263 if (msg->msg_flags&MSG_OOB)
1266 if (msg->msg_namelen) {
1267 err = unix_mkname(sunaddr, msg->msg_namelen, &hash);
1274 other = unix_peer_get(sk);
1279 if (test_bit(SOCK_PASSCRED, &sock->flags)
1280 && !u->addr && (err = unix_autobind(sock)) != 0)
1284 if (len > sk->sk_sndbuf - 32)
1287 skb = sock_alloc_send_skb(sk, len, msg->msg_flags&MSG_DONTWAIT, &err);
1291 memcpy(UNIXCREDS(skb), &siocb->scm->creds, sizeof(struct ucred));
1293 unix_attach_fds(siocb->scm, skb);
1295 skb->h.raw = skb->data;
1296 err = memcpy_fromiovec(skb_put(skb,len), msg->msg_iov, len);
1300 timeo = sock_sndtimeo(sk, msg->msg_flags & MSG_DONTWAIT);
1305 if (sunaddr == NULL)
1308 other = unix_find_other(sunaddr, namelen, sk->sk_type,
1314 unix_state_rlock(other);
1316 if (!unix_may_send(sk, other))
1319 if (sock_flag(other, SOCK_DEAD)) {
1321 * Check with 1003.1g - what should
1324 unix_state_runlock(other);
1328 unix_state_wlock(sk);
1329 if (unix_peer(sk) == other) {
1331 unix_state_wunlock(sk);
1333 unix_dgram_disconnected(sk, other);
1335 err = -ECONNREFUSED;
1337 unix_state_wunlock(sk);
1347 if (other->sk_shutdown & RCV_SHUTDOWN)
1350 if (sk->sk_type != SOCK_SEQPACKET) {
1351 err = security_unix_may_send(sk->sk_socket, other->sk_socket);
1356 if (unix_peer(other) != sk &&
1357 (skb_queue_len(&other->sk_receive_queue) >
1358 other->sk_max_ack_backlog)) {
1364 timeo = unix_wait_for_peer(other, timeo);
1366 err = sock_intr_errno(timeo);
1367 if (signal_pending(current))
1373 skb_queue_tail(&other->sk_receive_queue, skb);
1374 unix_state_runlock(other);
1375 other->sk_data_ready(other, len);
1377 scm_destroy(siocb->scm);
1381 unix_state_runlock(other);
1387 scm_destroy(siocb->scm);
1392 static int unix_stream_sendmsg(struct kiocb *kiocb, struct socket *sock,
1393 struct msghdr *msg, size_t len)
1395 struct sock_iocb *siocb = kiocb_to_siocb(kiocb);
1396 struct sock *sk = sock->sk;
1397 struct sock *other = NULL;
1398 struct sockaddr_un *sunaddr=msg->msg_name;
1400 struct sk_buff *skb;
1402 struct scm_cookie tmp_scm;
1404 if (NULL == siocb->scm)
1405 siocb->scm = &tmp_scm;
1406 err = scm_send(sock, msg, siocb->scm);
1411 if (msg->msg_flags&MSG_OOB)
1414 if (msg->msg_namelen) {
1415 err = sk->sk_state == TCP_ESTABLISHED ? -EISCONN : -EOPNOTSUPP;
1420 other = unix_peer_get(sk);
1425 if (sk->sk_shutdown & SEND_SHUTDOWN)
1431 * Optimisation for the fact that under 0.01% of X messages typically
1437 /* Keep two messages in the pipe so it schedules better */
1438 if (size > sk->sk_sndbuf / 2 - 64)
1439 size = sk->sk_sndbuf / 2 - 64;
1441 if (size > SKB_MAX_ALLOC)
1442 size = SKB_MAX_ALLOC;
1448 skb=sock_alloc_send_skb(sk,size,msg->msg_flags&MSG_DONTWAIT, &err);
1454 * If you pass two values to the sock_alloc_send_skb
1455 * it tries to grab the large buffer with GFP_NOFS
1456 * (which can fail easily), and if it fails grab the
1457 * fallback size buffer which is under a page and will
1460 size = min_t(int, size, skb_tailroom(skb));
1462 memcpy(UNIXCREDS(skb), &siocb->scm->creds, sizeof(struct ucred));
1464 unix_attach_fds(siocb->scm, skb);
1466 if ((err = memcpy_fromiovec(skb_put(skb,size), msg->msg_iov, size)) != 0) {
1471 unix_state_rlock(other);
1473 if (sock_flag(other, SOCK_DEAD) ||
1474 (other->sk_shutdown & RCV_SHUTDOWN))
1477 skb_queue_tail(&other->sk_receive_queue, skb);
1478 unix_state_runlock(other);
1479 other->sk_data_ready(other, size);
1484 scm_destroy(siocb->scm);
1490 unix_state_runlock(other);
1493 if (sent==0 && !(msg->msg_flags&MSG_NOSIGNAL))
1494 send_sig(SIGPIPE,current,0);
1499 scm_destroy(siocb->scm);
1501 return sent ? : err;
1504 static int unix_seqpacket_sendmsg(struct kiocb *kiocb, struct socket *sock,
1505 struct msghdr *msg, size_t len)
1508 struct sock *sk = sock->sk;
1510 err = sock_error(sk);
1514 if (sk->sk_state != TCP_ESTABLISHED)
1517 if (msg->msg_namelen)
1518 msg->msg_namelen = 0;
1520 return unix_dgram_sendmsg(kiocb, sock, msg, len);
1523 static void unix_copy_addr(struct msghdr *msg, struct sock *sk)
1525 struct unix_sock *u = unix_sk(sk);
1527 msg->msg_namelen = 0;
1529 msg->msg_namelen = u->addr->len;
1530 memcpy(msg->msg_name, u->addr->name, u->addr->len);
1534 static int unix_dgram_recvmsg(struct kiocb *iocb, struct socket *sock,
1535 struct msghdr *msg, size_t size,
1538 struct sock_iocb *siocb = kiocb_to_siocb(iocb);
1539 struct scm_cookie tmp_scm;
1540 struct sock *sk = sock->sk;
1541 struct unix_sock *u = unix_sk(sk);
1542 int noblock = flags & MSG_DONTWAIT;
1543 struct sk_buff *skb;
1550 msg->msg_namelen = 0;
1554 skb = skb_recv_datagram(sk, flags, noblock, &err);
1558 wake_up_interruptible(&u->peer_wait);
1561 unix_copy_addr(msg, skb->sk);
1563 if (size > skb->len)
1565 else if (size < skb->len)
1566 msg->msg_flags |= MSG_TRUNC;
1568 err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, size);
1573 siocb->scm = &tmp_scm;
1574 memset(&tmp_scm, 0, sizeof(tmp_scm));
1576 siocb->scm->creds = *UNIXCREDS(skb);
1578 if (!(flags & MSG_PEEK))
1581 unix_detach_fds(siocb->scm, skb);
1585 /* It is questionable: on PEEK we could:
1586 - do not return fds - good, but too simple 8)
1587 - return fds, and do not return them on read (old strategy,
1589 - clone fds (I chose it for now, it is the most universal
1592 POSIX 1003.1g does not actually define this clearly
1593 at all. POSIX 1003.1g doesn't define a lot of things
1598 siocb->scm->fp = scm_fp_dup(UNIXCB(skb).fp);
1602 scm_recv(sock, msg, siocb->scm, flags);
1605 skb_free_datagram(sk,skb);
1613 * Sleep until data has arrive. But check for races..
1616 static long unix_stream_data_wait(struct sock * sk, long timeo)
1620 unix_state_rlock(sk);
1623 prepare_to_wait(sk->sk_sleep, &wait, TASK_INTERRUPTIBLE);
1625 if (skb_queue_len(&sk->sk_receive_queue) ||
1627 (sk->sk_shutdown & RCV_SHUTDOWN) ||
1628 signal_pending(current) ||
1632 set_bit(SOCK_ASYNC_WAITDATA, &sk->sk_socket->flags);
1633 unix_state_runlock(sk);
1634 timeo = schedule_timeout(timeo);
1635 unix_state_rlock(sk);
1636 clear_bit(SOCK_ASYNC_WAITDATA, &sk->sk_socket->flags);
1639 finish_wait(sk->sk_sleep, &wait);
1640 unix_state_runlock(sk);
1646 static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
1647 struct msghdr *msg, size_t size,
1650 struct sock_iocb *siocb = kiocb_to_siocb(iocb);
1651 struct scm_cookie tmp_scm;
1652 struct sock *sk = sock->sk;
1653 struct unix_sock *u = unix_sk(sk);
1654 struct sockaddr_un *sunaddr=msg->msg_name;
1656 int check_creds = 0;
1662 if (sk->sk_state != TCP_ESTABLISHED)
1669 target = sock_rcvlowat(sk, flags&MSG_WAITALL, size);
1670 timeo = sock_rcvtimeo(sk, flags&MSG_DONTWAIT);
1672 msg->msg_namelen = 0;
1674 /* Lock the socket to prevent queue disordering
1675 * while sleeps in memcpy_tomsg
1679 siocb->scm = &tmp_scm;
1680 memset(&tmp_scm, 0, sizeof(tmp_scm));
1688 struct sk_buff *skb;
1690 skb = skb_dequeue(&sk->sk_receive_queue);
1693 if (copied >= target)
1697 * POSIX 1003.1g mandates this order.
1700 if ((err = sock_error(sk)) != 0)
1702 if (sk->sk_shutdown & RCV_SHUTDOWN)
1709 timeo = unix_stream_data_wait(sk, timeo);
1711 if (signal_pending(current)) {
1712 err = sock_intr_errno(timeo);
1720 /* Never glue messages from different writers */
1721 if (memcmp(UNIXCREDS(skb), &siocb->scm->creds, sizeof(siocb->scm->creds)) != 0) {
1722 skb_queue_head(&sk->sk_receive_queue, skb);
1726 /* Copy credentials */
1727 siocb->scm->creds = *UNIXCREDS(skb);
1731 /* Copy address just once */
1734 unix_copy_addr(msg, skb->sk);
1738 chunk = min_t(unsigned int, skb->len, size);
1739 if (memcpy_toiovec(msg->msg_iov, skb->data, chunk)) {
1740 skb_queue_head(&sk->sk_receive_queue, skb);
1748 /* Mark read part of skb as used */
1749 if (!(flags & MSG_PEEK))
1751 skb_pull(skb, chunk);
1754 unix_detach_fds(siocb->scm, skb);
1756 /* put the skb back if we didn't use it up.. */
1759 skb_queue_head(&sk->sk_receive_queue, skb);
1770 /* It is questionable, see note in unix_dgram_recvmsg.
1773 siocb->scm->fp = scm_fp_dup(UNIXCB(skb).fp);
1775 /* put message back and return */
1776 skb_queue_head(&sk->sk_receive_queue, skb);
1782 scm_recv(sock, msg, siocb->scm, flags);
1784 return copied ? : err;
1787 static int unix_shutdown(struct socket *sock, int mode)
1789 struct sock *sk = sock->sk;
1792 mode = (mode+1)&(RCV_SHUTDOWN|SEND_SHUTDOWN);
1795 unix_state_wlock(sk);
1796 sk->sk_shutdown |= mode;
1797 other=unix_peer(sk);
1800 unix_state_wunlock(sk);
1801 sk->sk_state_change(sk);
1804 (sk->sk_type == SOCK_STREAM || sk->sk_type == SOCK_SEQPACKET)) {
1808 if (mode&RCV_SHUTDOWN)
1809 peer_mode |= SEND_SHUTDOWN;
1810 if (mode&SEND_SHUTDOWN)
1811 peer_mode |= RCV_SHUTDOWN;
1812 unix_state_wlock(other);
1813 other->sk_shutdown |= peer_mode;
1814 unix_state_wunlock(other);
1815 other->sk_state_change(other);
1816 read_lock(&other->sk_callback_lock);
1817 if (peer_mode == SHUTDOWN_MASK)
1818 sk_wake_async(other,1,POLL_HUP);
1819 else if (peer_mode & RCV_SHUTDOWN)
1820 sk_wake_async(other,1,POLL_IN);
1821 read_unlock(&other->sk_callback_lock);
1829 static int unix_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1831 struct sock *sk = sock->sk;
1838 amount = atomic_read(&sk->sk_wmem_alloc);
1839 err = put_user(amount, (int __user *)arg);
1843 struct sk_buff *skb;
1845 if (sk->sk_state == TCP_LISTEN) {
1850 spin_lock(&sk->sk_receive_queue.lock);
1851 if (sk->sk_type == SOCK_STREAM ||
1852 sk->sk_type == SOCK_SEQPACKET) {
1853 skb_queue_walk(&sk->sk_receive_queue, skb)
1856 skb = skb_peek(&sk->sk_receive_queue);
1860 spin_unlock(&sk->sk_receive_queue.lock);
1861 err = put_user(amount, (int __user *)arg);
1866 err = dev_ioctl(cmd, (void __user *)arg);
1872 static unsigned int unix_poll(struct file * file, struct socket *sock, poll_table *wait)
1874 struct sock *sk = sock->sk;
1877 poll_wait(file, sk->sk_sleep, wait);
1880 /* exceptional events? */
1883 if (sk->sk_shutdown == SHUTDOWN_MASK)
1887 if (!skb_queue_empty(&sk->sk_receive_queue) ||
1888 (sk->sk_shutdown & RCV_SHUTDOWN))
1889 mask |= POLLIN | POLLRDNORM;
1891 /* Connection-based need to check for termination and startup */
1892 if ((sk->sk_type == SOCK_STREAM || sk->sk_type == SOCK_SEQPACKET) && sk->sk_state == TCP_CLOSE)
1896 * we set writable also when the other side has shut down the
1897 * connection. This prevents stuck sockets.
1899 if (unix_writable(sk))
1900 mask |= POLLOUT | POLLWRNORM | POLLWRBAND;
1906 #ifdef CONFIG_PROC_FS
1907 static struct sock *unix_seq_idx(int *iter, loff_t pos)
1912 for (s = first_unix_socket(iter); s; s = next_unix_socket(iter, s)) {
1921 static void *unix_seq_start(struct seq_file *seq, loff_t *pos)
1923 read_lock(&unix_table_lock);
1924 return *pos ? unix_seq_idx(seq->private, *pos - 1) : ((void *) 1);
1927 static void *unix_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1932 return first_unix_socket(seq->private);
1933 return next_unix_socket(seq->private, v);
1936 static void unix_seq_stop(struct seq_file *seq, void *v)
1938 read_unlock(&unix_table_lock);
1941 static int unix_seq_show(struct seq_file *seq, void *v)
1945 seq_puts(seq, "Num RefCount Protocol Flags Type St "
1949 struct unix_sock *u = unix_sk(s);
1950 unix_state_rlock(s);
1952 seq_printf(seq, "%p: %08X %08X %08X %04X %02X %5lu",
1954 atomic_read(&s->sk_refcnt),
1956 s->sk_state == TCP_LISTEN ? __SO_ACCEPTCON : 0,
1959 (s->sk_state == TCP_ESTABLISHED ? SS_CONNECTED : SS_UNCONNECTED) :
1960 (s->sk_state == TCP_ESTABLISHED ? SS_CONNECTING : SS_DISCONNECTING),
1968 len = u->addr->len - sizeof(short);
1969 if (!UNIX_ABSTRACT(s))
1975 for ( ; i < len; i++)
1976 seq_putc(seq, u->addr->name->sun_path[i]);
1978 unix_state_runlock(s);
1979 seq_putc(seq, '\n');
1985 static struct seq_operations unix_seq_ops = {
1986 .start = unix_seq_start,
1987 .next = unix_seq_next,
1988 .stop = unix_seq_stop,
1989 .show = unix_seq_show,
1993 static int unix_seq_open(struct inode *inode, struct file *file)
1995 struct seq_file *seq;
1997 int *iter = kmalloc(sizeof(int), GFP_KERNEL);
2002 rc = seq_open(file, &unix_seq_ops);
2006 seq = file->private_data;
2007 seq->private = iter;
2016 static struct file_operations unix_seq_fops = {
2017 .owner = THIS_MODULE,
2018 .open = unix_seq_open,
2020 .llseek = seq_lseek,
2021 .release = seq_release_private,
2026 static struct net_proto_family unix_family_ops = {
2028 .create = unix_create,
2029 .owner = THIS_MODULE,
2032 #ifdef CONFIG_SYSCTL
2033 extern void unix_sysctl_register(void);
2034 extern void unix_sysctl_unregister(void);
2036 static inline void unix_sysctl_register(void) {}
2037 static inline void unix_sysctl_unregister(void) {}
2040 static int __init af_unix_init(void)
2043 struct sk_buff *dummy_skb;
2045 if (sizeof(struct unix_skb_parms) > sizeof(dummy_skb->cb)) {
2046 printk(KERN_CRIT "%s: panic\n", __FUNCTION__);
2050 rc = proto_register(&unix_proto, 1);
2052 printk(KERN_CRIT "%s: Cannot create unix_sock SLAB cache!\n",
2057 sock_register(&unix_family_ops);
2058 #ifdef CONFIG_PROC_FS
2059 proc_net_fops_create("unix", 0, &unix_seq_fops);
2061 unix_sysctl_register();
2066 static void __exit af_unix_exit(void)
2068 sock_unregister(PF_UNIX);
2069 unix_sysctl_unregister();
2070 proc_net_remove("unix");
2071 proto_unregister(&unix_proto);
2074 module_init(af_unix_init);
2075 module_exit(af_unix_exit);
2077 MODULE_LICENSE("GPL");
2078 MODULE_ALIAS_NETPROTO(PF_UNIX);