From 7388b5291b8d650e1380cd440fcb17cc2b7d2960 Mon Sep 17 00:00:00 2001 From: Garrett Holmstrom Date: Tue, 14 Mar 2017 14:53:46 -0700 Subject: [PATCH] Fix IPv6 gateways in network sysconfig https://bugs.launchpad.net/cloud-init/+bug/1669504 https://git.launchpad.net/cloud-init/commit/?id=1d751a6f46f044e3c3827f3cef0e4a2e71d50fe7 --- cloud-init-0.7.9-ipv6-gateway.patch | 201 ++++++++++++++++++++++++++++ cloud-init.spec | 6 + 2 files changed, 207 insertions(+) create mode 100644 cloud-init-0.7.9-ipv6-gateway.patch diff --git a/cloud-init-0.7.9-ipv6-gateway.patch b/cloud-init-0.7.9-ipv6-gateway.patch new file mode 100644 index 0000000..0c9687d --- /dev/null +++ b/cloud-init-0.7.9-ipv6-gateway.patch @@ -0,0 +1,201 @@ +Index: cloud-init-0.7.9/cloudinit/net/sysconfig.py +=================================================================== +--- cloud-init-0.7.9.orig/cloudinit/net/sysconfig.py ++++ cloud-init-0.7.9/cloudinit/net/sysconfig.py +@@ -87,7 +87,8 @@ class Route(ConfigMap): + def __init__(self, route_name, base_sysconf_dir): + super(Route, self).__init__() + self.last_idx = 1 +- self.has_set_default = False ++ self.has_set_default_ipv4 = False ++ self.has_set_default_ipv6 = False + self._route_name = route_name + self._base_sysconf_dir = base_sysconf_dir + +@@ -95,7 +96,8 @@ class Route(ConfigMap): + r = Route(self._route_name, self._base_sysconf_dir) + r._conf = self._conf.copy() + r.last_idx = self.last_idx +- r.has_set_default = self.has_set_default ++ r.has_set_default_ipv4 = self.has_set_default_ipv4 ++ r.has_set_default_ipv6 = self.has_set_default_ipv6 + return r + + @property +@@ -119,10 +121,10 @@ class NetInterface(ConfigMap): + super(NetInterface, self).__init__() + self.children = [] + self.routes = Route(iface_name, base_sysconf_dir) +- self._kind = kind ++ self.kind = kind ++ + self._iface_name = iface_name + self._conf['DEVICE'] = iface_name +- self._conf['TYPE'] = self.iface_types[kind] + self._base_sysconf_dir = base_sysconf_dir + + @property +@@ -140,6 +142,8 @@ class NetInterface(ConfigMap): + + @kind.setter + def kind(self, kind): ++ if kind not in self.iface_types: ++ raise ValueError(kind) + self._kind = kind + self._conf['TYPE'] = self.iface_types[kind] + +@@ -172,7 +176,7 @@ class Renderer(renderer.Renderer): + ('BOOTPROTO', 'none'), + ]) + +- # If these keys exist, then there values will be used to form ++ # If these keys exist, then their values will be used to form + # a BONDING_OPTS grouping; otherwise no grouping will be set. + bond_tpl_opts = tuple([ + ('bond_mode', "mode=%s"), +@@ -198,6 +202,7 @@ class Renderer(renderer.Renderer): + def _render_iface_shared(cls, iface, iface_cfg): + for k, v in cls.iface_defaults: + iface_cfg[k] = v ++ + for (old_key, new_key) in [('mac_address', 'HWADDR'), ('mtu', 'MTU')]: + old_value = iface.get(old_key) + if old_value is not None: +@@ -226,10 +231,20 @@ class Renderer(renderer.Renderer): + if 'netmask' in subnet: + iface_cfg['NETMASK'] = subnet['netmask'] + for route in subnet.get('routes', []): ++ if subnet.get('ipv6'): ++ gw_cfg = 'IPV6_DEFAULTGW' ++ else: ++ gw_cfg = 'GATEWAY' ++ + if _is_default_route(route): +- if route_cfg.has_set_default: +- raise ValueError("Duplicate declaration of default" +- " route found for interface '%s'" ++ if ( ++ (subnet.get('ipv4') and ++ route_cfg.has_set_default_ipv4) or ++ (subnet.get('ipv6') and ++ route_cfg.has_set_default_ipv6) ++ ): ++ raise ValueError("Duplicate declaration of default " ++ "route found for interface '%s'" + % (iface_cfg.name)) + # NOTE(harlowja): ipv6 and ipv4 default gateways + gw_key = 'GATEWAY0' +@@ -241,7 +256,7 @@ class Renderer(renderer.Renderer): + # also provided the default route? + iface_cfg['DEFROUTE'] = True + if 'gateway' in route: +- iface_cfg['GATEWAY'] = route['gateway'] ++ iface_cfg[gw_cfg] = route['gateway'] + route_cfg.has_set_default = True + else: + gw_key = 'GATEWAY%s' % route_cfg.last_idx +Index: cloud-init-0.7.9/tests/unittests/test_net.py +=================================================================== +--- cloud-init-0.7.9.orig/tests/unittests/test_net.py ++++ cloud-init-0.7.9/tests/unittests/test_net.py +@@ -165,6 +165,100 @@ nameserver 172.19.0.12 + ('etc/udev/rules.d/70-persistent-net.rules', + "".join(['SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ', + 'ATTR{address}=="fa:16:3e:ed:9a:59", NAME="eth0"\n']))] ++ }, ++ { ++ 'in_data': { ++ "services": [{"type": "dns", "address": "172.19.0.12"}], ++ "networks": [{ ++ "network_id": "public-ipv4", ++ "type": "ipv4", "netmask": "255.255.252.0", ++ "link": "tap1a81968a-79", ++ "routes": [{ ++ "netmask": "0.0.0.0", ++ "network": "0.0.0.0", ++ "gateway": "172.19.3.254", ++ }], ++ "ip_address": "172.19.1.34", "id": "network0" ++ }, { ++ "network_id": "public-ipv6", ++ "type": "ipv6", "netmask": "", ++ "link": "tap1a81968a-79", ++ "routes": [ ++ { ++ "gateway": "2001:DB8::1", ++ "netmask": "::", ++ "network": "::" ++ } ++ ], ++ "ip_address": "2001:DB8::10", "id": "network1" ++ }], ++ "links": [ ++ { ++ "ethernet_mac_address": "fa:16:3e:ed:9a:59", ++ "mtu": None, "type": "bridge", "id": ++ "tap1a81968a-79", ++ "vif_id": "1a81968a-797a-400f-8a80-567f997eb93f" ++ }, ++ ], ++ }, ++ 'in_macs': { ++ 'fa:16:3e:ed:9a:59': 'eth0', ++ }, ++ 'out_sysconfig': [ ++ ('etc/sysconfig/network-scripts/ifcfg-eth0', ++ """ ++# Created by cloud-init on instance boot automatically, do not edit. ++# ++BOOTPROTO=none ++DEVICE=eth0 ++HWADDR=fa:16:3e:ed:9a:59 ++NM_CONTROLLED=no ++ONBOOT=yes ++TYPE=Ethernet ++USERCTL=no ++""".lstrip()), ++ ('etc/sysconfig/network-scripts/ifcfg-eth0:0', ++ """ ++# Created by cloud-init on instance boot automatically, do not edit. ++# ++BOOTPROTO=static ++DEFROUTE=yes ++DEVICE=eth0:0 ++GATEWAY=172.19.3.254 ++HWADDR=fa:16:3e:ed:9a:59 ++IPADDR=172.19.1.34 ++NETMASK=255.255.252.0 ++NM_CONTROLLED=no ++ONBOOT=yes ++TYPE=Ethernet ++USERCTL=no ++""".lstrip()), ++ ('etc/sysconfig/network-scripts/ifcfg-eth0:1', ++ """ ++# Created by cloud-init on instance boot automatically, do not edit. ++# ++BOOTPROTO=static ++DEFROUTE=yes ++DEVICE=eth0:1 ++HWADDR=fa:16:3e:ed:9a:59 ++IPV6ADDR=2001:DB8::10 ++IPV6INIT=yes ++IPV6_DEFAULTGW=2001:DB8::1 ++NETMASK= ++NM_CONTROLLED=no ++ONBOOT=yes ++TYPE=Ethernet ++USERCTL=no ++""".lstrip()), ++ ('etc/resolv.conf', ++ """ ++; Created by cloud-init on instance boot automatically, do not edit. ++; ++nameserver 172.19.0.12 ++""".lstrip()), ++ ('etc/udev/rules.d/70-persistent-net.rules', ++ "".join(['SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ', ++ 'ATTR{address}=="fa:16:3e:ed:9a:59", NAME="eth0"\n']))] + } + ] + diff --git a/cloud-init.spec b/cloud-init.spec index da18c56..c447e10 100644 --- a/cloud-init.spec +++ b/cloud-init.spec @@ -61,6 +61,11 @@ Patch15: cloud-init-0.7.9-sysconfig-iface.patch # https://git.launchpad.net/cloud-init/commit/?id=657fd40f9ee692a817ec4614cd0d6cb0539ffabf Patch16: cloud-init-0.7.9-gt3-nameservers.patch +# Fix IPv6 gateways in network sysconfig +# https://bugs.launchpad.net/cloud-init/+bug/1669504 +# https://git.launchpad.net/cloud-init/commit/?id=1d751a6f46f044e3c3827f3cef0e4a2e71d50fe7 +Patch17: cloud-init-0.7.9-ipv6-gateway.patch + BuildArch: noarch BuildRequires: pkgconfig(systemd) @@ -202,6 +207,7 @@ nosetests-%{python3_version} tests/unittests/ \ - Fixed systemd dependency cycle with cloud-init and multi-user.target [RH:1428492, RH:1430511] - Fixed errors in network sysconfig handling [RH:1389530, LP:1665441] - Made > 3 name servers a warning, not a fatal error, unbreaking IPv6 setups [LP:1670052] +- Fixed IPv6 gateways in network sysconfig [LP:1669504] * Fri Feb 10 2017 Fedora Release Engineering - 0.7.9-3 - Rebuilt for https://fedoraproject.org/wiki/Fedora_26_Mass_Rebuild