| 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
|---|---|
| 2 | #ifndef __LINUX_NET_AFUNIX_H |
| 3 | #define __LINUX_NET_AFUNIX_H |
| 4 | |
| 5 | #include <linux/atomic.h> |
| 6 | #include <linux/mutex.h> |
| 7 | #include <linux/net.h> |
| 8 | #include <linux/path.h> |
| 9 | #include <linux/refcount.h> |
| 10 | #include <linux/spinlock.h> |
| 11 | #include <linux/wait.h> |
| 12 | #include <net/sock.h> |
| 13 | #include <uapi/linux/un.h> |
| 14 | |
| 15 | #if IS_ENABLED(CONFIG_UNIX) |
| 16 | struct unix_sock *unix_get_socket(struct file *filp); |
| 17 | #else |
| 18 | static inline struct unix_sock *unix_get_socket(struct file *filp) |
| 19 | { |
| 20 | return NULL; |
| 21 | } |
| 22 | #endif |
| 23 | |
| 24 | struct unix_address { |
| 25 | refcount_t refcnt; |
| 26 | int len; |
| 27 | struct sockaddr_un name[]; |
| 28 | }; |
| 29 | |
| 30 | struct scm_stat { |
| 31 | atomic_t nr_fds; |
| 32 | unsigned long nr_unix_fds; |
| 33 | }; |
| 34 | |
| 35 | /* The AF_UNIX socket */ |
| 36 | struct unix_sock { |
| 37 | /* WARNING: sk has to be the first member */ |
| 38 | struct sock sk; |
| 39 | struct unix_address *addr; |
| 40 | struct path path; |
| 41 | struct mutex iolock, bindlock; |
| 42 | struct sock *peer; |
| 43 | struct sock *listener; |
| 44 | struct unix_vertex *vertex; |
| 45 | spinlock_t lock; |
| 46 | struct socket_wq peer_wq; |
| 47 | #define peer_wait peer_wq.wait |
| 48 | wait_queue_entry_t peer_wake; |
| 49 | struct scm_stat scm_stat; |
| 50 | int inq_len; |
| 51 | bool recvmsg_inq; |
| 52 | #if IS_ENABLED(CONFIG_AF_UNIX_OOB) |
| 53 | struct sk_buff *oob_skb; |
| 54 | #endif |
| 55 | }; |
| 56 | |
| 57 | #define unix_sk(ptr) container_of_const(ptr, struct unix_sock, sk) |
| 58 | #define unix_peer(sk) (unix_sk(sk)->peer) |
| 59 | |
| 60 | #define unix_state_lock(s) spin_lock(&unix_sk(s)->lock) |
| 61 | #define unix_state_unlock(s) spin_unlock(&unix_sk(s)->lock) |
| 62 | |
| 63 | #endif |
| 64 |
