netlink: add basic decoding of NETLINK_ROUTE ifaddrmsg attributes

* rtnl_addr.c: Include "nlattr.h" and "xlat/rtnl_addr_attrs.h".
(decode_ifaddrmsg): Call decode_nlattr.
* xlat/rtnl_addr_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:11 +08:00 committed by Dmitry V. Levin
parent cbe8ddd2db
commit 7e15bde453
2 changed files with 21 additions and 1 deletions

View File

@ -29,6 +29,7 @@
#include "defs.h"
#include "netlink_route.h"
#include "nlattr.h"
#include "print_fields.h"
#include "netlink.h"
@ -39,11 +40,13 @@
#include "xlat/ifaddrflags.h"
#include "xlat/routing_scopes.h"
#include "xlat/rtnl_addr_attrs.h"
DECL_NETLINK_ROUTE_DECODER(decode_ifaddrmsg)
{
struct ifaddrmsg ifaddr = { .ifa_family = family };
const size_t offset = sizeof(ifaddr.ifa_family);
size_t offset = sizeof(ifaddr.ifa_family);
bool decode_nla = false;
PRINT_FIELD_XVAL("{", ifaddr, ifa_family, addrfams, "AF_???");
@ -58,8 +61,16 @@ DECL_NETLINK_ROUTE_DECODER(decode_ifaddrmsg)
PRINT_FIELD_XVAL(", ", ifaddr, ifa_scope,
routing_scopes, NULL);
PRINT_FIELD_IFINDEX(", ", ifaddr, ifa_index);
decode_nla = true;
}
} else
tprints("...");
tprints("}");
offset = NLMSG_ALIGN(sizeof(ifaddr));
if (decode_nla && len > offset) {
tprints(", ");
decode_nlattr(tcp, addr + offset, len - offset,
rtnl_addr_attrs, "IFA_???", NULL, 0, NULL);
}
}

9
xlat/rtnl_addr_attrs.in Normal file
View File

@ -0,0 +1,9 @@
IFA_UNSPEC 0
IFA_ADDRESS 1
IFA_LOCAL 2
IFA_LABEL 3
IFA_BROADCAST 4
IFA_ANYCAST 5
IFA_CACHEINFO 6
IFA_MULTICAST 7
IFA_FLAGS 8