af_unix.h 2.04 KB
Newer Older
Linus Torvalds's avatar
Linus Torvalds committed
1 2
#ifndef __LINUX_NET_AFUNIX_H
#define __LINUX_NET_AFUNIX_H
3 4 5

#include <linux/socket.h>
#include <linux/un.h>
Ingo Molnar's avatar
Ingo Molnar committed
6
#include <linux/mutex.h>
7 8
#include <net/sock.h>

Linus Torvalds's avatar
Linus Torvalds committed
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);
Eric Dumazet's avatar
Eric Dumazet committed
13
extern struct sock *unix_get_socket(struct file *filp);
14
extern struct sock *unix_peer_get(struct sock *);
Linus Torvalds's avatar
Linus Torvalds committed
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];
Linus Torvalds's avatar
Linus Torvalds committed
21 22 23 24

struct unix_address {
	atomic_t	refcnt;
	int		len;
25
	unsigned int	hash;
Linus Torvalds's avatar
Linus Torvalds committed
26 27 28 29
	struct sockaddr_un name[0];
};

struct unix_skb_parms {
30 31
	struct pid		*pid;		/* Skb credentials	*/
	const struct cred	*cred;
Linus Torvalds's avatar
Linus Torvalds committed
32
	struct scm_fp_list	*fp;		/* Passed files		*/
33
#ifdef CONFIG_SECURITY_NETWORK
34
	u32			secid;		/* Security ID		*/
35
#endif
Linus Torvalds's avatar
Linus Torvalds committed
36 37
};

38
#define UNIXCB(skb) 	(*(struct unix_skb_parms *)&((skb)->cb))
39
#define UNIXSID(skb)	(&UNIXCB((skb)).secid)
Linus Torvalds's avatar
Linus Torvalds committed
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)
Linus Torvalds's avatar
Linus Torvalds committed
46 47 48 49 50

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

66 67
#define peer_wait peer_wq.wait

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

71
#ifdef CONFIG_SYSCTL
72 73
extern int unix_sysctl_register(struct net *net);
extern void unix_sysctl_unregister(struct net *net);
74
#else
75 76
static inline int unix_sysctl_register(struct net *net) { return 0; }
static inline void unix_sysctl_unregister(struct net *net) {}
77
#endif
Linus Torvalds's avatar
Linus Torvalds committed
78
#endif