af_unix.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 <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. };
  47. #define UNIXCB(skb) (*(struct unix_skb_parms*)&((skb)->cb))
  48. #define UNIXCREDS(skb) (&UNIXCB((skb)).creds)
  49. #define unix_state_rlock(s) read_lock(&unix_sk(s)->lock)
  50. #define unix_state_runlock(s) read_unlock(&unix_sk(s)->lock)
  51. #define unix_state_wlock(s) write_lock(&unix_sk(s)->lock)
  52. #define unix_state_wunlock(s) write_unlock(&unix_sk(s)->lock)
  53. #ifdef __KERNEL__
  54. /* The AF_UNIX socket */
  55. struct unix_sock {
  56. /* WARNING: sk has to be the first member */
  57. struct sock sk;
  58. struct unix_address *addr;
  59. struct dentry *dentry;
  60. struct vfsmount *mnt;
  61. struct semaphore readsem;
  62. struct sock *peer;
  63. struct sock *other;
  64. struct sock *gc_tree;
  65. atomic_t inflight;
  66. rwlock_t lock;
  67. wait_queue_head_t peer_wait;
  68. };
  69. #define unix_sk(__sk) ((struct unix_sock *)__sk)
  70. #ifdef CONFIG_SYSCTL
  71. extern int sysctl_unix_max_dgram_qlen;
  72. extern void unix_sysctl_register(void);
  73. extern void unix_sysctl_unregister(void);
  74. #else
  75. static inline void unix_sysctl_register(void) {}
  76. static inline void unix_sysctl_unregister(void) {}
  77. #endif
  78. #endif
  79. #endif