1*43a90889SApple OSS Distributions /* 2*43a90889SApple OSS Distributions * Copyright (c) 2017-2021 Apple Inc. All rights reserved. 3*43a90889SApple OSS Distributions * 4*43a90889SApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5*43a90889SApple OSS Distributions * 6*43a90889SApple OSS Distributions * This file contains Original Code and/or Modifications of Original Code 7*43a90889SApple OSS Distributions * as defined in and that are subject to the Apple Public Source License 8*43a90889SApple OSS Distributions * Version 2.0 (the 'License'). You may not use this file except in 9*43a90889SApple OSS Distributions * compliance with the License. The rights granted to you under the License 10*43a90889SApple OSS Distributions * may not be used to create, or enable the creation or redistribution of, 11*43a90889SApple OSS Distributions * unlawful or unlicensed copies of an Apple operating system, or to 12*43a90889SApple OSS Distributions * circumvent, violate, or enable the circumvention or violation of, any 13*43a90889SApple OSS Distributions * terms of an Apple operating system software license agreement. 14*43a90889SApple OSS Distributions * 15*43a90889SApple OSS Distributions * Please obtain a copy of the License at 16*43a90889SApple OSS Distributions * http://www.opensource.apple.com/apsl/ and read it before using this file. 17*43a90889SApple OSS Distributions * 18*43a90889SApple OSS Distributions * The Original Code and all software distributed under the License are 19*43a90889SApple OSS Distributions * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20*43a90889SApple OSS Distributions * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21*43a90889SApple OSS Distributions * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22*43a90889SApple OSS Distributions * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23*43a90889SApple OSS Distributions * Please see the License for the specific language governing rights and 24*43a90889SApple OSS Distributions * limitations under the License. 25*43a90889SApple OSS Distributions * 26*43a90889SApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27*43a90889SApple OSS Distributions */ 28*43a90889SApple OSS Distributions 29*43a90889SApple OSS Distributions #ifndef __NET_API_STATS__ 30*43a90889SApple OSS Distributions #define __NET_API_STATS__ 31*43a90889SApple OSS Distributions 32*43a90889SApple OSS Distributions #ifdef PRIVATE 33*43a90889SApple OSS Distributions #include <stdint.h> 34*43a90889SApple OSS Distributions 35*43a90889SApple OSS Distributions #define NAS_HAS_FLTR_OS_COUNTS 1 36*43a90889SApple OSS Distributions 37*43a90889SApple OSS Distributions /* 38*43a90889SApple OSS Distributions * net_api_stats counts the usage of the networking APIs 39*43a90889SApple OSS Distributions * 40*43a90889SApple OSS Distributions * Note: we are using signed 64 bit values to detect and prevent wrap around 41*43a90889SApple OSS Distributions */ 42*43a90889SApple OSS Distributions struct net_api_stats { 43*43a90889SApple OSS Distributions /* 44*43a90889SApple OSS Distributions * Interface Filters 45*43a90889SApple OSS Distributions */ 46*43a90889SApple OSS Distributions int64_t nas_iflt_attach_count; // Currently attached 47*43a90889SApple OSS Distributions int64_t nas_iflt_attach_os_count; 48*43a90889SApple OSS Distributions int64_t nas_iflt_attach_total; // Total number of attachments 49*43a90889SApple OSS Distributions int64_t nas_iflt_attach_os_total; 50*43a90889SApple OSS Distributions 51*43a90889SApple OSS Distributions /* 52*43a90889SApple OSS Distributions * IP Filters 53*43a90889SApple OSS Distributions */ 54*43a90889SApple OSS Distributions int64_t nas_ipf_add_count; // Currently attached 55*43a90889SApple OSS Distributions int64_t nas_ipf_add_os_count; 56*43a90889SApple OSS Distributions int64_t nas_ipf_add_total; // Total number of attachments 57*43a90889SApple OSS Distributions int64_t nas_ipf_add_os_total; 58*43a90889SApple OSS Distributions 59*43a90889SApple OSS Distributions /* 60*43a90889SApple OSS Distributions * Socket Filters 61*43a90889SApple OSS Distributions */ 62*43a90889SApple OSS Distributions int64_t nas_sfltr_register_count; // Currently attached 63*43a90889SApple OSS Distributions int64_t nas_sfltr_register_os_count; 64*43a90889SApple OSS Distributions int64_t nas_sfltr_register_total; // Total number of attachments 65*43a90889SApple OSS Distributions int64_t nas_sfltr_register_os_total; 66*43a90889SApple OSS Distributions 67*43a90889SApple OSS Distributions /* 68*43a90889SApple OSS Distributions * Sockets 69*43a90889SApple OSS Distributions */ 70*43a90889SApple OSS Distributions int64_t nas_socket_alloc_total; 71*43a90889SApple OSS Distributions int64_t nas_socket_in_kernel_total; 72*43a90889SApple OSS Distributions int64_t nas_socket_in_kernel_os_total; 73*43a90889SApple OSS Distributions int64_t nas_socket_necp_clientuuid_total; 74*43a90889SApple OSS Distributions 75*43a90889SApple OSS Distributions /* 76*43a90889SApple OSS Distributions * Sockets per protocol domains 77*43a90889SApple OSS Distributions */ 78*43a90889SApple OSS Distributions int64_t nas_socket_domain_local_total; 79*43a90889SApple OSS Distributions int64_t nas_socket_domain_route_total; 80*43a90889SApple OSS Distributions int64_t nas_socket_domain_inet_total; 81*43a90889SApple OSS Distributions int64_t nas_socket_domain_inet6_total; 82*43a90889SApple OSS Distributions int64_t nas_socket_domain_system_total; 83*43a90889SApple OSS Distributions int64_t nas_socket_domain_multipath_total; 84*43a90889SApple OSS Distributions int64_t nas_socket_domain_key_total; 85*43a90889SApple OSS Distributions int64_t nas_socket_domain_ndrv_total; 86*43a90889SApple OSS Distributions int64_t nas_socket_domain_other_total; 87*43a90889SApple OSS Distributions 88*43a90889SApple OSS Distributions /* 89*43a90889SApple OSS Distributions * Sockets per domain and type 90*43a90889SApple OSS Distributions */ 91*43a90889SApple OSS Distributions int64_t nas_socket_inet_stream_total; 92*43a90889SApple OSS Distributions int64_t nas_socket_inet_dgram_total; 93*43a90889SApple OSS Distributions int64_t nas_socket_inet_dgram_connected; 94*43a90889SApple OSS Distributions int64_t nas_socket_inet_dgram_dns; // port 53 95*43a90889SApple OSS Distributions int64_t nas_socket_inet_dgram_no_data; // typically for interface ioctl 96*43a90889SApple OSS Distributions 97*43a90889SApple OSS Distributions int64_t nas_socket_inet6_stream_total; 98*43a90889SApple OSS Distributions int64_t nas_socket_inet6_dgram_total; 99*43a90889SApple OSS Distributions int64_t nas_socket_inet6_dgram_connected; 100*43a90889SApple OSS Distributions int64_t nas_socket_inet6_dgram_dns; // port 53 101*43a90889SApple OSS Distributions int64_t nas_socket_inet6_dgram_no_data; // typically for interface ioctl 102*43a90889SApple OSS Distributions 103*43a90889SApple OSS Distributions /* 104*43a90889SApple OSS Distributions * Multicast join 105*43a90889SApple OSS Distributions */ 106*43a90889SApple OSS Distributions int64_t nas_socket_mcast_join_total; 107*43a90889SApple OSS Distributions int64_t nas_socket_mcast_join_os_total; 108*43a90889SApple OSS Distributions 109*43a90889SApple OSS Distributions /* 110*43a90889SApple OSS Distributions * IPv6 Extension Header Socket API 111*43a90889SApple OSS Distributions */ 112*43a90889SApple OSS Distributions int64_t nas_sock_inet6_stream_exthdr_in; 113*43a90889SApple OSS Distributions int64_t nas_sock_inet6_stream_exthdr_out; 114*43a90889SApple OSS Distributions int64_t nas_sock_inet6_dgram_exthdr_in; 115*43a90889SApple OSS Distributions int64_t nas_sock_inet6_dgram_exthdr_out; 116*43a90889SApple OSS Distributions 117*43a90889SApple OSS Distributions /* 118*43a90889SApple OSS Distributions * Nexus flows 119*43a90889SApple OSS Distributions */ 120*43a90889SApple OSS Distributions int64_t nas_nx_flow_inet_stream_total; 121*43a90889SApple OSS Distributions int64_t nas_nx_flow_inet_dgram_total; 122*43a90889SApple OSS Distributions 123*43a90889SApple OSS Distributions int64_t nas_nx_flow_inet6_stream_total; 124*43a90889SApple OSS Distributions int64_t nas_nx_flow_inet6_dgram_total; 125*43a90889SApple OSS Distributions 126*43a90889SApple OSS Distributions /* 127*43a90889SApple OSS Distributions * Interfaces 128*43a90889SApple OSS Distributions */ 129*43a90889SApple OSS Distributions int64_t nas_ifnet_alloc_count; 130*43a90889SApple OSS Distributions int64_t nas_ifnet_alloc_total; 131*43a90889SApple OSS Distributions int64_t nas_ifnet_alloc_os_count; 132*43a90889SApple OSS Distributions int64_t nas_ifnet_alloc_os_total; 133*43a90889SApple OSS Distributions 134*43a90889SApple OSS Distributions /* 135*43a90889SApple OSS Distributions * PF 136*43a90889SApple OSS Distributions */ 137*43a90889SApple OSS Distributions int64_t nas_pf_addrule_total; 138*43a90889SApple OSS Distributions int64_t nas_pf_addrule_os; 139*43a90889SApple OSS Distributions 140*43a90889SApple OSS Distributions /* 141*43a90889SApple OSS Distributions * vmnet API 142*43a90889SApple OSS Distributions */ 143*43a90889SApple OSS Distributions int64_t nas_vmnet_total; 144*43a90889SApple OSS Distributions }; 145*43a90889SApple OSS Distributions 146*43a90889SApple OSS Distributions #ifdef XNU_KERNEL_PRIVATE 147*43a90889SApple OSS Distributions extern struct net_api_stats net_api_stats; 148*43a90889SApple OSS Distributions 149*43a90889SApple OSS Distributions /* 150*43a90889SApple OSS Distributions * Increment up to the max value of int64_t 151*43a90889SApple OSS Distributions */ 152*43a90889SApple OSS Distributions #define INC_ATOMIC_INT64_LIM(counter) { \ 153*43a90889SApple OSS Distributions int64_t val; \ 154*43a90889SApple OSS Distributions do { \ 155*43a90889SApple OSS Distributions val = counter; \ 156*43a90889SApple OSS Distributions if (val >= INT64_MAX) { \ 157*43a90889SApple OSS Distributions break; \ 158*43a90889SApple OSS Distributions } \ 159*43a90889SApple OSS Distributions } while (!OSCompareAndSwap64(val, val + 1, &(counter))); \ 160*43a90889SApple OSS Distributions } 161*43a90889SApple OSS Distributions #endif /* XNU_KERNEL_PRIVATE */ 162*43a90889SApple OSS Distributions 163*43a90889SApple OSS Distributions #endif /* PRIVATE */ 164*43a90889SApple OSS Distributions 165*43a90889SApple OSS Distributions #endif /* __NET_API_STATS__ */ 166