1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */ 21da177e4SLinus Torvalds #ifndef __LINUX_NET_AFUNIX_H 31da177e4SLinus Torvalds #define __LINUX_NET_AFUNIX_H 420380731SArnaldo Carvalho de Melo 520380731SArnaldo Carvalho de Melo #include <linux/socket.h> 620380731SArnaldo Carvalho de Melo #include <linux/un.h> 757b47a53SIngo Molnar #include <linux/mutex.h> 88c9814b9SReshetova, Elena #include <linux/refcount.h> 920380731SArnaldo Carvalho de Melo #include <net/sock.h> 1020380731SArnaldo Carvalho de Melo 11415e3d3eSHannes Frederic Sowa void unix_inflight(struct user_struct *user, struct file *fp); 12415e3d3eSHannes Frederic Sowa void unix_notinflight(struct user_struct *user, struct file *fp); 13f4e65870SJens Axboe void unix_destruct_scm(struct sk_buff *skb); 14b60a8280SJoe Perches void unix_gc(void); 15b60a8280SJoe Perches void wait_for_unix_gc(void); 16b60a8280SJoe Perches struct sock *unix_get_socket(struct file *filp); 17c4147beaSBo YU struct sock *unix_peer_get(struct sock *sk); 181da177e4SLinus Torvalds 191da177e4SLinus Torvalds #define UNIX_HASH_SIZE 256 207123aaa3SEric Dumazet #define UNIX_HASH_BITS 8 211da177e4SLinus Torvalds 229305cfa4SPavel Emelyanov extern unsigned int unix_tot_inflight; 23fa7ff56fSPavel Emelyanov extern spinlock_t unix_table_lock; 247123aaa3SEric Dumazet extern struct hlist_head unix_socket_table[2 * UNIX_HASH_SIZE]; 251da177e4SLinus Torvalds 261da177e4SLinus Torvalds struct unix_address { 278c9814b9SReshetova, Elena refcount_t refcnt; 281da177e4SLinus Torvalds int len; 2995c96174SEric Dumazet unsigned int hash; 301da177e4SLinus Torvalds struct sockaddr_un name[0]; 311da177e4SLinus Torvalds }; 321da177e4SLinus Torvalds 331da177e4SLinus Torvalds struct unix_skb_parms { 347361c36cSEric W. Biederman struct pid *pid; /* Skb credentials */ 356b0ee8c0SEric W. Biederman kuid_t uid; 366b0ee8c0SEric W. Biederman kgid_t gid; 371da177e4SLinus Torvalds struct scm_fp_list *fp; /* Passed files */ 38877ce7c1SCatherine Zhang #ifdef CONFIG_SECURITY_NETWORK 39dc49c1f9SCatherine Zhang u32 secid; /* Security ID */ 40877ce7c1SCatherine Zhang #endif 41e370a723SEric Dumazet u32 consumed; 423859a271SKees Cook } __randomize_layout; 431da177e4SLinus Torvalds 44*3c32da19SKirill Tkhai struct scm_stat { 45*3c32da19SKirill Tkhai u32 nr_fds; 46*3c32da19SKirill Tkhai }; 47*3c32da19SKirill Tkhai 481da177e4SLinus Torvalds #define UNIXCB(skb) (*(struct unix_skb_parms *)&((skb)->cb)) 491da177e4SLinus Torvalds 501c92b4e5SDavid S. Miller #define unix_state_lock(s) spin_lock(&unix_sk(s)->lock) 511c92b4e5SDavid S. Miller #define unix_state_unlock(s) spin_unlock(&unix_sk(s)->lock) 521c92b4e5SDavid S. Miller #define unix_state_lock_nested(s) \ 53a09785a2SIngo Molnar spin_lock_nested(&unix_sk(s)->lock, \ 54a09785a2SIngo Molnar SINGLE_DEPTH_NESTING) 551da177e4SLinus Torvalds 561da177e4SLinus Torvalds /* The AF_UNIX socket */ 571da177e4SLinus Torvalds struct unix_sock { 581da177e4SLinus Torvalds /* WARNING: sk has to be the first member */ 591da177e4SLinus Torvalds struct sock sk; 601da177e4SLinus Torvalds struct unix_address *addr; 6140ffe67dSAl Viro struct path path; 626e1ce3c3SLinus Torvalds struct mutex iolock, bindlock; 631da177e4SLinus Torvalds struct sock *peer; 641fd05ba5SMiklos Szeredi struct list_head link; 65516e0cc5SAl Viro atomic_long_t inflight; 66fd19f329SBenjamin LaHaise spinlock_t lock; 6760bc851aSEric Dumazet unsigned long gc_flags; 6860bc851aSEric Dumazet #define UNIX_GC_CANDIDATE 0 6960bc851aSEric Dumazet #define UNIX_GC_MAYBE_CYCLE 1 7043815482SEric Dumazet struct socket_wq peer_wq; 71ac6424b9SIngo Molnar wait_queue_entry_t peer_wake; 72*3c32da19SKirill Tkhai struct scm_stat scm_stat; 731da177e4SLinus Torvalds }; 744613012dSAaron Conole 75c72eda06SPaul Moore static inline struct unix_sock *unix_sk(const struct sock *sk) 764613012dSAaron Conole { 774613012dSAaron Conole return (struct unix_sock *)sk; 784613012dSAaron Conole } 7920380731SArnaldo Carvalho de Melo 8043815482SEric Dumazet #define peer_wait peer_wq.wait 8143815482SEric Dumazet 82885ee74dSPavel Emelyanov long unix_inq_len(struct sock *sk); 83885ee74dSPavel Emelyanov long unix_outq_len(struct sock *sk); 84885ee74dSPavel Emelyanov 8520380731SArnaldo Carvalho de Melo #ifdef CONFIG_SYSCTL 86b60a8280SJoe Perches int unix_sysctl_register(struct net *net); 87b60a8280SJoe Perches void unix_sysctl_unregister(struct net *net); 8820380731SArnaldo Carvalho de Melo #else 8997577e38SPavel Emelyanov static inline int unix_sysctl_register(struct net *net) { return 0; } 9097577e38SPavel Emelyanov static inline void unix_sysctl_unregister(struct net *net) {} 9120380731SArnaldo Carvalho de Melo #endif 921da177e4SLinus Torvalds #endif 93