Skip to content

Commit

Permalink
net: fix ipv6_dhcpv6_stateful/stateless/slaac configuration for rhel (#…
Browse files Browse the repository at this point in the history
…4395)

When network type is ipv6_dhcpv6-stateful/stateless/slaac, cloud-init seems to
enable dhcp for both ipv4 and ipv6. Network manager prefers dhcp over ipv4 and
hence dhcp6 is not used to obtain the IP address. This is incorrect.
For only ipv6_dhcpv6-stateful/stateless/slaac networks, we should set:

ipv4.method = disabled // disables all ipv4 dhcp

For ifcfg files (sysconfig renderer), the corresponding changes should be:
BOOTPROTO = none // instead of dhcp so that dhcp4 is disabled.

Additionally, for only ipv6_dhcpv6_stateful, we should set:
ipv6.may-fail = no // dhcp6 must succeed.

which translates to the following ifcfg setting:
IPV6_FAILURE_FATAL = yes // so that dhcp6 should succeed.

This patch fixes this for rhel. The patch has been tested by Red Hat QE.

RHBZ: 2046491
fixes: f550c87 ("Adding BOOTPROTO = dhcp to render sysconfig dhcp6 stateful on RHEL (#685)")

Signed-off-by: Ani Sinha <anisinha@redhat.com>
  • Loading branch information
ani-sinha authored Sep 6, 2023
1 parent 80e4608 commit fd214a1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
9 changes: 9 additions & 0 deletions cloudinit/net/network_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ def _set_ip_method(self, family, subnet_type):
if self.config[family]["method"] == "auto" and method == "manual":
return

if (
subnet_type == "ipv6_dhcpv6-stateful"
or subnet_type == "ipv6_dhcpv6-stateless"
or subnet_type == "ipv6_slaac"
):
# set ipv4 method to 'disabled' to align with sysconfig renderer.
self._set_default("ipv4", "method", "disabled")

self.config[family]["method"] = method
self._set_default(family, "may-fail", "false")

Expand Down Expand Up @@ -342,6 +350,7 @@ class Renderer(renderer.Renderer):

def __init__(self, config=None):
self.connections = {}
self.config = config

def get_conn(self, con_id):
return self.connections[con_id]
Expand Down
6 changes: 3 additions & 3 deletions cloudinit/net/sysconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,13 +436,13 @@ def _render_subnets(cls, iface_cfg, subnets, has_default_route, flavor):
iface_cfg["BOOTPROTO"] = "dhcp6"
iface_cfg["DHCLIENT6_MODE"] = "managed"
# only if rhel AND dhcpv6 stateful
elif (
flavor == "rhel" and subnet_type == "ipv6_dhcpv6-stateful"
elif flavor == "rhel" and (
subnet_type == "ipv6_dhcpv6-stateful"
):
iface_cfg["BOOTPROTO"] = "dhcp"
iface_cfg["DHCPV6C"] = True
iface_cfg["IPV6INIT"] = True
iface_cfg["IPV6_AUTOCONF"] = False
iface_cfg["IPV6_FAILURE_FATAL"] = True
else:
iface_cfg["IPV6INIT"] = True
# Configure network settings using DHCPv6
Expand Down
9 changes: 8 additions & 1 deletion tests/unittests/test_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -1932,6 +1932,9 @@
method=auto
may-fail=false
[ipv4]
method=disabled
"""
),
},
Expand Down Expand Up @@ -2044,6 +2047,9 @@
method=auto
may-fail=false
[ipv4]
method=disabled
"""
),
},
Expand Down Expand Up @@ -2091,11 +2097,12 @@
"expected_sysconfig_rhel": {
"ifcfg-iface0": textwrap.dedent(
"""\
BOOTPROTO=dhcp
BOOTPROTO=none
DEVICE=iface0
DHCPV6C=yes
IPV6INIT=yes
IPV6_AUTOCONF=no
IPV6_FAILURE_FATAL=yes
IPV6_FORCE_ACCEPT_RA=yes
DEVICE=iface0
NM_CONTROLLED=no
Expand Down

0 comments on commit fd214a1

Please sign in to comment.