~niedbalski/ubuntu/vivid/neutron/fixes-1447803

« back to all changes in this revision

Viewing changes to neutron/db/securitygroups_rpc_base.py

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-10-03 18:45:23 UTC
  • mfrom: (1.1.15)
  • Revision ID: package-import@ubuntu.com-20141003184523-4mt6dy1q3j8n30c9
Tags: 1:2014.2~rc1-0ubuntu1
* New upstream release candidate:
  - d/p/*: Refreshed.
  - d/control: Add python-requests-mock to BD's.
  - d/control: Align versioned requirements with upstream.
* Transition linuxbridge and openvswitch plugin users to modular
  layer 2 plugin (LP: #1323729):
  - d/control: Mark removed plugin packages as transitional, depend
    on neutron-plugin-ml2, mark oldlibs/extra.
  - d/neutron-plugin-{linuxbridge,openvswitch}.install: Drop.
  - d/control: Depend on neutron-plugin-ml2 for linuxbridge
    agent package.
  - d/neutron-plugin-linuxbridge-agent.upstart: Use ml2 plugin
    configuration files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
LOG = logging.getLogger(__name__)
28
28
 
29
29
 
30
 
IP_MASK = {q_const.IPv4: 32,
31
 
           q_const.IPv6: 128}
32
 
 
33
 
 
34
30
DIRECTION_IP_PREFIX = {'ingress': 'source_ip_prefix',
35
31
                       'egress': 'dest_ip_prefix'}
36
32
 
 
33
DHCP_RULE_PORT = {4: (67, 68, q_const.IPv4), 6: (547, 546, q_const.IPv6)}
 
34
 
37
35
 
38
36
class SecurityGroupServerRpcMixin(sg_db.SecurityGroupDbMixin):
39
37
    """Mixin class to add agent-based security group implementation."""
208
206
        for sg_id, member_ips in ips.items():
209
207
            for ip in member_ips:
210
208
                ethertype = 'IPv%d' % netaddr.IPAddress(ip).version
211
 
                if ip not in sg_info['sg_member_ips'][sg_id][ethertype]:
 
209
                if (ethertype in sg_info['sg_member_ips'][sg_id]
 
210
                    and ip not in sg_info['sg_member_ips'][sg_id][ethertype]):
212
211
                    sg_info['sg_member_ips'][sg_id][ethertype].append(ip)
213
212
        return sg_info
214
213
 
282
281
            ips[network_id] = []
283
282
 
284
283
        for port, ip in query:
285
 
            ips[port['network_id']].append(ip)
 
284
            if (netaddr.IPAddress(ip).version == 6
 
285
                and not netaddr.IPAddress(ip).is_link_local()):
 
286
                mac_address = port['mac_address']
 
287
                ip = str(ipv6.get_ipv6_addr_by_EUI64(q_const.IPV6_LLA_PREFIX,
 
288
                    mac_address))
 
289
            if ip not in ips[port['network_id']]:
 
290
                ips[port['network_id']].append(ip)
 
291
 
286
292
        return ips
287
293
 
288
294
    def _select_ra_ips_for_network_ids(self, context, network_ids):
376
382
    def _add_ingress_dhcp_rule(self, port, ips):
377
383
        dhcp_ips = ips.get(port['network_id'])
378
384
        for dhcp_ip in dhcp_ips:
379
 
            if not netaddr.IPAddress(dhcp_ip).version == 4:
380
 
                return
381
 
 
 
385
            source_port, dest_port, ethertype = DHCP_RULE_PORT[
 
386
                netaddr.IPAddress(dhcp_ip).version]
382
387
            dhcp_rule = {'direction': 'ingress',
383
 
                         'ethertype': q_const.IPv4,
 
388
                         'ethertype': ethertype,
384
389
                         'protocol': 'udp',
385
 
                         'port_range_min': 68,
386
 
                         'port_range_max': 68,
387
 
                         'source_port_range_min': 67,
388
 
                         'source_port_range_max': 67}
389
 
            dhcp_rule['source_ip_prefix'] = "%s/%s" % (dhcp_ip,
390
 
                                                       IP_MASK[q_const.IPv4])
 
390
                         'port_range_min': dest_port,
 
391
                         'port_range_max': dest_port,
 
392
                         'source_port_range_min': source_port,
 
393
                         'source_port_range_max': source_port,
 
394
                         'source_ip_prefix': dhcp_ip}
391
395
            port['security_group_rules'].append(dhcp_rule)
392
396
 
393
397
    def _add_ingress_ra_rule(self, port, ips):