#include "common.h"
#include <sys/sysctl.h>
// NEEDED BY: do_bandwidth
#include <net/route.h>
// NEEDED BY do_tcp...
#include <sys/socketvar.h>
#include <netinet/tcp_var.h>
#include <netinet/tcp_fsm.h>
// NEEDED BY do_udp..., do_ip...
#include <netinet/ip_var.h>
// NEEDED BY do_udp...
#include <netinet/udp.h>
#include <netinet/udp_var.h>
// NEEDED BY do_icmp...
#include <netinet/ip.h>
#include <netinet/ip_icmp.h>
#include <netinet/icmp_var.h>
// NEEDED BY do_icmp6...
#include <netinet/icmp6.h>
// NEEDED BY do_uptime
#include <time.h>
// MacOS calculates load averages once every 5 seconds
#define MIN_LOADAVG_UPDATE_EVERY 5
int do_macos_sysctl(int update_every, usec_t dt) {
static int do_loadavg = -1, do_swap = -1, do_bandwidth = -1,
do_tcp_packets = -1, do_tcp_errors = -1, do_tcp_handshake = -1, do_ecn = -1,
do_tcpext_syscookies = -1, do_tcpext_ofo = -1, do_tcpext_connaborts = -1,
do_udp_packets = -1, do_udp_errors = -1, do_icmp_packets = -1, do_icmpmsg = -1,
do_ip_packets = -1, do_ip_fragsout = -1, do_ip_fragsin = -1, do_ip_errors = -1,
do_ip6_packets = -1, do_ip6_fragsout = -1, do_ip6_fragsin = -1, do_ip6_errors = -1,
do_icmp6 = -1, do_icmp6_redir = -1, do_icmp6_errors = -1, do_icmp6_echos = -1,
do_icmp6_router = -1, do_icmp6_neighbor = -1, do_icmp6_types = -1, do_uptime = -1;
if (unlikely(do_loadavg == -1)) {
do_loadavg = config_get_boolean("plugin:macos:sysctl", "enable load average", 1);
do_swap = config_get_boolean("plugin:macos:sysctl", "system swap", 1);
do_bandwidth = config_get_boolean("plugin:macos:sysctl", "bandwidth", 1);
do_tcp_packets = config_get_boolean("plugin:macos:sysctl", "ipv4 TCP packets", 1);
do_tcp_errors = config_get_boolean("plugin:macos:sysctl", "ipv4 TCP errors", 1);
do_tcp_handshake = config_get_boolean("plugin:macos:sysctl", "ipv4 TCP handshake issues", 1);
do_ecn = config_get_boolean_ondemand("plugin:macos:sysctl", "ECN packets", CONFIG_BOOLEAN_AUTO);
do_tcpext_syscookies = config_get_boolean_ondemand("plugin:macos:sysctl", "TCP SYN cookies", CONFIG_BOOLEAN_AUTO);
do_tcpext_ofo = config_get_boolean_ondemand("plugin:macos:sysctl", "TCP out-of-order queue", CONFIG_BOOLEAN_AUTO);
do_tcpext_connaborts = config_get_boolean_ondemand("plugin:macos:sysctl", "TCP connection aborts", CONFIG_BOOLEAN_AUTO);
do_udp_packets = config_get_boolean("plugin:macos:sysctl", "ipv4 UDP packets", 1);
do_udp_errors = config_get_boolean("plugin:macos:sysctl", "ipv4 UDP errors", 1);
do_icmp_packets = config_get_boolean("plugin:macos:sysctl", "ipv4 ICMP packets", 1);
do_icmpmsg = config_get_boolean("plugin:macos:sysctl", "ipv4 ICMP messages", 1);
do_ip_packets = config_get_boolean("plugin:macos:sysctl", "ipv4 packets", 1);
do_ip_fragsout = config_get_boolean("plugin:macos:sysctl", "ipv4 fragments sent"