Change in vdsm[master]: configurators: make disable_ipv6 permanent by using sysctl.d...

osvoboda at redhat.com osvoboda at redhat.com
Mon Oct 5 14:54:47 UTC 2015


Ondřej Svoboda has uploaded a new change for review.

Change subject: configurators: make disable_ipv6 permanent by using sysctl.d configs
......................................................................

configurators: make disable_ipv6 permanent by using sysctl.d configs

TODO: Will SELinux complain?

Change-Id: I8eb8c529dae7a773530c6c5e98c12d33ef91968f
Bug-Url: https://bugzilla.redhat.com/1219363
Backport-To: 3.6
Signed-off-by: Ondřej Svoboda <osvoboda at redhat.com>
---
M lib/vdsm/sysctl.py
M vdsm/network/api.py
M vdsm/network/configurators/__init__.py
3 files changed, 28 insertions(+), 9 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/85/46985/1

diff --git a/lib/vdsm/sysctl.py b/lib/vdsm/sysctl.py
index 603c67a..287653f 100644
--- a/lib/vdsm/sysctl.py
+++ b/lib/vdsm/sysctl.py
@@ -20,8 +20,15 @@
 
 
 from __future__ import absolute_import
+import os
+
+from utils import rmFile
+
 _RPFILTER_STRICT = '1'
 _RPFILTER_LOOSE = '2'
+_DISABLE_IPV6_RUNTIME_PATH = '/proc/sys/net/ipv6/conf/{}/disable_ipv6'
+_SYSCTL_DIR = '/etc/sysctl.d'
+_DISABLE_IPV6_CONF_PATH = os.path.join(_SYSCTL_DIR, 'vdsm-{}.conf')
 
 
 def set_rp_filter(dev, mode):
@@ -38,12 +45,22 @@
     set_rp_filter(dev, _RPFILTER_STRICT)
 
 
-def toggle_ipv6(dev, enable):
-    with open('/proc/sys/net/ipv6/conf/%s/disable_ipv6' % dev, 'w') as f:
+def toggle_ipv6(device, enable, permanently=False):
+    with open(_DISABLE_IPV6_RUNTIME_PATH.format(device), 'w') as f:
         f.write('0' if enable else '1')
+    if permanently:
+        with open(_DISABLE_IPV6_CONF_PATH.format(device), 'w') as f:
+            f.write(
+                '# control IPv6 traffic between VMs and the world\n'
+                'net.ipv6.conf.{}.disable_ipv6 = {}\n'.format(
+                    device, '0' if enable else '1'))
 
 
 def is_disabled_ipv6():
-    with open('/proc/sys/net/ipv6/conf/default/disable_ipv6') as f:
-        ipv6_enabled = f.read()
-    return int(ipv6_enabled)
+    with open(_DISABLE_IPV6_RUNTIME_PATH.format('default')) as f:
+        ipv6_disabled = f.read()
+    return int(ipv6_disabled)
+
+
+def remove_permanent_ipv6_conf(device):
+    rmFile(_DISABLE_IPV6_CONF_PATH.format(device))
diff --git a/vdsm/network/api.py b/vdsm/network/api.py
index 3f1216e..735323e 100755
--- a/vdsm/network/api.py
+++ b/vdsm/network/api.py
@@ -30,11 +30,12 @@
 
 from vdsm.config import config
 from vdsm import constants
+from vdsm import ipwrapper
 from vdsm import netconfpersistence
 from vdsm import netinfo
+from vdsm import sysctl
 from vdsm import udevadm
 from vdsm import utils
-from vdsm import ipwrapper
 
 from .configurators import dhclient, libvirt
 from .errors import ConfigNetworkError
@@ -494,6 +495,8 @@
     if net_ent_to_remove is not None:
         logging.info('Removing network entity %s', net_ent_to_remove)
         net_ent_to_remove.remove()
+    if bridged:
+        sysctl.remove_permanent_ipv6_conf(network)
     # We must remove the QoS last so that no devices nor networks mark the
     # QoS as used
     backing_device = hierarchy_backing_device(net_ent)
diff --git a/vdsm/network/configurators/__init__.py b/vdsm/network/configurators/__init__.py
index e66f611..8967f44 100644
--- a/vdsm/network/configurators/__init__.py
+++ b/vdsm/network/configurators/__init__.py
@@ -167,11 +167,10 @@
         return maxMtu
 
     def _update_ipv6_sysctl(device):
+        _wait_for_device(device.name)
         ipv6_requested = (device.ipv6.address or device.ipv6.ipv6autoconf or
                           device.ipv6.dhcpv6)
-        if not ipv6_requested:
-            _wait_for_device(device.name)
-            sysctl.toggle_ipv6(device.name, False)
+        sysctl.toggle_ipv6(device.name, ipv6_requested, permanent=True)
 
 
 def getEthtoolOpts(name):


-- 
To view, visit https://gerrit.ovirt.org/46985
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8eb8c529dae7a773530c6c5e98c12d33ef91968f
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Ondřej Svoboda <osvoboda at redhat.com>


More information about the vdsm-patches mailing list