Skip to content
Snippets Groups Projects
Commit bd9ced0a authored by Husaam Mehdi's avatar Husaam Mehdi
Browse files

qosmngr: update checks for valid queue rate and fix protocol val

parent cc1d993b
Branches
No related tags found
No related merge requests found
Pipeline #196701 passed
......@@ -11,10 +11,60 @@
#include "qos_bbf.h"
#include "libbbfdm_api.h"
#define PROTOCOLS_FILE "/etc/protocols"
/*************************************************************
* COMMON FUNCTIONS
**************************************************************/
static int is_numeric(const char *str)
{
if (!str || !*str)
return 0;
for (; *str; str++) {
if (!isdigit((unsigned char)*str))
return 0;
}
return 1;
}
static int lookup_protocol_number(const char *protocol)
{
FILE *file = fopen(PROTOCOLS_FILE, "r");
if (!file)
return -1;
char line[256];
while (fgets(line, sizeof(line), file)) {
if (line[0] == '#' || line[0] == '\n')
continue;
char name[32] = {0};
int number = 0;
if (sscanf(line, "%31s %d", name, &number) == 2) {
if (strcasecmp(name, protocol) == 0) {
fclose(file);
return number;
}
}
}
fclose(file);
return -1;
}
static void convert_protocol(char **value)
{
if (!value || !*value || is_numeric(*value))
return;
int protocol_number = lookup_protocol_number(*value);
if (protocol_number >= 0) {
char new_value[12] = {0}; // Enough for an int as a string
snprintf(new_value, 12, "%d", protocol_number);
*value = dmstrdup(new_value);
}
}
static unsigned long qos_get_new_order(void)
{
struct uci_section *s = NULL;
......@@ -754,6 +804,7 @@ static int set_QoSClassification_SourceIP(char *refparam, struct dmctx *ctx, voi
static int get_QoSClassification_Protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmuci_get_value_by_section_fallback_def(((struct dm_data *)data)->config_section, "proto", "-1");
convert_protocol(value);
return 0;
}
......@@ -1622,8 +1673,8 @@ static int set_QoSQueue_ShapingRate(char *refparam, struct dmctx *ctx, void *dat
if (bbfdm_validate_long(ctx, value, RANGE_ARGS{{"-1",NULL}}, 1))
return FAULT_9007;
if (DM_STRTOL(value) >= 0 && DM_STRTOL(value) < 1000) {
bbfdm_set_fault_message(ctx, "ShapingRate value less than 1000 not supported");
if (DM_STRTOL(value) > 100 && DM_STRTOL(value) < 1000) {
bbfdm_set_fault_message(ctx, "ShapingRate value in range 101-999 not supported");
return FAULT_9007;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment