mirror of
https://github.com/systemd/systemd.git
synced 2025-01-11 09:18:07 +03:00
network: make link enter failed state when a configuration fails
Some path of configuring address, route or etc., go to failed state, but some do not. E.g., failure in address configuration which is provided by DHCPv4 goes to failed state, but static address does not. This is just for consistency. This should not change anything if everything is fine. This also voidify manager_rtnl_process_address().
This commit is contained in:
parent
8eb0cafeb0
commit
4ff296b024
@ -94,10 +94,12 @@ static int address_label_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *
|
||||
return 1;
|
||||
|
||||
r = sd_netlink_message_get_errno(m);
|
||||
if (r < 0 && r != -EEXIST)
|
||||
if (r < 0 && r != -EEXIST) {
|
||||
log_link_warning_errno(link, r, "could not set address label: %m");
|
||||
else if (r >= 0)
|
||||
manager_rtnl_process_address(rtnl, m, link->manager);
|
||||
link_enter_failed(link);
|
||||
return 1;
|
||||
} else if (r >= 0)
|
||||
(void) manager_rtnl_process_address(rtnl, m, link->manager);
|
||||
|
||||
if (link->address_label_messages == 0)
|
||||
log_link_debug(link, "Addresses label set");
|
||||
|
@ -459,9 +459,8 @@ static int dhcp4_address_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *
|
||||
log_link_error_errno(link, r, "Could not set DHCPv4 address: %m");
|
||||
link_enter_failed(link);
|
||||
return 1;
|
||||
}
|
||||
if (r >= 0)
|
||||
manager_rtnl_process_address(rtnl, m, link->manager);
|
||||
} else if (r >= 0)
|
||||
(void) manager_rtnl_process_address(rtnl, m, link->manager);
|
||||
|
||||
r = link_set_dhcp_routes(link);
|
||||
if (r < 0) {
|
||||
@ -470,7 +469,11 @@ static int dhcp4_address_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *
|
||||
}
|
||||
|
||||
/* Add back static routes since kernel removes while DHCPv4 address is removed from when lease expires */
|
||||
link_request_set_routes(link);
|
||||
r = link_request_set_routes(link);
|
||||
if (r < 0) {
|
||||
link_enter_failed(link);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (link->dhcp4_messages == 0) {
|
||||
link->dhcp4_configured = true;
|
||||
|
@ -106,6 +106,9 @@ static int dhcp6_route_remove_handler(sd_netlink *nl, sd_netlink_message *m, Lin
|
||||
|
||||
assert(link);
|
||||
|
||||
if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER))
|
||||
return 1;
|
||||
|
||||
r = sd_netlink_message_get_errno(m);
|
||||
if (r < 0)
|
||||
log_link_debug_errno(link, r, "Received error on unreachable route removal for DHCPv6 delegated subnet: %m");
|
||||
@ -243,8 +246,11 @@ static int dhcp6_route_handler(sd_netlink *nl, sd_netlink_message *m, Link *link
|
||||
|
||||
assert(link);
|
||||
|
||||
if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER))
|
||||
return 1;
|
||||
|
||||
r = sd_netlink_message_get_errno(m);
|
||||
if (r < 0 && r != -EEXIST)
|
||||
if (r < 0 && r != -EEXIST)
|
||||
log_link_debug_errno(link, r, "Received error when adding unreachable route for DHCPv6 delegated subnet: %m");
|
||||
|
||||
return 1;
|
||||
@ -394,6 +400,9 @@ static int dhcp6_address_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *
|
||||
|
||||
assert(link);
|
||||
|
||||
if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER))
|
||||
return 1;
|
||||
|
||||
r = sd_netlink_message_get_errno(m);
|
||||
if (r < 0 && r != -EEXIST) {
|
||||
if (link->rtnl_extended_attrs) {
|
||||
@ -411,9 +420,13 @@ static int dhcp6_address_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *
|
||||
return 1;
|
||||
}
|
||||
if (r >= 0)
|
||||
manager_rtnl_process_address(rtnl, m, link->manager);
|
||||
(void) manager_rtnl_process_address(rtnl, m, link->manager);
|
||||
|
||||
link_request_set_routes(link);
|
||||
r = link_request_set_routes(link);
|
||||
if (r < 0) {
|
||||
link_enter_failed(link);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
@ -448,9 +461,9 @@ static int dhcp6_address_change(
|
||||
|
||||
r = address_configure(addr, link, dhcp6_address_handler, true);
|
||||
if (r < 0)
|
||||
log_link_warning_errno(link, r, "Could not assign DHCPv6 address: %m");
|
||||
return log_link_warning_errno(link, r, "Could not assign DHCPv6 address: %m");
|
||||
|
||||
return r;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int dhcp6_lease_address_acquired(sd_dhcp6_client *client, Link *link) {
|
||||
@ -705,11 +718,17 @@ static int dhcp6_route_add_handler(sd_netlink *nl, sd_netlink_message *m, Link *
|
||||
|
||||
assert(link);
|
||||
|
||||
r = sd_netlink_message_get_errno(m);
|
||||
if (r < 0 && r != -EEXIST)
|
||||
log_link_debug_errno(link, r, "Received error adding DHCPv6 Prefix Delegation route: %m");
|
||||
if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER))
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
r = sd_netlink_message_get_errno(m);
|
||||
if (r < 0 && r != -EEXIST) {
|
||||
log_link_debug_errno(link, r, "Received error adding DHCPv6 Prefix Delegation route: %m");
|
||||
link_enter_failed(link);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int dhcp6_prefix_add(Manager *m, struct in6_addr *addr, Link *link) {
|
||||
@ -762,9 +781,15 @@ static int dhcp6_prefix_remove_handler(sd_netlink *nl, sd_netlink_message *m, Li
|
||||
|
||||
assert(link);
|
||||
|
||||
if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER))
|
||||
return 1;
|
||||
|
||||
r = sd_netlink_message_get_errno(m);
|
||||
if (r < 0)
|
||||
if (r < 0) {
|
||||
log_link_debug_errno(link, r, "Received error on DHCPv6 Prefix Delegation route removal: %m");
|
||||
link_enter_failed(link);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -100,9 +100,15 @@ static int set_fdb_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link)
|
||||
|
||||
assert(link);
|
||||
|
||||
if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER))
|
||||
return 1;
|
||||
|
||||
r = sd_netlink_message_get_errno(m);
|
||||
if (r < 0 && r != -EEXIST)
|
||||
if (r < 0 && r != -EEXIST) {
|
||||
log_link_error_errno(link, r, "Could not add FDB entry: %m");
|
||||
link_enter_failed(link);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -67,6 +67,7 @@ static int ipv4ll_route_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *l
|
||||
if (r < 0 && r != -EEXIST) {
|
||||
log_link_error_errno(link, r, "could not set ipv4ll route: %m");
|
||||
link_enter_failed(link);
|
||||
return 1;
|
||||
}
|
||||
|
||||
link->ipv4ll_route = true;
|
||||
@ -103,8 +104,9 @@ static int ipv4ll_address_handler(sd_netlink *rtnl, sd_netlink_message *m, Link
|
||||
if (r < 0 && r != -EEXIST) {
|
||||
log_link_error_errno(link, r, "could not set ipv4ll address: %m");
|
||||
link_enter_failed(link);
|
||||
return 1;
|
||||
} else if (r >= 0)
|
||||
manager_rtnl_process_address(rtnl, m, link->manager);
|
||||
(void) manager_rtnl_process_address(rtnl, m, link->manager);
|
||||
|
||||
link->ipv4ll_address = true;
|
||||
|
||||
|
@ -870,11 +870,8 @@ static int link_request_set_routing_policy_rule(Link *link) {
|
||||
}
|
||||
|
||||
r = routing_policy_rule_configure(rule, link, NULL);
|
||||
if (r < 0) {
|
||||
log_link_warning_errno(link, r, "Could not set routing policy rules: %m");
|
||||
link_enter_failed(link);
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_link_warning_errno(link, r, "Could not set routing policy rules: %m");
|
||||
if (r > 0)
|
||||
link->routing_policy_rule_messages++;
|
||||
}
|
||||
@ -905,8 +902,11 @@ static int route_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
|
||||
return 1;
|
||||
|
||||
r = sd_netlink_message_get_errno(m);
|
||||
if (r < 0 && r != -EEXIST)
|
||||
if (r < 0 && r != -EEXIST) {
|
||||
log_link_warning_errno(link, r, "Could not set route: %m");
|
||||
link_enter_failed(link);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (link->route_messages == 0) {
|
||||
log_link_debug(link, "Routes set");
|
||||
@ -946,11 +946,8 @@ int link_request_set_routes(Link *link) {
|
||||
continue;
|
||||
|
||||
r = route_configure(rt, link, route_handler);
|
||||
if (r < 0) {
|
||||
log_link_warning_errno(link, r, "Could not set routes: %m");
|
||||
link_enter_failed(link);
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_link_warning_errno(link, r, "Could not set routes: %m");
|
||||
if (r > 0)
|
||||
link->route_messages++;
|
||||
}
|
||||
@ -969,6 +966,7 @@ int link_request_set_routes(Link *link) {
|
||||
void link_check_ready(Link *link) {
|
||||
Address *a;
|
||||
Iterator i;
|
||||
int r;
|
||||
|
||||
assert(link);
|
||||
|
||||
@ -990,7 +988,9 @@ void link_check_ready(Link *link) {
|
||||
|
||||
if (!link->addresses_ready) {
|
||||
link->addresses_ready = true;
|
||||
link_request_set_routes(link);
|
||||
r = link_request_set_routes(link);
|
||||
if (r < 0)
|
||||
link_enter_failed(link);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1039,11 +1039,8 @@ static int link_request_set_neighbors(Link *link) {
|
||||
|
||||
LIST_FOREACH(neighbors, neighbor, link->network->neighbors) {
|
||||
r = neighbor_configure(neighbor, link, NULL);
|
||||
if (r < 0) {
|
||||
log_link_warning_errno(link, r, "Could not set neighbor: %m");
|
||||
link_enter_failed(link);
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_link_warning_errno(link, r, "Could not set neighbor: %m");
|
||||
}
|
||||
|
||||
if (link->neighbor_messages == 0) {
|
||||
@ -1074,10 +1071,12 @@ static int address_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link)
|
||||
return 1;
|
||||
|
||||
r = sd_netlink_message_get_errno(m);
|
||||
if (r < 0 && r != -EEXIST)
|
||||
if (r < 0 && r != -EEXIST) {
|
||||
log_link_warning_errno(link, r, "could not set address: %m");
|
||||
else if (r >= 0)
|
||||
manager_rtnl_process_address(rtnl, m, link->manager);
|
||||
link_enter_failed(link);
|
||||
return 1;
|
||||
} else if (r >= 0)
|
||||
(void) manager_rtnl_process_address(rtnl, m, link->manager);
|
||||
|
||||
if (link->address_messages == 0) {
|
||||
log_link_debug(link, "Addresses set");
|
||||
@ -1131,22 +1130,16 @@ static int link_request_set_addresses(Link *link) {
|
||||
update = address_get(link, ad->family, &ad->in_addr, ad->prefixlen, NULL) > 0;
|
||||
|
||||
r = address_configure(ad, link, address_handler, update);
|
||||
if (r < 0) {
|
||||
log_link_warning_errno(link, r, "Could not set addresses: %m");
|
||||
link_enter_failed(link);
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_link_warning_errno(link, r, "Could not set addresses: %m");
|
||||
if (r > 0)
|
||||
link->address_messages++;
|
||||
}
|
||||
|
||||
LIST_FOREACH(labels, label, link->network->address_labels) {
|
||||
r = address_label_configure(label, link, NULL, false);
|
||||
if (r < 0) {
|
||||
log_link_warning_errno(link, r, "Could not set address label: %m");
|
||||
link_enter_failed(link);
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_link_warning_errno(link, r, "Could not set address label: %m");
|
||||
|
||||
link->address_label_messages++;
|
||||
}
|
||||
@ -1155,10 +1148,8 @@ static int link_request_set_addresses(Link *link) {
|
||||
start it */
|
||||
if (link_dhcp4_server_enabled(link) && (link->flags & IFF_UP)) {
|
||||
r = dhcp4_server_configure(link);
|
||||
if (r < 0) {
|
||||
link_enter_failed(link);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
log_link_debug(link, "Offering DHCPv4 leases");
|
||||
}
|
||||
|
||||
@ -1211,16 +1202,17 @@ static int set_mtu_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link)
|
||||
return 1;
|
||||
|
||||
r = sd_netlink_message_get_errno(m);
|
||||
if (r < 0) {
|
||||
log_link_warning_errno(link, r, "Could not set MTU: %m");
|
||||
return 1;
|
||||
if (r < 0)
|
||||
log_link_warning_errno(link, r, "Could not set MTU, ignoring: %m");
|
||||
else
|
||||
log_link_debug(link, "Setting MTU done.");
|
||||
|
||||
if (link->state == LINK_STATE_INITIALIZED) {
|
||||
r = link_configure_after_setting_mtu(link);
|
||||
if (r < 0)
|
||||
link_enter_failed(link);
|
||||
}
|
||||
|
||||
log_link_debug(link, "Setting MTU done.");
|
||||
|
||||
if (link->state == LINK_STATE_INITIALIZED)
|
||||
(void) link_configure_after_setting_mtu(link);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -1327,7 +1319,7 @@ static int set_flags_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link
|
||||
|
||||
r = sd_netlink_message_get_errno(m);
|
||||
if (r < 0)
|
||||
log_link_warning_errno(link, r, "Could not set link flags: %m");
|
||||
log_link_warning_errno(link, r, "Could not set link flags, ignoring: %m");
|
||||
|
||||
return 1;
|
||||
}
|
||||
@ -1494,7 +1486,7 @@ static int link_address_genmode_handler(sd_netlink *rtnl, sd_netlink_message *m,
|
||||
|
||||
r = sd_netlink_message_get_errno(m);
|
||||
if (r < 0)
|
||||
log_link_warning_errno(link, r, "Could not set address genmode for interface: %m");
|
||||
log_link_warning_errno(link, r, "Could not set address genmode for interface, ignoring: %m");
|
||||
|
||||
return 1;
|
||||
}
|
||||
@ -2033,11 +2025,14 @@ static int netdev_join_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *li
|
||||
log_link_error_errno(link, r, "Could not join netdev: %m");
|
||||
link_enter_failed(link);
|
||||
return 1;
|
||||
} else
|
||||
log_link_debug(link, "Joined netdev");
|
||||
}
|
||||
|
||||
log_link_debug(link, "Joined netdev");
|
||||
|
||||
if (link->enslaving == 0) {
|
||||
link_joined(link);
|
||||
r = link_joined(link);
|
||||
if (r < 0)
|
||||
link_enter_failed(link);
|
||||
}
|
||||
|
||||
return 1;
|
||||
@ -2642,7 +2637,7 @@ configure:
|
||||
while ((link = set_steal_first(manager->links_requesting_uuid))) {
|
||||
r = link_configure(link);
|
||||
if (r < 0)
|
||||
log_link_error_errno(link, r, "Failed to configure link: %m");
|
||||
link_enter_failed(link);
|
||||
}
|
||||
|
||||
manager->links_requesting_uuid = set_free(manager->links_requesting_uuid);
|
||||
@ -2787,7 +2782,11 @@ static int link_initialized_and_synced(Link *link) {
|
||||
}
|
||||
|
||||
static int link_initialized_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
|
||||
(void) link_initialized_and_synced(link);
|
||||
int r;
|
||||
|
||||
r = link_initialized_and_synced(link);
|
||||
if (r < 0)
|
||||
link_enter_failed(link);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -27,13 +27,23 @@ static int ndisc_netlink_route_message_handler(sd_netlink *rtnl, sd_netlink_mess
|
||||
|
||||
link->ndisc_messages--;
|
||||
|
||||
if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER))
|
||||
return 1;
|
||||
|
||||
r = sd_netlink_message_get_errno(m);
|
||||
if (r < 0 && r != -EEXIST)
|
||||
if (r < 0 && r != -EEXIST) {
|
||||
log_link_error_errno(link, r, "Could not set NDisc route or address: %m");
|
||||
link_enter_failed(link);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (link->ndisc_messages == 0) {
|
||||
link->ndisc_configured = true;
|
||||
link_request_set_routes(link);
|
||||
r = link_request_set_routes(link);
|
||||
if (r < 0) {
|
||||
link_enter_failed(link);
|
||||
return 1;
|
||||
}
|
||||
link_check_ready(link);
|
||||
}
|
||||
|
||||
@ -48,15 +58,24 @@ static int ndisc_netlink_address_message_handler(sd_netlink *rtnl, sd_netlink_me
|
||||
|
||||
link->ndisc_messages--;
|
||||
|
||||
if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER))
|
||||
return 1;
|
||||
|
||||
r = sd_netlink_message_get_errno(m);
|
||||
if (r < 0 && r != -EEXIST)
|
||||
if (r < 0 && r != -EEXIST) {
|
||||
log_link_error_errno(link, r, "Could not set NDisc route or address: %m");
|
||||
else if (r >= 0)
|
||||
manager_rtnl_process_address(rtnl, m, link->manager);
|
||||
link_enter_failed(link);
|
||||
return 1;
|
||||
} else if (r >= 0)
|
||||
(void) manager_rtnl_process_address(rtnl, m, link->manager);
|
||||
|
||||
if (link->ndisc_messages == 0) {
|
||||
link->ndisc_configured = true;
|
||||
link_request_set_routes(link);
|
||||
r = link_request_set_routes(link);
|
||||
if (r < 0) {
|
||||
link_enter_failed(link);
|
||||
return 1;
|
||||
}
|
||||
link_check_ready(link);
|
||||
}
|
||||
|
||||
|
@ -95,7 +95,8 @@ static int neighbor_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link)
|
||||
|
||||
r = sd_netlink_message_get_errno(m);
|
||||
if (r < 0 && r != -EEXIST)
|
||||
log_link_warning_errno(link, r, "Could not set neighbor: %m");
|
||||
/* Neighbor may not exist yet. So, do not enter failed state here. */
|
||||
log_link_warning_errno(link, r, "Could not set neighbor, ignoring: %m");
|
||||
|
||||
if (link->neighbor_messages == 0) {
|
||||
log_link_debug(link, "Neighbors set");
|
||||
|
@ -408,8 +408,11 @@ static int routing_policy_rule_handler(sd_netlink *rtnl, sd_netlink_message *m,
|
||||
return 1;
|
||||
|
||||
r = sd_netlink_message_get_errno(m);
|
||||
if (r < 0 && r != -EEXIST)
|
||||
if (r < 0 && r != -EEXIST) {
|
||||
log_link_warning_errno(link, r, "Could not add routing policy rule: %m");
|
||||
link_enter_failed(link);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (link->routing_policy_rule_messages == 0) {
|
||||
log_link_debug(link, "Routing policy rule configured");
|
||||
|
Loading…
Reference in New Issue
Block a user