blob: 2dfa96b0575e638233475bd7af33a457319dd1c9 [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);
12
13#define UNIX_HASH_SIZE 256
14
Pavel Emelyanov9305cfa2007-11-10 22:06:01 -080015extern unsigned int unix_tot_inflight;
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
Linus Torvalds1da177e2005-04-16 15:20:36 -070017struct unix_address {
18 atomic_t refcnt;
19 int len;
20 unsigned hash;
21 struct sockaddr_un name[0];
22};
23
24struct unix_skb_parms {
25 struct ucred creds; /* Skb credentials */
26 struct scm_fp_list *fp; /* Passed files */
Catherine Zhang877ce7c2006-06-29 12:27:47 -070027#ifdef CONFIG_SECURITY_NETWORK
Catherine Zhangdc49c1f2006-08-02 14:12:06 -070028 u32 secid; /* Security ID */
Catherine Zhang877ce7c2006-06-29 12:27:47 -070029#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070030};
31
32#define UNIXCB(skb) (*(struct unix_skb_parms*)&((skb)->cb))
33#define UNIXCREDS(skb) (&UNIXCB((skb)).creds)
Catherine Zhangdc49c1f2006-08-02 14:12:06 -070034#define UNIXSID(skb) (&UNIXCB((skb)).secid)
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
David S. Miller1c92b4e2007-05-31 13:24:26 -070036#define unix_state_lock(s) spin_lock(&unix_sk(s)->lock)
37#define unix_state_unlock(s) spin_unlock(&unix_sk(s)->lock)
38#define unix_state_lock_nested(s) \
Ingo Molnara09785a2006-07-03 00:25:12 -070039 spin_lock_nested(&unix_sk(s)->lock, \
40 SINGLE_DEPTH_NESTING)
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
42#ifdef __KERNEL__
43/* The AF_UNIX socket */
44struct unix_sock {
45 /* WARNING: sk has to be the first member */
46 struct sock sk;
47 struct unix_address *addr;
48 struct dentry *dentry;
49 struct vfsmount *mnt;
Ingo Molnar57b47a52006-03-20 22:35:41 -080050 struct mutex readlock;
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 struct sock *peer;
52 struct sock *other;
Miklos Szeredi1fd05ba2007-07-11 14:22:39 -070053 struct list_head link;
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 atomic_t inflight;
Benjamin LaHaisefd19f322006-01-03 14:10:46 -080055 spinlock_t lock;
Miklos Szeredi1fd05ba2007-07-11 14:22:39 -070056 unsigned int gc_candidate : 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 wait_queue_head_t peer_wait;
58};
59#define unix_sk(__sk) ((struct unix_sock *)__sk)
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030060
61#ifdef CONFIG_SYSCTL
Pavel Emelyanov97577e32007-12-01 23:40:40 +110062extern int unix_sysctl_register(struct net *net);
63extern void unix_sysctl_unregister(struct net *net);
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030064#else
Pavel Emelyanov97577e32007-12-01 23:40:40 +110065static inline int unix_sysctl_register(struct net *net) { return 0; }
66static inline void unix_sysctl_unregister(struct net *net) {}
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030067#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070068#endif
69#endif