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