af_unix.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 file *fp);
  8. void unix_notinflight(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 readlock;
  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. };
  57. #define unix_sk(__sk) ((struct unix_sock *)__sk)
  58. #define peer_wait peer_wq.wait
  59. long unix_inq_len(struct sock *sk);
  60. long unix_outq_len(struct sock *sk);
  61. #ifdef CONFIG_SYSCTL
  62. int unix_sysctl_register(struct net *net);
  63. void unix_sysctl_unregister(struct net *net);
  64. #else
  65. static inline int unix_sysctl_register(struct net *net) { return 0; }
  66. static inline void unix_sysctl_unregister(struct net *net) {}
  67. #endif
  68. #endif