mirror of
https://github.com/systemd/systemd.git
synced 2025-03-21 02:50:18 +03:00
network: read link specific sysctl value
This introduce link_sysctl_ipv6_enabled() and replaces manager_sysctl_ipv6_enabled() with it.
This commit is contained in:
parent
6ea420a3b6
commit
bafa964144
@ -566,7 +566,7 @@ int address_configure(
|
||||
assert(link->manager->rtnl);
|
||||
assert(callback);
|
||||
|
||||
if (address->family == AF_INET6 && manager_sysctl_ipv6_enabled(link->manager) == 0) {
|
||||
if (address->family == AF_INET6 && link_sysctl_ipv6_enabled(link) == 0) {
|
||||
log_link_warning(link, "An IPv6 address is requested, but IPv6 is disabled by sysctl, ignoring.");
|
||||
return 0;
|
||||
}
|
||||
|
@ -124,7 +124,7 @@ int fdb_entry_configure(Link *link, FdbEntry *fdb_entry) {
|
||||
assert(link->manager);
|
||||
assert(fdb_entry);
|
||||
|
||||
if (fdb_entry->family == AF_INET6 && manager_sysctl_ipv6_enabled(link->manager) == 0) {
|
||||
if (fdb_entry->family == AF_INET6 && link_sysctl_ipv6_enabled(link) == 0) {
|
||||
log_link_warning(link, "An IPv6 fdb entry is requested, but IPv6 is disabled by sysctl, ignoring.");
|
||||
return 0;
|
||||
}
|
||||
|
@ -62,6 +62,20 @@ DUID* link_get_duid(Link *link) {
|
||||
return &link->manager->duid;
|
||||
}
|
||||
|
||||
int link_sysctl_ipv6_enabled(Link *link) {
|
||||
_cleanup_free_ char *value = NULL;
|
||||
int r;
|
||||
|
||||
r = sysctl_read_ip_property(AF_INET6, link->ifname, "disable_ipv6", &value);
|
||||
if (r < 0)
|
||||
return log_link_warning_errno(link, r,
|
||||
"Failed to read net.ipv6.conf.%s.disable_ipv6 sysctl property: %m",
|
||||
link->ifname);
|
||||
|
||||
link->sysctl_ipv6_enabled = value[0] == '0';
|
||||
return link->sysctl_ipv6_enabled;
|
||||
}
|
||||
|
||||
static bool link_dhcp6_enabled(Link *link) {
|
||||
assert(link);
|
||||
|
||||
@ -80,7 +94,7 @@ static bool link_dhcp6_enabled(Link *link) {
|
||||
if (STRPTR_IN_SET(link->kind, "can", "vcan", "vxcan"))
|
||||
return false;
|
||||
|
||||
if (manager_sysctl_ipv6_enabled(link->manager) == 0)
|
||||
if (link_sysctl_ipv6_enabled(link) == 0)
|
||||
return false;
|
||||
|
||||
return link->network->dhcp & ADDRESS_FAMILY_IPV6;
|
||||
@ -166,7 +180,7 @@ static bool link_ipv6ll_enabled(Link *link) {
|
||||
if (link->network->bond)
|
||||
return false;
|
||||
|
||||
if (manager_sysctl_ipv6_enabled(link->manager) == 0)
|
||||
if (link_sysctl_ipv6_enabled(link) == 0)
|
||||
return false;
|
||||
|
||||
return link->network->link_local & ADDRESS_FAMILY_IPV6;
|
||||
@ -181,7 +195,7 @@ static bool link_ipv6_enabled(Link *link) {
|
||||
if (link->network->bond)
|
||||
return false;
|
||||
|
||||
if (manager_sysctl_ipv6_enabled(link->manager) == 0)
|
||||
if (link_sysctl_ipv6_enabled(link) == 0)
|
||||
return false;
|
||||
|
||||
if (STRPTR_IN_SET(link->kind, "can", "vcan", "vxcan"))
|
||||
@ -230,7 +244,7 @@ static bool link_ipv6_forward_enabled(Link *link) {
|
||||
if (link->network->ip_forward == _ADDRESS_FAMILY_BOOLEAN_INVALID)
|
||||
return false;
|
||||
|
||||
if (manager_sysctl_ipv6_enabled(link->manager) == 0)
|
||||
if (link_sysctl_ipv6_enabled(link) == 0)
|
||||
return false;
|
||||
|
||||
return link->network->ip_forward & ADDRESS_FAMILY_IPV6;
|
||||
@ -541,6 +555,7 @@ static int link_new(Manager *manager, sd_netlink_message *message, Link **ret) {
|
||||
.rtnl_extended_attrs = true,
|
||||
.ifindex = ifindex,
|
||||
.iftype = iftype,
|
||||
.sysctl_ipv6_enabled = -1,
|
||||
};
|
||||
|
||||
link->ifname = strdup(ifname);
|
||||
|
@ -126,6 +126,8 @@ typedef struct Link {
|
||||
/* For speed meter */
|
||||
struct rtnl_link_stats64 stats_old, stats_new;
|
||||
bool stats_updated;
|
||||
|
||||
int sysctl_ipv6_enabled;
|
||||
} Link;
|
||||
|
||||
typedef int (*link_netlink_message_handler_t)(sd_netlink*, sd_netlink_message*, Link*);
|
||||
@ -192,6 +194,8 @@ uint32_t link_get_dhcp_route_table(Link *link);
|
||||
uint32_t link_get_ipv6_accept_ra_route_table(Link *link);
|
||||
int link_request_set_routes(Link *link);
|
||||
|
||||
int link_sysctl_ipv6_enabled(Link *link);
|
||||
|
||||
#define ADDRESS_FMT_VAL(address) \
|
||||
be32toh((address).s_addr) >> 24, \
|
||||
(be32toh((address).s_addr) >> 16) & 0xFFu, \
|
||||
|
@ -1382,8 +1382,6 @@ int manager_new(Manager **ret) {
|
||||
if (!m->state_file)
|
||||
return -ENOMEM;
|
||||
|
||||
m->sysctl_ipv6_enabled = -1;
|
||||
|
||||
r = sd_event_default(&m->event);
|
||||
if (r < 0)
|
||||
return r;
|
||||
@ -1886,18 +1884,3 @@ int manager_request_product_uuid(Manager *m, Link *link) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int manager_sysctl_ipv6_enabled(Manager *manager) {
|
||||
_cleanup_free_ char *value = NULL;
|
||||
int r;
|
||||
|
||||
if (manager->sysctl_ipv6_enabled >= 0)
|
||||
return manager->sysctl_ipv6_enabled;
|
||||
|
||||
r = sysctl_read_ip_property(AF_INET6, "all", "disable_ipv6", &value);
|
||||
if (r < 0)
|
||||
return log_warning_errno(r, "Failed to read net.ipv6.conf.all.disable_ipv6 sysctl property: %m");
|
||||
|
||||
manager->sysctl_ipv6_enabled = value[0] == '0';
|
||||
return manager->sysctl_ipv6_enabled;
|
||||
}
|
||||
|
@ -55,8 +55,6 @@ struct Manager {
|
||||
Set *rules_foreign;
|
||||
Set *rules_saved;
|
||||
|
||||
int sysctl_ipv6_enabled;
|
||||
|
||||
/* For link speed meter*/
|
||||
bool use_speed_meter;
|
||||
sd_event_source *speed_meter_event_source;
|
||||
@ -100,6 +98,4 @@ Link *manager_dhcp6_prefix_get(Manager *m, struct in6_addr *addr);
|
||||
int manager_dhcp6_prefix_add(Manager *m, struct in6_addr *addr, Link *link);
|
||||
int manager_dhcp6_prefix_remove_all(Manager *m, Link *link);
|
||||
|
||||
int manager_sysctl_ipv6_enabled(Manager *manager);
|
||||
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_free);
|
||||
|
@ -500,7 +500,7 @@ int route_configure(
|
||||
assert(IN_SET(route->family, AF_INET, AF_INET6));
|
||||
assert(callback);
|
||||
|
||||
if (route->family == AF_INET6 && manager_sysctl_ipv6_enabled(link->manager) == 0) {
|
||||
if (route->family == AF_INET6 && link_sysctl_ipv6_enabled(link) == 0) {
|
||||
log_link_warning(link, "An IPv6 route is requested, but IPv6 is disabled by sysctl, ignoring.");
|
||||
return 0;
|
||||
}
|
||||
|
@ -484,7 +484,7 @@ int routing_policy_rule_configure(RoutingPolicyRule *rule, Link *link, link_netl
|
||||
assert(link->manager);
|
||||
assert(link->manager->rtnl);
|
||||
|
||||
if (rule->family == AF_INET6 && manager_sysctl_ipv6_enabled(link->manager) == 0) {
|
||||
if (rule->family == AF_INET6 && link_sysctl_ipv6_enabled(link) == 0) {
|
||||
log_link_warning(link, "An IPv6 routing policy rule is requested, but IPv6 is disabled by sysctl, ignoring.");
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user