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