blob: 4f167c5f12b02540fbde3cd37bda9f6c6b36b452 [file] [log] [blame]
Nathan Harold1a371532017-01-30 12:30:48 -08001/*
2 * Copyright (C) 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#ifndef _XFRM_CONTROLLER_H
17#define _XFRM_CONTROLLER_H
18
19#include <atomic>
20#include <list>
21#include <map>
22#include <string>
23#include <utility> // for pair
24
Benedict Wong319f17e2018-05-15 17:06:44 -070025#include <linux/if.h>
manojboopathi8707f232018-01-02 14:45:47 -080026#include <linux/if_link.h>
27#include <linux/if_tunnel.h>
Nathan Harold1a371532017-01-30 12:30:48 -080028#include <linux/netlink.h>
Nathan Harold420ceac2017-04-05 19:36:59 -070029#include <linux/udp.h>
Nathan Harold1a371532017-01-30 12:30:48 -080030#include <linux/xfrm.h>
Bernie Innocenti97f388f2018-10-16 19:17:08 +090031#include <unistd.h>
Nathan Harold1a371532017-01-30 12:30:48 -080032
33#include "NetdConstants.h"
Bernie Innocenti97f388f2018-10-16 19:17:08 +090034#include "android-base/unique_fd.h"
Luke Huangb257d612019-03-14 21:19:13 +080035#include "netdutils/DumpWriter.h"
manojboopathi8707f232018-01-02 14:45:47 -080036#include "netdutils/Slice.h"
ludi6e8eccd2017-08-14 14:40:37 -070037#include "netdutils/Status.h"
Bernie Innocenti97f388f2018-10-16 19:17:08 +090038#include "sysutils/SocketClient.h"
Nathan Harold1a371532017-01-30 12:30:48 -080039
40namespace android {
41namespace net {
42
Nathan Harold39b5df42017-08-02 18:45:25 -070043// Exposed for testing
44extern const uint32_t ALGO_MASK_AUTH_ALL;
45// Exposed for testing
46extern const uint32_t ALGO_MASK_CRYPT_ALL;
47// Exposed for testing
Benedict Wongbe65b432017-08-22 21:43:14 -070048extern const uint32_t ALGO_MASK_AEAD_ALL;
49// Exposed for testing
Nathan Harold39b5df42017-08-02 18:45:25 -070050extern const uint8_t REPLAY_WINDOW_SIZE;
51
Nathan Harold1a371532017-01-30 12:30:48 -080052// Suggest we avoid the smallest and largest ints
53class XfrmMessage;
54class TransportModeSecurityAssociation;
55
56class XfrmSocket {
57public:
Maciej Żenczykowski8dc60de2020-04-30 16:44:50 -070058 // called from destructor and thus cannot be virtual
59 void close() {
Nathan Harold420ceac2017-04-05 19:36:59 -070060 if (mSock >= 0) {
Nathan Harold1a371532017-01-30 12:30:48 -080061 ::close(mSock);
62 }
63 mSock = -1;
64 }
65
ludi6e8eccd2017-08-14 14:40:37 -070066 virtual netdutils::Status open() = 0;
Nathan Harold1a371532017-01-30 12:30:48 -080067
68 virtual ~XfrmSocket() { close(); }
69
ludie51e3862017-08-15 19:28:12 -070070 // Sends the netlink message contained in iovecs. This populates iovecs[0] with
71 // a valid netlink message header.
ludi6e8eccd2017-08-14 14:40:37 -070072 virtual netdutils::Status sendMessage(uint16_t nlMsgType, uint16_t nlMsgFlags,
73 uint16_t nlMsgSeqNum,
74 std::vector<iovec>* iovecs) const = 0;
Nathan Harold1a371532017-01-30 12:30:48 -080075
76protected:
77 int mSock;
78};
79
80enum struct XfrmDirection : uint8_t {
81 IN = XFRM_POLICY_IN,
82 OUT = XFRM_POLICY_OUT,
83 FORWARD = XFRM_POLICY_FWD,
84 MASK = XFRM_POLICY_MASK,
85};
86
87enum struct XfrmMode : uint8_t {
88 TRANSPORT = XFRM_MODE_TRANSPORT,
89 TUNNEL = XFRM_MODE_TUNNEL,
90};
91
Nathan Harold420ceac2017-04-05 19:36:59 -070092enum struct XfrmEncapType : uint16_t {
93 NONE = 0,
94 ESPINUDP_NON_IKE = UDP_ENCAP_ESPINUDP_NON_IKE,
95 ESPINUDP = UDP_ENCAP_ESPINUDP
96};
97
Nathan Harold1a371532017-01-30 12:30:48 -080098struct XfrmAlgo {
99 std::string name;
100 std::vector<uint8_t> key;
101 uint16_t truncLenBits;
102};
103
Nathan Harold420ceac2017-04-05 19:36:59 -0700104struct XfrmEncap {
105 XfrmEncapType type;
106 uint16_t srcPort;
107 uint16_t dstPort;
108};
109
Nathan Harolddf59bc02021-02-05 15:12:49 -0800110struct XfrmEndpointPair {
Nathan Harold1a371532017-01-30 12:30:48 -0800111 xfrm_address_t dstAddr; // network order
112 xfrm_address_t srcAddr;
113 int addrFamily; // AF_INET or AF_INET6
Nathan Harolddf59bc02021-02-05 15:12:49 -0800114};
115
116// minimally sufficient structure to match either an SA or a Policy
117struct XfrmCommonInfo : XfrmEndpointPair {
Nathan Harold1a371532017-01-30 12:30:48 -0800118 int transformId; // requestId
119 int spi;
Di Lu2ccb3e52018-01-03 16:19:20 -0800120 xfrm_mark mark;
Benedict Wonga450e722018-05-07 10:29:02 -0700121 int xfrm_if_id;
Nathan Harold47189212021-02-05 15:30:47 -0800122 XfrmMode mode;
Nathan Harold1a371532017-01-30 12:30:48 -0800123};
124
Benedict Wonga04ffa72018-05-09 21:42:42 -0700125struct XfrmSaInfo : XfrmCommonInfo {
Nathan Harold1a371532017-01-30 12:30:48 -0800126 XfrmAlgo auth;
127 XfrmAlgo crypt;
Benedict Wongbe65b432017-08-22 21:43:14 -0700128 XfrmAlgo aead;
Nathan Harold1a371532017-01-30 12:30:48 -0800129 int netId;
Nathan Harold420ceac2017-04-05 19:36:59 -0700130 XfrmEncap encap;
Nathan Harold1a371532017-01-30 12:30:48 -0800131};
132
Nathan Harold47189212021-02-05 15:30:47 -0800133struct XfrmSpInfo : XfrmCommonInfo {
Benedict Wonga04ffa72018-05-09 21:42:42 -0700134 // Address family in XfrmCommonInfo used for template/SA matching, need separate addrFamily
135 // for selectors
136 int selAddrFamily; // AF_INET or AF_INET6
Nathan Harolda5d6c9d2021-02-05 15:30:47 -0800137 XfrmDirection direction;
Benedict Wonga04ffa72018-05-09 21:42:42 -0700138};
139
Nathan Harold47189212021-02-05 15:30:47 -0800140struct XfrmMigrateInfo : XfrmSpInfo {
141 XfrmEndpointPair newEndpointInfo;
142};
143
Nathan Haroldc8737b82019-02-25 09:45:38 -0800144/*
145 * This is a workaround for a kernel bug in the 32bit netlink compat layer
146 * that has been present on x86_64 kernels since 2010 with no fix on the
147 * horizon.
148 *
149 * Below is a redefinition of the xfrm_usersa_info struct that is part
150 * of the Linux uapi <linux/xfrm.h> to align the structures to a 64-bit
151 * boundary.
152 *
153 * Note that we turn this on for all x86 32bit targets, under the assumption
154 * that nowadays all x86 targets are running 64bit kernels.
155 */
156#if defined(__i386__)
157// Shadow the kernel definition of xfrm_usersa_info with a 64-bit aligned version
158struct xfrm_usersa_info : ::xfrm_usersa_info {
159} __attribute__((aligned(8)));
160// Shadow the kernel's version, using the aligned version of xfrm_usersa_info
161struct xfrm_userspi_info {
162 struct xfrm_usersa_info info;
163 __u32 min;
164 __u32 max;
165};
166struct xfrm_userpolicy_info : ::xfrm_userpolicy_info {
167} __attribute__((aligned(8)));
168
169/*
170 * Anyone who encounters a failure when sending netlink messages should look here
171 * first. Hitting the static_assert() below should be a strong hint that Android
172 * IPsec will probably not work with your current settings.
173 *
174 * Again, experimentally determined, the "flags" field should be the first byte in
175 * the final word of the xfrm_usersa_info struct. The check validates the size of
176 * the padding to be 7.
177 *
178 * This padding is verified to be correct on gcc/x86_64 kernel, and clang/x86 userspace.
179 */
180static_assert(sizeof(::xfrm_usersa_info) % 8 != 0,
181 "struct xfrm_usersa_info has changed "
182 "alignment. Please consider whether this "
183 "patch is needed.");
184static_assert(sizeof(xfrm_usersa_info) - offsetof(xfrm_usersa_info, flags) == 8,
185 "struct xfrm_usersa_info probably misaligned with kernel struct.");
186static_assert(sizeof(xfrm_usersa_info) % 8 == 0,
187 "struct xfrm_usersa_info_t is not 64-bit "
188 "aligned. Please consider whether this patch "
189 "is needed.");
190static_assert(sizeof(::xfrm_userspi_info) - sizeof(::xfrm_usersa_info) ==
191 sizeof(xfrm_userspi_info) - sizeof(xfrm_usersa_info),
192 "struct xfrm_userspi_info has changed and does not match the kernel struct.");
193static_assert(sizeof(::xfrm_userpolicy_info) % 8 != 0,
194 "struct xfrm_userpolicy_info has changed "
195 "alignment. Please consider whether this "
196 "patch is needed.");
197static_assert(sizeof(xfrm_userpolicy_info) - offsetof(xfrm_userpolicy_info, share) == 5,
198 "struct xfrm_userpolicy_info probably misaligned with kernel struct.");
199static_assert(sizeof(xfrm_userpolicy_info) % 8 == 0,
200 "struct xfrm_userpolicy_info is not 64-bit "
201 "aligned. Please consider whether this patch "
202 "is needed.");
203#endif
204
Nathan Harold1a371532017-01-30 12:30:48 -0800205class XfrmController {
206public:
207 XfrmController();
208
Benedict Wongaf855432018-05-10 17:07:37 -0700209 // Initializer to override XFRM-I support for unit-testing purposes
210 explicit XfrmController(bool xfrmIntfSupport);
211
Nathan Harold21299f72018-03-16 20:13:03 -0700212 static netdutils::Status Init();
Benedict Wongb2daefb2017-12-06 22:05:46 -0800213
Luke Huange203a152018-11-23 11:47:28 +0800214 static netdutils::Status ipSecSetEncapSocketOwner(int socketFd, int newUid, uid_t callerUid);
Nathan Harold1a371532017-01-30 12:30:48 -0800215
Nathan Harold21299f72018-03-16 20:13:03 -0700216 static netdutils::Status ipSecAllocateSpi(int32_t transformId, const std::string& localAddress,
217 const std::string& remoteAddress, int32_t inSpi,
218 int32_t* outSpi);
219
220 static netdutils::Status ipSecAddSecurityAssociation(
Benedict Wonga450e722018-05-07 10:29:02 -0700221 int32_t transformId, int32_t mode, const std::string& sourceAddress,
222 const std::string& destinationAddress, int32_t underlyingNetId, int32_t spi,
223 int32_t markValue, int32_t markMask, const std::string& authAlgo,
224 const std::vector<uint8_t>& authKey, int32_t authTruncBits,
225 const std::string& cryptAlgo, const std::vector<uint8_t>& cryptKey,
226 int32_t cryptTruncBits, const std::string& aeadAlgo,
227 const std::vector<uint8_t>& aeadKey, int32_t aeadIcvBits, int32_t encapType,
228 int32_t encapLocalPort, int32_t encapRemotePort, int32_t xfrmInterfaceId);
Nathan Harold1a371532017-01-30 12:30:48 -0800229
Nathan Harold21299f72018-03-16 20:13:03 -0700230 static netdutils::Status ipSecDeleteSecurityAssociation(int32_t transformId,
231 const std::string& sourceAddress,
232 const std::string& destinationAddress,
233 int32_t spi, int32_t markValue,
Benedict Wonga450e722018-05-07 10:29:02 -0700234 int32_t markMask,
235 int32_t xfrmInterfaceId);
Nathan Harold1a371532017-01-30 12:30:48 -0800236
Luke Huange203a152018-11-23 11:47:28 +0800237 static netdutils::Status ipSecApplyTransportModeTransform(int socketFd, int32_t transformId,
238 int32_t direction,
239 const std::string& localAddress,
240 const std::string& remoteAddress,
241 int32_t spi);
Nathan Harold1a371532017-01-30 12:30:48 -0800242
Luke Huange203a152018-11-23 11:47:28 +0800243 static netdutils::Status ipSecRemoveTransportModeTransform(int socketFd);
Nathan Harold1a371532017-01-30 12:30:48 -0800244
Benedict Wonga04ffa72018-05-09 21:42:42 -0700245 static netdutils::Status ipSecAddSecurityPolicy(int32_t transformId, int32_t selAddrFamily,
246 int32_t direction,
Benedict Wongad600cb2018-05-14 17:22:35 -0700247 const std::string& tmplSrcAddress,
248 const std::string& tmplDstAddress, int32_t spi,
Benedict Wonga450e722018-05-07 10:29:02 -0700249 int32_t markValue, int32_t markMask,
250 int32_t xfrmInterfaceId);
ludi771b8002017-11-20 15:09:05 -0800251
Benedict Wonga04ffa72018-05-09 21:42:42 -0700252 static netdutils::Status ipSecUpdateSecurityPolicy(int32_t transformId, int32_t selAddrFamily,
253 int32_t direction,
Benedict Wongad600cb2018-05-14 17:22:35 -0700254 const std::string& tmplSrcAddress,
255 const std::string& tmplDstAddress,
Nathan Harold21299f72018-03-16 20:13:03 -0700256 int32_t spi, int32_t markValue,
Benedict Wonga450e722018-05-07 10:29:02 -0700257 int32_t markMask, int32_t xfrmInterfaceId);
ludi771b8002017-11-20 15:09:05 -0800258
Benedict Wonga04ffa72018-05-09 21:42:42 -0700259 static netdutils::Status ipSecDeleteSecurityPolicy(int32_t transformId, int32_t selAddrFamily,
260 int32_t direction, int32_t markValue,
Benedict Wonga450e722018-05-07 10:29:02 -0700261 int32_t markMask, int32_t xfrmInterfaceId);
ludi771b8002017-11-20 15:09:05 -0800262
Benedict Wong319f17e2018-05-15 17:06:44 -0700263 static netdutils::Status ipSecAddTunnelInterface(const std::string& deviceName,
264 const std::string& localAddress,
265 const std::string& remoteAddress, int32_t ikey,
Benedict Wonga450e722018-05-07 10:29:02 -0700266 int32_t okey, int32_t interfaceId,
267 bool isUpdate);
manojboopathi8707f232018-01-02 14:45:47 -0800268
Benedict Wong319f17e2018-05-15 17:06:44 -0700269 static netdutils::Status ipSecRemoveTunnelInterface(const std::string& deviceName);
manojboopathi8707f232018-01-02 14:45:47 -0800270
Nathan Harold47189212021-02-05 15:30:47 -0800271 // Only available for Tunnel must already have a matching tunnel SA and policy
272 static netdutils::Status ipSecMigrate(int32_t transformId, int32_t selAddrFamily,
273 int32_t direction, const std::string& oldSourceAddress,
274 const std::string& oldDestinationAddress,
275 const std::string& newSourceAddress,
276 const std::string& newDestinationAddress,
277 int32_t xfrmInterfaceId);
Luke Huangb257d612019-03-14 21:19:13 +0800278 void dump(netdutils::DumpWriter& dw);
Benedict Wongaf855432018-05-10 17:07:37 -0700279
Jonathan Basseric6461a62017-08-31 14:47:33 -0700280 // Some XFRM netlink attributes comprise a header, a struct, and some data
281 // after the struct. We wrap all of those in one struct for easier
282 // marshalling. The structs below must be ABI compatible with the kernel and
283 // are composed from kernel structures; thus, they use the kernel naming
284 // convention.
285
Nathan Harold39b5df42017-08-02 18:45:25 -0700286 // Exposed for testing
Benedict Wong4f60ee12017-10-10 12:27:25 -0700287 static constexpr size_t MAX_KEY_LENGTH = 128;
Nathan Harold39b5df42017-08-02 18:45:25 -0700288
Jonathan Basseric6461a62017-08-31 14:47:33 -0700289 // Container for the content of an XFRMA_ALG_CRYPT netlink attribute.
Nathan Harold39b5df42017-08-02 18:45:25 -0700290 // Exposed for testing
291 struct nlattr_algo_crypt {
292 nlattr hdr;
293 xfrm_algo crypt;
Benedict Wong4f60ee12017-10-10 12:27:25 -0700294 uint8_t key[MAX_KEY_LENGTH];
Nathan Harold39b5df42017-08-02 18:45:25 -0700295 };
296
Jonathan Basseric6461a62017-08-31 14:47:33 -0700297 // Container for the content of an XFRMA_ALG_AUTH_TRUNC netlink attribute.
Nathan Harold39b5df42017-08-02 18:45:25 -0700298 // Exposed for testing
299 struct nlattr_algo_auth {
300 nlattr hdr;
301 xfrm_algo_auth auth;
Benedict Wong4f60ee12017-10-10 12:27:25 -0700302 uint8_t key[MAX_KEY_LENGTH];
Nathan Harold39b5df42017-08-02 18:45:25 -0700303 };
304
Jonathan Basseric6461a62017-08-31 14:47:33 -0700305 // Container for the content of an XFRMA_TMPL netlink attribute.
Nathan Harold39b5df42017-08-02 18:45:25 -0700306 // Exposed for testing
Benedict Wongbe65b432017-08-22 21:43:14 -0700307 struct nlattr_algo_aead {
308 nlattr hdr;
309 xfrm_algo_aead aead;
Benedict Wong4f60ee12017-10-10 12:27:25 -0700310 uint8_t key[MAX_KEY_LENGTH];
Benedict Wongbe65b432017-08-22 21:43:14 -0700311 };
312
313 // Exposed for testing
Nathan Harold39b5df42017-08-02 18:45:25 -0700314 struct nlattr_user_tmpl {
315 nlattr hdr;
316 xfrm_user_tmpl tmpl;
317 };
318
Jonathan Basseric6461a62017-08-31 14:47:33 -0700319 // Container for the content of an XFRMA_ENCAP netlink attribute.
Nathan Harold39b5df42017-08-02 18:45:25 -0700320 // Exposed for testing
321 struct nlattr_encap_tmpl {
322 nlattr hdr;
323 xfrm_encap_tmpl tmpl;
324 };
325
Di Lu2ccb3e52018-01-03 16:19:20 -0800326 // Container for the content of an XFRMA_MARK netlink attribute.
327 // Exposed for testing
328 struct nlattr_xfrm_mark {
329 nlattr hdr;
330 xfrm_mark mark;
331 };
332
Benedict Wong96abf482018-01-22 13:56:41 -0800333 // Container for the content of an XFRMA_OUTPUT_MARK netlink attribute.
334 // Exposed for testing
335 struct nlattr_xfrm_output_mark {
336 nlattr hdr;
337 __u32 outputMark;
338 };
339
Benedict Wong319f17e2018-05-15 17:06:44 -0700340 // Container for the content of an XFRMA_IF_ID netlink attribute.
341 // Exposed for testing
342 struct nlattr_xfrm_interface_id {
343 nlattr hdr;
344 __u32 if_id;
345 };
346
Nathan Harold47189212021-02-05 15:30:47 -0800347 // Container for the content of an XFRMA_MIGRATE netlink attribute.
348 // Exposed for testing
349 struct nlattr_xfrm_user_migrate {
350 nlattr hdr;
351 xfrm_user_migrate migrate;
352 };
353
Benedict Wong319f17e2018-05-15 17:06:44 -0700354 // Exposed for testing
355 struct nlattr_payload_u32 {
356 nlattr hdr;
357 uint32_t value;
358 };
359
360 private:
Benedict Wongaf855432018-05-10 17:07:37 -0700361 static bool isXfrmIntfSupported();
362
Nathan Harolddf59bc02021-02-05 15:12:49 -0800363 static netdutils::Status fillXfrmEndpointPair(const std::string& sourceAddress,
364 const std::string& destinationAddress,
365 XfrmEndpointPair* info);
Benedict Wonga04ffa72018-05-09 21:42:42 -0700366 // helper functions for filling in the XfrmCommonInfo (and XfrmSaInfo) structure
367 static netdutils::Status fillXfrmCommonInfo(const std::string& sourceAddress,
368 const std::string& destinationAddress, int32_t spi,
369 int32_t markValue, int32_t markMask,
Benedict Wonga450e722018-05-07 10:29:02 -0700370 int32_t transformId, int32_t xfrmInterfaceId,
371 XfrmCommonInfo* info);
Benedict Wonga04ffa72018-05-09 21:42:42 -0700372 static netdutils::Status fillXfrmCommonInfo(int32_t spi, int32_t markValue, int32_t markMask,
Benedict Wonga450e722018-05-07 10:29:02 -0700373 int32_t transformId, int32_t xfrmInterfaceId,
374 XfrmCommonInfo* info);
Nathan Harold1a371532017-01-30 12:30:48 -0800375
376 // Top level functions for managing a Transport Mode Transform
ludi6e8eccd2017-08-14 14:40:37 -0700377 static netdutils::Status addTransportModeTransform(const XfrmSaInfo& record);
Nathan Harold1a371532017-01-30 12:30:48 -0800378 static int removeTransportModeTransform(const XfrmSaInfo& record);
379
380 // TODO(messagerefactor): FACTOR OUT ALL MESSAGE BUILDING CODE BELOW HERE
381 // Shared between SA and SP
Benedict Wonga04ffa72018-05-09 21:42:42 -0700382 static void fillXfrmSelector(const int record, xfrm_selector* selector);
Nathan Harold1a371532017-01-30 12:30:48 -0800383
384 // Shared between Transport and Tunnel Mode
385 static int fillNlAttrXfrmAlgoEnc(const XfrmAlgo& in_algo, nlattr_algo_crypt* algo);
386 static int fillNlAttrXfrmAlgoAuth(const XfrmAlgo& in_algo, nlattr_algo_auth* algo);
Benedict Wongbe65b432017-08-22 21:43:14 -0700387 static int fillNlAttrXfrmAlgoAead(const XfrmAlgo& in_algo, nlattr_algo_aead* algo);
Nathan Harold420ceac2017-04-05 19:36:59 -0700388 static int fillNlAttrXfrmEncapTmpl(const XfrmSaInfo& record, nlattr_encap_tmpl* tmpl);
Nathan Harold1a371532017-01-30 12:30:48 -0800389
Di Lu0e16b5e2018-01-12 10:37:53 -0800390 // Functions for updating a Transport Mode SA
391 static netdutils::Status updateSecurityAssociation(const XfrmSaInfo& record,
manojboopathi4d2d6f12017-12-06 11:11:31 -0800392 const XfrmSocket& sock);
Nathan Harold1a371532017-01-30 12:30:48 -0800393 static int fillUserSaInfo(const XfrmSaInfo& record, xfrm_usersa_info* usersa);
394
395 // Functions for deleting a Transport Mode SA
Benedict Wonga04ffa72018-05-09 21:42:42 -0700396 static netdutils::Status deleteSecurityAssociation(const XfrmCommonInfo& record,
ludi6e8eccd2017-08-14 14:40:37 -0700397 const XfrmSocket& sock);
Benedict Wonga04ffa72018-05-09 21:42:42 -0700398 static int fillUserSaId(const XfrmCommonInfo& record, xfrm_usersa_id* said);
Maciej Żenczykowski322c9ee2020-04-22 09:44:19 -0700399 static void fillUserTemplate(const XfrmSpInfo& record, xfrm_user_tmpl* tmpl);
ludi771b8002017-11-20 15:09:05 -0800400
Nathan Harolda5d6c9d2021-02-05 15:30:47 -0800401 static int fillUserSpInfo(const XfrmSpInfo& record, xfrm_userpolicy_info* usersp);
Benedict Wonga04ffa72018-05-09 21:42:42 -0700402 static int fillNlAttrUserTemplate(const XfrmSpInfo& record, nlattr_user_tmpl* tmpl);
Nathan Harolda5d6c9d2021-02-05 15:30:47 -0800403 static int fillUserPolicyId(const XfrmSpInfo& record, xfrm_userpolicy_id* policy_id);
Benedict Wonga04ffa72018-05-09 21:42:42 -0700404 static int fillNlAttrXfrmMark(const XfrmCommonInfo& record, nlattr_xfrm_mark* mark);
Benedict Wong73119c22021-04-20 00:07:13 -0700405 static int fillNlAttrXfrmOutputMark(const XfrmSaInfo& record,
Benedict Wong96abf482018-01-22 13:56:41 -0800406 nlattr_xfrm_output_mark* output_mark);
Benedict Wong319f17e2018-05-15 17:06:44 -0700407 static int fillNlAttrXfrmIntfId(const __u32 intf_id_value, nlattr_xfrm_interface_id* intf_id);
Nathan Harold47189212021-02-05 15:30:47 -0800408 static int fillNlAttrXfrmMigrate(const XfrmMigrateInfo& record,
409 nlattr_xfrm_user_migrate* migrate);
Nathan Harold1a371532017-01-30 12:30:48 -0800410
ludi6e8eccd2017-08-14 14:40:37 -0700411 static netdutils::Status allocateSpi(const XfrmSaInfo& record, uint32_t minSpi, uint32_t maxSpi,
412 uint32_t* outSpi, const XfrmSocket& sock);
Nathan Harold1a371532017-01-30 12:30:48 -0800413
Benedict Wonga04ffa72018-05-09 21:42:42 -0700414 static netdutils::Status processSecurityPolicy(int32_t transformId, int32_t selAddrFamily,
415 int32_t direction,
Benedict Wongad600cb2018-05-14 17:22:35 -0700416 const std::string& tmplSrcAddress,
417 const std::string& tmplDstAddress, int32_t spi,
Nathan Harold21299f72018-03-16 20:13:03 -0700418 int32_t markValue, int32_t markMask,
Benedict Wonga450e722018-05-07 10:29:02 -0700419 int32_t xfrmInterfaceId, int32_t msgType);
Benedict Wonga04ffa72018-05-09 21:42:42 -0700420 static netdutils::Status updateTunnelModeSecurityPolicy(const XfrmSpInfo& record,
ludi771b8002017-11-20 15:09:05 -0800421 const XfrmSocket& sock,
ludi771b8002017-11-20 15:09:05 -0800422 uint16_t msgType);
Benedict Wonga04ffa72018-05-09 21:42:42 -0700423 static netdutils::Status deleteTunnelModeSecurityPolicy(const XfrmSpInfo& record,
Nathan Harolda5d6c9d2021-02-05 15:30:47 -0800424 const XfrmSocket& sock);
Nathan Harold47189212021-02-05 15:30:47 -0800425 static netdutils::Status migrate(const XfrmMigrateInfo& record, const XfrmSocket& sock);
Nathan Harold21299f72018-03-16 20:13:03 -0700426 static netdutils::Status flushInterfaces();
427 static netdutils::Status flushSaDb(const XfrmSocket& s);
428 static netdutils::Status flushPolicyDb(const XfrmSocket& s);
429
Benedict Wong319f17e2018-05-15 17:06:44 -0700430 static netdutils::Status ipSecAddXfrmInterface(const std::string& deviceName,
Benedict Wongaf855432018-05-10 17:07:37 -0700431 int32_t interfaceId, uint16_t flags);
Benedict Wong319f17e2018-05-15 17:06:44 -0700432 static netdutils::Status ipSecAddVirtualTunnelInterface(const std::string& deviceName,
433 const std::string& localAddress,
434 const std::string& remoteAddress,
435 int32_t ikey, int32_t okey,
436 uint16_t flags);
Nathan Harold1a371532017-01-30 12:30:48 -0800437 // END TODO(messagerefactor)
438};
439
440} // namespace net
441} // namespace android
442
443#endif /* !defined(XFRM_CONTROLLER_H) */