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