Browse Source

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.
Eugene Syromyatnikov 1 month ago
parent
commit
0f99f89cd9
2 changed files with 27 additions and 7 deletions
  1. 12
    7
      rtnl_link.c
  2. 15
    0
      tests/nlattr_ifla_port.c

+ 12
- 7
rtnl_link.c View File

@@ -558,13 +558,18 @@ decode_ifla_port_vsi(struct tcb *const tcp,
558 558
 
559 559
 	if (len < sizeof(vsi))
560 560
 		return false;
561
-	else if (!umove_or_printaddr(tcp, addr, &vsi)) {
562
-		PRINT_FIELD_U("{", vsi, vsi_mgr_id);
563
-		PRINT_FIELD_STRING(", ", vsi, vsi_type_id,
564
-				   sizeof(vsi.vsi_type_id), QUOTE_FORCE_HEX);
565
-		PRINT_FIELD_U(", ", vsi, vsi_type_version);
566
-		tprints("}");
567
-	}
561
+	if (umove_or_printaddr(tcp, addr, &vsi))
562
+		return true;
563
+
564
+	PRINT_FIELD_U("{", vsi, vsi_mgr_id);
565
+	PRINT_FIELD_STRING(", ", vsi, vsi_type_id,
566
+			   sizeof(vsi.vsi_type_id), QUOTE_FORCE_HEX);
567
+	PRINT_FIELD_U(", ", vsi, vsi_type_version);
568
+
569
+	if (!IS_ARRAY_ZERO(vsi.pad))
570
+		PRINT_FIELD_HEX_ARRAY(", ", vsi, pad);
571
+
572
+	tprints("}");
568 573
 
569 574
 	return true;
570 575
 }

+ 15
- 0
tests/nlattr_ifla_port.c View File

@@ -57,6 +57,21 @@ main(void)
57 57
 				  printf(", vsi_type_id=\"\\x61\\x62\\x63\"");
58 58
 				  PRINT_FIELD_U(", ", vsi, vsi_type_version);
59 59
 				  printf("}"));
60
+
61
+	static const struct ifla_port_vsi vsi2 = {
62
+		.vsi_mgr_id = 0xab,
63
+		.vsi_type_id = { 10, 0, 255 },
64
+		.vsi_type_version = 0xef,
65
+		.pad = { 0, 1, 2 },
66
+	};
67
+	TEST_NESTED_NLATTR_OBJECT(fd, nlh0, hdrlen,
68
+				  init_ifinfomsg, print_ifinfomsg,
69
+				  IFLA_PORT_VSI_TYPE, pattern, vsi2,
70
+				  PRINT_FIELD_U("{", vsi2, vsi_mgr_id);
71
+				  printf(", vsi_type_id=\"\\x0a\\x00\\xff\"");
72
+				  PRINT_FIELD_U(", ", vsi2, vsi_type_version);
73
+				  printf(", pad=\"\\x00\\x01\\x02\"");
74
+				  printf("}"));
60 75
 #endif
61 76
 
62 77
 	puts("+++ exited with 0 +++");

Loading…
Cancel
Save