mirror of
https://github.com/systemd/systemd.git
synced 2025-01-12 13:18:14 +03:00
network: move link_enumerate_ipv6_tentative_addresses()
This commit is contained in:
parent
acc9fc2f51
commit
51f5dfd8ba
@ -571,12 +571,62 @@ static bool link_address_is_dynamic(Link *link, Address *address) {
|
||||
return false;
|
||||
}
|
||||
|
||||
static int link_enumerate_ipv6_tentative_addresses(Link *link) {
|
||||
_cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL, *reply = NULL;
|
||||
sd_netlink_message *addr;
|
||||
int r;
|
||||
|
||||
assert(link);
|
||||
assert(link->manager);
|
||||
assert(link->manager->rtnl);
|
||||
|
||||
r = sd_rtnl_message_new_addr(link->manager->rtnl, &req, RTM_GETADDR, 0, AF_INET6);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = sd_netlink_call(link->manager->rtnl, req, 0, &reply);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
for (addr = reply; addr; addr = sd_netlink_message_next(addr)) {
|
||||
unsigned char flags;
|
||||
int ifindex;
|
||||
|
||||
r = sd_rtnl_message_addr_get_ifindex(addr, &ifindex);
|
||||
if (r < 0) {
|
||||
log_link_warning_errno(link, r, "rtnl: invalid ifindex, ignoring: %m");
|
||||
continue;
|
||||
} else if (link->ifindex != ifindex)
|
||||
continue;
|
||||
|
||||
r = sd_rtnl_message_addr_get_flags(addr, &flags);
|
||||
if (r < 0) {
|
||||
log_link_warning_errno(link, r, "rtnl: received address message with invalid flags, ignoring: %m");
|
||||
continue;
|
||||
} else if (!(flags & IFA_F_TENTATIVE))
|
||||
continue;
|
||||
|
||||
log_link_debug(link, "Found tentative ipv6 link-local address");
|
||||
(void) manager_rtnl_process_address(link->manager->rtnl, addr, link->manager);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int link_drop_foreign_addresses(Link *link) {
|
||||
Address *address;
|
||||
int k, r = 0;
|
||||
|
||||
assert(link);
|
||||
|
||||
/* The kernel doesn't notify us about tentative addresses;
|
||||
* so if ipv6ll is disabled, we need to enumerate them now so we can drop them below */
|
||||
if (!link_ipv6ll_enabled(link)) {
|
||||
r = link_enumerate_ipv6_tentative_addresses(link);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
SET_FOREACH(address, link->addresses_foreign) {
|
||||
/* we consider IPv6LL addresses to be managed by the kernel */
|
||||
if (address->family == AF_INET6 && in_addr_is_link_local(AF_INET6, &address->in_addr) == 1 && link_ipv6ll_enabled(link))
|
||||
|
@ -1906,59 +1906,9 @@ static int link_enter_join_netdev(Link *link) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int link_enumerate_ipv6_tentative_addresses(Link *link) {
|
||||
_cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL, *reply = NULL;
|
||||
sd_netlink_message *addr;
|
||||
int r;
|
||||
|
||||
assert(link);
|
||||
assert(link->manager);
|
||||
assert(link->manager->rtnl);
|
||||
|
||||
r = sd_rtnl_message_new_addr(link->manager->rtnl, &req, RTM_GETADDR, 0, AF_INET6);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = sd_netlink_call(link->manager->rtnl, req, 0, &reply);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
for (addr = reply; addr; addr = sd_netlink_message_next(addr)) {
|
||||
unsigned char flags;
|
||||
int ifindex;
|
||||
|
||||
r = sd_rtnl_message_addr_get_ifindex(addr, &ifindex);
|
||||
if (r < 0) {
|
||||
log_link_warning_errno(link, r, "rtnl: invalid ifindex, ignoring: %m");
|
||||
continue;
|
||||
} else if (link->ifindex != ifindex)
|
||||
continue;
|
||||
|
||||
r = sd_rtnl_message_addr_get_flags(addr, &flags);
|
||||
if (r < 0) {
|
||||
log_link_warning_errno(link, r, "rtnl: received address message with invalid flags, ignoring: %m");
|
||||
continue;
|
||||
} else if (!(flags & IFA_F_TENTATIVE))
|
||||
continue;
|
||||
|
||||
log_link_debug(link, "Found tentative ipv6 link-local address");
|
||||
(void) manager_rtnl_process_address(link->manager->rtnl, addr, link->manager);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int link_drop_foreign_config(Link *link) {
|
||||
int r;
|
||||
|
||||
/* The kernel doesn't notify us about tentative addresses;
|
||||
* so if ipv6ll is disabled, we need to enumerate them now so we can drop them below */
|
||||
if (!link_ipv6ll_enabled(link)) {
|
||||
r = link_enumerate_ipv6_tentative_addresses(link);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
r = link_drop_foreign_addresses(link);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
Loading…
Reference in New Issue
Block a user