move a few unmaintained packages from trunk to /packages
git-svn-id: svn://svn.openwrt.org/openwrt/packages@33634 3c298f89-4303-0410-b956-a3cf2f4a3e73
This commit is contained in:
12
net/wprobe/src/Makefile.inc
Normal file
12
net/wprobe/src/Makefile.inc
Normal file
@ -0,0 +1,12 @@
|
||||
HOST_OS=$(shell uname)
|
||||
|
||||
CC=gcc
|
||||
AR=ar
|
||||
RANLIB=ranlib
|
||||
|
||||
WFLAGS = -Wall -Werror -Wno-format
|
||||
CFLAGS?=-O2
|
||||
CPPFLAGS=
|
||||
LDFLAGS=
|
||||
LIBS=
|
||||
|
5
net/wprobe/src/exporter/Makefile
Normal file
5
net/wprobe/src/exporter/Makefile
Normal file
@ -0,0 +1,5 @@
|
||||
include ../Makefile.inc
|
||||
CPPFLAGS += -I../kernel -I../user
|
||||
|
||||
wprobe-export: wprobe-export.c
|
||||
$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(LIBS)
|
304
net/wprobe/src/exporter/wprobe-export.c
Normal file
304
net/wprobe/src/exporter/wprobe-export.c
Normal file
@ -0,0 +1,304 @@
|
||||
/*
|
||||
** exporter.c - example exporter
|
||||
**
|
||||
** Copyright Fraunhofer FOKUS
|
||||
**
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <ipfix_def.h>
|
||||
#include <ipfix_def_fokus.h>
|
||||
#include <ipfix_fields_fokus.h>
|
||||
|
||||
#include <ipfix.h>
|
||||
#include <mlog.h>
|
||||
#include <wprobe.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
static ipfix_datarecord_t g_data = { NULL, NULL, 0 };
|
||||
static int do_close = 0;
|
||||
|
||||
struct wprobe_mapping {
|
||||
int id;
|
||||
bool counter;
|
||||
const char *wprobe_id;
|
||||
struct wprobe_value *val;
|
||||
};
|
||||
|
||||
#ifndef ARRAY_SIZE
|
||||
#define ARRAY_SIZE(_array) (sizeof(_array) / sizeof((_array)[0]))
|
||||
#endif
|
||||
|
||||
#define WMAP(_id, _name, ...) \
|
||||
{ \
|
||||
.counter = false, \
|
||||
.id = IPFIX_FT_WPROBE_##_id##_N, \
|
||||
.wprobe_id = _name \
|
||||
, ## __VA_ARGS__ \
|
||||
}
|
||||
|
||||
#define WMAP_COUNTER(_id, _name, ...) \
|
||||
{ \
|
||||
.counter = true, \
|
||||
.id = IPFIX_FT_WPROBE_##_id, \
|
||||
.wprobe_id = _name \
|
||||
, ## __VA_ARGS__ \
|
||||
}
|
||||
|
||||
|
||||
#define WPROBE_OFFSET 2
|
||||
|
||||
static struct wprobe_mapping map_globals[] = {
|
||||
WMAP(NOISE, "noise"),
|
||||
WMAP(PHY_BUSY, "phy_busy"),
|
||||
WMAP(PHY_RX, "phy_rx"),
|
||||
WMAP(PHY_TX, "phy_tx"),
|
||||
WMAP_COUNTER(FRAMES, "frames"),
|
||||
WMAP_COUNTER(PROBEREQ, "probereq"),
|
||||
};
|
||||
|
||||
static struct wprobe_mapping map_perlink[] = {
|
||||
WMAP(IEEE_TX_RATE, "tx_rate"),
|
||||
WMAP(IEEE_RX_RATE, "rx_rate"),
|
||||
WMAP(RSSI, "rssi"),
|
||||
WMAP(SIGNAL, "signal"),
|
||||
WMAP(RETRANSMIT_200, "retransmit_200"),
|
||||
WMAP(RETRANSMIT_400, "retransmit_400"),
|
||||
WMAP(RETRANSMIT_800, "retransmit_800"),
|
||||
WMAP(RETRANSMIT_1600, "retransmit_1600"),
|
||||
};
|
||||
|
||||
static unsigned char link_local[6];
|
||||
static char link_default[6];
|
||||
static int nfields = 0;
|
||||
|
||||
#define FOKUS_USERID 12325
|
||||
|
||||
static void
|
||||
match_template(struct wprobe_mapping *map, int n, struct list_head *list)
|
||||
{
|
||||
struct wprobe_attribute *attr;
|
||||
int i, j, last = -1;
|
||||
|
||||
list_for_each_entry(attr, list, list) {
|
||||
for (i = 0; i < n; i++) {
|
||||
j = (last + 1 + i) % n;
|
||||
if (!strcmp(attr->name, map[j].wprobe_id))
|
||||
goto found;
|
||||
}
|
||||
continue;
|
||||
found:
|
||||
last = j;
|
||||
map[j].val = &attr->val;
|
||||
memset(&attr->val, 0, sizeof(attr->val));
|
||||
nfields++;
|
||||
}
|
||||
}
|
||||
|
||||
/* name: export_ipfix_get_template()
|
||||
*/
|
||||
static ipfix_template_t *
|
||||
prepare_template(ipfix_t *handle)
|
||||
{
|
||||
ipfix_template_t *t = NULL;
|
||||
int size = 3 * nfields + WPROBE_OFFSET;
|
||||
int i;
|
||||
|
||||
if (ipfix_new_data_template( handle, &t, size) < 0) {
|
||||
mlogf( 0, "ipfix_new_template() failed: %s\n", strerror(errno) );
|
||||
exit(1);
|
||||
}
|
||||
|
||||
ipfix_add_field(handle, t, 0, IPFIX_FT_SOURCEMACADDRESS, 6);
|
||||
ipfix_add_field(handle, t, 0, IPFIX_FT_DESTINATIONMACADDRESS, 6);
|
||||
|
||||
g_data.lens = calloc(size, sizeof(g_data.lens[0]));
|
||||
g_data.lens[0] = 6;
|
||||
g_data.lens[1] = 6;
|
||||
for (i = WPROBE_OFFSET; i < size; i++)
|
||||
g_data.lens[i] = 4;
|
||||
|
||||
g_data.addrs = calloc(size, sizeof(g_data.addrs[0]));
|
||||
g_data.addrs[0] = link_local;
|
||||
g_data.maxfields = WPROBE_OFFSET;
|
||||
return t;
|
||||
}
|
||||
|
||||
static void
|
||||
add_template_fields(ipfix_t *handle, ipfix_template_t *t, struct wprobe_mapping *map, int n)
|
||||
{
|
||||
int f = g_data.maxfields;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
if (!map[i].val)
|
||||
continue;
|
||||
|
||||
if (map[i].counter)
|
||||
g_data.addrs[f++] = &map[i].val->U32;
|
||||
else
|
||||
g_data.addrs[f++] = &map[i].val->n;
|
||||
|
||||
if (ipfix_add_field( handle, t, FOKUS_USERID, map[i].id + 0, 4) < 0)
|
||||
exit(1);
|
||||
|
||||
if (map[i].counter)
|
||||
continue;
|
||||
|
||||
g_data.lens[f] = 8;
|
||||
g_data.addrs[f++] = &map[i].val->s;
|
||||
|
||||
g_data.lens[f] = 8;
|
||||
g_data.addrs[f++] = &map[i].val->ss;
|
||||
if (ipfix_add_field( handle, t, FOKUS_USERID, map[i].id + 1, 8) < 0)
|
||||
exit(1);
|
||||
if (ipfix_add_field( handle, t, FOKUS_USERID, map[i].id + 2, 8) < 0)
|
||||
exit(1);
|
||||
}
|
||||
g_data.maxfields = f;
|
||||
}
|
||||
|
||||
static void
|
||||
wprobe_dump_data(ipfix_t *ipfixh, ipfix_template_t *ipfixt, struct wprobe_iface *dev)
|
||||
{
|
||||
struct wprobe_link *link;
|
||||
|
||||
wprobe_update_links(dev);
|
||||
wprobe_request_data(dev, NULL);
|
||||
if (list_empty(&dev->links)) {
|
||||
g_data.addrs[1] = link_default;
|
||||
ipfix_export_array(ipfixh, ipfixt, g_data.maxfields, g_data.addrs, g_data.lens);
|
||||
ipfix_export_flush(ipfixh);
|
||||
}
|
||||
list_for_each_entry(link, &dev->links, list) {
|
||||
g_data.addrs[1] = link->addr;
|
||||
wprobe_request_data(dev, link->addr);
|
||||
ipfix_export_array(ipfixh, ipfixt, g_data.maxfields, g_data.addrs, g_data.lens);
|
||||
ipfix_export_flush(ipfixh);
|
||||
}
|
||||
}
|
||||
|
||||
int main ( int argc, char **argv )
|
||||
{
|
||||
struct wprobe_iface *dev = NULL;
|
||||
ipfix_template_t *ipfixt = NULL;
|
||||
ipfix_t *ipfixh = NULL;
|
||||
int protocol = IPFIX_PROTO_TCP;
|
||||
char *chost = NULL;
|
||||
char *ifname = NULL;
|
||||
int sourceid = 12345;
|
||||
int port = IPFIX_PORTNO;
|
||||
int verbose_level = 0;
|
||||
int opt, i = 10;
|
||||
char *err = NULL;
|
||||
|
||||
while ((opt = getopt(argc, argv, "hi:c:p:vstu")) != EOF) {
|
||||
switch (opt) {
|
||||
case 'p':
|
||||
if ((port=atoi(optarg)) <0) {
|
||||
fprintf( stderr, "Invalid -p argument!\n" );
|
||||
exit(1);
|
||||
}
|
||||
break;
|
||||
case 'i':
|
||||
ifname = optarg;
|
||||
break;
|
||||
case 'c':
|
||||
chost = optarg;
|
||||
break;
|
||||
|
||||
case 's':
|
||||
protocol = IPFIX_PROTO_SCTP;
|
||||
break;
|
||||
|
||||
case 't':
|
||||
protocol = IPFIX_PROTO_TCP;
|
||||
break;
|
||||
|
||||
case 'u':
|
||||
protocol = IPFIX_PROTO_UDP;
|
||||
break;
|
||||
|
||||
case 'v':
|
||||
verbose_level ++;
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
default:
|
||||
fprintf(stderr, "usage: %s [-hstuv] -i <interface> -c <collector> [-p portno]\n"
|
||||
" -h this help\n"
|
||||
" -i <interface> wprobe interface\n"
|
||||
" -c <collector> collector address\n"
|
||||
" -p <portno> collector port number (default=%d)\n"
|
||||
" -s send data via SCTP\n"
|
||||
" -t send data via TCP (default)\n"
|
||||
" -u send data via UDP\n"
|
||||
" -v increase verbose level\n\n",
|
||||
argv[0], IPFIX_PORTNO );
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
if (!ifname) {
|
||||
fprintf(stderr, "No interface specified\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!chost) {
|
||||
fprintf(stderr, "No collector specified\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
dev = wprobe_get_auto(ifname, &err);
|
||||
if (!dev || (list_empty(&dev->global_attr) && list_empty(&dev->link_attr))) {
|
||||
fprintf(stderr, "Cannot connect to wprobe on interface '%s': %s\n", ifname, (err ? err : "Unknown error"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
match_template(map_globals, ARRAY_SIZE(map_globals), &dev->global_attr);
|
||||
match_template(map_perlink, ARRAY_SIZE(map_perlink), &dev->link_attr);
|
||||
if (nfields == 0) {
|
||||
fprintf(stderr, "No usable attributes found\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
mlog_set_vlevel( verbose_level );
|
||||
if (ipfix_init() < 0) {
|
||||
fprintf( stderr, "cannot init ipfix module: %s\n", strerror(errno) );
|
||||
exit(1);
|
||||
}
|
||||
|
||||
ipfix_add_vendor_information_elements(ipfix_ft_fokus);
|
||||
if (ipfix_open(&ipfixh, sourceid, IPFIX_VERSION) < 0) {
|
||||
fprintf( stderr, "ipfix_open() failed: %s\n", strerror(errno) );
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (ipfix_add_collector( ipfixh, chost, port, protocol ) < 0) {
|
||||
fprintf( stderr, "ipfix_add_collector(%s,%d) failed: %s\n",
|
||||
chost, port, strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
fprintf(stderr, "Local link address: %02x:%02x:%02x:%02x:%02x:%02x\n",
|
||||
link_local[0], link_local[1], link_local[2],
|
||||
link_local[3], link_local[4], link_local[5]);
|
||||
|
||||
ipfixt = prepare_template(ipfixh);
|
||||
add_template_fields(ipfixh, ipfixt, map_globals, ARRAY_SIZE(map_globals));
|
||||
add_template_fields(ipfixh, ipfixt, map_perlink, ARRAY_SIZE(map_perlink));
|
||||
|
||||
while (!do_close) {
|
||||
sleep(1);
|
||||
wprobe_dump_data(ipfixh, ipfixt, dev);
|
||||
}
|
||||
|
||||
ipfix_delete_template( ipfixh, ipfixt );
|
||||
ipfix_close( ipfixh );
|
||||
ipfix_cleanup();
|
||||
exit(0);
|
||||
}
|
34
net/wprobe/src/exporter/wprobe-export.h
Normal file
34
net/wprobe/src/exporter/wprobe-export.h
Normal file
@ -0,0 +1,34 @@
|
||||
#include <inttypes.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
/**
|
||||
* struct wprobe_value: data structure for attribute values
|
||||
* see kernel api netlink attributes for more information
|
||||
*/
|
||||
struct wprobe_value {
|
||||
/* attribute value */
|
||||
union data {
|
||||
const char *STRING;
|
||||
uint8_t U8;
|
||||
uint16_t U16;
|
||||
uint32_t U32;
|
||||
uint64_t U64;
|
||||
int8_t S8;
|
||||
int16_t S16;
|
||||
int32_t S32;
|
||||
int64_t S64;
|
||||
} data;
|
||||
/* statistics */
|
||||
int64_t s, ss;
|
||||
double avg, stdev;
|
||||
unsigned int n;
|
||||
void *usedata; /* Pointer to used data.something */
|
||||
};
|
||||
|
||||
struct exporter_data {
|
||||
int id; /* ipfix id */
|
||||
int userid; /* focus or global */
|
||||
int size; /* size in byte*/
|
||||
struct wprobe_value val;
|
||||
};
|
1
net/wprobe/src/filter/README.txt
Normal file
1
net/wprobe/src/filter/README.txt
Normal file
@ -0,0 +1 @@
|
||||
To compile pfc you need at least libpcap version 1.0, as it requires proper radiotap header support
|
63
net/wprobe/src/filter/gen_filter.pl
Executable file
63
net/wprobe/src/filter/gen_filter.pl
Executable file
@ -0,0 +1,63 @@
|
||||
#!/usr/bin/perl
|
||||
use strict;
|
||||
|
||||
# helpers for custom packet format
|
||||
# bytes 0-7 are used by a dummy radiotap header
|
||||
my $WLAN_LEN = "radio[8:2]";
|
||||
my $SNR = "radio[10:1]";
|
||||
my $DEFAULT = undef;
|
||||
|
||||
my $MAGIC = "WPFF";
|
||||
my $VERSION = 1; # filter binary format version
|
||||
my $HDRLEN = 3; # assumed storage space for custom fields
|
||||
|
||||
my $output = "filter.bin";
|
||||
my $config = {
|
||||
"packetsize" => [
|
||||
[ "small", "$WLAN_LEN < 250" ],
|
||||
[ "medium", "$WLAN_LEN < 800" ],
|
||||
[ "big", $DEFAULT ],
|
||||
],
|
||||
"snr" => [
|
||||
[ "low", "$SNR < 10" ],
|
||||
[ "medium", "$SNR < 20" ],
|
||||
[ "high", $DEFAULT ],
|
||||
],
|
||||
"type" => [
|
||||
[ "beacon", "type mgt subtype beacon" ],
|
||||
[ "data", "type data subtype data" ],
|
||||
[ "qosdata", "type data subtype qos-data" ],
|
||||
[ "other", "$DEFAULT" ]
|
||||
]
|
||||
};
|
||||
|
||||
sub escape_q($) {
|
||||
my $str = shift;
|
||||
$str =~ s/'/'\\''/g;
|
||||
return $str;
|
||||
}
|
||||
|
||||
my $GROUPS = scalar(keys %$config);
|
||||
open OUTPUT, ">$output" or die "Cannot open output file: $!\n";
|
||||
print OUTPUT pack("a4CCn", $MAGIC, $VERSION, $HDRLEN, $GROUPS);
|
||||
|
||||
foreach my $groupname (keys %$config) {
|
||||
my $default = 0;
|
||||
my $group = $config->{$groupname};
|
||||
print OUTPUT pack("a32N", $groupname, scalar(@$group));
|
||||
foreach my $filter (@$group) {
|
||||
if (!$filter->[1]) {
|
||||
$default > 0 and print "Cannot add more than one default filter per group: $groupname -> ".$filter->[0]."\n";
|
||||
print OUTPUT pack("a32N", $filter->[0], 0);
|
||||
$default++;
|
||||
} else {
|
||||
open FILTER, "./pfc '".escape_q($filter->[0])."' '".escape_q($filter->[1])."' |"
|
||||
or die "Failed to run filter command for '".$filter->[0]."': $!\n";
|
||||
while (<FILTER>) {
|
||||
print OUTPUT $_;
|
||||
}
|
||||
close FILTER;
|
||||
$? and die "Filter '".$filter->[0]."' did not compile.\n";
|
||||
}
|
||||
}
|
||||
}
|
58
net/wprobe/src/filter/pfc.c
Normal file
58
net/wprobe/src/filter/pfc.c
Normal file
@ -0,0 +1,58 @@
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <pcap.h>
|
||||
#include <pcap-bpf.h>
|
||||
|
||||
struct wprobe_filter_hdr {
|
||||
char name[32];
|
||||
uint32_t len;
|
||||
} hdr;
|
||||
|
||||
int main (int argc, char ** argv)
|
||||
{
|
||||
struct bpf_program filter;
|
||||
pcap_t *pc;
|
||||
int i;
|
||||
|
||||
if (argc != 3)
|
||||
{
|
||||
fprintf(stderr, "Usage: %s <name> <expression>\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
pc = pcap_open_dead(DLT_IEEE802_11_RADIO, 256);
|
||||
if (pcap_compile(pc, &filter, argv[2], 1, 0) != 0)
|
||||
{
|
||||
pcap_perror(pc, argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* fix up for linux */
|
||||
for (i = 0; i < filter.bf_len; i++) {
|
||||
struct bpf_insn *bi = &filter.bf_insns[i];
|
||||
switch(BPF_CLASS(bi->code)) {
|
||||
case BPF_RET:
|
||||
if (BPF_MODE(bi->code) == BPF_K) {
|
||||
if (bi->k != 0)
|
||||
bi->k = 65535;
|
||||
}
|
||||
break;
|
||||
}
|
||||
bi->code = ntohs(bi->code);
|
||||
bi->k = ntohl(bi->k);
|
||||
}
|
||||
|
||||
memset(&hdr, 0, sizeof(hdr));
|
||||
strncpy(hdr.name, argv[1], sizeof(hdr.name));
|
||||
hdr.len = htonl(filter.bf_len);
|
||||
fwrite(&hdr, sizeof(hdr), 1, stdout);
|
||||
fwrite(filter.bf_insns, 8, filter.bf_len, stdout);
|
||||
fflush(stdout);
|
||||
|
||||
return 0;
|
||||
}
|
5
net/wprobe/src/kernel/Makefile
Normal file
5
net/wprobe/src/kernel/Makefile
Normal file
@ -0,0 +1,5 @@
|
||||
EXTRA_CFLAGS += -I.
|
||||
|
||||
obj-m := wprobe.o wprobe-dummy.o
|
||||
|
||||
wprobe-objs := wprobe-core.o
|
397
net/wprobe/src/kernel/linux/wprobe.h
Normal file
397
net/wprobe/src/kernel/linux/wprobe.h
Normal file
@ -0,0 +1,397 @@
|
||||
/*
|
||||
* wprobe.h: API for the wireless probe interface
|
||||
* Copyright (C) 2008-2009 Felix Fietkau <nbd@openwrt.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef __WPROBE_H
|
||||
#define __WPROBE_H
|
||||
|
||||
#ifdef __KERNEL__
|
||||
#include <linux/types.h>
|
||||
#include <linux/if_ether.h>
|
||||
#include <linux/spinlock.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/list.h>
|
||||
#include <linux/timer.h>
|
||||
#include <linux/filter.h>
|
||||
#include <net/genetlink.h>
|
||||
#endif
|
||||
|
||||
/**
|
||||
* enum wprobe_attr: netlink attribute list
|
||||
*
|
||||
* @WPROBE_ATTR_UNSPEC: unused
|
||||
*
|
||||
* @WPROBE_ATTR_INTERFACE: interface name to process query on (NLA_STRING)
|
||||
* @WPROBE_ATTR_MAC: mac address (used for wireless links) (NLA_STRING)
|
||||
* @WPROBE_ATTR_FLAGS: interface/link/attribute flags (see enum wprobe_flags) (NLA_U32)a
|
||||
* @WPROBE_ATTR_DURATION: sampling duration (in milliseconds) (NLA_MSECS)
|
||||
*
|
||||
* @WPROBE_ATTR_ID: attribute id (NLA_U32)
|
||||
* @WPROBE_ATTR_NAME: attribute name (NLA_STRING)
|
||||
* @WPROBE_ATTR_TYPE: attribute type (NLA_U8)
|
||||
*
|
||||
* attribute values:
|
||||
*
|
||||
* @WPROBE_VAL_STRING: string value (NLA_STRING)
|
||||
* @WPROBE_VAL_S8: signed 8-bit integer (NLA_U8)
|
||||
* @WPROBE_VAL_S16: signed 16-bit integer (NLA_U16)
|
||||
* @WPROBE_VAL_S32: signed 32-bit integer (NLA_U32)
|
||||
* @WPROBE_VAL_S64: signed 64-bit integer (NLA_U64)
|
||||
* @WPROBE_VAL_U8: unsigned 8-bit integer (NLA_U8)
|
||||
* @WPROBE_VAL_U16: unsigned 16-bit integer (NLA_U16)
|
||||
* @WPROBE_VAL_U32: unsigned 32-bit integer (NLA_U32)
|
||||
* @WPROBE_VAL_U64: unsigned 64-bit integer (NLA_U64)
|
||||
*
|
||||
* statistics:
|
||||
* @WPROBE_VAL_SUM: sum of all samples
|
||||
* @WPROBE_VAL_SUM_SQ: sum of all samples^2
|
||||
* @WPROBE_VAL_SAMPLES: number of samples
|
||||
* @WPROBE_VAL_SCALE_TIME: last time the samples were scaled down
|
||||
*
|
||||
* configuration:
|
||||
* @WPROBE_ATTR_INTERVAL: (measurement interval in milliseconds) (NLA_MSECS)
|
||||
* @WPROBE_ATTR_SAMPLES_MIN: minimum samples to keep during inactivity (NLA_U32)
|
||||
* @WPROBE_ATTR_SAMPLES_MAX: maximum samples to keep before scaling down (NLA_U32)
|
||||
* @WPROBE_ATTR_SAMPLES_SCALE_M: multiplier for scaling down samples (NLA_U32)
|
||||
* @WPROBE_ATTR_SAMPLES_SCALE_D: divisor for scaling down samples (NLA_U32)
|
||||
*
|
||||
* @WPROBE_ATTR_LAST: unused
|
||||
*/
|
||||
enum wprobe_attr {
|
||||
/* query attributes */
|
||||
WPROBE_ATTR_UNSPEC,
|
||||
WPROBE_ATTR_INTERFACE,
|
||||
WPROBE_ATTR_MAC,
|
||||
WPROBE_ATTR_FLAGS,
|
||||
|
||||
/* response data */
|
||||
WPROBE_ATTR_ID,
|
||||
WPROBE_ATTR_NAME,
|
||||
WPROBE_ATTR_TYPE,
|
||||
WPROBE_ATTR_DURATION,
|
||||
|
||||
/* value type attributes */
|
||||
WPROBE_VAL_STRING,
|
||||
WPROBE_VAL_S8,
|
||||
WPROBE_VAL_S16,
|
||||
WPROBE_VAL_S32,
|
||||
WPROBE_VAL_S64,
|
||||
WPROBE_VAL_U8,
|
||||
WPROBE_VAL_U16,
|
||||
WPROBE_VAL_U32,
|
||||
WPROBE_VAL_U64,
|
||||
|
||||
/* aggregates for statistics */
|
||||
WPROBE_VAL_SUM,
|
||||
WPROBE_VAL_SUM_SQ,
|
||||
WPROBE_VAL_SAMPLES,
|
||||
WPROBE_VAL_SCALE_TIME,
|
||||
|
||||
/* config attributes */
|
||||
WPROBE_ATTR_INTERVAL,
|
||||
WPROBE_ATTR_SAMPLES_MIN,
|
||||
WPROBE_ATTR_SAMPLES_MAX,
|
||||
WPROBE_ATTR_SAMPLES_SCALE_M,
|
||||
WPROBE_ATTR_SAMPLES_SCALE_D,
|
||||
WPROBE_ATTR_FILTER,
|
||||
|
||||
WPROBE_ATTR_FILTER_GROUP,
|
||||
WPROBE_ATTR_RXCOUNT,
|
||||
WPROBE_ATTR_TXCOUNT,
|
||||
|
||||
WPROBE_ATTR_LAST
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* enum wprobe_cmd: netlink commands for interacting with wprobe
|
||||
*
|
||||
* @WPROBE_CMD_UNSPEC: unused
|
||||
*
|
||||
* @WPROBE_CMD_GET_LIST: get global/link property list
|
||||
* @WPROBE_CMD_GET_INFO: get global/link properties
|
||||
* @WPROBE_CMD_SET_FLAGS: set global/link flags
|
||||
* @WPROBE_CMD_MEASURE: take a snapshot of the current data
|
||||
* @WPROBE_CMD_GET_LINKS: get a list of links
|
||||
* @WPROBE_CMD_CONFIG: set config options
|
||||
* @WPROBE_CMD_GET_FILTER: get counters for active filters
|
||||
*
|
||||
* @WPROBE_CMD_LAST: unused
|
||||
*
|
||||
* options for GET_INFO and SET_FLAGS:
|
||||
* - mac address set: per-link
|
||||
* - mac address unset: globalsa
|
||||
*/
|
||||
enum wprobe_cmd {
|
||||
WPROBE_CMD_UNSPEC,
|
||||
WPROBE_CMD_GET_LIST,
|
||||
WPROBE_CMD_GET_INFO,
|
||||
WPROBE_CMD_SET_FLAGS,
|
||||
WPROBE_CMD_MEASURE,
|
||||
WPROBE_CMD_GET_LINKS,
|
||||
WPROBE_CMD_CONFIG,
|
||||
WPROBE_CMD_GET_FILTER,
|
||||
WPROBE_CMD_LAST
|
||||
};
|
||||
|
||||
/**
|
||||
* enum wprobe_flags: flags for wprobe links and items
|
||||
* @WPROBE_F_KEEPSTAT: keep statistics for this link/device
|
||||
* @WPROBE_F_RESET: reset statistics now
|
||||
* @WPROBE_F_NEWDATA: used to indicate that a value has been updated
|
||||
*/
|
||||
enum wprobe_flags {
|
||||
WPROBE_F_KEEPSTAT = (1 << 0),
|
||||
WPROBE_F_RESET = (1 << 1),
|
||||
WPROBE_F_NEWDATA = (1 << 2),
|
||||
};
|
||||
|
||||
#ifdef __KERNEL__
|
||||
|
||||
struct wprobe_link;
|
||||
struct wprobe_item;
|
||||
struct wprobe_source;
|
||||
struct wprobe_value;
|
||||
|
||||
/**
|
||||
* struct wprobe_link - data structure describing a wireless link
|
||||
* @iface: pointer to the wprobe_iface that this link belongs to
|
||||
* @addr: BSSID of the remote link partner
|
||||
* @flags: link flags (see wprobe_flags)
|
||||
* @priv: user pointer
|
||||
*
|
||||
* @list: for internal use
|
||||
* @val: for internal use
|
||||
*/
|
||||
struct wprobe_link {
|
||||
struct list_head list;
|
||||
struct wprobe_iface *iface;
|
||||
char addr[ETH_ALEN];
|
||||
u32 flags;
|
||||
void *priv;
|
||||
struct wprobe_value *val;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct wprobe_item - data structure describing the format of wprobe_link::data or wprobe_iface::data
|
||||
* @name: name of the field
|
||||
* @type: data type of this field
|
||||
* @flags: measurement item flags (see wprobe_flags)
|
||||
*/
|
||||
struct wprobe_item {
|
||||
const char *name;
|
||||
enum wprobe_attr type;
|
||||
u32 flags;
|
||||
};
|
||||
|
||||
struct wprobe_value {
|
||||
bool pending;
|
||||
union {
|
||||
/*
|
||||
* the following are kept uppercase to allow
|
||||
* for automated checking against WPROBE_VAL_*
|
||||
* via BUG_ON()
|
||||
*/
|
||||
const char *STRING;
|
||||
u8 U8;
|
||||
u16 U16;
|
||||
u32 U32;
|
||||
u64 U64;
|
||||
s8 S8;
|
||||
s16 S16;
|
||||
s32 S32;
|
||||
s64 S64;
|
||||
};
|
||||
s64 s, ss;
|
||||
unsigned int n;
|
||||
|
||||
/* timestamps */
|
||||
u64 first, last;
|
||||
u64 scale_timestamp;
|
||||
};
|
||||
|
||||
struct wprobe_filter_item_hdr {
|
||||
char name[32];
|
||||
__be32 n_items;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct wprobe_filter_item {
|
||||
struct wprobe_filter_item_hdr hdr;
|
||||
struct sock_filter filter[];
|
||||
} __attribute__((packed));
|
||||
|
||||
struct wprobe_filter_counter {
|
||||
u64 tx;
|
||||
u64 rx;
|
||||
};
|
||||
|
||||
struct wprobe_filter_group {
|
||||
const char *name;
|
||||
int n_items;
|
||||
struct wprobe_filter_item **items;
|
||||
struct wprobe_filter_counter *counters;
|
||||
};
|
||||
|
||||
struct wprobe_filter_hdr {
|
||||
__u8 magic[4];
|
||||
__u8 version;
|
||||
__u8 hdrlen;
|
||||
__u16 n_groups;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct wprobe_filter {
|
||||
spinlock_t lock;
|
||||
struct sk_buff *skb;
|
||||
void *data;
|
||||
int n_groups;
|
||||
int hdrlen;
|
||||
struct wprobe_filter_item **items;
|
||||
struct wprobe_filter_counter *counters;
|
||||
struct wprobe_filter_group groups[];
|
||||
};
|
||||
|
||||
enum {
|
||||
WPROBE_PKT_RX = 0x00,
|
||||
WPROBE_PKT_TX = 0x10,
|
||||
};
|
||||
|
||||
struct wprobe_wlan_hdr {
|
||||
u16 len;
|
||||
u8 snr;
|
||||
u8 type;
|
||||
} __attribute__((packed));
|
||||
|
||||
|
||||
/**
|
||||
* struct wprobe_source - data structure describing a wireless interface
|
||||
*
|
||||
* @name: name of the interface
|
||||
* @addr: local mac address of the interface
|
||||
* @links: list of wireless links to poll
|
||||
* @link_items: description of the per-link data structure
|
||||
* @n_link_items: number of link description items
|
||||
* @global_items: description of the per-interface data structure
|
||||
* @n_global_items: number of per-interface description items
|
||||
* @sync_data: callback allowing the driver to prepare data for the wprobe poll
|
||||
*
|
||||
* @list: head for the list of interfaces
|
||||
* @priv: user pointer
|
||||
* @lock: spinlock protecting value data access
|
||||
* @val: internal use
|
||||
* @query_val: internal use
|
||||
*
|
||||
* if sync_data is NULL, wprobe assumes that it can access the data structure
|
||||
* at any time (in atomic context). if sync_data returns a negative error code,
|
||||
* the poll request will not be handled for the given link
|
||||
*/
|
||||
struct wprobe_iface {
|
||||
/* to be filled in by wprobe source drivers */
|
||||
const char *name;
|
||||
const char *addr;
|
||||
const struct wprobe_item *link_items;
|
||||
int n_link_items;
|
||||
const struct wprobe_item *global_items;
|
||||
int n_global_items;
|
||||
|
||||
int (*sync_data)(struct wprobe_iface *dev, struct wprobe_link *l,
|
||||
struct wprobe_value *val, bool measure);
|
||||
void *priv;
|
||||
|
||||
/* handled by the wprobe core */
|
||||
struct list_head list;
|
||||
struct list_head links;
|
||||
spinlock_t lock;
|
||||
struct wprobe_value *val;
|
||||
struct wprobe_value *query_val;
|
||||
struct wprobe_filter *active_filter;
|
||||
|
||||
u32 measure_interval;
|
||||
struct timer_list measure_timer;
|
||||
|
||||
u32 scale_min;
|
||||
u32 scale_max;
|
||||
u32 scale_m;
|
||||
u32 scale_d;
|
||||
};
|
||||
|
||||
|
||||
#define WPROBE_FILL_BEGIN(_ptr, _list) do { \
|
||||
struct wprobe_value *__val = (_ptr); \
|
||||
const struct wprobe_item *__item = _list; \
|
||||
u64 __msecs = jiffies_to_msecs(jiffies)
|
||||
|
||||
#define WPROBE_SET(_idx, _type, _value) \
|
||||
if (__item[_idx].type != WPROBE_VAL_##_type) { \
|
||||
printk("ERROR: invalid data type at %s:%d\n", __FILE__, __LINE__); \
|
||||
break; \
|
||||
} \
|
||||
__val[_idx].pending = true; \
|
||||
__val[_idx]._type = _value; \
|
||||
if (!__val[_idx].first) \
|
||||
__val[_idx].first = __msecs; \
|
||||
__val[_idx].first = __msecs
|
||||
|
||||
#define WPROBE_FILL_END() \
|
||||
} while(0)
|
||||
|
||||
/**
|
||||
* wprobe_add_iface: register an interface with the wireless probe subsystem
|
||||
* @dev: wprobe_iface structure describing the interface
|
||||
*/
|
||||
extern int __weak wprobe_add_iface(struct wprobe_iface *dev);
|
||||
|
||||
/**
|
||||
* wprobe_remove_iface: deregister an interface from the wireless probe subsystem
|
||||
* @dev: wprobe_iface structure describing the interface
|
||||
*/
|
||||
extern void __weak wprobe_remove_iface(struct wprobe_iface *dev);
|
||||
|
||||
/**
|
||||
* wprobe_add_link: register a new wireless link
|
||||
* @dev: wprobe_iface structure describing the interface
|
||||
* @l: storage space for the wprobe_link structure
|
||||
* @addr: mac address of the new link
|
||||
*
|
||||
* the entire wprobe_link structure is overwritten by this function call
|
||||
*/
|
||||
extern int __weak wprobe_add_link(struct wprobe_iface *dev, struct wprobe_link *l, const char *addr);
|
||||
|
||||
/**
|
||||
* wprobe_remove_link: deregister a previously registered wireless link
|
||||
* @dev: wprobe_iface structure describing the interface
|
||||
* @l: wprobe_link data structure
|
||||
*/
|
||||
extern void __weak wprobe_remove_link(struct wprobe_iface *dev, struct wprobe_link *l);
|
||||
|
||||
/**
|
||||
* wprobe_update_stats: update statistics after sampling values
|
||||
* @dev: wprobe_iface structure describing the interface
|
||||
* @l: wprobe_link data structure
|
||||
*
|
||||
* if l == NULL, then the stats for globals are updated
|
||||
*/
|
||||
extern void __weak wprobe_update_stats(struct wprobe_iface *dev, struct wprobe_link *l);
|
||||
|
||||
/**
|
||||
* wprobe_add_frame: add frame for layer 2 analysis
|
||||
* @dev: wprobe_iface structure describing the interface
|
||||
* @hdr: metadata for the frame
|
||||
* @data: 802.11 header pointer
|
||||
* @len: length of the 802.11 header
|
||||
*/
|
||||
extern int __weak wprobe_add_frame(struct wprobe_iface *dev, const struct wprobe_wlan_hdr *hdr, void *data, int len);
|
||||
|
||||
#endif /* __KERNEL__ */
|
||||
|
||||
#endif
|
1164
net/wprobe/src/kernel/wprobe-core.c
Normal file
1164
net/wprobe/src/kernel/wprobe-core.c
Normal file
File diff suppressed because it is too large
Load Diff
96
net/wprobe/src/kernel/wprobe-dummy.c
Normal file
96
net/wprobe/src/kernel/wprobe-dummy.c
Normal file
@ -0,0 +1,96 @@
|
||||
/*
|
||||
* wprobe-core.c: Wireless probe interface dummy driver
|
||||
* Copyright (C) 2008-2009 Felix Fietkau <nbd@openwrt.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/version.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/types.h>
|
||||
#include <linux/spinlock.h>
|
||||
#include <linux/random.h>
|
||||
#include <linux/wprobe.h>
|
||||
|
||||
static const char local_addr[] = "\x00\x13\x37\xba\xbe\x00";
|
||||
|
||||
enum dummy_global_values {
|
||||
DUMMY_GLOBAL_MEDIUM_BUSY
|
||||
};
|
||||
enum dummy_link_values {
|
||||
DUMMY_LINK_SNR
|
||||
};
|
||||
|
||||
struct wprobe_item dummy_perlink[] = {
|
||||
[DUMMY_LINK_SNR] = {
|
||||
.name = "snr",
|
||||
.type = WPROBE_VAL_U8,
|
||||
.flags = WPROBE_F_KEEPSTAT,
|
||||
},
|
||||
};
|
||||
|
||||
struct wprobe_item dummy_globals[] = {
|
||||
[DUMMY_GLOBAL_MEDIUM_BUSY] = {
|
||||
.name = "medium_busy",
|
||||
.type = WPROBE_VAL_U8,
|
||||
.flags = WPROBE_F_KEEPSTAT,
|
||||
}
|
||||
};
|
||||
|
||||
int dummy_sync(struct wprobe_iface *dev, struct wprobe_link *l, struct wprobe_value *val, bool measure)
|
||||
{
|
||||
u8 intval = 0;
|
||||
|
||||
get_random_bytes(&intval, 1);
|
||||
if (l) {
|
||||
WPROBE_FILL_BEGIN(val, dummy_perlink);
|
||||
WPROBE_SET(DUMMY_LINK_SNR, U8, (intval % 40));
|
||||
WPROBE_FILL_END();
|
||||
} else {
|
||||
WPROBE_FILL_BEGIN(val, dummy_globals);
|
||||
WPROBE_SET(DUMMY_GLOBAL_MEDIUM_BUSY, U8, (intval % 100));
|
||||
WPROBE_FILL_END();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct wprobe_iface dummy_dev = {
|
||||
.name = "dummy",
|
||||
.addr = local_addr,
|
||||
.link_items = dummy_perlink,
|
||||
.n_link_items = ARRAY_SIZE(dummy_perlink),
|
||||
.global_items = dummy_globals,
|
||||
.n_global_items = ARRAY_SIZE(dummy_globals),
|
||||
.sync_data = dummy_sync,
|
||||
};
|
||||
|
||||
static struct wprobe_link dummy_link;
|
||||
|
||||
static int __init
|
||||
wprobe_dummy_init(void)
|
||||
{
|
||||
wprobe_add_iface(&dummy_dev);
|
||||
wprobe_add_link(&dummy_dev, &dummy_link, "\x00\x13\x37\xda\xda\x00");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void __exit
|
||||
wprobe_dummy_exit(void)
|
||||
{
|
||||
wprobe_remove_link(&dummy_dev, &dummy_link);
|
||||
wprobe_remove_iface(&dummy_dev);
|
||||
}
|
||||
|
||||
module_init(wprobe_dummy_init);
|
||||
module_exit(wprobe_dummy_exit);
|
||||
|
||||
MODULE_LICENSE("GPL");
|
38
net/wprobe/src/user/Makefile
Normal file
38
net/wprobe/src/user/Makefile
Normal file
@ -0,0 +1,38 @@
|
||||
include ../Makefile.inc
|
||||
|
||||
CPPFLAGS += -I../kernel
|
||||
LDFLAGS =
|
||||
|
||||
ifneq ($(HOST_OS),Linux)
|
||||
USE_LIBNL_MICRO=1
|
||||
else
|
||||
USE_LIBNL_MICRO=
|
||||
endif
|
||||
|
||||
ifeq ($(USE_LIBNL_MICRO),1)
|
||||
LIBNL_PREFIX = /usr/local
|
||||
LIBNL = $(LIBNL_PREFIX)/lib/libnl-micro.a
|
||||
CPPFLAGS += -I$(LIBNL_PREFIX)/include/libnl-micro
|
||||
EXTRA_CFLAGS += -DNO_LOCAL_ACCESS
|
||||
else
|
||||
LIBNL = -lnl
|
||||
endif
|
||||
|
||||
LIBM = -lm
|
||||
LIBS = $(LIBNL) $(LIBM)
|
||||
|
||||
all: libwprobe.a wprobe-util
|
||||
|
||||
libwprobe.a: wprobe-lib.o
|
||||
rm -f $@
|
||||
$(AR) rcu $@ $^
|
||||
$(RANLIB) $@
|
||||
|
||||
%.o: %.c
|
||||
$(CC) $(WFLAGS) -c -o $@ $(CPPFLAGS) $(CFLAGS) $(EXTRA_CFLAGS) $<
|
||||
|
||||
wprobe-util: wprobe-util.o wprobe-lib.o
|
||||
$(CC) -o $@ $^ $(LDFLAGS) $(LIBS)
|
||||
|
||||
clean:
|
||||
rm -f *.o *.a wprobe-util
|
601
net/wprobe/src/user/list.h
Normal file
601
net/wprobe/src/user/list.h
Normal file
@ -0,0 +1,601 @@
|
||||
#ifndef _LINUX_LIST_H
|
||||
#define _LINUX_LIST_H
|
||||
|
||||
#include <stddef.h>
|
||||
/**
|
||||
* container_of - cast a member of a structure out to the containing structure
|
||||
* @ptr: the pointer to the member.
|
||||
* @type: the type of the container struct this is embedded in.
|
||||
* @member: the name of the member within the struct.
|
||||
*
|
||||
*/
|
||||
#ifndef container_of
|
||||
#define container_of(ptr, type, member) ( \
|
||||
(type *)( (char *)ptr - offsetof(type,member) ))
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Simple doubly linked list implementation.
|
||||
*
|
||||
* Some of the internal functions ("__xxx") are useful when
|
||||
* manipulating whole lists rather than single entries, as
|
||||
* sometimes we already know the next/prev entries and we can
|
||||
* generate better code by using them directly rather than
|
||||
* using the generic single-entry routines.
|
||||
*/
|
||||
|
||||
struct list_head {
|
||||
struct list_head *next, *prev;
|
||||
};
|
||||
|
||||
#define LIST_HEAD_INIT(name) { &(name), &(name) }
|
||||
|
||||
#define LIST_HEAD(name) \
|
||||
struct list_head name = LIST_HEAD_INIT(name)
|
||||
|
||||
static inline void INIT_LIST_HEAD(struct list_head *list)
|
||||
{
|
||||
list->next = list;
|
||||
list->prev = list;
|
||||
}
|
||||
|
||||
/*
|
||||
* Insert a new entry between two known consecutive entries.
|
||||
*
|
||||
* This is only for internal list manipulation where we know
|
||||
* the prev/next entries already!
|
||||
*/
|
||||
static inline void __list_add(struct list_head *new,
|
||||
struct list_head *prev,
|
||||
struct list_head *next)
|
||||
{
|
||||
next->prev = new;
|
||||
new->next = next;
|
||||
new->prev = prev;
|
||||
prev->next = new;
|
||||
}
|
||||
|
||||
/**
|
||||
* list_add - add a new entry
|
||||
* @new: new entry to be added
|
||||
* @head: list head to add it after
|
||||
*
|
||||
* Insert a new entry after the specified head.
|
||||
* This is good for implementing stacks.
|
||||
*/
|
||||
static inline void list_add(struct list_head *new, struct list_head *head)
|
||||
{
|
||||
__list_add(new, head, head->next);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* list_add_tail - add a new entry
|
||||
* @new: new entry to be added
|
||||
* @head: list head to add it before
|
||||
*
|
||||
* Insert a new entry before the specified head.
|
||||
* This is useful for implementing queues.
|
||||
*/
|
||||
static inline void list_add_tail(struct list_head *new, struct list_head *head)
|
||||
{
|
||||
__list_add(new, head->prev, head);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Delete a list entry by making the prev/next entries
|
||||
* point to each other.
|
||||
*
|
||||
* This is only for internal list manipulation where we know
|
||||
* the prev/next entries already!
|
||||
*/
|
||||
static inline void __list_del(struct list_head * prev, struct list_head * next)
|
||||
{
|
||||
next->prev = prev;
|
||||
prev->next = next;
|
||||
}
|
||||
|
||||
/**
|
||||
* list_del - deletes entry from list.
|
||||
* @entry: the element to delete from the list.
|
||||
* Note: list_empty() on entry does not return true after this, the entry is
|
||||
* in an undefined state.
|
||||
*/
|
||||
static inline void list_del(struct list_head *entry)
|
||||
{
|
||||
__list_del(entry->prev, entry->next);
|
||||
entry->next = NULL;
|
||||
entry->prev = NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* list_replace - replace old entry by new one
|
||||
* @old : the element to be replaced
|
||||
* @new : the new element to insert
|
||||
*
|
||||
* If @old was empty, it will be overwritten.
|
||||
*/
|
||||
static inline void list_replace(struct list_head *old,
|
||||
struct list_head *new)
|
||||
{
|
||||
new->next = old->next;
|
||||
new->next->prev = new;
|
||||
new->prev = old->prev;
|
||||
new->prev->next = new;
|
||||
}
|
||||
|
||||
static inline void list_replace_init(struct list_head *old,
|
||||
struct list_head *new)
|
||||
{
|
||||
list_replace(old, new);
|
||||
INIT_LIST_HEAD(old);
|
||||
}
|
||||
|
||||
/**
|
||||
* list_del_init - deletes entry from list and reinitialize it.
|
||||
* @entry: the element to delete from the list.
|
||||
*/
|
||||
static inline void list_del_init(struct list_head *entry)
|
||||
{
|
||||
__list_del(entry->prev, entry->next);
|
||||
INIT_LIST_HEAD(entry);
|
||||
}
|
||||
|
||||
/**
|
||||
* list_move - delete from one list and add as another's head
|
||||
* @list: the entry to move
|
||||
* @head: the head that will precede our entry
|
||||
*/
|
||||
static inline void list_move(struct list_head *list, struct list_head *head)
|
||||
{
|
||||
__list_del(list->prev, list->next);
|
||||
list_add(list, head);
|
||||
}
|
||||
|
||||
/**
|
||||
* list_move_tail - delete from one list and add as another's tail
|
||||
* @list: the entry to move
|
||||
* @head: the head that will follow our entry
|
||||
*/
|
||||
static inline void list_move_tail(struct list_head *list,
|
||||
struct list_head *head)
|
||||
{
|
||||
__list_del(list->prev, list->next);
|
||||
list_add_tail(list, head);
|
||||
}
|
||||
|
||||
/**
|
||||
* list_is_last - tests whether @list is the last entry in list @head
|
||||
* @list: the entry to test
|
||||
* @head: the head of the list
|
||||
*/
|
||||
static inline int list_is_last(const struct list_head *list,
|
||||
const struct list_head *head)
|
||||
{
|
||||
return list->next == head;
|
||||
}
|
||||
|
||||
/**
|
||||
* list_empty - tests whether a list is empty
|
||||
* @head: the list to test.
|
||||
*/
|
||||
static inline int list_empty(const struct list_head *head)
|
||||
{
|
||||
return head->next == head;
|
||||
}
|
||||
|
||||
/**
|
||||
* list_empty_careful - tests whether a list is empty and not being modified
|
||||
* @head: the list to test
|
||||
*
|
||||
* Description:
|
||||
* tests whether a list is empty _and_ checks that no other CPU might be
|
||||
* in the process of modifying either member (next or prev)
|
||||
*
|
||||
* NOTE: using list_empty_careful() without synchronization
|
||||
* can only be safe if the only activity that can happen
|
||||
* to the list entry is list_del_init(). Eg. it cannot be used
|
||||
* if another CPU could re-list_add() it.
|
||||
*/
|
||||
static inline int list_empty_careful(const struct list_head *head)
|
||||
{
|
||||
struct list_head *next = head->next;
|
||||
return (next == head) && (next == head->prev);
|
||||
}
|
||||
|
||||
static inline void __list_splice(struct list_head *list,
|
||||
struct list_head *head)
|
||||
{
|
||||
struct list_head *first = list->next;
|
||||
struct list_head *last = list->prev;
|
||||
struct list_head *at = head->next;
|
||||
|
||||
first->prev = head;
|
||||
head->next = first;
|
||||
|
||||
last->next = at;
|
||||
at->prev = last;
|
||||
}
|
||||
|
||||
/**
|
||||
* list_splice - join two lists
|
||||
* @list: the new list to add.
|
||||
* @head: the place to add it in the first list.
|
||||
*/
|
||||
static inline void list_splice(struct list_head *list, struct list_head *head)
|
||||
{
|
||||
if (!list_empty(list))
|
||||
__list_splice(list, head);
|
||||
}
|
||||
|
||||
/**
|
||||
* list_splice_init - join two lists and reinitialise the emptied list.
|
||||
* @list: the new list to add.
|
||||
* @head: the place to add it in the first list.
|
||||
*
|
||||
* The list at @list is reinitialised
|
||||
*/
|
||||
static inline void list_splice_init(struct list_head *list,
|
||||
struct list_head *head)
|
||||
{
|
||||
if (!list_empty(list)) {
|
||||
__list_splice(list, head);
|
||||
INIT_LIST_HEAD(list);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* list_entry - get the struct for this entry
|
||||
* @ptr: the &struct list_head pointer.
|
||||
* @type: the type of the struct this is embedded in.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*/
|
||||
#define list_entry(ptr, type, member) \
|
||||
container_of(ptr, type, member)
|
||||
|
||||
/**
|
||||
* list_first_entry - get the first element from a list
|
||||
* @ptr: the list head to take the element from.
|
||||
* @type: the type of the struct this is embedded in.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*
|
||||
* Note, that list is expected to be not empty.
|
||||
*/
|
||||
#define list_first_entry(ptr, type, member) \
|
||||
list_entry((ptr)->next, type, member)
|
||||
|
||||
/**
|
||||
* list_for_each - iterate over a list
|
||||
* @pos: the &struct list_head to use as a loop cursor.
|
||||
* @head: the head for your list.
|
||||
*/
|
||||
#define list_for_each(pos, head) \
|
||||
for (pos = (head)->next; pos != (head); \
|
||||
pos = pos->next)
|
||||
|
||||
/**
|
||||
* __list_for_each - iterate over a list
|
||||
* @pos: the &struct list_head to use as a loop cursor.
|
||||
* @head: the head for your list.
|
||||
*
|
||||
* This variant differs from list_for_each() in that it's the
|
||||
* simplest possible list iteration code, no prefetching is done.
|
||||
* Use this for code that knows the list to be very short (empty
|
||||
* or 1 entry) most of the time.
|
||||
*/
|
||||
#define __list_for_each(pos, head) \
|
||||
for (pos = (head)->next; pos != (head); pos = pos->next)
|
||||
|
||||
/**
|
||||
* list_for_each_prev - iterate over a list backwards
|
||||
* @pos: the &struct list_head to use as a loop cursor.
|
||||
* @head: the head for your list.
|
||||
*/
|
||||
#define list_for_each_prev(pos, head) \
|
||||
for (pos = (head)->prev; pos != (head); \
|
||||
pos = pos->prev)
|
||||
|
||||
/**
|
||||
* list_for_each_safe - iterate over a list safe against removal of list entry
|
||||
* @pos: the &struct list_head to use as a loop cursor.
|
||||
* @n: another &struct list_head to use as temporary storage
|
||||
* @head: the head for your list.
|
||||
*/
|
||||
#define list_for_each_safe(pos, n, head) \
|
||||
for (pos = (head)->next, n = pos->next; pos != (head); \
|
||||
pos = n, n = pos->next)
|
||||
|
||||
/**
|
||||
* list_for_each_prev_safe - iterate over a list backwards safe against removal of list entry
|
||||
* @pos: the &struct list_head to use as a loop cursor.
|
||||
* @n: another &struct list_head to use as temporary storage
|
||||
* @head: the head for your list.
|
||||
*/
|
||||
#define list_for_each_prev_safe(pos, n, head) \
|
||||
for (pos = (head)->prev, n = pos->prev; \
|
||||
pos != (head); \
|
||||
pos = n, n = pos->prev)
|
||||
|
||||
/**
|
||||
* list_for_each_entry - iterate over list of given type
|
||||
* @pos: the type * to use as a loop cursor.
|
||||
* @head: the head for your list.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*/
|
||||
#define list_for_each_entry(pos, head, member) \
|
||||
for (pos = list_entry((head)->next, typeof(*pos), member); \
|
||||
&pos->member != (head); \
|
||||
pos = list_entry(pos->member.next, typeof(*pos), member))
|
||||
|
||||
/**
|
||||
* list_for_each_entry_reverse - iterate backwards over list of given type.
|
||||
* @pos: the type * to use as a loop cursor.
|
||||
* @head: the head for your list.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*/
|
||||
#define list_for_each_entry_reverse(pos, head, member) \
|
||||
for (pos = list_entry((head)->prev, typeof(*pos), member); \
|
||||
&pos->member != (head); \
|
||||
pos = list_entry(pos->member.prev, typeof(*pos), member))
|
||||
|
||||
/**
|
||||
* list_prepare_entry - prepare a pos entry for use in list_for_each_entry_continue()
|
||||
* @pos: the type * to use as a start point
|
||||
* @head: the head of the list
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*
|
||||
* Prepares a pos entry for use as a start point in list_for_each_entry_continue().
|
||||
*/
|
||||
#define list_prepare_entry(pos, head, member) \
|
||||
((pos) ? : list_entry(head, typeof(*pos), member))
|
||||
|
||||
/**
|
||||
* list_for_each_entry_continue - continue iteration over list of given type
|
||||
* @pos: the type * to use as a loop cursor.
|
||||
* @head: the head for your list.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*
|
||||
* Continue to iterate over list of given type, continuing after
|
||||
* the current position.
|
||||
*/
|
||||
#define list_for_each_entry_continue(pos, head, member) \
|
||||
for (pos = list_entry(pos->member.next, typeof(*pos), member); \
|
||||
&pos->member != (head); \
|
||||
pos = list_entry(pos->member.next, typeof(*pos), member))
|
||||
|
||||
/**
|
||||
* list_for_each_entry_continue_reverse - iterate backwards from the given point
|
||||
* @pos: the type * to use as a loop cursor.
|
||||
* @head: the head for your list.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*
|
||||
* Start to iterate over list of given type backwards, continuing after
|
||||
* the current position.
|
||||
*/
|
||||
#define list_for_each_entry_continue_reverse(pos, head, member) \
|
||||
for (pos = list_entry(pos->member.prev, typeof(*pos), member); \
|
||||
&pos->member != (head); \
|
||||
pos = list_entry(pos->member.prev, typeof(*pos), member))
|
||||
|
||||
/**
|
||||
* list_for_each_entry_from - iterate over list of given type from the current point
|
||||
* @pos: the type * to use as a loop cursor.
|
||||
* @head: the head for your list.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*
|
||||
* Iterate over list of given type, continuing from current position.
|
||||
*/
|
||||
#define list_for_each_entry_from(pos, head, member) \
|
||||
for (; &pos->member != (head); \
|
||||
pos = list_entry(pos->member.next, typeof(*pos), member))
|
||||
|
||||
/**
|
||||
* list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
|
||||
* @pos: the type * to use as a loop cursor.
|
||||
* @n: another type * to use as temporary storage
|
||||
* @head: the head for your list.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*/
|
||||
#define list_for_each_entry_safe(pos, n, head, member) \
|
||||
for (pos = list_entry((head)->next, typeof(*pos), member), \
|
||||
n = list_entry(pos->member.next, typeof(*pos), member); \
|
||||
&pos->member != (head); \
|
||||
pos = n, n = list_entry(n->member.next, typeof(*n), member))
|
||||
|
||||
/**
|
||||
* list_for_each_entry_safe_continue
|
||||
* @pos: the type * to use as a loop cursor.
|
||||
* @n: another type * to use as temporary storage
|
||||
* @head: the head for your list.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*
|
||||
* Iterate over list of given type, continuing after current point,
|
||||
* safe against removal of list entry.
|
||||
*/
|
||||
#define list_for_each_entry_safe_continue(pos, n, head, member) \
|
||||
for (pos = list_entry(pos->member.next, typeof(*pos), member), \
|
||||
n = list_entry(pos->member.next, typeof(*pos), member); \
|
||||
&pos->member != (head); \
|
||||
pos = n, n = list_entry(n->member.next, typeof(*n), member))
|
||||
|
||||
/**
|
||||
* list_for_each_entry_safe_from
|
||||
* @pos: the type * to use as a loop cursor.
|
||||
* @n: another type * to use as temporary storage
|
||||
* @head: the head for your list.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*
|
||||
* Iterate over list of given type from current point, safe against
|
||||
* removal of list entry.
|
||||
*/
|
||||
#define list_for_each_entry_safe_from(pos, n, head, member) \
|
||||
for (n = list_entry(pos->member.next, typeof(*pos), member); \
|
||||
&pos->member != (head); \
|
||||
pos = n, n = list_entry(n->member.next, typeof(*n), member))
|
||||
|
||||
/**
|
||||
* list_for_each_entry_safe_reverse
|
||||
* @pos: the type * to use as a loop cursor.
|
||||
* @n: another type * to use as temporary storage
|
||||
* @head: the head for your list.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*
|
||||
* Iterate backwards over list of given type, safe against removal
|
||||
* of list entry.
|
||||
*/
|
||||
#define list_for_each_entry_safe_reverse(pos, n, head, member) \
|
||||
for (pos = list_entry((head)->prev, typeof(*pos), member), \
|
||||
n = list_entry(pos->member.prev, typeof(*pos), member); \
|
||||
&pos->member != (head); \
|
||||
pos = n, n = list_entry(n->member.prev, typeof(*n), member))
|
||||
|
||||
/*
|
||||
* Double linked lists with a single pointer list head.
|
||||
* Mostly useful for hash tables where the two pointer list head is
|
||||
* too wasteful.
|
||||
* You lose the ability to access the tail in O(1).
|
||||
*/
|
||||
|
||||
struct hlist_head {
|
||||
struct hlist_node *first;
|
||||
};
|
||||
|
||||
struct hlist_node {
|
||||
struct hlist_node *next, **pprev;
|
||||
};
|
||||
|
||||
#define HLIST_HEAD_INIT { .first = NULL }
|
||||
#define HLIST_HEAD(name) struct hlist_head name = { .first = NULL }
|
||||
#define INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL)
|
||||
static inline void INIT_HLIST_NODE(struct hlist_node *h)
|
||||
{
|
||||
h->next = NULL;
|
||||
h->pprev = NULL;
|
||||
}
|
||||
|
||||
static inline int hlist_unhashed(const struct hlist_node *h)
|
||||
{
|
||||
return !h->pprev;
|
||||
}
|
||||
|
||||
static inline int hlist_empty(const struct hlist_head *h)
|
||||
{
|
||||
return !h->first;
|
||||
}
|
||||
|
||||
static inline void __hlist_del(struct hlist_node *n)
|
||||
{
|
||||
struct hlist_node *next = n->next;
|
||||
struct hlist_node **pprev = n->pprev;
|
||||
*pprev = next;
|
||||
if (next)
|
||||
next->pprev = pprev;
|
||||
}
|
||||
|
||||
static inline void hlist_del(struct hlist_node *n)
|
||||
{
|
||||
__hlist_del(n);
|
||||
n->next = NULL;
|
||||
n->pprev = NULL;
|
||||
}
|
||||
|
||||
static inline void hlist_del_init(struct hlist_node *n)
|
||||
{
|
||||
if (!hlist_unhashed(n)) {
|
||||
__hlist_del(n);
|
||||
INIT_HLIST_NODE(n);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
|
||||
{
|
||||
struct hlist_node *first = h->first;
|
||||
n->next = first;
|
||||
if (first)
|
||||
first->pprev = &n->next;
|
||||
h->first = n;
|
||||
n->pprev = &h->first;
|
||||
}
|
||||
|
||||
|
||||
/* next must be != NULL */
|
||||
static inline void hlist_add_before(struct hlist_node *n,
|
||||
struct hlist_node *next)
|
||||
{
|
||||
n->pprev = next->pprev;
|
||||
n->next = next;
|
||||
next->pprev = &n->next;
|
||||
*(n->pprev) = n;
|
||||
}
|
||||
|
||||
static inline void hlist_add_after(struct hlist_node *n,
|
||||
struct hlist_node *next)
|
||||
{
|
||||
next->next = n->next;
|
||||
n->next = next;
|
||||
next->pprev = &n->next;
|
||||
|
||||
if(next->next)
|
||||
next->next->pprev = &next->next;
|
||||
}
|
||||
|
||||
#define hlist_entry(ptr, type, member) container_of(ptr,type,member)
|
||||
|
||||
#define hlist_for_each(pos, head) \
|
||||
for (pos = (head)->first; pos; pos = pos->next)
|
||||
|
||||
#define hlist_for_each_safe(pos, n, head) \
|
||||
for (pos = (head)->first; pos; pos = n)
|
||||
|
||||
/**
|
||||
* hlist_for_each_entry - iterate over list of given type
|
||||
* @tpos: the type * to use as a loop cursor.
|
||||
* @pos: the &struct hlist_node to use as a loop cursor.
|
||||
* @head: the head for your list.
|
||||
* @member: the name of the hlist_node within the struct.
|
||||
*/
|
||||
#define hlist_for_each_entry(tpos, pos, head, member) \
|
||||
for (pos = (head)->first; pos && \
|
||||
({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
|
||||
pos = pos->next)
|
||||
|
||||
/**
|
||||
* hlist_for_each_entry_continue - iterate over a hlist continuing after current point
|
||||
* @tpos: the type * to use as a loop cursor.
|
||||
* @pos: the &struct hlist_node to use as a loop cursor.
|
||||
* @member: the name of the hlist_node within the struct.
|
||||
*/
|
||||
#define hlist_for_each_entry_continue(tpos, pos, member) \
|
||||
for (pos = (pos)->next; pos && \
|
||||
({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
|
||||
pos = pos->next)
|
||||
|
||||
/**
|
||||
* hlist_for_each_entry_from - iterate over a hlist continuing from current point
|
||||
* @tpos: the type * to use as a loop cursor.
|
||||
* @pos: the &struct hlist_node to use as a loop cursor.
|
||||
* @member: the name of the hlist_node within the struct.
|
||||
*/
|
||||
#define hlist_for_each_entry_from(tpos, pos, member) \
|
||||
for (; pos && \
|
||||
({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
|
||||
pos = pos->next)
|
||||
|
||||
/**
|
||||
* hlist_for_each_entry_safe - iterate over list of given type safe against removal of list entry
|
||||
* @tpos: the type * to use as a loop cursor.
|
||||
* @pos: the &struct hlist_node to use as a loop cursor.
|
||||
* @n: another &struct hlist_node to use as temporary storage
|
||||
* @head: the head for your list.
|
||||
* @member: the name of the hlist_node within the struct.
|
||||
*/
|
||||
#define hlist_for_each_entry_safe(tpos, pos, n, head, member) \
|
||||
for (pos = (head)->first; \
|
||||
pos && ({ n = pos->next; 1; }) && \
|
||||
({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
|
||||
pos = n)
|
||||
|
||||
#endif
|
1210
net/wprobe/src/user/wprobe-lib.c
Normal file
1210
net/wprobe/src/user/wprobe-lib.c
Normal file
File diff suppressed because it is too large
Load Diff
450
net/wprobe/src/user/wprobe-util.c
Normal file
450
net/wprobe/src/user/wprobe-util.c
Normal file
@ -0,0 +1,450 @@
|
||||
/*
|
||||
* wprobe-test.c: Wireless probe user space test code
|
||||
* Copyright (C) 2008-2009 Felix Fietkau <nbd@openwrt.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/wait.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <inttypes.h>
|
||||
#include <errno.h>
|
||||
#include <stdint.h>
|
||||
#include <getopt.h>
|
||||
#include <stdbool.h>
|
||||
#include <unistd.h>
|
||||
#include <netdb.h>
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include <linux/wprobe.h>
|
||||
#include "wprobe.h"
|
||||
|
||||
static bool simple_mode = false;
|
||||
|
||||
static const char *
|
||||
wprobe_dump_value(struct wprobe_attribute *attr)
|
||||
{
|
||||
static char buf[128];
|
||||
|
||||
#define HANDLE_TYPE(_type, _format) \
|
||||
case WPROBE_VAL_##_type: \
|
||||
snprintf(buf, sizeof(buf), _format, attr->val._type); \
|
||||
break
|
||||
|
||||
switch(attr->type) {
|
||||
HANDLE_TYPE(S8, "%d");
|
||||
HANDLE_TYPE(S16, "%d");
|
||||
HANDLE_TYPE(S32, "%d");
|
||||
HANDLE_TYPE(S64, "%lld");
|
||||
HANDLE_TYPE(U8, "%d");
|
||||
HANDLE_TYPE(U16, "%d");
|
||||
HANDLE_TYPE(U32, "%d");
|
||||
HANDLE_TYPE(U64, "%lld");
|
||||
case WPROBE_VAL_STRING:
|
||||
/* FIXME: implement this */
|
||||
default:
|
||||
strncpy(buf, "<unknown>", sizeof(buf));
|
||||
break;
|
||||
}
|
||||
if ((attr->flags & WPROBE_F_KEEPSTAT) &&
|
||||
(attr->val.n > 0)) {
|
||||
int len = strlen(buf);
|
||||
if (simple_mode)
|
||||
snprintf(buf + len, sizeof(buf) - len, ";%.02f;%.02f;%d;%lld;%lld", attr->val.avg, attr->val.stdev, attr->val.n, attr->val.s, attr->val.ss);
|
||||
else
|
||||
snprintf(buf + len, sizeof(buf) - len, " (avg: %.02f; stdev: %.02f, n=%d)", attr->val.avg, attr->val.stdev, attr->val.n);
|
||||
}
|
||||
#undef HANDLE_TYPE
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
wprobe_dump_data(struct wprobe_iface *dev)
|
||||
{
|
||||
struct wprobe_attribute *attr;
|
||||
struct wprobe_link *link;
|
||||
bool first = true;
|
||||
|
||||
if (!simple_mode)
|
||||
fprintf(stdout, "\n");
|
||||
wprobe_request_data(dev, NULL);
|
||||
list_for_each_entry(attr, &dev->global_attr, list) {
|
||||
if (simple_mode) {
|
||||
if (first)
|
||||
fprintf(stdout, "[global]\n");
|
||||
fprintf(stdout, "%s=%s\n", attr->name, wprobe_dump_value(attr));
|
||||
} else {
|
||||
fprintf(stdout, (first ?
|
||||
"Global: %s=%s\n" :
|
||||
" %s=%s\n"),
|
||||
attr->name,
|
||||
wprobe_dump_value(attr)
|
||||
);
|
||||
}
|
||||
first = false;
|
||||
}
|
||||
|
||||
list_for_each_entry(link, &dev->links, list) {
|
||||
first = true;
|
||||
wprobe_request_data(dev, link->addr);
|
||||
list_for_each_entry(attr, &dev->link_attr, list) {
|
||||
if (first) {
|
||||
fprintf(stdout,
|
||||
(simple_mode ?
|
||||
"[%02x:%02x:%02x:%02x:%02x:%02x]\n%s=%s\n" :
|
||||
"%02x:%02x:%02x:%02x:%02x:%02x: %s=%s\n"),
|
||||
link->addr[0], link->addr[1], link->addr[2],
|
||||
link->addr[3], link->addr[4], link->addr[5],
|
||||
attr->name,
|
||||
wprobe_dump_value(attr));
|
||||
first = false;
|
||||
} else {
|
||||
fprintf(stdout,
|
||||
(simple_mode ? "%s=%s\n" :
|
||||
" %s=%s\n"),
|
||||
attr->name,
|
||||
wprobe_dump_value(attr));
|
||||
}
|
||||
}
|
||||
}
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
static const char *attr_typestr[] = {
|
||||
[0] = "Unknown",
|
||||
[WPROBE_VAL_STRING] = "String",
|
||||
[WPROBE_VAL_U8] = "Unsigned 8 bit",
|
||||
[WPROBE_VAL_U16] = "Unsigned 16 bit",
|
||||
[WPROBE_VAL_U32] = "Unsigned 32 bit",
|
||||
[WPROBE_VAL_U64] = "Unsigned 64 bit",
|
||||
[WPROBE_VAL_S8] = "Signed 8 bit",
|
||||
[WPROBE_VAL_S16] = "Signed 16 bit",
|
||||
[WPROBE_VAL_S32] = "Signed 32 bit",
|
||||
[WPROBE_VAL_S64] = "Signed 64 bit",
|
||||
};
|
||||
|
||||
static int usage(const char *prog)
|
||||
{
|
||||
fprintf(stderr,
|
||||
#ifndef NO_LOCAL_ACCESS
|
||||
"Usage: %s <interface>|<host>:<device>|-P [options]\n"
|
||||
#else
|
||||
"Usage: %s <host>:<device> [options]\n"
|
||||
#endif
|
||||
"\n"
|
||||
"Options:\n"
|
||||
" -a: Print attributes\n"
|
||||
" -c: Only apply configuration\n"
|
||||
" -d: Delay between measurement dumps (in milliseconds, default: 1000)\n"
|
||||
" A value of 0 (zero) prints once and exits; useful for scripts\n"
|
||||
" -f: Dump contents of layer 2 filter counters during measurement\n"
|
||||
" -F <file>: Apply layer 2 filters from <file>\n"
|
||||
" -h: This help text\n"
|
||||
" -i <interval>: Set measurement interval\n"
|
||||
" -m: Run measurement loop\n"
|
||||
" -p: Set the TCP port for server/client (default: 17990)\n"
|
||||
#ifndef NO_LOCAL_ACCESS
|
||||
" -P: Run in proxy mode (listen on network)\n"
|
||||
#endif
|
||||
"\n"
|
||||
, prog);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static void show_attributes(struct wprobe_iface *dev)
|
||||
{
|
||||
struct wprobe_attribute *attr;
|
||||
if (simple_mode)
|
||||
return;
|
||||
list_for_each_entry(attr, &dev->global_attr, list) {
|
||||
fprintf(stdout, "Global attribute: '%s' (%s)\n",
|
||||
attr->name, attr_typestr[attr->type]);
|
||||
}
|
||||
list_for_each_entry(attr, &dev->link_attr, list) {
|
||||
fprintf(stdout, "Link attribute: '%s' (%s)\n",
|
||||
attr->name, attr_typestr[attr->type]);
|
||||
}
|
||||
}
|
||||
|
||||
static void show_filter_simple(void *arg, const char *group, struct wprobe_filter_item *items, int n_items)
|
||||
{
|
||||
int i;
|
||||
|
||||
fprintf(stdout, "[filter:%s]\n", group);
|
||||
for (i = 0; i < n_items; i++) {
|
||||
fprintf(stdout, "%s=%lld;%lld\n",
|
||||
items[i].name, items[i].tx, items[i].rx);
|
||||
}
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
|
||||
static void show_filter(void *arg, const char *group, struct wprobe_filter_item *items, int n_items)
|
||||
{
|
||||
int i;
|
||||
fprintf(stdout, "Filter group: '%s' (tx/rx)\n", group);
|
||||
for (i = 0; i < n_items; i++) {
|
||||
fprintf(stdout, " - %s (%lld/%lld)\n",
|
||||
items[i].name, items[i].tx, items[i].rx);
|
||||
}
|
||||
}
|
||||
|
||||
static void loop_measurement(struct wprobe_iface *dev, bool print_filters, unsigned long delay)
|
||||
{
|
||||
do {
|
||||
wprobe_update_links(dev);
|
||||
wprobe_dump_data(dev);
|
||||
if (print_filters)
|
||||
wprobe_dump_filters(dev, simple_mode ? show_filter_simple : show_filter, NULL);
|
||||
usleep(delay * 1000);
|
||||
}
|
||||
while (delay);
|
||||
}
|
||||
|
||||
static void set_filter(struct wprobe_iface *dev, const char *filename)
|
||||
{
|
||||
unsigned char *buf = NULL;
|
||||
unsigned int buflen = 0;
|
||||
unsigned int len = 0;
|
||||
int fd;
|
||||
|
||||
/* clear filter */
|
||||
if (filename[0] == 0) {
|
||||
dev->filter_len = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
fd = open(filename, O_RDONLY);
|
||||
if (fd < 0) {
|
||||
perror("open filter");
|
||||
return;
|
||||
}
|
||||
|
||||
do {
|
||||
int rlen;
|
||||
|
||||
if (!buf) {
|
||||
len = 0;
|
||||
buflen = 1024;
|
||||
buf = malloc(1024);
|
||||
} else {
|
||||
buflen *= 2;
|
||||
buf = realloc(buf, buflen);
|
||||
}
|
||||
rlen = read(fd, buf + len, buflen - len);
|
||||
if (rlen < 0)
|
||||
break;
|
||||
|
||||
len += rlen;
|
||||
} while (len == buflen);
|
||||
|
||||
dev->filter = buf;
|
||||
dev->filter_len = len;
|
||||
close(fd);
|
||||
}
|
||||
|
||||
#ifndef NO_LOCAL_ACCESS
|
||||
|
||||
static void sigchld_handler(int s)
|
||||
{
|
||||
while (waitpid(-1, NULL, WNOHANG) > 0);
|
||||
}
|
||||
|
||||
static int run_proxy(int port)
|
||||
{
|
||||
struct sockaddr_in sa;
|
||||
struct sigaction sig;
|
||||
int v = 1;
|
||||
int s;
|
||||
|
||||
s = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (s < 0) {
|
||||
perror("socket");
|
||||
return 1;
|
||||
}
|
||||
|
||||
sig.sa_handler = sigchld_handler; // Signal Handler fuer Zombie Prozesse
|
||||
sigemptyset(&sig.sa_mask);
|
||||
sig.sa_flags = SA_RESTART;
|
||||
sigaction(SIGCHLD, &sig, NULL);
|
||||
|
||||
memset(&sa, 0, sizeof(sa));
|
||||
sa.sin_family = AF_INET;
|
||||
sa.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
sa.sin_port = htons(wprobe_port);
|
||||
|
||||
setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &v, sizeof(v));
|
||||
if (bind(s, (struct sockaddr *) &sa, sizeof(sa)) < 0) {
|
||||
perror("bind");
|
||||
return 1;
|
||||
}
|
||||
if (listen(s, 10)) {
|
||||
perror("listen");
|
||||
return 1;
|
||||
}
|
||||
while(1) {
|
||||
unsigned int addrlen = sizeof(struct sockaddr_in);
|
||||
int ret, c;
|
||||
|
||||
c = accept(s, (struct sockaddr *)&sa, &addrlen);
|
||||
if (c < 0) {
|
||||
if (errno == EINTR)
|
||||
continue;
|
||||
|
||||
perror("accept");
|
||||
return 1;
|
||||
}
|
||||
if (fork() == 0) {
|
||||
/* close server socket, stdin, stdout, stderr */
|
||||
close(s);
|
||||
close(0);
|
||||
close(1);
|
||||
close(2);
|
||||
|
||||
wprobe_server_init(c);
|
||||
do {
|
||||
ret = wprobe_server_handle(c);
|
||||
} while (ret >= 0);
|
||||
wprobe_server_done();
|
||||
close(c);
|
||||
exit(0);
|
||||
}
|
||||
close(c);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
struct wprobe_iface *dev = NULL;
|
||||
const char *ifname;
|
||||
const char *prog = argv[0];
|
||||
char *err = NULL;
|
||||
enum {
|
||||
CMD_NONE,
|
||||
CMD_CONFIG,
|
||||
CMD_MEASURE,
|
||||
CMD_PROXY,
|
||||
} cmd = CMD_NONE;
|
||||
const char *filter = NULL;
|
||||
bool print_attributes = false;
|
||||
bool print_filters = false;
|
||||
unsigned long delay = 1000;
|
||||
int interval = -1;
|
||||
int ch;
|
||||
|
||||
if (argc < 2)
|
||||
return usage(prog);
|
||||
|
||||
#ifndef NO_LOCAL_ACCESS
|
||||
if (!strcmp(argv[1], "-P")) {
|
||||
while ((ch = getopt(argc - 1, argv + 1, "p:")) != -1) {
|
||||
switch(ch) {
|
||||
case 'p':
|
||||
/* set port */
|
||||
wprobe_port = strtoul(optarg, NULL, 0);
|
||||
break;
|
||||
default:
|
||||
return usage(prog);
|
||||
}
|
||||
}
|
||||
return run_proxy(wprobe_port);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (argv[1][0] == '-')
|
||||
return usage(prog);
|
||||
|
||||
ifname = argv[1];
|
||||
argv++;
|
||||
argc--;
|
||||
|
||||
while ((ch = getopt(argc, argv, "acd:fF:hi:msp:")) != -1) {
|
||||
switch(ch) {
|
||||
case 'a':
|
||||
print_attributes = true;
|
||||
break;
|
||||
case 'c':
|
||||
cmd = CMD_CONFIG;
|
||||
break;
|
||||
case 'd':
|
||||
delay = strtoul(optarg, NULL, 10);
|
||||
break;
|
||||
case 'm':
|
||||
cmd = CMD_MEASURE;
|
||||
break;
|
||||
case 'i':
|
||||
interval = strtoul(optarg, NULL, 10);
|
||||
break;
|
||||
case 'f':
|
||||
print_filters = true;
|
||||
break;
|
||||
case 'F':
|
||||
if (filter) {
|
||||
fprintf(stderr, "Cannot set multiple filters\n");
|
||||
return usage(prog);
|
||||
}
|
||||
filter = optarg;
|
||||
break;
|
||||
case 's':
|
||||
simple_mode = true;
|
||||
break;
|
||||
case 'p':
|
||||
/* set port */
|
||||
wprobe_port = strtoul(optarg, NULL, 0);
|
||||
break;
|
||||
case 'h':
|
||||
default:
|
||||
usage(prog);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
dev = wprobe_get_auto(ifname, &err);
|
||||
if (!dev || (list_empty(&dev->global_attr) &&
|
||||
list_empty(&dev->link_attr))) {
|
||||
if (err)
|
||||
fprintf(stdout, "%s\n", err);
|
||||
else
|
||||
fprintf(stderr, "Interface '%s' not found\n", ifname);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (filter || interval >= 0) {
|
||||
if (filter)
|
||||
set_filter(dev, filter);
|
||||
if (interval >= 0)
|
||||
dev->interval = interval;
|
||||
|
||||
wprobe_apply_config(dev);
|
||||
}
|
||||
|
||||
if (cmd != CMD_CONFIG) {
|
||||
if (print_attributes)
|
||||
show_attributes(dev);
|
||||
}
|
||||
if (cmd == CMD_MEASURE)
|
||||
loop_measurement(dev, print_filters, delay);
|
||||
|
||||
wprobe_free_dev(dev);
|
||||
|
||||
return 0;
|
||||
}
|
213
net/wprobe/src/user/wprobe.h
Normal file
213
net/wprobe/src/user/wprobe.h
Normal file
@ -0,0 +1,213 @@
|
||||
/*
|
||||
* wprobe.h: Wireless probe user space library
|
||||
* Copyright (C) 2008-2009 Felix Fietkau <nbd@openwrt.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef __WPROBE_USER_H
|
||||
#define __WPROBE_USER_H
|
||||
#include <inttypes.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "list.h"
|
||||
|
||||
/**
|
||||
* struct wprobe_value: data structure for attribute values
|
||||
* @STRING: string value (currently unsupported)
|
||||
* @U8: unsigned 8-bit integer value
|
||||
* @U16: unsigned 16-bit integer value
|
||||
* @U32: unsigned 32-bit integer value
|
||||
* @U64: unsigned 64-bit integer value
|
||||
* @S8: signed 8-bit integer value
|
||||
* @S16: signed 16-bit integer value
|
||||
* @S32: signed 32-bit integer value
|
||||
* @S64: signed 64-bit integer value
|
||||
*
|
||||
* @n: number of sample values
|
||||
* @avg: average value
|
||||
* @stdev: standard deviation
|
||||
* @s: sum of all sample values (internal use)
|
||||
* @ss: sum of all sample values squared (internal use)
|
||||
*/
|
||||
struct wprobe_value {
|
||||
/* attribute value */
|
||||
union {
|
||||
const char *STRING;
|
||||
uint8_t U8;
|
||||
uint16_t U16;
|
||||
uint32_t U32;
|
||||
uint64_t U64;
|
||||
int8_t S8;
|
||||
int16_t S16;
|
||||
int32_t S32;
|
||||
int64_t S64;
|
||||
};
|
||||
/* statistics */
|
||||
int64_t s, ss;
|
||||
float avg, stdev;
|
||||
unsigned int n;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct wprobe_attribute: data structures for attribute descriptions
|
||||
* @list: linked list data structure for a list of attributes
|
||||
* @id: attribute id
|
||||
* @type: netlink type for the attribute (see kernel api documentation)
|
||||
* @flags: attribute flags (see kernel api documentation)
|
||||
* @val: cached version of the last netlink query, will be overwritten on each request
|
||||
* @name: attribute name
|
||||
*/
|
||||
struct wprobe_attribute {
|
||||
struct list_head list;
|
||||
int id;
|
||||
int type;
|
||||
uint32_t flags;
|
||||
struct wprobe_value val;
|
||||
char name[];
|
||||
};
|
||||
|
||||
/**
|
||||
* struct wprobe_link: data structure for the link description
|
||||
* @list: linked list data structure for a list of links
|
||||
* @flags: link flags (see kernel api documentation)
|
||||
* @addr: mac address of the remote link partner
|
||||
*/
|
||||
struct wprobe_link {
|
||||
struct list_head list;
|
||||
uint32_t flags;
|
||||
unsigned char addr[6];
|
||||
};
|
||||
|
||||
struct wprobe_filter_item {
|
||||
char name[32];
|
||||
uint64_t rx;
|
||||
uint64_t tx;
|
||||
};
|
||||
|
||||
struct wprobe_iface_ops;
|
||||
struct wprobe_iface {
|
||||
const struct wprobe_iface_ops *ops;
|
||||
|
||||
int sockfd;
|
||||
const char *ifname;
|
||||
unsigned int genl_family;
|
||||
char addr[6];
|
||||
|
||||
struct list_head global_attr;
|
||||
struct list_head link_attr;
|
||||
struct list_head links;
|
||||
|
||||
/* config */
|
||||
int interval;
|
||||
int scale_min;
|
||||
int scale_max;
|
||||
int scale_m;
|
||||
int scale_d;
|
||||
|
||||
/* filter */
|
||||
void *filter;
|
||||
|
||||
/* filter_len:
|
||||
* set to -1 to drop the current filter
|
||||
* automatically reset to 0 after config apply
|
||||
*/
|
||||
int filter_len;
|
||||
};
|
||||
|
||||
typedef void (*wprobe_filter_cb)(void *arg, const char *group, struct wprobe_filter_item *items, int n_items);
|
||||
extern int wprobe_port;
|
||||
|
||||
/**
|
||||
* wprobe_update_links: get a list of all link partners
|
||||
* @dev: wprobe device structure
|
||||
* @list: linked list for storing link descriptions
|
||||
*
|
||||
* when wprobe_update_links is called multiple times, the linked list
|
||||
* is updated with new link partners, old entries are automatically expired
|
||||
*/
|
||||
extern int wprobe_update_links(struct wprobe_iface *dev);
|
||||
|
||||
/**
|
||||
* wprobe_dump_filters: dump all layer 2 filter counters
|
||||
* @dev: wprobe device structure
|
||||
* @cb: callback (called once per filter group)
|
||||
* @arg: user argument for the callback
|
||||
*/
|
||||
extern int wprobe_dump_filters(struct wprobe_iface *dev, wprobe_filter_cb cb, void *arg);
|
||||
|
||||
/**
|
||||
* wprobe_measure: start a measurement request for all global attributes
|
||||
* @dev: wprobe device structure
|
||||
*
|
||||
* not all attributes are automatically filled with data, since for some
|
||||
* it may be desirable to control the sampling interval from user space
|
||||
* you can use this function to do that.
|
||||
*/
|
||||
extern int wprobe_measure(struct wprobe_iface *dev);
|
||||
|
||||
/**
|
||||
* wprobe_get_dev: get a handle to a local wprobe device
|
||||
* @ifname: name of the wprobe interface
|
||||
*
|
||||
* queries the wprobe interface for all attributes
|
||||
* must be freed with wprobe_free_dev
|
||||
*/
|
||||
extern struct wprobe_iface *wprobe_get_dev(const char *ifname);
|
||||
|
||||
/**
|
||||
* wprobe_get_auto: get a handle to a local or remote wprobe device
|
||||
* @arg: pointer to the wprobe device, either <dev> (local) or <host>:<dev> (remote)
|
||||
*/
|
||||
extern struct wprobe_iface *wprobe_get_auto(const char *arg, char **err);
|
||||
|
||||
/**
|
||||
* wprobe_get_dev: free all device information
|
||||
* @dev: wprobe device structure
|
||||
*/
|
||||
extern void wprobe_free_dev(struct wprobe_iface *dev);
|
||||
|
||||
/**
|
||||
* wprobe_apply_config: apply configuration data
|
||||
* @dev: wprobe device structure
|
||||
*
|
||||
* uploads all configuration values from @dev that are not set to -1
|
||||
*/
|
||||
extern int wprobe_apply_config(struct wprobe_iface *dev);
|
||||
|
||||
/**
|
||||
* wprobe_request_data: request new sampling values for the given list of attributes
|
||||
* @dev: wprobe device structure
|
||||
* @addr: (optional) mac address of the link partner
|
||||
*
|
||||
* if addr is unset, global values are stored in the global attributes list
|
||||
* if addr is set, per-link values for the given address are stored in the link attributes list
|
||||
*/
|
||||
extern int wprobe_request_data(struct wprobe_iface *dev, const unsigned char *addr);
|
||||
|
||||
/**
|
||||
* wprobe_server_init: send a wprobe server init message to a server's client socket
|
||||
* @socket: socket of the connection to the client
|
||||
*/
|
||||
extern int wprobe_server_init(int socket);
|
||||
|
||||
/**
|
||||
* wprobe_server_handle: read a request from the client socket, process it, send the response
|
||||
* @socket: socket of the connection to the client
|
||||
*/
|
||||
extern int wprobe_server_handle(int socket);
|
||||
|
||||
/**
|
||||
* wprobe_server_done: release memory allocated for the server connection
|
||||
*/
|
||||
extern void wprobe_server_done(void);
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user