mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-12-23 17:34:00 +03:00
Merge pull request #19656 from yuwata/network-trivial-cleanups
network: several trivial cleanups
This commit is contained in:
commit
aa4d11a4eb
@ -82,8 +82,7 @@ static int address_label_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *
|
||||
log_link_message_warning_errno(link, m, r, "Could not set address label");
|
||||
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");
|
||||
|
@ -653,14 +653,13 @@ static int address_set_netlink_message(const Address *address, sd_netlink_messag
|
||||
return 0;
|
||||
}
|
||||
|
||||
int address_remove_handler_internal(sd_netlink *rtnl, sd_netlink_message *m, Link *link, const char *error_msg) {
|
||||
static int address_remove_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
|
||||
int r;
|
||||
|
||||
assert(rtnl);
|
||||
assert(m);
|
||||
assert(link);
|
||||
assert(link->address_remove_messages > 0);
|
||||
assert(error_msg);
|
||||
|
||||
link->address_remove_messages--;
|
||||
|
||||
@ -669,22 +668,12 @@ int address_remove_handler_internal(sd_netlink *rtnl, sd_netlink_message *m, Lin
|
||||
|
||||
r = sd_netlink_message_get_errno(m);
|
||||
if (r < 0 && r != -EADDRNOTAVAIL)
|
||||
log_link_message_warning_errno(link, m, r, error_msg);
|
||||
else if (r >= 0)
|
||||
(void) manager_rtnl_process_address(rtnl, m, link->manager);
|
||||
log_link_message_warning_errno(link, m, r, "Could not drop address");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int address_remove_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
|
||||
return address_remove_handler_internal(rtnl, m, link, "Could not drop address");
|
||||
}
|
||||
|
||||
int address_remove(
|
||||
const Address *address,
|
||||
Link *link,
|
||||
link_netlink_message_handler_t callback) {
|
||||
|
||||
int address_remove(const Address *address, Link *link) {
|
||||
_cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL;
|
||||
int r;
|
||||
|
||||
@ -707,7 +696,7 @@ int address_remove(
|
||||
return r;
|
||||
|
||||
r = netlink_call_async(link->manager->rtnl, NULL, req,
|
||||
callback ?: address_remove_handler,
|
||||
address_remove_handler,
|
||||
link_netlink_destroy_callback, link);
|
||||
if (r < 0)
|
||||
return log_link_error_errno(link, r, "Could not send rtnetlink message: %m");
|
||||
@ -834,7 +823,7 @@ int link_drop_foreign_addresses(Link *link) {
|
||||
r = k;
|
||||
}
|
||||
} else {
|
||||
k = address_remove(address, link, NULL);
|
||||
k = address_remove(address, link);
|
||||
if (k < 0 && r >= 0)
|
||||
r = k;
|
||||
}
|
||||
@ -854,7 +843,7 @@ int link_drop_addresses(Link *link) {
|
||||
if (address->family == AF_INET6 && in6_addr_is_link_local(&address->in_addr.in6) == 1 && link_ipv6ll_enabled(link))
|
||||
continue;
|
||||
|
||||
k = address_remove(address, link, NULL);
|
||||
k = address_remove(address, link);
|
||||
if (k < 0 && r >= 0) {
|
||||
r = k;
|
||||
continue;
|
||||
@ -934,8 +923,7 @@ int address_configure_handler_internal(sd_netlink *rtnl, sd_netlink_message *m,
|
||||
log_link_message_warning_errno(link, m, r, error_msg);
|
||||
link_enter_failed(link);
|
||||
return 0;
|
||||
} else if (r >= 0)
|
||||
(void) manager_rtnl_process_address(rtnl, m, link->manager);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
@ -1434,7 +1422,7 @@ static void static_address_on_acd(sd_ipv4acd *acd, int event, void *userdata) {
|
||||
case SD_IPV4ACD_EVENT_CONFLICT:
|
||||
log_link_warning(link, "DAD conflict. Dropping address "IPV4_ADDRESS_FMT_STR,
|
||||
IPV4_ADDRESS_FMT_VAL(address->in_addr.in));
|
||||
r = address_remove(address, link, NULL);
|
||||
r = address_remove(address, link);
|
||||
if (r < 0)
|
||||
log_link_error_errno(link, r, "Failed to drop DAD conflicted address "IPV4_ADDRESS_FMT_STR,
|
||||
IPV4_ADDRESS_FMT_VAL(address->in_addr.in));
|
||||
|
@ -53,8 +53,7 @@ int address_new(Address **ret);
|
||||
Address *address_free(Address *address);
|
||||
int address_get(Link *link, const Address *in, Address **ret);
|
||||
int address_configure_handler_internal(sd_netlink *rtnl, sd_netlink_message *m, Link *link, const char *error_msg);
|
||||
int address_remove_handler_internal(sd_netlink *rtnl, sd_netlink_message *m, Link *link, const char *error_msg);
|
||||
int address_remove(const Address *address, Link *link, link_netlink_message_handler_t callback);
|
||||
int address_remove(const Address *address, Link *link);
|
||||
bool address_equal(const Address *a1, const Address *a2);
|
||||
bool address_is_ready(const Address *a);
|
||||
void address_set_broadcast(Address *a);
|
||||
|
@ -66,13 +66,13 @@ static int dhcp4_release_old_lease(Link *link) {
|
||||
log_link_debug(link, "Removing old DHCPv4 address and routes.");
|
||||
|
||||
SET_FOREACH(route, link->dhcp_routes_old) {
|
||||
k = route_remove(route, NULL, link, NULL);
|
||||
k = route_remove(route, NULL, link);
|
||||
if (k < 0)
|
||||
r = k;
|
||||
}
|
||||
|
||||
if (link->dhcp_address_old) {
|
||||
k = address_remove(link->dhcp_address_old, link, NULL);
|
||||
k = address_remove(link->dhcp_address_old, link);
|
||||
if (k < 0)
|
||||
r = k;
|
||||
}
|
||||
@ -180,6 +180,10 @@ static int dhcp4_route_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *li
|
||||
if (r < 0)
|
||||
link_enter_failed(link);
|
||||
|
||||
r = dhcp4_request_address_and_routes(link, false);
|
||||
if (r < 0)
|
||||
link_enter_failed(link);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -712,48 +716,6 @@ static int dhcp_reset_hostname(Link *link) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int dhcp4_route_remove_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
|
||||
int r;
|
||||
|
||||
assert(link);
|
||||
assert(link->dhcp4_remove_messages > 0);
|
||||
|
||||
link->dhcp4_remove_messages--;
|
||||
|
||||
r = link_route_remove_handler_internal(rtnl, m, link, "Failed to remove DHCPv4 route, ignoring");
|
||||
if (r <= 0)
|
||||
return r;
|
||||
|
||||
if (link->dhcp4_remove_messages == 0) {
|
||||
r = dhcp4_request_address_and_routes(link, false);
|
||||
if (r < 0)
|
||||
link_enter_failed(link);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int dhcp4_address_remove_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
|
||||
int r;
|
||||
|
||||
assert(link);
|
||||
assert(link->dhcp4_remove_messages > 0);
|
||||
|
||||
link->dhcp4_remove_messages--;
|
||||
|
||||
r = address_remove_handler_internal(rtnl, m, link, "Failed to remove DHCPv4 address, ignoring");
|
||||
if (r <= 0)
|
||||
return r;
|
||||
|
||||
if (link->dhcp4_remove_messages == 0) {
|
||||
r = dhcp4_request_address_and_routes(link, false);
|
||||
if (r < 0)
|
||||
link_enter_failed(link);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int dhcp4_remove_all(Link *link) {
|
||||
Route *route;
|
||||
int k, r = 0;
|
||||
@ -761,19 +723,15 @@ static int dhcp4_remove_all(Link *link) {
|
||||
assert(link);
|
||||
|
||||
SET_FOREACH(route, link->dhcp_routes) {
|
||||
k = route_remove(route, NULL, link, dhcp4_route_remove_handler);
|
||||
k = route_remove(route, NULL, link);
|
||||
if (k < 0)
|
||||
r = k;
|
||||
else
|
||||
link->dhcp4_remove_messages++;
|
||||
}
|
||||
|
||||
if (link->dhcp_address) {
|
||||
k = address_remove(link->dhcp_address, link, dhcp4_address_remove_handler);
|
||||
k = address_remove(link->dhcp_address, link);
|
||||
if (k < 0)
|
||||
r = k;
|
||||
else
|
||||
link->dhcp4_remove_messages++;
|
||||
}
|
||||
|
||||
return r;
|
||||
@ -990,7 +948,7 @@ static int dhcp4_after_address_configure(Request *req, void *object) {
|
||||
if (link->dhcp_address_old &&
|
||||
!address_equal(link->dhcp_address_old, link->dhcp_address)) {
|
||||
/* Still too old address exists? Let's remove it immediately. */
|
||||
r = address_remove(link->dhcp_address_old, link, NULL);
|
||||
r = address_remove(link->dhcp_address_old, link);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
@ -170,7 +170,7 @@ static int dhcp6_pd_remove_old(Link *link, bool force) {
|
||||
log_link_debug(link, "Removing old DHCPv6 Prefix Delegation addresses and routes.");
|
||||
|
||||
SET_FOREACH(route, link->dhcp6_pd_routes_old) {
|
||||
k = route_remove(route, NULL, link, NULL);
|
||||
k = route_remove(route, NULL, link);
|
||||
if (k < 0)
|
||||
r = k;
|
||||
|
||||
@ -180,7 +180,7 @@ static int dhcp6_pd_remove_old(Link *link, bool force) {
|
||||
}
|
||||
|
||||
SET_FOREACH(address, link->dhcp6_pd_addresses_old) {
|
||||
k = address_remove(address, link, NULL);
|
||||
k = address_remove(address, link);
|
||||
if (k < 0)
|
||||
r = k;
|
||||
}
|
||||
@ -212,7 +212,7 @@ int dhcp6_pd_remove(Link *link) {
|
||||
log_link_debug(link, "Removing DHCPv6 Prefix Delegation addresses and routes.");
|
||||
|
||||
SET_FOREACH(route, link->dhcp6_pd_routes) {
|
||||
k = route_remove(route, NULL, link, NULL);
|
||||
k = route_remove(route, NULL, link);
|
||||
if (k < 0)
|
||||
r = k;
|
||||
|
||||
@ -222,7 +222,7 @@ int dhcp6_pd_remove(Link *link) {
|
||||
}
|
||||
|
||||
SET_FOREACH(address, link->dhcp6_pd_addresses) {
|
||||
k = address_remove(address, link, NULL);
|
||||
k = address_remove(address, link);
|
||||
if (k < 0)
|
||||
r = k;
|
||||
}
|
||||
@ -761,13 +761,13 @@ static int dhcp6_remove_old(Link *link, bool force) {
|
||||
log_link_debug(link, "Removing old DHCPv6 addresses and routes.");
|
||||
|
||||
SET_FOREACH(route, link->dhcp6_routes_old) {
|
||||
k = route_remove(route, NULL, link, NULL);
|
||||
k = route_remove(route, NULL, link);
|
||||
if (k < 0)
|
||||
r = k;
|
||||
}
|
||||
|
||||
SET_FOREACH(address, link->dhcp6_addresses_old) {
|
||||
k = address_remove(address, link, NULL);
|
||||
k = address_remove(address, link);
|
||||
if (k < 0)
|
||||
r = k;
|
||||
}
|
||||
@ -795,13 +795,13 @@ static int dhcp6_remove(Link *link) {
|
||||
log_link_debug(link, "Removing DHCPv6 addresses and routes.");
|
||||
|
||||
SET_FOREACH(route, link->dhcp6_routes) {
|
||||
k = route_remove(route, NULL, link, NULL);
|
||||
k = route_remove(route, NULL, link);
|
||||
if (k < 0)
|
||||
r = k;
|
||||
}
|
||||
|
||||
SET_FOREACH(address, link->dhcp6_addresses) {
|
||||
k = address_remove(address, link, NULL);
|
||||
k = address_remove(address, link);
|
||||
if (k < 0)
|
||||
r = k;
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ static int ipv4ll_address_lost(Link *link) {
|
||||
log_link_debug(link, "IPv4 link-local release "IPV4_ADDRESS_FMT_STR,
|
||||
IPV4_ADDRESS_FMT_VAL(address->in_addr.in));
|
||||
|
||||
return address_remove(address, link, NULL);
|
||||
return address_remove(address, link);
|
||||
}
|
||||
|
||||
static int ipv4ll_address_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
|
||||
|
@ -138,7 +138,7 @@ bool link_ipv6_enabled(Link *link) {
|
||||
bool link_is_ready_to_configure(Link *link, bool allow_unmanaged) {
|
||||
assert(link);
|
||||
|
||||
if (!link->network || link->network->unmanaged) {
|
||||
if (!link->network) {
|
||||
if (!allow_unmanaged)
|
||||
return false;
|
||||
|
||||
|
@ -112,7 +112,6 @@ typedef struct Link {
|
||||
char *lease_file;
|
||||
uint32_t original_mtu;
|
||||
unsigned dhcp4_messages;
|
||||
unsigned dhcp4_remove_messages;
|
||||
sd_ipv4acd *dhcp_acd;
|
||||
bool dhcp4_route_failed:1;
|
||||
bool dhcp4_route_retrying:1;
|
||||
|
@ -171,14 +171,14 @@ static int ndisc_remove_old_one(Link *link, const struct in6_addr *router, bool
|
||||
|
||||
SET_FOREACH(na, link->ndisc_addresses)
|
||||
if (na->marked && in6_addr_equal(&na->router, router)) {
|
||||
k = address_remove(na->address, link, NULL);
|
||||
k = address_remove(na->address, link);
|
||||
if (k < 0)
|
||||
r = k;
|
||||
}
|
||||
|
||||
SET_FOREACH(nr, link->ndisc_routes)
|
||||
if (nr->marked && in6_addr_equal(&nr->router, router)) {
|
||||
k = route_remove(nr->route, NULL, link, NULL);
|
||||
k = route_remove(nr->route, NULL, link);
|
||||
if (k < 0)
|
||||
r = k;
|
||||
}
|
||||
|
@ -903,13 +903,12 @@ static int route_set_netlink_message(const Route *route, sd_netlink_message *req
|
||||
return 0;
|
||||
}
|
||||
|
||||
int link_route_remove_handler_internal(sd_netlink *rtnl, sd_netlink_message *m, Link *link, const char *error_msg) {
|
||||
static int link_route_remove_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
|
||||
int r;
|
||||
|
||||
assert(m);
|
||||
assert(link);
|
||||
assert(link->route_remove_messages > 0);
|
||||
assert(error_msg);
|
||||
|
||||
link->route_remove_messages--;
|
||||
|
||||
@ -918,15 +917,11 @@ int link_route_remove_handler_internal(sd_netlink *rtnl, sd_netlink_message *m,
|
||||
|
||||
r = sd_netlink_message_get_errno(m);
|
||||
if (r < 0 && r != -ESRCH)
|
||||
log_link_message_warning_errno(link, m, r, error_msg);
|
||||
log_link_message_warning_errno(link, m, r, "Could not drop route, ignoring");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int link_route_remove_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
|
||||
return link_route_remove_handler_internal(rtnl, m, link, "Could not drop route, ignoring");
|
||||
}
|
||||
|
||||
static int manager_route_remove_handler(sd_netlink *rtnl, sd_netlink_message *m, Manager *manager) {
|
||||
int r;
|
||||
|
||||
@ -943,12 +938,7 @@ static int manager_route_remove_handler(sd_netlink *rtnl, sd_netlink_message *m,
|
||||
return 1;
|
||||
}
|
||||
|
||||
int route_remove(
|
||||
const Route *route,
|
||||
Manager *manager,
|
||||
Link *link,
|
||||
link_netlink_message_handler_t callback) {
|
||||
|
||||
int route_remove(const Route *route, Manager *manager, Link *link) {
|
||||
_cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL;
|
||||
unsigned char type;
|
||||
int r;
|
||||
@ -988,7 +978,7 @@ int route_remove(
|
||||
|
||||
if (link) {
|
||||
r = netlink_call_async(manager->rtnl, NULL, req,
|
||||
callback ?: link_route_remove_handler,
|
||||
link_route_remove_handler,
|
||||
link_netlink_destroy_callback, link);
|
||||
if (r < 0)
|
||||
return log_link_error_errno(link, r, "Could not send rtnetlink message: %m");
|
||||
@ -1062,7 +1052,7 @@ static int manager_drop_routes_internal(Manager *manager, bool foreign, const Li
|
||||
|
||||
/* The existing links do not have the route. Let's drop this now. It may be
|
||||
* re-configured later. */
|
||||
k = route_remove(route, manager, NULL, NULL);
|
||||
k = route_remove(route, manager, NULL);
|
||||
if (k < 0 && r >= 0)
|
||||
r = k;
|
||||
|
||||
@ -1112,7 +1102,7 @@ int link_drop_foreign_routes(Link *link) {
|
||||
if (link_has_static_route(link, route))
|
||||
k = route_add(NULL, link, route, NULL, NULL, NULL);
|
||||
else
|
||||
k = route_remove(route, NULL, link, NULL);
|
||||
k = route_remove(route, NULL, link);
|
||||
if (k < 0 && r >= 0)
|
||||
r = k;
|
||||
}
|
||||
@ -1135,7 +1125,7 @@ int link_drop_routes(Link *link) {
|
||||
if (route->protocol == RTPROT_KERNEL)
|
||||
continue;
|
||||
|
||||
k = route_remove(route, NULL, link, NULL);
|
||||
k = route_remove(route, NULL, link);
|
||||
if (k < 0 && r >= 0)
|
||||
r = k;
|
||||
}
|
||||
@ -1153,7 +1143,7 @@ static int route_expire_handler(sd_event_source *s, uint64_t usec, void *userdat
|
||||
|
||||
assert(route);
|
||||
|
||||
r = route_remove(route, route->manager, route->link, NULL);
|
||||
r = route_remove(route, route->manager, route->link);
|
||||
if (r < 0) {
|
||||
log_link_warning_errno(route->link, r, "Could not remove route: %m");
|
||||
route_free(route);
|
||||
|
@ -74,8 +74,7 @@ DEFINE_NETWORK_SECTION_FUNCTIONS(Route, route_free);
|
||||
int route_dup(const Route *src, Route **ret);
|
||||
|
||||
int route_configure_handler_internal(sd_netlink *rtnl, sd_netlink_message *m, Link *link, const char *error_msg);
|
||||
int link_route_remove_handler_internal(sd_netlink *rtnl, sd_netlink_message *m, Link *link, const char *error_msg);
|
||||
int route_remove(const Route *route, Manager *manager, Link *link, link_netlink_message_handler_t callback);
|
||||
int route_remove(const Route *route, Manager *manager, Link *link);
|
||||
|
||||
int link_has_route(Link *link, const Route *route);
|
||||
bool manager_address_is_reachable(Manager *manager, int family, const union in_addr_union *address);
|
||||
|
Loading…
Reference in New Issue
Block a user