blob: 1a14a72deaca5063b9fbf60b379ea57223e59083 [file] [log] [blame]
ludi5c81c762017-05-19 13:47:53 -07001/*
2 * Copyright 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * xfrm_ctrl_test.cpp - unit tests for xfrm controllers.
17 */
18
19#include <cerrno>
20#include <cinttypes>
21#include <cstdint>
22#include <cstdio>
23#include <cstdlib>
24#include <set>
25#include <vector>
26
27#include <arpa/inet.h>
28#include <fcntl.h>
29#include <gmock/gmock.h>
30#include <ifaddrs.h>
31#include <linux/if.h>
32#include <linux/if_tun.h>
33#include <linux/netfilter/nfnetlink.h>
34#include <linux/netlink.h>
35#include <netdb.h>
36#include <netinet/in.h>
37#include <sys/socket.h>
38#include <sys/types.h>
39
40#include <android-base/macros.h>
41#include <android-base/stringprintf.h>
42#include <android-base/strings.h>
43#include <android-base/unique_fd.h>
44#include <gtest/gtest.h>
45
46#include "NetdConstants.h"
47#include "NetlinkCommands.h"
48#include "Stopwatch.h"
49#include "XfrmController.h"
50#include "android/net/INetd.h"
51#include "android/net/UidRange.h"
52#include "binder/IServiceManager.h"
53#include "netdutils/MockSyscalls.h"
54#include "netdutils/Netlink.h"
55#include "tun_interface.h"
56
57using android::base::unique_fd;
58using android::netdutils::Fd;
59using android::netdutils::MockSyscalls;
60using android::netdutils::Slice;
61using android::netdutils::Status;
62using android::netdutils::StatusOr;
63using android::netdutils::Syscalls;
64
Jonathan Basseri20a17c32017-09-14 17:42:40 -070065using ::testing::_;
ludi5c81c762017-05-19 13:47:53 -070066using ::testing::DoAll;
Jonathan Basserifc3b35f2017-09-14 15:58:16 -070067using ::testing::Invoke;
ludi5c81c762017-05-19 13:47:53 -070068using ::testing::Return;
69using ::testing::SaveArg;
70using ::testing::SetArgPointee;
Jonathan Basseri20a17c32017-09-14 17:42:40 -070071using ::testing::Values;
Jonathan Basserifc3b35f2017-09-14 15:58:16 -070072using ::testing::WithArg;
ludi5c81c762017-05-19 13:47:53 -070073
74/**
Jonathan Basseric6128662017-09-14 17:32:59 -070075 * This gMock action works like SetArgPointee, but for netdutils::Slice.
76 * It sets the memory which is pointed to by the N-th argument with the supplied value.
ludi5c81c762017-05-19 13:47:53 -070077 */
Jonathan Basseric6128662017-09-14 17:32:59 -070078ACTION_TEMPLATE(SetArgSlice, HAS_1_TEMPLATE_PARAMS(int, N), AND_1_VALUE_PARAMS(value)) {
79 Slice orig = ::testing::get<N>(args);
ludi5c81c762017-05-19 13:47:53 -070080 android::netdutils::copy(orig, value);
81}
82
Jonathan Basseric6128662017-09-14 17:32:59 -070083/**
84 * This gMock action works like SaveArg, but is specialized for vector<iovec>.
85 * It copies the memory pointed to by each of the iovecs into a single vector<uint8_t>.
86 *
87 * Flattening the iovec objects cannot be done later, since there is no guarantee that the memory
88 * they point to will still be valid after the mock method returns.
89 */
90ACTION_TEMPLATE(SaveFlattenedIovecs, HAS_1_TEMPLATE_PARAMS(int, N), AND_1_VALUE_PARAMS(resVec)) {
91 const std::vector<iovec>& iovs = ::testing::get<N>(args);
ludi5c81c762017-05-19 13:47:53 -070092
93 for (const iovec& iov : iovs) {
94 resVec->insert(resVec->end(), reinterpret_cast<uint8_t*>(iov.iov_base),
95 reinterpret_cast<uint8_t*>(iov.iov_base) + iov.iov_len);
96 }
97}
98
99namespace android {
100namespace net {
101
102static constexpr int DROID_SPI = 0xD1201D;
103static constexpr size_t KEY_LENGTH = 32;
104static constexpr int NLMSG_DEFAULTSIZE = 8192;
105
Jonathan Basseri20a17c32017-09-14 17:42:40 -0700106static constexpr char LOCALHOST_V4[] = "127.0.0.1";
107static constexpr char LOCALHOST_V6[] = "::1";
108static constexpr char TEST_ADDR_V4[] = "8.8.8.8";
109static constexpr char TEST_ADDR_V6[] = "2001:4860:4860::8888";
110
ludi5c81c762017-05-19 13:47:53 -0700111struct Policy {
112 xfrm_userpolicy_info info;
113 xfrm_user_tmpl tmpl;
114};
115
116struct NetlinkResponse {
117 nlmsghdr hdr;
118 char buf[NLMSG_DEFAULTSIZE];
119};
120
Jonathan Basserid6c08582017-09-14 16:10:56 -0700121void expectAddressEquals(int family, const std::string& expected, const xfrm_address_t& actual) {
122 char actualStr[INET6_ADDRSTRLEN];
123 const char* ret =
124 inet_ntop(family, reinterpret_cast<const void*>(&actual), actualStr, INET6_ADDRSTRLEN);
125 EXPECT_NE(nullptr, ret) << "Unable to convert xfrm_address_t to string";
126 EXPECT_EQ(expected, actualStr);
127}
128
ludi5c81c762017-05-19 13:47:53 -0700129class XfrmControllerTest : public ::testing::Test {
130public:
131 MockSyscalls mockSyscalls;
132
133 void SetUp() override { netdutils::sSyscalls.swap(mockSyscalls); }
134};
135
Jonathan Basseri20a17c32017-09-14 17:42:40 -0700136// Test class allowing IPv4/IPv6 parameterized tests.
137class XfrmControllerParameterizedTest : public XfrmControllerTest,
138 public ::testing::WithParamInterface<int> {};
ludi5c81c762017-05-19 13:47:53 -0700139
Jonathan Basseri20a17c32017-09-14 17:42:40 -0700140// Helper to make generated test names readable.
141std::string FamilyName(::testing::TestParamInfo<int> info) {
142 return (info.param == AF_INET) ? "AF_INET" : "AF_INET6";
ludi5c81c762017-05-19 13:47:53 -0700143}
144
Jonathan Basseri20a17c32017-09-14 17:42:40 -0700145// The TEST_P cases below will run with each of the following value parameters.
146INSTANTIATE_TEST_CASE_P(ByFamily, XfrmControllerParameterizedTest, Values(AF_INET, AF_INET6),
147 FamilyName);
148
149TEST_P(XfrmControllerParameterizedTest, TestIpSecAllocateSpi) {
150 const int family = GetParam();
151 const std::string localAddr = (family == AF_INET6) ? LOCALHOST_V6 : LOCALHOST_V4;
152 const std::string remoteAddr = (family == AF_INET6) ? TEST_ADDR_V6 : TEST_ADDR_V4;
ludi5c81c762017-05-19 13:47:53 -0700153
Jonathan Basseri643d9632017-09-14 18:02:31 -0700154 NetlinkResponse response{};
ludi5c81c762017-05-19 13:47:53 -0700155 response.hdr.nlmsg_type = XFRM_MSG_ALLOCSPI;
Jonathan Basseri643d9632017-09-14 18:02:31 -0700156 Slice responseSlice = netdutils::makeSlice(response);
ludi5c81c762017-05-19 13:47:53 -0700157
Jonathan Basseri643d9632017-09-14 18:02:31 -0700158 size_t expectedMsgLength = NLMSG_HDRLEN + NLMSG_ALIGN(sizeof(xfrm_userspi_info));
ludi5c81c762017-05-19 13:47:53 -0700159
160 // A vector to hold the flattened netlink message for nlMsgSlice
161 std::vector<uint8_t> nlMsgBuf;
162 EXPECT_CALL(mockSyscalls, writev(_, _))
Jonathan Basseri643d9632017-09-14 18:02:31 -0700163 .WillOnce(DoAll(SaveFlattenedIovecs<1>(&nlMsgBuf), Return(expectedMsgLength)));
ludi5c81c762017-05-19 13:47:53 -0700164 EXPECT_CALL(mockSyscalls, read(_, _))
Jonathan Basseri643d9632017-09-14 18:02:31 -0700165 .WillOnce(DoAll(SetArgSlice<1>(responseSlice), Return(responseSlice)));
ludi5c81c762017-05-19 13:47:53 -0700166
Jonathan Basseri643d9632017-09-14 18:02:31 -0700167 XfrmController ctrl;
168 int outSpi = 0;
Jonathan Basseri20a17c32017-09-14 17:42:40 -0700169 Status res = ctrl.ipSecAllocateSpi(1 /* resourceId */, static_cast<int>(XfrmDirection::OUT),
170 localAddr, remoteAddr, DROID_SPI, &outSpi);
ludi5c81c762017-05-19 13:47:53 -0700171
Jonathan Basserid6c08582017-09-14 16:10:56 -0700172 EXPECT_TRUE(isOk(res)) << res;
ludi5c81c762017-05-19 13:47:53 -0700173 EXPECT_EQ(DROID_SPI, outSpi);
Jonathan Basseri643d9632017-09-14 18:02:31 -0700174 EXPECT_EQ(expectedMsgLength, nlMsgBuf.size());
ludi5c81c762017-05-19 13:47:53 -0700175
176 Slice nlMsgSlice = netdutils::makeSlice(nlMsgBuf);
177 nlMsgSlice = drop(nlMsgSlice, NLMSG_HDRLEN);
178
179 xfrm_userspi_info userspi{};
180 netdutils::extract(nlMsgSlice, userspi);
181
Jonathan Basseri20a17c32017-09-14 17:42:40 -0700182 EXPECT_EQ(family, userspi.info.sel.family);
183 expectAddressEquals(family, localAddr, userspi.info.saddr);
184 expectAddressEquals(family, remoteAddr, userspi.info.id.daddr);
ludi5c81c762017-05-19 13:47:53 -0700185
186 EXPECT_EQ(DROID_SPI, static_cast<int>(userspi.min));
187 EXPECT_EQ(DROID_SPI, static_cast<int>(userspi.max));
188}
189
Jonathan Basseri20a17c32017-09-14 17:42:40 -0700190TEST_P(XfrmControllerParameterizedTest, TestIpSecAddSecurityAssociation) {
191 const int family = GetParam();
192 const std::string localAddr = (family == AF_INET6) ? LOCALHOST_V6 : LOCALHOST_V4;
193 const std::string remoteAddr = (family == AF_INET6) ? TEST_ADDR_V6 : TEST_ADDR_V4;
ludi5c81c762017-05-19 13:47:53 -0700194
Jonathan Basseri643d9632017-09-14 18:02:31 -0700195 NetlinkResponse response{};
ludi5c81c762017-05-19 13:47:53 -0700196 response.hdr.nlmsg_type = XFRM_MSG_ALLOCSPI;
Jonathan Basseri643d9632017-09-14 18:02:31 -0700197 Slice responseSlice = netdutils::makeSlice(response);
ludi5c81c762017-05-19 13:47:53 -0700198
199 std::vector<uint8_t> authKey(KEY_LENGTH, 0);
200 std::vector<uint8_t> cryptKey(KEY_LENGTH, 1);
201
202 // Calculate the length of the expected netlink message.
Jonathan Basseri643d9632017-09-14 18:02:31 -0700203 size_t expectedMsgLength =
Jonathan Basserid6c08582017-09-14 16:10:56 -0700204 NLMSG_HDRLEN + NLMSG_ALIGN(sizeof(xfrm_usersa_info)) +
205 NLA_ALIGN(offsetof(XfrmController::nlattr_algo_crypt, key) + KEY_LENGTH) +
Jonathan Basseri20a17c32017-09-14 17:42:40 -0700206 NLA_ALIGN(offsetof(XfrmController::nlattr_algo_auth, key) + KEY_LENGTH);
ludi5c81c762017-05-19 13:47:53 -0700207
208 std::vector<uint8_t> nlMsgBuf;
209 EXPECT_CALL(mockSyscalls, writev(_, _))
Jonathan Basseri643d9632017-09-14 18:02:31 -0700210 .WillOnce(DoAll(SaveFlattenedIovecs<1>(&nlMsgBuf), Return(expectedMsgLength)));
ludi5c81c762017-05-19 13:47:53 -0700211 EXPECT_CALL(mockSyscalls, read(_, _))
Jonathan Basseri643d9632017-09-14 18:02:31 -0700212 .WillOnce(DoAll(SetArgSlice<1>(responseSlice), Return(responseSlice)));
ludi5c81c762017-05-19 13:47:53 -0700213
Jonathan Basseri643d9632017-09-14 18:02:31 -0700214 XfrmController ctrl;
ludi5c81c762017-05-19 13:47:53 -0700215 Status res = ctrl.ipSecAddSecurityAssociation(
216 1 /* resourceId */, static_cast<int>(XfrmMode::TUNNEL),
Jonathan Basseri20a17c32017-09-14 17:42:40 -0700217 static_cast<int>(XfrmDirection::OUT), localAddr, remoteAddr, 0 /* underlying network */,
218 DROID_SPI, "hmac(sha256)" /* auth algo */, authKey, 128 /* auth trunc length */,
219 "cbc(aes)" /* encryption algo */, cryptKey, 0 /* crypt trunc length? */, "" /* AEAD algo */,
220 {}, 0, static_cast<int>(XfrmEncapType::NONE), 0 /* local port */, 0 /* remote port */);
ludi5c81c762017-05-19 13:47:53 -0700221
Jonathan Basserid6c08582017-09-14 16:10:56 -0700222 EXPECT_TRUE(isOk(res)) << res;
Jonathan Basseri643d9632017-09-14 18:02:31 -0700223 EXPECT_EQ(expectedMsgLength, nlMsgBuf.size());
ludi5c81c762017-05-19 13:47:53 -0700224
225 Slice nlMsgSlice = netdutils::makeSlice(nlMsgBuf);
226 nlMsgSlice = drop(nlMsgSlice, NLMSG_HDRLEN);
227
228 xfrm_usersa_info usersa{};
229 netdutils::extract(nlMsgSlice, usersa);
230
Jonathan Basseri20a17c32017-09-14 17:42:40 -0700231 EXPECT_EQ(family, usersa.family);
ludi5c81c762017-05-19 13:47:53 -0700232 EXPECT_EQ(1 /* Transform Id*/, static_cast<int>(usersa.reqid));
233 EXPECT_EQ(XFRM_MODE_TUNNEL, usersa.mode);
234 EXPECT_EQ(htonl(DROID_SPI), usersa.id.spi);
235 EXPECT_EQ(IPPROTO_ESP, usersa.id.proto);
236
Jonathan Basseri20a17c32017-09-14 17:42:40 -0700237 expectAddressEquals(family, localAddr, usersa.saddr);
238 expectAddressEquals(family, remoteAddr, usersa.id.daddr);
ludi5c81c762017-05-19 13:47:53 -0700239
Jonathan Basseri643d9632017-09-14 18:02:31 -0700240 // Extract and check the encryption/authentication algorithms.
ludi5c81c762017-05-19 13:47:53 -0700241 Slice attr_buf = drop(nlMsgSlice, NLA_ALIGN(sizeof(xfrm_usersa_info)));
242
243 // Extract and check the encryption/authentication algorithm
244 XfrmController::nlattr_algo_crypt encryptAlgo{};
245 XfrmController::nlattr_algo_auth authAlgo{};
246 auto attrHandler = [&encryptAlgo, &authAlgo](const nlattr& attr, const Slice& attr_payload) {
247 Slice buf = attr_payload;
248 if (attr.nla_type == XFRMA_ALG_CRYPT) {
249 encryptAlgo.hdr = attr;
250 netdutils::extract(buf, encryptAlgo.crypt);
251 buf = drop(buf, sizeof(xfrm_algo));
252 netdutils::extract(buf, encryptAlgo.key);
253 } else if (attr.nla_type == XFRMA_ALG_AUTH_TRUNC) {
254 authAlgo.hdr = attr;
255 netdutils::extract(buf, authAlgo.auth);
256 buf = drop(buf, sizeof(xfrm_algo_auth));
257 netdutils::extract(buf, authAlgo.key);
Jonathan Basseri20a17c32017-09-14 17:42:40 -0700258 } else {
259 FAIL() << "Unexpected nlattr type: " << attr.nla_type;
ludi5c81c762017-05-19 13:47:53 -0700260 }
261 };
262 forEachNetlinkAttribute(attr_buf, attrHandler);
263
Jonathan Basserid6c08582017-09-14 16:10:56 -0700264 // TODO: Use ContainerEq or ElementsAreArray to get better test failure messages.
ludi5c81c762017-05-19 13:47:53 -0700265 EXPECT_EQ(0, memcmp(reinterpret_cast<void*>(cryptKey.data()),
266 reinterpret_cast<void*>(&encryptAlgo.key), KEY_LENGTH));
267 EXPECT_EQ(0, memcmp(reinterpret_cast<void*>(authKey.data()),
268 reinterpret_cast<void*>(&authAlgo.key), KEY_LENGTH));
269}
270
Jonathan Basseri20a17c32017-09-14 17:42:40 -0700271TEST_F(XfrmControllerTest, TestIpSecAddSecurityAssociationIPv4Encap) {
272 // TODO: Implement this test, which is nearly identical to
273 // TestIpSecAddSecurityAssociation.
274}
ludi5c81c762017-05-19 13:47:53 -0700275
Jonathan Basseri20a17c32017-09-14 17:42:40 -0700276// Test that input validation rejects IPv6 UDP encap.
277TEST_F(XfrmControllerTest, TestIpSecAddSecurityAssociationIPv6Encap) {
278 EXPECT_CALL(mockSyscalls, writev(_, _)).Times(0);
279
280 XfrmController ctrl;
281 Status res = ctrl.ipSecAddSecurityAssociation(
282 1, static_cast<int>(XfrmMode::TUNNEL), static_cast<int>(XfrmDirection::OUT), LOCALHOST_V6,
283 TEST_ADDR_V6, 0, DROID_SPI, "hmac(sha256)", {}, 128, "cbc(aes)", {}, 0, "", {}, 0,
284 static_cast<int>(XfrmEncapType::ESPINUDP_NON_IKE), 0, 0);
285
286 EXPECT_FALSE(isOk(res)) << "IPv6 UDP encap not rejected";
287}
288
289TEST_P(XfrmControllerParameterizedTest, TestIpSecApplyTransportModeTransform) {
290 const int family = GetParam();
291 const std::string localAddr = (family == AF_INET6) ? LOCALHOST_V6 : LOCALHOST_V4;
292 const std::string remoteAddr = (family == AF_INET6) ? TEST_ADDR_V6 : TEST_ADDR_V4;
Jonathan Basseri643d9632017-09-14 18:02:31 -0700293
Jonathan Basseri20a17c32017-09-14 17:42:40 -0700294 size_t optlen = 0;
Jonathan Basserifc3b35f2017-09-14 15:58:16 -0700295 Policy policy{};
296 // Need to cast from void* in order to "SaveArg" policy. Easier to invoke a
297 // lambda than to write a gMock action.
298 auto SavePolicy = [&policy](const void* value) {
299 policy = *reinterpret_cast<const Policy*>(value);
300 };
301
ludi5c81c762017-05-19 13:47:53 -0700302 struct sockaddr socketaddr;
Jonathan Basseri20a17c32017-09-14 17:42:40 -0700303 socketaddr.sa_family = family;
ludi5c81c762017-05-19 13:47:53 -0700304
Jonathan Basseri20a17c32017-09-14 17:42:40 -0700305 unique_fd sock(socket(family, SOCK_STREAM, 0));
ludi5c81c762017-05-19 13:47:53 -0700306
307 EXPECT_CALL(mockSyscalls, getsockname(_, _, _))
308 .WillOnce(DoAll(SetArgPointee<1>(socketaddr), Return(netdutils::status::ok)));
309
310 EXPECT_CALL(mockSyscalls, setsockopt(_, _, _, _, _))
Jonathan Basserifc3b35f2017-09-14 15:58:16 -0700311 .WillOnce(DoAll(WithArg<3>(Invoke(SavePolicy)), SaveArg<4>(&optlen),
312 Return(netdutils::status::ok)));
ludi5c81c762017-05-19 13:47:53 -0700313
Jonathan Basseri643d9632017-09-14 18:02:31 -0700314 XfrmController ctrl;
Jonathan Basseri20a17c32017-09-14 17:42:40 -0700315 Status res = ctrl.ipSecApplyTransportModeTransform(sock, 1 /* resourceId */,
316 static_cast<int>(XfrmDirection::OUT),
317 localAddr, remoteAddr, DROID_SPI);
ludi5c81c762017-05-19 13:47:53 -0700318
Jonathan Basserid6c08582017-09-14 16:10:56 -0700319 EXPECT_TRUE(isOk(res)) << res;
Jonathan Basseri20a17c32017-09-14 17:42:40 -0700320 EXPECT_EQ(sizeof(Policy), optlen);
ludi5c81c762017-05-19 13:47:53 -0700321
Jonathan Basserifc3b35f2017-09-14 15:58:16 -0700322 EXPECT_EQ(1 /* resourceId */, static_cast<int>(policy.tmpl.reqid));
323 EXPECT_EQ(htonl(DROID_SPI), policy.tmpl.id.spi);
ludi5c81c762017-05-19 13:47:53 -0700324
Jonathan Basseri20a17c32017-09-14 17:42:40 -0700325 expectAddressEquals(family, localAddr, policy.tmpl.saddr);
326 expectAddressEquals(family, remoteAddr, policy.tmpl.id.daddr);
ludi5c81c762017-05-19 13:47:53 -0700327}
328
Jonathan Basseri20a17c32017-09-14 17:42:40 -0700329TEST_P(XfrmControllerParameterizedTest, TestIpSecDeleteSecurityAssociation) {
330 const int family = GetParam();
331 const std::string localAddr = (family == AF_INET6) ? LOCALHOST_V6 : LOCALHOST_V4;
332 const std::string remoteAddr = (family == AF_INET6) ? TEST_ADDR_V6 : TEST_ADDR_V4;
Jonathan Basseri643d9632017-09-14 18:02:31 -0700333
334 NetlinkResponse response{};
ludi5c81c762017-05-19 13:47:53 -0700335 response.hdr.nlmsg_type = XFRM_MSG_ALLOCSPI;
Jonathan Basseri643d9632017-09-14 18:02:31 -0700336 Slice responseSlice = netdutils::makeSlice(response);
ludi5c81c762017-05-19 13:47:53 -0700337
Jonathan Basseri643d9632017-09-14 18:02:31 -0700338 size_t expectedMsgLength = NLMSG_HDRLEN + NLMSG_ALIGN(sizeof(xfrm_usersa_id));
ludi5c81c762017-05-19 13:47:53 -0700339
340 std::vector<uint8_t> nlMsgBuf;
341 EXPECT_CALL(mockSyscalls, writev(_, _))
Jonathan Basseri643d9632017-09-14 18:02:31 -0700342 .WillOnce(DoAll(SaveFlattenedIovecs<1>(&nlMsgBuf), Return(expectedMsgLength)));
ludi5c81c762017-05-19 13:47:53 -0700343 EXPECT_CALL(mockSyscalls, read(_, _))
Jonathan Basseri643d9632017-09-14 18:02:31 -0700344 .WillOnce(DoAll(SetArgSlice<1>(responseSlice), Return(responseSlice)));
ludi5c81c762017-05-19 13:47:53 -0700345
Jonathan Basseri643d9632017-09-14 18:02:31 -0700346 XfrmController ctrl;
ludi5c81c762017-05-19 13:47:53 -0700347 Status res = ctrl.ipSecDeleteSecurityAssociation(
Jonathan Basseri20a17c32017-09-14 17:42:40 -0700348 1 /* resourceId */, static_cast<int>(XfrmDirection::OUT), localAddr, remoteAddr, DROID_SPI);
ludi5c81c762017-05-19 13:47:53 -0700349
Jonathan Basserid6c08582017-09-14 16:10:56 -0700350 EXPECT_TRUE(isOk(res)) << res;
Jonathan Basseri643d9632017-09-14 18:02:31 -0700351 EXPECT_EQ(expectedMsgLength, nlMsgBuf.size());
ludi5c81c762017-05-19 13:47:53 -0700352
353 Slice nlMsgSlice = netdutils::makeSlice(nlMsgBuf);
354 nlMsgSlice = netdutils::drop(nlMsgSlice, NLMSG_HDRLEN);
355
356 xfrm_usersa_id said{};
357 netdutils::extract(nlMsgSlice, said);
358
359 EXPECT_EQ(htonl(DROID_SPI), said.spi);
Jonathan Basseri20a17c32017-09-14 17:42:40 -0700360 expectAddressEquals(family, remoteAddr, said.daddr);
ludi5c81c762017-05-19 13:47:53 -0700361}
362
363} // namespace net
364} // namespace android