af_unix.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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_destruct_scm(struct sk_buff *skb);
  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 *sk);
  16. #define UNIX_HASH_MOD (256 - 1)
  17. #define UNIX_HASH_SIZE (256 * 2)
  18. #define UNIX_HASH_BITS 8
  19. extern unsigned int unix_tot_inflight;
  20. struct unix_address {
  21. refcount_t refcnt;
  22. int len;
  23. struct sockaddr_un name[];
  24. };
  25. struct unix_skb_parms {
  26. struct pid *pid; /* Skb credentials */
  27. kuid_t uid;
  28. kgid_t gid;
  29. struct scm_fp_list *fp; /* Passed files */
  30. #ifdef CONFIG_SECURITY_NETWORK
  31. u32 secid; /* Security ID */
  32. #endif
  33. u32 consumed;
  34. } __randomize_layout;
  35. struct scm_stat {
  36. atomic_t nr_fds;
  37. };
  38. #define UNIXCB(skb) (*(struct unix_skb_parms *)&((skb)->cb))
  39. #define unix_state_lock(s) spin_lock(&unix_sk(s)->lock)
  40. #define unix_state_unlock(s) spin_unlock(&unix_sk(s)->lock)
  41. #define unix_state_lock_nested(s) \
  42. spin_lock_nested(&unix_sk(s)->lock, \
  43. SINGLE_DEPTH_NESTING)
  44. /* The AF_UNIX socket */
  45. struct unix_sock {
  46. /* WARNING: sk has to be the first member */
  47. struct sock sk;
  48. struct unix_address *addr;
  49. struct path path;
  50. struct mutex iolock, bindlock;
  51. struct sock *peer;
  52. struct list_head link;
  53. unsigned long inflight;
  54. spinlock_t lock;
  55. unsigned long gc_flags;
  56. #define UNIX_GC_CANDIDATE 0
  57. #define UNIX_GC_MAYBE_CYCLE 1
  58. struct socket_wq peer_wq;
  59. wait_queue_entry_t peer_wake;
  60. struct scm_stat scm_stat;
  61. #if IS_ENABLED(CONFIG_AF_UNIX_OOB)
  62. struct sk_buff *oob_skb;
  63. #endif
  64. };
  65. static inline struct unix_sock *unix_sk(const struct sock *sk)
  66. {
  67. return (struct unix_sock *)sk;
  68. }
  69. #define peer_wait peer_wq.wait
  70. long unix_inq_len(struct sock *sk);
  71. long unix_outq_len(struct sock *sk);
  72. int __unix_dgram_recvmsg(struct sock *sk, struct msghdr *msg, size_t size,
  73. int flags);
  74. int __unix_stream_recvmsg(struct sock *sk, struct msghdr *msg, size_t size,
  75. int flags);
  76. #ifdef CONFIG_SYSCTL
  77. int unix_sysctl_register(struct net *net);
  78. void unix_sysctl_unregister(struct net *net);
  79. #else
  80. static inline int unix_sysctl_register(struct net *net) { return 0; }
  81. static inline void unix_sysctl_unregister(struct net *net) {}
  82. #endif
  83. #ifdef CONFIG_BPF_SYSCALL
  84. extern struct proto unix_dgram_proto;
  85. extern struct proto unix_stream_proto;
  86. int unix_dgram_bpf_update_proto(struct sock *sk, struct sk_psock *psock, bool restore);
  87. int unix_stream_bpf_update_proto(struct sock *sk, struct sk_psock *psock, bool restore);
  88. void __init unix_bpf_build_proto(void);
  89. #else
  90. static inline void __init unix_bpf_build_proto(void)
  91. {}
  92. #endif
  93. #endif