af_unix.h 2.1 KB

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