From: Eugene Syromyatnikov <evgsyr@gmail.com> Date: Fri, 18 May 2018 15:37:51 +0000 (+0200) Subject: nlattr: add ethernet protocol decoder X-Git-Tag: v4.23~45 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fd0cd658cc150992669f14ce2b4536c4f7f488e1;p=strace nlattr: add ethernet protocol decoder * nlattr.h (DECL_NLA(ether_proto)): New declaration. * nlattr.c (process_host_order, decode_nla_ether_proto): New functions. --- diff --git a/nlattr.c b/nlattr.c index b11f6821..4666132b 100644 --- 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, diff --git a/nlattr.h b/nlattr.h index 478b8f11..b3d50ce0 100644 --- 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);