network: drop invalid [Neighbor] section earlier

This commit is contained in:
Yu Watanabe 2019-07-11 03:08:31 +09:00
parent b956364db0
commit 044d4b4067
3 changed files with 22 additions and 6 deletions

View File

@ -116,11 +116,6 @@ int neighbor_configure(Neighbor *neighbor, Link *link, link_netlink_message_hand
assert(link->manager);
assert(link->manager->rtnl);
if (neighbor->family == AF_UNSPEC)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Neighbor without Address= configured");
if (neighbor->lladdr_type < 0)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Neighbor without LinkLayerAddress= configured");
r = sd_rtnl_message_new_neigh(link->manager->rtnl, &req, RTM_NEWNEIGH,
link->ifindex, neighbor->family);
if (r < 0)
@ -156,6 +151,25 @@ int neighbor_configure(Neighbor *neighbor, Link *link, link_netlink_message_hand
return 0;
}
int neighbor_section_verify(Neighbor *neighbor) {
if (section_is_invalid(neighbor->section))
return -EINVAL;
if (neighbor->family == AF_UNSPEC)
return log_warning_errno(SYNTHETIC_ERRNO(EINVAL),
"%s: Neighbor section without Address= configured. "
"Ignoring [Neighbor] section from line %u.",
neighbor->section->filename, neighbor->section->line);
if (neighbor->lladdr_type < 0)
return log_warning_errno(SYNTHETIC_ERRNO(EINVAL),
"%s: Neighbor section without LinkLayerAddress= configured. "
"Ignoring [Neighbor] section from line %u.",
neighbor->section->filename, neighbor->section->line);
return 0;
}
int config_parse_neighbor_address(
const char *unit,
const char *filename,

View File

@ -44,6 +44,8 @@ DEFINE_NETWORK_SECTION_FUNCTIONS(Neighbor, neighbor_free);
int neighbor_configure(Neighbor *neighbor, Link *link, link_netlink_message_handler_t callback);
int neighbor_section_verify(Neighbor *neighbor);
CONFIG_PARSER_PROTOTYPE(config_parse_neighbor_address);
CONFIG_PARSER_PROTOTYPE(config_parse_neighbor_hwaddr);
CONFIG_PARSER_PROTOTYPE(config_parse_neighbor_lladdr);

View File

@ -269,7 +269,7 @@ int network_verify(Network *network) {
fdb_entry_free(fdb);
LIST_FOREACH_SAFE(neighbors, neighbor, neighbor_next, network->neighbors)
if (section_is_invalid(neighbor->section))
if (neighbor_section_verify(neighbor) < 0)
neighbor_free(neighbor);
LIST_FOREACH_SAFE(labels, label, label_next, network->address_labels)