Merge "Log the IPTables rules if "debug_iptables_rules""

This commit is contained in:
Zuul 2019-10-19 01:56:23 +00:00 committed by Gerrit Code Review
commit 86e4f14115
4 changed files with 36 additions and 0 deletions

View File

@ -20,5 +20,8 @@ ip6tables-restore: CommandFilter, ip6tables-restore, root
iptables: CommandFilter, iptables, root
ip6tables: CommandFilter, ip6tables, root
# neutron/agent/linux/iptables_firewall.py
sysctl: CommandFilter, sysctl, root
# neutron/agent/linux/ip_conntrack.py
conntrack: CommandFilter, conntrack, root

View File

@ -30,6 +30,7 @@ from neutron.agent.linux import ip_conntrack
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 as a_utils
from neutron.common import _constants as const
from neutron.common import ipv6_utils
from neutron.common import utils as c_utils
@ -94,6 +95,36 @@ class IptablesFirewallDriver(firewall.FirewallDriver):
self.updated_sg_members = set()
self.devices_with_updated_sg_members = collections.defaultdict(list)
self._iptables_protocol_name_map = {}
self._check_netfilter_for_bridges()
@staticmethod
def _check_netfilter_for_bridges():
"""Check if br_netfilter is loaded and the needed flags for IPtables"""
log_warning = False
if not a_utils.execute(
['sysctl', '-N', 'net.bridge'], run_as_root=True,
log_fail_as_error=False, check_exit_code=False):
LOG.warning('Kernel module br_netfilter is not loaded.')
log_warning = True
if not log_warning:
for proto in ('arp', 'ip', 'ip6'):
key = 'net.bridge.bridge-nf-call-%stables' % proto
enabled = a_utils.execute(
['sysctl', '-b', key], run_as_root=True,
log_fail_as_error=False, check_exit_code=False)
if enabled == '1':
status = 'enabled'
log_method = LOG.debug
else:
status = 'disabled'
log_method = LOG.warning
log_warning = True
log_method('Key %(key)s is %(status)s',
{'key': key, 'status': status})
if log_warning:
LOG.warning('Please ensure that netfilter options for bridge are '
'enabled to provide working security groups.')
@property
def ports(self):

View File

@ -464,6 +464,7 @@ class IptablesManager(object):
first = self._apply_synchronized()
if not cfg.CONF.AGENT.debug_iptables_rules:
return first
LOG.debug('List of IPTables Rules applied: %s', '\n'.join(first))
second = self._apply_synchronized()
if second:
msg = (_("IPTables Rules did not converge. Diff: %s") %

View File

@ -94,6 +94,7 @@ class BaseIptablesFirewallTestCase(base.BaseTestCase):
self.iptables_inst.get_rules_for_table.return_value = (
RAW_TABLE_OUTPUT.splitlines())
self.firewall = iptables_firewall.IptablesFirewallDriver()
self.utils_exec.reset_mock()
self.firewall.iptables = self.iptables_inst
# don't mess with sysctl knobs in unit tests
self.firewall._enabled_netfilter_for_bridges = True