[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;
}