af_unix.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __LINUX_NET_AFUNIX_H
  3. #define __LINUX_NET_AFUNIX_H
  4. #include <linux/socket.h>
  5. #include <linux/un.h>
  6. #include <linux/mutex.h>
  7. #include <linux/refcount.h>
  8. #include <net/sock.h>
  9. void unix_inflight(struct user_struct *user, struct file *fp);
  10. void unix_notinflight(struct user_struct *user, struct file *fp);
  11. void unix_gc(void);
  12. void wait_for_unix_gc(void);
  13. struct sock *unix_get_socket(struct file *filp);
  14. struct sock *unix_peer_get(struct sock *);
  15. #define UNIX_HASH_SIZE 256
  16. #define UNIX_HASH_BITS 8
  17. extern unsigned int unix_tot_inflight;
  18. extern spinlock_t unix_table_lock;
  19. extern struct hlist_head unix_socket_table[2 * UNIX_HASH_SIZE];
  20. struct unix_address {
  21. refcount_t refcnt;
  22. int len;
  23. unsigned int hash;
  24. struct sockaddr_un name[0];
  25. };
  26. struct unix_skb_parms {
  27. struct pid *pid; /* Skb credentials */
  28. kuid_t uid;
  29. kgid_t gid;
  30. struct scm_fp_list *fp; /* Passed files */
  31. #ifdef CONFIG_SECURITY_NETWORK
  32. u32 secid; /* Security ID */
  33. #endif
  34. u32 consumed;
  35. } __randomize_layout;
  36. #define UNIXCB(skb) (*(struct unix_skb_parms *)&((skb)->cb))
  37. #define unix_state_lock(s) spin_lock(&unix_sk(s)->lock)
  38. #define unix_state_unlock(s) spin_unlock(&unix_sk(s)->lock)
  39. #define unix_state_lock_nested(s) \
  40. spin_lock_nested(&unix_sk(s)->lock, \
  41. SINGLE_DEPTH_NESTING)
  42. /* The AF_UNIX socket */
  43. struct unix_sock {
  44. /* WARNING: sk has to be the first member */
  45. struct sock sk;
  46. struct unix_address *addr;
  47. struct path path;
  48. struct mutex iolock, bindlock;
  49. struct sock *peer;
  50. struct list_head link;
  51. atomic_long_t inflight;
  52. spinlock_t lock;
  53. unsigned long gc_flags;
  54. #define UNIX_GC_CANDIDATE 0
  55. #define UNIX_GC_MAYBE_CYCLE 1
  56. struct socket_wq peer_wq;
  57. wait_queue_entry_t peer_wake;
  58. };
  59. static inline struct unix_sock *unix_sk(const struct sock *sk)
  60. {
  61. return (struct unix_sock *)sk;
  62. }
  63. #define peer_wait peer_wq.wait
  64. long unix_inq_len(struct sock *sk);
  65. long unix_outq_len(struct sock *sk);
  66. #ifdef CONFIG_SYSCTL
  67. int unix_sysctl_register(struct net *net);
  68. void unix_sysctl_unregister(struct net *net);
  69. #else
  70. static inline int unix_sysctl_register(struct net *net) { return 0; }
  71. static inline void unix_sysctl_unregister(struct net *net) {}
  72. #endif
  73. #endif