Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef __LINUX_NET_AFUNIX_H
0003 #define __LINUX_NET_AFUNIX_H
0004 
0005 #include <linux/socket.h>
0006 #include <linux/un.h>
0007 #include <linux/mutex.h>
0008 #include <linux/refcount.h>
0009 #include <net/sock.h>
0010 
0011 void unix_inflight(struct user_struct *user, struct file *fp);
0012 void unix_notinflight(struct user_struct *user, struct file *fp);
0013 void unix_destruct_scm(struct sk_buff *skb);
0014 void unix_gc(void);
0015 void wait_for_unix_gc(void);
0016 struct sock *unix_get_socket(struct file *filp);
0017 struct sock *unix_peer_get(struct sock *sk);
0018 
0019 #define UNIX_HASH_MOD   (256 - 1)
0020 #define UNIX_HASH_SIZE  (256 * 2)
0021 #define UNIX_HASH_BITS  8
0022 
0023 extern unsigned int unix_tot_inflight;
0024 
0025 struct unix_address {
0026     refcount_t  refcnt;
0027     int     len;
0028     struct sockaddr_un name[];
0029 };
0030 
0031 struct unix_skb_parms {
0032     struct pid      *pid;       /* Skb credentials  */
0033     kuid_t          uid;
0034     kgid_t          gid;
0035     struct scm_fp_list  *fp;        /* Passed files     */
0036 #ifdef CONFIG_SECURITY_NETWORK
0037     u32         secid;      /* Security ID      */
0038 #endif
0039     u32         consumed;
0040 } __randomize_layout;
0041 
0042 struct scm_stat {
0043     atomic_t nr_fds;
0044 };
0045 
0046 #define UNIXCB(skb) (*(struct unix_skb_parms *)&((skb)->cb))
0047 
0048 #define unix_state_lock(s)  spin_lock(&unix_sk(s)->lock)
0049 #define unix_state_unlock(s)    spin_unlock(&unix_sk(s)->lock)
0050 #define unix_state_lock_nested(s) \
0051                 spin_lock_nested(&unix_sk(s)->lock, \
0052                 SINGLE_DEPTH_NESTING)
0053 
0054 /* The AF_UNIX socket */
0055 struct unix_sock {
0056     /* WARNING: sk has to be the first member */
0057     struct sock     sk;
0058     struct unix_address *addr;
0059     struct path     path;
0060     struct mutex        iolock, bindlock;
0061     struct sock     *peer;
0062     struct list_head    link;
0063     atomic_long_t       inflight;
0064     spinlock_t      lock;
0065     unsigned long       gc_flags;
0066 #define UNIX_GC_CANDIDATE   0
0067 #define UNIX_GC_MAYBE_CYCLE 1
0068     struct socket_wq    peer_wq;
0069     wait_queue_entry_t  peer_wake;
0070     struct scm_stat     scm_stat;
0071 #if IS_ENABLED(CONFIG_AF_UNIX_OOB)
0072     struct sk_buff      *oob_skb;
0073 #endif
0074 };
0075 
0076 static inline struct unix_sock *unix_sk(const struct sock *sk)
0077 {
0078     return (struct unix_sock *)sk;
0079 }
0080 
0081 #define peer_wait peer_wq.wait
0082 
0083 long unix_inq_len(struct sock *sk);
0084 long unix_outq_len(struct sock *sk);
0085 
0086 int __unix_dgram_recvmsg(struct sock *sk, struct msghdr *msg, size_t size,
0087              int flags);
0088 int __unix_stream_recvmsg(struct sock *sk, struct msghdr *msg, size_t size,
0089               int flags);
0090 #ifdef CONFIG_SYSCTL
0091 int unix_sysctl_register(struct net *net);
0092 void unix_sysctl_unregister(struct net *net);
0093 #else
0094 static inline int unix_sysctl_register(struct net *net) { return 0; }
0095 static inline void unix_sysctl_unregister(struct net *net) {}
0096 #endif
0097 
0098 #ifdef CONFIG_BPF_SYSCALL
0099 extern struct proto unix_dgram_proto;
0100 extern struct proto unix_stream_proto;
0101 
0102 int unix_dgram_bpf_update_proto(struct sock *sk, struct sk_psock *psock, bool restore);
0103 int unix_stream_bpf_update_proto(struct sock *sk, struct sk_psock *psock, bool restore);
0104 void __init unix_bpf_build_proto(void);
0105 #else
0106 static inline void __init unix_bpf_build_proto(void)
0107 {}
0108 #endif
0109 #endif