af_unix.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. extern void unix_inflight(struct file *fp);
  8. extern void unix_notinflight(struct file *fp);
  9. extern void unix_gc(void);
  10. #define UNIX_HASH_SIZE 256
  11. extern struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1];
  12. extern spinlock_t unix_table_lock;
  13. extern atomic_t unix_tot_inflight;
  14. static inline struct sock *first_unix_socket(int *i)
  15. {
  16. for (*i = 0; *i <= UNIX_HASH_SIZE; (*i)++) {
  17. if (!hlist_empty(&unix_socket_table[*i]))
  18. return __sk_head(&unix_socket_table[*i]);
  19. }
  20. return NULL;
  21. }
  22. static inline struct sock *next_unix_socket(int *i, struct sock *s)
  23. {
  24. struct sock *next = sk_next(s);
  25. /* More in this chain? */
  26. if (next)
  27. return next;
  28. /* Look for next non-empty chain. */
  29. for ((*i)++; *i <= UNIX_HASH_SIZE; (*i)++) {
  30. if (!hlist_empty(&unix_socket_table[*i]))
  31. return __sk_head(&unix_socket_table[*i]);
  32. }
  33. return NULL;
  34. }
  35. #define forall_unix_sockets(i, s) \
  36. for (s = first_unix_socket(&(i)); s; s = next_unix_socket(&(i),(s)))
  37. struct unix_address {
  38. atomic_t refcnt;
  39. int len;
  40. unsigned hash;
  41. struct sockaddr_un name[0];
  42. };
  43. struct unix_skb_parms {
  44. struct ucred creds; /* Skb credentials */
  45. struct scm_fp_list *fp; /* Passed files */
  46. #ifdef CONFIG_SECURITY_NETWORK
  47. u32 secid; /* Security ID */
  48. #endif
  49. };
  50. #define UNIXCB(skb) (*(struct unix_skb_parms*)&((skb)->cb))
  51. #define UNIXCREDS(skb) (&UNIXCB((skb)).creds)
  52. #define UNIXSID(skb) (&UNIXCB((skb)).secid)
  53. #define unix_state_rlock(s) spin_lock(&unix_sk(s)->lock)
  54. #define unix_state_runlock(s) spin_unlock(&unix_sk(s)->lock)
  55. #define unix_state_wlock(s) spin_lock(&unix_sk(s)->lock)
  56. #define unix_state_wlock_nested(s) \
  57. spin_lock_nested(&unix_sk(s)->lock, \
  58. SINGLE_DEPTH_NESTING)
  59. #define unix_state_wunlock(s) spin_unlock(&unix_sk(s)->lock)
  60. #ifdef __KERNEL__
  61. /* The AF_UNIX socket */
  62. struct unix_sock {
  63. /* WARNING: sk has to be the first member */
  64. struct sock sk;
  65. struct unix_address *addr;
  66. struct dentry *dentry;
  67. struct vfsmount *mnt;
  68. struct mutex readlock;
  69. struct sock *peer;
  70. struct sock *other;
  71. struct sock *gc_tree;
  72. atomic_t inflight;
  73. spinlock_t lock;
  74. wait_queue_head_t peer_wait;
  75. };
  76. #define unix_sk(__sk) ((struct unix_sock *)__sk)
  77. #ifdef CONFIG_SYSCTL
  78. extern int sysctl_unix_max_dgram_qlen;
  79. extern void unix_sysctl_register(void);
  80. extern void unix_sysctl_unregister(void);
  81. #else
  82. static inline void unix_sysctl_register(void) {}
  83. static inline void unix_sysctl_unregister(void) {}
  84. #endif
  85. #endif
  86. #endif