summaryrefslogtreecommitdiff
path: root/service/src/classifier_rule_parser.c
blob: 08a7ec992e4896202dd9b8c372caac462eee3d4e (plain)
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
#include <MESA_prof_load.h>
#include <sc_classifier_rule_parser.h>

/* Dump rule information. */
void classifier_rule_dump(struct rule_field_parser * rule)
{
    char str_rule_info[2048] = {};
    unsigned int max_len = sizeof(str_rule_info) - 1;

    int len = snprintf(str_rule_info, max_len, "Pkt classifier,rule id:%u, ", rule->rule_id);

    if (rule->ether_type == RTE_ETHER_TYPE_IPV4)
    {
        struct in_addr src_addr, dst_addr;
        src_addr.s_addr = rule->src_addr_v4;
        dst_addr.s_addr = rule->dst_addr_v4;

        len += snprintf(str_rule_info + len, max_len - len, "IPv4, ");
        len += snprintf(str_rule_info + len, max_len - len, "src addr: %s/%u, ", inet_ntoa(src_addr),
                        rule->src_addr_mask_len);
        len += snprintf(str_rule_info + len, max_len - len, "dst addr: %s/%u, ", inet_ntoa(dst_addr),
                        rule->dst_addr_mask_len);
    }
    else if (rule->ether_type == RTE_ETHER_TYPE_IPV6)
    {
        char str_ipv6_src[INET6_ADDRSTRLEN] = {}, str_ipv6_dst[INET6_ADDRSTRLEN] = {};
        inet_ntop(AF_INET6, rule->src_addr_v6, str_ipv6_src, INET6_ADDRSTRLEN);
        inet_ntop(AF_INET6, rule->dst_addr_v6, str_ipv6_dst, INET6_ADDRSTRLEN);
        len += snprintf(str_rule_info + len, max_len - len, "IPv6, ");
        len += snprintf(str_rule_info + len, max_len - len, "src addr: %s/%u, ", str_ipv6_src, rule->src_addr_mask_len);
        len += snprintf(str_rule_info + len, max_len - len, "dst addr: %s/%u, ", str_ipv6_dst, rule->dst_addr_mask_len);
    }
    else
    {
        len += snprintf(str_rule_info + len, max_len - len, "Any, ");
    }

    if (rule->proto == IPPROTO_TCP)
    {
        len += snprintf(str_rule_info + len, max_len - len, "proto: TCP, ");
    }
    else if (rule->proto == IPPROTO_UDP)
    {
        len += snprintf(str_rule_info + len, max_len - len, "proto: UDP, ");
    }
    else
    {
        len += snprintf(str_rule_info + len, max_len - len, "proto: Any, ");
    }

    len += snprintf(str_rule_info + len, max_len - len, "src port: %u~%u, ", rule->src_port_start, rule->src_port_end);

    len += snprintf(str_rule_info + len, max_len - len, "dst port: %u~%u, ", rule->dst_port_start, rule->dst_port_end);

    len += snprintf(str_rule_info + len, max_len - len, "priority: %u, ", rule->priority);

    if (rule->action.type == ACTION_DROP)
    {
        len += snprintf(str_rule_info + len, max_len - len, "action: drop");
    }
    else if (rule->action.type == ACTION_NF_STEERING)
    {
        len += snprintf(str_rule_info + len, max_len - len, "action: nf_steering, sid: %u, ", rule->action.sid);

        if (rule->adapter.type == ADAPTER_TYPE_EF)
        {
            len += snprintf(str_rule_info + len, max_len - len, "ef_adapter_id: %u", rule->adapter.id);
        }
        else if (rule->adapter.type == ADAPTER_TYPE_VWIRE)
        {
            len += snprintf(str_rule_info + len, max_len - len, "vwire_id: %u", rule->adapter.id);
        }
        else if (rule->adapter.type == ADAPTER_TYPE_TERA)
        {
            len += snprintf(str_rule_info + len, max_len - len, "tera_adapter_id: %u", rule->adapter.id);
        }
        else
        {
            len += snprintf(str_rule_info + len, max_len - len,
                            "ef_adapter_id: all, vwire_id: all, tera_adapter_id: all");
        }
    }
    MR_INFO("%s", str_rule_info);
}

/* Dump all rules information. */
void classifier_rule_list_dump(struct rule_list_parsed * rule_list)
{
    /* Dump the total rule number */
    MR_INFO(" ");
    MR_INFO("Pkt classifier total rules: %u", rule_list->nr_rules);
    MR_INFO("Pkt classifier total static rules: %u", rule_list->nr_static_rules);
    MR_INFO("Pkt classifier total dynamic rules: %u", rule_list->nr_dynamic_rules);

    for (uint16_t index = 0; index < rule_list->nr_rules; index++)
    {
        struct rule_field_parser * rule = &rule_list->rules[index];
        classifier_rule_dump(rule);
    }
}

uint16_t pkt_classifier_duplicate_rules_process(struct rule_list_parsed * rule_list)
{
    uint16_t nr_duplicate_rules = 0;

    /* Iterate through all rules to check for duplicates */
    for (uint16_t rule_index = 0; rule_index < rule_list->nr_rules; rule_index++)
    {
        struct rule_field_parser * rule = &rule_list->rules[rule_index];

        /* Iterate through all rules to compare with the current rule */
        rule->rule_state = RULE_STATE_ACTIVE;
        for (uint16_t compare_index = 0; compare_index < rule_list->nr_rules; compare_index++)
        {
            struct rule_field_parser * compare_rule = &rule_list->rules[compare_index];

            /* Skip the rule if it's the same rule */
            if (rule_index == compare_index)
            {
                continue;
            }

            /* Skip the rule if it's not active */
            if (compare_rule->rule_state != RULE_STATE_ACTIVE)
            {
                continue;
            }

            /* Compare the rules */
            if (rule->adapter.type != compare_rule->adapter.type)
            {
                continue;
            }

            if (rule->adapter.id != compare_rule->adapter.id)
            {
                continue;
            }

            if (rule->proto != compare_rule->proto)
            {
                continue;
            }

            if (rule->proto_mask != compare_rule->proto_mask)
            {
                continue;
            }

            if (rule->priority != compare_rule->priority)
            {
                continue;
            }

            if (rule->ether_type != compare_rule->ether_type)
            {
                continue;
            }

            if (rule->src_port_start != compare_rule->src_port_start)
            {
                continue;
            }

            if (rule->src_port_end != compare_rule->src_port_end)
            {
                continue;
            }

            if (rule->dst_port_start != compare_rule->dst_port_start)
            {
                continue;
            }

            if (rule->dst_port_end != compare_rule->dst_port_end)
            {
                continue;
            }

            if (rule->src_addr_mask_len != compare_rule->src_addr_mask_len)
            {
                continue;
            }

            if (rule->dst_addr_mask_len != compare_rule->dst_addr_mask_len)
            {
                continue;
            }

            if (rule->ether_type == RTE_ETHER_TYPE_IPV4)
            {
                if ((rule->src_addr_v4 != compare_rule->src_addr_v4) ||
                    (rule->dst_addr_v4 != compare_rule->dst_addr_v4))
                {
                    continue;
                }
            }
            else if (rule->ether_type == RTE_ETHER_TYPE_IPV6)
            {
                if ((memcmp(rule->src_addr_v6, compare_rule->src_addr_v6, sizeof(rule->src_addr_v6)) != 0) ||
                    (memcmp(rule->dst_addr_v6, compare_rule->dst_addr_v6, sizeof(rule->dst_addr_v6)) != 0))
                {
                    continue;
                }
            }

            /* If the rules are identical, mark the current rule as inactive */
            rule->rule_state = RULE_STATE_INACTIVE;
            nr_duplicate_rules++;

            /* Dump the duplicate rule information */
            MR_INFO("\nPkt classifier, rule id: %u, is duplicate with rule id: %u.", rule->rule_id,
                    compare_rule->rule_id);
            MR_INFO("Packet classifier: rule id %u is marked as inactive and will not be loaded.", rule->rule_id);

            classifier_rule_dump(rule);
            classifier_rule_dump(compare_rule);

            break;
        }
    }

    /* If there are no duplicate rules, return */
    if (nr_duplicate_rules == 0)
    {
        return nr_duplicate_rules;
    }

    /* Clean up rule_list by removing invalid rule configurations */
    uint16_t new_nr_rules = 0;
    uint16_t new_nr_static_rules = 0;
    uint16_t new_nr_dynamic_rules = 0;
    struct rule_field_parser new_rule_list[MAX_RULES] = {};

    for (uint32_t rule_index = 0; rule_index < rule_list->nr_rules; rule_index++)
    {
        struct rule_field_parser * rule = &rule_list->rules[rule_index];

        if (rule->rule_state == RULE_STATE_ACTIVE)
        {
            struct rule_field_parser * new_rule = &new_rule_list[new_nr_rules];
            memcpy(new_rule, rule, sizeof(struct rule_field_parser));

            if (rule->rule_attr == RULE_ATTR_STATIC)
            {
                new_nr_static_rules++;
            }
            else if (rule->rule_attr == RULE_ATTR_DYNAMIC)
            {
                new_nr_dynamic_rules++;
            }

            new_nr_rules++;
        }
    }

    /* Update the rule list */
    memset(rule_list->rules, 0, sizeof(rule_list->rules));
    memcpy(rule_list->rules, new_rule_list, sizeof(new_rule_list));
    rule_list->nr_rules = new_nr_rules;
    rule_list->nr_static_rules = new_nr_static_rules;
    rule_list->nr_dynamic_rules = new_nr_dynamic_rules;

    return nr_duplicate_rules;
}

int pkt_classifier_rule_parser(const struct sc_main * sc, enum ruleset_type ruleset_type, enum rule_attribute rule_attr,
                               struct rule_list_parsed * out_rule_list)
{
    const char * file_path = NULL;
    uint16_t * nr_rules_by_type = NULL;

    switch (rule_attr)
    {
    case RULE_ATTR_STATIC:
        file_path = sc->local_cfgfile;
        nr_rules_by_type = &out_rule_list->nr_static_rules;
        break;
    case RULE_ATTR_DYNAMIC:
        file_path = sc->local_dyfile;
        nr_rules_by_type = &out_rule_list->nr_dynamic_rules;
        break;
    default:
        MR_ERROR("Pkt classifier rule parser, cfg_file_type '%u' is invalid.", rule_attr);
        return RT_ERR;
    }

    for (int rule_index = 0; rule_index < MAX_RULES; rule_index++)
    {
        /*  Retrieve the rule ID */
        uint32_t rule_id;
        char str_section[MR_SYMBOL_MAX] = {};
        snprintf(str_section, sizeof(str_section), "classifier_rule:%d", rule_index);
        int ret = MESA_load_profile_uint_nodef(file_path, str_section, "rule_id", &rule_id);
        if (ret < 0)
        {
            continue;
        }

        /* Retrieve the ruleset type; if there's no configured ruleset, break the current rule */

        uint32_t load_ruleset_type;
        MESA_load_profile_uint_def(file_path, str_section, "ruleset_type", &load_ruleset_type, RULESET_TYPE_CLASSIFIER);
        if (load_ruleset_type != ruleset_type)
        {
            continue;
        }

        /* Initialize rule field with default values */
        struct rule_field_parser rule_field_parser = {};
        rule_field_parser.rule_state = RULE_STATE_PENDING;
        rule_field_parser.src_port_start = 0;
        rule_field_parser.src_port_end = 65535;
        rule_field_parser.dst_port_start = 0;
        rule_field_parser.dst_port_end = 65535;
        rule_field_parser.ether_type = UINT16_MAX;
        rule_field_parser.rule_id = rule_id;
        rule_field_parser.rule_attr = rule_attr;

        /* Retrieve the proto */
        uint32_t proto;
        MESA_load_profile_uint_def(file_path, str_section, "proto", &proto, UINT32_MAX);

        if (proto == UINT32_MAX)
        {
            /* UINT32_MAX indicates 'any' */
            rule_field_parser.proto = 0;
            rule_field_parser.proto_mask = 0;
        }
        else if ((proto == IPPROTO_TCP) || (proto == IPPROTO_UDP))
        {
            rule_field_parser.proto = (uint8_t)proto;
            rule_field_parser.proto_mask = UINT8_MAX;
        }
        else
        {
            MR_ERROR("Cfg path : '%s', rule name: '%s', proto must be either 'tcp(6)','udp(17)' or 'any(if not "
                     "configured)'.",
                     file_path, str_section);
            return RT_ERR;
        }

        /* Retrieve source port start and end */
        uint32_t src_port_start = 0, src_port_end = 0;
        int ret_start = MESA_load_profile_uint_def(file_path, str_section, "src_port_start", &src_port_start, 0);
        int ret_end = MESA_load_profile_uint_def(file_path, str_section, "src_port_end", &src_port_end, 65535);

        if ((ret_start >= 0) && (ret_end < 0))
        {
            src_port_end = src_port_start;
        }
        else if ((ret_start < 0) && (ret_end >= 0))
        {
            src_port_start = src_port_end;
        }

        if (src_port_start > src_port_end)
        {
            MR_ERROR("Cfg path : '%s', rule name: '%s', src_port_start must be less than or equal to src_port_end.",
                     file_path, str_section);
            return RT_ERR;
        }

        rule_field_parser.src_port_start = (uint16_t)src_port_start;
        rule_field_parser.src_port_end = (uint16_t)src_port_end;

        /* Retrieve destination port start and end */
        uint32_t dst_port_start = 0, dst_port_end = 0;
        ret_start = MESA_load_profile_uint_def(file_path, str_section, "dst_port_start", &dst_port_start, 0);
        ret_end = MESA_load_profile_uint_def(file_path, str_section, "dst_port_end", &dst_port_end, 65535);

        if ((ret_start >= 0) && (ret_end < 0))
        {
            dst_port_end = dst_port_start;
        }
        else if ((ret_start < 0) && (ret_end >= 0))
        {
            dst_port_start = dst_port_end;
        }

        if (dst_port_start > dst_port_end)
        {
            MR_ERROR("Cfg path : '%s', rule name: '%s', dst_port_start must be less than or equal to dst_port_end.",
                     file_path, str_section);
            return RT_ERR;
        }

        rule_field_parser.dst_port_start = (uint16_t)dst_port_start;
        rule_field_parser.dst_port_end = (uint16_t)dst_port_end;

        /* Retrieve the priority */
        uint32_t priority;
        ret = MESA_load_profile_uint_nodef(file_path, str_section, "priority", &priority);
        if (ret < 0)
        {
            MR_ERROR("Cfg path : '%s', rule name: '%s', must config the 'priority'.", file_path, str_section);
            return RT_ERR;
        }

        if (priority >= 16)
        {
            MR_ERROR("Cfg path : '%s', rule name: '%s', priority must be 0~15.", file_path, str_section);
            return RT_ERR;
        }

        rule_field_parser.priority = (uint8_t)priority;

        /* Retrieve the IPv4 source address and mask*/
        char str_src_ip_addr_v4[MR_SYMBOL_MAX] = {};
        if (MESA_load_profile_string_nodef(file_path, str_section, "src_ip_addr_v4", str_src_ip_addr_v4,
                                           sizeof(str_src_ip_addr_v4)) > 0)
        {
            rule_field_parser.ether_type = RTE_ETHER_TYPE_IPV4;

            ret = inet_pton(AF_INET, str_src_ip_addr_v4, &rule_field_parser.src_addr_v4);
            if ((!ret) && (strcmp(str_src_ip_addr_v4, "0.0.0.0") != 0))
            {
                MR_ERROR("Cfg path : '%s', rule name: '%s', src ip addr is invalid:  %s", file_path, str_section,
                         str_src_ip_addr_v4);
                return RT_ERR;
            }

            MESA_load_profile_uint_def(file_path, str_section, "src_ip_mask_v4", &rule_field_parser.src_addr_mask_len,
                                       32);
        }

        /* Retrieve the IPv4 destination address and mask */
        char str_dst_ip_addr_v4[MR_SYMBOL_MAX] = {};
        if (MESA_load_profile_string_nodef(file_path, str_section, "dst_ip_addr_v4", str_dst_ip_addr_v4,
                                           sizeof(str_dst_ip_addr_v4)) > 0)
        {
            rule_field_parser.ether_type = RTE_ETHER_TYPE_IPV4;
            ret = inet_pton(AF_INET, str_dst_ip_addr_v4, &rule_field_parser.dst_addr_v4);
            if ((!ret) && (strcmp(str_dst_ip_addr_v4, "0.0.0.0") != 0))
            {
                MR_ERROR("Cfg path : '%s', rule name: '%s', dst ip addr is invalid:  %s", file_path, str_section,
                         str_dst_ip_addr_v4);
                return RT_ERR;
            }

            MESA_load_profile_uint_def(file_path, str_section, "dst_ip_mask_v4", &rule_field_parser.dst_addr_mask_len,
                                       32);
        }

        /* Retrieve the IPv6 source address and mask  */
        char str_src_ip_addr_v6[MR_SYMBOL_MAX] = {};
        if (MESA_load_profile_string_nodef(file_path, str_section, "src_ip_addr_v6", str_src_ip_addr_v6,
                                           sizeof(str_src_ip_addr_v6)) > 0)
        {
            /* Verify the IP version */
            if (rule_field_parser.ether_type == RTE_ETHER_TYPE_IPV4)
            {
                MR_ERROR("Cfg path : '%s', rule name: '%s', IPv4 or IPv6 only one can be configured.", file_path,
                         str_section);
                return RT_ERR;
            }

            rule_field_parser.ether_type = RTE_ETHER_TYPE_IPV6;
            ret = inet_pton(AF_INET6, str_src_ip_addr_v6, &rule_field_parser.src_addr_v6);
            if ((!ret) && (strcmp(str_src_ip_addr_v6, "::") != 0))
            {
                MR_ERROR("Cfg path : '%s', rule name: '%s', src ip addr is invalid:  %s", file_path, str_section,
                         str_src_ip_addr_v6);
                return RT_ERR;
            }

            MESA_load_profile_uint_def(file_path, str_section, "src_ip_mask_v6", &rule_field_parser.src_addr_mask_len,
                                       128);
        }

        /* Retrieve the IPv6 destination address and mask  */
        char str_dst_ip_addr_v6[MR_SYMBOL_MAX] = {};
        if (MESA_load_profile_string_nodef(file_path, str_section, "dst_ip_addr_v6", str_dst_ip_addr_v6,
                                           sizeof(str_dst_ip_addr_v6)) > 0)
        {
            /* Verify the IP version */
            if (rule_field_parser.ether_type == RTE_ETHER_TYPE_IPV4)
            {
                MR_ERROR("Cfg path : '%s', rule name: '%s', IPv4 or IPv6 only one can be configured.", file_path,
                         str_section);
                return RT_ERR;
            }

            rule_field_parser.ether_type = RTE_ETHER_TYPE_IPV6;
            ret = inet_pton(AF_INET6, str_dst_ip_addr_v6, &rule_field_parser.dst_addr_v6);
            if ((!ret) && (strcmp(str_dst_ip_addr_v6, "::") != 0))
            {
                MR_ERROR("Cfg path : '%s', rule name: '%s', dst ip addr is invalid:  %s", file_path, str_section,
                         str_dst_ip_addr_v6);
                return RT_ERR;
            }

            MESA_load_profile_uint_def(file_path, str_section, "dst_ip_mask_v6", &rule_field_parser.dst_addr_mask_len,
                                       128);
        }

        /* Retrieve the action */
        uint32_t action;
        ret = MESA_load_profile_uint_nodef(file_path, str_section, "action", &action);

        if (ret < 0)
        {
            MR_ERROR("Cfg path : '%s', rule name: '%s', must config the 'action'.", file_path, str_section);
            return RT_ERR;
        }

        /* Verify if the action type is invalid */
        if (action != ACTION_NF_STEERING)
        {
            MR_ERROR("Cfg path : '%s', rule name: '%s', only 'nf_steering(2)' is supported as the action.", file_path,
                     str_section);
            return RT_ERR;
        }

        rule_field_parser.action.type = action;
        rule_field_parser.action.rule_id = rule_id;

        /* Retrieve the Network Function Steering (NF steering) configuration */
        if (rule_field_parser.action.type == ACTION_NF_STEERING)
        {
            /* Retrieve the SID */
            uint32_t sid = 0;
            ret = MESA_load_profile_uint_nodef(file_path, str_section, "sid", &sid);
            if (ret < 0)
            {
                MR_ERROR("Cfg path : '%s', rule name: '%s', must config the 'sid'.", file_path, str_section);
                return RT_ERR;
            }

            rule_field_parser.action.sid = (uint16_t)sid;

            /* Retrieve the adapter type and ID */
            uint32_t ef_adapter_id = UINT32_MAX;
            uint32_t vwire_id = UINT32_MAX;
            uint32_t tera_adapter_id = UINT32_MAX;
            int ef_ret = MESA_load_profile_uint_nodef(file_path, str_section, "ef_adapter_id", &ef_adapter_id);
            int vwire_ret = MESA_load_profile_uint_nodef(file_path, str_section, "vwire_id", &vwire_id);
            int tera_ret = MESA_load_profile_uint_nodef(file_path, str_section, "tera_adapter_id", &tera_adapter_id);

            if (ef_ret >= 0)
            {
                rule_field_parser.adapter.type = ADAPTER_TYPE_EF;
                rule_field_parser.adapter.id = ef_adapter_id;
            }
            else if (vwire_ret >= 0)
            {
                rule_field_parser.adapter.type = ADAPTER_TYPE_VWIRE;
                rule_field_parser.adapter.id = vwire_id;
            }
            else if (tera_ret >= 0)
            {
                rule_field_parser.adapter.type = ADAPTER_TYPE_TERA;
                rule_field_parser.adapter.id = tera_adapter_id;
            }
            else
            {
                rule_field_parser.adapter.type = ADAPTER_TYPE_ALL;
                rule_field_parser.adapter.id = UINT16_MAX;
            }
        }

        /* Copy the rule field information to the output rule list */
        struct rule_field_parser * rule_field_item = &out_rule_list->rules[out_rule_list->nr_rules];
        memcpy(rule_field_item, &rule_field_parser, sizeof(struct rule_field_parser));

        out_rule_list->nr_rules++;
        (*nr_rules_by_type)++;
        if (out_rule_list->nr_rules >= MAX_RULES)
        {
            MR_ERROR("Cfg path : '%s', rule name: '%s', rules is full.", file_path, str_section);
            return RT_ERR;
        }
    }

    /* Check for duplicate rules */
    uint16_t nr_duplicate_rules = pkt_classifier_duplicate_rules_process(out_rule_list);
    if (nr_duplicate_rules > 0)
    {
        MR_ERROR("Pkt classifier, duplicate rules found: %u", nr_duplicate_rules);
    }

    return RT_SUCCESS;
}