Merge pull request #12774 from yuwata/network-ignore-ipv6-settings-when-sysctl-disable-ipv6

network: ignore ipv6 settings when sysctl disable ipv6
This commit is contained in:
Yu Watanabe
2019-06-12 14:46:00 +09:00
committed by GitHub
8 changed files with 63 additions and 20 deletions
+6 -1
View File
@@ -566,6 +566,11 @@ int address_configure(
assert(link->manager->rtnl);
assert(callback);
if (address->family == AF_INET6 && manager_sysctl_ipv6_enabled(link->manager) == 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)
@@ -665,7 +670,7 @@ int address_configure(
return log_link_error_errno(link, r, "Could not add address: %m");
}
return 0;
return 1;
}
int config_parse_broadcast(
+6 -1
View File
@@ -124,6 +124,11 @@ 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) {
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)
@@ -169,7 +174,7 @@ int fdb_entry_configure(Link *link, FdbEntry *fdb_entry) {
link_ref(link);
return 0;
return 1;
}
/* remove and FDB entry. */
+6 -6
View File
@@ -838,8 +838,8 @@ static int link_request_set_routing_policy_rule(Link *link) {
link_enter_failed(link);
return r;
}
link->routing_policy_rule_messages++;
if (r > 0)
link->routing_policy_rule_messages++;
}
routing_policy_rule_purge(link->manager, link);
@@ -913,8 +913,8 @@ int link_request_set_routes(Link *link) {
link_enter_failed(link);
return r;
}
link->route_messages++;
if (r > 0)
link->route_messages++;
}
if (link->route_messages == 0) {
@@ -1194,8 +1194,8 @@ static int link_request_set_addresses(Link *link) {
link_enter_failed(link);
return r;
}
link->address_messages++;
if (r > 0)
link->address_messages++;
}
LIST_FOREACH(labels, label, link->network->address_labels) {
+8 -8
View File
@@ -121,8 +121,8 @@ static int ndisc_router_process_default(Link *link, sd_ndisc_router *rt) {
link_enter_failed(link);
return r;
}
link->ndisc_messages++;
if (r > 0)
link->ndisc_messages++;
return 0;
}
@@ -209,8 +209,8 @@ static int ndisc_router_process_autonomous_prefix(Link *link, sd_ndisc_router *r
link_enter_failed(link);
return r;
}
link->ndisc_messages++;
if (r > 0)
link->ndisc_messages++;
return 0;
}
@@ -259,8 +259,8 @@ static int ndisc_router_process_onlink_prefix(Link *link, sd_ndisc_router *rt) {
link_enter_failed(link);
return r;
}
link->ndisc_messages++;
if (r > 0)
link->ndisc_messages++;
return 0;
}
@@ -320,8 +320,8 @@ static int ndisc_router_process_route(Link *link, sd_ndisc_router *rt) {
link_enter_failed(link);
return r;
}
link->ndisc_messages++;
if (r > 0)
link->ndisc_messages++;
return 0;
}
+6 -1
View File
@@ -500,6 +500,11 @@ 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) {
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->tos, route->priority, route->table, NULL) <= 0 &&
set_size(link->routes) >= routes_max())
return log_link_error_errno(link, SYNTHETIC_ERRNO(E2BIG),
@@ -688,7 +693,7 @@ int route_configure(
sd_event_source_unref(route->expire);
route->expire = TAKE_PTR(expire);
return 0;
return 1;
}
int network_add_ipv4ll_route(Network *network) {
+6 -1
View File
@@ -484,6 +484,11 @@ 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) {
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");
@@ -593,7 +598,7 @@ int routing_policy_rule_configure(RoutingPolicyRule *rule, Link *link, link_netl
if (r < 0)
return log_error_errno(r, "Could not add rule: %m");
return 0;
return 1;
}
static int parse_fwmark_fwmask(const char *s, uint32_t *fwmark, uint32_t *fwmask) {
@@ -4,3 +4,15 @@ Name=dummy98
[Network]
IPv6AcceptRA=no
Address=10.2.3.4/16
# This should be ignored when ipv6 is disabled
Gateway=2607:5300:0203:39ff:ff:ff:ff:ff
[Address]
# This should be ignored when ipv6 is disabled
Address=2607:5300:0203:3906::/64
[Route]
# This should be ignored when ipv6 is disabled
Destination=2607:5300:0203:39ff:ff:ff:ff:ff
Scope=link
+13 -2
View File
@@ -1579,7 +1579,12 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities):
output = check_output('ip -6 address show dummy98')
print(output)
self.assertEqual(output, '')
self.check_operstate('dummy98', 'routable')
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, '')
check_output('ip link del dummy98')
@@ -1595,8 +1600,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.assertRegex(output, 'inet6 2607:5300:203:3906::/64 scope global')
self.assertRegex(output, 'inet6 .* scope link')
self.check_operstate('dummy98', 'routable')
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.assertRegex(output, 'default via 2607:5300:203:39ff:ff:ff:ff:ff proto static')
def test_bind_carrier(self):
copy_unit_to_networkd_unit_path('25-bind-carrier.network', '11-dummy.netdev')