mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-04-27 13:28:32 +00:00
MEDIUM: stktable/cli: simplify entry key handling
Make use of smp_to_stkey() in table_process_entry_per_key() to simplify key handling and leverage auto type conversions from sample API. One noticeable side effect is that integer input checks will be relaxed given that c_str2int() sample conv is more permissible than the integrated table_process_entry_per_key() integer parser.
This commit is contained in:
parent
c6826b9570
commit
0a47e6bccc
@ -4890,8 +4890,7 @@ static int table_process_entry_per_key(struct appctx *appctx, char **args)
|
|||||||
struct show_table_ctx *ctx = appctx->svcctx;
|
struct show_table_ctx *ctx = appctx->svcctx;
|
||||||
struct stktable *t = ctx->target;
|
struct stktable *t = ctx->target;
|
||||||
struct stksess *ts;
|
struct stksess *ts;
|
||||||
uint32_t uint32_key;
|
struct sample key;
|
||||||
unsigned char ip6_key[sizeof(struct in6_addr)];
|
|
||||||
long long value;
|
long long value;
|
||||||
int data_type;
|
int data_type;
|
||||||
int cur_arg;
|
int cur_arg;
|
||||||
@ -4901,35 +4900,16 @@ static int table_process_entry_per_key(struct appctx *appctx, char **args)
|
|||||||
if (!*args[4])
|
if (!*args[4])
|
||||||
return cli_err(appctx, "Key value expected\n");
|
return cli_err(appctx, "Key value expected\n");
|
||||||
|
|
||||||
|
memset(&key, 0, sizeof(key));
|
||||||
|
key.data.type = SMP_T_STR;
|
||||||
|
key.data.u.str.area = args[4];
|
||||||
|
key.data.u.str.data = strlen(args[4]);
|
||||||
|
|
||||||
switch (t->type) {
|
switch (t->type) {
|
||||||
case SMP_T_IPV4:
|
case SMP_T_IPV4:
|
||||||
if (inet_pton(AF_INET, args[4], &uint32_key) <= 0)
|
|
||||||
return cli_err(appctx, "Invalid key\n");
|
|
||||||
static_table_key.key = &uint32_key;
|
|
||||||
break;
|
|
||||||
case SMP_T_IPV6:
|
case SMP_T_IPV6:
|
||||||
if (inet_pton(AF_INET6, args[4], ip6_key) <= 0)
|
|
||||||
return cli_err(appctx, "Invalid key\n");
|
|
||||||
static_table_key.key = &ip6_key;
|
|
||||||
break;
|
|
||||||
case SMP_T_SINT:
|
case SMP_T_SINT:
|
||||||
{
|
|
||||||
char *endptr;
|
|
||||||
unsigned long val;
|
|
||||||
errno = 0;
|
|
||||||
val = strtoul(args[4], &endptr, 10);
|
|
||||||
if ((errno == ERANGE && val == ULONG_MAX) ||
|
|
||||||
(errno != 0 && val == 0) || endptr == args[4] ||
|
|
||||||
val > 0xffffffff)
|
|
||||||
return cli_err(appctx, "Invalid key\n");
|
|
||||||
uint32_key = (uint32_t) val;
|
|
||||||
static_table_key.key = &uint32_key;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case SMP_T_STR:
|
case SMP_T_STR:
|
||||||
static_table_key.key = args[4];
|
|
||||||
static_table_key.key_len = strlen(args[4]);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
switch (ctx->action) {
|
switch (ctx->action) {
|
||||||
@ -4944,6 +4924,12 @@ static int table_process_entry_per_key(struct appctx *appctx, char **args)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* try to convert key according to table type
|
||||||
|
* (it will fill static_table_key on success)
|
||||||
|
*/
|
||||||
|
if (!smp_to_stkey(&key, t))
|
||||||
|
return cli_err(appctx, "Invalid key\n");
|
||||||
|
|
||||||
/* check permissions */
|
/* check permissions */
|
||||||
if (!cli_has_level(appctx, ACCESS_LVL_OPER))
|
if (!cli_has_level(appctx, ACCESS_LVL_OPER))
|
||||||
return 1;
|
return 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user