]> granicus.if.org Git - strace/commitdiff
nlattr: add ethernet protocol decoder
authorEugene Syromyatnikov <evgsyr@gmail.com>
Fri, 18 May 2018 15:37:51 +0000 (17:37 +0200)
committerDmitry V. Levin <ldv@altlinux.org>
Wed, 6 Jun 2018 15:10:37 +0000 (15:10 +0000)
* nlattr.h (DECL_NLA(ether_proto)): New declaration.
* nlattr.c (process_host_order, decode_nla_ether_proto): New functions.

nlattr.c
nlattr.h

index b11f682109e55c21e2f59d89538b11df62286262..4666132b0f52b5e4e40a27e97d9cbd3a14b91a22 100644 (file)
--- a/nlattr.c
+++ b/nlattr.c
@@ -287,6 +287,31 @@ decode_nla_xval(struct tcb *const tcp,
        return true;
 }
 
+static uint64_t
+process_host_order(uint64_t val)
+{
+       return ntohs(val);
+}
+
+bool
+decode_nla_ether_proto(struct tcb *const tcp,
+                      const kernel_ulong_t addr,
+                      const unsigned int len,
+                      const void *const opaque_data)
+{
+       const struct decode_nla_xlat_opts opts = {
+               .xlat = ethernet_protocols,
+               .xlat_size = ethernet_protocols_size,
+               .dflt = "ETHER_P_???",
+               .xt = XT_SORTED,
+               .prefix = "htons(",
+               .suffix = ")",
+               .process_fn = process_host_order,
+       };
+
+       return decode_nla_xval(tcp, addr, len, &opts);
+}
+
 bool
 decode_nla_ip_proto(struct tcb *const tcp,
                    const kernel_ulong_t addr,
index 478b8f11852e42ab10332152fd92f097d7b68550..b3d50ce0cfb2ccd403f824b762f10011168cdf87 100644 (file)
--- a/nlattr.h
+++ b/nlattr.h
@@ -83,6 +83,7 @@ DECL_NLA(str);
 DECL_NLA(strn);
 DECL_NLA(fd);
 DECL_NLA(ifindex);
+DECL_NLA(ether_proto);
 DECL_NLA(ip_proto);
 DECL_NLA(meminfo);
 DECL_NLA(rt_class);