af_unix.h 1.4 KB

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