Debian Codegraph @

libibverbs/man/ibv_create_flow_action.3.md

raw symbols SCIP
1 ---
2 layout: page
3 title: ibv_flow_action_esp
4 section: 3
5 tagline: Verbs
6 ---
7
8 # NAME
9
10 ibv_flow_action_esp - Flow action esp for verbs
11
12 # SYNOPSIS
13
14 ```c
15 #include <infiniband/verbs.h>
16
17 struct ibv_flow_action *
18 ibv_create_flow_action_esp(struct ibv_context *ctx,
19 struct ibv_flow_action_esp *esp);
20 int
21 ibv_modify_flow_action_esp(struct ibv_flow_action *action,
22 struct ibv_flow_action_esp *esp);
23
24 int ibv_destroy_flow_action(struct ibv_flow_action *action);
25 ```
26
27 # DESCRIPTION
28
29 An IPSEC ESP flow steering action allows a flow steering rule to decrypt or
30 encrypt a packet after matching. Each action contains the necessary
31 information for this operation in the *params* argument.
32
33 After the crypto operation the packet will continue to be processed by flow
34 steering rules until it reaches a final action of discard or delivery.
35
36 After the action is created, then it should be associated with a *struct
37 ibv_flow_attr* using *struct ibv_flow_spec_action_handle* flow specification.
38 Each action can be associated with multiple flows, and *ibv_modify_flow_action_esp*
39 will alter all associated flows simultaneously.
40
41 # ARGUMENTS
42
43 *ctx*
44 : RDMA device context to create the action on.
45
46 *esp*
47 : ESP parameters and key material for the action.
48
49 *action*
50 : Existing action to modify ESP parameters.
51
52 ## *action* Argument
53
54 ```c
55 struct ibv_flow_action_esp {
56 struct ibv_flow_action_esp_attr *esp_attr;
57
58 /* See Key Material */
59 uint16_t keymat_proto;
60 uint16_t keymat_len;
61 void *keymat_ptr;
62
63 /* See Replay Protection */
64 uint16_t replay_proto;
65 uint16_t replay_len;
66 void *replay_ptr;
67
68 struct ibv_flow_action_esp_encap *esp_encap;
69
70 uint32_t comp_mask;
71 uint32_t esn;
72 };
73 ```
74
75 *comp_mask*
76 : Bitmask specifying what fields in the structure are valid.
77
78 *esn*
79 : The starting value of the ESP extended sequence number.
80 Valid only if *IBV_FLOW_ACTION_ESP_MASK_ESN* is set in *comp_mask*.
81
82 The 32 bits of *esn* will be used to compute the full 64 bit ESN
83 required for the AAD construction.
84
85 When in *IB_UVERBS_FLOW_ACTION_ESP_FLAGS_INLINE_CRYPTO* mode, the
86 implementation will automatically track rollover of the lower 32 bits
87 of the ESN. However, an update of the window is required once every
88 2^31 sequences.
89
90 When in *IB_UVERBS_FLOW_ACTION_ESP_FLAGS_FULL_OFFLOAD* mode this value is
91 automatically incremended and it is also used for anti-replay checks.
92
93 *esp_attr*
94 : See *ESP Attributes*. May be NULL on modify.
95
96 *keymat_proto*, *keymat_len*, *keymat_ptr*
97 : Describe the key material and encryption standard to use. May be NULL on
98 modify.
99
100 *replay_proto*, *replay_len*, *replay_ptr*
101 : Describe the replay protection scheme used to manage sequence numbers and
102 prevent replay attacks. This field is only valid in full offload mode.
103 May be NULL on modify.
104
105 *esp_encap*
106 : Describe the encapsulation of ESP packets such as the IP tunnel and/or
107 UDP encapsulation. This field is only valid in full offload mode.
108 May be NULL on modify.
109
110 ## ESP attributes
111
112 ```c
113 struct ibv_flow_action_esp_attr {
114 uint32_t spi;
115 uint32_t seq;
116 uint32_t tfc_pad;
117 uint32_t flags;
118 uint64_t hard_limit_pkts;
119 };
120 ```
121
122 *flags*
123 : A bitwise OR of the various *IB_UVERBS_FLOW_ACTION_ESP_FLAGS* described below.
124
125 *IB_UVERBS_FLOW_ACTION_ESP_FLAGS_DECRYPT*, *IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ENCRYPT*
126 : The action will decrypt or encrypt a packet using the provided
127 keying material.
128
129 The implementation may require that encrypt is only used with an
130 egress flow steering rule, and that decrypt is only used with an
131 ingress flow steering rule.
132
133 ## Full Offload Mode
134
135 When *esp_attr* flag *IB_UVERBS_FLOW_ACTION_ESP_FLAGS_FULL_OFFLOAD* is set the
136 ESP header and trailer are added and removed automatically during the cipher
137 operation. In this case the *esn* and *spi* are used to populate and check
138 the ESP header, and any information from the *keymat* (eg a IV) is placed in
139 the headers and otherwise handled automatically.
140
141 For decrypt the hardware will perform anti-replay.
142
143 Decryption failure will cause the packet to be dropped.
144
145 This action must be combined with the flow steering that identifies the
146 packets protected by the SA defined in this action.
147
148 The following members of the esp_attr are used only in full offload mode:
149
150 *spi*
151 : The value for the ESP Security Parameters Index.
152 It is only used for *IB_UVERBS_FLOW_ACTION_ESP_FLAGS_FULL_OFFLAOD*.
153
154 *seq*
155 : The initial 32 lower bytes of the sequence number.
156 This is the value of the ESP sequence number.
157 It is only used for *IB_UVERBS_FLOW_ACTION_ESP_FLAGS_FULL_OFFLAOD*.
158
159 *tfc_pad*
160 : The length of Traffic Flow Confidentiality Padding as specified by
161 RFC4303. If it is set to zero no additional padding is added.
162 It is only used for *IB_UVERBS_FLOW_ACTION_ESP_FLAGS_FULL_OFFLAOD*.
163
164 *hard_limit_pkts*
165 : The hard lifetime of the SA measured in number of packets.
166 As specified by RFC4301.
167 After this limit is reached the action will drop future packets
168 to prevent breaking the crypto.
169 It is only used for *IB_UVERBS_FLOW_ACTION_ESP_FLAGS_FULL_OFFLAOD*.
170
171 ## Inline Crypto Mode
172
173 When *esp_attr* flag *IB_UVERBS_FLOW_ACTION_ESP_FLAGS_INLINE_CRYPTO* is set
174 the user must providate packets with additional headers.
175
176 For encrypt the packet must contain a fully populated IPSEC packet except the
177 data payload is left un-encrypted and there is no IPsec trailer.
178 If the IV must be unpredictable, then a flag should indicate the transofrmation
179 such as *IB_UVERBS_FLOW_ACTION_IV_ALGO_SEQ*.
180
181 *IB_UVERBS_FLOW_ACTION_IV_ALGO_SEQ* means that the IV is incremented
182 sequentually. If the IV algorithm is supported by HW, then it could provide
183 support for LSO offload with ESP inline crypto.
184
185 Finally, the IV used to encrypt the packet replaces the IV field provided, the
186 payload is encrypted and authenticated, a trailer with padding is added and
187 the ICV is added as well.
188
189 For decrypt the packet is authenticated and decrypted in-place, resulting in a
190 decrypted IPSEC packet with no trailer. The result of decryption and
191 authentication can be retrieved from an extended CQ via the
192 *ibv_wc_read_XXX(3)* function.
193
194 This mode must be combined with the flow steering including
195 *IBV_FLOW_SPEC_IPV4* and *IBV_FLOW_SPEC_ESP* to match the outer packet headers
196 to ensure that the action is only applied to IPSEC packets with the correct
197 identifiers.
198
199 For inline crypto, we have some special requirements to maintain a stateless
200 ESN while maintaining the same parameters as software. The system supports
201 offloading a portion of the IPSEC flow, enabling a single flow to be split
202 between multiple NICs.
203
204 ### Determining the ESN for Ingress Packets
205
206 We require a "modify" command once every 2^31 packets. This
207 modify command allows the implementation in HW to be stateless, as follows:
208
209 ```
210 ESN 1 ESN 2 ESN 3
211 |-------------*-------------|-------------*-------------|-------------*
212 ^ ^ ^ ^ ^ ^
213 ```
214
215 ^ - marks where command invoked to update the SA ESN state machine.
216 | - marks the start of the ESN scope (0-2^32-1). At this point move SA ESN "new_window" bit to zero and increment ESN.
217 * - marks the middle of the ESN scope (2^31). At this point move SA ESN "new_window" bit to one.
218
219 For decryption the implementation uses the following state machine to determine ESN:
220
221 ```c
222 if (!overlap) {
223 use esn // regardless of packet.seq
224 } else { // new_window
225 if (packet.seq >= 2^31)
226 use esn
227 else // packet.seq < 2^31
228 use esn+1
229 }
230 ```
231
232 This mechanism is controlled by the *esp_attr* flag:
233
234 *IB_UVERBS_FLOW_ACTION_ESP_FLAGS_ESN_NEW_WINDOW*
235 : This flag is only used to provide stateless ESN support for inline crypto.
236 It is used only for *IB_UVERBS_FLOW_ACTION_ESP_FLAGS_INLINE_CRYPTO* and
237 *IBV_FLOW_ACTION_ESP_MASK_ESN*.
238
239 Setting this flag indicates that the bottom of the replay window is
240 between 2^31 - 2^32.
241
242 ## Key Material for AES GCM (*IBV_ACTION_ESP_KEYMAT_AES_GCM*)
243
244 The AES GCM crypto algorithm as defined by RFC4106. This struct is to be
245 provided in *keymat_ptr* when *keymat_proto* is set to
246 *IBV_ACTION_ESP_KEYMAT_AES_GCM*.
247
248 ```c
249 struct ibv_flow_action_esp_aes_keymat_aes_gcm {
250 uint64_t iv;
251 uint32_t iv_algo; /* Use enum ib_uverbs_flow_action_esp_aes_gcm_keymat_iv_algo */
252
253 uint32_t salt;
254 uint32_t icv_len;
255
256 uint32_t key_len;
257 uint32_t aes_key[256 / 32];
258 };
259 ```
260
261 *iv*
262 : The starting value for the initialization vector used only with
263 *IB_UVERBS_FLOW_ACTION_ESP_FLAGS_FULL_OFFLOAD* encryption as defined in
264 RFC4106. This field is ignored for
265 *IB_UVERBS_FLOW_ACTION_ESP_FLAGS_INLINE_CRYPTO*.
266
267 For a given key, the IV MUST NOT be reused.
268
269 *iv_algo*
270 : The algorithm used to transform/generate new IVs with
271 *IB_UVERBS_FLOW_ACTION_ESP_FLAGS_FULL_OFFLOAD* encryption.
272
273 The only supported value is *IB_UVERBS_FLOW_ACTION_IV_ALGO_SEQ* to
274 generate sequantial IVs.
275
276 *salt*
277 : The salt as defined by RFC4106.
278
279 *icv_len*
280 : The length of the Integrity Check Value in bytes as defined by RFC4106.
281
282 *aes_key*, *key_len*
283 : The cipher key data. It must be either 16, 24 or 32 bytes as defined by RFC4106.
284
285 ## Bitmap Replay Protection (*IBV_FLOW_ACTION_ESP_REPLAY_BMP*)
286
287 A shifting bitmap is used to identify which packets have already been
288 transmitted. Each bit in the bitmap represents a packet, it is set if a packet
289 with this ESP sequence number has been received and it passed authentication.
290 If a packet with the same sequence is received, then the bit is already set,
291 causing replay protection to drop the packet. The bitmap represents a window
292 of *size* sequence numbers. If a newer sequence number is received, then the
293 bitmap will shift to represent this as in RFC6479. The replay window cannot
294 shift more than 2^31 sequence numbers forward.
295
296 This struct is to be provided in *replay_ptr* when *reply_proto* is set to
297 *IBV_FLOW_ACTION_ESP_REPLAY_BMP*. In this mode reply_ptr and reply_len should
298 point to a struct ibv_flow_action_esp_replay_bmp containing:
299 *size*
300 : The size of the bitmap.
301
302 ## ESP Encapsulation
303
304 An *esp_encap* specification is required when *eps_attr* flags
305 *IB_UVERBS_FLOW_ACTION_ESP_FLAGS_TUNNEL* is set. It is used to provide the fields
306 for the encapsulation header that is added/removed to/from packets.
307 Tunnel and Transport mode are defined as in RFC4301.
308 UDP encapsulation of ESP can be specified by providing the appropriate UDP header.
309
310 This setting is only used in *IB_UVERBS_FLOW_ACTION_ESP_FLAGS_FULL_OFFLOAD*
311 mode.
312
313 ```C
314 struct ibv_flow_action_esp_encap {
315 void *val; /* pointer to struct ibv_flow_xxxx_filter */
316 struct ibv_flow_action_esp_encap *next_ptr;
317 uint16_t len; /* Len of mask and pointer (separately) */
318 uint16_t type; /* Use flow_spec enum */
319 };
320 ```
321
322 Each link in the list specifies a network header in the same manner as the flow steering API.
323 The header should be selected from a supported header in 'enum ibv_flow_spec_type'.
324
325 # RETURN VALUE
326
327 Upon success *ibv_create_flow_action_esp* will return a new *struct
328 ibv_flow_action* object, on error NULL will be returned and errno will be set.
329
330 Upon success *ibv_modify_action_esp* will return 0. On error the value of
331 errno will be returned. If ibv_modify_flow_action fails, it is guaranteed that
332 the last action still holds. If it succeeds, there is a point in the future
333 where the old action is applied on all packets until this point and the new
334 one is applied on all packets from this point and on.
335
336 # SEE ALSO
337
338 *ibv_create_flow(3)*, *ibv_destroy_action(3)*, *RFC 4106*