network/fou-tunnel: simplify parsing of protocol number
Previously, we would call parse_ip_protocol(), which internally calls safe_atoi(), and then call safe_atou(). This isn't terrible, but it's also slightly confusing. Use parse_ip_protocol_full() to avoid the second call.
This commit is contained in:
@@ -156,37 +156,32 @@ int config_parse_ip_protocol(
|
||||
void *data,
|
||||
void *userdata) {
|
||||
|
||||
uint8_t *ret = ASSERT_PTR(data);
|
||||
unsigned protocol;
|
||||
/* linux/fou.h defines the netlink field as one byte, so we need to reject protocols numbers that
|
||||
* don't fit in one byte. */
|
||||
int r;
|
||||
|
||||
assert(filename);
|
||||
assert(section);
|
||||
assert(lvalue);
|
||||
assert(rvalue);
|
||||
|
||||
r = parse_ip_protocol(rvalue);
|
||||
if (r >= 0)
|
||||
protocol = r;
|
||||
else {
|
||||
r = safe_atou(rvalue, &protocol);
|
||||
if (r < 0)
|
||||
log_syntax(unit, LOG_WARNING, filename, line, r,
|
||||
"Failed to parse IP protocol '%s' for FooOverUDP tunnel, "
|
||||
"ignoring assignment: %m", rvalue);
|
||||
uint8_t *proto = ASSERT_PTR(data);
|
||||
int r;
|
||||
|
||||
r = parse_ip_protocol_full(rvalue, /* relaxed= */ true);
|
||||
if (r < 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, r,
|
||||
"Failed to parse '%s=%s', ignoring: %m",
|
||||
lvalue, rvalue);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (protocol > UINT8_MAX) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, 0,
|
||||
"IP protocol '%s' for FooOverUDP tunnel out of range, "
|
||||
"ignoring assignment: %m", rvalue);
|
||||
if (r > UINT8_MAX) {
|
||||
/* linux/fou.h defines the netlink field as one byte, so we need to reject
|
||||
* protocols numbers that don't fit in one byte. */
|
||||
log_syntax(unit, LOG_WARNING, filename, line, r,
|
||||
"Invalid '%s=%s', allowed range is 0..255, ignoring.",
|
||||
lvalue, rvalue);
|
||||
return 0;
|
||||
}
|
||||
|
||||
*ret = protocol;
|
||||
*proto = r;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user