3d0f25fc9fbf0846b9d9e49aa5fbb4deca85090c
[davej-history.git] / net / unix / af_unix.c
blob3d0f25fc9fbf0846b9d9e49aa5fbb4deca85090c
1 /*
2 * NET3: 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.78 1999/05/27 00:38:41 davem Exp $
13 * Fixes:
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
23 * Mike Shaver's work.
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
30 * reference counting
31 * Kirk Petersen : Made this a module
32 * Christoph Rohland : Elegant non-blocking accept/connect algorithm.
33 * Lots of bug fixes.
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
45 * dgram receiver.
47 * Known differences from reference BSD that was tested:
49 * [TO FIX]
50 * ECONNREFUSED is not returned from one end of a connected() socket to the
51 * other the moment one end closes.
52 * fstat() doesn't return st_dev=NODEV, and give the blksize as high water mark
53 * and a fake inode identifier (nor the BSD first socket fstat twice bug).
54 * [NOT TO FIX]
55 * accept() returns a path name even if the connecting socket has closed
56 * in the meantime (BSD loses the path and gives up).
57 * accept() returns 0 length path for an unbound connector. BSD returns 16
58 * and a null first byte in the path (but not for gethost/peername - BSD bug ??)
59 * socketpair(...SOCK_RAW..) doesn't panic the kernel.
60 * BSD af_unix apparently has connect forgetting to block properly.
61 * (need to check this with the POSIX spec in detail)
63 * Differences from 2.0.0-11-... (ANK)
64 * Bug fixes and improvements.
65 * - client shutdown killed server socket.
66 * - removed all useless cli/sti pairs.
68 * Semantic changes/extensions.
69 * - generic control message passing.
70 * - SCM_CREDENTIALS control message.
71 * - "Abstract" (not FS based) socket bindings.
72 * Abstract names are sequences of bytes (not zero terminated)
73 * started by 0, so that this name space does not intersect
74 * with BSD names.
77 #include <linux/module.h>
78 #include <linux/config.h>
79 #include <linux/kernel.h>
80 #include <linux/major.h>
81 #include <linux/signal.h>
82 #include <linux/sched.h>
83 #include <linux/errno.h>
84 #include <linux/string.h>
85 #include <linux/stat.h>
86 #include <linux/socket.h>
87 #include <linux/un.h>
88 #include <linux/fcntl.h>
89 #include <linux/termios.h>
90 #include <linux/socket.h>
91 #include <linux/sockios.h>
92 #include <linux/net.h>
93 #include <linux/in.h>
94 #include <linux/fs.h>
95 #include <linux/malloc.h>
96 #include <asm/uaccess.h>
97 #include <linux/skbuff.h>
98 #include <linux/netdevice.h>
99 #include <net/sock.h>
100 #include <net/tcp.h>
101 #include <net/af_unix.h>
102 #include <linux/proc_fs.h>
103 #include <net/scm.h>
104 #include <linux/init.h>
105 #include <linux/poll.h>
106 #include <linux/smp_lock.h>
108 #include <asm/checksum.h>
110 #define min(a,b) (((a)<(b))?(a):(b))
112 int sysctl_unix_delete_delay = HZ;
113 int sysctl_unix_destroy_delay =10*HZ;
114 int sysctl_unix_max_dgram_qlen =10;
116 unix_socket *unix_socket_table[UNIX_HASH_SIZE+1];
117 static atomic_t unix_nr_socks =ATOMIC_INIT(0);
118 staticDECLARE_WAIT_QUEUE_HEAD(unix_ack_wqueue);
119 staticDECLARE_WAIT_QUEUE_HEAD(unix_dgram_wqueue);
121 #define unix_sockets_unbound (unix_socket_table[UNIX_HASH_SIZE])
123 #define UNIX_ABSTRACT(sk) ((sk)->protinfo.af_unix.addr->hash!=UNIX_HASH_SIZE)
125 static voidunix_destroy_socket(unix_socket *sk);
126 static voidunix_stream_write_space(struct sock *sk);
128 extern __inline__ unsignedunix_hash_fold(unsigned hash)
130 hash ^= hash>>16;
131 hash ^= hash>>8;
132 hash ^= hash>>4;
133 return hash;
136 #define unix_peer(sk) ((sk)->pair)
138 extern __inline__ intunix_our_peer(unix_socket *sk, unix_socket *osk)
140 returnunix_peer(osk) == sk;
143 extern __inline__ intunix_may_send(unix_socket *sk, unix_socket *osk)
145 return(unix_peer(osk) == NULL ||unix_our_peer(sk, osk));
148 #define ulock(sk) (&(sk->protinfo.af_unix.user_count))
150 extern __inline__ voidunix_lock(unix_socket *sk)
152 atomic_inc(ulock(sk));
155 extern __inline__ voidunix_unlock(unix_socket *sk)
157 atomic_dec(ulock(sk));
160 extern __inline__ intunix_locked(unix_socket *sk)
162 return(atomic_read(ulock(sk)) !=0);
165 extern __inline__ voidunix_release_addr(struct unix_address *addr)
167 if(addr)
169 if(atomic_dec_and_test(&addr->refcnt))
170 kfree(addr);
174 static voidunix_destruct_addr(struct sock *sk)
176 struct unix_address *addr = sk->protinfo.af_unix.addr;
178 unix_release_addr(addr);
182 * Check unix socket name:
183 * - should be not zero length.
184 * - if started by not zero, should be NULL terminated (FS object)
185 * - if started by zero, it is abstract name.
188 static intunix_mkname(struct sockaddr_un * sunaddr,int len,unsigned*hashp)
190 if(len <=sizeof(short) || len >sizeof(*sunaddr))
191 return-EINVAL;
192 if(!sunaddr || sunaddr->sun_family != AF_UNIX)
193 return-EINVAL;
194 if(sunaddr->sun_path[0])
197 * This may look like an off by one error but it is
198 * a bit more subtle. 108 is the longest valid AF_UNIX
199 * path for a binding. sun_path[108] doesnt as such
200 * exist. However in kernel space we are guaranteed that
201 * it is a valid memory location in our kernel
202 * address buffer.
204 if(len >sizeof(*sunaddr))
205 len =sizeof(*sunaddr);
206 ((char*)sunaddr)[len]=0;
207 len =strlen(sunaddr->sun_path)+1+sizeof(short);
208 return len;
211 *hashp =unix_hash_fold(csum_partial((char*)sunaddr, len,0));
212 return len;
215 static voidunix_remove_socket(unix_socket *sk)
217 unix_socket **list = sk->protinfo.af_unix.list;
218 if(sk->next)
219 sk->next->prev = sk->prev;
220 if(sk->prev)
221 sk->prev->next = sk->next;
222 if(*list == sk)
223 *list = sk->next;
224 sk->protinfo.af_unix.list = NULL;
225 sk->prev = NULL;
226 sk->next = NULL;
229 static voidunix_insert_socket(unix_socket *sk)
231 unix_socket **list = sk->protinfo.af_unix.list;
232 sk->prev = NULL;
233 sk->next = *list;
234 if(*list)
235 (*list)->prev = sk;
236 *list=sk;
239 static unix_socket *unix_find_socket_byname(struct sockaddr_un *sunname,
240 int len,int type,unsigned hash)
242 unix_socket *s;
244 for(s=unix_socket_table[(hash^type)&0xF]; s; s=s->next)
246 if(s->protinfo.af_unix.addr->len==len &&
247 memcmp(s->protinfo.af_unix.addr->name, sunname, len) ==0&&
248 s->type == type)
250 unix_lock(s);
251 return(s);
254 return(NULL);
257 static unix_socket *unix_find_socket_byinode(struct inode *i)
259 unix_socket *s;
261 for(s=unix_socket_table[i->i_ino &0xF]; s; s=s->next)
263 struct dentry *dentry = s->protinfo.af_unix.dentry;
265 if(dentry && dentry->d_inode == i)
267 unix_lock(s);
268 return(s);
271 return(NULL);
275 * Delete a unix socket. We have to allow for deferring this on a timer.
278 static voidunix_destroy_timer(unsigned long data)
280 unix_socket *sk=(unix_socket *)data;
281 if(!unix_locked(sk) &&atomic_read(&sk->wmem_alloc) ==0)
283 atomic_dec(&unix_nr_socks);
285 sk_free(sk);
287 /* socket destroyed, decrement count */
288 MOD_DEC_USE_COUNT;
289 return;
293 * Retry;
296 sk->timer.expires=jiffies+sysctl_unix_destroy_delay;/* No real hurry try it every 10 seconds or so */
297 add_timer(&sk->timer);
301 static voidunix_delayed_delete(unix_socket *sk)
303 sk->timer.data=(unsigned long)sk;
304 sk->timer.expires=jiffies+sysctl_unix_delete_delay;/* Normally 1 second after will clean up. After that we try every 10 */
305 sk->timer.function=unix_destroy_timer;
306 add_timer(&sk->timer);
309 static intunix_release_sock(unix_socket *sk)
311 unix_socket *skpair;
313 sk->state_change(sk);
314 sk->dead=1;
315 sk->socket = NULL;
317 if(sk->state == TCP_LISTEN)
318 wake_up_interruptible(&unix_ack_wqueue);
319 if(sk->type == SOCK_DGRAM)
320 wake_up_interruptible(&unix_dgram_wqueue);
322 skpair=unix_peer(sk);
324 if(skpair!=NULL)
326 if(sk->type==SOCK_STREAM &&unix_our_peer(sk, skpair))
328 skpair->data_ready(skpair,0);
329 skpair->shutdown=SHUTDOWN_MASK;/* No more writes*/
331 unix_unlock(skpair);/* It may now die */
334 /* Try to flush out this socket. Throw out buffers at least */
335 unix_destroy_socket(sk);
338 * Fixme: BSD difference: In BSD all sockets connected to use get
339 * ECONNRESET and we die on the spot. In Linux we behave
340 * like files and pipes do and wait for the last
341 * dereference.
343 * Can't we simply set sock->err?
345 * What the above comment does talk about? --ANK(980817)
348 unix_gc();/* Garbage collect fds */
349 return0;
352 static voidunix_destroy_socket(unix_socket *sk)
354 struct sk_buff *skb;
356 unix_remove_socket(sk);
358 while((skb=skb_dequeue(&sk->receive_queue))!=NULL)
360 if(sk->state==TCP_LISTEN)
361 unix_release_sock(skb->sk);
362 /* passed fds are erased in the kfree_skb hook */
363 kfree_skb(skb);
366 if(sk->protinfo.af_unix.dentry!=NULL)
368 dput(sk->protinfo.af_unix.dentry);
369 sk->protinfo.af_unix.dentry=NULL;
372 if(!unix_locked(sk) &&atomic_read(&sk->wmem_alloc) ==0)
374 atomic_dec(&unix_nr_socks);
376 sk_free(sk);
378 /* socket destroyed, decrement count */
379 MOD_DEC_USE_COUNT;
381 else
383 sk->state=TCP_CLOSE;
384 sk->dead=1;
385 unix_delayed_delete(sk);/* Try every so often until buffers are all freed */
390 static intunix_listen(struct socket *sock,int backlog)
392 struct sock *sk = sock->sk;
394 if(sock->state != SS_UNCONNECTED)
395 return(-EINVAL);
396 if(sock->type!=SOCK_STREAM)
397 return-EOPNOTSUPP;/* Only stream sockets accept */
398 if(!sk->protinfo.af_unix.addr)
399 return-EINVAL;/* No listens on an unbound socket */
400 if((unsigned) backlog > SOMAXCONN)
401 backlog = SOMAXCONN;
402 sk->max_ack_backlog=backlog;
403 sk->state=TCP_LISTEN;
404 sock->flags |= SO_ACCEPTCON;
405 /* set credentials so connect can copy them */
406 sk->peercred.pid = current->pid;
407 sk->peercred.uid = current->euid;
408 sk->peercred.gid = current->egid;
409 return0;
412 externstruct proto_ops unix_stream_ops;
413 externstruct proto_ops unix_dgram_ops;
415 static struct sock *unix_create1(struct socket *sock,int stream)
417 struct sock *sk;
419 if(atomic_read(&unix_nr_socks) >=2*max_files)
420 return NULL;
422 MOD_INC_USE_COUNT;
423 sk =sk_alloc(PF_UNIX, GFP_KERNEL,1);
424 if(!sk) {
425 MOD_DEC_USE_COUNT;
426 return NULL;
429 atomic_inc(&unix_nr_socks);
431 sock_init_data(sock,sk);
433 if(stream)
434 sk->write_space = unix_stream_write_space;
436 sk->destruct = unix_destruct_addr;
437 sk->protinfo.af_unix.family=PF_UNIX;
438 sk->protinfo.af_unix.dentry=NULL;
439 init_MUTEX(&sk->protinfo.af_unix.readsem);/* single task reading lock */
440 sk->protinfo.af_unix.list=&unix_sockets_unbound;
441 unix_insert_socket(sk);
443 return sk;
446 static intunix_create(struct socket *sock,int protocol)
448 int stream =0;
450 if(protocol && protocol != PF_UNIX)
451 return-EPROTONOSUPPORT;
453 sock->state = SS_UNCONNECTED;
455 switch(sock->type) {
456 case SOCK_STREAM:
457 sock->ops = &unix_stream_ops;
458 stream =1;
459 break;
461 * Believe it or not BSD has AF_UNIX, SOCK_RAW though
462 * nothing uses it.
464 case SOCK_RAW:
465 sock->type=SOCK_DGRAM;
466 case SOCK_DGRAM:
467 sock->ops = &unix_dgram_ops;
468 break;
469 default:
470 return-ESOCKTNOSUPPORT;
473 returnunix_create1(sock, stream) ?0: -ENOMEM;
476 static intunix_release(struct socket *sock,struct socket *peer)
478 unix_socket *sk = sock->sk;
480 if(!sk)
481 return0;
483 sock->sk = NULL;
484 if(sock->state != SS_UNCONNECTED)
485 sock->state = SS_DISCONNECTING;
487 returnunix_release_sock(sk);
490 static intunix_autobind(struct socket *sock)
492 struct sock *sk = sock->sk;
493 static u32 ordernum =1;
494 struct unix_address * addr;
495 unix_socket *osk;
497 addr =kmalloc(sizeof(*addr) +sizeof(short) +16, GFP_KERNEL);
498 if(!addr)
499 return-ENOMEM;
500 if(sk->protinfo.af_unix.addr || sk->protinfo.af_unix.dentry)
502 kfree(addr);
503 return-EINVAL;
505 memset(addr,0,sizeof(*addr) +sizeof(short) +16);
506 addr->name->sun_family = AF_UNIX;
507 atomic_set(&addr->refcnt,1);
509 retry:
510 addr->len =sprintf(addr->name->sun_path+1,"%08x", ordernum) +1+sizeof(short);
511 addr->hash =unix_hash_fold(csum_partial((void*)addr->name, addr->len,0));
512 ordernum++;
514 if((osk=unix_find_socket_byname(addr->name, addr->len, sock->type,
515 addr->hash)) != NULL)
517 unix_unlock(osk);
518 goto retry;
521 sk->protinfo.af_unix.addr = addr;
522 unix_remove_socket(sk);
523 sk->protinfo.af_unix.list = &unix_socket_table[(addr->hash ^ sk->type)&0xF];
524 unix_insert_socket(sk);
525 return0;
528 static unix_socket *unix_find_other(struct sockaddr_un *sunname,int len,
529 int type,unsigned hash,int*error)
531 unix_socket *u;
533 if(sunname->sun_path[0])
535 struct dentry *dentry;
536 dentry =open_namei(sunname->sun_path,2, S_IFSOCK);
537 if(IS_ERR(dentry)) {
538 *error =PTR_ERR(dentry);
539 return NULL;
541 u=unix_find_socket_byinode(dentry->d_inode);
542 dput(dentry);
543 if(u && u->type != type)
545 *error=-EPROTOTYPE;
546 unix_unlock(u);
547 return NULL;
550 else
551 u=unix_find_socket_byname(sunname, len, type, hash);
553 if(u==NULL)
555 *error=-ECONNREFUSED;
556 return NULL;
558 return u;
562 static intunix_bind(struct socket *sock,struct sockaddr *uaddr,int addr_len)
564 struct sock *sk = sock->sk;
565 struct sockaddr_un *sunaddr=(struct sockaddr_un *)uaddr;
566 struct dentry * dentry;
567 int err;
568 unsigned hash;
569 struct unix_address *addr;
571 if(sk->protinfo.af_unix.addr || sk->protinfo.af_unix.dentry ||
572 sunaddr->sun_family != AF_UNIX)
573 return-EINVAL;
575 if(addr_len==sizeof(short))
576 returnunix_autobind(sock);
578 addr_len =unix_mkname(sunaddr, addr_len, &hash);
579 if(addr_len <0)
580 return addr_len;
582 addr =kmalloc(sizeof(*addr)+addr_len, GFP_KERNEL);
583 if(!addr)
584 return-ENOMEM;
586 /* We slept; recheck ... */
588 if(sk->protinfo.af_unix.addr || sk->protinfo.af_unix.dentry)
590 kfree(addr);
591 return-EINVAL;/* Already bound */
594 memcpy(addr->name, sunaddr, addr_len);
595 addr->len = addr_len;
596 addr->hash = hash;
597 atomic_set(&addr->refcnt,1);
599 if(!sunaddr->sun_path[0])
601 unix_socket *osk =unix_find_socket_byname(sunaddr, addr_len,
602 sk->type, hash);
603 if(osk)
605 unix_unlock(osk);
606 kfree(addr);
607 return-EADDRINUSE;
609 unix_remove_socket(sk);
610 sk->protinfo.af_unix.addr = addr;
611 sk->protinfo.af_unix.list = &unix_socket_table[(hash^sk->type)&0xF];
612 unix_insert_socket(sk);
613 return0;
616 addr->hash = UNIX_HASH_SIZE;
617 sk->protinfo.af_unix.addr = addr;
620 dentry =do_mknod(sunaddr->sun_path, S_IFSOCK|sock->inode->i_mode,0);
621 if(IS_ERR(dentry))
623 err =PTR_ERR(dentry);
624 unix_release_addr(addr);
625 sk->protinfo.af_unix.addr = NULL;
626 if(err==-EEXIST)
627 return-EADDRINUSE;
628 else
629 return err;
631 unix_remove_socket(sk);
632 sk->protinfo.af_unix.list = &unix_socket_table[dentry->d_inode->i_ino &0xF];
633 sk->protinfo.af_unix.dentry = dentry;
634 unix_insert_socket(sk);
636 return0;
639 static intunix_dgram_connect(struct socket *sock,struct sockaddr *addr,
640 int alen,int flags)
642 struct sock *sk = sock->sk;
643 struct sockaddr_un *sunaddr=(struct sockaddr_un*)addr;
644 struct sock *other;
645 unsigned hash;
646 int err;
649 * 1003.1g breaking connected state with AF_UNSPEC
652 if(addr->sa_family==AF_UNSPEC)
654 if(unix_peer(sk))
656 unix_unlock(unix_peer(sk));
657 unix_peer(sk) = NULL;
658 sock->state=SS_UNCONNECTED;
660 return0;
663 alen =unix_mkname(sunaddr, alen, &hash);
664 if(alen <0)
665 return alen;
667 other=unix_find_other(sunaddr, alen, sock->type, hash, &err);
668 if(!other)
669 return err;
670 if(!unix_may_send(sk, other))
672 unix_unlock(other);
673 return-EINVAL;
677 * If it was connected, reconnect.
679 if(unix_peer(sk))
681 unix_unlock(unix_peer(sk));
682 unix_peer(sk)=NULL;
684 unix_peer(sk)=other;
685 if(sock->passcred && !sk->protinfo.af_unix.addr)
686 unix_autobind(sock);
687 return0;
690 static intunix_stream_connect(struct socket *sock,struct sockaddr *uaddr,
691 int addr_len,int flags)
693 struct sockaddr_un *sunaddr=(struct sockaddr_un *)uaddr;
694 struct sock *sk = sock->sk, *newsk;
695 unix_socket *other;
696 struct sk_buff *skb;
697 int err;
698 unsigned hash;
700 addr_len =unix_mkname(sunaddr, addr_len, &hash);
701 if(addr_len <0)
702 return addr_len;
704 /* First of all allocate resources.
705 If we will make it after state checks,
706 we will have to recheck all again in any case.
709 restart:
710 /* Find listening sock */
711 other=unix_find_other(sunaddr, addr_len, sk->type, hash, &err);
713 if(!other)
714 return-ECONNREFUSED;
716 while(other->ack_backlog >= other->max_ack_backlog) {
717 unix_unlock(other);
718 if(other->dead || other->state != TCP_LISTEN)
719 return-ECONNREFUSED;
720 if(flags & O_NONBLOCK)
721 return-EAGAIN;
722 interruptible_sleep_on(&unix_ack_wqueue);
723 if(signal_pending(current))
724 return-ERESTARTSYS;
725 goto restart;
728 /* create new sock for complete connection */
729 newsk =unix_create1(NULL,1);
731 /* Allocate skb for sending to listening sock */
732 skb = NULL;
733 if(newsk)
734 skb =sock_wmalloc(newsk,1,0, GFP_KERNEL);
736 switch(sock->state)
738 case SS_UNCONNECTED:
739 /* This is ok... continue with connect */
740 break;
741 case SS_CONNECTED:
742 /* Socket is already connected */
743 err = -EISCONN;
744 goto out;
745 default:
746 err = -EINVAL;
747 goto out;
750 err = -EINVAL;
751 if(sk->state != TCP_CLOSE)
752 goto out;
754 /* Check that listener is in valid state. */
755 err = -ECONNREFUSED;
756 if(other->dead || other->state != TCP_LISTEN)
757 goto out;
759 err = -ENOMEM;
760 if(newsk == NULL || skb == NULL)
761 goto out;
763 UNIXCB(skb).attr = MSG_SYN;
765 /* set up connecting socket */
766 sock->state=SS_CONNECTED;
767 if(!sk->protinfo.af_unix.addr)
768 unix_autobind(sock);
769 unix_peer(sk)=newsk;
770 unix_lock(sk);
771 sk->state=TCP_ESTABLISHED;
772 /* Set credentials */
773 sk->peercred = other->peercred;
775 /* set up newly created sock */
776 unix_peer(newsk)=sk;
777 unix_lock(newsk);
778 newsk->state=TCP_ESTABLISHED;
779 newsk->type=SOCK_STREAM;
780 newsk->peercred.pid = current->pid;
781 newsk->peercred.uid = current->euid;
782 newsk->peercred.gid = current->egid;
784 /* copy address information from listening to new sock*/
785 if(other->protinfo.af_unix.addr)
787 atomic_inc(&other->protinfo.af_unix.addr->refcnt);
788 newsk->protinfo.af_unix.addr=other->protinfo.af_unix.addr;
790 if(other->protinfo.af_unix.dentry)
791 newsk->protinfo.af_unix.dentry=dget(other->protinfo.af_unix.dentry);
793 /* send info to listening sock */
794 other->ack_backlog++;
795 skb_queue_tail(&other->receive_queue,skb);
796 other->data_ready(other,0);/* Wake up ! */
797 unix_unlock(other);
798 return0;
800 out:
801 if(skb)
802 kfree_skb(skb);
803 if(newsk)
804 unix_destroy_socket(newsk);
805 if(other)
806 unix_unlock(other);
807 return err;
810 static intunix_socketpair(struct socket *socka,struct socket *sockb)
812 struct sock *ska=socka->sk, *skb = sockb->sk;
814 /* Join our sockets back to back */
815 unix_lock(ska);
816 unix_lock(skb);
817 unix_peer(ska)=skb;
818 unix_peer(skb)=ska;
820 if(ska->type != SOCK_DGRAM)
822 ska->state=TCP_ESTABLISHED;
823 skb->state=TCP_ESTABLISHED;
824 socka->state=SS_CONNECTED;
825 sockb->state=SS_CONNECTED;
827 return0;
830 static intunix_accept(struct socket *sock,struct socket *newsock,int flags)
832 unix_socket *sk = sock->sk;
833 unix_socket *newsk = newsock->sk;
834 unix_socket *tsk;
835 struct sk_buff *skb;
837 if(sock->state != SS_UNCONNECTED)
838 return(-EINVAL);
839 if(!(sock->flags & SO_ACCEPTCON))
840 return(-EINVAL);
842 if(sock->type!=SOCK_STREAM)
843 return-EOPNOTSUPP;
844 if(sk->state!=TCP_LISTEN)
845 return-EINVAL;
847 for(;;)
849 skb=skb_dequeue(&sk->receive_queue);
850 if(skb==NULL)
852 if(flags&O_NONBLOCK)
853 return-EAGAIN;
854 interruptible_sleep_on(sk->sleep);
855 if(signal_pending(current))
856 return-ERESTARTSYS;
857 continue;
859 if(!(UNIXCB(skb).attr & MSG_SYN))
861 tsk=skb->sk;
862 tsk->state_change(tsk);
863 kfree_skb(skb);
864 continue;
866 tsk = skb->sk;
867 if(sk->max_ack_backlog == sk->ack_backlog--)
868 wake_up_interruptible(&unix_ack_wqueue);
869 kfree_skb(skb);
870 break;
874 /* attach accepted sock to socket */
875 newsock->state=SS_CONNECTED;
876 newsock->sk=tsk;
877 tsk->sleep=newsk->sleep;
878 tsk->socket=newsock;
880 /* destroy handed sock */
881 newsk->socket = NULL;
882 unix_destroy_socket(newsk);
884 return0;
888 static intunix_getname(struct socket *sock,struct sockaddr *uaddr,int*uaddr_len,int peer)
890 struct sock *sk = sock->sk;
891 struct sockaddr_un *sunaddr=(struct sockaddr_un *)uaddr;
893 if(peer)
895 if(!unix_peer(sk))
896 return-ENOTCONN;
897 sk=unix_peer(sk);
899 if(!sk->protinfo.af_unix.addr)
901 sunaddr->sun_family = AF_UNIX;
902 sunaddr->sun_path[0] =0;
903 *uaddr_len =sizeof(short);
904 return0;/* Not bound */
906 *uaddr_len = sk->protinfo.af_unix.addr->len;
907 memcpy(sunaddr, sk->protinfo.af_unix.addr->name, *uaddr_len);
908 return0;
911 static voidunix_detach_fds(struct scm_cookie *scm,struct sk_buff *skb)
913 int i;
915 scm->fp =UNIXCB(skb).fp;
916 skb->destructor = sock_wfree;
917 UNIXCB(skb).fp = NULL;
919 for(i=scm->fp->count-1; i>=0; i--)
920 unix_notinflight(scm->fp->fp[i]);
923 static voidunix_destruct_fds(struct sk_buff *skb)
925 struct scm_cookie scm;
926 memset(&scm,0,sizeof(scm));
927 unix_detach_fds(&scm, skb);
928 scm_destroy(&scm);
929 sock_wfree(skb);
932 static voidunix_attach_fds(struct scm_cookie *scm,struct sk_buff *skb)
934 int i;
935 for(i=scm->fp->count-1; i>=0; i--)
936 unix_inflight(scm->fp->fp[i]);
937 UNIXCB(skb).fp = scm->fp;
938 skb->destructor = unix_destruct_fds;
939 scm->fp = NULL;
944 * Send AF_UNIX data.
947 static intdo_unix_dgram_sendmsg(struct socket *sock,struct msghdr *msg,int len,
948 struct scm_cookie *scm)
950 struct sock *sk = sock->sk;
951 struct sockaddr_un *sunaddr=msg->msg_name;
952 unix_socket *other;
953 int namelen =0;/* fake GCC */
954 int err;
955 unsigned hash;
956 struct sk_buff *skb;
958 if(msg->msg_flags&MSG_OOB)
959 return-EOPNOTSUPP;
961 if(msg->msg_flags&~(MSG_DONTWAIT|MSG_NOSIGNAL))
962 return-EINVAL;
964 if(msg->msg_namelen) {
965 namelen =unix_mkname(sunaddr, msg->msg_namelen, &hash);
966 if(namelen <0)
967 return namelen;
968 }else{
969 sunaddr = NULL;
970 if(!unix_peer(sk))
971 return-ENOTCONN;
974 if(sock->passcred && !sk->protinfo.af_unix.addr)
975 unix_autobind(sock);
977 skb =sock_alloc_send_skb(sk, len,0, msg->msg_flags&MSG_DONTWAIT, &err);
978 if(skb==NULL)
979 goto out;
981 memcpy(UNIXCREDS(skb), &scm->creds,sizeof(struct ucred));
982 UNIXCB(skb).attr = msg->msg_flags;
983 if(scm->fp)
984 unix_attach_fds(scm, skb);
986 skb->h.raw = skb->data;
987 err =memcpy_fromiovec(skb_put(skb,len), msg->msg_iov, len);
988 if(err)
989 goto out_free;
991 other =unix_peer(sk);
992 if(other && other->dead)
995 * Check with 1003.1g - what should
996 * datagram error
998 dead:
999 unix_unlock(other);
1000 unix_peer(sk)=NULL;
1001 other = NULL;
1002 err = -ECONNRESET;
1003 if(sunaddr == NULL)
1004 goto out_free;
1006 if(!other)
1008 other =unix_find_other(sunaddr, namelen, sk->type, hash, &err);
1009 if(other==NULL)
1010 goto out_free;
1011 err = -EINVAL;
1012 if(!unix_may_send(sk, other))
1013 goto out_unlock;
1016 while(skb_queue_len(&other->receive_queue) >=
1017 sysctl_unix_max_dgram_qlen)
1019 if(sock->file->f_flags & O_NONBLOCK)
1021 err = -EAGAIN;
1022 goto out_unlock;
1024 interruptible_sleep_on(&unix_dgram_wqueue);
1025 if(other->dead)
1026 goto dead;
1027 if(sk->shutdown & SEND_SHUTDOWN)
1029 err = -EPIPE;
1030 goto out_unlock;
1032 if(signal_pending(current))
1034 err = -ERESTARTSYS;
1035 goto out_unlock;
1039 skb_queue_tail(&other->receive_queue, skb);
1040 other->data_ready(other,len);
1042 if(!unix_peer(sk))
1043 unix_unlock(other);
1045 return len;
1047 out_unlock:
1048 unix_unlock(other);
1049 out_free:
1050 kfree_skb(skb);
1051 out:
1052 return err;
1055 static intunix_dgram_sendmsg(struct socket *sock,struct msghdr *msg,int len,
1056 struct scm_cookie *scm)
1058 int retval;
1060 lock_kernel();
1061 retval =do_unix_dgram_sendmsg(sock, msg, len, scm);
1062 unlock_kernel();
1063 return retval;
1066 static intdo_unix_stream_sendmsg(struct socket *sock,struct msghdr *msg,int len,
1067 struct scm_cookie *scm)
1069 struct sock *sk = sock->sk;
1070 unix_socket *other;
1071 struct sockaddr_un *sunaddr=msg->msg_name;
1072 int err,size;
1073 struct sk_buff *skb;
1074 int limit=0;
1075 int sent=0;
1077 if(sock->flags & SO_ACCEPTCON)
1078 return(-EINVAL);
1080 if(msg->msg_flags&MSG_OOB)
1081 return-EOPNOTSUPP;
1083 if(msg->msg_flags&~(MSG_DONTWAIT|MSG_NOSIGNAL))
1084 return-EINVAL;
1086 if(msg->msg_namelen) {
1087 if(sk->state==TCP_ESTABLISHED)
1088 return-EISCONN;
1089 else
1090 return-EOPNOTSUPP;
1091 }else{
1092 sunaddr = NULL;
1093 if(!unix_peer(sk))
1094 return-ENOTCONN;
1097 if(sk->shutdown&SEND_SHUTDOWN) {
1098 if(!(msg->msg_flags&MSG_NOSIGNAL))
1099 send_sig(SIGPIPE,current,0);
1100 return-EPIPE;
1103 while(sent < len)
1106 * Optimisation for the fact that under 0.01% of X messages typically
1107 * need breaking up.
1110 size=len-sent;
1112 /* Keep two messages in the pipe so it schedules better */
1113 if(size > sk->sndbuf/2-16)
1114 size = sk->sndbuf/2-16;
1117 * Keep to page sized kmalloc()'s as various people
1118 * have suggested. Big mallocs stress the vm too
1119 * much.
1122 if(size >4096-16)
1123 limit =4096-16;/* Fall back to a page if we can't grab a big buffer this instant */
1124 else
1125 limit =0;/* Otherwise just grab and wait */
1128 * Grab a buffer
1131 skb=sock_alloc_send_skb(sk,size,limit,msg->msg_flags&MSG_DONTWAIT, &err);
1133 if(skb==NULL)
1135 if(!sent)
1136 sent = err;
1137 goto out;
1141 * If you pass two values to the sock_alloc_send_skb
1142 * it tries to grab the large buffer with GFP_BUFFER
1143 * (which can fail easily), and if it fails grab the
1144 * fallback size buffer which is under a page and will
1145 * succeed. [Alan]
1147 size =min(size,skb_tailroom(skb));
1149 memcpy(UNIXCREDS(skb), &scm->creds,sizeof(struct ucred));
1150 UNIXCB(skb).attr = msg->msg_flags;
1151 if(scm->fp)
1152 unix_attach_fds(scm, skb);
1154 if(memcpy_fromiovec(skb_put(skb,size), msg->msg_iov, size)) {
1155 kfree_skb(skb);
1156 if(!sent)
1157 sent = -EFAULT;
1158 goto out;
1161 other=unix_peer(sk);
1163 if(other->dead || (sk->shutdown & SEND_SHUTDOWN))
1165 kfree_skb(skb);
1166 if(sent)
1167 goto out;
1168 if(!(msg->msg_flags&MSG_NOSIGNAL))
1169 send_sig(SIGPIPE,current,0);
1170 sent = -EPIPE;
1171 goto out;
1174 skb_queue_tail(&other->receive_queue, skb);
1175 other->data_ready(other,size);
1176 sent+=size;
1178 out:
1179 return sent;
1182 static intunix_stream_sendmsg(struct socket *sock,struct msghdr *msg,int len,
1183 struct scm_cookie *scm)
1185 int retval;
1187 lock_kernel();
1188 retval =do_unix_stream_sendmsg(sock, msg, len, scm);
1189 unlock_kernel();
1190 return retval;
1194 * Sleep until data has arrive. But check for races..
1197 static voidunix_data_wait(unix_socket * sk)
1199 if(!skb_peek(&sk->receive_queue))
1201 sk->socket->flags |= SO_WAITDATA;
1202 interruptible_sleep_on(sk->sleep);
1203 sk->socket->flags &= ~SO_WAITDATA;
1207 static intdo_unix_dgram_recvmsg(struct socket *sock,struct msghdr *msg,int size,
1208 int flags,struct scm_cookie *scm)
1210 struct sock *sk = sock->sk;
1211 int noblock = flags & MSG_DONTWAIT;
1212 struct sk_buff *skb;
1213 int err;
1215 if(flags&MSG_OOB)
1216 return-EOPNOTSUPP;
1218 msg->msg_namelen =0;
1220 skb =skb_recv_datagram(sk, flags, noblock, &err);
1221 if(!skb)
1222 goto out;
1225 * sysctl_unix_max_dgram_qlen may change over the time we blocked
1226 * in the waitqueue so we must wakeup every time we shrink the
1227 * receiver queue. -arca
1229 wake_up_interruptible(&unix_dgram_wqueue);
1231 if(msg->msg_name)
1233 msg->msg_namelen =sizeof(short);
1234 if(skb->sk->protinfo.af_unix.addr)
1236 msg->msg_namelen=skb->sk->protinfo.af_unix.addr->len;
1237 memcpy(msg->msg_name,
1238 skb->sk->protinfo.af_unix.addr->name,
1239 skb->sk->protinfo.af_unix.addr->len);
1243 if(size > skb->len)
1244 size = skb->len;
1245 else if(size < skb->len)
1246 msg->msg_flags |= MSG_TRUNC;
1248 err =skb_copy_datagram_iovec(skb,0, msg->msg_iov, size);
1249 if(err)
1250 goto out_free;
1252 scm->creds = *UNIXCREDS(skb);
1254 if(!(flags & MSG_PEEK))
1256 if(UNIXCB(skb).fp)
1257 unix_detach_fds(scm, skb);
1259 else
1261 /* It is questionable: on PEEK we could:
1262 - do not return fds - good, but too simple 8)
1263 - return fds, and do not return them on read (old strategy,
1264 apparently wrong)
1265 - clone fds (I choosed it for now, it is the most universal
1266 solution)
1268 POSIX 1003.1g does not actually define this clearly
1269 at all. POSIX 1003.1g doesn't define a lot of things
1270 clearly however!
1273 if(UNIXCB(skb).fp)
1274 scm->fp =scm_fp_dup(UNIXCB(skb).fp);
1276 err = size;
1278 out_free:
1279 skb_free_datagram(sk,skb);
1280 out:
1281 return err;
1284 static intunix_dgram_recvmsg(struct socket *sock,struct msghdr *msg,int size,
1285 int flags,struct scm_cookie *scm)
1287 int retval;
1289 lock_kernel();
1290 retval =do_unix_dgram_recvmsg(sock, msg, size, flags, scm);
1291 unlock_kernel();
1292 return retval;
1295 static intdo_unix_stream_recvmsg(struct socket *sock,struct msghdr *msg,int size,
1296 int flags,struct scm_cookie *scm)
1298 struct sock *sk = sock->sk;
1299 int noblock = flags & MSG_DONTWAIT;
1300 struct sockaddr_un *sunaddr=msg->msg_name;
1301 int copied =0;
1302 int check_creds =0;
1303 int target =1;
1305 if(sock->flags & SO_ACCEPTCON)
1306 return(-EINVAL);
1308 if(flags&MSG_OOB)
1309 return-EOPNOTSUPP;
1310 if(flags&MSG_WAITALL)
1311 target = size;
1313 msg->msg_namelen =0;
1315 /* Lock the socket to prevent queue disordering
1316 * while sleeps in memcpy_tomsg
1319 down(&sk->protinfo.af_unix.readsem);
1323 int chunk;
1324 struct sk_buff *skb;
1326 skb=skb_dequeue(&sk->receive_queue);
1327 if(skb==NULL)
1329 if(copied >= target)
1330 break;
1333 * POSIX 1003.1g mandates this order.
1336 if(sk->err)
1338 up(&sk->protinfo.af_unix.readsem);
1339 returnsock_error(sk);
1342 if(sk->shutdown & RCV_SHUTDOWN)
1343 break;
1344 up(&sk->protinfo.af_unix.readsem);
1345 if(noblock)
1346 return-EAGAIN;
1347 unix_data_wait(sk);
1348 if(signal_pending(current))
1349 return-ERESTARTSYS;
1350 down(&sk->protinfo.af_unix.readsem);
1351 continue;
1354 /* Never glue messages from different writers */
1355 if(check_creds &&
1356 memcmp(UNIXCREDS(skb), &scm->creds,sizeof(scm->creds)) !=0)
1358 skb_queue_head(&sk->receive_queue, skb);
1359 break;
1362 /* Copy address just once */
1363 if(sunaddr)
1365 msg->msg_namelen =sizeof(short);
1366 if(skb->sk->protinfo.af_unix.addr)
1368 msg->msg_namelen=skb->sk->protinfo.af_unix.addr->len;
1369 memcpy(sunaddr,
1370 skb->sk->protinfo.af_unix.addr->name,
1371 skb->sk->protinfo.af_unix.addr->len);
1373 sunaddr = NULL;
1376 chunk =min(skb->len, size);
1377 if(memcpy_toiovec(msg->msg_iov, skb->data, chunk)) {
1378 skb_queue_head(&sk->receive_queue, skb);
1379 if(copied ==0)
1380 copied = -EFAULT;
1381 break;
1383 copied += chunk;
1384 size -= chunk;
1386 /* Copy credentials */
1387 scm->creds = *UNIXCREDS(skb);
1388 check_creds =1;
1390 /* Mark read part of skb as used */
1391 if(!(flags & MSG_PEEK))
1393 skb_pull(skb, chunk);
1395 if(UNIXCB(skb).fp)
1396 unix_detach_fds(scm, skb);
1398 /* put the skb back if we didn't use it up.. */
1399 if(skb->len)
1401 skb_queue_head(&sk->receive_queue, skb);
1402 break;
1405 kfree_skb(skb);
1407 if(scm->fp)
1408 break;
1410 else
1412 /* It is questionable, see note in unix_dgram_recvmsg.
1415 if(UNIXCB(skb).fp)
1416 scm->fp =scm_fp_dup(UNIXCB(skb).fp);
1418 /* put message back and return */
1419 skb_queue_head(&sk->receive_queue, skb);
1420 break;
1422 }while(size);
1424 up(&sk->protinfo.af_unix.readsem);
1425 return copied;
1428 static intunix_stream_recvmsg(struct socket *sock,struct msghdr *msg,int size,
1429 int flags,struct scm_cookie *scm)
1431 int retval;
1433 lock_kernel();
1434 retval =do_unix_stream_recvmsg(sock, msg, size, flags, scm);
1435 unlock_kernel();
1436 return retval;
1439 static intunix_shutdown(struct socket *sock,int mode)
1441 struct sock *sk = sock->sk;
1442 unix_socket *other=unix_peer(sk);
1444 mode = (mode+1)&(RCV_SHUTDOWN|SEND_SHUTDOWN);
1446 if(mode) {
1447 sk->shutdown |= mode;
1448 sk->state_change(sk);
1449 if(other && sk->type == SOCK_STREAM &&
1450 unix_our_peer(sk, other)) {
1451 int peer_mode =0;
1453 if(mode&RCV_SHUTDOWN)
1454 peer_mode |= SEND_SHUTDOWN;
1455 if(mode&SEND_SHUTDOWN)
1456 peer_mode |= RCV_SHUTDOWN;
1457 other->shutdown |= peer_mode;
1458 if(peer_mode&RCV_SHUTDOWN)
1459 other->data_ready(other,0);
1460 else
1461 other->state_change(other);
1464 return0;
1468 static intunix_ioctl(struct socket *sock,unsigned int cmd,unsigned long arg)
1470 struct sock *sk = sock->sk;
1471 long amount=0;
1473 switch(cmd)
1476 case TIOCOUTQ:
1477 amount = sk->sndbuf -atomic_read(&sk->wmem_alloc);
1478 if(amount<0)
1479 amount=0;
1480 returnput_user(amount, (int*)arg);
1481 case TIOCINQ:
1483 struct sk_buff *skb;
1484 if(sk->state==TCP_LISTEN)
1485 return-EINVAL;
1487 * These two are safe on current systems as
1488 * only user tasks fiddle here
1490 if((skb=skb_peek(&sk->receive_queue))!=NULL)
1491 amount=skb->len;
1492 returnput_user(amount, (int*)arg);
1495 default:
1496 return-EINVAL;
1498 /*NOTREACHED*/
1499 return(0);
1502 static unsigned intunix_poll(struct file * file,struct socket *sock, poll_table *wait)
1504 struct sock *sk = sock->sk;
1505 unsigned int mask;
1507 poll_wait(file, sk->sleep, wait);
1508 mask =0;
1510 /* exceptional events? */
1511 if(sk->err)
1512 mask |= POLLERR;
1513 if(sk->shutdown & RCV_SHUTDOWN)
1514 mask |= POLLHUP;
1516 /* readable? */
1517 if(!skb_queue_empty(&sk->receive_queue))
1518 mask |= POLLIN | POLLRDNORM;
1520 /* Connection-based need to check for termination and startup */
1521 if(sk->type == SOCK_STREAM && sk->state==TCP_CLOSE)
1522 mask |= POLLHUP;
1525 * we set writable also when the other side has shut down the
1526 * connection. This prevents stuck sockets.
1528 if(sk->sndbuf - (int)atomic_read(&sk->wmem_alloc) >= MIN_WRITE_SPACE)
1529 mask |= POLLOUT | POLLWRNORM | POLLWRBAND;
1531 return mask;
1534 static voidunix_stream_write_space(struct sock *sk)
1536 if(sk->dead)
1537 return;
1538 wake_up_interruptible(sk->sleep);
1539 if(sk->sndbuf - (int)atomic_read(&sk->wmem_alloc) >= MIN_WRITE_SPACE)
1540 sock_wake_async(sk->socket,2);
1543 #ifdef CONFIG_PROC_FS
1544 static intunix_read_proc(char*buffer,char**start, off_t offset,
1545 int length,int*eof,void*data)
1547 off_t pos=0;
1548 off_t begin=0;
1549 int len=0;
1550 int i;
1551 unix_socket *s;
1553 len+=sprintf(buffer,"Num RefCount Protocol Flags Type St "
1554 "Inode Path\n");
1556 forall_unix_sockets(i,s)
1558 len+=sprintf(buffer+len,"%p: %08X %08X %08lX %04X %02X %5ld",
1560 atomic_read(ulock(s)),
1562 s->socket ? s->socket->flags :0,
1563 s->type,
1564 s->socket ? s->socket->state :
1565 (s->state == TCP_ESTABLISHED ?
1566 SS_CONNECTING : SS_DISCONNECTING),
1567 s->socket ? s->socket->inode->i_ino :0);
1569 if(s->protinfo.af_unix.addr)
1571 buffer[len++] =' ';
1572 memcpy(buffer+len, s->protinfo.af_unix.addr->name->sun_path,
1573 s->protinfo.af_unix.addr->len-sizeof(short));
1574 if(!UNIX_ABSTRACT(s))
1575 len--;
1576 else
1577 buffer[len] ='@';
1578 len += s->protinfo.af_unix.addr->len -sizeof(short);
1580 buffer[len++]='\n';
1582 pos = begin + len;
1583 if(pos<offset)
1585 len=0;
1586 begin=pos;
1588 if(pos>offset+length)
1589 goto done;
1591 *eof =1;
1592 done:
1593 *start=buffer+(offset-begin);
1594 len-=(offset-begin);
1595 if(len>length)
1596 len=length;
1597 if(len <0)
1598 len =0;
1599 return len;
1601 #endif
1603 struct proto_ops unix_stream_ops = {
1604 PF_UNIX,
1606 sock_no_dup,
1607 unix_release,
1608 unix_bind,
1609 unix_stream_connect,
1610 unix_socketpair,
1611 unix_accept,
1612 unix_getname,
1613 unix_poll,
1614 unix_ioctl,
1615 unix_listen,
1616 unix_shutdown,
1617 sock_no_setsockopt,
1618 sock_no_getsockopt,
1619 sock_no_fcntl,
1620 unix_stream_sendmsg,
1621 unix_stream_recvmsg
1624 struct proto_ops unix_dgram_ops = {
1625 PF_UNIX,
1627 sock_no_dup,
1628 unix_release,
1629 unix_bind,
1630 unix_dgram_connect,
1631 unix_socketpair,
1632 sock_no_accept,
1633 unix_getname,
1634 datagram_poll,
1635 unix_ioctl,
1636 sock_no_listen,
1637 unix_shutdown,
1638 sock_no_setsockopt,
1639 sock_no_getsockopt,
1640 sock_no_fcntl,
1641 unix_dgram_sendmsg,
1642 unix_dgram_recvmsg
1645 struct net_proto_family unix_family_ops = {
1646 PF_UNIX,
1647 unix_create
1650 #ifdef MODULE
1651 #ifdef CONFIG_SYSCTL
1652 externvoidunix_sysctl_register(void);
1653 externvoidunix_sysctl_unregister(void);
1654 #endif
1656 intinit_module(void)
1657 #else
1658 __initfunc(voidunix_proto_init(struct net_proto *pro))
1659 #endif
1661 struct sk_buff *dummy_skb;
1662 struct proc_dir_entry *ent;
1664 printk(KERN_INFO "NET4: Unix domain sockets 1.0 for Linux NET4.0.\n");
1665 if(sizeof(struct unix_skb_parms) >sizeof(dummy_skb->cb))
1667 printk(KERN_CRIT "unix_proto_init: panic\n");
1668 #ifdef MODULE
1669 return-1;
1670 #else
1671 return;
1672 #endif
1674 sock_register(&unix_family_ops);
1675 #ifdef CONFIG_PROC_FS
1676 ent =create_proc_entry("net/unix",0,0);
1677 ent->read_proc = unix_read_proc;
1678 #endif
1680 #ifdef MODULE
1681 #ifdef CONFIG_SYSCTL
1682 unix_sysctl_register();
1683 #endif
1685 return0;
1686 #endif
1689 #ifdef MODULE
1690 voidcleanup_module(void)
1692 sock_unregister(PF_UNIX);
1693 #ifdef CONFIG_SYSCTL
1694 unix_sysctl_unregister();
1695 #endif
1696 #ifdef CONFIG_PROC_FS
1697 remove_proc_entry("net/unix",0);
1698 #endif
1700 #endif
1703 * Local variables:
1704 * compile-command: "gcc -g -D__KERNEL__ -Wall -O6 -I/usr/src/linux/include -c af_unix.c"
1705 * End:
close