af_unix.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 <linux/refcount.h>
  7. #include <net/sock.h>
  8. void unix_inflight(struct user_struct *user, struct file *fp);
  9. void unix_notinflight(struct user_struct *user, struct file *fp);
  10. void unix_gc(void);
  11. void wait_for_unix_gc(void);
  12. struct sock *unix_get_socket(struct file *filp);
  13. struct sock *unix_peer_get(struct sock *);
  14. #define UNIX_HASH_SIZE 256
  15. #define UNIX_HASH_BITS 8
  16. extern unsigned int unix_tot_inflight;
  17. extern spinlock_t unix_table_lock;
  18. extern struct hlist_head unix_socket_table[2 * UNIX_HASH_SIZE];
  19. struct unix_address {
  20. refcount_t refcnt;
  21. int len;
  22. unsigned int hash;
  23. struct sockaddr_un name[0];
  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. };
  35. #define UNIXCB(skb) (*(struct unix_skb_parms *)&((skb)->cb))
  36. #define unix_state_lock(s) spin_lock(&unix_sk(s)->lock)
  37. #define unix_state_unlock(s) spin_unlock(&unix_sk(s)->lock)
  38. #define unix_state_lock_nested(s) \
  39. spin_lock_nested(&unix_sk(s)->lock, \
  40. SINGLE_DEPTH_NESTING)
  41. /* The AF_UNIX socket */
  42. struct unix_sock {
  43. /* WARNING: sk has to be the first member */
  44. struct sock sk;
  45. struct unix_address *addr;
  46. struct path path;
  47. struct mutex iolock, bindlock;
  48. struct sock *peer;
  49. struct list_head link;
  50. atomic_long_t inflight;
  51. spinlock_t lock;
  52. unsigned char recursion_level;
  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_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