xref: /xnu-12377.41.6/bsd/net/aop/kpi_aop.h (revision bbb1b6f9e71b8cdde6e5cd6f4841f207dee3d828)
1 /*
2  * Copyright (c) 2025 Apple Inc. All rights reserved.
3  *
4  * @APPLE_OSREFERENCE_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. The rights granted to you under the License
10  * may not be used to create, or enable the creation or redistribution of,
11  * unlawful or unlicensed copies of an Apple operating system, or to
12  * circumvent, violate, or enable the circumvention or violation of, any
13  * terms of an Apple operating system software license agreement.
14  *
15  * Please obtain a copy of the License at
16  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17  *
18  * The Original Code and all software distributed under the License are
19  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23  * Please see the License for the specific language governing rights and
24  * limitations under the License.
25  *
26  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27  */
28 /*!
29  *       @header kpi_aop.h
30  *       This header defines an SPI to interact with the AOP
31  *       using shared memory. The SPIs could be used to collect networking
32  *       stats associated with flows in AOP.
33  */
34 
35 #ifndef __NET_KPI_AOP_H__
36 #define __NET_KPI_AOP_H__
37 
38 #include <net/aop/aop_stats.h>
39 #include <net/aop/aop_flow_stats.h>
40 
41 __BEGIN_DECLS
42 
43 typedef enum {
44 	NET_AOP_CAPAB_FLOW_SETUP = 1,
45 	NET_AOP_CAPAB_FLOW_STATS = 2,
46 	NET_AOP_CAPAB_STATS = 3,
47 	NET_AOP_CAPAB_PROC_ACTIVITY_BITMAP = 4,
48 } net_aop_capab_t;
49 
50 typedef errno_t (*net_aop_config_fn_t)(void *prov_ctx,
51     net_aop_capab_t capab, void *contents, uint32_t *len);
52 
53 #define NET_AOP_VERSION_1 1
54 typedef struct net_aop_provider_init {
55 	uint32_t                 kaopi_version;
56 	net_aop_config_fn_t kaopi_config_capab;
57 } net_aop_provider_init_t;
58 
59 #define NET_AOP_CAPAB_FLOW_SETUP_VERSION_1 1
60 typedef errno_t (*net_aop_flow_setup_fn_t)(void *prov_ctx,
61     uint32_t flow_id, bool add, uint32_t *stats_index);
62 struct net_aop_capab_flow_setup {
63 	uint32_t kaopcfsp_version;
64 	void *kaopcfsp_prov_ctx;
65 	net_aop_flow_setup_fn_t kaopcfsp_config;
66 };
67 
68 #define NET_AOP_CAPAB_FLOW_STATS_VERSION_1 1
69 typedef errno_t (*net_aop_flow_stats_fn_t)(void *prov_ctx,
70     uint32_t stats_index, struct aop_flow_stats *flow_stats);
71 struct net_aop_capab_flow_stats {
72 	uint32_t kaopcfs_version;
73 	void *kaopcfs_prov_ctx;
74 	net_aop_flow_stats_fn_t kaopcfs_config;
75 };
76 
77 typedef enum {
78 	NET_AOP_STATS_TYPE_INVALID = 0,
79 	NET_AOP_STATS_TYPE_IP = 1,
80 	NET_AOP_STATS_TYPE_IPV6 = 2,
81 	NET_AOP_STATS_TYPE_TCP = 3,
82 	NET_AOP_STATS_TYPE_UDP = 4,
83 	NET_AOP_STATS_TYPE_DRIVER = 5,
84 	NET_AOP_STATS_TYPE_MAX = NET_AOP_STATS_TYPE_DRIVER,
85 } net_aop_stats_type_t;
86 
87 #define NET_AOP_CAPAB_STATS_VERSION_1 1
88 typedef errno_t (*net_aop_stats_fn_t)(void *prov_ctx,
89     net_aop_stats_type_t type, uint8_t *stats, size_t stats_len);
90 struct net_aop_capab_stats {
91 	uint32_t kaopcgs_version;
92 	void *kaopcgs_prov_ctx;
93 	net_aop_stats_fn_t kaopcgs_config;
94 };
95 
96 #define NET_AOP_CAPAB_PROC_ACTIVITY_BITMAP_VERSION_1 1
97 typedef errno_t (*net_aop_proc_activity_bitmap_fn_t)(void *prov_ctx,
98     struct aop_proc_activity_bitmap *proc_activity_bitmaps, uint16_t *inout_count);
99 struct net_aop_capab_proc_activity_bitmap {
100 	uint32_t kaopbm_version;
101 	void *kaopbm_prov_ctx;
102 	net_aop_proc_activity_bitmap_fn_t kaopbm_config;
103 };
104 
105 typedef struct net_aop_provider_handle *net_aop_provider_handle_t;
106 
107 extern net_aop_provider_handle_t
108 net_aop_register_provider(const struct net_aop_provider_init *init,
109     const uint32_t init_len, void *ctx);
110 extern void
111 net_aop_deregister_provider(net_aop_provider_handle_t prov);
112 
113 #ifdef BSD_KERNEL_PRIVATE
114 void net_aop_init(void);
115 
116 int net_aop_setup_flow(uint32_t flow_id, bool add, uint32_t *stats_index);
117 
118 int net_aop_get_flow_stats(uint32_t stats_index, struct aop_flow_stats *flow_stats);
119 
120 int net_aop_get_stats(net_aop_stats_type_t type,
121     uint8_t *__sized_by(stats_len) stats, size_t stats_len);
122 
123 int net_aop_get_proc_activity_bitmaps(struct aop_proc_activity_bitmap *proc_activity_bitmaps,
124     uint16_t *inout_count);
125 #endif // BSD_KERNEL_PRIVATE
126 
127 __END_DECLS
128 
129 #endif /* __NET_KPI_AOP_H__ */
130