af_unix.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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_lock(s) spin_lock(&unix_sk(s)->lock)
  54. #define unix_state_unlock(s) spin_unlock(&unix_sk(s)->lock)
  55. #define unix_state_lock_nested(s) \
  56. spin_lock_nested(&unix_sk(s)->lock, \
  57. SINGLE_DEPTH_NESTING)
  58. #ifdef __KERNEL__
  59. /* The AF_UNIX socket */
  60. struct unix_sock {
  61. /* WARNING: sk has to be the first member */
  62. struct sock sk;
  63. struct unix_address *addr;
  64. struct dentry *dentry;
  65. struct vfsmount *mnt;
  66. struct mutex readlock;
  67. struct sock *peer;
  68. struct sock *other;
  69. struct sock *gc_tree;
  70. atomic_t inflight;
  71. spinlock_t lock;
  72. wait_queue_head_t peer_wait;
  73. };
  74. #define unix_sk(__sk) ((struct unix_sock *)__sk)
  75. #ifdef CONFIG_SYSCTL
  76. extern int sysctl_unix_max_dgram_qlen;
  77. extern void unix_sysctl_register(void);
  78. extern void unix_sysctl_unregister(void);
  79. #else
  80. static inline void unix_sysctl_register(void) {}
  81. static inline void unix_sysctl_unregister(void) {}
  82. #endif
  83. #endif
  84. #endif