netlink: add basic decoding of NETLINK_ROUTE rtgenmsg attributes

* rtnl_nsid.c: Include "nlattr.h" and "xlat/rtnl_nsid_attrs.h".
(decode_rtgenmsg): Call decode_nlattr.
* xlat/rtnl_nsid_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:22 +08:00 committed by Dmitry V. Levin
parent 4c1e85025f
commit b9afb63fd7
2 changed files with 15 additions and 0 deletions

View File

@ -29,15 +29,25 @@
#include "defs.h"
#include "netlink_route.h"
#include "nlattr.h"
#include "print_fields.h"
#include "netlink.h"
#include <linux/rtnetlink.h>
#include "xlat/rtnl_nsid_attrs.h"
DECL_NETLINK_ROUTE_DECODER(decode_rtgenmsg)
{
struct rtgenmsg rtgenmsg = { .rtgen_family = family };
PRINT_FIELD_XVAL("{", rtgenmsg, rtgen_family, addrfams, "AF_???");
tprints("}");
const size_t offset = NLMSG_ALIGN(sizeof(rtgenmsg));
if (len > offset) {
tprints(", ");
decode_nlattr(tcp, addr + offset, len - offset,
rtnl_nsid_attrs, "NETNSA_???", NULL, 0, NULL);
}
}

5
xlat/rtnl_nsid_attrs.in Normal file
View File

@ -0,0 +1,5 @@
NETNSA_NSID_NOT_ASSIGNED -1
NETNSA_NONE 0
NETNSA_NSID 1
NETNSA_PID 2
NETNSA_FD 3