summaryrefslogtreecommitdiff
path: root/src/nlattr.c
diff options
context:
space:
mode:
authorEugene Syromyatnikov <evgsyr@gmail.com>2021-10-14 20:04:17 +0200
committerDmitry V. Levin <ldv@strace.io>2021-11-07 08:00:00 +0000
commit1f724b7b14421051c17d8a00bb89f9216282fd27 (patch)
tree9be22723f92b07b81916d4758d93c6dd09a34459 /src/nlattr.c
parent832827a9560d167a0e57ad146ca2c9c8d416e864 (diff)
downloadstrace-1f724b7b14421051c17d8a00bb89f9216282fd27.tar.gz
nlattr: factor out AF_SPEC-typed netlink attribute decoding
decode_ifstats_af and decode_ifla_af do about the same thing, except the latter employs AF-indexed array and the former uses a list. This is going to change with the addition of AF_MCTP protocol IFLA_AF_SPEC decoding support, as its address family number (45) necessitates the switch from AF-indexed array to a list as well, so these two decoders are going to have exactly the same logic, and that is a reason for factoring it out in a separate function. * src/nlattr.h (struct af_spec_decoder_desc): New type definition. (decode_nla_af_spec): New declaration. * src/nlattr.c (decode_nla_af_spec): New function. * src/rtnl_link.c (ifla_af_spec_protos): Move inside decode_ifla_af, rename to protos, change type to struct af_spec_decoder_desc[], initialise af fields of each item. (decode_ifla_af): Call decode_nla_af_spec. (decode_ifstats_af): Change type of the protos local variable to struct af_spec_decoder_desc[], replace the body with a call to decode_nla_af_spec.
Diffstat (limited to 'src/nlattr.c')
-rw-r--r--src/nlattr.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/nlattr.c b/src/nlattr.c
index 295d29105..9b4879a84 100644
--- a/src/nlattr.c
+++ b/src/nlattr.c
@@ -427,6 +427,33 @@ decode_nla_flags(struct tcb *const tcp,
return true;
}
+void
+decode_nla_af_spec(struct tcb *const tcp,
+ const kernel_ulong_t addr,
+ const unsigned int len,
+ uint8_t af,
+ const struct af_spec_decoder_desc *descs,
+ size_t desc_cnt)
+{
+ const struct af_spec_decoder_desc *const descs_end = descs + desc_cnt;
+ const struct af_spec_decoder_desc *desc = descs;
+
+ for (; desc < descs_end; desc++) {
+ if (desc->af == af)
+ break;
+ }
+
+ if (desc >= descs_end) {
+ printstr_ex(tcp, addr, len, QUOTE_FORCE_HEX);
+
+ } else {
+ decode_nlattr(tcp, addr, len,
+ desc->xlat, desc->dflt, desc->table, desc->size,
+ NULL);
+ }
+}
+
+
bool
decode_nla_be16(struct tcb *const tcp,
const kernel_ulong_t addr,