mirror of
https://github.com/systemd/systemd.git
synced 2025-01-26 14:04:03 +03:00
network: split out link_get_address_states()
No functional change, just refactoring and preparation for later commits.
This commit is contained in:
parent
76859a9785
commit
60415c1360
@ -90,6 +90,49 @@ int address_flags_to_string_alloc(uint32_t flags, int family, char **ret) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static LinkAddressState address_state_from_scope(uint8_t scope) {
|
||||
if (scope < RT_SCOPE_SITE)
|
||||
/* universally accessible addresses found */
|
||||
return LINK_ADDRESS_STATE_ROUTABLE;
|
||||
|
||||
if (scope < RT_SCOPE_HOST)
|
||||
/* only link or site local addresses found */
|
||||
return LINK_ADDRESS_STATE_DEGRADED;
|
||||
|
||||
/* no useful addresses found */
|
||||
return LINK_ADDRESS_STATE_OFF;
|
||||
}
|
||||
|
||||
void link_get_address_states(
|
||||
Link *link,
|
||||
LinkAddressState *ret_ipv4,
|
||||
LinkAddressState *ret_ipv6,
|
||||
LinkAddressState *ret_all) {
|
||||
|
||||
uint8_t ipv4_scope = RT_SCOPE_NOWHERE, ipv6_scope = RT_SCOPE_NOWHERE;
|
||||
Address *address;
|
||||
|
||||
assert(link);
|
||||
|
||||
SET_FOREACH(address, link->addresses) {
|
||||
if (!address_is_ready(address))
|
||||
continue;
|
||||
|
||||
if (address->family == AF_INET)
|
||||
ipv4_scope = MIN(ipv4_scope, address->scope);
|
||||
|
||||
if (address->family == AF_INET6)
|
||||
ipv6_scope = MIN(ipv6_scope, address->scope);
|
||||
}
|
||||
|
||||
if (ret_ipv4)
|
||||
*ret_ipv4 = address_state_from_scope(ipv4_scope);
|
||||
if (ret_ipv6)
|
||||
*ret_ipv6 = address_state_from_scope(ipv6_scope);
|
||||
if (ret_all)
|
||||
*ret_all = address_state_from_scope(MIN(ipv4_scope, ipv6_scope));
|
||||
}
|
||||
|
||||
int address_new(Address **ret) {
|
||||
_cleanup_(address_freep) Address *address = NULL;
|
||||
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "firewall-util.h"
|
||||
#include "hash-funcs.h"
|
||||
#include "in-addr-util.h"
|
||||
#include "network-util.h"
|
||||
#include "networkd-link.h"
|
||||
#include "networkd-util.h"
|
||||
#include "time-util.h"
|
||||
@ -74,6 +75,12 @@ const char* format_lifetime(char *buf, size_t l, usec_t lifetime_usec) _warn_unu
|
||||
|
||||
int address_flags_to_string_alloc(uint32_t flags, int family, char **ret);
|
||||
|
||||
void link_get_address_states(
|
||||
Link *link,
|
||||
LinkAddressState *ret_ipv4,
|
||||
LinkAddressState *ret_ipv6,
|
||||
LinkAddressState *ret_all);
|
||||
|
||||
extern const struct hash_ops address_hash_ops;
|
||||
|
||||
int address_new(Address **ret);
|
||||
|
@ -1687,28 +1687,13 @@ static bool link_is_enslaved(Link *link) {
|
||||
return false;
|
||||
}
|
||||
|
||||
static LinkAddressState address_state_from_scope(uint8_t scope) {
|
||||
if (scope < RT_SCOPE_SITE)
|
||||
/* universally accessible addresses found */
|
||||
return LINK_ADDRESS_STATE_ROUTABLE;
|
||||
|
||||
if (scope < RT_SCOPE_HOST)
|
||||
/* only link or site local addresses found */
|
||||
return LINK_ADDRESS_STATE_DEGRADED;
|
||||
|
||||
/* no useful addresses found */
|
||||
return LINK_ADDRESS_STATE_OFF;
|
||||
}
|
||||
|
||||
void link_update_operstate(Link *link, bool also_update_master) {
|
||||
LinkOperationalState operstate;
|
||||
LinkCarrierState carrier_state;
|
||||
LinkAddressState ipv4_address_state, ipv6_address_state, address_state;
|
||||
LinkOnlineState online_state;
|
||||
_cleanup_strv_free_ char **p = NULL;
|
||||
uint8_t ipv4_scope = RT_SCOPE_NOWHERE, ipv6_scope = RT_SCOPE_NOWHERE;
|
||||
bool changed = false;
|
||||
Address *address;
|
||||
|
||||
assert(link);
|
||||
|
||||
@ -1735,20 +1720,7 @@ void link_update_operstate(Link *link, bool also_update_master) {
|
||||
}
|
||||
}
|
||||
|
||||
SET_FOREACH(address, link->addresses) {
|
||||
if (!address_is_ready(address))
|
||||
continue;
|
||||
|
||||
if (address->family == AF_INET)
|
||||
ipv4_scope = MIN(ipv4_scope, address->scope);
|
||||
|
||||
if (address->family == AF_INET6)
|
||||
ipv6_scope = MIN(ipv6_scope, address->scope);
|
||||
}
|
||||
|
||||
ipv4_address_state = address_state_from_scope(ipv4_scope);
|
||||
ipv6_address_state = address_state_from_scope(ipv6_scope);
|
||||
address_state = address_state_from_scope(MIN(ipv4_scope, ipv6_scope));
|
||||
link_get_address_states(link, &ipv4_address_state, &ipv6_address_state, &address_state);
|
||||
|
||||
/* Mapping of address and carrier state vs operational state
|
||||
* carrier state
|
||||
|
Loading…
x
Reference in New Issue
Block a user