1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
|
#pragma once
#ifndef MR_PORT_NAME_MAX
#define MR_PORT_NAME_MAX MR_SYMBOL_MAX
#endif
#ifndef MR_FLOW_MAX_NUM
#define MR_FLOW_MAX_NUM 1024
#endif
#ifndef MR_INVALID_PORT_ID
#define MR_INVALID_PORT_ID 65535
#endif
#ifndef MR_MAX_ITEM_NUM
#define MR_MAX_ITEM_NUM 32
#endif
#ifndef MR_MAX_ACTION_NUM
#define MR_MAX_ACTION_NUM 16
#endif
#ifndef MR_RULE_MAC_ADDR_LEN
#define MR_RULE_MAC_ADDR_LEN 18
#endif
#ifndef MR_RULE_TYEP_NO_SET
#define MR_RULE_TYEP_NO_SET 255
#endif
#ifndef MR_DEFAULT_MASK_U8
#define MR_DEFAULT_MASK_U8 0xff
#endif
#ifndef MR_RULE_DELETE
#define MR_RULE_DELETE 0
#endif
#ifndef MR_RULE_CREATE
#define MR_RULE_CREATE 1
#endif
#ifndef MR_RULE_SEARCH
#define MR_RULE_SEARCH 2
#endif
#ifndef MR_RULE_GET_RULE_COUNT
#define MR_RULE_GET_RULE_COUNT 3
#endif
#ifndef MR_RULE_ARG_DISABLE
#define MR_RULE_ARG_DISABLE 0
#endif
#ifndef MR_RULE_ARG_ENABLE
#define MR_RULE_ARG_ENABLE 1
#endif
/* Public */
#ifndef MR_CJSON_KEY_ARG_FLAG
#define MR_CJSON_KEY_ARG_FLAG "ArgFlag"
#endif
/* Rule */
#ifndef MR_CJSON_KEY_PORT_NAME
#define MR_CJSON_KEY_PORT_NAME "PortName"
#endif
#ifndef MR_CJSON_KEY_RULE_TYPE
#define MR_CJSON_KEY_RULE_TYPE "RuleType"
#endif
/* Delete */
#ifndef MR_CJSON_KEY_DELETE_RULE
#define MR_CJSON_KEY_DELETE_RULE "DeleteRule"
#endif
#ifndef MR_CJSON_KEY_DELETE_RULE_ID
#define MR_CJSON_KEY_DELETE_RULE_ID "RuleId"
#endif
/* Get Rule Count */
#ifndef MR_CJSON_KEY_GET_RULE_COUNT_RULE
#define MR_CJSON_KEY_GET_RULE_COUNT_RULE "GetRuleCount"
#endif
#ifndef MR_CJSON_KEY_GET_RULE_COUNT_ID
#define MR_CJSON_KEY_GET_RULE_COUNT_ID "RuleId"
#endif
/* Attr */
#ifndef MR_CJSON_KEY_ATTR
#define MR_CJSON_KEY_ATTR "Attr"
#endif
#ifndef MR_CJSON_KEY_ATTR_GROUP
#define MR_CJSON_KEY_ATTR_GROUP "Group"
#endif
#ifndef MR_CJSON_KEY_ATTR_PRIORITY
#define MR_CJSON_KEY_ATTR_PRIORITY "Priority"
#endif
#ifndef MR_CJSON_KEY_ATTR_INGRESS
#define MR_CJSON_KEY_ATTR_INGRESS "Ingress"
#endif
#ifndef MR_CJSON_KEY_ATTR_EGRESS
#define MR_CJSON_KEY_ATTR_EGRESS "Egress"
#endif
/* Item */
#ifndef MR_CJSON_KEY_ITEMS
#define MR_CJSON_KEY_ITEMS "Items"
#endif
#ifndef MR_CJSON_KEY_ITEM_LIST
#define MR_CJSON_KEY_ITEM_LIST "ItemList"
#endif
#ifndef MR_CJSON_KEY_ITEM_NUM
#define MR_CJSON_KEY_ITEM_NUM "ItemNum"
#endif
/* Ether Item */
#ifndef MR_CJSON_KEY_ETHER
#define MR_CJSON_KEY_ETHER "Ether"
#endif
#ifndef MR_CJSON_KEY_ETHER_HASVLAN
#define MR_CJSON_KEY_ETHER_HASVLAN "HasVlan"
#endif
#ifndef MR_CJSON_KEY_ETHER_SMAC
#define MR_CJSON_KEY_ETHER_SMAC "SMac"
#endif
#ifndef MR_CJSON_KEY_ETHER_DMAC
#define MR_CJSON_KEY_ETHER_DMAC "DMac"
#endif
#ifndef MR_CJSON_KEY_ETHER_SMAC_MASK
#define MR_CJSON_KEY_ETHER_SMAC_MASK "SMacMask"
#endif
#ifndef MR_CJSON_KEY_ETHER_DMAC_MASK
#define MR_CJSON_KEY_ETHER_DMAC_MASK "DMacMask"
#endif
#ifndef MR_CJSON_KEY_ETHER_TYPE
#define MR_CJSON_KEY_ETHER_TYPE "Type"
#endif
/* Ipv4 Item */
#ifndef MR_CJSON_KEY_IPV4
#define MR_CJSON_KEY_IPV4 "Ipv4"
#endif
#ifndef MR_CJSON_KEY_IPV4_TOS
#define MR_CJSON_KEY_IPV4_TOS "Tos"
#endif
#ifndef MR_CJSON_KEY_IPV4_FRAGMENT_OFFSET
#define MR_CJSON_KEY_IPV4_FRAGMENT_OFFSET "FragmentOffset"
#endif
#ifndef MR_CJSON_KEY_IPV4_TTL
#define MR_CJSON_KEY_IPV4_TTL "Ttl"
#endif
#ifndef MR_CJSON_KEY_IPV4_NEXT_PROTO
#define MR_CJSON_KEY_IPV4_NEXT_PROTO "NextProto"
#endif
#ifndef MR_CJSON_KEY_IPV4_SADDR
#define MR_CJSON_KEY_IPV4_SADDR "SrcAddr"
#endif
#ifndef MR_CJSON_KEY_IPV4_SADDR_STR
#define MR_CJSON_KEY_IPV4_SADDR_STR "SrcAddrStr"
#endif
#ifndef MR_CJSON_KEY_IPV4_SADDR_MASK
#define MR_CJSON_KEY_IPV4_SADDR_MASK "SrcAddrMask"
#endif
#ifndef MR_CJSON_KEY_IPV4_SADDR_MASK_STR
#define MR_CJSON_KEY_IPV4_SADDR_MASK_STR "SrcAddrMaskStr"
#endif
#ifndef MR_CJSON_KEY_IPV4_DADDR
#define MR_CJSON_KEY_IPV4_DADDR "DstAddr"
#endif
#ifndef MR_CJSON_KEY_IPV4_DADDR_STR
#define MR_CJSON_KEY_IPV4_DADDR_STR "DstAddrStr"
#endif
#ifndef MR_CJSON_KEY_IPV4_DADDR_MASK
#define MR_CJSON_KEY_IPV4_DADDR_MASK "DstAddrMask"
#endif
#ifndef MR_CJSON_KEY_IPV4_DADDR_MASK_STR
#define MR_CJSON_KEY_IPV4_DADDR_MASK_STR "DstAddrMaskStr"
#endif
/* UDP Item */
#ifndef MR_CJSON_KEY_UDP
#define MR_CJSON_KEY_UDP "UDP"
#endif
#ifndef MR_CJSON_KEY_UDP_SRC_PORT
#define MR_CJSON_KEY_UDP_SRC_PORT "Src Port"
#endif
#ifndef MR_CJSON_KEY_UDP_SRC_PORT_MASK
#define MR_CJSON_KEY_UDP_SRC_PORT_MASK "Src Port Mask"
#endif
#ifndef MR_CJSON_KEY_UDP_DST_PORT
#define MR_CJSON_KEY_UDP_DST_PORT "Dst Port"
#endif
#ifndef MR_CJSON_KEY_UDP_DST_PORT_MASK
#define MR_CJSON_KEY_UDP_DST_PORT_MASK "Dst Port Mask"
#endif
/* TCP Item */
#ifndef MR_CJSON_KEY_TCP
#define MR_CJSON_KEY_TCP "TCP"
#endif
#ifndef MR_CJSON_KEY_TCP_SRC_PORT
#define MR_CJSON_KEY_TCP_SRC_PORT "Src Port"
#endif
#ifndef MR_CJSON_KEY_TCP_SRC_PORT_MASK
#define MR_CJSON_KEY_TCP_SRC_PORT_MASK "Src Port Mask"
#endif
#ifndef MR_CJSON_KEY_TCP_DST_PORT
#define MR_CJSON_KEY_TCP_DST_PORT "Dst Port"
#endif
#ifndef MR_CJSON_KEY_TCP_DST_PORT_MASK
#define MR_CJSON_KEY_TCP_DST_PORT_MASK "Dst Port Mask"
#endif
#ifndef MR_CJSON_KEY_TCP_FLAGS
#define MR_CJSON_KEY_TCP_FLAGS "Flags"
#endif
/* VXLAN Item */
#ifndef MR_CJSON_KEY_VXLAN
#define MR_CJSON_KEY_VXLAN "Vxlan"
#endif
#ifndef MR_CJSON_KEY_VXLAN_VNI
#define MR_CJSON_KEY_VXLAN_VNI "Vni"
#endif
#ifndef MR_CJSON_KEY_VXLAN_VNI_MASK
#define MR_CJSON_KEY_VXLAN_VNI_MASK "VniMask"
#endif
/* Action */
#ifndef MR_CJSON_KEY_ACTIONS
#define MR_CJSON_KEY_ACTIONS "Actions"
#endif
#ifndef MR_CJSON_KEY_ACTION_LIST
#define MR_CJSON_KEY_ACTION_LIST "ActionList"
#endif
#ifndef MR_CJSON_KEY_ACTION_NUM
#define MR_CJSON_KEY_ACTION_NUM "ActionNum"
#endif
/* Action Count */
#ifndef MR_CJSON_KEY_COUNT
#define MR_CJSON_KEY_COUNT "Count"
#endif
#ifndef MR_CJSON_KEY_COUNT_SHARED
#define MR_CJSON_KEY_COUNT_SHARED "Shared"
#endif
#ifndef MR_CJSON_KEY_COUNT_ID
#define MR_CJSON_KEY_COUNT_ID "Id"
#endif
/* Action Queue */
#ifndef MR_CJSON_KEY_QUEUE
#define MR_CJSON_KEY_QUEUE "Queue"
#endif
#ifndef MR_CJSON_KEY_QUEUE_INDEX
#define MR_CJSON_KEY_QUEUE_INDEX "QueueIndex"
#endif
/* Action Drop */
#ifndef MR_CJSON_KEY_DROP
#define MR_CJSON_KEY_DROP "Drop"
#endif
#ifndef MR_CJSON_KEY_STATE
#define MR_CJSON_KEY_STATE "State"
#endif
/* Action Set Src Mac */
#ifndef MR_CJSON_KEY_SET_SRC_MAC
#define MR_CJSON_KEY_SET_SRC_MAC "SetSrcMac"
#endif
#ifndef MR_CJSON_KEY_SET_SRC_MAC_SMAC
#define MR_CJSON_KEY_SET_SRC_MAC_SMAC "SMac"
#endif
/* Action Set Dst Mac */
#ifndef MR_CJSON_KEY_SET_DST_MAC
#define MR_CJSON_KEY_SET_DST_MAC "SetDstMac"
#endif
#ifndef MR_CJSON_KEY_SET_DST_MAC_DMAC
#define MR_CJSON_KEY_SET_DST_MAC_DMAC "DMac"
#endif
/* Response Error Info */
#ifndef MR_CJSON_KEY_ERROR_INFO
#define MR_CJSON_KEY_ERROR_INFO "ErrorInfo"
#endif
/* Response Success Info */
#ifndef MR_CJSON_KEY_SUCCESS_INFO
#define MR_CJSON_KEY_SUCCESS_INFO "SuccessInfo"
#endif
/* Response Rule */
#ifndef MR_CJSON_KEY_RULE_NUM
#define MR_CJSON_KEY_RULE_NUM "RuleNum"
#endif
/* Response Rule Info */
#ifndef MR_CJSON_KEY_RULE_INFO
#define MR_CJSON_KEY_RULE_INFO "RuleInfo"
#endif
/* Response Rule Id */
#ifndef MR_CJSON_KEY_RULE_ID
#define MR_CJSON_KEY_RULE_ID "RuleId"
#endif
/* Response Rule Str */
#ifndef MR_CJSON_KEY_RULE_STR
#define MR_CJSON_KEY_RULE_STR "RuleStr"
#endif
/* Response Rule End */
#ifndef MR_CJSON_KEY_RULE_END
#define MR_CJSON_KEY_RULE_END "RuleEnd"
#endif
/* Response Count Hits */
#ifndef MR_CJSON_KEY_COUNT_RULE_ID
#define MR_CJSON_KEY_COUNT_RULE_ID "RuleId"
#endif
#ifndef MR_CJSON_KEY_COUNT_HITS
#define MR_CJSON_KEY_COUNT_HITS "CountHits"
#endif
#ifndef MR_CJSON_KEY_COUNT_ERR_INFO
#define MR_CJSON_KEY_COUNT_ERR_INFO "ErrorInfo"
#endif
/* Delete Arg */
enum mr_cli_delete_arg
{
MR_RULE_FLOW_DELETE_ARG_NOT_SET = 0,
MR_RULE_FLOW_DELETE_ARG_RULE_ID = 1 << 0,
MR_RULE_FLOW_DELETE_ARG_DELETE_ALL = 1 << 1,
};
/* Get Rule Count Arg */
enum mr_cli_get_rule_count_arg
{
MR_RULE_FLOW_GET_RULE_COUNT_ARG_NOT_SET = 0,
MR_RULE_FLOW_GET_RULE_COUNT_ARG_RULE_ID = 1 << 0,
MR_RULE_FLOW_GET_RULE_COUNT_ARG_ALL = 1 << 1,
};
/* Attr Arg */
enum mr_cli_attr_arg
{
MR_RULE_FLOW_ATTR_ARG_NOT_SET = 0,
MR_RULE_FLOW_ATTR_ARG_GROUP_ENABLE = 1 << 0,
MR_RULE_FLOW_ATTR_ARG_PRIORITY_ENABLE = 1 << 1,
MR_RULE_FLOW_ATTR_ARG_INGRESS_ENABLE = 1 << 2,
MR_RULE_FLOW_ATTR_ARG_EGRESS_ENABLE = 1 << 3,
MR_RULE_FLOW_ATTR_ARG_PORTNAME_ENABLE = 1 << 4,
};
/* Item */
/* Item List */
enum mr_cli_item_list
{
MR_RULE_FLOW_ITEM_LIST_ETHER = 1 << 0,
MR_RULE_FLOW_ITEM_LIST_VLAN = 1 << 1,
MR_RULE_FLOW_ITEM_LIST_IPV4 = 1 << 2,
MR_RULE_FLOW_ITEM_LIST_IPV6 = 1 << 3,
MR_RULE_FLOW_ITEM_LIST_TCP = 1 << 4,
MR_RULE_FLOW_ITEM_LIST_UDP = 1 << 5,
MR_RULE_FLOW_ITEM_LIST_VXLAN = 1 << 6,
};
/* Item type */
enum mr_cli_item_type
{
MR_RULE_FLOW_ITEM_ETHER = 0,
MR_RULE_FLOW_ITEM_VLAN,
MR_RULE_FLOW_ITEM_IPV4,
MR_RULE_FLOW_ITEM_IPV6,
MR_RULE_FLOW_ITEM_TCP,
MR_RULE_FLOW_ITEM_UDP,
MR_RULE_FLOW_ITEM_VXLAN,
MR_RULE_FLOW_ITEM_MAX = MR_MAX_ITEM_NUM
};
/* Ether Arg */
enum mr_cli_ether_arg
{
MR_RULE_FLOW_ETHER_ARG_NOT_SET = 0,
MR_RULE_FLOW_ETHER_ARG_SMAC_ENABLE = 1 << 0,
MR_RULE_FLOW_ETHER_ARG_DMAC_ENABLE = 1 << 1,
MR_RULE_FLOW_ETHER_ARG_SMAC_MASK_ENABLE = 1 << 2,
MR_RULE_FLOW_ETHER_ARG_DMAC_MASK_ENABLE = 1 << 3,
MR_RULE_FLOW_ETHER_ARG_TYPE_ENABLE = 1 << 4,
MR_RULE_FLOW_ETHER_ARG_HAS_VLAN_ENABLE = 1 << 5,
};
/* Ipv4 Arg */
enum mr_cli_ipv4_arg
{
MR_RULE_FLOW_IPV4_ARG_NOT_SET = 0,
MR_RULE_FLOW_IPV4_ARG_TOS_ENABLE = 1 << 0,
MR_RULE_FLOW_IPV4_ARG_FRAGMENT_OFFSET_ENABLE = 1 << 1,
MR_RULE_FLOW_IPV4_ARG_TTL_ENABLE = 1 << 2,
MR_RULE_FLOW_IPV4_ARG_NEXT_PROTO_ENABLE = 1 << 3,
MR_RULE_FLOW_IPV4_ARG_SADDR_ENABLE = 1 << 4,
MR_RULE_FLOW_IPV4_ARG_SADDR_MASK_ENABLE = 1 << 5,
MR_RULE_FLOW_IPV4_ARG_DADDR_ENABLE = 1 << 6,
MR_RULE_FLOW_IPV4_ARG_DADDR_MASK_ENABLE = 1 << 7,
};
/* UDP Arg */
enum mr_cli_udp_arg
{
MR_RULE_FLOW_UDP_ARG_NOT_SET = 0,
MR_RULE_FLOW_UDP_ARG_SRC_PORT_ENABLE = 1 << 0,
MR_RULE_FLOW_UDP_ARG_SRC_PORT_MASK_ENABLE = 1 << 1,
MR_RULE_FLOW_UDP_ARG_DST_PORT_ENABLE = 1 << 2,
MR_RULE_FLOW_UDP_ARG_DST_PORT_MASK_ENABLE = 1 << 3,
};
/* TCP Arg */
enum mr_cli_tcp_arg
{
MR_RULE_FLOW_TCP_ARG_NOT_SET = 0,
MR_RULE_FLOW_TCP_ARG_SRC_PORT_ENABLE = 1 << 0,
MR_RULE_FLOW_TCP_ARG_SRC_PORT_MASK_ENABLE = 1 << 1,
MR_RULE_FLOW_TCP_ARG_DST_PORT_ENABLE = 1 << 2,
MR_RULE_FLOW_TCP_ARG_DST_PORT_MASK_ENABLE = 1 << 3,
MR_RULE_FLOW_TCP_ARG_FLAGS_ENABLE = 1 << 4,
};
/* VXLAN Arg */
enum mr_cli_vxlan_arg
{
MR_RULE_FLOW_VXLAN_ARG_NOT_SET = 0,
MR_RULE_FLOW_VXLAN_ARG_VNI_ENABLE = 1 << 0,
MR_RULE_FLOW_VXLAN_ARG_VNI_MASK_ENABLE = 1 << 1,
};
/* Action */
/* Action List */
enum mr_cli_action_list
{
MR_RULE_FLOW_ACTION_LIST_COUNT = 1 << 0,
MR_RULE_FLOW_ACTION_LIST_DROP = 1 << 1,
MR_RULE_FLOW_ACTION_LIST_QUEUE = 1 << 2,
MR_RULE_FLOW_ACTION_LIST_SET_SRC_MAC = 1 << 3,
MR_RULE_FLOW_ACTION_LIST_SET_DST_MAC = 1 << 4,
};
/* Action type */
enum mr_cli_action_type
{
MR_RULE_FLOW_ACTION_COUNT = 0,
MR_RULE_FLOW_ACTION_DROP,
MR_RULE_FLOW_ACTION_QUEUE,
MR_RULE_FLOW_ACTION_SET_SRC_MAC,
MR_RULE_FLOW_ACTION_SET_DST_MAC,
MR_RULE_FLOW_ACTION_MAX = MR_MAX_ACTION_NUM,
};
/* Count Arg */
enum mr_cli_count_arg
{
MR_RULE_FLOW_COUNT_ARG_NOT_SET = 0,
MR_RULE_FLOW_COUNT_ARG_SHARED_ENABLE = 1 << 0,
MR_RULE_FLOW_COUNT_ARG_ID_ENABLE = 1 << 1,
};
/* Queue Arg */
enum mr_cli_queue_arg
{
MR_RULE_FLOW_QUEUE_ARG_NOT_SET = 0,
MR_RULE_FLOW_QUEUE_ARG_QUEUE_INDEX = 1 << 0,
};
/* Set Src Mac Arg */
enum mr_cli_set_src_mac_arg
{
MR_RULE_FLOW_SET_SRC_MAC_ARG_NOT_SET = 0,
MR_RULE_FLOW_SET_SRC_MAC_ARG_SMAC_ENABLE = 1 << 0,
};
/* Set Dst Mac Arg */
enum mr_cli_set_dst_mac_arg
{
MR_RULE_FLOW_SET_DST_MAC_ARG_NOT_SET = 0,
MR_RULE_FLOW_SET_DST_MAC_ARG_DMAC_ENABLE = 1 << 0,
};
/* Struct */
struct mr_flow_attr
{
uint16_t arg_flag;
struct rte_flow_attr attr;
};
struct mr_flow_delete
{
uint16_t arg_flag;
u_int32_t rule_id;
};
struct mr_flow_get_count
{
uint16_t arg_flag;
u_int32_t rule_id;
};
/* Item Struct */
/* Ether */
struct mr_flow_item_ether
{
uint8_t has_vlan;
uint16_t arg_flag;
struct rte_ether_addr smac_mask;
struct rte_ether_addr dmac_mask;
struct rte_ether_hdr ether_hdr;
};
/* Ipv4 */
struct mr_flow_item_ipv4
{
uint16_t arg_flag;
struct rte_ipv4_hdr ipv4_hdr;
struct rte_ipv4_hdr ip_mask;
};
/* Tcp */
struct mr_flow_item_tcp
{
uint16_t arg_flag;
struct rte_tcp_hdr tcp_hdr;
struct rte_tcp_hdr tcp_mask;
};
/* Udp */
struct mr_flow_item_udp
{
uint16_t arg_flag;
struct rte_udp_hdr udp_hdr;
struct rte_udp_hdr udp_mask;
};
/* Vxlan */
struct mr_flow_item_vxlan
{
uint16_t arg_flag;
uint32_t vni;
uint32_t vni_mask;
};
/* Item Union */
union mr_flow_item_union
{
struct mr_flow_item_ether ether_item;
struct mr_flow_item_ipv4 ipv4_item;
struct mr_flow_item_tcp tcp_item;
struct mr_flow_item_udp udp_item;
struct mr_flow_item_vxlan vxlan_item;
};
/* Action */
/* Count Action */
struct mr_flow_action_count
{
uint8_t shared;
uint16_t arg_flag;
uint32_t id;
};
/* Drop Action*/
struct mr_flow_action_drop
{
uint8_t state;
};
/* Queue Action*/
struct mr_flow_action_queue
{
uint16_t arg_flag;
uint16_t index;
};
/* Set Src Mac Action*/
struct mr_flow_action_set_mac
{
uint16_t arg_flag;
struct rte_ether_addr mac_addr;
};
/* Action Union */
union mr_flow_action_union
{
struct mr_flow_action_count count;
struct mr_flow_action_drop drop;
struct mr_flow_action_queue queue;
struct mr_flow_action_set_mac set_src_mac;
struct mr_flow_action_set_mac set_dst_mac;
};
/* Rule */
struct mrctl_flow_rule
{
uint8_t rule_flag;
uint8_t rule_type;
uint64_t item_num;
uint64_t action_num;
uint64_t item_list;
uint64_t action_list;
char port_name[MR_PORT_NAME_MAX];
struct mr_flow_delete delete;
struct mr_flow_get_count get_count;
struct mr_flow_attr attrs;
union mr_flow_item_union items[MR_MAX_ITEM_NUM];
union mr_flow_action_union actions[MR_MAX_ACTION_NUM];
};
/* String to mac */
int string_to_mac(char *s,struct rte_ether_addr * addr )
{
unsigned char a[6];
int rc = sscanf(s, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", a + 0, a + 1, a + 2, a + 3, a + 4, a + 5);
if(rc !=6 )
{
return RT_ERR;
}
addr->addr_bytes[0] = (uint8_t)a[0];
addr->addr_bytes[1] = (uint8_t)a[1];
addr->addr_bytes[2] = (uint8_t)a[2];
addr->addr_bytes[3] = (uint8_t)a[3];
addr->addr_bytes[4] = (uint8_t)a[4];
addr->addr_bytes[5] = (uint8_t)a[5];
return RT_SUCCESS;
}
|