netlink_route: implement RTM_NEWSTATS, RTM_GETSTATS message decoding
* xlat/ifstats_attr.in: New file. * xlat/ifstats_attr_mask.in: Likewise. * xlat/ifstats_offload_attr.in: Likewise. * xlat/ifstats_xstats_type_attr.in: Likewise. * xlat/nl_bridge_vlan_flags.in: Likewise. * rtnl_stats.c: Likewise. * Makefile.am (strace_SOURCES): Add it. * configure.ac: Add struct if_stats_msg type check. * netlink_route.c (route_decoders) <[RTM_NEWSTATS - RTM_BASE], [RTM_GETSTATS - RTM_BASE]>: New decoder, call decode_ifstatsmsg. * netlink_route.h (decode_ifstatsmsg): New declaration. * nlattr.h (DECL_NLA(ifla_af_spec), DECL_NLA(rtnl_link_stats64)): New declaration. * rtnl_link.c (decode_nla_rtnl_link_stats64): Rename from decode_rtnl_link_stats64. (decode_nla_ifla_af_spec): Rename from decode_ifla_af_spec. (ifinfomsg_nla_decoders) <[IFLA_STATS64], [IFLA_AF_SPEC]>: Use new decoder function names.
This commit is contained in:
parent
1d7b8edda9
commit
d5f960204c
@ -289,6 +289,7 @@ strace_SOURCES = \
|
||||
rtnl_nsid.c \
|
||||
rtnl_route.c \
|
||||
rtnl_rule.c \
|
||||
rtnl_stats.c \
|
||||
rtnl_tc.c \
|
||||
rtnl_tc_action.c \
|
||||
s390.c \
|
||||
|
@ -494,6 +494,7 @@ AC_CHECK_MEMBERS(m4_normalize([
|
||||
|
||||
AC_CHECK_TYPES([struct dcbmsg],,, [#include <linux/dcbnl.h>])
|
||||
AC_CHECK_TYPES([struct ifaddrlblmsg],,, [#include <linux/if_addrlabel.h>])
|
||||
AC_CHECK_TYPES([struct if_stats_msg],,, [#include <linux/if_link.h>])
|
||||
AC_CHECK_TYPES([struct netconfmsg],,, [#include <linux/netconf.h>])
|
||||
|
||||
AC_CHECK_TYPES(m4_normalize([
|
||||
|
@ -118,7 +118,10 @@ static const netlink_route_decoder_t route_decoders[] = {
|
||||
|
||||
[RTM_DELNSID - RTM_BASE] = decode_rtgenmsg,
|
||||
[RTM_GETNSID - RTM_BASE] = decode_rtgenmsg,
|
||||
[RTM_NEWNSID - RTM_BASE] = decode_rtgenmsg
|
||||
[RTM_NEWNSID - RTM_BASE] = decode_rtgenmsg,
|
||||
|
||||
[RTM_NEWSTATS - RTM_BASE] = decode_ifstatsmsg,
|
||||
[RTM_GETSTATS - RTM_BASE] = decode_ifstatsmsg,
|
||||
};
|
||||
|
||||
bool
|
||||
|
@ -45,6 +45,7 @@ extern DECL_NETLINK_ROUTE_DECODER(decode_fib_rule_hdr);
|
||||
extern DECL_NETLINK_ROUTE_DECODER(decode_ifaddrlblmsg);
|
||||
extern DECL_NETLINK_ROUTE_DECODER(decode_ifaddrmsg);
|
||||
extern DECL_NETLINK_ROUTE_DECODER(decode_ifinfomsg);
|
||||
extern DECL_NETLINK_ROUTE_DECODER(decode_ifstatsmsg);
|
||||
extern DECL_NETLINK_ROUTE_DECODER(decode_ndmsg);
|
||||
extern DECL_NETLINK_ROUTE_DECODER(decode_ndtmsg);
|
||||
extern DECL_NETLINK_ROUTE_DECODER(decode_netconfmsg);
|
||||
|
2
nlattr.h
2
nlattr.h
@ -100,11 +100,13 @@ DECL_NLA(fd);
|
||||
DECL_NLA(uid);
|
||||
DECL_NLA(gid);
|
||||
DECL_NLA(ifindex);
|
||||
DECL_NLA(ifla_af_spec);
|
||||
DECL_NLA(ether_proto);
|
||||
DECL_NLA(ip_proto);
|
||||
DECL_NLA(meminfo);
|
||||
DECL_NLA(rt_class);
|
||||
DECL_NLA(rt_proto);
|
||||
DECL_NLA(rtnl_link_stats64);
|
||||
DECL_NLA(tc_stats);
|
||||
|
||||
#endif /* !STRACE_NLATTR_H */
|
||||
|
12
rtnl_link.c
12
rtnl_link.c
@ -437,8 +437,8 @@ decode_ifla_linkinfo(struct tcb *const tcp,
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
decode_rtnl_link_stats64(struct tcb *const tcp,
|
||||
bool
|
||||
decode_nla_rtnl_link_stats64(struct tcb *const tcp,
|
||||
const kernel_ulong_t addr,
|
||||
const unsigned int len,
|
||||
const void *const opaque_data)
|
||||
@ -839,8 +839,8 @@ decode_ifla_af(struct tcb *const tcp,
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
decode_ifla_af_spec(struct tcb *const tcp,
|
||||
bool
|
||||
decode_nla_ifla_af_spec(struct tcb *const tcp,
|
||||
const kernel_ulong_t addr,
|
||||
const unsigned int len,
|
||||
const void *const opaque_data)
|
||||
@ -876,10 +876,10 @@ static const nla_decoder_t ifinfomsg_nla_decoders[] = {
|
||||
[IFLA_IFALIAS] = decode_nla_str,
|
||||
[IFLA_NUM_VF] = decode_nla_u32,
|
||||
[IFLA_VFINFO_LIST] = NULL, /* unimplemented */
|
||||
[IFLA_STATS64] = decode_rtnl_link_stats64,
|
||||
[IFLA_STATS64] = decode_nla_rtnl_link_stats64,
|
||||
[IFLA_VF_PORTS] = decode_ifla_vf_ports,
|
||||
[IFLA_PORT_SELF] = decode_ifla_port,
|
||||
[IFLA_AF_SPEC] = decode_ifla_af_spec,
|
||||
[IFLA_AF_SPEC] = decode_nla_ifla_af_spec,
|
||||
[IFLA_GROUP] = decode_nla_u32,
|
||||
[IFLA_NET_NS_FD] = decode_nla_fd,
|
||||
[IFLA_EXT_MASK] = decode_nla_u32,
|
||||
|
173
rtnl_stats.c
Normal file
173
rtnl_stats.c
Normal file
@ -0,0 +1,173 @@
|
||||
/*
|
||||
* Copyright (c) 2018 The strace developers.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "defs.h"
|
||||
#include "netlink_route.h"
|
||||
#include "nlattr.h"
|
||||
#include "print_fields.h"
|
||||
|
||||
#include "netlink.h"
|
||||
|
||||
#include <netinet/in.h>
|
||||
|
||||
#ifdef HAVE_LINUX_IF_LINK_H
|
||||
# include <linux/if_link.h>
|
||||
#endif
|
||||
#include <linux/rtnetlink.h>
|
||||
|
||||
#include "xlat/ifstats_attr_mask.h"
|
||||
#include "xlat/ifstats_attr.h"
|
||||
#include "xlat/ifstats_offload_attr.h"
|
||||
#include "xlat/ifstats_xstats_type_attr.h"
|
||||
#include "xlat/nl_bridge_vlan_flags.h"
|
||||
|
||||
#ifndef HAVE_STRUCT_IF_STATS_MSG
|
||||
struct if_stats_msg {
|
||||
uint8_t family;
|
||||
uint8_t pad1;
|
||||
uint16_t pad2;
|
||||
uint32_t ifindex;
|
||||
uint32_t filter_mask;
|
||||
};
|
||||
#endif
|
||||
|
||||
static bool
|
||||
decode_nla_xstats_bridge(struct tcb *const tcp,
|
||||
const kernel_ulong_t addr,
|
||||
const unsigned int len,
|
||||
const void *const opaque_data)
|
||||
{
|
||||
struct strace_bridge_vlan_xstats {
|
||||
uint64_t rx_bytes;
|
||||
uint64_t rx_packets;
|
||||
uint64_t tx_bytes;
|
||||
uint64_t tx_packets;
|
||||
uint16_t vid;
|
||||
uint16_t flags;
|
||||
uint32_t pad2;
|
||||
} st;
|
||||
|
||||
if (len < sizeof(struct strace_bridge_vlan_xstats))
|
||||
return false;
|
||||
|
||||
if (umove_or_printaddr(tcp, addr, &st))
|
||||
return true;
|
||||
|
||||
PRINT_FIELD_U("{", st, rx_bytes);
|
||||
PRINT_FIELD_U(", ", st, rx_packets);
|
||||
PRINT_FIELD_U(", ", st, tx_bytes);
|
||||
PRINT_FIELD_U(", ", st, tx_packets);
|
||||
PRINT_FIELD_U(", ", st, vid);
|
||||
PRINT_FIELD_FLAGS(", ", st, flags, nl_bridge_vlan_flags,
|
||||
"BRIDGE_VLAN_INFO_???");
|
||||
tprints("}");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static const nla_decoder_t ifstats_xstats_decoders[] = {
|
||||
[LINK_XSTATS_TYPE_UNSPEC] = NULL,
|
||||
[LINK_XSTATS_TYPE_BRIDGE] = decode_nla_xstats_bridge,
|
||||
};
|
||||
|
||||
static bool
|
||||
decode_nla_link_xstats(struct tcb *const tcp,
|
||||
const kernel_ulong_t addr,
|
||||
const unsigned int len,
|
||||
const void *const opaque_data)
|
||||
{
|
||||
decode_nlattr(tcp, addr, len, ifstats_xstats_type_attr,
|
||||
"LINK_XSTATS_TYPE_???",
|
||||
ARRSZ_PAIR(ifstats_xstats_decoders),
|
||||
opaque_data);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static const nla_decoder_t ifstats_offload_xstats_decoders[] = {
|
||||
[LINK_XSTATS_TYPE_UNSPEC] = NULL,
|
||||
[LINK_XSTATS_TYPE_BRIDGE] = decode_nla_rtnl_link_stats64,
|
||||
};
|
||||
|
||||
static bool
|
||||
decode_nla_link_offload_xstats(struct tcb *const tcp,
|
||||
const kernel_ulong_t addr,
|
||||
const unsigned int len,
|
||||
const void *const opaque_data)
|
||||
{
|
||||
decode_nlattr(tcp, addr, len, ifstats_offload_attr,
|
||||
"IFLA_OFFLOAD_XSTATS_???",
|
||||
ARRSZ_PAIR(ifstats_offload_xstats_decoders),
|
||||
opaque_data);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static const nla_decoder_t ifstatsmsg_nla_decoders[] = {
|
||||
[IFLA_STATS_UNSPEC] = NULL,
|
||||
[IFLA_STATS_LINK_64] = decode_nla_rtnl_link_stats64,
|
||||
[IFLA_STATS_LINK_XSTATS] = decode_nla_link_xstats,
|
||||
[IFLA_STATS_LINK_XSTATS_SLAVE] = decode_nla_link_xstats,
|
||||
[IFLA_STATS_LINK_OFFLOAD_XSTATS] = decode_nla_link_offload_xstats,
|
||||
[IFLA_STATS_AF_SPEC] = decode_nla_ifla_af_spec,
|
||||
};
|
||||
|
||||
DECL_NETLINK_ROUTE_DECODER(decode_ifstatsmsg)
|
||||
{
|
||||
struct if_stats_msg ifstats = { .family = family };
|
||||
size_t offset = sizeof(ifstats.family);
|
||||
bool decode_nla = false;
|
||||
|
||||
PRINT_FIELD_XVAL("{", ifstats, family, addrfams, "AF_???");
|
||||
|
||||
tprints(", ");
|
||||
if (len >= sizeof(ifstats)) {
|
||||
if (!umoven_or_printaddr(tcp, addr + offset,
|
||||
sizeof(ifstats) - offset,
|
||||
(char *) &ifstats + offset)) {
|
||||
if (ifstats.pad1)
|
||||
PRINT_FIELD_X("", ifstats, pad1);
|
||||
if (ifstats.pad2)
|
||||
PRINT_FIELD_X("", ifstats, pad2);
|
||||
PRINT_FIELD_IFINDEX(", ", ifstats, ifindex);
|
||||
PRINT_FIELD_FLAGS(", ", ifstats, filter_mask,
|
||||
ifstats_attr_mask ,
|
||||
"IFLA_STATS_???");
|
||||
decode_nla = true;
|
||||
}
|
||||
} else
|
||||
tprints("...");
|
||||
tprints("}");
|
||||
|
||||
offset = NLMSG_ALIGN(sizeof(ifstats));
|
||||
if (decode_nla && len > offset) {
|
||||
tprints(", ");
|
||||
decode_nlattr(tcp, addr + offset, len - offset,
|
||||
ifstats_attr, "IFLA_STATS_???",
|
||||
ARRSZ_PAIR(ifstatsmsg_nla_decoders), NULL);
|
||||
}
|
||||
}
|
6
xlat/ifstats_attr.in
Normal file
6
xlat/ifstats_attr.in
Normal file
@ -0,0 +1,6 @@
|
||||
IFLA_STATS_UNSPEC 0
|
||||
IFLA_STATS_LINK_64 1
|
||||
IFLA_STATS_LINK_XSTATS 2
|
||||
IFLA_STATS_LINK_XSTATS_SLAVE 3
|
||||
IFLA_STATS_LINK_OFFLOAD_XSTATS 4
|
||||
IFLA_STATS_AF_SPEC 5
|
6
xlat/ifstats_attr_mask.in
Normal file
6
xlat/ifstats_attr_mask.in
Normal file
@ -0,0 +1,6 @@
|
||||
1<<IFLA_STATS_UNSPEC
|
||||
1<<IFLA_STATS_LINK_64
|
||||
1<<IFLA_STATS_LINK_XSTATS
|
||||
1<<IFLA_STATS_LINK_XSTATS_SLAVE
|
||||
1<<IFLA_STATS_LINK_OFFLOAD_XSTATS
|
||||
1<<IFLA_STATS_AF_SPEC
|
2
xlat/ifstats_offload_attr.in
Normal file
2
xlat/ifstats_offload_attr.in
Normal file
@ -0,0 +1,2 @@
|
||||
IFLA_OFFLOAD_XSTATS_UNSPEC 0
|
||||
IFLA_OFFLOAD_XSTATS_CPU_HIT 1
|
2
xlat/ifstats_xstats_type_attr.in
Normal file
2
xlat/ifstats_xstats_type_attr.in
Normal file
@ -0,0 +1,2 @@
|
||||
LINK_XSTATS_TYPE_UNSPEC 0
|
||||
LINK_XSTATS_TYPE_BRIDGE 1
|
6
xlat/nl_bridge_vlan_flags.in
Normal file
6
xlat/nl_bridge_vlan_flags.in
Normal file
@ -0,0 +1,6 @@
|
||||
BRIDGE_VLAN_INFO_MASTER (1<<0)
|
||||
BRIDGE_VLAN_INFO_PVID (1<<1)
|
||||
BRIDGE_VLAN_INFO_UNTAGGED (1<<2)
|
||||
BRIDGE_VLAN_INFO_RANGE_BEGIN (1<<3)
|
||||
BRIDGE_VLAN_INFO_RANGE_END (1<<4)
|
||||
BRIDGE_VLAN_INFO_BRENTRY (1<<5)
|
Loading…
x
Reference in New Issue
Block a user