mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-03-01 17:10:42 +00:00
[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).
This commit is contained in:
parent
888617dc3b
commit
ac78288eaf
@ -53,6 +53,8 @@ struct proxy *find_stktable(const char *name);
|
||||
* 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 @@ static inline int stktable_alloc_data_type(struct stktable *t, int type, const c
|
||||
/* 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;
|
||||
}
|
||||
|
||||
|
@ -2275,7 +2275,7 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
|
||||
/* 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 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
|
||||
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++;
|
||||
|
Loading…
Reference in New Issue
Block a user