/**
- * There are several data streams provided by Madwifi plugin, some are
+ * There are several data streams provided by Madwifi plugin, some are
* connected to network interface, some are connected to each node
* associated to that interface. Nodes represents other sides in
* wireless communication, for example on network interface in AP mode,
* node_stat Node statistic counters
*
* Both statistic counters have type instances for each counter returned
- * by Madwifi. See madwifi.h for content of ieee80211_nodestats,
+ * by Madwifi. See madwifi.h for content of ieee80211_nodestats,
* ieee80211_stats and ath_stats structures. Type instances use the same
* name as fields in these structures (like ns_rx_dup). Some fields are
* not reported, because they are not counters (like ns_tx_deauth_code
* or ast_tx_rssi). Fields ns_rx_bytes and ns_tx_bytes are reported as
* node_octets data stream instead of type instance of node_stat.
* Statistics are not logged when they are zero.
- *
+ *
* There are two sets of these counters - the first 'WatchList' is a
* set of counters that are individually logged. The second 'MiscList'
* is a set of counters that are summed together and the sum is logged.
- * By default, the most important statistics are in the WatchList and
+ * By default, the most important statistics are in the WatchList and
* many error statistics are in MiscList. There are also many statistics
* that are not in any of these sets, so they are not monitored by default.
* It is possible to alter these lists using configuration options:
#include <dirent.h>
#include <sys/ioctl.h>
-#include <sys/socket.h>
#if !KERNEL_LINUX
# error "No applicable input method."
static inline int item_watched(int i)
{
assert (i >= 0);
- assert (i < ((STATIC_ARRAY_SIZE (watch_items) + 1) * 32));
+ assert (((size_t) i) < ((STATIC_ARRAY_SIZE (watch_items) + 1) * 32));
return watch_items[i / 32] & FLAG (i);
}
static inline int item_summed(int i)
{
assert (i >= 0);
- assert (i < ((STATIC_ARRAY_SIZE (misc_items) + 1) * 32));
+ assert (((size_t) i) < ((STATIC_ARRAY_SIZE (misc_items) + 1) * 32));
return misc_items[i / 32] & FLAG (i);
}
static int madwifi_real_init (void)
{
- int max = STATIC_ARRAY_SIZE (specs);
- int i;
+ size_t max = STATIC_ARRAY_SIZE (specs);
+ size_t i;
for (i = 0; i < STATIC_ARRAY_SIZE (bounds); i++)
bounds[i] = 0;
plugin_dispatch_values (&vl);
}
-static void submit_counter (const char *dev, const char *type, const char *ti1,
- const char *ti2, counter_t val)
+static void submit_derive (const char *dev, const char *type, const char *ti1,
+ const char *ti2, derive_t val)
{
value_t item;
- item.counter = val;
+ item.derive = val;
submit (dev, type, ti1, ti2, &item, 1);
}
-static void submit_counter2 (const char *dev, const char *type, const char *ti1,
- const char *ti2, counter_t val1, counter_t val2)
+static void submit_derive2 (const char *dev, const char *type, const char *ti1,
+ const char *ti2, derive_t val1, derive_t val2)
{
value_t items[2];
- items[0].counter = val1;
- items[1].counter = val2;
+ items[0].derive = val1;
+ items[1].derive = val2;
submit (dev, type, ti1, ti2, items, 2);
}
if (vals[i] == 0)
continue;
- ssnprintf (ti2, sizeof (ti2), "antenna%i", i);
- submit_counter (dev, "ath_stat", name, ti2,
- (counter_t) vals[i]);
+ ssnprintf (ti2, sizeof (ti2), "%i", i);
+ submit_derive (dev, "ath_stat", name, ti2,
+ (derive_t) vals[i]);
}
}
int i;
assert (which >= 1);
- assert (which < STATIC_ARRAY_SIZE (bounds));
+ assert (((size_t) which) < STATIC_ARRAY_SIZE (bounds));
for (i = bounds[which - 1]; i < bounds[which]; i++)
{
uint32_t val = *(uint32_t *)(((char *) ptr) + specs[i].offset) ;
if (item_watched (i) && (val != 0))
- submit_counter (dev, type_name, specs[i].name, mac, val);
+ submit_derive (dev, type_name, specs[i].name, mac, val);
if (item_summed (i))
misc += val;
}
-
+
if (misc != 0)
- submit_counter (dev, type_name, misc_name, mac, misc);
+ submit_derive (dev, type_name, misc_name, mac, misc);
}
-static void
+static int
process_athstats (int sk, const char *dev)
{
struct ifreq ifr;
struct ath_stats stats;
+ int status;
sstrncpy (ifr.ifr_name, dev, sizeof (ifr.ifr_name));
ifr.ifr_data = (void *) &stats;
- if (ioctl (sk, SIOCGATHSTATS, &ifr) < 0)
- return;
+ status = ioctl (sk, SIOCGATHSTATS, &ifr);
+ if (status < 0)
+ {
+ /* Silent, because not all interfaces support all ioctls. */
+ DEBUG ("madwifi plugin: Sending IO-control "
+ "SIOCGATHSTATS to device %s "
+ "failed with status %i.",
+ dev, status);
+ return (status);
+ }
/* These stats are handled as a special case, because they are
eight values each */
/* All other ath statistics */
process_stat_struct (ATH_STAT, &stats, dev, NULL, "ath_stat", "ast_misc");
+ return (0);
}
-static void
+static int
process_80211stats (int sk, const char *dev)
{
struct ifreq ifr;
struct ieee80211_stats stats;
+ int status;
+
sstrncpy (ifr.ifr_name, dev, sizeof (ifr.ifr_name));
ifr.ifr_data = (void *) &stats;
- if (ioctl(sk, SIOCG80211STATS, &ifr) < 0)
- return;
+ status = ioctl(sk, SIOCG80211STATS, &ifr);
+ if (status < 0)
+ {
+ /* Silent, because not all interfaces support all ioctls. */
+ DEBUG ("madwifi plugin: Sending IO-control "
+ "SIOCG80211STATS to device %s "
+ "failed with status %i.",
+ dev, status);
+ return (status);
+ }
process_stat_struct (IFA_STAT, &stats, dev, NULL, "ath_stat", "is_misc");
+ return (0);
}
-static void
+static int
process_station (int sk, const char *dev, struct ieee80211req_sta_info *si)
{
struct iwreq iwr;
static char mac[DATA_MAX_NAME_LEN];
struct ieee80211req_sta_stats stats;
const struct ieee80211_nodestats *ns = &stats.is_stats;
+ int status;
macaddr_to_str (mac, sizeof (mac), si->isi_macaddr);
iwr.u.data.pointer = (void *) &stats;
iwr.u.data.length = sizeof (stats);
memcpy(stats.is_u.macaddr, si->isi_macaddr, IEEE80211_ADDR_LEN);
- if (ioctl(sk, IEEE80211_IOCTL_STA_STATS, &iwr) < 0)
- return;
+ status = ioctl(sk, IEEE80211_IOCTL_STA_STATS, &iwr);
+ if (status < 0)
+ {
+ /* Silent, because not all interfaces support all ioctls. */
+ DEBUG ("madwifi plugin: Sending IO-control "
+ "IEEE80211_IOCTL_STA_STATS to device %s "
+ "failed with status %i.",
+ dev, status);
+ return (status);
+ }
/* These two stats are handled as a special case as they are
a pair of 64bit values */
if (item_watched (STAT_NODE_OCTETS))
- submit_counter2 (dev, "node_octets", mac, NULL,
+ submit_derive2 (dev, "node_octets", mac, NULL,
ns->ns_rx_bytes, ns->ns_tx_bytes);
/* This stat is handled as a special case, because it is stored
as uin64_t, but we will ignore upper half */
if (item_watched (STAT_NS_RX_BEACONS))
- submit_counter (dev, "node_stat", "ns_rx_beacons", mac,
+ submit_derive (dev, "node_stat", "ns_rx_beacons", mac,
(ns->ns_rx_beacons & 0xFFFFFFFF));
/* All other node statistics */
process_stat_struct (NOD_STAT, ns, dev, mac, "node_stat", "ns_misc");
+ return (0);
}
-static void
+static int
process_stations (int sk, const char *dev)
{
uint8_t buf[24*1024];
struct iwreq iwr;
uint8_t *cp;
- int len, nodes;
+ int nodes;
+ size_t len;
int status;
memset (&iwr, 0, sizeof (iwr));
status = ioctl (sk, IEEE80211_IOCTL_STA_INFO, &iwr);
if (status < 0)
{
- ERROR ("madwifi plugin: Sending IO-control "
+ /* Silent, because not all interfaces support all ioctls. */
+ DEBUG ("madwifi plugin: Sending IO-control "
"IEEE80211_IOCTL_STA_INFO to device %s "
"failed with status %i.",
dev, status);
- return;
+ return (status);
}
len = iwr.u.data.length;
if (item_watched (STAT_ATH_NODES))
submit_gauge (dev, "ath_nodes", NULL, NULL, nodes);
+ return (0);
}
-static void
+static int
process_device (int sk, const char *dev)
{
- process_athstats (sk, dev);
- process_80211stats (sk, dev);
- process_stations (sk, dev);
+ int num_success = 0;
+ int status;
+
+ status = process_athstats (sk, dev);
+ if (status == 0)
+ num_success++;
+
+ status = process_80211stats (sk, dev);
+ if (status == 0)
+ num_success++;
+
+ status = process_stations (sk, dev);
+ if (status == 0)
+ num_success++;
+
+ return ((num_success == 0) ? -1 : 0);
}
static int
if (dev[0] == '.')
return 0;
-
+
ssnprintf (buf, sizeof (buf), "/sys/class/net/%s/device/driver", dev);
- buf[sizeof (buf) - 1] = 0;
+ buf[sizeof (buf) - 1] = '\0';
- memset (buf2, 0, sizeof (buf2));
i = readlink (buf, buf2, sizeof (buf2) - 1);
if (i < 0)
return 0;
+ buf2[i] = '\0';
+
if (strstr (buf2, "/drivers/ath_") == NULL)
return 0;
return 1;
sysfs_iterate(int sk)
{
struct dirent *de;
+ DIR *nets;
+ int status;
+ int num_success;
+ int num_fail;
- DIR *nets = opendir ("/sys/class/net/");
+ nets = opendir ("/sys/class/net/");
if (nets == NULL)
{
WARNING ("madwifi plugin: opening /sys/class/net failed");
return (-1);
}
+ num_success = 0;
+ num_fail = 0;
while ((de = readdir (nets)))
- if (check_devname (de->d_name) &&
- (ignorelist_match (ignorelist, de->d_name) == 0))
- process_device (sk, de->d_name);
+ {
+ if (check_devname (de->d_name) == 0)
+ continue;
+
+ if (ignorelist_match (ignorelist, de->d_name) != 0)
+ continue;
+
+ status = process_device (sk, de->d_name);
+ if (status != 0)
+ {
+ ERROR ("madwifi plugin: Processing interface "
+ "%s failed.", de->d_name);
+ num_fail++;
+ }
+ else
+ {
+ num_success++;
+ }
+ } /* while (readdir) */
closedir(nets);
- return 0;
+ if ((num_success == 0) && (num_fail != 0))
+ return (-1);
+ return (0);
}
static int
char buffer[1024];
char *device, *dummy;
FILE *fh;
-
+ int status;
+ int num_success;
+ int num_fail;
+
if ((fh = fopen ("/proc/net/dev", "r")) == NULL)
{
WARNING ("madwifi plugin: opening /proc/net/dev failed");
return (-1);
}
+ num_success = 0;
+ num_fail = 0;
while (fgets (buffer, sizeof (buffer), fh) != NULL)
{
dummy = strchr(buffer, ':');
if (device[0] == 0)
continue;
- if (ignorelist_match (ignorelist, device) == 0)
- process_device (sk, device);
- }
+ if (ignorelist_match (ignorelist, device) != 0)
+ continue;
+
+ status = process_device (sk, device);
+ if (status != 0)
+ {
+ ERROR ("madwifi plugin: Processing interface "
+ "%s failed.", device);
+ num_fail++;
+ }
+ else
+ {
+ num_success++;
+ }
+ } /* while (fgets) */
fclose(fh);
+
+ if ((num_success == 0) && (num_fail != 0))
+ return (-1);
return 0;
}
/* procfs iteration is not safe because it does not check whether given
interface is madwifi interface and there are private ioctls used, which
- may do something completely different on non-madwifi devices.
+ may do something completely different on non-madwifi devices.
Therefore, it is not used unless explicitly enabled (and should be used
together with ignorelist). */