From eede641dd2ce43b1490730ae02cb74859a495e78 Mon Sep 17 00:00:00 2001 From: JingPiao Chen Date: Tue, 15 Aug 2017 12:41:14 +0800 Subject: [PATCH] netlink: add basic decoding of NETLINK_ROUTE ndmsg attributes * rtnl_neigh.c: Include "nlattr.h" and "xlat/rtnl_neigh_attrs.h". (decode_ndmsg): Call decode_nlattr. * xlat/rtnl_neigh_attrs.in: New file. Co-authored-by: Fabien Siron --- rtnl_neigh.c | 13 ++++++++++++- xlat/rtnl_neigh_attrs.in | 12 ++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 xlat/rtnl_neigh_attrs.in diff --git a/rtnl_neigh.c b/rtnl_neigh.c index c10fc979..2ce237a6 100644 --- a/rtnl_neigh.c +++ b/rtnl_neigh.c @@ -29,6 +29,7 @@ #include "defs.h" #include "netlink_route.h" +#include "nlattr.h" #include "print_fields.h" #include "netlink.h" @@ -40,11 +41,13 @@ #include "xlat/nda_types.h" #include "xlat/neighbor_cache_entry_flags.h" #include "xlat/neighbor_cache_entry_states.h" +#include "xlat/rtnl_neigh_attrs.h" DECL_NETLINK_ROUTE_DECODER(decode_ndmsg) { struct ndmsg ndmsg = { .ndm_family = family }; - const size_t offset = sizeof(ndmsg.ndm_family); + size_t offset = sizeof(ndmsg.ndm_family); + bool decode_nla = false; PRINT_FIELD_XVAL("{", ndmsg, ndm_family, addrfams, "AF_???"); @@ -62,10 +65,18 @@ DECL_NETLINK_ROUTE_DECODER(decode_ndmsg) "NTF_???"); PRINT_FIELD_XVAL(", ", ndmsg, ndm_type, nda_types, "NDA_???"); + decode_nla = true; } } else tprints("..."); tprints("}"); + + offset = NLMSG_ALIGN(sizeof(ndmsg)); + if (decode_nla && len > offset) { + tprints(", "); + decode_nlattr(tcp, addr + offset, len - offset, + rtnl_neigh_attrs, "NDA_???", NULL, 0, NULL); + } } DECL_NETLINK_ROUTE_DECODER(decode_rtm_getneigh) diff --git a/xlat/rtnl_neigh_attrs.in b/xlat/rtnl_neigh_attrs.in new file mode 100644 index 00000000..fed013a1 --- /dev/null +++ b/xlat/rtnl_neigh_attrs.in @@ -0,0 +1,12 @@ +NDA_UNSPEC 0 +NDA_DST 1 +NDA_LLADDR 2 +NDA_CACHEINFO 3 +NDA_PROBES 4 +NDA_VLAN 5 +NDA_PORT 6 +NDA_VNI 7 +NDA_IFINDEX 8 +NDA_MASTER 9 +NDA_LINK_NETNSID 10 +NDA_SRC_VNI 11