af_unix.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. extern void unix_gc(void);
  10. extern void wait_for_unix_gc(void);
  11. extern struct sock *unix_get_socket(struct file *filp);
  12. extern 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. const struct cred *cred;
  27. struct scm_fp_list *fp; /* Passed files */
  28. #ifdef CONFIG_SECURITY_NETWORK
  29. u32 secid; /* Security ID */
  30. #endif
  31. };
  32. #define UNIXCB(skb) (*(struct unix_skb_parms *)&((skb)->cb))
  33. #define UNIXSID(skb) (&UNIXCB((skb)).secid)
  34. #define unix_state_lock(s) spin_lock(&unix_sk(s)->lock)
  35. #define unix_state_unlock(s) spin_unlock(&unix_sk(s)->lock)
  36. #define unix_state_lock_nested(s) \
  37. spin_lock_nested(&unix_sk(s)->lock, \
  38. SINGLE_DEPTH_NESTING)
  39. /* The AF_UNIX socket */
  40. struct unix_sock {
  41. /* WARNING: sk has to be the first member */
  42. struct sock sk;
  43. struct unix_address *addr;
  44. struct path path;
  45. struct mutex readlock;
  46. struct sock *peer;
  47. struct sock *other;
  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. #define unix_sk(__sk) ((struct unix_sock *)__sk)
  59. #define peer_wait peer_wq.wait
  60. long unix_inq_len(struct sock *sk);
  61. long unix_outq_len(struct sock *sk);
  62. #ifdef CONFIG_SYSCTL
  63. extern int unix_sysctl_register(struct net *net);
  64. extern void unix_sysctl_unregister(struct net *net);
  65. #else
  66. static inline int unix_sysctl_register(struct net *net) { return 0; }
  67. static inline void unix_sysctl_unregister(struct net *net) {}
  68. #endif
  69. #endif