mirror of
https://github.com/systemd/systemd.git
synced 2025-01-21 22:04:01 +03:00
parse-util: accept arbitrary MTU size when AF_UNSPEC
When [Link] MTU= is specified in a .network file, we have no idea about that what kind of interface will be configured with the .network file. The maximum and minimum MTU size depend on the kind of interface. So, we should not filter MTU eagerly in the parser. Closes #30140.
This commit is contained in:
parent
f43ce810c4
commit
a0460dfed6
@ -123,8 +123,7 @@ int parse_ifindex(const char *s) {
|
||||
}
|
||||
|
||||
int parse_mtu(int family, const char *s, uint32_t *ret) {
|
||||
uint64_t u;
|
||||
size_t m;
|
||||
uint64_t u, m;
|
||||
int r;
|
||||
|
||||
r = parse_size(s, 1024, &u);
|
||||
@ -134,10 +133,16 @@ int parse_mtu(int family, const char *s, uint32_t *ret) {
|
||||
if (u > UINT32_MAX)
|
||||
return -ERANGE;
|
||||
|
||||
if (family == AF_INET6)
|
||||
switch (family) {
|
||||
case AF_INET:
|
||||
m = IPV4_MIN_MTU; /* This is 68 */
|
||||
break;
|
||||
case AF_INET6:
|
||||
m = IPV6_MIN_MTU; /* This is 1280 */
|
||||
else
|
||||
m = IPV4_MIN_MTU; /* For all other protocols, including 'unspecified' we assume the IPv4 minimal MTU */
|
||||
break;
|
||||
default:
|
||||
m = 0;
|
||||
}
|
||||
|
||||
if (u < m)
|
||||
return -ERANGE;
|
||||
|
@ -914,15 +914,30 @@ TEST(parse_mtu) {
|
||||
assert_se(parse_mtu(AF_UNSPEC, "4294967295", &mtu) >= 0 && mtu == 4294967295);
|
||||
assert_se(parse_mtu(AF_UNSPEC, "500", &mtu) >= 0 && mtu == 500);
|
||||
assert_se(parse_mtu(AF_UNSPEC, "1280", &mtu) >= 0 && mtu == 1280);
|
||||
assert_se(parse_mtu(AF_UNSPEC, "4294967296", &mtu) == -ERANGE);
|
||||
assert_se(parse_mtu(AF_UNSPEC, "68", &mtu) >= 0 && mtu == 68);
|
||||
assert_se(parse_mtu(AF_UNSPEC, "67", &mtu) >= 0 && mtu == 67);
|
||||
assert_se(parse_mtu(AF_UNSPEC, "0", &mtu) >= 0 && mtu == 0);
|
||||
assert_se(parse_mtu(AF_UNSPEC, "", &mtu) == -EINVAL);
|
||||
|
||||
assert_se(parse_mtu(AF_INET, "1500", &mtu) >= 0 && mtu == 1500);
|
||||
assert_se(parse_mtu(AF_INET, "1400", &mtu) >= 0 && mtu == 1400);
|
||||
assert_se(parse_mtu(AF_INET, "65535", &mtu) >= 0 && mtu == 65535);
|
||||
assert_se(parse_mtu(AF_INET, "65536", &mtu) >= 0 && mtu == 65536);
|
||||
assert_se(parse_mtu(AF_INET, "4294967295", &mtu) >= 0 && mtu == 4294967295);
|
||||
assert_se(parse_mtu(AF_INET, "500", &mtu) >= 0 && mtu == 500);
|
||||
assert_se(parse_mtu(AF_INET, "1280", &mtu) >= 0 && mtu == 1280);
|
||||
assert_se(parse_mtu(AF_INET, "4294967296", &mtu) == -ERANGE);
|
||||
assert_se(parse_mtu(AF_INET, "68", &mtu) >= 0 && mtu == 68);
|
||||
assert_se(parse_mtu(AF_INET, "67", &mtu) == -ERANGE);
|
||||
assert_se(parse_mtu(AF_INET, "0", &mtu) == -ERANGE);
|
||||
assert_se(parse_mtu(AF_INET, "", &mtu) == -EINVAL);
|
||||
|
||||
assert_se(parse_mtu(AF_INET6, "1280", &mtu) >= 0 && mtu == 1280);
|
||||
assert_se(parse_mtu(AF_INET6, "1279", &mtu) == -ERANGE);
|
||||
assert_se(parse_mtu(AF_UNSPEC, "4294967296", &mtu) == -ERANGE);
|
||||
assert_se(parse_mtu(AF_INET6, "4294967296", &mtu) == -ERANGE);
|
||||
assert_se(parse_mtu(AF_INET6, "68", &mtu) == -ERANGE);
|
||||
assert_se(parse_mtu(AF_UNSPEC, "68", &mtu) >= 0 && mtu == 68);
|
||||
assert_se(parse_mtu(AF_UNSPEC, "67", &mtu) == -ERANGE);
|
||||
assert_se(parse_mtu(AF_UNSPEC, "0", &mtu) == -ERANGE);
|
||||
assert_se(parse_mtu(AF_UNSPEC, "", &mtu) == -EINVAL);
|
||||
assert_se(parse_mtu(AF_INET6, "", &mtu) == -EINVAL);
|
||||
}
|
||||
|
||||
TEST(parse_loadavg_fixed_point) {
|
||||
|
@ -296,7 +296,7 @@ INVALID_COMMAND_LINES=(
|
||||
"ip=10.0.0.1:::255.255.255::foo99:off"
|
||||
"ip=10.0.0.1:::255.255.255.0:invalid_hostname:foo99:off"
|
||||
"ip=10.0.0.1:::255.255.255.0::verylonginterfacename:off"
|
||||
"ip=:::::dhcp99:dhcp6:0"
|
||||
"ip=:::::dhcp99:dhcp6:4294967296"
|
||||
"ip=:::::dhcp99:dhcp6:-1"
|
||||
"ip=:::::dhcp99:dhcp6:666:52:54:00"
|
||||
"ip=fdef:c400:bd01:1096::2::[fdef:c400:bd01:1096::1]:64::ipv6:off:[fdef:c400:bd01:1096::aaaa]"
|
||||
|
Loading…
x
Reference in New Issue
Block a user