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 17

#define UNIX_HASH_SIZE	256

18
extern unsigned int unix_tot_inflight;
19 20
extern spinlock_t unix_table_lock;
extern struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1];
L
Linus Torvalds 已提交
21 22 23 24 25 26 27 28 29

struct unix_address {
	atomic_t	refcnt;
	int		len;
	unsigned	hash;
	struct sockaddr_un name[0];
};

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

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

41 42 43
#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) \
44 45
				spin_lock_nested(&unix_sk(s)->lock, \
				SINGLE_DEPTH_NESTING)
L
Linus Torvalds 已提交
46 47 48 49 50

/* The AF_UNIX socket */
struct unix_sock {
	/* WARNING: sk has to be the first member */
	struct sock		sk;
51 52 53
	struct unix_address     *addr;
	struct dentry		*dentry;
	struct vfsmount		*mnt;
I
Ingo Molnar 已提交
54
	struct mutex		readlock;
55 56
	struct sock		*peer;
	struct sock		*other;
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
#ifdef CONFIG_SYSCTL
70 71
extern int unix_sysctl_register(struct net *net);
extern void unix_sysctl_unregister(struct net *net);
72
#else
73 74
static inline int unix_sysctl_register(struct net *net) { return 0; }
static inline void unix_sysctl_unregister(struct net *net) {}
75
#endif
L
Linus Torvalds 已提交
76
#endif