/*
* in_netlink.c Netlink input
*
* Copyright (c) 2001-2013 Thomas Graf <tgraf@suug.ch>
* Copyright (c) 2013 Red Hat, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include <bmon/bmon.h>
#include <bmon/input.h>
#include <bmon/element.h>
#include <bmon/attr.h>
#include <bmon/conf.h>
#include <bmon/input.h>
#include <bmon/utils.h>
#ifndef SYS_BSD
static int c_notc = 0;
static struct element_group *grp;
static struct bmon_module netlink_ops;
#include <linux/if.h>
#include <netlink/netlink.h>
#include <netlink/cache.h>
#include <netlink/utils.h>
#include <netlink/route/link.h>
#include <netlink/route/tc.h>
#include <netlink/route/qdisc.h>
#include <netlink/route/class.h>
#include <netlink/route/classifier.h>
#include <netlink/route/qdisc/htb.h>
/* These counters are not available prior to libnl 3.2.25. Set them to -1 so
* rtnl_link_get_stat() won't be called for them. */
#if LIBNL_CURRENT < 220
# define RTNL_LINK_ICMP6_CSUMERRORS -1
# define RTNL_LINK_IP6_CSUMERRORS -1
# define RTNL_LINK_IP6_NOECTPKTS -1
# define RTNL_LINK_IP6_ECT1PKTS -1
# define RTNL_LINK_IP6_ECT0PKTS -1
# define RTNL_LINK_IP6_CEPKTS -1
#endif
static struct attr_map link_attrs[] = {
{
.name = "bytes",
.type = ATTR_TYPE_COUNTER,
.unit = UNIT_BYTE,
.description = "Bytes",
.rxid = RTNL_LINK_RX_BYTES,
.txid = RTNL_LINK_TX_BYTES,
},
{
.name = "packets",
.type = ATTR_TYPE_COUNTER,
.unit = UNIT_NUMBER,
.description = "Packets",
.rxid = RTNL_LINK_RX_PACKETS,
.txid = RTNL_LINK_TX_PACKETS,
},
{
.name = "errors",
.type = ATTR_TYPE_COUNTER,
.unit = UNIT_NUMBER,
.description = "Errors",
.rxid = RTNL_LINK_RX_ERRORS,
.txid = RTNL_LINK_TX_ERRORS,
},
{
.name = "drop",
.type = ATTR_TYPE_COUNTER,
.unit = UNIT_NUMBER,
.description = "Dropped",
.rxid = RTNL_LINK_RX_DROPPED,
.txid = RTNL_LINK_TX_DROPPED,
},
{
.name = "compressed",
.type = ATTR_TYPE_COUNTER,
.unit = UNIT_NUMBER,
.description = "Compressed",
.rxid = RTNL_LINK_RX_COMPRESSED,
.txid = RTNL_LINK_TX_COMPRESSED,
},
{
.name = "fifoerr",
.type = ATTR_TYPE_COUNTER,
.unit = UNIT_NUMBER,
.description = "FIFO Error",
.rxid = RTNL_LINK_RX_FIFO_ERR,
.txid = RTNL_LINK_TX_FIFO_ERR,
},
{
.name = "lenerr",
.type = ATTR_TYPE_COUNTER,
.unit = UNIT_NUMBER,
.description = "Length Error",
.rxid = RTNL_LINK_RX_LEN_ERR,
.txid = -1,
},
{
.name = "overerr",
.type = ATTR_TYPE_COUNTER,
.unit = UNIT_NUMBER,
.description = "Over Error",
.rxid = RTNL_LINK_RX_OVER_ERR,
.txid = -1,
},
{
.name = "crcerr",
.type = ATTR_TYPE_COUNTER,
.unit = UNIT_NUMBER,
.description = "CRC Error",
.rxid = RTNL_LINK_RX_CRC_ERR,
.txid = -1,
},
{
.name = "frameerr",
.type = ATTR_TYPE_COUNTER,
.unit = UNIT_NUMBER,
.description = "Frame Error",
.rxid = RTNL_LINK_RX_FRAME_ERR,
.txid = -1,
},
{
.name = "misserr",
.type = ATTR_TYPE_COUNTER,
.unit = UNIT_NUMBER,
.description = "Missed Error",
.rxid = RTNL_LINK_RX_MISSED_ERR,
.txid = -1,
},
{
.name = "aborterr",
.type = ATTR_TYPE_COUNTER,
.unit = UNIT_NUMBER,
.description = "Abort Error",
.rxid = -1,
.txid = RTNL_LINK_TX_ABORT_ERR,
},
{
.name = "carrerr",
.type = ATTR_TYPE_COUNTER,
.unit = UNIT_NUMBER,
.description = "Carrier Error",
.rxid = -1,
.txid = RTNL_LINK_TX_CARRIER_ERR,
},
{
.name = "hbeaterr",
.type = ATTR_TYPE_COUNTER,
.unit = UNIT_NUMBER,
.description = "Heartbeat Error",
.rxid = -1,
.txid = RTNL_LINK_TX_HBEAT_ERR,
},
{
.name = "winerr",
.type = ATTR_TYPE_COUNTER,
.unit =