Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

networkd: Implement ipv6-address-generation: stable-privacy #480

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions doc/netplan-yaml.md
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,8 @@ Match devices by MAC when setting options like: `wakeonlan` or `*-offload`.
- **`ipv6-address-generation`** (scalar) – since 0.99

> Configure method for creating the address for use with RFC4862 IPv6
> Stateless Address Auto-configuration (only supported with `NetworkManager`
> back end). Possible values are `eui64` or `stable-privacy`.
> Stateless Address Auto-configuration.
> Possible values are `eui64` or `stable-privacy`.

- **`ipv6-address-token`** (scalar) – since 0.100

Expand Down
19 changes: 13 additions & 6 deletions src/networkd.c
Original file line number Diff line number Diff line change
Expand Up @@ -903,12 +903,19 @@ _netplan_netdef_write_network_file(
g_string_append_printf(network, "Address=%s\n", g_array_index(def->ip6_addresses, char*, i));
if (def->ip6_addr_gen_token) {
g_string_append_printf(network, "IPv6Token=static:%s\n", def->ip6_addr_gen_token);
} else if (def->ip6_addr_gen_mode > NETPLAN_ADDRGEN_EUI64) {
/* EUI-64 mode is enabled by default, if no IPv6Token= is specified */
/* TODO: Enable stable-privacy mode for networkd, once PR#16618 has been released:
* https://github.com/systemd/systemd/pull/16618 */
g_set_error(error, NETPLAN_BACKEND_ERROR, NETPLAN_ERROR_UNSUPPORTED, "ERROR: %s: ipv6-address-generation mode is not supported by networkd\n", def->id);
return FALSE;
} else {
switch (def->ip6_addr_gen_mode) {
case NETPLAN_ADDRGEN_DEFAULT:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: We should potentially keep the original comment about "EUI-64" here.

Suggested change
case NETPLAN_ADDRGEN_DEFAULT:
/* EUI-64 mode is enabled by default, if no IPv6Token= is specified */
case NETPLAN_ADDRGEN_DEFAULT:

case NETPLAN_ADDRGEN_EUI64:
break;
case NETPLAN_ADDRGEN_STABLEPRIVACY:
g_string_append(network, "IPv6Token=prefixstable\n");
break;
// LCOV_EXCL_START
default:
g_assert_not_reached();
// LCOV_EXCL_STOP
}
}
if (def->accept_ra == NETPLAN_RA_MODE_ENABLED)
g_string_append_printf(network, "IPv6AcceptRA=yes\n");
Expand Down
15 changes: 14 additions & 1 deletion tests/generator/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -765,10 +765,23 @@ def test_ip6_addr_gen_mode(self):
version: 2
renderer: networkd
ethernets:
engreen:
dhcp6: yes
ipv6-address-generation: stable-privacy
enblue:
dhcp6: yes
ipv6-address-generation: eui64''')
self.assert_networkd({'enblue.network': '''[Match]\nName=enblue\n
self.assert_networkd({'engreen.network': '''[Match]\nName=engreen\n
[Network]
DHCP=ipv6
LinkLocalAddressing=ipv6
IPv6Token=prefixstable

[DHCP]
RouteMetric=100
UseMTU=true
''',
'enblue.network': '''[Match]\nName=enblue\n
[Network]
DHCP=ipv6
LinkLocalAddressing=ipv6
Expand Down
8 changes: 0 additions & 8 deletions tests/generator/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,14 +350,6 @@ def test_invalid_addr_gen_mode(self):
ipv6-address-generation: 0''', expect_fail=True)
self.assertIn("unknown ipv6-address-generation '0'", err)

def test_addr_gen_mode_not_supported(self):
err = self.generate('''network:
version: 2
ethernets:
engreen:
ipv6-address-generation: stable-privacy''', expect_fail=True)
self.assertIn("ERROR: engreen: ipv6-address-generation mode is not supported by networkd", err)

def test_addr_gen_mode_and_addr_gen_token(self):
err = self.generate('''network:
version: 2
Expand Down
11 changes: 0 additions & 11 deletions tests/generator/test_ovs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1055,17 +1055,6 @@ def test_bridge_non_ovs_bond(self):
'ovs-br.network': ND_EMPTY % ('ovs-br', 'ipv6'),
'non-ovs-bond.netdev': '[NetDev]\nName=non-ovs-bond\nKind=bond\n'})

def test_ovs_invalid_networkd_config(self):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo: We need to keep this test-case, in order to not decrease src/openvswitch.c code-coverage, checking that the OVS "cleanup" unit is created in failure case, too.

Of course, we cannot use the current failure case any more, as that got fixed :)

I'd suggest using something like this, which will trigger a similar failure-case:

    def test_ovs_invalid_networkd_config(self):
        err = self.generate('''network:
  version: 2
  bridges:
    br0:
      openvswitch: {}
      dhcp4: true
      dhcp4-overrides:
        use-domains: true
      dhcp6: true
      dhcp6-overrides:
        use-domains: false
''', expect_fail=True)
        self.assert_ovs({'cleanup.service': OVS_CLEANUP % {'iface': 'cleanup'}})
        self.assertIn('br0: networkd requires that use-domains has the same value', err)

err = self.generate('''network:
version: 2
bridges:
br0:
openvswitch: {}
ipv6-address-generation: stable-privacy
''', expect_fail=True)
self.assert_ovs({'cleanup.service': OVS_CLEANUP % {'iface': 'cleanup'}})
self.assertIn('br0: ipv6-address-generation mode is not supported by networkd', err)

def test_ovs_duplicates_when_parser_needs_second_pass(self):
''' Test case for LP: #2007682
The generator shouldn't generate duplicates when the parser
Expand Down
Loading