← Back to team overview

yahoo-eng-team team mailing list archive

[Bug 1696176] [NEW] Add default routes for IPv4 and IPv6 only to ifcfg-* files and not to route-* or route6-* files in sysconfig

 

Public bug reported:

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-*

sysconfig.py
(...)
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
                             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'
                    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 sysconfig.py.back sysconfig.py
--- sysconfig.py.back	2017-06-06 12:39:25.857595506 -0400
+++ sysconfig.py	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]
 
     @classmethod
     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.

** Affects: cloud-init
     Importance: Undecided
         Status: New

-- 
You received this bug notification because you are a member of Yahoo!
Engineering Team, which is subscribed to cloud-init.
https://bugs.launchpad.net/bugs/1696176

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

Status in cloud-init:
  New

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-*

  sysconfig.py
  (...)
  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
                               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'
                      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 sysconfig.py.back sysconfig.py
  --- sysconfig.py.back	2017-06-06 12:39:25.857595506 -0400
  +++ sysconfig.py	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]
   
       @classmethod
       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.

To manage notifications about this bug go to:
https://bugs.launchpad.net/cloud-init/+bug/1696176/+subscriptions


Follow ups