xref: /openbmc/linux/include/net/af_unix.h (revision fa7ff56f75add89bbedaf2dfcfa8f6661e8e8b3a)
11da177e4SLinus Torvalds #ifndef __LINUX_NET_AFUNIX_H
21da177e4SLinus Torvalds #define __LINUX_NET_AFUNIX_H
320380731SArnaldo Carvalho de Melo 
420380731SArnaldo Carvalho de Melo #include <linux/socket.h>
520380731SArnaldo Carvalho de Melo #include <linux/un.h>
657b47a53SIngo Molnar #include <linux/mutex.h>
720380731SArnaldo Carvalho de Melo #include <net/sock.h>
820380731SArnaldo Carvalho de Melo 
91da177e4SLinus Torvalds extern void unix_inflight(struct file *fp);
101da177e4SLinus Torvalds extern void unix_notinflight(struct file *fp);
111da177e4SLinus Torvalds extern void unix_gc(void);
125f23b734Sdann frazier extern void wait_for_unix_gc(void);
1325888e30SEric Dumazet extern struct sock *unix_get_socket(struct file *filp);
14*fa7ff56fSPavel Emelyanov extern struct sock *unix_peer_get(struct sock *);
151da177e4SLinus Torvalds 
161da177e4SLinus Torvalds #define UNIX_HASH_SIZE	256
171da177e4SLinus Torvalds 
189305cfa4SPavel Emelyanov extern unsigned int unix_tot_inflight;
19*fa7ff56fSPavel Emelyanov extern spinlock_t unix_table_lock;
20*fa7ff56fSPavel Emelyanov extern struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1];
211da177e4SLinus Torvalds 
221da177e4SLinus Torvalds struct unix_address {
231da177e4SLinus Torvalds 	atomic_t	refcnt;
241da177e4SLinus Torvalds 	int		len;
251da177e4SLinus Torvalds 	unsigned	hash;
261da177e4SLinus Torvalds 	struct sockaddr_un name[0];
271da177e4SLinus Torvalds };
281da177e4SLinus Torvalds 
291da177e4SLinus Torvalds struct unix_skb_parms {
307361c36cSEric W. Biederman 	struct pid		*pid;		/* Skb credentials	*/
317361c36cSEric W. Biederman 	const struct cred	*cred;
321da177e4SLinus Torvalds 	struct scm_fp_list	*fp;		/* Passed files		*/
33877ce7c1SCatherine Zhang #ifdef CONFIG_SECURITY_NETWORK
34dc49c1f9SCatherine Zhang 	u32			secid;		/* Security ID		*/
35877ce7c1SCatherine Zhang #endif
361da177e4SLinus Torvalds };
371da177e4SLinus Torvalds 
381da177e4SLinus Torvalds #define UNIXCB(skb) 	(*(struct unix_skb_parms *)&((skb)->cb))
39dc49c1f9SCatherine Zhang #define UNIXSID(skb)	(&UNIXCB((skb)).secid)
401da177e4SLinus Torvalds 
411c92b4e5SDavid S. Miller #define unix_state_lock(s)	spin_lock(&unix_sk(s)->lock)
421c92b4e5SDavid S. Miller #define unix_state_unlock(s)	spin_unlock(&unix_sk(s)->lock)
431c92b4e5SDavid S. Miller #define unix_state_lock_nested(s) \
44a09785a2SIngo Molnar 				spin_lock_nested(&unix_sk(s)->lock, \
45a09785a2SIngo Molnar 				SINGLE_DEPTH_NESTING)
461da177e4SLinus Torvalds 
471da177e4SLinus Torvalds /* The AF_UNIX socket */
481da177e4SLinus Torvalds struct unix_sock {
491da177e4SLinus Torvalds 	/* WARNING: sk has to be the first member */
501da177e4SLinus Torvalds 	struct sock		sk;
511da177e4SLinus Torvalds 	struct unix_address     *addr;
521da177e4SLinus Torvalds 	struct dentry		*dentry;
531da177e4SLinus Torvalds 	struct vfsmount		*mnt;
5457b47a53SIngo Molnar 	struct mutex		readlock;
551da177e4SLinus Torvalds 	struct sock		*peer;
561da177e4SLinus Torvalds 	struct sock		*other;
571fd05ba5SMiklos Szeredi 	struct list_head	link;
58516e0cc5SAl Viro 	atomic_long_t		inflight;
59fd19f329SBenjamin LaHaise 	spinlock_t		lock;
601fd05ba5SMiklos Szeredi 	unsigned int		gc_candidate : 1;
616209344fSMiklos Szeredi 	unsigned int		gc_maybe_cycle : 1;
6225888e30SEric Dumazet 	unsigned char		recursion_level;
6343815482SEric Dumazet 	struct socket_wq	peer_wq;
641da177e4SLinus Torvalds };
651da177e4SLinus Torvalds #define unix_sk(__sk) ((struct unix_sock *)__sk)
6620380731SArnaldo Carvalho de Melo 
6743815482SEric Dumazet #define peer_wait peer_wq.wait
6843815482SEric Dumazet 
6920380731SArnaldo Carvalho de Melo #ifdef CONFIG_SYSCTL
7097577e38SPavel Emelyanov extern int unix_sysctl_register(struct net *net);
7197577e38SPavel Emelyanov extern void unix_sysctl_unregister(struct net *net);
7220380731SArnaldo Carvalho de Melo #else
7397577e38SPavel Emelyanov static inline int unix_sysctl_register(struct net *net) { return 0; }
7497577e38SPavel Emelyanov static inline void unix_sysctl_unregister(struct net *net) {}
7520380731SArnaldo Carvalho de Melo #endif
761da177e4SLinus Torvalds #endif
77