blob: 1614d78c60ed2c4b616b530b89f8247addbcc17f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef __LINUX_NET_AFUNIX_H
2#define __LINUX_NET_AFUNIX_H
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -03003
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -03004#include <linux/socket.h>
5#include <linux/un.h>
Ingo Molnar57b47a52006-03-20 22:35:41 -08006#include <linux/mutex.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -03007#include <net/sock.h>
8
Linus Torvalds1da177e2005-04-16 15:20:36 -07009extern void unix_inflight(struct file *fp);
10extern void unix_notinflight(struct file *fp);
11extern void unix_gc(void);
dann frazier5f23b732008-11-26 15:32:27 -080012extern void wait_for_unix_gc(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070013
14#define UNIX_HASH_SIZE 256
15
Pavel Emelyanov9305cfa2007-11-10 22:06:01 -080016extern unsigned int unix_tot_inflight;
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
Linus Torvalds1da177e2005-04-16 15:20:36 -070018struct unix_address {
19 atomic_t refcnt;
20 int len;
21 unsigned hash;
22 struct sockaddr_un name[0];
23};
24
25struct unix_skb_parms {
26 struct ucred creds; /* Skb credentials */
27 struct scm_fp_list *fp; /* Passed files */
Catherine Zhang877ce7c2006-06-29 12:27:47 -070028#ifdef CONFIG_SECURITY_NETWORK
Catherine Zhangdc49c1f2006-08-02 14:12:06 -070029 u32 secid; /* Security ID */
Catherine Zhang877ce7c2006-06-29 12:27:47 -070030#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070031};
32
33#define UNIXCB(skb) (*(struct unix_skb_parms*)&((skb)->cb))
34#define UNIXCREDS(skb) (&UNIXCB((skb)).creds)
Catherine Zhangdc49c1f2006-08-02 14:12:06 -070035#define UNIXSID(skb) (&UNIXCB((skb)).secid)
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
David S. Miller1c92b4e2007-05-31 13:24:26 -070037#define unix_state_lock(s) spin_lock(&unix_sk(s)->lock)
38#define unix_state_unlock(s) spin_unlock(&unix_sk(s)->lock)
39#define unix_state_lock_nested(s) \
Ingo Molnara09785a2006-07-03 00:25:12 -070040 spin_lock_nested(&unix_sk(s)->lock, \
41 SINGLE_DEPTH_NESTING)
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43#ifdef __KERNEL__
44/* The AF_UNIX socket */
45struct unix_sock {
46 /* WARNING: sk has to be the first member */
47 struct sock sk;
48 struct unix_address *addr;
49 struct dentry *dentry;
50 struct vfsmount *mnt;
Ingo Molnar57b47a52006-03-20 22:35:41 -080051 struct mutex readlock;
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 struct sock *peer;
53 struct sock *other;
Miklos Szeredi1fd05ba2007-07-11 14:22:39 -070054 struct list_head link;
Al Viro516e0cc2008-07-26 00:39:17 -040055 atomic_long_t inflight;
Benjamin LaHaisefd19f322006-01-03 14:10:46 -080056 spinlock_t lock;
Miklos Szeredi1fd05ba2007-07-11 14:22:39 -070057 unsigned int gc_candidate : 1;
Miklos Szeredi62093442008-11-09 15:23:57 +010058 unsigned int gc_maybe_cycle : 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 wait_queue_head_t peer_wait;
60};
61#define unix_sk(__sk) ((struct unix_sock *)__sk)
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030062
63#ifdef CONFIG_SYSCTL
Pavel Emelyanov97577e32007-12-01 23:40:40 +110064extern int unix_sysctl_register(struct net *net);
65extern void unix_sysctl_unregister(struct net *net);
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030066#else
Pavel Emelyanov97577e32007-12-01 23:40:40 +110067static inline int unix_sysctl_register(struct net *net) { return 0; }
68static inline void unix_sysctl_unregister(struct net *net) {}
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030069#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070070#endif
71#endif