Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef __LINUX_NET_AFUNIX_H |
| 2 | #define __LINUX_NET_AFUNIX_H |
Arnaldo Carvalho de Melo | 2038073 | 2005-08-16 02:18:02 -0300 | [diff] [blame] | 3 | |
Arnaldo Carvalho de Melo | 2038073 | 2005-08-16 02:18:02 -0300 | [diff] [blame] | 4 | #include <linux/socket.h> |
| 5 | #include <linux/un.h> |
Ingo Molnar | 57b47a5 | 2006-03-20 22:35:41 -0800 | [diff] [blame] | 6 | #include <linux/mutex.h> |
Arnaldo Carvalho de Melo | 2038073 | 2005-08-16 02:18:02 -0300 | [diff] [blame] | 7 | #include <net/sock.h> |
| 8 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | extern void unix_inflight(struct file *fp); |
| 10 | extern void unix_notinflight(struct file *fp); |
| 11 | extern void unix_gc(void); |
dann frazier | 5f23b73 | 2008-11-26 15:32:27 -0800 | [diff] [blame] | 12 | extern void wait_for_unix_gc(void); |
Eric Dumazet | 25888e3 | 2010-11-25 04:11:39 +0000 | [diff] [blame] | 13 | extern struct sock *unix_get_socket(struct file *filp); |
Pavel Emelyanov | fa7ff56 | 2011-12-15 02:44:03 +0000 | [diff] [blame] | 14 | extern struct sock *unix_peer_get(struct sock *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | |
| 16 | #define UNIX_HASH_SIZE 256 |
| 17 | |
Pavel Emelyanov | 9305cfa | 2007-11-10 22:06:01 -0800 | [diff] [blame] | 18 | extern unsigned int unix_tot_inflight; |
Pavel Emelyanov | fa7ff56 | 2011-12-15 02:44:03 +0000 | [diff] [blame] | 19 | extern spinlock_t unix_table_lock; |
| 20 | extern struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | struct unix_address { |
| 23 | atomic_t refcnt; |
| 24 | int len; |
| 25 | unsigned hash; |
| 26 | struct sockaddr_un name[0]; |
| 27 | }; |
| 28 | |
| 29 | struct unix_skb_parms { |
Eric W. Biederman | 7361c36 | 2010-06-13 03:34:33 +0000 | [diff] [blame] | 30 | struct pid *pid; /* Skb credentials */ |
| 31 | const struct cred *cred; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | struct scm_fp_list *fp; /* Passed files */ |
Catherine Zhang | 877ce7c | 2006-06-29 12:27:47 -0700 | [diff] [blame] | 33 | #ifdef CONFIG_SECURITY_NETWORK |
Catherine Zhang | dc49c1f | 2006-08-02 14:12:06 -0700 | [diff] [blame] | 34 | u32 secid; /* Security ID */ |
Catherine Zhang | 877ce7c | 2006-06-29 12:27:47 -0700 | [diff] [blame] | 35 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | }; |
| 37 | |
Eric Dumazet | 4381548 | 2010-04-29 11:01:49 +0000 | [diff] [blame] | 38 | #define UNIXCB(skb) (*(struct unix_skb_parms *)&((skb)->cb)) |
Catherine Zhang | dc49c1f | 2006-08-02 14:12:06 -0700 | [diff] [blame] | 39 | #define UNIXSID(skb) (&UNIXCB((skb)).secid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
David S. Miller | 1c92b4e | 2007-05-31 13:24:26 -0700 | [diff] [blame] | 41 | #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 Molnar | a09785a | 2006-07-03 00:25:12 -0700 | [diff] [blame] | 44 | spin_lock_nested(&unix_sk(s)->lock, \ |
| 45 | SINGLE_DEPTH_NESTING) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | /* The AF_UNIX socket */ |
| 48 | struct unix_sock { |
| 49 | /* WARNING: sk has to be the first member */ |
| 50 | struct sock sk; |
Eric Dumazet | 4381548 | 2010-04-29 11:01:49 +0000 | [diff] [blame] | 51 | struct unix_address *addr; |
| 52 | struct dentry *dentry; |
| 53 | struct vfsmount *mnt; |
Ingo Molnar | 57b47a5 | 2006-03-20 22:35:41 -0800 | [diff] [blame] | 54 | struct mutex readlock; |
Eric Dumazet | 4381548 | 2010-04-29 11:01:49 +0000 | [diff] [blame] | 55 | struct sock *peer; |
| 56 | struct sock *other; |
Miklos Szeredi | 1fd05ba | 2007-07-11 14:22:39 -0700 | [diff] [blame] | 57 | struct list_head link; |
Eric Dumazet | 4381548 | 2010-04-29 11:01:49 +0000 | [diff] [blame] | 58 | atomic_long_t inflight; |
| 59 | spinlock_t lock; |
Miklos Szeredi | 1fd05ba | 2007-07-11 14:22:39 -0700 | [diff] [blame] | 60 | unsigned int gc_candidate : 1; |
Miklos Szeredi | 6209344 | 2008-11-09 15:23:57 +0100 | [diff] [blame] | 61 | unsigned int gc_maybe_cycle : 1; |
Eric Dumazet | 25888e3 | 2010-11-25 04:11:39 +0000 | [diff] [blame] | 62 | unsigned char recursion_level; |
Eric Dumazet | 4381548 | 2010-04-29 11:01:49 +0000 | [diff] [blame] | 63 | struct socket_wq peer_wq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | }; |
| 65 | #define unix_sk(__sk) ((struct unix_sock *)__sk) |
Arnaldo Carvalho de Melo | 2038073 | 2005-08-16 02:18:02 -0300 | [diff] [blame] | 66 | |
Eric Dumazet | 4381548 | 2010-04-29 11:01:49 +0000 | [diff] [blame] | 67 | #define peer_wait peer_wq.wait |
| 68 | |
Pavel Emelyanov | 885ee74 | 2011-12-30 00:54:11 +0000 | [diff] [blame^] | 69 | long unix_inq_len(struct sock *sk); |
| 70 | long unix_outq_len(struct sock *sk); |
| 71 | |
Arnaldo Carvalho de Melo | 2038073 | 2005-08-16 02:18:02 -0300 | [diff] [blame] | 72 | #ifdef CONFIG_SYSCTL |
Pavel Emelyanov | 97577e3 | 2007-12-01 23:40:40 +1100 | [diff] [blame] | 73 | extern int unix_sysctl_register(struct net *net); |
| 74 | extern void unix_sysctl_unregister(struct net *net); |
Arnaldo Carvalho de Melo | 2038073 | 2005-08-16 02:18:02 -0300 | [diff] [blame] | 75 | #else |
Pavel Emelyanov | 97577e3 | 2007-12-01 23:40:40 +1100 | [diff] [blame] | 76 | static inline int unix_sysctl_register(struct net *net) { return 0; } |
| 77 | static inline void unix_sysctl_unregister(struct net *net) {} |
Arnaldo Carvalho de Melo | 2038073 | 2005-08-16 02:18:02 -0300 | [diff] [blame] | 78 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | #endif |