af_unix.h 2.1 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 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. extern unsigned int unix_tot_inflight;
  15. extern spinlock_t unix_table_lock;
  16. extern struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1];
  17. struct unix_address {
  18. atomic_t refcnt;
  19. int len;
  20. unsigned hash;
  21. struct sockaddr_un name[0];
  22. };
  23. struct unix_skb_parms {
  24. struct pid *pid; /* Skb credentials */
  25. const struct cred *cred;
  26. struct scm_fp_list *fp; /* Passed files */
  27. #ifdef CONFIG_SECURITY_NETWORK
  28. u32 secid; /* Security ID */
  29. #endif
  30. };
  31. #define UNIXCB(skb) (*(struct unix_skb_parms *)&((skb)->cb))
  32. #define UNIXSID(skb) (&UNIXCB((skb)).secid)
  33. #define unix_state_lock(s) spin_lock(&unix_sk(s)->lock)
  34. #define unix_state_unlock(s) spin_unlock(&unix_sk(s)->lock)
  35. #define unix_state_lock_nested(s) \
  36. spin_lock_nested(&unix_sk(s)->lock, \
  37. SINGLE_DEPTH_NESTING)
  38. /* The AF_UNIX socket */
  39. struct unix_sock {
  40. /* WARNING: sk has to be the first member */
  41. struct sock sk;
  42. struct unix_address *addr;
  43. struct path path;
  44. struct mutex readlock;
  45. struct sock *peer;
  46. struct sock *other;
  47. struct list_head link;
  48. atomic_long_t inflight;
  49. spinlock_t lock;
  50. unsigned char recursion_level;
  51. unsigned long gc_flags;
  52. #define UNIX_GC_CANDIDATE 0
  53. #define UNIX_GC_MAYBE_CYCLE 1
  54. struct socket_wq peer_wq;
  55. wait_queue_t peer_wake;
  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. extern int unix_sysctl_register(struct net *net);
  63. extern 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