diff --git a/bbf_plugin/qos_bbf.c b/bbf_plugin/qos_bbf.c index 63173cb3a3c8b8f77a4555d874e86b90bfbdbeca..12b7d426c39e2ee5c0880239f618870e18d7de00 100644 --- a/bbf_plugin/qos_bbf.c +++ b/bbf_plugin/qos_bbf.c @@ -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; }