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> |
Reshetova, Elena | 8c9814b | 2017-06-30 13:08:05 +0300 | [diff] [blame] | 7 | #include <linux/refcount.h> |
Arnaldo Carvalho de Melo | 2038073 | 2005-08-16 02:18:02 -0300 | [diff] [blame] | 8 | #include <net/sock.h> |
| 9 | |
Hannes Frederic Sowa | 415e3d3 | 2016-02-03 02:11:03 +0100 | [diff] [blame] | 10 | void unix_inflight(struct user_struct *user, struct file *fp); |
| 11 | void unix_notinflight(struct user_struct *user, struct file *fp); |
Joe Perches | b60a828 | 2013-07-31 17:31:33 -0700 | [diff] [blame] | 12 | void unix_gc(void); |
| 13 | void wait_for_unix_gc(void); |
| 14 | struct sock *unix_get_socket(struct file *filp); |
| 15 | struct sock *unix_peer_get(struct sock *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | |
| 17 | #define UNIX_HASH_SIZE 256 |
Eric Dumazet | 7123aaa | 2012-06-08 05:03:21 +0000 | [diff] [blame] | 18 | #define UNIX_HASH_BITS 8 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | |
Pavel Emelyanov | 9305cfa | 2007-11-10 22:06:01 -0800 | [diff] [blame] | 20 | extern unsigned int unix_tot_inflight; |
Pavel Emelyanov | fa7ff56 | 2011-12-15 02:44:03 +0000 | [diff] [blame] | 21 | extern spinlock_t unix_table_lock; |
Eric Dumazet | 7123aaa | 2012-06-08 05:03:21 +0000 | [diff] [blame] | 22 | extern struct hlist_head unix_socket_table[2 * UNIX_HASH_SIZE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | struct unix_address { |
Reshetova, Elena | 8c9814b | 2017-06-30 13:08:05 +0300 | [diff] [blame] | 25 | refcount_t refcnt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | int len; |
Eric Dumazet | 95c9617 | 2012-04-15 05:58:06 +0000 | [diff] [blame] | 27 | unsigned int hash; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | struct sockaddr_un name[0]; |
| 29 | }; |
| 30 | |
| 31 | struct unix_skb_parms { |
Eric W. Biederman | 7361c36 | 2010-06-13 03:34:33 +0000 | [diff] [blame] | 32 | struct pid *pid; /* Skb credentials */ |
Eric W. Biederman | 6b0ee8c0 | 2013-04-03 17:28:16 +0000 | [diff] [blame] | 33 | kuid_t uid; |
| 34 | kgid_t gid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | struct scm_fp_list *fp; /* Passed files */ |
Catherine Zhang | 877ce7c | 2006-06-29 12:27:47 -0700 | [diff] [blame] | 36 | #ifdef CONFIG_SECURITY_NETWORK |
Catherine Zhang | dc49c1f | 2006-08-02 14:12:06 -0700 | [diff] [blame] | 37 | u32 secid; /* Security ID */ |
Catherine Zhang | 877ce7c | 2006-06-29 12:27:47 -0700 | [diff] [blame] | 38 | #endif |
Eric Dumazet | e370a72 | 2013-08-08 14:37:32 -0700 | [diff] [blame] | 39 | u32 consumed; |
Kees Cook | 3859a27 | 2016-10-28 01:22:25 -0700 | [diff] [blame] | 40 | } __randomize_layout; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
Eric Dumazet | 4381548 | 2010-04-29 11:01:49 +0000 | [diff] [blame] | 42 | #define UNIXCB(skb) (*(struct unix_skb_parms *)&((skb)->cb)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
David S. Miller | 1c92b4e | 2007-05-31 13:24:26 -0700 | [diff] [blame] | 44 | #define unix_state_lock(s) spin_lock(&unix_sk(s)->lock) |
| 45 | #define unix_state_unlock(s) spin_unlock(&unix_sk(s)->lock) |
| 46 | #define unix_state_lock_nested(s) \ |
Ingo Molnar | a09785a | 2006-07-03 00:25:12 -0700 | [diff] [blame] | 47 | spin_lock_nested(&unix_sk(s)->lock, \ |
| 48 | SINGLE_DEPTH_NESTING) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | /* The AF_UNIX socket */ |
| 51 | struct unix_sock { |
| 52 | /* WARNING: sk has to be the first member */ |
| 53 | struct sock sk; |
Eric Dumazet | 4381548 | 2010-04-29 11:01:49 +0000 | [diff] [blame] | 54 | struct unix_address *addr; |
Al Viro | 40ffe67 | 2012-03-14 21:54:32 -0400 | [diff] [blame] | 55 | struct path path; |
Linus Torvalds | 6e1ce3c | 2016-09-01 14:43:53 -0700 | [diff] [blame] | 56 | struct mutex iolock, bindlock; |
Eric Dumazet | 4381548 | 2010-04-29 11:01:49 +0000 | [diff] [blame] | 57 | struct sock *peer; |
Miklos Szeredi | 1fd05ba | 2007-07-11 14:22:39 -0700 | [diff] [blame] | 58 | struct list_head link; |
Eric Dumazet | 4381548 | 2010-04-29 11:01:49 +0000 | [diff] [blame] | 59 | atomic_long_t inflight; |
| 60 | spinlock_t lock; |
Eric Dumazet | 60bc851 | 2013-05-01 05:24:03 +0000 | [diff] [blame] | 61 | unsigned long gc_flags; |
| 62 | #define UNIX_GC_CANDIDATE 0 |
| 63 | #define UNIX_GC_MAYBE_CYCLE 1 |
Eric Dumazet | 4381548 | 2010-04-29 11:01:49 +0000 | [diff] [blame] | 64 | struct socket_wq peer_wq; |
Ingo Molnar | ac6424b | 2017-06-20 12:06:13 +0200 | [diff] [blame] | 65 | wait_queue_entry_t peer_wake; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | }; |
Aaron Conole | 4613012 | 2015-09-26 18:50:42 -0400 | [diff] [blame] | 67 | |
Paul Moore | c72eda0 | 2015-10-06 15:03:53 -0400 | [diff] [blame] | 68 | static inline struct unix_sock *unix_sk(const struct sock *sk) |
Aaron Conole | 4613012 | 2015-09-26 18:50:42 -0400 | [diff] [blame] | 69 | { |
| 70 | return (struct unix_sock *)sk; |
| 71 | } |
Arnaldo Carvalho de Melo | 2038073 | 2005-08-16 02:18:02 -0300 | [diff] [blame] | 72 | |
Eric Dumazet | 4381548 | 2010-04-29 11:01:49 +0000 | [diff] [blame] | 73 | #define peer_wait peer_wq.wait |
| 74 | |
Pavel Emelyanov | 885ee74 | 2011-12-30 00:54:11 +0000 | [diff] [blame] | 75 | long unix_inq_len(struct sock *sk); |
| 76 | long unix_outq_len(struct sock *sk); |
| 77 | |
Arnaldo Carvalho de Melo | 2038073 | 2005-08-16 02:18:02 -0300 | [diff] [blame] | 78 | #ifdef CONFIG_SYSCTL |
Joe Perches | b60a828 | 2013-07-31 17:31:33 -0700 | [diff] [blame] | 79 | int unix_sysctl_register(struct net *net); |
| 80 | void unix_sysctl_unregister(struct net *net); |
Arnaldo Carvalho de Melo | 2038073 | 2005-08-16 02:18:02 -0300 | [diff] [blame] | 81 | #else |
Pavel Emelyanov | 97577e3 | 2007-12-01 23:40:40 +1100 | [diff] [blame] | 82 | static inline int unix_sysctl_register(struct net *net) { return 0; } |
| 83 | static inline void unix_sysctl_unregister(struct net *net) {} |
Arnaldo Carvalho de Melo | 2038073 | 2005-08-16 02:18:02 -0300 | [diff] [blame] | 84 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | #endif |