@@ -168,95 +168,60 @@ func marshalAction(cmd int, info *Action, actOption uint16) ([]byte, error) {
168
168
if len (info .Kind ) == 0 {
169
169
return []byte {}, fmt .Errorf ("kind is missing" )
170
170
}
171
- var multiError error
171
+ var err error
172
+ var data []byte
172
173
173
174
// TODO: improve logic and check combinations
174
175
switch info .Kind {
175
176
case "bpf" :
176
- data , err := marshalActBpf (info .Bpf )
177
- multiError = concatError (multiError , err )
178
- options = append (options , tcOption {Interpretation : vtBytes , Type : actOption , Data : data })
177
+ data , err = marshalActBpf (info .Bpf )
179
178
case "connmark" :
180
- data , err := marshalConnmark (info .ConnMark )
181
- multiError = concatError (multiError , err )
182
- options = append (options , tcOption {Interpretation : vtBytes , Type : actOption , Data : data })
179
+ data , err = marshalConnmark (info .ConnMark )
183
180
case "csum" :
184
- data , err := marshalCsum (info .CSum )
185
- multiError = concatError (multiError , err )
186
- options = append (options , tcOption {Interpretation : vtBytes , Type : actOption , Data : data })
181
+ data , err = marshalCsum (info .CSum )
187
182
case "ct" :
188
- data , err := marshalCt (info .Ct )
189
- multiError = concatError (multiError , err )
190
- options = append (options , tcOption {Interpretation : vtBytes , Type : actOption , Data : data })
183
+ data , err = marshalCt (info .Ct )
191
184
case "ctinfo" :
192
- data , err := marshalCtInfo (info .CtInfo )
193
- multiError = concatError (multiError , err )
194
- options = append (options , tcOption {Interpretation : vtBytes , Type : actOption , Data : data })
185
+ data , err = marshalCtInfo (info .CtInfo )
195
186
case "defact" :
196
- data , err := marshalDefact (info .Defact )
197
- multiError = concatError (multiError , err )
198
- options = append (options , tcOption {Interpretation : vtBytes , Type : actOption , Data : data })
187
+ data , err = marshalDefact (info .Defact )
199
188
case "gact" :
200
- data , err := marshalGact (info .Gact )
201
- multiError = concatError (multiError , err )
202
- options = append (options , tcOption {Interpretation : vtBytes , Type : actOption , Data : data })
189
+ data , err = marshalGact (info .Gact )
203
190
case "gate" :
204
- data , err := marshalGate (info .Gate )
205
- multiError = concatError (multiError , err )
206
- options = append (options , tcOption {Interpretation : vtBytes , Type : actOption , Data : data })
191
+ data , err = marshalGate (info .Gate )
207
192
case "ife" :
208
- data , err := marshalIfe (info .Ife )
209
- multiError = concatError (multiError , err )
210
- options = append (options , tcOption {Interpretation : vtBytes , Type : actOption , Data : data })
193
+ data , err = marshalIfe (info .Ife )
211
194
case "ipt" :
212
- data , err := marshalIpt (info .Ipt )
213
- multiError = concatError (multiError , err )
214
- options = append (options , tcOption {Interpretation : vtBytes , Type : actOption , Data : data })
195
+ data , err = marshalIpt (info .Ipt )
215
196
case "mirred" :
216
- data , err := marshalMirred (info .Mirred )
217
- multiError = concatError (multiError , err )
218
- options = append (options , tcOption {Interpretation : vtBytes , Type : actOption , Data : data })
197
+ data , err = marshalMirred (info .Mirred )
219
198
case "nat" :
220
- data , err := marshalNat (info .Nat )
221
- multiError = concatError (multiError , err )
222
- options = append (options , tcOption {Interpretation : vtBytes , Type : actOption , Data : data })
199
+ data , err = marshalNat (info .Nat )
223
200
case "sample" :
224
- data , err := marshalSample (info .Sample )
225
- multiError = concatError (multiError , err )
226
- options = append (options , tcOption {Interpretation : vtBytes , Type : actOption , Data : data })
201
+ data , err = marshalSample (info .Sample )
227
202
case "vlan" :
228
- data , err := marshalVlan (info .VLan )
229
- multiError = concatError (multiError , err )
230
- options = append (options , tcOption {Interpretation : vtBytes , Type : actOption , Data : data })
203
+ data , err = marshalVlan (info .VLan )
231
204
case "police" :
232
- data , err := marshalPolice (info .Police )
233
- multiError = concatError (multiError , err )
234
- options = append (options , tcOption {Interpretation : vtBytes , Type : actOption , Data : data })
205
+ data , err = marshalPolice (info .Police )
235
206
case "tunnel_key" :
236
- data , err := marshalTunnelKey (info .TunnelKey )
237
- multiError = concatError (multiError , err )
238
- options = append (options , tcOption {Interpretation : vtBytes , Type : actOption , Data : data })
207
+ data , err = marshalTunnelKey (info .TunnelKey )
239
208
case "mpls" :
240
- data , err := marshalMPLS (info .MPLS )
241
- multiError = concatError (multiError , err )
242
- options = append (options , tcOption {Interpretation : vtBytes , Type : actOption , Data : data })
209
+ data , err = marshalMPLS (info .MPLS )
243
210
case "skbedit" :
244
- data , err := marshalSkbEdit (info .SkbEdit )
245
- multiError = concatError (multiError , err )
246
- options = append (options , tcOption {Interpretation : vtBytes , Type : actOption , Data : data })
211
+ data , err = marshalSkbEdit (info .SkbEdit )
247
212
case "skbmod" :
248
- data , err := marshalSkbMod (info .SkbMod )
249
- multiError = concatError (multiError , err )
250
- options = append (options , tcOption {Interpretation : vtBytes , Type : actOption , Data : data })
213
+ data , err = marshalSkbMod (info .SkbMod )
251
214
default :
252
215
return []byte {}, fmt .Errorf ("unknown kind '%s'" , info .Kind )
253
216
}
254
- options = append (options , tcOption {Interpretation : vtString , Type : tcaActKind , Data : info .Kind })
255
217
256
- if multiError != nil && ! errors .Is (multiError , ErrNoArg ) && cmd != unix .RTM_DELACTION {
257
- return []byte {}, multiError
218
+ if err != nil && ! errors .Is (err , ErrNoArg ) && cmd != unix .RTM_DELACTION {
219
+ return []byte {}, err
258
220
}
259
221
222
+ options = append (options , tcOption {Interpretation : vtBytes , Type : actOption , Data : data })
223
+ options = append (options , tcOption {Interpretation : vtString , Type : tcaActKind , Data : info .Kind })
224
+
260
225
if info .Index != 0 {
261
226
options = append (options , tcOption {Interpretation : vtUint32 , Type : tcaActIndex , Data : info .Index })
262
227
}
@@ -270,111 +235,94 @@ func marshalAction(cmd int, info *Action, actOption uint16) ([]byte, error) {
270
235
if info .Cookie != nil {
271
236
options = append (options , tcOption {Interpretation : vtBytes , Type : tcaActCookie , Data : bytesValue (info .Cookie )})
272
237
}
238
+ if info .Flags != nil {
239
+ options = append (options , tcOption {Interpretation : vtUint64 , Type : tcaActFlags , Data : uint64Value (info .Flags )})
240
+ }
273
241
return marshalAttributes (options )
274
242
}
275
243
276
244
func extractActOptions (data []byte , act * Action , kind string ) error {
277
- var multiError error
278
245
var err error
279
246
switch kind {
280
247
case "bpf" :
281
248
info := & ActBpf {}
282
249
err = unmarshalActBpf (data , info )
283
- multiError = concatError (multiError , err )
284
250
act .Bpf = info
285
251
case "connmark" :
286
252
info := & Connmark {}
287
253
err = unmarshalConnmark (data , info )
288
- multiError = concatError (multiError , err )
289
254
act .ConnMark = info
290
255
case "csum" :
291
256
info := & Csum {}
292
257
err = unmarshalCsum (data , info )
293
- multiError = concatError (multiError , err )
294
258
act .CSum = info
295
259
case "ct" :
296
260
info := & Ct {}
297
261
err = unmarshalCt (data , info )
298
- multiError = concatError (multiError , err )
299
262
act .Ct = info
300
263
case "ctinfo" :
301
264
info := & CtInfo {}
302
265
err = unmarshalCtInfo (data , info )
303
- multiError = concatError (multiError , err )
304
266
act .CtInfo = info
305
267
case "defact" :
306
268
info := & Defact {}
307
269
err = unmarshalDefact (data , info )
308
- multiError = concatError (multiError , err )
309
270
act .Defact = info
310
271
case "gact" :
311
272
info := & Gact {}
312
273
err = unmarshalGact (data , info )
313
- multiError = concatError (multiError , err )
314
274
act .Gact = info
315
275
case "gate" :
316
276
info := & Gate {}
317
277
err = unmarshalGate (data , info )
318
- multiError = concatError (multiError , err )
319
278
act .Gate = info
320
279
case "ife" :
321
280
info := & Ife {}
322
281
err = unmarshalIfe (data , info )
323
- multiError = concatError (multiError , err )
324
282
act .Ife = info
325
283
case "ipt" :
326
284
info := & Ipt {}
327
285
err = unmarshalIpt (data , info )
328
- multiError = concatError (multiError , err )
329
286
act .Ipt = info
330
287
case "mirred" :
331
288
info := & Mirred {}
332
289
err = unmarshalMirred (data , info )
333
- multiError = concatError (multiError , err )
334
290
act .Mirred = info
335
291
case "nat" :
336
292
info := & Nat {}
337
293
err = unmarshalNat (data , info )
338
- multiError = concatError (multiError , err )
339
294
act .Nat = info
340
295
case "sample" :
341
296
info := & Sample {}
342
297
err = unmarshalSample (data , info )
343
- multiError = concatError (multiError , err )
344
298
act .Sample = info
345
299
case "vlan" :
346
300
info := & VLan {}
347
301
err = unmarshalVLan (data , info )
348
- multiError = concatError (multiError , err )
349
302
act .VLan = info
350
303
case "police" :
351
304
info := & Police {}
352
305
err = unmarshalPolice (data , info )
353
- multiError = concatError (multiError , err )
354
306
act .Police = info
355
307
case "tunnel_key" :
356
308
info := & TunnelKey {}
357
309
err = unmarshalTunnelKey (data , info )
358
- multiError = concatError (multiError , err )
359
310
act .TunnelKey = info
360
311
case "mpls" :
361
312
info := & MPLS {}
362
313
err = unmarshalMPLS (data , info )
363
- multiError = concatError (multiError , err )
364
314
act .MPLS = info
365
315
case "skbedit" :
366
316
info := & SkbEdit {}
367
317
err = unmarshalSkbEdit (data , info )
368
- multiError = concatError (multiError , err )
369
318
act .SkbEdit = info
370
319
case "skbmod" :
371
320
info := & SkbMod {}
372
321
err = unmarshalSkbMod (data , info )
373
- multiError = concatError (multiError , err )
374
322
act .SkbMod = info
375
323
default :
376
324
return fmt .Errorf ("extractActOptions(): unsupported kind: %s" , kind )
377
325
378
326
}
379
- return multiError
327
+ return err
380
328
}
0 commit comments