xref: /linux/net/unix/af_unix.h (revision 1a9239bb4253f9076b5b4b2a1a4e8d7defd77a95)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __AF_UNIX_H
3 #define __AF_UNIX_H
4 
5 #include <linux/uidgid.h>
6 
7 #define UNIX_HASH_MOD	(256 - 1)
8 #define UNIX_HASH_SIZE	(256 * 2)
9 #define UNIX_HASH_BITS	8
10 
11 struct sock *unix_peer_get(struct sock *sk);
12 
13 struct unix_skb_parms {
14 	struct pid		*pid;		/* skb credentials	*/
15 	kuid_t			uid;
16 	kgid_t			gid;
17 	struct scm_fp_list	*fp;		/* Passed files		*/
18 #ifdef CONFIG_SECURITY_NETWORK
19 	u32			secid;		/* Security ID		*/
20 #endif
21 	u32			consumed;
22 } __randomize_layout;
23 
24 #define UNIXCB(skb)	(*(struct unix_skb_parms *)&((skb)->cb))
25 
26 /* GC for SCM_RIGHTS */
27 extern unsigned int unix_tot_inflight;
28 void unix_add_edges(struct scm_fp_list *fpl, struct unix_sock *receiver);
29 void unix_del_edges(struct scm_fp_list *fpl);
30 void unix_update_edges(struct unix_sock *receiver);
31 int unix_prepare_fpl(struct scm_fp_list *fpl);
32 void unix_destroy_fpl(struct scm_fp_list *fpl);
33 void unix_gc(void);
34 void wait_for_unix_gc(struct scm_fp_list *fpl);
35 
36 /* SOCK_DIAG */
37 long unix_inq_len(struct sock *sk);
38 long unix_outq_len(struct sock *sk);
39 
40 /* sysctl */
41 #ifdef CONFIG_SYSCTL
42 int unix_sysctl_register(struct net *net);
43 void unix_sysctl_unregister(struct net *net);
44 #else
unix_sysctl_register(struct net * net)45 static inline int unix_sysctl_register(struct net *net)
46 {
47 	return 0;
48 }
49 
unix_sysctl_unregister(struct net * net)50 static inline void unix_sysctl_unregister(struct net *net)
51 {
52 }
53 #endif
54 
55 /* BPF SOCKMAP */
56 int __unix_dgram_recvmsg(struct sock *sk, struct msghdr *msg, size_t size, int flags);
57 int __unix_stream_recvmsg(struct sock *sk, struct msghdr *msg, size_t size, int flags);
58 
59 #ifdef CONFIG_BPF_SYSCALL
60 extern struct proto unix_dgram_proto;
61 extern struct proto unix_stream_proto;
62 
63 int unix_dgram_bpf_update_proto(struct sock *sk, struct sk_psock *psock, bool restore);
64 int unix_stream_bpf_update_proto(struct sock *sk, struct sk_psock *psock, bool restore);
65 void __init unix_bpf_build_proto(void);
66 #else
unix_bpf_build_proto(void)67 static inline void __init unix_bpf_build_proto(void)
68 {
69 }
70 #endif
71 
72 #endif
73