netlink: add basic decoding of NETLINK_ROUTE ifinfomsg attributes

* rtnl_link.c: Include "nlattr.h" and "xlat/rtnl_link_attrs.h".
(decode_ifinfomsg): Call decode_nlattr.
* xlat/rtnl_link_attrs.in: New file.

Co-authored-by: Fabien Siron <fabien.siron@epita.fr>
This commit is contained in:
JingPiao Chen 2017-08-15 12:41:10 +08:00 committed by Dmitry V. Levin
parent a10961a9e1
commit d15343ad2c
2 changed files with 58 additions and 1 deletions

View File

@ -29,15 +29,19 @@
#include "defs.h"
#include "netlink_route.h"
#include "nlattr.h"
#include "print_fields.h"
#include "netlink.h"
#include <linux/rtnetlink.h>
#include "xlat/rtnl_link_attrs.h"
DECL_NETLINK_ROUTE_DECODER(decode_ifinfomsg)
{
struct ifinfomsg ifinfo = { .ifi_family = family };
const size_t offset = sizeof(ifinfo.ifi_family);
size_t offset = sizeof(ifinfo.ifi_family);
bool decode_nla = false;
PRINT_FIELD_XVAL("{", ifinfo, ifi_family, addrfams, "AF_???");
@ -52,8 +56,16 @@ DECL_NETLINK_ROUTE_DECODER(decode_ifinfomsg)
PRINT_FIELD_FLAGS(", ", ifinfo, ifi_flags,
iffflags, "IFF_???");
PRINT_FIELD_X(", ", ifinfo, ifi_change);
decode_nla = true;
}
} else
tprints("...");
tprints("}");
offset = NLMSG_ALIGN(sizeof(ifinfo));
if (decode_nla && len > offset) {
tprints(", ");
decode_nlattr(tcp, addr + offset, len - offset,
rtnl_link_attrs, "IFLA_???", NULL, 0, NULL);
}
}

45
xlat/rtnl_link_attrs.in Normal file
View File

@ -0,0 +1,45 @@
IFLA_UNSPEC 0
IFLA_ADDRESS 1
IFLA_BROADCAST 2
IFLA_IFNAME 3
IFLA_MTU 4
IFLA_LINK 5
IFLA_QDISC 6
IFLA_STATS 7
IFLA_COST 8
IFLA_PRIORITY 9
IFLA_MASTER 10
IFLA_WIRELESS 11
IFLA_PROTINFO 12
IFLA_TXQLEN 13
IFLA_MAP 14
IFLA_WEIGHT 15
IFLA_OPERSTATE 16
IFLA_LINKMODE 17
IFLA_LINKINFO 18
IFLA_NET_NS_PID 19
IFLA_IFALIAS 20
IFLA_NUM_VF 21
IFLA_VFINFO_LIST 22
IFLA_STATS64 23
IFLA_VF_PORTS 24
IFLA_PORT_SELF 25
IFLA_AF_SPEC 26
IFLA_GROUP 27
IFLA_NET_NS_FD 28
IFLA_EXT_MASK 29
IFLA_PROMISCUITY 30
IFLA_NUM_TX_QUEUES 31
IFLA_NUM_RX_QUEUES 32
IFLA_CARRIER 33
IFLA_PHYS_PORT_ID 34
IFLA_CARRIER_CHANGES 35
IFLA_PHYS_SWITCH_ID 36
IFLA_LINK_NETNSID 37
IFLA_PHYS_PORT_NAME 38
IFLA_PROTO_DOWN 39
IFLA_GSO_MAX_SEGS 40
IFLA_GSO_MAX_SIZE 41
IFLA_PAD 42
IFLA_XDP 43
IFLA_EVENT 44