Add default routes for IPv4 and IPv6 only to ifcfg-* files and not to route-* or route6-* files in sysconfig

Bug #1696176 reported by Andreas Karis
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Fix Released
Andreas Karis

Bug Description

Since f38fa41317602908139aa96e930b634f65e39555 , default routes get added to both ifcfg-* and route-* and route6-* files. (ii) Default routes should only go to ifcfg-* files, otherwise the information is redundant. (i) Also, in dual stack networks, this redundant "feature" isn't working correctly, only the IPv6 route is added to both route6-* and ifcfg-*, but not the IPv4 route.

(i) First of all, let me explain why only the IPv6 route was added to route6-* and not the IPv4 route to route-*
for route in subnet.get('routes', []):
                is_ipv6 = subnet.get('ipv6')

                if _is_default_route(route):
                    if (
                            (subnet.get('ipv4') and
                             route_cfg.has_set_default_ipv4) or
                            (subnet.get('ipv6') and
                        raise ValueError("Duplicate declaration of default "
                                         "route found for interface '%s'"
                                         % (
                    # NOTE(harlowja): ipv6 and ipv4 default gateways
                    gw_key = 'GATEWAY0'
                    nm_key = 'NETMASK0'
                    addr_key = 'ADDRESS0'

The above will obviously overwrite GATEWAY0, NETMASK0, ADDRESS0 when there is an IPv4 default route and an IPv6 default route.

(ii) Now, interestingly, we don't want to add these routes to the route-* and route6-* files, because this would only result in duplicate default route declaration (we only need it in the ifcfg-* files, not in the route-* or route6-*).

Which means that this can be fixed by changing indentation for the following lines (moving all lines marked with "+" exactly 4 characters to the right). This moves the route_cfg part into the "else" condition:
cd /usr/lib/python2.7/site-packages/cloudinit/net
[root@rhel-test net]# diff -u
--- 2017-06-06 12:39:25.857595506 -0400
+++ 2017-06-06 12:40:19.059595506 -0400
@@ -372,11 +372,11 @@
                     nm_key = 'NETMASK%s' % route_cfg.last_idx
                     addr_key = 'ADDRESS%s' % route_cfg.last_idx
                     route_cfg.last_idx += 1
- for (old_key, new_key) in [('gateway', gw_key),
- ('netmask', nm_key),
- ('network', addr_key)]:
- if old_key in route:
- route_cfg[new_key] = route[old_key]
+ for (old_key, new_key) in [('gateway', gw_key),
+ ('netmask', nm_key),
+ ('network', addr_key)]:
+ if old_key in route:
+ route_cfg[new_key] = route[old_key]

     def _render_bonding_opts(cls, iface_cfg, iface):

The above means that a route will only be added to the route_cfg array if it is not a default route.

Related branches

Andreas Karis (akaris)
Changed in cloud-init:
assignee: nobody → Andreas Karis (akaris)
Scott Moser (smoser)
Changed in cloud-init:
status: New → Confirmed
importance: Undecided → Medium
Scott Moser (smoser)
Changed in cloud-init:
status: Confirmed → Fix Committed
Revision history for this message
Scott Moser (smoser) wrote : Fixed in Cloud-init 17.1

This bug is believed to be fixed in cloud-init in 17.1. If this is still a problem for you, please make a comment and set the state back to New

Thank you.

Changed in cloud-init:
status: Fix Committed → Fix Released
Revision history for this message
James Falcon (falcojr) wrote :
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.