From 52a55f2081763435fa44b8795aceebea35409d1d Mon Sep 17 00:00:00 2001 From: JingPiao Chen Date: Tue, 15 Aug 2017 12:41:18 +0800 Subject: [PATCH] netlink: add basic decoding of NETLINK_ROUTE ifaddrlblmsg attributes * rtnl_addrlabel.c: Include "netlink.h", "nlattr.h", and "xlat/rtnl_addrlabel_attrs.h". (decode_ifaddrlblmsg): Call decode_nlattr. * xlat/rtnl_addrlabel_attrs.in: New file. Co-authored-by: Fabien Siron --- rtnl_addrlabel.c | 15 ++++++++++++++- xlat/rtnl_addrlabel_attrs.in | 2 ++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 xlat/rtnl_addrlabel_attrs.in diff --git a/rtnl_addrlabel.c b/rtnl_addrlabel.c index 42dc65e2..53cfb2c7 100644 --- a/rtnl_addrlabel.c +++ b/rtnl_addrlabel.c @@ -32,14 +32,19 @@ #ifdef HAVE_STRUCT_IFADDRLBLMSG # include "netlink_route.h" +# include "nlattr.h" # include "print_fields.h" # include +# include "netlink.h" + +# include "xlat/rtnl_addrlabel_attrs.h" DECL_NETLINK_ROUTE_DECODER(decode_ifaddrlblmsg) { struct ifaddrlblmsg ifal = { .ifal_family = family }; - const size_t offset = sizeof(ifal.ifal_family); + size_t offset = sizeof(ifal.ifal_family); + bool decode_nla = false; PRINT_FIELD_XVAL("{", ifal, ifal_family, addrfams, "AF_???"); @@ -52,10 +57,18 @@ DECL_NETLINK_ROUTE_DECODER(decode_ifaddrlblmsg) PRINT_FIELD_U(", ", ifal, ifal_flags); PRINT_FIELD_IFINDEX(", ", ifal, ifal_index); PRINT_FIELD_U(", ", ifal, ifal_seq); + decode_nla = true; } } else tprints("..."); tprints("}"); + + offset = NLMSG_ALIGN(sizeof(ifal)); + if (decode_nla && len > offset) { + tprints(", "); + decode_nlattr(tcp, addr + offset, len - offset, + rtnl_addrlabel_attrs, "IFAL_???", NULL, 0, NULL); + } } #endif diff --git a/xlat/rtnl_addrlabel_attrs.in b/xlat/rtnl_addrlabel_attrs.in new file mode 100644 index 00000000..0dc464d6 --- /dev/null +++ b/xlat/rtnl_addrlabel_attrs.in @@ -0,0 +1,2 @@ +IFAL_ADDRESS 1 +IFAL_LABEL 2