af_unix.h 2.1 KB

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