from neutron.common import constants
from neutron.common import exceptions as n_exc
from neutron.common import ipv6_utils
+from neutron.common import utils as c_utils
from neutron.extensions import portsecurity as psec
from neutron.i18n import _LI
'-m mac --mac-source %s -j RETURN'
% mac.upper(), comment=ic.PAIR_ALLOW)
else:
+ # we need to convert it into a prefix to match iptables
+ ip = c_utils.ip_to_cidr(ip)
table.add_rule(chain_name,
'-s %s -m mac --mac-source %s -j RETURN'
% (ip, mac.upper()), comment=ic.PAIR_ALLOW)
#NOTE (nati) : source_group_id is converted to list of source_
# ip_prefix in server side
if ip_prefix:
+ if '/' not in ip_prefix:
+ # we need to convert it into a prefix to match iptables
+ ip_prefix = c_utils.ip_to_cidr(ip_prefix)
+ elif ip_prefix.endswith('/0'):
+ # an allow for every address is not a constraint so
+ # iptables drops it
+ return []
return ['-%s' % direction, ip_prefix]
return []
from neutron.agent import securitygroups_rpc as sg_cfg
from neutron.common import constants
from neutron.common import exceptions as n_exc
+from neutron.common import utils
from neutron.tests import base
from neutron.tests.unit.api.v2 import test_base
mock.call.add_chain('sfake_dev'),
mock.call.add_rule(
'sfake_dev',
- '-s 10.0.0.1 -m mac --mac-source FF:FF:FF:FF:FF:FF '
+ '-s 10.0.0.1/32 -m mac --mac-source FF:FF:FF:FF:FF:FF '
'-j RETURN',
comment=ic.PAIR_ALLOW),
mock.call.add_rule(
egress_expected_call=None):
port = self._fake_port()
ethertype = rule['ethertype']
- prefix = FAKE_IP[ethertype]
+ prefix = utils.ip_to_cidr(FAKE_IP[ethertype])
filter_inst = self.v4filter_inst
dhcp_rule = [mock.call.add_rule(
'ofake_dev',
mock.call.add_chain('sfake_dev'),
mock.call.add_rule(
'sfake_dev',
- '-s 10.0.0.1 -m mac --mac-source FF:FF:FF:FF:FF:FF '
+ '-s 10.0.0.1/32 -m mac --mac-source FF:FF:FF:FF:FF:FF '
'-j RETURN',
comment=ic.PAIR_ALLOW),
mock.call.add_rule(
mock.call.add_chain('sfake_dev'),
mock.call.add_rule(
'sfake_dev',
- '-s 10.0.0.1 -m mac --mac-source FF:FF:FF:FF:FF:FF '
+ '-s 10.0.0.1/32 -m mac --mac-source FF:FF:FF:FF:FF:FF '
'-j RETURN',
comment=ic.PAIR_ALLOW),
mock.call.add_rule(
mock.call.add_chain('sfake_dev'),
mock.call.add_rule(
'sfake_dev',
- '-s 10.0.0.1 -m mac --mac-source FF:FF:FF:FF:FF:FF '
+ '-s 10.0.0.1/32 -m mac --mac-source FF:FF:FF:FF:FF:FF '
'-j RETURN',
comment=ic.PAIR_ALLOW),
mock.call.add_rule(
'sfake_dev',
- '-s 10.0.0.2 -m mac --mac-source FF:FF:FF:FF:FF:FF '
+ '-s 10.0.0.2/32 -m mac --mac-source FF:FF:FF:FF:FF:FF '
'-j RETURN',
comment=ic.PAIR_ALLOW),
mock.call.add_rule(