This commit also throws out the redundant string_to_number_*.
Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
exit_error(PARAMETER_PROBLEM,
"HL: unexpected `!'");
- if (string_to_number(optarg, 0, UINT8_MAX, &value) == -1)
+ if (!xtables_strtoui(optarg, NULL, &value, 0, UINT8_MAX))
exit_error(PARAMETER_PROBLEM,
"HL: Expected value between 0 and 255");
unsigned int lev = -1;
unsigned int set = 0;
- if (string_to_number(level, 0, 7, &lev) == -1) {
+ if (!xtables_strtoui(level, NULL, &lev, 0, 7)) {
unsigned int i = 0;
for (i = 0;
if (slash)
*slash = '\0';
- if (string_to_number(buffer, 0, UINT8_MAX, &number) == -1)
+ if (!xtables_strtoui(buffer, NULL, &number, 0, UINT8_MAX))
exit_error(PARAMETER_PROBLEM,
"Invalid ICMPv6 type `%s'\n", buffer);
*type = number;
if (slash) {
- if (string_to_number(slash+1, 0, UINT8_MAX, &number) == -1)
+ if (!xtables_strtoui(slash+1, NULL, &number, 0, UINT8_MAX))
exit_error(PARAMETER_PROBLEM,
"Invalid ICMPv6 code `%s'\n",
slash+1);
} else {
unsigned int number;
- if (string_to_number(name, 0, UINT8_MAX, &number) == -1)
+ if (!xtables_strtoui(name, NULL, &number, 0, UINT8_MAX))
exit_error(PARAMETER_PROBLEM,
"Invalid MH type `%s'\n", name);
return number;
exit_error(PARAMETER_PROBLEM, "Can only specify node number combined with `--new'\n");
if (*flags & PARAM_TOTALNODE)
exit_error(PARAMETER_PROBLEM, "Can only specify total node number once\n");
- if (string_to_number(optarg, 1, CLUSTERIP_MAX_NODES, &num) < 0)
+ if (!xtables_strtoui(optarg, NULL, &num, 1, CLUSTERIP_MAX_NODES))
exit_error(PARAMETER_PROBLEM, "Unable to parse `%s'\n", optarg);
cipinfo->num_total_nodes = num;
*flags |= PARAM_TOTALNODE;
exit_error(PARAMETER_PROBLEM, "Can only specify node number combined with `--new'\n");
if (*flags & PARAM_LOCALNODE)
exit_error(PARAMETER_PROBLEM, "Can only specify local node number once\n");
- if (string_to_number(optarg, 1, CLUSTERIP_MAX_NODES, &num) < 0)
+ if (!xtables_strtoui(optarg, NULL, &num, 1, CLUSTERIP_MAX_NODES))
exit_error(PARAMETER_PROBLEM, "Unable to parse `%s'\n", optarg);
cipinfo->num_local_nodes = 1;
cipinfo->local_nodes[0] = num;
exit_error(PARAMETER_PROBLEM, "Can only specify hash init value combined with `--new'\n");
if (*flags & PARAM_HASHINIT)
exit_error(PARAMETER_PROBLEM, "Can specify hash init value only once\n");
- if (string_to_number(optarg, 0, UINT_MAX, &num) < 0)
+ if (!xtables_strtoui(optarg, NULL, &num, 0, UINT_MAX))
exit_error(PARAMETER_PROBLEM, "Unable to parse `%s'\n", optarg);
cipinfo->hash_initval = num;
*flags |= PARAM_HASHINIT;
if (*flags & IPT_ECN_OP_SET_CWR)
exit_error(PARAMETER_PROBLEM,
"ECN target: Only use --ecn-tcp-cwr ONCE!");
- if (string_to_number(optarg, 0, 1, &result))
+ if (!xtables_strtoui(optarg, NULL, &result, 0, 1))
exit_error(PARAMETER_PROBLEM,
"ECN target: Value out of range");
einfo->operation |= IPT_ECN_OP_SET_CWR;
if (*flags & IPT_ECN_OP_SET_ECE)
exit_error(PARAMETER_PROBLEM,
"ECN target: Only use --ecn-tcp-ece ONCE!");
- if (string_to_number(optarg, 0, 1, &result))
+ if (!xtables_strtoui(optarg, NULL, &result, 0, 1))
exit_error(PARAMETER_PROBLEM,
"ECN target: Value out of range");
einfo->operation |= IPT_ECN_OP_SET_ECE;
if (*flags & IPT_ECN_OP_SET_IP)
exit_error(PARAMETER_PROBLEM,
"ECN target: Only use --ecn-ip-ect ONCE!");
- if (string_to_number(optarg, 0, 3, &result))
+ if (!xtables_strtoui(optarg, NULL, &result, 0, 3))
exit_error(PARAMETER_PROBLEM,
"ECN target: Value out of range");
einfo->operation |= IPT_ECN_OP_SET_IP;
unsigned int lev = -1;
unsigned int set = 0;
- if (string_to_number(level, 0, 7, &lev) == -1) {
+ if (!xtables_strtoui(level, NULL, &lev, 0, 7)) {
unsigned int i = 0;
for (i = 0;
netmask = ip->s_addr;
}
else {
- if (string_to_number(slash+1, 0, 32, &bits) == -1)
+ if (!xtables_strtoui(slash+1, NULL, &bits, 0, 32))
exit_error(PARAMETER_PROBLEM, "Bad netmask `%s'\n",
slash+1);
netmask = bits2netmask(bits);
exit_error(PARAMETER_PROBLEM,
"TTL: unexpected `!'");
- if (string_to_number(optarg, 0, UINT8_MAX, &value) == -1)
+ if (!xtables_strtoui(optarg, NULL, &value, 0, UINT8_MAX))
exit_error(PARAMETER_PROBLEM,
"TTL: Expected value between 0 and 255");
einfo->invert |= IPT_ECN_OP_MATCH_IP;
*flags |= IPT_ECN_OP_MATCH_IP;
einfo->operation |= IPT_ECN_OP_MATCH_IP;
- if (string_to_number(optarg, 0, 3, &result))
+ if (!xtables_strtoui(optarg, NULL, &result, 0, 3))
exit_error(PARAMETER_PROBLEM,
"ECN match: Value out of range");
einfo->ip_ect = result;
if (slash)
*slash = '\0';
- if (string_to_number(buffer, 0, UINT8_MAX, &number) == -1)
+ if (!xtables_strtoui(buffer, NULL, &number, 0, UINT8_MAX))
exit_error(PARAMETER_PROBLEM,
"Invalid ICMP type `%s'\n", buffer);
*type = number;
if (slash) {
- if (string_to_number(slash+1, 0, UINT8_MAX, &number) == -1)
+ if (!xtables_strtoui(slash+1, NULL, &number, 0, UINT8_MAX))
exit_error(PARAMETER_PROBLEM,
"Invalid ICMP code `%s'\n",
slash+1);
switch (c) {
case '2':
- if (string_to_number(optarg, 0, UINT8_MAX, &value) == -1)
+ if (!xtables_strtoui(optarg, NULL, &value, 0, UINT8_MAX))
exit_error(PARAMETER_PROBLEM,
"ttl: Expected value between 0 and 255");
info->ttl = value;
break;
case '3':
- if (string_to_number(optarg, 0, UINT8_MAX, &value) == -1)
+ if (!xtables_strtoui(optarg, NULL, &value, 0, UINT8_MAX))
exit_error(PARAMETER_PROBLEM,
"ttl: Expected value between 0 and 255");
info->ttl = value;
break;
case '4':
- if (string_to_number(optarg, 0, UINT8_MAX, &value) == -1)
+ if (!xtables_strtoui(optarg, NULL, &value, 0, UINT8_MAX))
exit_error(PARAMETER_PROBLEM,
"ttl: Expected value between 0 and 255");
case '=': /* --set-xmark */
case '-': /* --set-mark */
param_act(P_ONE_ACTION, "CONNMARK", *flags & F_MARK);
- if (!strtonum(optarg, &end, &value, 0, UINT32_MAX))
+ if (!xtables_strtoui(optarg, &end, &value, 0, UINT32_MAX))
param_act(P_BAD_VALUE, "CONNMARK", "--set-xmark/--set-mark", optarg);
if (*end == '/')
- if (!strtonum(end + 1, &end, &mask, 0, UINT32_MAX))
+ if (!xtables_strtoui(end + 1, &end, &mask, 0, UINT32_MAX))
param_act(P_BAD_VALUE, "CONNMARK", "--set-xmark/--set-mark", optarg);
if (*end != '\0')
param_act(P_BAD_VALUE, "CONNMARK", "--set-xmark/--set-mark", optarg);
case '&': /* --and-mark */
param_act(P_ONE_ACTION, "CONNMARK", *flags & F_MARK);
- if (!strtonum(optarg, NULL, &mask, 0, UINT32_MAX))
+ if (!xtables_strtoui(optarg, NULL, &mask, 0, UINT32_MAX))
param_act(P_BAD_VALUE, "CONNMARK", "--and-mark", optarg);
info->mode = XT_CONNMARK_SET;
info->ctmark = 0;
case '|': /* --or-mark */
param_act(P_ONE_ACTION, "CONNMARK", *flags & F_MARK);
- if (!strtonum(optarg, NULL, &value, 0, UINT32_MAX))
+ if (!xtables_strtoui(optarg, NULL, &value, 0, UINT32_MAX))
param_act(P_BAD_VALUE, "CONNMARK", "--or-mark", optarg);
info->mode = XT_CONNMARK_SET;
info->ctmark = value;
case '^': /* --xor-mark */
param_act(P_ONE_ACTION, "CONNMARK", *flags & F_MARK);
- if (!strtonum(optarg, NULL, &value, 0, UINT32_MAX))
+ if (!xtables_strtoui(optarg, NULL, &value, 0, UINT32_MAX))
param_act(P_BAD_VALUE, "CONNMARK", "--xor-mark", optarg);
info->mode = XT_CONNMARK_SET;
info->ctmark = value;
exit_error(PARAMETER_PROBLEM, "CONNMARK: --save-mark "
"or --restore-mark is required for "
"--nfmask");
- if (!strtonum(optarg, NULL, &value, 0, UINT32_MAX))
+ if (!xtables_strtoui(optarg, NULL, &value, 0, UINT32_MAX))
param_act(P_BAD_VALUE, "CONNMARK", "--nfmask", optarg);
info->nfmask = value;
return true;
exit_error(PARAMETER_PROBLEM, "CONNMARK: --save-mark "
"or --restore-mark is required for "
"--ctmask");
- if (!strtonum(optarg, NULL, &value, 0, UINT32_MAX))
+ if (!xtables_strtoui(optarg, NULL, &value, 0, UINT32_MAX))
param_act(P_BAD_VALUE, "CONNMARK", "--ctmask", optarg);
info->ctmask = value;
return true;
exit_error(PARAMETER_PROBLEM, "CONNMARK: --save-mark "
"or --restore-mark is required for "
"--mask");
- if (!strtonum(optarg, NULL, &value, 0, UINT32_MAX))
+ if (!xtables_strtoui(optarg, NULL, &value, 0, UINT32_MAX))
param_act(P_BAD_VALUE, "CONNMARK", "--mask", optarg);
info->nfmask = info->ctmask = value;
return true;
{
unsigned int dscp;
- if (string_to_number(s, 0, UINT8_MAX, &dscp) == -1)
+ if (!xtables_strtoui(s, NULL, &dscp, 0, UINT8_MAX))
exit_error(PARAMETER_PROBLEM,
"Invalid dscp `%s'\n", s);
{
struct xt_mark_target_info *markinfo
= (struct xt_mark_target_info *)(*target)->data;
+ unsigned int mark = 0;
switch (c) {
case '1':
- if (string_to_number_l(optarg, 0, 0,
- &markinfo->mark))
+ if (!xtables_strtoui(optarg, NULL, &mark, 0, UINT32_MAX))
exit_error(PARAMETER_PROBLEM, "Bad MARK value `%s'", optarg);
+ markinfo->mark = mark;
if (*flags)
exit_error(PARAMETER_PROBLEM,
"MARK target: Can't specify --set-mark twice");
{
struct xt_mark_target_info_v1 *markinfo
= (struct xt_mark_target_info_v1 *)(*target)->data;
+ unsigned int mark = 0;
switch (c) {
case '1':
return 0;
}
- if (string_to_number_l(optarg, 0, 0, &markinfo->mark))
+ if (!xtables_strtoui(optarg, NULL, &mark, 0, UINT32_MAX))
exit_error(PARAMETER_PROBLEM, "Bad MARK value `%s'", optarg);
-
+ markinfo->mark = mark;
if (*flags)
exit_error(PARAMETER_PROBLEM,
"MARK target: Can't specify --set-mark twice");
case '=': /* --set-mark */
param_act(P_ONE_ACTION, "MARK", *flags & F_MARK);
param_act(P_NO_INVERT, "MARK", "--set-xmark/--set-mark", invert);
- if (!strtonum(optarg, &end, &value, 0, UINT32_MAX))
+ if (!xtables_strtoui(optarg, &end, &value, 0, UINT32_MAX))
param_act(P_BAD_VALUE, "MARK", "--set-xmark/--set-mark", optarg);
if (*end == '/')
- if (!strtonum(end + 1, &end, &mask, 0, UINT32_MAX))
+ if (!xtables_strtoui(end + 1, &end, &mask, 0, UINT32_MAX))
param_act(P_BAD_VALUE, "MARK", "--set-xmark/--set-mark", optarg);
if (*end != '\0')
param_act(P_BAD_VALUE, "MARK", "--set-xmark/--set-mark", optarg);
case '&': /* --and-mark */
param_act(P_ONE_ACTION, "MARK", *flags & F_MARK);
param_act(P_NO_INVERT, "MARK", "--and-mark", invert);
- if (!strtonum(optarg, NULL, &mask, 0, UINT32_MAX))
+ if (!xtables_strtoui(optarg, NULL, &mask, 0, UINT32_MAX))
param_act(P_BAD_VALUE, "MARK", "--and-mark", optarg);
info->mark = 0;
info->mask = ~mask;
case '|': /* --or-mark */
param_act(P_ONE_ACTION, "MARK", *flags & F_MARK);
param_act(P_NO_INVERT, "MARK", "--or-mark", invert);
- if (!strtonum(optarg, NULL, &value, 0, UINT32_MAX))
+ if (!xtables_strtoui(optarg, NULL, &value, 0, UINT32_MAX))
param_act(P_BAD_VALUE, "MARK", "--or-mark", optarg);
info->mark = value;
info->mask = value;
case '^': /* --xor-mark */
param_act(P_ONE_ACTION, "MARK", *flags & F_MARK);
param_act(P_NO_INVERT, "MARK", "--xor-mark", invert);
- if (!strtonum(optarg, NULL, &value, 0, UINT32_MAX))
+ if (!xtables_strtoui(optarg, NULL, &value, 0, UINT32_MAX))
param_act(P_BAD_VALUE, "MARK", "--xor-mark", optarg);
info->mark = value;
info->mask = 0;
{
unsigned int num;
- if (string_to_number(s, 0, UINT16_MAX, &num) == -1)
+ if (!xtables_strtoui(s, NULL, &num, 0, UINT16_MAX))
exit_error(PARAMETER_PROBLEM,
"Invalid queue number `%s'\n", s);
if (*flags)
exit_error(PARAMETER_PROBLEM,
"TCPMSS target: Only one option may be specified");
- if (string_to_number(optarg, 0, UINT16_MAX - hdrsize, &mssval) == -1)
+ if (!xtables_strtoui(optarg, NULL, &mssval,
+ 0, UINT16_MAX - hdrsize))
exit_error(PARAMETER_PROBLEM, "Bad TCPMSS value `%s'", optarg);
mssinfo->mss = mssval;
break;
}
- if (option == 0 && string_to_number(arg, 0, UINT8_MAX, &option) == -1)
+ if (option == 0 &&
+ !xtables_strtoui(arg, NULL, &option, 0, UINT8_MAX))
exit_error(PARAMETER_PROBLEM,
"Bad TCP option value \"%s\"", arg);
case '&': /* --and-tos */
param_act(P_ONLY_ONCE, "TOS", "--and-tos", *flags & FLAG_TOS);
param_act(P_NO_INVERT, "TOS", "--and-tos", invert);
- if (!strtonum(optarg, NULL, &bits, 0, UINT8_MAX))
+ if (!xtables_strtoui(optarg, NULL, &bits, 0, UINT8_MAX))
param_act(P_BAD_VALUE, "TOS", "--and-tos", optarg);
info->tos_value = 0;
info->tos_mask = ~bits;
case '|': /* --or-tos */
param_act(P_ONLY_ONCE, "TOS", "--or-tos", *flags & FLAG_TOS);
param_act(P_NO_INVERT, "TOS", "--or-tos", invert);
- if (!strtonum(optarg, NULL, &bits, 0, UINT8_MAX))
+ if (!xtables_strtoui(optarg, NULL, &bits, 0, UINT8_MAX))
param_act(P_BAD_VALUE, "TOS", "--or-tos", optarg);
info->tos_value = bits;
info->tos_mask = bits;
case '^': /* --xor-tos */
param_act(P_ONLY_ONCE, "TOS", "--xor-tos", *flags & FLAG_TOS);
param_act(P_NO_INVERT, "TOS", "--xor-tos", invert);
- if (!strtonum(optarg, NULL, &bits, 0, UINT8_MAX))
+ if (!xtables_strtoui(optarg, NULL, &bits, 0, UINT8_MAX))
param_act(P_BAD_VALUE, "TOS", "--xor-tos", optarg);
info->tos_value = bits;
info->tos_mask = 0;
{
unsigned int lport;
- if (string_to_number(s, 0, UINT16_MAX, &lport) != -1)
+ if (xtables_strtoui(s, NULL, &lport, 0, UINT16_MAX))
info->lport = htons(lport);
else
param_act(P_BAD_VALUE, "TPROXY", "--on-port", s);
unsigned int value, mask = UINT32_MAX;
char *end;
- if (!strtonum(s, &end, &value, 0, UINT_MAX))
+ if (!xtables_strtoui(s, &end, &value, 0, UINT32_MAX))
param_act(P_BAD_VALUE, "TPROXY", "--tproxy-mark", s);
if (*end == '/')
- if (!strtonum(end + 1, &end, &mask, 0, UINT_MAX))
+ if (!xtables_strtoui(end + 1, &end, &mask, 0, UINT32_MAX))
param_act(P_BAD_VALUE, "TPROXY", "--tproxy-mark", s);
if (*end != '\0')
param_act(P_BAD_VALUE, "TPROXY", "--tproxy-mark", s);
switch (c) {
case '1': /* --mark */
param_act(P_ONLY_ONCE, "connmark", "--mark", *flags & F_MARK);
- if (!strtonum(optarg, &end, &mark, 0, UINT32_MAX))
+ if (!xtables_strtoui(optarg, &end, &mark, 0, UINT32_MAX))
param_act(P_BAD_VALUE, "connmark", "--mark", optarg);
if (*end == '/')
- if (!strtonum(end + 1, &end, &mask, 0, UINT32_MAX))
+ if (!xtables_strtoui(end + 1, &end, &mask, 0, UINT32_MAX))
param_act(P_BAD_VALUE, "connmark", "--mark", optarg);
if (*end != '\0')
param_act(P_BAD_VALUE, "connmark", "--mark", optarg);
{
unsigned int len;
- if (string_to_number(s, 0, 0, &len) == -1)
+ if (!xtables_strtoui(s, NULL, &len, 0, UINT32_MAX))
exit_error(PARAMETER_PROBLEM, "expire value invalid: `%s'\n", s);
else
return len;
unsigned int min, max;
char *end;
- if (!strtonum(s, &end, &min, 0, ~0))
+ if (!xtables_strtoui(s, &end, &min, 0, UINT32_MAX))
param_act(P_BAD_VALUE, "conntrack", "--expires", s);
max = min;
if (*end == ':')
- if (!strtonum(s, &end, &max, 0, UINT32_MAX))
+ if (!xtables_strtoui(s, &end, &max, 0, UINT32_MAX))
param_act(P_BAD_VALUE, "conntrack", "--expires", s);
if (*end != '\0')
param_act(P_BAD_VALUE, "conntrack", "--expires", s);
break;
case 'a': /* --ctorigsrcport */
- if (!strtonum(optarg, NULL, &port, 0, UINT16_MAX))
+ if (!xtables_strtoui(optarg, NULL, &port, 0, UINT16_MAX))
param_act(P_BAD_VALUE, "conntrack",
"--ctorigsrcport", optarg);
info->match_flags |= XT_CONNTRACK_ORIGSRC_PORT;
break;
case 'b': /* --ctorigdstport */
- if (!strtonum(optarg, NULL, &port, 0, UINT16_MAX))
+ if (!xtables_strtoui(optarg, NULL, &port, 0, UINT16_MAX))
param_act(P_BAD_VALUE, "conntrack",
"--ctorigdstport", optarg);
info->match_flags |= XT_CONNTRACK_ORIGDST_PORT;
break;
case 'c': /* --ctreplsrcport */
- if (!strtonum(optarg, NULL, &port, 0, UINT16_MAX))
+ if (!xtables_strtoui(optarg, NULL, &port, 0, UINT16_MAX))
param_act(P_BAD_VALUE, "conntrack",
"--ctreplsrcport", optarg);
info->match_flags |= XT_CONNTRACK_REPLSRC_PORT;
break;
case 'd': /* --ctrepldstport */
- if (!strtonum(optarg, NULL, &port, 0, UINT16_MAX))
+ if (!xtables_strtoui(optarg, NULL, &port, 0, UINT16_MAX))
param_act(P_BAD_VALUE, "conntrack",
"--ctrepldstport", optarg);
info->match_flags |= XT_CONNTRACK_REPLDST_PORT;
{
unsigned int ret;
- if (string_to_number(optstring, 1, UINT8_MAX, &ret) == -1)
+ if (!xtables_strtoui(optstring, NULL, &ret, 1, UINT8_MAX))
exit_error(PARAMETER_PROBLEM, "Bad DCCP option `%s'",
optstring);
{
unsigned int dscp;
- if (string_to_number(s, 0, UINT8_MAX, &dscp) == -1)
+ if (!xtables_strtoui(s, NULL, &dscp, 0, UINT8_MAX))
exit_error(PARAMETER_PROBLEM,
"Invalid dscp `%s'\n", s);
param_act(P_ONLY_ONCE, "hashlimit", "--hashlimit-burst",
*flags & PARAM_BURST);
if (check_inverse(argv[optind-1], &invert, &optind, 0)) break;
- if (string_to_number(optarg, 0, 10000, &num) == -1)
+ if (!xtables_strtoui(optarg, NULL, &num, 0, 10000))
exit_error(PARAMETER_PROBLEM,
"bad --hashlimit-burst `%s'", optarg);
r->cfg.burst = num;
param_act(P_ONLY_ONCE, "hashlimit", "--hashlimit-htable-size",
*flags & PARAM_SIZE);
if (check_inverse(argv[optind-1], &invert, &optind, 0)) break;
- if (string_to_number(optarg, 0, UINT32_MAX, &num) == -1)
+ if (!xtables_strtoui(optarg, NULL, &num, 0, UINT32_MAX))
exit_error(PARAMETER_PROBLEM,
"bad --hashlimit-htable-size: `%s'", optarg);
r->cfg.size = num;
param_act(P_ONLY_ONCE, "hashlimit", "--hashlimit-htable-max",
*flags & PARAM_MAX);
if (check_inverse(argv[optind-1], &invert, &optind, 0)) break;
- if (string_to_number(optarg, 0, UINT32_MAX, &num) == -1)
+ if (!xtables_strtoui(optarg, NULL, &num, 0, UINT32_MAX))
exit_error(PARAMETER_PROBLEM,
"bad --hashlimit-htable-max: `%s'", optarg);
r->cfg.max = num;
"--hashlimit-htable-gcinterval",
*flags & PARAM_GCINTERVAL);
if (check_inverse(argv[optind-1], &invert, &optind, 0)) break;
- if (string_to_number(optarg, 0, UINT32_MAX, &num) == -1)
+ if (!xtables_strtoui(optarg, NULL, &num, 0, UINT32_MAX))
exit_error(PARAMETER_PROBLEM,
"bad --hashlimit-htable-gcinterval: `%s'",
optarg);
param_act(P_ONLY_ONCE, "hashlimit",
"--hashlimit-htable-expire", *flags & PARAM_EXPIRE);
if (check_inverse(argv[optind-1], &invert, &optind, 0)) break;
- if (string_to_number(optarg, 0, UINT32_MAX, &num) == -1)
+ if (!xtables_strtoui(optarg, NULL, &num, 0, UINT32_MAX))
exit_error(PARAMETER_PROBLEM,
"bad --hashlimit-htable-expire: `%s'", optarg);
/* FIXME: not HZ dependent */
case '$': /* --hashlimit-burst */
param_act(P_ONLY_ONCE, "hashlimit", "--hashlimit-burst",
*flags & PARAM_BURST);
- if (!strtonum(optarg, NULL, &num, 0, 10000))
+ if (!xtables_strtoui(optarg, NULL, &num, 0, 10000))
param_act(P_BAD_VALUE, "hashlimit",
"--hashlimit-burst", optarg);
info->cfg.burst = num;
case '&': /* --hashlimit-htable-size */
param_act(P_ONLY_ONCE, "hashlimit", "--hashlimit-htable-size",
*flags & PARAM_SIZE);
- if (!strtonum(optarg, NULL, &num, 0, UINT32_MAX))
+ if (!xtables_strtoui(optarg, NULL, &num, 0, UINT32_MAX))
param_act(P_BAD_VALUE, "hashlimit",
"--hashlimit-htable-size", optarg);
info->cfg.size = num;
case '*': /* --hashlimit-htable-max */
param_act(P_ONLY_ONCE, "hashlimit", "--hashlimit-htable-max",
*flags & PARAM_MAX);
- if (!strtonum(optarg, NULL, &num, 0, UINT32_MAX))
+ if (!xtables_strtoui(optarg, NULL, &num, 0, UINT32_MAX))
param_act(P_BAD_VALUE, "hashlimit",
"--hashlimit-htable-max", optarg);
info->cfg.max = num;
param_act(P_ONLY_ONCE, "hashlimit",
"--hashlimit-htable-gcinterval",
*flags & PARAM_GCINTERVAL);
- if (!strtonum(optarg, NULL, &num, 0, UINT32_MAX))
+ if (!xtables_strtoui(optarg, NULL, &num, 0, UINT32_MAX))
param_act(P_BAD_VALUE, "hashlimit",
"--hashlimit-htable-gcinterval", optarg);
/* FIXME: not HZ dependent!! */
case ')': /* --hashlimit-htable-expire */
param_act(P_ONLY_ONCE, "hashlimit",
"--hashlimit-htable-expire", *flags & PARAM_EXPIRE);
- if (!strtonum(optarg, NULL, &num, 0, UINT32_MAX))
+ if (!xtables_strtoui(optarg, NULL, &num, 0, UINT32_MAX))
param_act(P_BAD_VALUE, "hashlimit",
"--hashlimit-htable-expire", optarg);
/* FIXME: not HZ dependent */
case '<': /* --hashlimit-srcmask */
param_act(P_ONLY_ONCE, "hashlimit", "--hashlimit-srcmask",
*flags & PARAM_SRCMASK);
- if (!strtonum(optarg, NULL, &num, 0, maxmask))
+ if (!xtables_strtoui(optarg, NULL, &num, 0, maxmask))
param_act(P_BAD_VALUE, "hashlimit",
"--hashlimit-srcmask", optarg);
info->cfg.srcmask = num;
case '>': /* --hashlimit-dstmask */
param_act(P_ONLY_ONCE, "hashlimit", "--hashlimit-dstmask",
*flags & PARAM_DSTMASK);
- if (!strtonum(optarg, NULL, &num, 0, maxmask))
+ if (!xtables_strtoui(optarg, NULL, &num, 0, maxmask))
param_act(P_BAD_VALUE, "hashlimit",
"--hashlimit-dstmask", optarg);
info->cfg.dstmask = num;
{
unsigned int len;
- if (string_to_number(s, 0, UINT16_MAX, &len) == -1)
+ if (!xtables_strtoui(s, NULL, &len, 0, UINT32_MAX))
exit_error(PARAMETER_PROBLEM, "length invalid: `%s'\n", s);
else
return len;
case '$':
if (check_inverse(argv[optind-1], &invert, &optind, 0)) break;
- if (string_to_number(optarg, 0, 10000, &num) == -1)
+ if (!xtables_strtoui(optarg, NULL, &num, 0, 10000))
exit_error(PARAMETER_PROBLEM,
"bad --limit-burst `%s'", optarg);
r->burst = num;
switch (c) {
case '1': /* --mark */
param_act(P_ONLY_ONCE, "mark", "--mark", *flags & F_MARK);
- if (!strtonum(optarg, &end, &mark, 0, UINT32_MAX))
+ if (!xtables_strtoui(optarg, &end, &mark, 0, UINT32_MAX))
param_act(P_BAD_VALUE, "mark", "--mark", optarg);
if (*end == '/')
- if (!strtonum(end + 1, &end, &mask, 0, UINT32_MAX))
+ if (!xtables_strtoui(end + 1, &end, &mask, 0, UINT32_MAX))
param_act(P_BAD_VALUE, "mark", "--mark", optarg);
if (*end != '\0')
param_act(P_BAD_VALUE, "mark", "--mark", optarg);
#include <linux/netfilter_ipv4/ipt_owner.h>
#include <linux/netfilter_ipv6/ip6t_owner.h>
+/*
+ * Note: "UINT32_MAX - 1" is used in the code because -1 is a reserved
+ * UID/GID value anyway.
+ */
+
enum {
FLAG_UID_OWNER = 1 << 0,
FLAG_GID_OWNER = 1 << 1,
param_act(P_ONLY_ONCE, "owner", "--uid-owner", *flags & FLAG_UID_OWNER);
if ((pwd = getpwnam(optarg)) != NULL)
id = pwd->pw_uid;
- else if (!strtonum(optarg, NULL, &id, 0, UINT32_MAX - 1))
+ else if (!xtables_strtoui(optarg, NULL, &id, 0, UINT32_MAX - 1))
param_act(P_BAD_VALUE, "owner", "--uid-owner", optarg);
if (invert)
info->invert |= IPT_OWNER_UID;
param_act(P_ONLY_ONCE, "owner", "--gid-owner", *flags & FLAG_GID_OWNER);
if ((grp = getgrnam(optarg)) != NULL)
id = grp->gr_gid;
- else if (!strtonum(optarg, NULL, &id, 0, UINT32_MAX - 1))
+ else if (!xtables_strtoui(optarg, NULL, &id, 0, UINT32_MAX - 1))
param_act(P_BAD_VALUE, "owner", "--gid-owner", optarg);
if (invert)
info->invert |= IPT_OWNER_GID;
case 'p':
param_act(P_ONLY_ONCE, "owner", "--pid-owner", *flags & FLAG_PID_OWNER);
- if (!strtonum(optarg, NULL, &id, 0, INT_MAX))
+ if (!xtables_strtoui(optarg, NULL, &id, 0, INT_MAX))
param_act(P_BAD_VALUE, "owner", "--pid-owner", optarg);
if (invert)
info->invert |= IPT_OWNER_PID;
case 's':
param_act(P_ONLY_ONCE, "owner", "--sid-owner", *flags & FLAG_SID_OWNER);
- if (!strtonum(optarg, NULL, &id, 0, INT_MAX))
+ if (!xtables_strtoui(optarg, NULL, &id, 0, INT_MAX))
param_act(P_BAD_VALUE, "owner", "--sid-value", optarg);
if (invert)
info->invert |= IPT_OWNER_SID;
*flags & FLAG_UID_OWNER);
if ((pwd = getpwnam(optarg)) != NULL)
id = pwd->pw_uid;
- else if (!strtonum(optarg, NULL, &id, 0, UINT32_MAX - 1))
+ else if (!xtables_strtoui(optarg, NULL, &id, 0, UINT32_MAX - 1))
param_act(P_BAD_VALUE, "owner", "--uid-owner", optarg);
if (invert)
info->invert |= IP6T_OWNER_UID;
*flags & FLAG_GID_OWNER);
if ((grp = getgrnam(optarg)) != NULL)
id = grp->gr_gid;
- else if (!strtonum(optarg, NULL, &id, 0, UINT32_MAX - 1))
+ else if (!xtables_strtoui(optarg, NULL, &id, 0, UINT32_MAX - 1))
param_act(P_BAD_VALUE, "owner", "--gid-owner", optarg);
if (invert)
info->invert |= IP6T_OWNER_GID;
case 'p':
param_act(P_ONLY_ONCE, "owner", "--pid-owner",
*flags & FLAG_PID_OWNER);
- if (!strtonum(optarg, NULL, &id, 0, INT_MAX))
+ if (!xtables_strtoui(optarg, NULL, &id, 0, INT_MAX))
param_act(P_BAD_VALUE, "owner", "--pid-owner", optarg);
if (invert)
info->invert |= IP6T_OWNER_PID;
case 's':
param_act(P_ONLY_ONCE, "owner", "--sid-owner",
*flags & FLAG_SID_OWNER);
- if (!strtonum(optarg, NULL, &id, 0, INT_MAX))
+ if (!xtables_strtoui(optarg, NULL, &id, 0, INT_MAX))
param_act(P_BAD_VALUE, "owner", "--sid-owner", optarg);
if (invert)
info->invert |= IP6T_OWNER_SID;
char *end;
/* -1 is reversed, so the max is one less than that. */
- if (!strtonum(s, &end, from, 0, UINT32_MAX - 1))
+ if (!xtables_strtoui(s, &end, from, 0, UINT32_MAX - 1))
param_act(P_BAD_VALUE, "owner", opt, s);
*to = *from;
if (*end == '-' || *end == ':')
- if (!strtonum(end + 1, &end, to, 0, UINT32_MAX - 1))
+ if (!xtables_strtoui(end + 1, &end, to, 0, UINT32_MAX - 1))
param_act(P_BAD_VALUE, "owner", opt, s);
if (*end != '\0')
param_act(P_BAD_VALUE, "owner", opt, s);
const void *entry, struct xt_entry_match **match)
{
struct xt_rateest_match_info *info = (void *)(*match)->data;
+ unsigned int val;
rateest_info = info;
if (!argv[optind] || *argv[optind] == '-' || *argv[optind] == '!')
break;
- if (string_to_number(argv[optind], 0, 0, &info->pps1) < 0)
+ if (!xtables_strtoui(argv[optind], NULL, &val, 0, UINT32_MAX))
exit_error(PARAMETER_PROBLEM,
"rateest: could not parse pps `%s'",
argv[optind]);
+ info->pps1 = val;
optind++;
break;
if (!argv[optind] || *argv[optind] == '-' || *argv[optind] == '!')
break;
- if (string_to_number(argv[optind], 0, 0, &info->pps2) < 0)
+ if (!xtables_strtoui(argv[optind], NULL, &val, 0, UINT32_MAX))
exit_error(PARAMETER_PROBLEM,
"rateest: could not parse pps `%s'",
argv[optind]);
+ info->pps2 = val;
optind++;
break;
const void *entry, struct xt_entry_match **match)
{
struct xt_statistic_info *info = (void *)(*match)->data;
+ unsigned int val;
double prob;
if (invert)
case '3':
if (*flags & 0x4)
exit_error(PARAMETER_PROBLEM, "double --every");
- if (string_to_number(optarg, 0, UINT32_MAX,
- &info->u.nth.every) == -1)
+ if (!xtables_strtoui(optarg, NULL, &val, 0, UINT32_MAX))
exit_error(PARAMETER_PROBLEM,
"cannot parse --every `%s'", optarg);
+ info->u.nth.every = val;
if (info->u.nth.every == 0)
exit_error(PARAMETER_PROBLEM, "--every cannot be 0");
info->u.nth.every--;
case '4':
if (*flags & 0x8)
exit_error(PARAMETER_PROBLEM, "double --packet");
- if (string_to_number(optarg, 0, UINT32_MAX,
- &info->u.nth.packet) == -1)
+ if (!xtables_strtoui(optarg, NULL, &val, 0, UINT32_MAX))
exit_error(PARAMETER_PROBLEM,
"cannot parse --packet `%s'", optarg);
+ info->u.nth.packet = val;
*flags |= 0x8;
break;
default:
{
unsigned int ret;
- if (string_to_number(option, 1, UINT8_MAX, &ret) == -1)
+ if (!xtables_strtoui(option, NULL, &ret, 1, UINT8_MAX))
exit_error(PARAMETER_PROBLEM, "Bad TCP option `%s'", option);
*result = ret;
{
unsigned int mssvaluenum;
- if (string_to_number(mssvalue, 0, UINT16_MAX, &mssvaluenum) != -1)
+ if (!xtables_strtoui(mssvalue, NULL, &mssvaluenum, 0, UINT16_MAX))
return mssvaluenum;
exit_error(PARAMETER_PROBLEM,
unsigned int value;
char *end;
- strtonum(str, &end, &value, 0, max);
+ xtables_strtoui(str, &end, &value, 0, max);
tvm->value = value;
tvm->mask = max;
if (*end == '/') {
const char *p = end + 1;
- if (!strtonum(p, &end, &value, 0, max))
+ if (!xtables_strtoui(p, &end, &value, 0, max))
exit_error(PARAMETER_PROBLEM, "Illegal value: \"%s\"",
str);
tvm->mask = value;
const struct tos_symbol_info *symbol;
char *tmp;
- if (strtonum(str, &tmp, NULL, 0, max))
+ if (xtables_strtoui(str, &tmp, NULL, 0, max))
return tos_parse_numeric(str, tvm, max);
/* Do not consider ECN bits */
extern void xtables_register_match(struct xtables_match *me);
extern void xtables_register_target(struct xtables_target *me);
-extern int string_to_number_ll(const char *s,
- unsigned long long min,
- unsigned long long max,
- unsigned long long *ret);
-extern int string_to_number_l(const char *s,
- unsigned long min,
- unsigned long max,
- unsigned long *ret);
-extern int string_to_number(const char *s,
- unsigned int min,
- unsigned int max,
- unsigned int *ret);
-extern bool strtonuml(const char *, char **, unsigned long *,
+extern bool xtables_strtoul(const char *, char **, unsigned long *,
unsigned long, unsigned long);
-extern bool strtonum(const char *, char **, unsigned int *,
+extern bool xtables_strtoui(const char *, char **, unsigned int *,
unsigned int, unsigned int);
extern int service_to_port(const char *name, const char *proto);
extern u_int16_t parse_port(const char *port, const char *proto);
{
unsigned int proto;
- if (string_to_number(pname, 0, UINT8_MAX, &proto) != -1) {
+ if (xtables_strtoui(pname, NULL, &proto, 0, UINT8_MAX)) {
char *protoname = proto_to_name(proto, nolookup);
if (protoname)
{
unsigned int proto;
- if (string_to_number(s, 0, UINT8_MAX, &proto) == -1) {
+ if (!xtables_strtoui(s, NULL, &proto, 0, UINT8_MAX)) {
struct protoent *pent;
/* first deal with the special case of 'all' to prevent
{
unsigned int rulenum;
- if (string_to_number(rule, 1, INT_MAX, &rulenum) == -1)
+ if (!xtables_strtoui(rule, NULL, &rulenum, 1, INT_MAX))
exit_error(PARAMETER_PROBLEM,
"Invalid rule number `%s'", rule);
{
unsigned int proto;
- if (string_to_number(pname, 0, UINT8_MAX, &proto) != -1) {
+ if (xtables_strtoui(pname, NULL, &proto, 0, UINT8_MAX)) {
char *protoname = proto_to_name(proto, nolookup);
if (protoname)
{
unsigned int proto;
- if (string_to_number(s, 0, UINT8_MAX, &proto) == -1) {
+ if (!xtables_strtoui(s, NULL, &proto, 0, UINT8_MAX)) {
struct protoent *pent;
/* first deal with the special case of 'all' to prevent
{
unsigned int rulenum;
- if (string_to_number(rule, 1, INT_MAX, &rulenum) == -1)
+ if (!xtables_strtoui(rule, NULL, &rulenum, 1, INT_MAX))
exit_error(PARAMETER_PROBLEM,
"Invalid rule number `%s'", rule);
return ret;
}
-int string_to_number_ll(const char *s, unsigned long long min,
- unsigned long long max, unsigned long long *ret)
-{
- unsigned long long number;
- char *end;
-
- /* Handle hex, octal, etc. */
- errno = 0;
- number = strtoull(s, &end, 0);
- if (*end == '\0' && end != s) {
- /* we parsed a number, let's see if we want this */
- if (errno != ERANGE && min <= number && (!max || number <= max)) {
- *ret = number;
- return 0;
- }
- }
- return -1;
-}
-
-int string_to_number_l(const char *s, unsigned long min, unsigned long max,
- unsigned long *ret)
-{
- int result;
- unsigned long long number;
-
- result = string_to_number_ll(s, min, max, &number);
- *ret = (unsigned long)number;
-
- return result;
-}
-
-int string_to_number(const char *s, unsigned int min, unsigned int max,
- unsigned int *ret)
-{
- int result;
- unsigned long number;
-
- result = string_to_number_l(s, min, max, &number);
- *ret = (unsigned int)number;
-
- return result;
-}
-
-/*
- * strtonum{,l} - string to number conversion
+/**
+ * xtables_strtou{i,l} - string to number conversion
+ * @s: input string
+ * @end: like strtoul's "end" pointer
+ * @value: pointer for result
+ * @min: minimum accepted value
+ * @max: maximum accepted value
+ *
+ * If @end is NULL, we assume the caller wants a "strict strtoul", and hence
+ * "15a" is rejected.
+ * In either case, the value obtained is compared for min-max compliance.
+ * Base is always 0, i.e. autodetect depending on @s.
*
- * If @end is NULL, we assume the caller does not want
- * a case like "15a", so reject it.
+ * Returns true/false whether number was accepted. On failure, *value has
+ * undefined contents.
*/
-bool strtonuml(const char *s, char **end, unsigned long *value,
- unsigned long min, unsigned long max)
+bool xtables_strtoul(const char *s, char **end, unsigned long *value,
+ unsigned long min, unsigned long max)
{
unsigned long v;
char *my_end;
return false;
}
-bool strtonum(const char *s, char **end, unsigned int *value,
- unsigned int min, unsigned int max)
+bool xtables_strtoui(const char *s, char **end, unsigned int *value,
+ unsigned int min, unsigned int max)
{
unsigned long v;
bool ret;
- ret = strtonuml(s, end, &v, min, max);
+ ret = xtables_strtoul(s, end, &v, min, max);
if (value != NULL)
*value = v;
return ret;
{
unsigned int portnum;
- if (string_to_number(port, 0, UINT16_MAX, &portnum) != -1 ||
+ if (xtables_strtoui(port, NULL, &portnum, 0, UINT16_MAX) ||
(portnum = service_to_port(port, proto)) != (unsigned)-1)
return portnum;
return NULL;
/* autocomplete, this is a network address */
- if (!strtonum(p, NULL, &onebyte, 0, UINT8_MAX))
+ if (!xtables_strtoui(p, NULL, &onebyte, 0, UINT8_MAX))
return NULL;
addrp[i] = onebyte;
}
*q = '\0';
- if (!strtonum(p, NULL, &onebyte, 0, UINT8_MAX))
+ if (!xtables_strtoui(p, NULL, &onebyte, 0, UINT8_MAX))
return NULL;
addrp[i] = onebyte;
}
/* we have checked 3 bytes, now we check the last one */
- if (!strtonum(p, NULL, &onebyte, 0, UINT8_MAX))
+ if (!xtables_strtoui(p, NULL, &onebyte, 0, UINT8_MAX))
return NULL;
addrp[3] = onebyte;
if ((addrp = numeric_to_ipmask(mask)) != NULL)
/* dotted_to_addr already returns a network byte order addr */
return addrp;
- if (string_to_number(mask, 0, 32, &bits) == -1)
+ if (!xtables_strtoui(mask, NULL, &bits, 0, 32))
exit_error(PARAMETER_PROBLEM,
"invalid mask `%s' specified", mask);
if (bits != 0) {
}
if ((addrp = numeric_to_ip6addr(mask)) != NULL)
return addrp;
- if (string_to_number(mask, 0, 128, &bits) == -1)
+ if (!xtables_strtoui(mask, NULL, &bits, 0, 128))
exit_error(PARAMETER_PROBLEM,
"invalid mask `%s' specified", mask);
if (bits != 0) {