From fb287742d4221195708f5865fd5335d43e8a8a5d Mon Sep 17 00:00:00 2001 From: Eugene Syromyatnikov Date: Sat, 19 Oct 2019 10:44:36 +0200 Subject: [PATCH 64/76] 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. --- rtnl_link.c | 19 ++++++++++++------- tests/nlattr_ifla_port.c | 15 +++++++++++++++ 2 files changed, 27 insertions(+), 7 deletions(-) Index: strace-5.1/rtnl_link.c =================================================================== --- strace-5.1.orig/rtnl_link.c 2020-01-29 12:36:17.631477314 +0100 +++ strace-5.1/rtnl_link.c 2020-01-29 12:36:19.726458084 +0100 @@ -560,13 +560,18 @@ 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; } Index: strace-5.1/tests/nlattr_ifla_port.c =================================================================== --- strace-5.1.orig/tests/nlattr_ifla_port.c 2018-12-10 01:00:00.000000000 +0100 +++ strace-5.1/tests/nlattr_ifla_port.c 2020-01-29 12:36:19.729458056 +0100 @@ -57,6 +57,21 @@ 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 +++"); Index: strace-5.1/tests-m32/nlattr_ifla_port.c =================================================================== --- strace-5.1.orig/tests-m32/nlattr_ifla_port.c 2018-12-10 01:00:00.000000000 +0100 +++ strace-5.1/tests-m32/nlattr_ifla_port.c 2020-01-29 12:36:51.841163297 +0100 @@ -57,6 +57,21 @@ 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 +++"); Index: strace-5.1/tests-mx32/nlattr_ifla_port.c =================================================================== --- strace-5.1.orig/tests-mx32/nlattr_ifla_port.c 2018-12-10 01:00:00.000000000 +0100 +++ strace-5.1/tests-mx32/nlattr_ifla_port.c 2020-01-29 12:36:51.843163278 +0100 @@ -57,6 +57,21 @@ 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 +++");