]> granicus.if.org Git - strace/commitdiff
nlattr: add value processing support for xlat/flags nlattr decoders
authorEugene Syromyatnikov <evgsyr@gmail.com>
Fri, 18 May 2018 15:36:00 +0000 (17:36 +0200)
committerDmitry V. Levin <ldv@altlinux.org>
Wed, 6 Jun 2018 15:10:37 +0000 (15:10 +0000)
Needed for upcoming decoder of ethernet proto which is stored in the
host order and has to be converted to the network order before printing
as an xval constant.  This change also adds ability to provide
prefix/suffix in order to enclose the printed value in something that
describes the performed conversion.

* nlattr.h (struct decode_nla_xlat_opts): Add prefix, suffix, and
process_fn fields.
* nlattr.c (decode_nla_xval, decode_nla_flags): Handle process_fn,
prefix, snd uffix parameters.

nlattr.c
nlattr.h

index 835cf25e5f07f7687d1c9cfa46a1f370caf56f73..b11f682109e55c21e2f59d89538b11df62286262 100644 (file)
--- a/nlattr.c
+++ b/nlattr.c
@@ -273,8 +273,16 @@ decode_nla_xval(struct tcb *const tcp,
        if (len > sizeof(data))
                return false;
        else if (!umoven_or_printaddr(tcp, addr, len, data.bytes + bytes_offs))
+       {
+               if (opts->process_fn)
+                       data.val = opts->process_fn(data.val);
+               if (opts->prefix)
+                       tprints(opts->prefix);
                printxval_dispatch_ex(opts->xlat, opts->xlat_size, data.val,
                                      opts->dflt, opts->xt, opts->style);
+               if (opts->suffix)
+                       tprints(opts->suffix);
+       }
 
        return true;
 }
@@ -315,8 +323,16 @@ decode_nla_flags(struct tcb *const tcp,
        if (len > sizeof(data))
                return false;
        else if (!umoven_or_printaddr(tcp, addr, len, data.bytes + bytes_offs))
+       {
+               if (opts->process_fn)
+                       data.flags = opts->process_fn(data.flags);
+               if (opts->prefix)
+                       tprints(opts->prefix);
                printflags_ex(data.flags, opts->dflt, opts->style, opts->xlat,
                              NULL);
+               if (opts->suffix)
+                       tprints(opts->suffix);
+       }
 
        return true;
 }
index fc7a67d9261c2b239c0a54a704b2f35ce4759de7..478b8f11852e42ab10332152fd92f097d7b68550 100644 (file)
--- a/nlattr.h
+++ b/nlattr.h
@@ -38,6 +38,9 @@ struct decode_nla_xlat_opts {
        const char *dflt;
        enum xlat_type xt;
        enum xlat_style style;
+       const char *prefix;
+       const char *suffix;
+       uint64_t (*process_fn)(uint64_t val);
 };
 
 typedef bool (*nla_decoder_t)(struct tcb *, kernel_ulong_t addr,