[Xorp-hackers] [PATCH 3/5] xorp: policy: Remove tags from _protocol_tags when removing tags from _tagmap
igorm at etf.rs
igorm at etf.rs
Wed Apr 11 09:26:19 PDT 2012
From: Igor Maravic <igorm at etf.rs>
If we don't remove them here they're just going to pile up.
Signed-off-by: Igor Maravic <igorm at etf.rs>
---
xorp/policy/configuration.cc | 32 ++++++++++++++++++++++++++++++--
xorp/policy/configuration.hh | 7 +++++++
2 files changed, 37 insertions(+), 2 deletions(-)
diff --git a/xorp/policy/configuration.cc b/xorp/policy/configuration.cc
index a0e951e..d6736bc 100644
--- a/xorp/policy/configuration.cc
+++ b/xorp/policy/configuration.cc
@@ -189,10 +189,11 @@ Configuration::update_exports(const string& protocol,
TagMap::iterator i = _tagmap.find(protocol);
if(i != _tagmap.end()) {
TagSet* ts = (*i).second;
+ _tagmap.erase(i);
- delete ts;
+ clear_protocol_tags(*ts);
- _tagmap.erase(i);
+ delete ts;
}
update_ie(protocol, exports, _exports, PolicyList::EXPORT, mod);
@@ -203,6 +204,33 @@ Configuration::update_exports(const string& protocol,
}
void
+Configuration::clear_protocol_tags(const TagSet& ts)
+{
+ // check if some ts element already exists in _tagmap
+ // if they do, don't remove them from the _protocol_tags
+ TagSet::const_iterator ts_iter;
+ for (ts_iter = ts.begin(); ts_iter != ts.end(); ts_iter++) {
+ bool skip = false;
+
+ for (TagMap::const_iterator iter = _tagmap.begin(); iter != _tagmap.end(); ++iter) {
+ if (iter->second->find(*ts_iter) != iter->second->end()) {
+ skip = true;
+ break;
+ }
+ }
+
+ if (!skip) {
+ map<string, set<uint32_t> >::iterator pt_iter;
+ for (pt_iter = _protocol_tags.begin(); pt_iter != _protocol_tags.end(); pt_iter++) {
+ pt_iter->second.erase(*ts_iter);
+ if (pt_iter->second.empty())
+ _protocol_tags.erase(pt_iter);
+ }
+ }
+ }
+}
+
+void
Configuration::clear_imports(const string& protocol)
{
// check if protocol exists
diff --git a/xorp/policy/configuration.hh b/xorp/policy/configuration.hh
index 3b5ffc3..61f474f 100644
--- a/xorp/policy/configuration.hh
+++ b/xorp/policy/configuration.hh
@@ -318,6 +318,13 @@ public:
*/
string dump_state(uint32_t id);
+ /**
+ * Clear tags specified with ts from _protocol_tags
+ *
+ * @param ts tags to erase from _protocol_tags
+ */
+ void clear_protocol_tags(const TagSet& ts);
+
void clear_imports(const string& protocol);
void clear_exports(const string& protocol);
bool test_policy(const string& policy, const RATTR& attrs, RATTR& mods);
--
1.7.5.4
More information about the Xorp-hackers
mailing list