af_unix.h 2.0 KB
Newer Older
L
Linus Torvalds 已提交
1 2
#ifndef __LINUX_NET_AFUNIX_H
#define __LINUX_NET_AFUNIX_H
3 4 5

#include <linux/socket.h>
#include <linux/un.h>
I
Ingo Molnar 已提交
6
#include <linux/mutex.h>
7 8
#include <net/sock.h>

L
Linus Torvalds 已提交
9 10 11
extern void unix_inflight(struct file *fp);
extern void unix_notinflight(struct file *fp);
extern void unix_gc(void);
12
extern void wait_for_unix_gc(void);
E
Eric Dumazet 已提交
13
extern struct sock *unix_get_socket(struct file *filp);
14
extern struct sock *unix_peer_get(struct sock *);
L
Linus Torvalds 已提交
15 16

#define UNIX_HASH_SIZE	256
E
Eric Dumazet 已提交
17
#define UNIX_HASH_BITS	8
L
Linus Torvalds 已提交
18

19
extern unsigned int unix_tot_inflight;
20
extern spinlock_t unix_table_lock;
E
Eric Dumazet 已提交
21
extern struct hlist_head unix_socket_table[2 * UNIX_HASH_SIZE];
L
Linus Torvalds 已提交
22 23 24 25

struct unix_address {
	atomic_t	refcnt;
	int		len;
26
	unsigned int	hash;
L
Linus Torvalds 已提交
27 28 29 30
	struct sockaddr_un name[0];
};

struct unix_skb_parms {
31
	struct pid		*pid;		/* Skb credentials	*/
32 33
	kuid_t			uid;
	kgid_t			gid;
L
Linus Torvalds 已提交
34
	struct scm_fp_list	*fp;		/* Passed files		*/
C
Catherine Zhang 已提交
35
#ifdef CONFIG_SECURITY_NETWORK
36
	u32			secid;		/* Security ID		*/
C
Catherine Zhang 已提交
37
#endif
L
Linus Torvalds 已提交
38 39
};

40
#define UNIXCB(skb) 	(*(struct unix_skb_parms *)&((skb)->cb))
41
#define UNIXSID(skb)	(&UNIXCB((skb)).secid)
L
Linus Torvalds 已提交
42

43 44 45
#define unix_state_lock(s)	spin_lock(&unix_sk(s)->lock)
#define unix_state_unlock(s)	spin_unlock(&unix_sk(s)->lock)
#define unix_state_lock_nested(s) \
46 47
				spin_lock_nested(&unix_sk(s)->lock, \
				SINGLE_DEPTH_NESTING)
L
Linus Torvalds 已提交
48 49 50 51 52

/* The AF_UNIX socket */
struct unix_sock {
	/* WARNING: sk has to be the first member */
	struct sock		sk;
53
	struct unix_address     *addr;
A
Al Viro 已提交
54
	struct path		path;
I
Ingo Molnar 已提交
55
	struct mutex		readlock;
56
	struct sock		*peer;
57
	struct list_head	link;
58 59
	atomic_long_t		inflight;
	spinlock_t		lock;
60
	unsigned int		gc_candidate : 1;
61
	unsigned int		gc_maybe_cycle : 1;
E
Eric Dumazet 已提交
62
	unsigned char		recursion_level;
63
	struct socket_wq	peer_wq;
L
Linus Torvalds 已提交
64 65
};
#define unix_sk(__sk) ((struct unix_sock *)__sk)
66

67 68
#define peer_wait peer_wq.wait

69 70 71
long unix_inq_len(struct sock *sk);
long unix_outq_len(struct sock *sk);

72
#ifdef CONFIG_SYSCTL
73 74
extern int unix_sysctl_register(struct net *net);
extern void unix_sysctl_unregister(struct net *net);
75
#else
76 77
static inline int unix_sysctl_register(struct net *net) { return 0; }
static inline void unix_sysctl_unregister(struct net *net) {}
78
#endif
L
Linus Torvalds 已提交
79
#endif