'Configure address scope related iptables rules for the router\'s
floating IPs.'

def process_floating_ip_address_scope_rules(self):

    self.iptables_manager.ipv4['mangle'].clear_rules_by_tag('floating_ip')
    all_floating_ips = self.get_floating_ips()
    ext_scope = self._get_external_address_scope()
    floating_ips = [fip for fip in all_floating_ips if (fip.get('fixed_ip_address_scope') != ext_scope)]
    if floating_ips:
        ext_scope_mark = self.get_address_scope_mark_mask(ext_scope)
        ports_scopemark = self._get_address_scope_mark()
        devices_in_ext_scope = {device for (device, mark) in ports_scopemark[lib_constants.IP_VERSION_4].items() if (mark == ext_scope_mark)}
        for device in devices_in_ext_scope:
            self.iptables_manager.ipv4['mangle'].add_rule('float-snat', ('-o    %s    -j    MARK    --set-xmark    %s' % (device, ext_scope_mark)), tag='floating_ip')
    for fip in floating_ips:
        fip_ip = fip['floating_ip_address']
        fixed_ip = fip['fixed_ip_address']
        fixed_scope = fip.get('fixed_ip_address_scope')
        internal_mark = self.get_address_scope_mark_mask(fixed_scope)
        mangle_rules = self.floating_mangle_rules(fip_ip, fixed_ip, internal_mark)
        for (chain, rule) in mangle_rules:
            self.iptables_manager.ipv4['mangle'].add_rule(chain, rule, tag='floating_ip')
