18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci#ifndef __LINUX_NET_AFUNIX_H 38c2ecf20Sopenharmony_ci#define __LINUX_NET_AFUNIX_H 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci#include <linux/socket.h> 68c2ecf20Sopenharmony_ci#include <linux/un.h> 78c2ecf20Sopenharmony_ci#include <linux/mutex.h> 88c2ecf20Sopenharmony_ci#include <linux/refcount.h> 98c2ecf20Sopenharmony_ci#include <net/sock.h> 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_civoid unix_inflight(struct user_struct *user, struct file *fp); 128c2ecf20Sopenharmony_civoid unix_notinflight(struct user_struct *user, struct file *fp); 138c2ecf20Sopenharmony_civoid unix_destruct_scm(struct sk_buff *skb); 148c2ecf20Sopenharmony_civoid unix_gc(void); 158c2ecf20Sopenharmony_civoid wait_for_unix_gc(void); 168c2ecf20Sopenharmony_cistruct sock *unix_get_socket(struct file *filp); 178c2ecf20Sopenharmony_cistruct sock *unix_peer_get(struct sock *sk); 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci#define UNIX_HASH_SIZE 256 208c2ecf20Sopenharmony_ci#define UNIX_HASH_BITS 8 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ciextern unsigned int unix_tot_inflight; 238c2ecf20Sopenharmony_ciextern spinlock_t unix_table_lock; 248c2ecf20Sopenharmony_ciextern struct hlist_head unix_socket_table[2 * UNIX_HASH_SIZE]; 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_cistruct unix_address { 278c2ecf20Sopenharmony_ci refcount_t refcnt; 288c2ecf20Sopenharmony_ci int len; 298c2ecf20Sopenharmony_ci unsigned int hash; 308c2ecf20Sopenharmony_ci struct sockaddr_un name[]; 318c2ecf20Sopenharmony_ci}; 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_cistruct unix_skb_parms { 348c2ecf20Sopenharmony_ci struct pid *pid; /* Skb credentials */ 358c2ecf20Sopenharmony_ci kuid_t uid; 368c2ecf20Sopenharmony_ci kgid_t gid; 378c2ecf20Sopenharmony_ci struct scm_fp_list *fp; /* Passed files */ 388c2ecf20Sopenharmony_ci#ifdef CONFIG_SECURITY_NETWORK 398c2ecf20Sopenharmony_ci u32 secid; /* Security ID */ 408c2ecf20Sopenharmony_ci#endif 418c2ecf20Sopenharmony_ci u32 consumed; 428c2ecf20Sopenharmony_ci} __randomize_layout; 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_cistruct scm_stat { 458c2ecf20Sopenharmony_ci atomic_t nr_fds; 468c2ecf20Sopenharmony_ci}; 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci#define UNIXCB(skb) (*(struct unix_skb_parms *)&((skb)->cb)) 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci/* The AF_UNIX socket */ 518c2ecf20Sopenharmony_cistruct unix_sock { 528c2ecf20Sopenharmony_ci /* WARNING: sk has to be the first member */ 538c2ecf20Sopenharmony_ci struct sock sk; 548c2ecf20Sopenharmony_ci struct unix_address *addr; 558c2ecf20Sopenharmony_ci struct path path; 568c2ecf20Sopenharmony_ci struct mutex iolock, bindlock; 578c2ecf20Sopenharmony_ci struct sock *peer; 588c2ecf20Sopenharmony_ci struct list_head link; 598c2ecf20Sopenharmony_ci atomic_long_t inflight; 608c2ecf20Sopenharmony_ci spinlock_t lock; 618c2ecf20Sopenharmony_ci unsigned long gc_flags; 628c2ecf20Sopenharmony_ci#define UNIX_GC_CANDIDATE 0 638c2ecf20Sopenharmony_ci#define UNIX_GC_MAYBE_CYCLE 1 648c2ecf20Sopenharmony_ci struct socket_wq peer_wq; 658c2ecf20Sopenharmony_ci wait_queue_entry_t peer_wake; 668c2ecf20Sopenharmony_ci struct scm_stat scm_stat; 678c2ecf20Sopenharmony_ci}; 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_cistatic inline struct unix_sock *unix_sk(const struct sock *sk) 708c2ecf20Sopenharmony_ci{ 718c2ecf20Sopenharmony_ci return (struct unix_sock *)sk; 728c2ecf20Sopenharmony_ci} 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_ci#define unix_state_lock(s) spin_lock(&unix_sk(s)->lock) 758c2ecf20Sopenharmony_ci#define unix_state_unlock(s) spin_unlock(&unix_sk(s)->lock) 768c2ecf20Sopenharmony_cienum unix_socket_lock_class { 778c2ecf20Sopenharmony_ci U_LOCK_NORMAL, 788c2ecf20Sopenharmony_ci U_LOCK_SECOND, /* for double locking, see unix_state_double_lock(). */ 798c2ecf20Sopenharmony_ci U_LOCK_DIAG, /* used while dumping icons, see sk_diag_dump_icons(). */ 808c2ecf20Sopenharmony_ci}; 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_cistatic inline void unix_state_lock_nested(struct sock *sk, 838c2ecf20Sopenharmony_ci enum unix_socket_lock_class subclass) 848c2ecf20Sopenharmony_ci{ 858c2ecf20Sopenharmony_ci spin_lock_nested(&unix_sk(sk)->lock, subclass); 868c2ecf20Sopenharmony_ci} 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ci#define peer_wait peer_wq.wait 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_cilong unix_inq_len(struct sock *sk); 918c2ecf20Sopenharmony_cilong unix_outq_len(struct sock *sk); 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_ci#ifdef CONFIG_SYSCTL 948c2ecf20Sopenharmony_ciint unix_sysctl_register(struct net *net); 958c2ecf20Sopenharmony_civoid unix_sysctl_unregister(struct net *net); 968c2ecf20Sopenharmony_ci#else 978c2ecf20Sopenharmony_cistatic inline int unix_sysctl_register(struct net *net) { return 0; } 988c2ecf20Sopenharmony_cistatic inline void unix_sysctl_unregister(struct net *net) {} 998c2ecf20Sopenharmony_ci#endif 1008c2ecf20Sopenharmony_ci#endif 101