xref: /openbmc/linux/include/net/af_unix.h (revision 8c9814b97002f61846ebf3048e8df5aae52f7828)
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>
7*8c9814b9SReshetova, Elena #include <linux/refcount.h>
820380731SArnaldo Carvalho de Melo #include <net/sock.h>
920380731SArnaldo Carvalho de Melo 
10415e3d3eSHannes Frederic Sowa void unix_inflight(struct user_struct *user, struct file *fp);
11415e3d3eSHannes Frederic Sowa void unix_notinflight(struct user_struct *user, struct file *fp);
12b60a8280SJoe Perches void unix_gc(void);
13b60a8280SJoe Perches void wait_for_unix_gc(void);
14b60a8280SJoe Perches struct sock *unix_get_socket(struct file *filp);
15b60a8280SJoe Perches struct sock *unix_peer_get(struct sock *);
161da177e4SLinus Torvalds 
171da177e4SLinus Torvalds #define UNIX_HASH_SIZE	256
187123aaa3SEric Dumazet #define UNIX_HASH_BITS	8
191da177e4SLinus Torvalds 
209305cfa4SPavel Emelyanov extern unsigned int unix_tot_inflight;
21fa7ff56fSPavel Emelyanov extern spinlock_t unix_table_lock;
227123aaa3SEric Dumazet extern struct hlist_head unix_socket_table[2 * UNIX_HASH_SIZE];
231da177e4SLinus Torvalds 
241da177e4SLinus Torvalds struct unix_address {
25*8c9814b9SReshetova, Elena 	refcount_t	refcnt;
261da177e4SLinus Torvalds 	int		len;
2795c96174SEric Dumazet 	unsigned int	hash;
281da177e4SLinus Torvalds 	struct sockaddr_un name[0];
291da177e4SLinus Torvalds };
301da177e4SLinus Torvalds 
311da177e4SLinus Torvalds struct unix_skb_parms {
327361c36cSEric W. Biederman 	struct pid		*pid;		/* Skb credentials	*/
336b0ee8c0SEric W. Biederman 	kuid_t			uid;
346b0ee8c0SEric W. Biederman 	kgid_t			gid;
351da177e4SLinus Torvalds 	struct scm_fp_list	*fp;		/* Passed files		*/
36877ce7c1SCatherine Zhang #ifdef CONFIG_SECURITY_NETWORK
37dc49c1f9SCatherine Zhang 	u32			secid;		/* Security ID		*/
38877ce7c1SCatherine Zhang #endif
39e370a723SEric Dumazet 	u32			consumed;
401da177e4SLinus Torvalds };
411da177e4SLinus Torvalds 
421da177e4SLinus Torvalds #define UNIXCB(skb) 	(*(struct unix_skb_parms *)&((skb)->cb))
431da177e4SLinus Torvalds 
441c92b4e5SDavid S. Miller #define unix_state_lock(s)	spin_lock(&unix_sk(s)->lock)
451c92b4e5SDavid S. Miller #define unix_state_unlock(s)	spin_unlock(&unix_sk(s)->lock)
461c92b4e5SDavid S. Miller #define unix_state_lock_nested(s) \
47a09785a2SIngo Molnar 				spin_lock_nested(&unix_sk(s)->lock, \
48a09785a2SIngo Molnar 				SINGLE_DEPTH_NESTING)
491da177e4SLinus Torvalds 
501da177e4SLinus Torvalds /* The AF_UNIX socket */
511da177e4SLinus Torvalds struct unix_sock {
521da177e4SLinus Torvalds 	/* WARNING: sk has to be the first member */
531da177e4SLinus Torvalds 	struct sock		sk;
541da177e4SLinus Torvalds 	struct unix_address     *addr;
5540ffe67dSAl Viro 	struct path		path;
566e1ce3c3SLinus Torvalds 	struct mutex		iolock, bindlock;
571da177e4SLinus Torvalds 	struct sock		*peer;
581fd05ba5SMiklos Szeredi 	struct list_head	link;
59516e0cc5SAl Viro 	atomic_long_t		inflight;
60fd19f329SBenjamin LaHaise 	spinlock_t		lock;
6125888e30SEric Dumazet 	unsigned char		recursion_level;
6260bc851aSEric Dumazet 	unsigned long		gc_flags;
6360bc851aSEric Dumazet #define UNIX_GC_CANDIDATE	0
6460bc851aSEric Dumazet #define UNIX_GC_MAYBE_CYCLE	1
6543815482SEric Dumazet 	struct socket_wq	peer_wq;
667d267278SRainer Weikusat 	wait_queue_t		peer_wake;
671da177e4SLinus Torvalds };
684613012dSAaron Conole 
69c72eda06SPaul Moore static inline struct unix_sock *unix_sk(const struct sock *sk)
704613012dSAaron Conole {
714613012dSAaron Conole 	return (struct unix_sock *)sk;
724613012dSAaron Conole }
7320380731SArnaldo Carvalho de Melo 
7443815482SEric Dumazet #define peer_wait peer_wq.wait
7543815482SEric Dumazet 
76885ee74dSPavel Emelyanov long unix_inq_len(struct sock *sk);
77885ee74dSPavel Emelyanov long unix_outq_len(struct sock *sk);
78885ee74dSPavel Emelyanov 
7920380731SArnaldo Carvalho de Melo #ifdef CONFIG_SYSCTL
80b60a8280SJoe Perches int unix_sysctl_register(struct net *net);
81b60a8280SJoe Perches void unix_sysctl_unregister(struct net *net);
8220380731SArnaldo Carvalho de Melo #else
8397577e38SPavel Emelyanov static inline int unix_sysctl_register(struct net *net) { return 0; }
8497577e38SPavel Emelyanov static inline void unix_sysctl_unregister(struct net *net) {}
8520380731SArnaldo Carvalho de Melo #endif
861da177e4SLinus Torvalds #endif
87