6 struct tos_value_mask
{
10 static const struct tos_symbol_info
{
13 } tos_symbol_names
[] = {
14 {IPTOS_LOWDELAY
, "Minimize-Delay"},
15 {IPTOS_THROUGHPUT
, "Maximize-Throughput"},
16 {IPTOS_RELIABILITY
, "Maximize-Reliability"},
17 {IPTOS_MINCOST
, "Minimize-Cost"},
18 {IPTOS_NORMALSVC
, "Normal-Service"},
23 * tos_parse_numeric - parse sth. like "15/255"
26 * @info: accompanying structure
27 * @bits: number of bits that are allowed
28 * (8 for IPv4 TOS field, 4 for IPv6 Priority Field)
30 static bool tos_parse_numeric(const char *str
, struct tos_value_mask
*tvm
,
33 const unsigned int max
= (1 << bits
) - 1;
37 xtables_strtoui(str
, &end
, &value
, 0, max
);
42 const char *p
= end
+ 1;
44 if (!xtables_strtoui(p
, &end
, &value
, 0, max
))
45 xtables_error(PARAMETER_PROBLEM
, "Illegal value: \"%s\"",
51 xtables_error(PARAMETER_PROBLEM
, "Illegal value: \"%s\"", str
);
55 static bool tos_parse_symbolic(const char *str
, struct tos_value_mask
*tvm
,
56 unsigned int def_mask
)
58 const unsigned int max
= UINT8_MAX
;
59 const struct tos_symbol_info
*symbol
;
62 if (xtables_strtoui(str
, &tmp
, NULL
, 0, max
))
63 return tos_parse_numeric(str
, tvm
, max
);
65 /* Do not consider ECN bits */
67 for (symbol
= tos_symbol_names
; symbol
->name
!= NULL
; ++symbol
)
68 if (strcasecmp(str
, symbol
->name
) == 0) {
69 tvm
->value
= symbol
->value
;
73 xtables_error(PARAMETER_PROBLEM
, "Symbolic name \"%s\" is unknown", str
);
77 static bool tos_try_print_symbolic(const char *prefix
,
78 u_int8_t value
, u_int8_t mask
)
80 const struct tos_symbol_info
*symbol
;
85 for (symbol
= tos_symbol_names
; symbol
->name
!= NULL
; ++symbol
)
86 if (value
== symbol
->value
) {
87 printf("%s%s ", prefix
, symbol
->name
);