blob: 2fec827c8801456e6058c4a94ea16917559ace83 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef __LINUX_NET_AFUNIX_H
2#define __LINUX_NET_AFUNIX_H
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -03003
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -03004#include <linux/socket.h>
5#include <linux/un.h>
Ingo Molnar57b47a52006-03-20 22:35:41 -08006#include <linux/mutex.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -03007#include <net/sock.h>
8
Linus Torvalds1da177e2005-04-16 15:20:36 -07009extern void unix_inflight(struct file *fp);
10extern void unix_notinflight(struct file *fp);
11extern void unix_gc(void);
12
13#define UNIX_HASH_SIZE 256
14
15extern struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1];
David S. Millerfbe9cc42005-12-13 23:26:29 -080016extern spinlock_t unix_table_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
18extern atomic_t unix_tot_inflight;
19
20static inline struct sock *first_unix_socket(int *i)
21{
22 for (*i = 0; *i <= UNIX_HASH_SIZE; (*i)++) {
23 if (!hlist_empty(&unix_socket_table[*i]))
24 return __sk_head(&unix_socket_table[*i]);
25 }
26 return NULL;
27}
28
29static inline struct sock *next_unix_socket(int *i, struct sock *s)
30{
31 struct sock *next = sk_next(s);
32 /* More in this chain? */
33 if (next)
34 return next;
35 /* Look for next non-empty chain. */
36 for ((*i)++; *i <= UNIX_HASH_SIZE; (*i)++) {
37 if (!hlist_empty(&unix_socket_table[*i]))
38 return __sk_head(&unix_socket_table[*i]);
39 }
40 return NULL;
41}
42
43#define forall_unix_sockets(i, s) \
44 for (s = first_unix_socket(&(i)); s; s = next_unix_socket(&(i),(s)))
45
46struct unix_address {
47 atomic_t refcnt;
48 int len;
49 unsigned hash;
50 struct sockaddr_un name[0];
51};
52
53struct unix_skb_parms {
54 struct ucred creds; /* Skb credentials */
55 struct scm_fp_list *fp; /* Passed files */
Catherine Zhang877ce7c2006-06-29 12:27:47 -070056#ifdef CONFIG_SECURITY_NETWORK
57 char *secdata; /* Security context */
58 u32 seclen; /* Security length */
59#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070060};
61
62#define UNIXCB(skb) (*(struct unix_skb_parms*)&((skb)->cb))
63#define UNIXCREDS(skb) (&UNIXCB((skb)).creds)
Catherine Zhang877ce7c2006-06-29 12:27:47 -070064#define UNIXSECDATA(skb) (&UNIXCB((skb)).secdata)
65#define UNIXSECLEN(skb) (&UNIXCB((skb)).seclen)
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
Benjamin LaHaisefd19f322006-01-03 14:10:46 -080067#define unix_state_rlock(s) spin_lock(&unix_sk(s)->lock)
68#define unix_state_runlock(s) spin_unlock(&unix_sk(s)->lock)
69#define unix_state_wlock(s) spin_lock(&unix_sk(s)->lock)
Ingo Molnara09785a2006-07-03 00:25:12 -070070#define unix_state_wlock_nested(s) \
71 spin_lock_nested(&unix_sk(s)->lock, \
72 SINGLE_DEPTH_NESTING)
Benjamin LaHaisefd19f322006-01-03 14:10:46 -080073#define unix_state_wunlock(s) spin_unlock(&unix_sk(s)->lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
75#ifdef __KERNEL__
76/* The AF_UNIX socket */
77struct unix_sock {
78 /* WARNING: sk has to be the first member */
79 struct sock sk;
80 struct unix_address *addr;
81 struct dentry *dentry;
82 struct vfsmount *mnt;
Ingo Molnar57b47a52006-03-20 22:35:41 -080083 struct mutex readlock;
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 struct sock *peer;
85 struct sock *other;
86 struct sock *gc_tree;
87 atomic_t inflight;
Benjamin LaHaisefd19f322006-01-03 14:10:46 -080088 spinlock_t lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 wait_queue_head_t peer_wait;
90};
91#define unix_sk(__sk) ((struct unix_sock *)__sk)
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030092
93#ifdef CONFIG_SYSCTL
94extern int sysctl_unix_max_dgram_qlen;
95extern void unix_sysctl_register(void);
96extern void unix_sysctl_unregister(void);
97#else
98static inline void unix_sysctl_register(void) {}
99static inline void unix_sysctl_unregister(void) {}
100#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101#endif
102#endif