HALF ECHO LEARN / REFERENCE COLLECTION
v262.2src/network/networkd-route-nexthop.c
Git blob: 642cc508f05e27c6a112da47c777d5036f39a14f
Lines 1001–1143 of 1,143
r = in_addr_from_string_auto(rvalue, &route->nexthop.family, &route->nexthop.gw);
if (r < 0)
return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue);
route->gateway_from_dhcp_or_ra = false;
return 1;
}
int config_parse_route_nexthop(
const char *unit,
const char *filename,
unsigned line,
const char *section,
unsigned section_line,
const char *lvalue,
int ltype,
const char *rvalue,
void *data,
void *userdata) {
uint32_t id, *p = ASSERT_PTR(data);
int r;
if (isempty(rvalue)) {
*p = 0;
return 1;
}
r = safe_atou32(rvalue, &id);
if (r < 0)
return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue);
if (id == 0) {
log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid nexthop ID, ignoring assignment: %s", rvalue);
return 0;
}
*p = id;
return 1;
}
int config_parse_multipath_route(
const char *unit,
const char *filename,
unsigned line,
const char *section,
unsigned section_line,
const char *lvalue,
int ltype,
const char *rvalue,
void *data,
void *userdata) {
_cleanup_(route_nexthop_freep) RouteNextHop *nh = NULL;
_cleanup_free_ char *word = NULL;
OrderedSet **nexthops = ASSERT_PTR(data);
const char *p;
char *dev;
int r;
assert(filename);
assert(section);
assert(lvalue);
assert(rvalue);
assert(data);
if (isempty(rvalue)) {
*nexthops = ordered_set_free(*nexthops);
return 1;
}
nh = new0(RouteNextHop, 1);
if (!nh)
return log_oom();
p = rvalue;
r = extract_first_word(&p, &word, NULL, 0);
if (r <= 0)
return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue);
dev = strchr(word, '@');
if (dev) {
*dev++ = '\0';
r = parse_ifindex(dev);
if (r > 0)
nh->ifindex = r;
else {
if (!ifname_valid_full(dev, IFNAME_VALID_ALTERNATIVE)) {
log_syntax(unit, LOG_WARNING, filename, line, 0,
"Invalid interface name '%s' in %s=, ignoring: %s", dev, lvalue, rvalue);
return 0;
}
nh->ifname = strdup(dev);
if (!nh->ifname)
return log_oom();
}
}
if (isempty(word)) {
if (!dev)
return log_syntax_parse_error(unit, filename, line, SYNTHETIC_ERRNO(EINVAL), lvalue, rvalue);
} else {
r = in_addr_from_string_auto(word, &nh->family, &nh->gw);
if (r < 0) {
log_syntax(unit, LOG_WARNING, filename, line, r,
"Invalid multipath route gateway '%s', ignoring assignment: %m", rvalue);
return 0;
}
}
if (!isempty(p)) {
r = safe_atou32(p, &nh->weight);
if (r < 0) {
log_syntax(unit, LOG_WARNING, filename, line, r,
"Invalid multipath route weight, ignoring assignment: %s", p);
return 0;
}
/* ip command takes weight in the range 1…255, while kernel takes the value in the
* range 0…254. MultiPathRoute= setting also takes weight in the same range which ip
* command uses, then networkd decreases by one and stores it to match the range which
* kernel uses. */
if (nh->weight == 0 || nh->weight > 256) {
log_syntax(unit, LOG_WARNING, filename, line, 0,
"Invalid multipath route weight, ignoring assignment: %s", p);
return 0;
}
nh->weight--;
}
r = ordered_set_ensure_put(nexthops, &route_nexthop_hash_ops, nh);
if (r == -ENOMEM)
return log_oom();
if (r < 0) {
log_syntax(unit, LOG_WARNING, filename, line, r,
"Failed to store multipath route, ignoring assignment: %m");
return 0;
}
TAKE_PTR(nh);
return 1;
}