Newer
Older
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
/*
* rules.c - rules wrapper functions
*
* Copyright (C) 2019 IOPSYS Software Solutions AB. All rights reserved.
*
* Author: anjan.chanda@iopsys.eu
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <libubox/list.h>
#include <1905_tlvs.h>
#include "utils/debug.h"
#include "steer_rules.h"
/* Rule types */
enum qos_rule_type {
QOS_RULE_TYPE_DSCP_PCP,
QOS_RULE_TYPE_MSCS,
QOS_RULE_TYPE_SCS,
QOS_RULE_TYPE_MGMT,
};
/* Temporary rule structure which contains both SPR and DSCP parts */
typedef struct temp_rule {
struct list_head list;
struct tlv_spr spr;
enum qos_rule_type type;
union {
struct ieee1905_dscp_pcp_usr dscp;
};
} temp_rule;
/* Rules list */
LIST_HEAD(rules);
int qos_add_dscp_rule(struct tlv_spr *spr, struct ieee1905_dscp_pcp_usr *dscp_pcp)
{
struct temp_rule *r;
list_for_each_entry(r, &rules, list) {
if (r->spr.rule_id == spr->rule_id) {
err("%s: adding DSCP rule exists", __func__);
return -1;
}
}
r = calloc(1, sizeof(struct temp_rule));
if (r == NULL) {
return -1;
}
r->type = QOS_RULE_TYPE_DSCP_PCP;
memcpy(&r->spr, spr, sizeof(struct tlv_spr));
memcpy(&r->dscp, dscp_pcp, sizeof(struct ieee1905_dscp_pcp_usr));
list_add_tail(&r->list, &rules);
return 0;
}
int qos_get_rules(void)
{
struct temp_rule *r;
int nr = 0;
info("Registered QoS rules: ");
list_for_each_entry(r, &rules, list) {
info("[%d] add %d prec %doutput %d always %d",
r->spr.rule_id,
r->spr.add_remove,
r->spr.precedence,
r->spr.output,
r->spr.always_match);
nr++;
}
info("\n");
return nr;
}