From: Eugene Syromyatnikov Date: Sat, 19 Oct 2019 08:44:36 +0000 (+0200) Subject: rtnl_link: print pad field in the struct ifla_port_vsi decoder X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0f99f89cd90992148e426f288c9bf7df994e8943;p=strace rtnl_link: print pad field in the struct ifla_port_vsi decoder And steamline the flow a bit. * rtnl_link.c (decode_ifla_port_vsi): Factor the printing code out of the conditional statement, add pad field printing. * tests/nlattr_ifla_port.c: Add check for the pad field printing. --- diff --git a/rtnl_link.c b/rtnl_link.c index e1f2caac..f668cd66 100644 --- a/rtnl_link.c +++ b/rtnl_link.c @@ -558,13 +558,18 @@ decode_ifla_port_vsi(struct tcb *const tcp, if (len < sizeof(vsi)) return false; - else if (!umove_or_printaddr(tcp, addr, &vsi)) { - PRINT_FIELD_U("{", vsi, vsi_mgr_id); - PRINT_FIELD_STRING(", ", vsi, vsi_type_id, - sizeof(vsi.vsi_type_id), QUOTE_FORCE_HEX); - PRINT_FIELD_U(", ", vsi, vsi_type_version); - tprints("}"); - } + if (umove_or_printaddr(tcp, addr, &vsi)) + return true; + + PRINT_FIELD_U("{", vsi, vsi_mgr_id); + PRINT_FIELD_STRING(", ", vsi, vsi_type_id, + sizeof(vsi.vsi_type_id), QUOTE_FORCE_HEX); + PRINT_FIELD_U(", ", vsi, vsi_type_version); + + if (!IS_ARRAY_ZERO(vsi.pad)) + PRINT_FIELD_HEX_ARRAY(", ", vsi, pad); + + tprints("}"); return true; } diff --git a/tests/nlattr_ifla_port.c b/tests/nlattr_ifla_port.c index df2a2ef6..1a7f7deb 100644 --- a/tests/nlattr_ifla_port.c +++ b/tests/nlattr_ifla_port.c @@ -57,6 +57,21 @@ main(void) printf(", vsi_type_id=\"\\x61\\x62\\x63\""); PRINT_FIELD_U(", ", vsi, vsi_type_version); printf("}")); + + static const struct ifla_port_vsi vsi2 = { + .vsi_mgr_id = 0xab, + .vsi_type_id = { 10, 0, 255 }, + .vsi_type_version = 0xef, + .pad = { 0, 1, 2 }, + }; + TEST_NESTED_NLATTR_OBJECT(fd, nlh0, hdrlen, + init_ifinfomsg, print_ifinfomsg, + IFLA_PORT_VSI_TYPE, pattern, vsi2, + PRINT_FIELD_U("{", vsi2, vsi_mgr_id); + printf(", vsi_type_id=\"\\x0a\\x00\\xff\""); + PRINT_FIELD_U(", ", vsi2, vsi_type_version); + printf(", pad=\"\\x00\\x01\\x02\""); + printf("}")); #endif puts("+++ exited with 0 +++");