Merge "Ensure netfilter is enabled for bridges"
This commit is contained in:
commit
3b27f83964
@ -23,6 +23,7 @@ from neutron.agent import firewall
|
||||
from neutron.agent.linux import ipset_manager
|
||||
from neutron.agent.linux import iptables_comments as ic
|
||||
from neutron.agent.linux import iptables_manager
|
||||
from neutron.agent.linux import utils
|
||||
from neutron.common import constants
|
||||
from neutron.common import ipv6_utils
|
||||
from neutron.extensions import portsecurity as psec
|
||||
@ -72,6 +73,32 @@ class IptablesFirewallDriver(firewall.FirewallDriver):
|
||||
lambda: collections.defaultdict(list))
|
||||
self.pre_sg_members = None
|
||||
self.enable_ipset = cfg.CONF.SECURITYGROUP.enable_ipset
|
||||
self._enabled_netfilter_for_bridges = False
|
||||
|
||||
def _enable_netfilter_for_bridges(self):
|
||||
# we only need to set these values once, but it has to be when
|
||||
# we create a bridge; before that the bridge module might not
|
||||
# be loaded and the proc values aren't there.
|
||||
if self._enabled_netfilter_for_bridges:
|
||||
return
|
||||
else:
|
||||
self._enabled_netfilter_for_bridges = True
|
||||
|
||||
# These proc values ensure that netfilter is enabled on
|
||||
# bridges; essential for enforcing security groups rules with
|
||||
# OVS Hybrid. Distributions can differ on whether this is
|
||||
# enabled by default or not (Ubuntu - yes, Redhat - no, for
|
||||
# example).
|
||||
LOG.debug("Enabling netfilter for bridges")
|
||||
utils.execute(['sysctl', '-w',
|
||||
'net.bridge.bridge-nf-call-arptables=1'],
|
||||
run_as_root=True)
|
||||
utils.execute(['sysctl', '-w',
|
||||
'net.bridge.bridge-nf-call-ip6tables=1'],
|
||||
run_as_root=True)
|
||||
utils.execute(['sysctl', '-w',
|
||||
'net.bridge.bridge-nf-call-iptables=1'],
|
||||
run_as_root=True)
|
||||
|
||||
@property
|
||||
def ports(self):
|
||||
@ -104,7 +131,7 @@ class IptablesFirewallDriver(firewall.FirewallDriver):
|
||||
LOG.debug("Preparing device (%s) filter", port['device'])
|
||||
self._remove_chains()
|
||||
self._set_ports(port)
|
||||
|
||||
self._enable_netfilter_for_bridges()
|
||||
# each security group has it own chains
|
||||
self._setup_chains()
|
||||
self.iptables.apply()
|
||||
|
@ -2488,6 +2488,9 @@ class TestSecurityGroupAgentWithIptables(base.BaseTestCase):
|
||||
cfg.CONF.set_override('enable_ipset', False, group='SECURITYGROUP')
|
||||
cfg.CONF.set_override('comment_iptables_rules', False, group='AGENT')
|
||||
|
||||
self.utils_exec = mock.patch(
|
||||
'neutron.agent.linux.utils.execute').start()
|
||||
|
||||
self.rpc = mock.Mock()
|
||||
self._init_agent(defer_refresh_firewall)
|
||||
|
||||
@ -2612,6 +2615,13 @@ class TestSecurityGroupAgentWithIptables(base.BaseTestCase):
|
||||
self.assertThat(kwargs['process_input'],
|
||||
matchers.MatchesRegex(expected_regex))
|
||||
|
||||
expected = ['net.bridge.bridge-nf-call-arptables=1',
|
||||
'net.bridge.bridge-nf-call-ip6tables=1',
|
||||
'net.bridge.bridge-nf-call-iptables=1']
|
||||
for e in expected:
|
||||
self.utils_exec.assert_any_call(['sysctl', '-w', e],
|
||||
run_as_root=True)
|
||||
|
||||
def _replay_iptables(self, v4_filter, v6_filter, raw):
|
||||
self._register_mock_call(
|
||||
['iptables-save', '-c'],
|
||||
|
Loading…
Reference in New Issue
Block a user