1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-07 18:27:04 +03:00

networkd: route replace parse prefix with generic in_addr_prefix_from_string

This commit is contained in:
Susant Sahani 2017-05-11 10:12:54 +05:30
parent 5efd9f72ca
commit 36423ff433

View File

@ -772,45 +772,18 @@ int config_parse_destination(const char *unit,
if (r < 0) if (r < 0)
return r; return r;
/* Destination|Source=address/prefixlen */ r = in_addr_prefix_from_string(rvalue, AF_INET, &buffer, &prefixlen);
/* address */
e = strchr(rvalue, '/');
if (e)
address = strndupa(rvalue, e - rvalue);
else
address = rvalue;
r = in_addr_from_string_auto(address, &f, &buffer);
if (r < 0) { if (r < 0) {
log_syntax(unit, LOG_ERR, filename, line, r, "Destination is invalid, ignoring assignment: %s", address); r = in_addr_prefix_from_string(rvalue, AF_INET6, &buffer, &prefixlen);
return 0;
}
if (f != AF_INET && f != AF_INET6) {
log_syntax(unit, LOG_ERR, filename, line, 0, "Unknown address family, ignoring assignment: %s", address);
return 0;
}
/* prefixlen */
if (e) {
r = safe_atou8(e + 1, &prefixlen);
if (r < 0) { if (r < 0) {
log_syntax(unit, LOG_ERR, filename, line, r, "Route destination prefix length is invalid, ignoring assignment: %s", e + 1); log_syntax(unit, LOG_ERR, filename, line, r, "Route source or destination prefix is invalid, ignoring assignment: %s", rvalue);
return 0; return 0;
} }
} else {
switch (f) {
case AF_INET:
prefixlen = 32;
break;
case AF_INET6:
prefixlen = 128;
break;
}
}
n->family = f; n->family = AF_INET6;
} else
n->family = AF_INET;
if (streq(lvalue, "Destination")) { if (streq(lvalue, "Destination")) {
n->dst = buffer; n->dst = buffer;
n->dst_prefixlen = prefixlen; n->dst_prefixlen = prefixlen;