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;
}
+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,
return decode_nla_xval(tcp, addr, len, &opts);
}
+bool
+decode_nla_flags(struct tcb *const tcp,
+ const kernel_ulong_t addr,
+ const unsigned int len,
+ const void *const opaque_data)
+{
+ const struct decode_nla_xlat_opts * const opts = opaque_data;
+ union {
+ uint64_t flags;
+ uint8_t bytes[sizeof(uint64_t)];
+ } data = { .flags = 0 };
+ const size_t bytes_offs = is_bigendian ? sizeof(data) - len : 0;
+
+ if (opts->xt == XT_INDEXED)
+ error_func_msg("indexed xlats are currently incompatible with "
+ "printflags");
+
+ 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;
+}
+
bool
decode_nla_be16(struct tcb *const tcp,
const kernel_ulong_t addr,
return true; \
}
+DECODE_NLA_INTEGER(x8, uint8_t, "%#" PRIx8)
+DECODE_NLA_INTEGER(x16, uint16_t, "%#" PRIx16)
+DECODE_NLA_INTEGER(x32, uint32_t, "%#" PRIx32)
+DECODE_NLA_INTEGER(x64, uint64_t, "%#" PRIx64)
DECODE_NLA_INTEGER(u8, uint8_t, "%" PRIu8)
DECODE_NLA_INTEGER(u16, uint16_t, "%" PRIu16)
DECODE_NLA_INTEGER(u32, uint32_t, "%" PRIu32)