blob: afb37f83544983c2fe54236f2a3806ecc9b43f53 [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>
Reshetova, Elena8c9814b2017-06-30 13:08:05 +03007#include <linux/refcount.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -03008#include <net/sock.h>
9
Hannes Frederic Sowa415e3d32016-02-03 02:11:03 +010010void unix_inflight(struct user_struct *user, struct file *fp);
11void unix_notinflight(struct user_struct *user, struct file *fp);
Joe Perchesb60a8282013-07-31 17:31:33 -070012void unix_gc(void);
13void wait_for_unix_gc(void);
14struct sock *unix_get_socket(struct file *filp);
15struct sock *unix_peer_get(struct sock *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
17#define UNIX_HASH_SIZE 256
Eric Dumazet7123aaa2012-06-08 05:03:21 +000018#define UNIX_HASH_BITS 8
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
Pavel Emelyanov9305cfa2007-11-10 22:06:01 -080020extern unsigned int unix_tot_inflight;
Pavel Emelyanovfa7ff562011-12-15 02:44:03 +000021extern spinlock_t unix_table_lock;
Eric Dumazet7123aaa2012-06-08 05:03:21 +000022extern struct hlist_head unix_socket_table[2 * UNIX_HASH_SIZE];
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
Linus Torvalds1da177e2005-04-16 15:20:36 -070024struct unix_address {
Reshetova, Elena8c9814b2017-06-30 13:08:05 +030025 refcount_t refcnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -070026 int len;
Eric Dumazet95c96172012-04-15 05:58:06 +000027 unsigned int hash;
Linus Torvalds1da177e2005-04-16 15:20:36 -070028 struct sockaddr_un name[0];
29};
30
31struct unix_skb_parms {
Eric W. Biederman7361c362010-06-13 03:34:33 +000032 struct pid *pid; /* Skb credentials */
Eric W. Biederman6b0ee8c02013-04-03 17:28:16 +000033 kuid_t uid;
34 kgid_t gid;
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 struct scm_fp_list *fp; /* Passed files */
Catherine Zhang877ce7c2006-06-29 12:27:47 -070036#ifdef CONFIG_SECURITY_NETWORK
Catherine Zhangdc49c1f2006-08-02 14:12:06 -070037 u32 secid; /* Security ID */
Catherine Zhang877ce7c2006-06-29 12:27:47 -070038#endif
Eric Dumazete370a722013-08-08 14:37:32 -070039 u32 consumed;
Kees Cook3859a272016-10-28 01:22:25 -070040} __randomize_layout;
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
Eric Dumazet43815482010-04-29 11:01:49 +000042#define UNIXCB(skb) (*(struct unix_skb_parms *)&((skb)->cb))
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
David S. Miller1c92b4e2007-05-31 13:24:26 -070044#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 Molnara09785a2006-07-03 00:25:12 -070047 spin_lock_nested(&unix_sk(s)->lock, \
48 SINGLE_DEPTH_NESTING)
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
Linus Torvalds1da177e2005-04-16 15:20:36 -070050/* The AF_UNIX socket */
51struct unix_sock {
52 /* WARNING: sk has to be the first member */
53 struct sock sk;
Eric Dumazet43815482010-04-29 11:01:49 +000054 struct unix_address *addr;
Al Viro40ffe672012-03-14 21:54:32 -040055 struct path path;
Linus Torvalds6e1ce3c2016-09-01 14:43:53 -070056 struct mutex iolock, bindlock;
Eric Dumazet43815482010-04-29 11:01:49 +000057 struct sock *peer;
Miklos Szeredi1fd05ba2007-07-11 14:22:39 -070058 struct list_head link;
Eric Dumazet43815482010-04-29 11:01:49 +000059 atomic_long_t inflight;
60 spinlock_t lock;
Eric Dumazet60bc8512013-05-01 05:24:03 +000061 unsigned long gc_flags;
62#define UNIX_GC_CANDIDATE 0
63#define UNIX_GC_MAYBE_CYCLE 1
Eric Dumazet43815482010-04-29 11:01:49 +000064 struct socket_wq peer_wq;
Ingo Molnarac6424b2017-06-20 12:06:13 +020065 wait_queue_entry_t peer_wake;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066};
Aaron Conole46130122015-09-26 18:50:42 -040067
Paul Moorec72eda02015-10-06 15:03:53 -040068static inline struct unix_sock *unix_sk(const struct sock *sk)
Aaron Conole46130122015-09-26 18:50:42 -040069{
70 return (struct unix_sock *)sk;
71}
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030072
Eric Dumazet43815482010-04-29 11:01:49 +000073#define peer_wait peer_wq.wait
74
Pavel Emelyanov885ee742011-12-30 00:54:11 +000075long unix_inq_len(struct sock *sk);
76long unix_outq_len(struct sock *sk);
77
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030078#ifdef CONFIG_SYSCTL
Joe Perchesb60a8282013-07-31 17:31:33 -070079int unix_sysctl_register(struct net *net);
80void unix_sysctl_unregister(struct net *net);
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030081#else
Pavel Emelyanov97577e32007-12-01 23:40:40 +110082static inline int unix_sysctl_register(struct net *net) { return 0; }
83static inline void unix_sysctl_unregister(struct net *net) {}
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030084#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070085#endif