// SPDX-License-Identifier: GPL-3.0-or-later
#include "plugin_proc.h"
#define PLUGIN_PROC_MODULE_NETDEV_NAME "/proc/net/dev"
#define CONFIG_SECTION_PLUGIN_PROC_NETDEV "plugin:" PLUGIN_PROC_CONFIG_NAME ":" PLUGIN_PROC_MODULE_NETDEV_NAME
#define STATE_LENGTH_MAX 32
// As defined in https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-class-net
const char *operstate_names[] = { "unknown", "notpresent", "down", "lowerlayerdown", "testing", "dormant", "up" };
static inline int get_operstate(char *operstate)
{
int i;
for (i = 0; i < (int) (sizeof(operstate_names) / sizeof(char *)); i++) {
if (!strcmp(operstate, operstate_names[i])) {
return i;
}
}
return 0;
}
// ----------------------------------------------------------------------------
// netdev list
static struct netdev {
char *name;
uint32_t hash;
size_t len;
// flags
int virtual;
int configured;
int enabled;
int updated;
int do_bandwidth;
int do_packets;
int do_errors;
int do_drops;
int do_fifo;
int do_compressed;
int do_events;
int do_speed;
int do_duplex;
int do_operstate;
int do_carrier;
int do_mtu;
const char *chart_type_net_bytes;