xref: /xnu-12377.41.6/bsd/kern/uipc_socket.h (revision bbb1b6f9e71b8cdde6e5cd6f4841f207dee3d828)
1 /*
2  * Copyright (c) 2024 Apple Inc. All rights reserved.
3  *
4  * @APPLE_LICENSE_HEADER_START@
5  *
6  * This file contains Original Code and/or Modifications of Original Code
7  * as defined in and that are subject to the Apple Public Source License
8  * Version 2.0 (the 'License'). You may not use this file except in
9  * compliance with the License. Please obtain a copy of the License at
10  * http://www.opensource.apple.com/apsl/ and read it before using this
11  * file.
12  *
13  * The Original Code and all software distributed under the License are
14  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18  * Please see the License for the specific language governing rights and
19  * limitations under the License.
20  *
21  * @APPLE_LICENSE_HEADER_END@
22  */
23 
24 #ifdef XNU_KERNEL_PRIVATE
25 
26 #ifndef _KERN_UIPC_SOCKET_H
27 #define _KERN_UIPC_SOCKET_H
28 
29 #include <kern/mem_acct.h>
30 
31 #include <sys/socketvar.h>
32 
33 extern struct mem_acct *socket_memacct;
34 
35 static inline void
socket_memacct_add(unsigned int size)36 socket_memacct_add(unsigned int size)
37 {
38 	mem_acct_add(socket_memacct, size);
39 }
40 
41 static inline void
socket_memacct_sub(unsigned int size)42 socket_memacct_sub(unsigned int size)
43 {
44 	mem_acct_sub(socket_memacct, size);
45 }
46 
47 static inline bool
socket_memacct_hardlimit()48 socket_memacct_hardlimit()
49 {
50 	return mem_acct_limited(socket_memacct) == MEMACCT_HARDLIMIT;
51 }
52 
53 static inline bool
socket_memacct_limited()54 socket_memacct_limited()
55 {
56 	return mem_acct_limited(socket_memacct) != 0;
57 }
58 
59 struct sock_cm_info {
60 	int sotc;
61 	int netsvctype;
62 	uint64_t tx_time;
63 };
64 
65 static inline void
sock_init_cm_info(struct sock_cm_info * sockcminfo,const struct socket * so)66 sock_init_cm_info(struct sock_cm_info *sockcminfo, const struct socket *so)
67 {
68 	sockcminfo->sotc = so->so_traffic_class;
69 	sockcminfo->netsvctype = so->so_netsvctype;
70 	sockcminfo->tx_time = 0;
71 }
72 
73 extern void sock_parse_cm_info(struct mbuf *control, struct sock_cm_info *sockcminfo);
74 
75 #endif /*_KERN_UIPC_SOCKET_H */
76 
77 #endif /* XNU_KERNEL_PRIVATE */
78