summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJingPiao Chen <chenjingpiao@gmail.com>2017-08-28 00:46:22 +0800
committerJingPiao Chen <chenjingpiao@gmail.com>2017-08-29 15:23:36 +0800
commit19abd528fbba0a64764e647b7bcd57408259b6f5 (patch)
tree97e1f877b02bb1f43e53c739f91ccf9eb7516cce
parent65ad4f2cce08b32918832214101bc606910db011 (diff)
downloadstrace-19abd528fbba0a64764e647b7bcd57408259b6f5.tar.gz
rtnl_neigh: decode ndmsg netlink attributes
* nlattr.c: Include <netinet/in.h> and <arpa/inet.h>. (decode_nla_be16): New function. * nlattr.h (decode_nla_be16): New prototype. * rtnl_neigh.c (decode_neigh_addr, decode_nda_cacheinfo): New functions. (ndmsg_nla_decoders): New array. (decode_ndmsg): Use it.
-rw-r--r--nlattr.c18
-rw-r--r--nlattr.h1
-rw-r--r--rtnl_neigh.c52
3 files changed, 70 insertions, 1 deletions
diff --git a/nlattr.c b/nlattr.c
index 847fa3935..6f35b9944 100644
--- a/nlattr.c
+++ b/nlattr.c
@@ -31,6 +31,8 @@
#include <endian.h>
#include "netlink.h"
#include "nlattr.h"
+#include <netinet/in.h>
+#include <arpa/inet.h>
#include <linux/sock_diag.h>
static bool
@@ -222,6 +224,22 @@ decode_nla_ifindex(struct tcb *const tcp,
}
bool
+decode_nla_be16(struct tcb *const tcp,
+ const kernel_ulong_t addr,
+ const unsigned int len,
+ const void *const opaque_data)
+{
+ uint16_t num;
+
+ if (len < sizeof(num))
+ return false;
+ else if (!umove_or_printaddr(tcp, addr, &num))
+ tprintf("htons(%u)", ntohs(num));
+
+ return true;
+}
+
+bool
decode_nla_be64(struct tcb *const tcp,
const kernel_ulong_t addr,
const unsigned int len,
diff --git a/nlattr.h b/nlattr.h
index db1fd69f2..09c233e76 100644
--- a/nlattr.h
+++ b/nlattr.h
@@ -56,6 +56,7 @@ DECL_NLA(s8);
DECL_NLA(s16);
DECL_NLA(s32);
DECL_NLA(s64);
+DECL_NLA(be16);
DECL_NLA(be64);
DECL_NLA(str);
DECL_NLA(strn);
diff --git a/rtnl_neigh.c b/rtnl_neigh.c
index 7191ecbab..0eaadc593 100644
--- a/rtnl_neigh.c
+++ b/rtnl_neigh.c
@@ -42,6 +42,54 @@
#include "xlat/neighbor_cache_entry_states.h"
#include "xlat/rtnl_neigh_attrs.h"
+static bool
+decode_neigh_addr(struct tcb *const tcp,
+ const kernel_ulong_t addr,
+ const unsigned int len,
+ const void *const opaque_data)
+{
+ const struct ndmsg *const ndmsg = opaque_data;
+
+ decode_inet_addr(tcp, addr, len, ndmsg->ndm_family, NULL);
+
+ return true;
+}
+
+static bool
+decode_nda_cacheinfo(struct tcb *const tcp,
+ const kernel_ulong_t addr,
+ const unsigned int len,
+ const void *const opaque_data)
+{
+ struct nda_cacheinfo ci;
+
+ if (len < sizeof(ci))
+ return false;
+ else if (!umove_or_printaddr(tcp, addr, &ci)) {
+ PRINT_FIELD_U("{", ci, ndm_confirmed);
+ PRINT_FIELD_U(", ", ci, ndm_used);
+ PRINT_FIELD_U(", ", ci, ndm_updated);
+ PRINT_FIELD_U(", ", ci, ndm_refcnt);
+ tprints("}");
+ }
+
+ return true;
+}
+
+static const nla_decoder_t ndmsg_nla_decoders[] = {
+ [NDA_DST] = decode_neigh_addr,
+ [NDA_LLADDR] = decode_neigh_addr,
+ [NDA_CACHEINFO] = decode_nda_cacheinfo,
+ [NDA_PROBES] = decode_nla_u32,
+ [NDA_VLAN] = decode_nla_u16,
+ [NDA_PORT] = decode_nla_be16,
+ [NDA_VNI] = decode_nla_u32,
+ [NDA_IFINDEX] = decode_nla_ifindex,
+ [NDA_MASTER] = decode_nla_ifindex,
+ [NDA_LINK_NETNSID] = decode_nla_u32,
+ [NDA_SRC_VNI] = NULL,
+};
+
DECL_NETLINK_ROUTE_DECODER(decode_ndmsg)
{
struct ndmsg ndmsg = { .ndm_family = family };
@@ -74,7 +122,9 @@ DECL_NETLINK_ROUTE_DECODER(decode_ndmsg)
if (decode_nla && len > offset) {
tprints(", ");
decode_nlattr(tcp, addr + offset, len - offset,
- rtnl_neigh_attrs, "NDA_???", NULL, 0, NULL);
+ rtnl_neigh_attrs, "NDA_???",
+ ndmsg_nla_decoders,
+ ARRAY_SIZE(ndmsg_nla_decoders), &ndmsg);
}
}