Modify a few data structures into unions.
The new 6.0 kernel headers changed all variable length
structures from [0] to []. This causes a clang warning to
trigger, so silence the warning around those structures.
In addition, create ptrs to two structures used in a lambda
since clang does not allow variable length arrays passed
by reference to a lambda.
Test: Builds.
Test: Ran netd_unit_tests on a device (coral).
Change-Id: Ie47d0811ca9384ca27b620baf2c0f96469e45de5
diff --git a/server/XfrmController.h b/server/XfrmController.h
index 4f167c5..6da0c68 100644
--- a/server/XfrmController.h
+++ b/server/XfrmController.h
@@ -286,6 +286,10 @@
// Exposed for testing
static constexpr size_t MAX_KEY_LENGTH = 128;
+ // Disable this warning since avoiding it makes the code unreadable.
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wgnu-variable-sized-type-not-at-end"
+
// Container for the content of an XFRMA_ALG_CRYPT netlink attribute.
// Exposed for testing
struct nlattr_algo_crypt {
@@ -310,6 +314,8 @@
uint8_t key[MAX_KEY_LENGTH];
};
+#pragma clang diagnostic pop
+
// Exposed for testing
struct nlattr_user_tmpl {
nlattr hdr;
diff --git a/server/XfrmControllerTest.cpp b/server/XfrmControllerTest.cpp
index f1c3807..9328c14 100644
--- a/server/XfrmControllerTest.cpp
+++ b/server/XfrmControllerTest.cpp
@@ -390,8 +390,12 @@
Slice attr_buf = drop(nlMsgSlice, NLA_ALIGN(sizeof(xfrm_usersa_info)));
// Extract and check the encryption/authentication algorithm
- XfrmController::nlattr_algo_crypt encryptAlgo{};
- XfrmController::nlattr_algo_auth authAlgo{};
+ XfrmController::nlattr_algo_crypt _encryptAlgo{};
+ XfrmController::nlattr_algo_auth _authAlgo{};
+ // Need to use a pointer since you can't pass a structure with a variable
+ // sized array in a lambda.
+ XfrmController::nlattr_algo_crypt* const encryptAlgo = &_encryptAlgo;
+ XfrmController::nlattr_algo_auth* const authAlgo = &_authAlgo;
XfrmController::nlattr_xfrm_mark mark{};
XfrmController::nlattr_xfrm_output_mark outputmark{};
XfrmController::nlattr_xfrm_interface_id xfrm_if_id{};
@@ -399,15 +403,15 @@
const nlattr& attr, const Slice& attr_payload) {
Slice buf = attr_payload;
if (attr.nla_type == XFRMA_ALG_CRYPT) {
- encryptAlgo.hdr = attr;
- netdutils::extract(buf, encryptAlgo.crypt);
+ encryptAlgo->hdr = attr;
+ netdutils::extract(buf, encryptAlgo->crypt);
buf = drop(buf, sizeof(xfrm_algo));
- netdutils::extract(buf, encryptAlgo.key);
+ netdutils::extract(buf, encryptAlgo->key);
} else if (attr.nla_type == XFRMA_ALG_AUTH_TRUNC) {
- authAlgo.hdr = attr;
- netdutils::extract(buf, authAlgo.auth);
+ authAlgo->hdr = attr;
+ netdutils::extract(buf, authAlgo->auth);
buf = drop(buf, sizeof(xfrm_algo_auth));
- netdutils::extract(buf, authAlgo.key);
+ netdutils::extract(buf, authAlgo->key);
} else if (attr.nla_type == XFRMA_MARK) {
mark.hdr = attr;
netdutils::extract(buf, mark.mark);
@@ -425,9 +429,9 @@
// TODO: Use ContainerEq or ElementsAreArray to get better test failure messages.
EXPECT_EQ(0, memcmp(reinterpret_cast<void*>(cryptKey.data()),
- reinterpret_cast<void*>(&encryptAlgo.key), KEY_LENGTH));
+ reinterpret_cast<void*>(&encryptAlgo->key), KEY_LENGTH));
EXPECT_EQ(0, memcmp(reinterpret_cast<void*>(authKey.data()),
- reinterpret_cast<void*>(&authAlgo.key), KEY_LENGTH));
+ reinterpret_cast<void*>(&authAlgo->key), KEY_LENGTH));
if (mode == XfrmMode::TUNNEL) {
if (params.xfrmInterfacesEnabled) {