blob: ca68e2cef23027fc545d3f649e48e68361620f12 [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);
Eric Dumazet25888e32010-11-25 04:11:39 +000013extern struct sock *unix_get_socket(struct file *filp);
Pavel Emelyanovfa7ff562011-12-15 02:44:03 +000014extern struct sock *unix_peer_get(struct sock *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
16#define UNIX_HASH_SIZE 256
17
Pavel Emelyanov9305cfa2007-11-10 22:06:01 -080018extern unsigned int unix_tot_inflight;
Pavel Emelyanovfa7ff562011-12-15 02:44:03 +000019extern spinlock_t unix_table_lock;
20extern struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
Linus Torvalds1da177e2005-04-16 15:20:36 -070022struct unix_address {
23 atomic_t refcnt;
24 int len;
25 unsigned hash;
26 struct sockaddr_un name[0];
27};
28
29struct unix_skb_parms {
Eric W. Biederman7361c362010-06-13 03:34:33 +000030 struct pid *pid; /* Skb credentials */
31 const struct cred *cred;
Linus Torvalds1da177e2005-04-16 15:20:36 -070032 struct scm_fp_list *fp; /* Passed files */
Catherine Zhang877ce7c2006-06-29 12:27:47 -070033#ifdef CONFIG_SECURITY_NETWORK
Catherine Zhangdc49c1f2006-08-02 14:12:06 -070034 u32 secid; /* Security ID */
Catherine Zhang877ce7c2006-06-29 12:27:47 -070035#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070036};
37
Eric Dumazet43815482010-04-29 11:01:49 +000038#define UNIXCB(skb) (*(struct unix_skb_parms *)&((skb)->cb))
Catherine Zhangdc49c1f2006-08-02 14:12:06 -070039#define UNIXSID(skb) (&UNIXCB((skb)).secid)
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
David S. Miller1c92b4e2007-05-31 13:24:26 -070041#define unix_state_lock(s) spin_lock(&unix_sk(s)->lock)
42#define unix_state_unlock(s) spin_unlock(&unix_sk(s)->lock)
43#define unix_state_lock_nested(s) \
Ingo Molnara09785a2006-07-03 00:25:12 -070044 spin_lock_nested(&unix_sk(s)->lock, \
45 SINGLE_DEPTH_NESTING)
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
Linus Torvalds1da177e2005-04-16 15:20:36 -070047/* The AF_UNIX socket */
48struct unix_sock {
49 /* WARNING: sk has to be the first member */
50 struct sock sk;
Eric Dumazet43815482010-04-29 11:01:49 +000051 struct unix_address *addr;
Al Viro40ffe672012-03-14 21:54:32 -040052 struct path path;
Ingo Molnar57b47a52006-03-20 22:35:41 -080053 struct mutex readlock;
Eric Dumazet43815482010-04-29 11:01:49 +000054 struct sock *peer;
55 struct sock *other;
Miklos Szeredi1fd05ba2007-07-11 14:22:39 -070056 struct list_head link;
Eric Dumazet43815482010-04-29 11:01:49 +000057 atomic_long_t inflight;
58 spinlock_t lock;
Miklos Szeredi1fd05ba2007-07-11 14:22:39 -070059 unsigned int gc_candidate : 1;
Miklos Szeredi62093442008-11-09 15:23:57 +010060 unsigned int gc_maybe_cycle : 1;
Eric Dumazet25888e32010-11-25 04:11:39 +000061 unsigned char recursion_level;
Eric Dumazet43815482010-04-29 11:01:49 +000062 struct socket_wq peer_wq;
Linus Torvalds1da177e2005-04-16 15:20:36 -070063};
64#define unix_sk(__sk) ((struct unix_sock *)__sk)
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030065
Eric Dumazet43815482010-04-29 11:01:49 +000066#define peer_wait peer_wq.wait
67
Pavel Emelyanov885ee742011-12-30 00:54:11 +000068long unix_inq_len(struct sock *sk);
69long unix_outq_len(struct sock *sk);
70
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030071#ifdef CONFIG_SYSCTL
Pavel Emelyanov97577e32007-12-01 23:40:40 +110072extern int unix_sysctl_register(struct net *net);
73extern void unix_sysctl_unregister(struct net *net);
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030074#else
Pavel Emelyanov97577e32007-12-01 23:40:40 +110075static inline int unix_sysctl_register(struct net *net) { return 0; }
76static inline void unix_sysctl_unregister(struct net *net) {}
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030077#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070078#endif