@@ -46,13 +46,17 @@ static int uverbs_free_flow_action(struct ib_uobject *uobject,
4646}
4747
4848static u64 esp_flags_uverbs_to_verbs (struct uverbs_attr_bundle * attrs ,
49- u32 flags )
49+ u32 flags , bool is_modify )
5050{
5151 u64 verbs_flags = flags ;
5252
5353 if (uverbs_attr_is_valid (attrs , UVERBS_ATTR_FLOW_ACTION_ESP_ESN ))
5454 verbs_flags |= IB_FLOW_ACTION_ESP_FLAGS_ESN_TRIGGERED ;
5555
56+ if (is_modify && uverbs_attr_is_valid (attrs ,
57+ UVERBS_ATTR_FLOW_ACTION_ESP_ATTRS ))
58+ verbs_flags |= IB_FLOW_ACTION_ESP_FLAGS_MOD_ESP_ATTRS ;
59+
5660 return verbs_flags ;
5761};
5862
@@ -81,6 +85,32 @@ static int (* const flow_action_esp_keymat_validate[])(struct ib_flow_action_att
8185 [IB_UVERBS_FLOW_ACTION_ESP_KEYMAT_AES_GCM ] = validate_flow_action_esp_keymat_aes_gcm ,
8286};
8387
88+ static int flow_action_esp_replay_none (struct ib_flow_action_attrs_esp_replays * replay ,
89+ bool is_modify )
90+ {
91+ /* This is used in order to modify an esp flow action with an enabled
92+ * replay protection to a disabled one. This is only supported via
93+ * modify, as in create verb we can simply drop the REPLAY attribute and
94+ * achieve the same thing.
95+ */
96+ return is_modify ? 0 : - EINVAL ;
97+ }
98+
99+ static int flow_action_esp_replay_def_ok (struct ib_flow_action_attrs_esp_replays * replay ,
100+ bool is_modify )
101+ {
102+ /* Some replay protections could always be enabled without validating
103+ * anything.
104+ */
105+ return 0 ;
106+ }
107+
108+ static int (* const flow_action_esp_replay_validate [])(struct ib_flow_action_attrs_esp_replays * replay ,
109+ bool is_modify ) = {
110+ [IB_UVERBS_FLOW_ACTION_ESP_REPLAY_NONE ] = flow_action_esp_replay_none ,
111+ [IB_UVERBS_FLOW_ACTION_ESP_REPLAY_BMP ] = flow_action_esp_replay_def_ok ,
112+ };
113+
84114static int parse_esp_ip (enum ib_flow_spec_type proto ,
85115 const void __user * val_ptr ,
86116 size_t len , union ib_flow_spec * out )
@@ -194,7 +224,8 @@ struct ib_flow_action_esp_attr {
194224static int parse_flow_action_esp (struct ib_device * ib_dev ,
195225 struct ib_uverbs_file * file ,
196226 struct uverbs_attr_bundle * attrs ,
197- struct ib_flow_action_esp_attr * esp_attr )
227+ struct ib_flow_action_esp_attr * esp_attr ,
228+ bool is_modify )
198229{
199230 struct ib_uverbs_flow_action_esp uverbs_esp = {};
200231 int ret ;
@@ -222,7 +253,8 @@ static int parse_flow_action_esp(struct ib_device *ib_dev,
222253 esp_attr -> hdr .tfc_pad = uverbs_esp .tfc_pad ;
223254 esp_attr -> hdr .hard_limit_pkts = uverbs_esp .hard_limit_pkts ;
224255 }
225- esp_attr -> hdr .flags = esp_flags_uverbs_to_verbs (attrs , uverbs_esp .flags );
256+ esp_attr -> hdr .flags = esp_flags_uverbs_to_verbs (attrs , uverbs_esp .flags ,
257+ is_modify );
226258
227259 if (uverbs_attr_is_valid (attrs , UVERBS_ATTR_FLOW_ACTION_ESP_KEYMAT )) {
228260 esp_attr -> keymat .protocol =
@@ -252,6 +284,11 @@ static int parse_flow_action_esp(struct ib_device *ib_dev,
252284 if (ret )
253285 return ret ;
254286
287+ ret = flow_action_esp_replay_validate [esp_attr -> replay .protocol ](& esp_attr -> replay ,
288+ is_modify );
289+ if (ret )
290+ return ret ;
291+
255292 esp_attr -> hdr .replay = & esp_attr -> replay ;
256293 }
257294
@@ -278,7 +315,7 @@ static int UVERBS_HANDLER(UVERBS_METHOD_FLOW_ACTION_ESP_CREATE)(struct ib_device
278315 if (!ib_dev -> create_flow_action_esp )
279316 return - EOPNOTSUPP ;
280317
281- ret = parse_flow_action_esp (ib_dev , file , attrs , & esp_attr );
318+ ret = parse_flow_action_esp (ib_dev , file , attrs , & esp_attr , false );
282319 if (ret )
283320 return ret ;
284321
@@ -297,6 +334,33 @@ static int UVERBS_HANDLER(UVERBS_METHOD_FLOW_ACTION_ESP_CREATE)(struct ib_device
297334 return 0 ;
298335}
299336
337+ static int UVERBS_HANDLER (UVERBS_METHOD_FLOW_ACTION_ESP_MODIFY )(struct ib_device * ib_dev ,
338+ struct ib_uverbs_file * file ,
339+ struct uverbs_attr_bundle * attrs )
340+ {
341+ int ret ;
342+ struct ib_uobject * uobj ;
343+ struct ib_flow_action * action ;
344+ struct ib_flow_action_esp_attr esp_attr = {};
345+
346+ if (!ib_dev -> modify_flow_action_esp )
347+ return - EOPNOTSUPP ;
348+
349+ ret = parse_flow_action_esp (ib_dev , file , attrs , & esp_attr , true);
350+ if (ret )
351+ return ret ;
352+
353+ uobj = uverbs_attr_get (attrs , UVERBS_ATTR_FLOW_ACTION_ESP_HANDLE )-> obj_attr .uobject ;
354+ action = uobj -> object ;
355+
356+ if (action -> type != IB_FLOW_ACTION_ESP )
357+ return - EINVAL ;
358+
359+ return ib_dev -> modify_flow_action_esp (action ,
360+ & esp_attr .hdr ,
361+ attrs );
362+ }
363+
300364static const struct uverbs_attr_spec uverbs_flow_action_esp_keymat [] = {
301365 [IB_UVERBS_FLOW_ACTION_ESP_KEYMAT_AES_GCM ] = {
302366 .ptr = {
@@ -308,6 +372,13 @@ static const struct uverbs_attr_spec uverbs_flow_action_esp_keymat[] = {
308372};
309373
310374static const struct uverbs_attr_spec uverbs_flow_action_esp_replay [] = {
375+ [IB_UVERBS_FLOW_ACTION_ESP_REPLAY_NONE ] = {
376+ .ptr = {
377+ .type = UVERBS_ATTR_TYPE_PTR_IN ,
378+ /* No need to specify any data */
379+ .len = 0 ,
380+ }
381+ },
311382 [IB_UVERBS_FLOW_ACTION_ESP_REPLAY_BMP ] = {
312383 .ptr = {
313384 .type = UVERBS_ATTR_TYPE_PTR_IN ,
@@ -334,6 +405,21 @@ static DECLARE_UVERBS_NAMED_METHOD(UVERBS_METHOD_FLOW_ACTION_ESP_CREATE,
334405 & UVERBS_ATTR_PTR_IN (UVERBS_ATTR_FLOW_ACTION_ESP_ENCAP ,
335406 UVERBS_ATTR_STRUCT (struct ib_uverbs_flow_action_esp_encap , type ))) ;
336407
408+ static DECLARE_UVERBS_NAMED_METHOD (UVERBS_METHOD_FLOW_ACTION_ESP_MODIFY ,
409+ & UVERBS_ATTR_IDR (UVERBS_ATTR_FLOW_ACTION_ESP_HANDLE , UVERBS_OBJECT_FLOW_ACTION ,
410+ UVERBS_ACCESS_WRITE ,
411+ UA_FLAGS (UVERBS_ATTR_SPEC_F_MANDATORY )),
412+ & UVERBS_ATTR_PTR_IN (UVERBS_ATTR_FLOW_ACTION_ESP_ATTRS ,
413+ UVERBS_ATTR_STRUCT (struct ib_uverbs_flow_action_esp , hard_limit_pkts ),
414+ UA_FLAGS (UVERBS_ATTR_SPEC_F_MIN_SZ_OR_ZERO )),
415+ & UVERBS_ATTR_PTR_IN (UVERBS_ATTR_FLOW_ACTION_ESP_ESN , UVERBS_ATTR_TYPE (__u32 )),
416+ & UVERBS_ATTR_ENUM_IN (UVERBS_ATTR_FLOW_ACTION_ESP_KEYMAT ,
417+ uverbs_flow_action_esp_keymat ),
418+ & UVERBS_ATTR_ENUM_IN (UVERBS_ATTR_FLOW_ACTION_ESP_REPLAY ,
419+ uverbs_flow_action_esp_replay ),
420+ & UVERBS_ATTR_PTR_IN (UVERBS_ATTR_FLOW_ACTION_ESP_ENCAP ,
421+ UVERBS_ATTR_STRUCT (struct ib_uverbs_flow_action_esp_encap , type ))) ;
422+
337423static DECLARE_UVERBS_NAMED_METHOD_WITH_HANDLER (UVERBS_METHOD_FLOW_ACTION_DESTROY ,
338424 uverbs_destroy_def_handler ,
339425 & UVERBS_ATTR_IDR (UVERBS_ATTR_DESTROY_FLOW_ACTION_HANDLE ,
@@ -344,5 +430,6 @@ static DECLARE_UVERBS_NAMED_METHOD_WITH_HANDLER(UVERBS_METHOD_FLOW_ACTION_DESTRO
344430DECLARE_UVERBS_NAMED_OBJECT (UVERBS_OBJECT_FLOW_ACTION ,
345431 & UVERBS_TYPE_ALLOC_IDR (0 , uverbs_free_flow_action ),
346432 & UVERBS_METHOD (UVERBS_METHOD_FLOW_ACTION_ESP_CREATE ),
347- & UVERBS_METHOD (UVERBS_METHOD_FLOW_ACTION_DESTROY ));
433+ & UVERBS_METHOD (UVERBS_METHOD_FLOW_ACTION_DESTROY ),
434+ & UVERBS_METHOD (UVERBS_METHOD_FLOW_ACTION_ESP_MODIFY ));
348435
0 commit comments