Index: backend/iv_exec.cc
===================================================================
--- backend/iv_exec.cc	(revision 506)
+++ backend/iv_exec.cc	(working copy)
@@ -69,7 +69,7 @@
     _stackptr--;
 
     // execute all policies
-    for (unsigned i = 0; i < _policy_count; ++i) {
+    for (int i = _policy_count-1; i >= 0; --i) {
 	FlowAction fa = runPolicy(*_policies[i]);
 
 	// if a policy rejected/accepted a route then terminate.
Index: policy_list.hh
===================================================================
--- policy_list.hh	(revision 506)
+++ policy_list.hh	(working copy)
@@ -81,7 +81,8 @@
      */
     void compile_policy(PolicyStatement& ps,
 			Code::TargetSet& mod, 
-			uint32_t& tagstart);
+			uint32_t& tagstart,
+			map<string, set<uint32_t> >& ptags);
 
     /**
      * Compile all policies which were not previously compiled.
@@ -91,7 +92,7 @@
      * @param mod set filled with targets which are modified by compilation.
      * @param tagstart first policy tag available.
      */
-    void compile(Code::TargetSet& mod, uint32_t& tagstart);
+    void compile(Code::TargetSet& mod, uint32_t& tagstart, map<string, set<uint32_t> >& ptags);
    
     /**
      * @return string representation of list
@@ -158,7 +159,8 @@
      * @param tagstart first policy tag available.
      */
     void compile_export(PolicyCodeList::iterator& iter, PolicyStatement& ps,
-			Code::TargetSet& modified_targets, uint32_t& tagstart);
+			Code::TargetSet& modified_targets, uint32_t& tagstart,
+			map<string, set<uint32_t> > & ptags);
 
     Term* create_mod(Term::BLOCKS block);
     void  add_policy_expression(const string& exp);
Index: configuration.hh
===================================================================
--- configuration.hh	(revision 506)
+++ configuration.hh	(working copy)
@@ -60,8 +60,8 @@
     void	clear(TARGETSET& ts);
     void	get_targets(const string& proto, const string& mod,
 			    TARGETSET& targets);
-    void	compile(PolicyStatement& ps, TARGETSET& targets, tag_t& tag);
-    void	compile(TARGETSET& targets, tag_t& tag);
+    void	compile(PolicyStatement& ps, TARGETSET& targets, tag_t& tag, map<string, set<uint32_t> >& ptags);
+    void	compile(TARGETSET& targets, tag_t& tag, map<string, set<uint32_t> >& ptags);
     void	link_code(Code& code);
     void	link_code(const string& proto, Code& code);
     void	get_redist_tags(const string& proto, TagSet& ts);
@@ -394,6 +394,7 @@
     CodeMap		    _sourcematch_filters;
     CodeMap		    _export_filters;
     tag_t		    _currtag;
+    map<string, set<uint32_t> > _protocol_tags;
     TagMap		    _tagmap;
     VarMap		    _varmap;
     FilterManagerBase*	    _filter_manager; // do not delete
Index: source_match_code_generator.cc
===================================================================
--- source_match_code_generator.cc	(revision 506)
+++ source_match_code_generator.cc	(working copy)
@@ -27,8 +27,10 @@
 
 SourceMatchCodeGenerator::SourceMatchCodeGenerator(uint32_t tagstart,
 						   const VarMap& varmap,
-						   PolicyMap& pmap) 
-	   : CodeGenerator(varmap, pmap), _currtag(tagstart)
+						   PolicyMap& pmap,
+					map<string, set<uint32_t> > & ptags) 
+	   : CodeGenerator(varmap, pmap), _currtag(tagstart),
+	     _protocol_tags(ptags)
 {
 }
 
Index: source_match_code_generator.hh
===================================================================
--- source_match_code_generator.hh	(revision 506)
+++ source_match_code_generator.hh	(working copy)
@@ -68,7 +68,8 @@
      * @param varmap the varmap.
      */
     SourceMatchCodeGenerator(uint32_t tagstart, const VarMap& varmap,
-			     PolicyMap& pmap);
+			     PolicyMap& pmap, 
+			    map<string, set<uint32_t> >& ptags);
 
     const Element* visit_policy(PolicyStatement& policy);
     const Element* visit_term(Term& term);
@@ -116,7 +117,7 @@
     // FIXME: who deletes these on exception ?
     vector<Code*>		_codes_vect; 
     Tags			_tags;
-    map<string, set<uint32_t> >	_protocol_tags;
+    map<string, set<uint32_t> >& _protocol_tags;
     bool			_protocol_statement;
     string			_policy;
 
Index: policy_list.cc
===================================================================
--- policy_list.cc	(revision 506)
+++ policy_list.cc	(working copy)
@@ -161,7 +161,8 @@
 
 void 
 PolicyList::compile_policy(PolicyStatement& ps,Code::TargetSet& mod, 
-			   uint32_t& tagstart)
+			   uint32_t& tagstart,
+			    map<string, set<uint32_t> >& ptags)
 {
     // go throw all the policies present in this list
     for(PolicyCodeList::iterator i = _policies.begin();
@@ -174,7 +175,7 @@
 		    compile_import(i,ps,mod);
 		    break;
 		case EXPORT:
-		    compile_export(i,ps,mod,tagstart);
+		    compile_export(i,ps,mod,tagstart, ptags);
 		    break;
 	    }
 	}
@@ -182,7 +183,7 @@
 }
 
 void 
-PolicyList::compile(Code::TargetSet& mod, uint32_t& tagstart)
+PolicyList::compile(Code::TargetSet& mod, uint32_t& tagstart, map<string, set<uint32_t> >& ptags)
 {
     // go throw all policies in the list
     for (PolicyCodeList::iterator i = _policies.begin();
@@ -204,7 +205,7 @@
 	    break;
 	
 	case EXPORT:
-	    compile_export(i, ps, mod, tagstart);
+	    compile_export(i, ps, mod, tagstart, ptags);
 	    break;
 	}
     }    
@@ -352,7 +353,8 @@
 void 
 PolicyList::compile_export(PolicyCodeList::iterator& iter, PolicyStatement& ps, 
 			   Code::TargetSet& modified_targets, 
-			   uint32_t& tagstart)
+			   uint32_t& tagstart,
+			    map<string, set<uint32_t> >& ptags)
 {
     _mod_term = _mod_term_export;
 
@@ -360,7 +362,7 @@
     semantic_check(ps, VisitorSemantic::EXPORT);
 
     // generate source match code
-    SourceMatchCodeGenerator smcg(tagstart, _varmap, _pmap);
+    SourceMatchCodeGenerator smcg(tagstart, _varmap, _pmap, ptags);
     
     // check modifier [a bit of a hack]
     if (_mod_term)
Index: configuration.cc
===================================================================
--- configuration.cc	(revision 506)
+++ configuration.cc	(working copy)
@@ -304,10 +304,10 @@
     tag_t old_currtag = _currtag; 
 
     // go through all the import statements
-    _imports.compile(policy, _modified_targets, _currtag);
+    _imports.compile(policy, _modified_targets, _currtag, _protocol_tags);
 
     // go through all export statements
-    _exports.compile(policy, _modified_targets, _currtag);
+    _exports.compile(policy, _modified_targets, _currtag, _protocol_tags);
 
     // integer overflow
     if (_currtag < old_currtag)
@@ -332,10 +332,10 @@
     // compile any import policies that have not yet been compiled.
     // This is a case if a policy is not modified, but just added to a policy
     // list.
-    _imports.compile(_modified_targets, _currtag);
+    _imports.compile(_modified_targets, _currtag, _protocol_tags);
 
     // same for exports.
-    _exports.compile(_modified_targets, _currtag);
+    _exports.compile(_modified_targets, _currtag, _protocol_tags);
 
     // integer overflow.
     if (_currtag < old_currtag) {
@@ -731,22 +731,22 @@
 }
 
 void
-IEMap::compile(PolicyStatement& ps, TARGETSET& ts, tag_t& tag)
+IEMap::compile(PolicyStatement& ps, TARGETSET& ts, tag_t& tag, map<string, set<uint32_t> >& ptags)
 {
     FOR_ALL_POLICIES(j) {
 	PolicyList* p = j->second;
 
-	p->compile_policy(ps, ts, tag);
+	p->compile_policy(ps, ts, tag, ptags);
     }
 }
 
 void
-IEMap::compile(TARGETSET& ts, tag_t& tag)
+IEMap::compile(TARGETSET& ts, tag_t& tag, map<string, set<uint32_t> >& ptags)
 {
     FOR_ALL_POLICIES(j) {
 	PolicyList* p = j->second;
 
-	p->compile(ts, tag);
+	p->compile(ts, tag, ptags);
     }
 }
 
