Merge pull request #13382 from keszybz/network-ipv6-enable

Network ipv6 enable
This commit is contained in:
Yu Watanabe 2019-08-28 00:29:29 +09:00 committed by GitHub
commit 6c431a16c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 16 additions and 71 deletions

View File

@ -568,11 +568,6 @@ int address_configure(
assert(link->manager->rtnl);
assert(callback);
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;
}
/* If this is a new address, then refuse adding more than the limit */
if (address_get(link, address->family, &address->in_addr, address->prefixlen, NULL) <= 0 &&
set_size(link->addresses) >= ADDRESSES_PER_LINK_MAX)

View File

@ -123,11 +123,6 @@ int fdb_entry_configure(Link *link, FdbEntry *fdb_entry) {
assert(link->manager);
assert(fdb_entry);
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;
}
/* create new RTM message */
r = sd_rtnl_message_new_neigh(link->manager->rtnl, &req, RTM_NEWNEIGH, link->ifindex, PF_BRIDGE);
if (r < 0)

View File

@ -69,27 +69,6 @@ DUID* link_get_duid(Link *link) {
return &link->manager->duid;
}
int link_sysctl_ipv6_enabled(Link *link) {
_cleanup_free_ char *value = NULL;
int r;
assert(link);
assert(link->ifname);
if (link->sysctl_ipv6_enabled >= 0)
return link->sysctl_ipv6_enabled;
const char *ifname = link->ifname; /* work around bogus gcc warning */
r = sysctl_read_ip_property(AF_INET6, 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",
ifname);
link->sysctl_ipv6_enabled = value[0] == '0';
return link->sysctl_ipv6_enabled;
}
static bool link_dhcp6_enabled(Link *link) {
assert(link);
@ -108,9 +87,6 @@ static bool link_dhcp6_enabled(Link *link) {
if (link->iftype == ARPHRD_CAN)
return false;
if (link_sysctl_ipv6_enabled(link) == 0)
return false;
return link->network->dhcp & ADDRESS_FAMILY_IPV6;
}
@ -199,9 +175,6 @@ static bool link_ipv6ll_enabled(Link *link) {
if (link->network->bond)
return false;
if (link_sysctl_ipv6_enabled(link) == 0)
return false;
return link->network->link_local & ADDRESS_FAMILY_IPV6;
}
@ -214,9 +187,6 @@ static bool link_ipv6_enabled(Link *link) {
if (link->network->bond)
return false;
if (link_sysctl_ipv6_enabled(link) == 0)
return false;
if (link->iftype == ARPHRD_CAN)
return false;
@ -263,9 +233,6 @@ static bool link_ipv6_forward_enabled(Link *link) {
if (link->network->ip_forward == _ADDRESS_FAMILY_INVALID)
return false;
if (link_sysctl_ipv6_enabled(link) == 0)
return false;
return link->network->ip_forward & ADDRESS_FAMILY_IPV6;
}
@ -329,20 +296,21 @@ static IPv6PrivacyExtensions link_ipv6_privacy_extensions(Link *link) {
return link->network->ipv6_privacy_extensions;
}
static int link_enable_ipv6(Link *link) {
bool disabled;
static int link_update_ipv6_sysctl(Link *link) {
bool enabled;
int r;
if (link->flags & IFF_LOOPBACK)
return 0;
disabled = !link_ipv6_enabled(link);
enabled = link_ipv6_enabled(link);
if (enabled) {
r = sysctl_write_ip_property_boolean(AF_INET6, link->ifname, "disable_ipv6", false);
if (r < 0)
return log_link_warning_errno(link, r, "Cannot enable IPv6: %m");
r = sysctl_write_ip_property_boolean(AF_INET6, link->ifname, "disable_ipv6", disabled);
if (r < 0)
log_link_warning_errno(link, r, "Cannot %s IPv6: %m", enable_disable(!disabled));
else
log_link_info(link, "IPv6 successfully %sd", enable_disable(!disabled));
log_link_info(link, "IPv6 successfully enabled");
}
return 0;
}
@ -614,7 +582,6 @@ static int link_new(Manager *manager, sd_netlink_message *message, Link **ret) {
.state = LINK_STATE_PENDING,
.ifindex = ifindex,
.iftype = iftype,
.sysctl_ipv6_enabled = -1,
.n_dns = (unsigned) -1,
.dns_default_route = -1,
@ -1281,10 +1248,6 @@ int link_set_mtu(Link *link, uint32_t mtu) {
if (r < 0)
return log_link_error_errno(link, r, "Could not allocate RTM_SETLINK message: %m");
/* If IPv6 not configured (no static IPv6 address and IPv6LL autoconfiguration is disabled)
* for this interface, then disable IPv6 else enable it. */
(void) link_enable_ipv6(link);
/* IPv6 protocol requires a minimum MTU of IPV6_MTU_MIN(1280) bytes
* on the interface. Bump up MTU bytes to IPV6_MTU_MIN. */
if (link_ipv6_enabled(link) && mtu < IPV6_MIN_MTU) {
@ -2554,6 +2517,10 @@ static int link_configure(Link *link) {
return r;
}
/* If IPv6 configured that is static IPv6 address and IPv6LL autoconfiguration is enabled
* for this interface, then enable IPv6 */
(void) link_update_ipv6_sysctl(link);
r = link_set_proxy_arp(link);
if (r < 0)
return r;

View File

@ -133,7 +133,6 @@ typedef struct Link {
struct rtnl_link_stats64 stats_old, stats_new;
bool stats_updated;
int sysctl_ipv6_enabled;
/* All kinds of DNS configuration */
struct in_addr_data *dns;
@ -200,8 +199,6 @@ 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, \

View File

@ -636,11 +636,6 @@ int route_configure(
assert(IN_SET(route->family, AF_INET, AF_INET6));
assert(callback);
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;
}
if (route_get(link, route->family, &route->dst, route->dst_prefixlen, &route->gw, route->tos, route->priority, route->table, NULL) <= 0 &&
set_size(link->routes) >= routes_max())
return log_link_error_errno(link, SYNTHETIC_ERRNO(E2BIG),

View File

@ -453,11 +453,6 @@ int routing_policy_rule_configure(RoutingPolicyRule *rule, Link *link, link_netl
assert(link->manager);
assert(link->manager->rtnl);
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;
}
r = sd_rtnl_message_new_routing_policy_rule(link->manager->rtnl, &m, RTM_NEWRULE, rule->family);
if (r < 0)
return log_error_errno(r, "Could not allocate RTM_NEWRULE message: %m");

View File

@ -1842,13 +1842,14 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities):
self.assertRegex(output, 'inet 10.2.3.4/16 brd 10.2.255.255 scope global dummy98')
output = check_output('ip -6 address show dummy98')
print(output)
self.assertEqual(output, '')
self.assertRegex(output, 'inet6 2607:5300:203:3906::/64 scope global')
self.assertRegex(output, 'inet6 .* scope link')
output = check_output('ip -4 route show dev dummy98')
print(output)
self.assertEqual(output, '10.2.0.0/16 proto kernel scope link src 10.2.3.4')
output = check_output('ip -6 route show dev dummy98')
print(output)
self.assertEqual(output, '')
self.assertRegex(output, 'default via 2607:5300:203:39ff:ff:ff:ff:ff proto static')
check_output('ip link del dummy98')