af_unix.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. #if IS_ENABLED(CONFIG_UNIX)
  10. struct unix_sock *unix_get_socket(struct file *filp);
  11. #else
  12. static inline struct unix_sock *unix_get_socket(struct file *filp)
  13. {
  14. return NULL;
  15. }
  16. #endif
  17. extern unsigned int unix_tot_inflight;
  18. void unix_add_edges(struct scm_fp_list *fpl, struct unix_sock *receiver);
  19. void unix_del_edges(struct scm_fp_list *fpl);
  20. void unix_update_edges(struct unix_sock *receiver);
  21. int unix_prepare_fpl(struct scm_fp_list *fpl);
  22. void unix_destroy_fpl(struct scm_fp_list *fpl);
  23. void unix_gc(void);
  24. void wait_for_unix_gc(struct scm_fp_list *fpl);
  25. struct unix_vertex {
  26. struct list_head edges;
  27. struct list_head entry;
  28. struct list_head scc_entry;
  29. unsigned long out_degree;
  30. unsigned long index;
  31. unsigned long scc_index;
  32. };
  33. struct unix_edge {
  34. struct unix_sock *predecessor;
  35. struct unix_sock *successor;
  36. struct list_head vertex_entry;
  37. struct list_head stack_entry;
  38. };
  39. struct sock *unix_peer_get(struct sock *sk);
  40. #define UNIX_HASH_MOD (256 - 1)
  41. #define UNIX_HASH_SIZE (256 * 2)
  42. #define UNIX_HASH_BITS 8
  43. struct unix_address {
  44. refcount_t refcnt;
  45. int len;
  46. struct sockaddr_un name[];
  47. };
  48. struct unix_skb_parms {
  49. struct pid *pid; /* Skb credentials */
  50. kuid_t uid;
  51. kgid_t gid;
  52. struct scm_fp_list *fp; /* Passed files */
  53. #ifdef CONFIG_SECURITY_NETWORK
  54. u32 secid; /* Security ID */
  55. #endif
  56. u32 consumed;
  57. } __randomize_layout;
  58. struct scm_stat {
  59. atomic_t nr_fds;
  60. unsigned long nr_unix_fds;
  61. };
  62. #define UNIXCB(skb) (*(struct unix_skb_parms *)&((skb)->cb))
  63. /* The AF_UNIX socket */
  64. struct unix_sock {
  65. /* WARNING: sk has to be the first member */
  66. struct sock sk;
  67. struct unix_address *addr;
  68. struct path path;
  69. struct mutex iolock, bindlock;
  70. struct sock *peer;
  71. struct sock *listener;
  72. struct unix_vertex *vertex;
  73. spinlock_t lock;
  74. struct socket_wq peer_wq;
  75. wait_queue_entry_t peer_wake;
  76. struct scm_stat scm_stat;
  77. #if IS_ENABLED(CONFIG_AF_UNIX_OOB)
  78. struct sk_buff *oob_skb;
  79. #endif
  80. };
  81. #define unix_sk(ptr) container_of_const(ptr, struct unix_sock, sk)
  82. #define unix_peer(sk) (unix_sk(sk)->peer)
  83. #define unix_state_lock(s) spin_lock(&unix_sk(s)->lock)
  84. #define unix_state_unlock(s) spin_unlock(&unix_sk(s)->lock)
  85. #define peer_wait peer_wq.wait
  86. long unix_inq_len(struct sock *sk);
  87. long unix_outq_len(struct sock *sk);
  88. int __unix_dgram_recvmsg(struct sock *sk, struct msghdr *msg, size_t size,
  89. int flags);
  90. int __unix_stream_recvmsg(struct sock *sk, struct msghdr *msg, size_t size,
  91. int flags);
  92. #ifdef CONFIG_SYSCTL
  93. int unix_sysctl_register(struct net *net);
  94. void unix_sysctl_unregister(struct net *net);
  95. #else
  96. static inline int unix_sysctl_register(struct net *net) { return 0; }
  97. static inline void unix_sysctl_unregister(struct net *net) {}
  98. #endif
  99. #ifdef CONFIG_BPF_SYSCALL
  100. extern struct proto unix_dgram_proto;
  101. extern struct proto unix_stream_proto;
  102. int unix_dgram_bpf_update_proto(struct sock *sk, struct sk_psock *psock, bool restore);
  103. int unix_stream_bpf_update_proto(struct sock *sk, struct sk_psock *psock, bool restore);
  104. void __init unix_bpf_build_proto(void);
  105. #else
  106. static inline void __init unix_bpf_build_proto(void)
  107. {}
  108. #endif
  109. #endif