af_unix.h 2.4 KB

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