[MEDIUM] stick-tables: add stored data argument type checking
We're now able to return errors based on the validity of an argument
passed to a stick-table store data type. We also support ARG_T_DELAY
to pass delays to stored data types (eg: for rate counters).
diff --git a/include/proto/stick_table.h b/include/proto/stick_table.h
index 7381737..7cfeaae 100644
--- a/include/proto/stick_table.h
+++ b/include/proto/stick_table.h
@@ -53,6 +53,8 @@
* not NULL. Returns PE_NONE (0) if OK or an error code among :
* - PE_ENUM_OOR if <type> does not exist
* - PE_EXIST if <type> is already registered
+ * - PE_ARG_NOT_USE if <sa> was provided but not expected
+ * - PE_ARG_MISSING if <sa> was expected but not provided
*/
static inline int stktable_alloc_data_type(struct stktable *t, int type, const char *sa)
{
@@ -63,12 +65,27 @@
/* already allocated */
return PE_EXIST;
+ switch (stktable_data_types[type].arg_type) {
+ case ARG_T_NONE:
+ if (sa)
+ return PE_ARG_NOT_USED;
+ break;
+ case ARG_T_INT:
+ if (!sa)
+ return PE_ARG_MISSING;
+ t->data_arg[type].i = atoi(sa);
+ break;
+ case ARG_T_DELAY:
+ if (!sa)
+ return PE_ARG_MISSING;
+ sa = parse_time_err(sa, &t->data_arg[type].u, TIME_UNIT_MS);
+ if (sa)
+ return PE_ARG_INVC; /* invalid char */
+ break;
+ }
+
t->data_size += stktable_data_types[type].data_length;
t->data_ofs[type] = -t->data_size;
- /* right now only int type is supported, but we may later support type-
- * specific arg type.
- */
- t->data_arg[type].i = sa ? atoi(sa) : 0;
return PE_NONE;
}
diff --git a/src/cfgparse.c b/src/cfgparse.c
index 3fa6c7e..7a33910 100644
--- a/src/cfgparse.c
+++ b/src/cfgparse.c
@@ -2275,7 +2275,7 @@
/* myidx already points to next arg */
}
else if (strcmp(args[myidx], "store") == 0) {
- int type;
+ int type, err;
char *cw, *nw, *sa;
myidx++;
@@ -2310,10 +2310,33 @@
err_code |= ERR_ALERT | ERR_FATAL;
goto out;
}
- if (stktable_alloc_data_type(&curproxy->table, type, sa)) {
+
+ err = stktable_alloc_data_type(&curproxy->table, type, sa);
+ switch (err) {
+ case PE_NONE: break;
+ case PE_EXIST:
Warning("parsing [%s:%d]: %s: store option '%s' already enabled, ignored.\n",
file, linenum, args[0], cw);
err_code |= ERR_WARN;
+ break;
+
+ case PE_ARG_MISSING:
+ Alert("parsing [%s:%d] : %s: missing argument to store option '%s'.\n",
+ file, linenum, args[0], cw);
+ err_code |= ERR_ALERT | ERR_FATAL;
+ goto out;
+
+ case PE_ARG_NOT_USED:
+ Alert("parsing [%s:%d] : %s: unexpected argument to store option '%s'.\n",
+ file, linenum, args[0], cw);
+ err_code |= ERR_ALERT | ERR_FATAL;
+ goto out;
+
+ default:
+ Alert("parsing [%s:%d] : %s: error when processing store option '%s'.\n",
+ file, linenum, args[0], cw);
+ err_code |= ERR_ALERT | ERR_FATAL;
+ goto out;
}
}
myidx++;